diff mbox series

[rdma-next,v2,04/11] RDMA/efa: Add the efa_com.h file

Message ID 1550763193-14128-5-git-send-email-galpress@amazon.com (mailing list archive)
State Superseded
Headers show
Series RDMA/efa: Elastic Fabric Adapter (EFA) driver | expand

Commit Message

Gal Pressman Feb. 21, 2019, 3:33 p.m. UTC
A helper header file for EFA admin queue, admin queue completion, asynchronous
notification queue, and various hardware configuration data structures and
functions.

Signed-off-by: Gal Pressman <galpress@amazon.com>
---
 drivers/infiniband/hw/efa/efa_com.h | 141 ++++++++++++++++++++++++++++++++++++
 1 file changed, 141 insertions(+)
 create mode 100644 drivers/infiniband/hw/efa/efa_com.h

Comments

Steve Wise Feb. 26, 2019, 8:09 p.m. UTC | #1
On 2/21/2019 9:33 AM, Gal Pressman wrote:
> A helper header file for EFA admin queue, admin queue completion, asynchronous
> notification queue, and various hardware configuration data structures and
> functions.
>
> Signed-off-by: Gal Pressman <galpress@amazon.com>
> ---
>  drivers/infiniband/hw/efa/efa_com.h | 141 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 141 insertions(+)
>  create mode 100644 drivers/infiniband/hw/efa/efa_com.h
>
> diff --git a/drivers/infiniband/hw/efa/efa_com.h b/drivers/infiniband/hw/efa/efa_com.h
> new file mode 100644
> index 000000000000..439305a8d5e7
> --- /dev/null
> +++ b/drivers/infiniband/hw/efa/efa_com.h
> @@ -0,0 +1,141 @@
> +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
> +/*
> + * Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All rights reserved.
> + */
> +
> +#ifndef _EFA_COM_H_
> +#define _EFA_COM_H_
> +
> +#include <linux/delay.h>
> +#include <linux/semaphore.h>
> +
> +#include "efa_common_defs.h"
> +#include "efa_admin_defs.h"
> +#include "efa_admin_cmds_defs.h"
> +#include "efa_regs_defs.h"
> +
> +#define EFA_MAX_HANDLERS 256
> +
> +#define ADMIN_SQ_SIZE(depth)    ((depth) * sizeof(struct efa_admin_aq_entry))
> +#define ADMIN_CQ_SIZE(depth)    ((depth) * sizeof(struct efa_admin_acq_entry))
> +#define ADMIN_AENQ_SIZE(depth)  ((depth) * sizeof(struct efa_admin_aenq_entry))
> +
> +struct efa_com_admin_cq {
> +	struct efa_admin_acq_entry *entries;
> +	dma_addr_t dma_addr;
> +	spinlock_t lock; /* Protects ACQ */
> +
> +	u16 cc; /* consumer counter */
> +	u8 phase;
> +};
> +
> +struct efa_com_admin_sq {
> +	struct efa_admin_aq_entry *entries;
> +	dma_addr_t dma_addr;
> +	spinlock_t lock; /* Protects ASQ */
> +
> +	u32 __iomem *db_addr;
> +
> +	u16 cc; /* consumer counter */
> +	u16 pc; /* producer counter */
> +	u8 phase;
> +
> +};
> +
> +struct efa_com_stats_admin {
> +	u64 aborted_cmd;
> +	u64 submitted_cmd;
> +	u64 completed_cmd;
> +	u64 no_completion;
> +};
> +
> +enum {
> +	EFA_AQ_STATE_RUNNING_BIT = 0,
> +	EFA_AQ_STATE_POLLING_BIT = 1,
> +};
> +
> +struct efa_com_admin_queue {
> +	void *dmadev;
> +	struct efa_comp_ctx *comp_ctx;
> +	u32 completion_timeout; /* usecs */
> +	u16 poll_interval; /* msecs */
> +	u16 depth;
> +	struct efa_com_admin_cq cq;
> +	struct efa_com_admin_sq sq;
> +	u16 msix_vector_idx;
> +
> +	unsigned long state;
> +
> +	/* Count the number of available admin commands */
> +	struct semaphore avail_cmds;
> +
> +	struct efa_com_stats_admin stats;
> +	spinlock_t stats_lock; /* Protects admin stats */
> +
> +	spinlock_t comp_ctx_lock; /* Protects completion context pool */
> +	u32 *comp_ctx_pool;
> +	u16 comp_ctx_pool_next;
> +};
> +
> +struct efa_aenq_handlers;
> +
> +struct efa_com_aenq {
> +	struct efa_admin_aenq_entry *entries;
> +	struct efa_aenq_handlers *aenq_handlers;
> +	dma_addr_t dma_addr;
> +	u32 cc; /* consumer counter */
> +	u16 msix_vector_idx;
> +	u16 depth;
> +	u8 phase;
> +};
> +
> +struct efa_com_mmio_read {
> +	struct efa_admin_mmio_req_read_less_resp    *read_resp;
> +	dma_addr_t                                   read_resp_dma_addr;
> +	u16                                          seq_num;
> +	u16                                          mmio_read_timeout; /* usecs */
> +	/* serializes mmio reads */
> +	spinlock_t lock;
> +};
> +
> +struct efa_com_dev {
> +	struct efa_com_admin_queue      aq;
> +	struct efa_com_aenq             aenq;
> +	u8 __iomem                     *reg_bar;
> +	void                           *dmadev;
> +	u32                             supported_features;
> +	u32                             dma_addr_bits;
> +
> +	struct efa_com_mmio_read        mmio_read;
> +};
> +


nit: Some structs align the field names, and others don't...

> +typedef void (*efa_aenq_handler)(void *data,
> +	      struct efa_admin_aenq_entry *aenq_e);
> +
> +/* Holds aenq handlers. Indexed by AENQ event group */
> +struct efa_aenq_handlers {
> +	efa_aenq_handler handlers[EFA_MAX_HANDLERS];
> +	efa_aenq_handler unimplemented_handler;
> +};
> +
> +int efa_com_admin_init(struct efa_com_dev *edev,
> +		       struct efa_aenq_handlers *aenq_handlers);
> +void efa_com_admin_destroy(struct efa_com_dev *edev);
> +int efa_com_dev_reset(struct efa_com_dev *edev,
> +		      enum efa_regs_reset_reason_types reset_reason);
> +void efa_com_set_admin_polling_mode(struct efa_com_dev *edev, bool polling);
> +void efa_com_admin_q_comp_intr_handler(struct efa_com_dev *edev);
> +int efa_com_mmio_reg_read_init(struct efa_com_dev *edev);
> +void efa_com_mmio_reg_read_destroy(struct efa_com_dev *edev);
> +
> +int efa_com_validate_version(struct efa_com_dev *edev);
> +int efa_com_get_dma_width(struct efa_com_dev *edev);
> +
> +int efa_com_cmd_exec(struct efa_com_admin_queue *aq,
> +		     struct efa_admin_aq_entry *cmd,
> +		     size_t cmd_size,
> +		     struct efa_admin_acq_entry *comp,
> +		     size_t comp_size);
> +void efa_com_aenq_intr_handler(struct efa_com_dev *edev, void *data);
> +
> +#endif /* _EFA_COM_H_ */


Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Gal Pressman Feb. 27, 2019, 8 a.m. UTC | #2
On 26-Feb-19 22:09, Steve Wise wrote:
>> +struct efa_com_dev {
>> +	struct efa_com_admin_queue      aq;
>> +	struct efa_com_aenq             aenq;
>> +	u8 __iomem                     *reg_bar;
>> +	void                           *dmadev;
>> +	u32                             supported_features;
>> +	u32                             dma_addr_bits;
>> +
>> +	struct efa_com_mmio_read        mmio_read;
>> +};
>> +
> 
> 
> nit: Some structs align the field names, and others don't...

Right, I'll remove the alignments.

> 
>> +typedef void (*efa_aenq_handler)(void *data,
>> +	      struct efa_admin_aenq_entry *aenq_e);
>> +
>> +/* Holds aenq handlers. Indexed by AENQ event group */
>> +struct efa_aenq_handlers {
>> +	efa_aenq_handler handlers[EFA_MAX_HANDLERS];
>> +	efa_aenq_handler unimplemented_handler;
>> +};
>> +
>> +int efa_com_admin_init(struct efa_com_dev *edev,
>> +		       struct efa_aenq_handlers *aenq_handlers);
>> +void efa_com_admin_destroy(struct efa_com_dev *edev);
>> +int efa_com_dev_reset(struct efa_com_dev *edev,
>> +		      enum efa_regs_reset_reason_types reset_reason);
>> +void efa_com_set_admin_polling_mode(struct efa_com_dev *edev, bool polling);
>> +void efa_com_admin_q_comp_intr_handler(struct efa_com_dev *edev);
>> +int efa_com_mmio_reg_read_init(struct efa_com_dev *edev);
>> +void efa_com_mmio_reg_read_destroy(struct efa_com_dev *edev);
>> +
>> +int efa_com_validate_version(struct efa_com_dev *edev);
>> +int efa_com_get_dma_width(struct efa_com_dev *edev);
>> +
>> +int efa_com_cmd_exec(struct efa_com_admin_queue *aq,
>> +		     struct efa_admin_aq_entry *cmd,
>> +		     size_t cmd_size,
>> +		     struct efa_admin_acq_entry *comp,
>> +		     size_t comp_size);
>> +void efa_com_aenq_intr_handler(struct efa_com_dev *edev, void *data);
>> +
>> +#endif /* _EFA_COM_H_ */
> 
> 
> Reviewed-by: Steve Wise <swise@opengridcomputing.com>

Thanks Steve!
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/efa/efa_com.h b/drivers/infiniband/hw/efa/efa_com.h
new file mode 100644
index 000000000000..439305a8d5e7
--- /dev/null
+++ b/drivers/infiniband/hw/efa/efa_com.h
@@ -0,0 +1,141 @@ 
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
+/*
+ * Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All rights reserved.
+ */
+
+#ifndef _EFA_COM_H_
+#define _EFA_COM_H_
+
+#include <linux/delay.h>
+#include <linux/semaphore.h>
+
+#include "efa_common_defs.h"
+#include "efa_admin_defs.h"
+#include "efa_admin_cmds_defs.h"
+#include "efa_regs_defs.h"
+
+#define EFA_MAX_HANDLERS 256
+
+#define ADMIN_SQ_SIZE(depth)    ((depth) * sizeof(struct efa_admin_aq_entry))
+#define ADMIN_CQ_SIZE(depth)    ((depth) * sizeof(struct efa_admin_acq_entry))
+#define ADMIN_AENQ_SIZE(depth)  ((depth) * sizeof(struct efa_admin_aenq_entry))
+
+struct efa_com_admin_cq {
+	struct efa_admin_acq_entry *entries;
+	dma_addr_t dma_addr;
+	spinlock_t lock; /* Protects ACQ */
+
+	u16 cc; /* consumer counter */
+	u8 phase;
+};
+
+struct efa_com_admin_sq {
+	struct efa_admin_aq_entry *entries;
+	dma_addr_t dma_addr;
+	spinlock_t lock; /* Protects ASQ */
+
+	u32 __iomem *db_addr;
+
+	u16 cc; /* consumer counter */
+	u16 pc; /* producer counter */
+	u8 phase;
+
+};
+
+struct efa_com_stats_admin {
+	u64 aborted_cmd;
+	u64 submitted_cmd;
+	u64 completed_cmd;
+	u64 no_completion;
+};
+
+enum {
+	EFA_AQ_STATE_RUNNING_BIT = 0,
+	EFA_AQ_STATE_POLLING_BIT = 1,
+};
+
+struct efa_com_admin_queue {
+	void *dmadev;
+	struct efa_comp_ctx *comp_ctx;
+	u32 completion_timeout; /* usecs */
+	u16 poll_interval; /* msecs */
+	u16 depth;
+	struct efa_com_admin_cq cq;
+	struct efa_com_admin_sq sq;
+	u16 msix_vector_idx;
+
+	unsigned long state;
+
+	/* Count the number of available admin commands */
+	struct semaphore avail_cmds;
+
+	struct efa_com_stats_admin stats;
+	spinlock_t stats_lock; /* Protects admin stats */
+
+	spinlock_t comp_ctx_lock; /* Protects completion context pool */
+	u32 *comp_ctx_pool;
+	u16 comp_ctx_pool_next;
+};
+
+struct efa_aenq_handlers;
+
+struct efa_com_aenq {
+	struct efa_admin_aenq_entry *entries;
+	struct efa_aenq_handlers *aenq_handlers;
+	dma_addr_t dma_addr;
+	u32 cc; /* consumer counter */
+	u16 msix_vector_idx;
+	u16 depth;
+	u8 phase;
+};
+
+struct efa_com_mmio_read {
+	struct efa_admin_mmio_req_read_less_resp    *read_resp;
+	dma_addr_t                                   read_resp_dma_addr;
+	u16                                          seq_num;
+	u16                                          mmio_read_timeout; /* usecs */
+	/* serializes mmio reads */
+	spinlock_t lock;
+};
+
+struct efa_com_dev {
+	struct efa_com_admin_queue      aq;
+	struct efa_com_aenq             aenq;
+	u8 __iomem                     *reg_bar;
+	void                           *dmadev;
+	u32                             supported_features;
+	u32                             dma_addr_bits;
+
+	struct efa_com_mmio_read        mmio_read;
+};
+
+typedef void (*efa_aenq_handler)(void *data,
+	      struct efa_admin_aenq_entry *aenq_e);
+
+/* Holds aenq handlers. Indexed by AENQ event group */
+struct efa_aenq_handlers {
+	efa_aenq_handler handlers[EFA_MAX_HANDLERS];
+	efa_aenq_handler unimplemented_handler;
+};
+
+int efa_com_admin_init(struct efa_com_dev *edev,
+		       struct efa_aenq_handlers *aenq_handlers);
+void efa_com_admin_destroy(struct efa_com_dev *edev);
+int efa_com_dev_reset(struct efa_com_dev *edev,
+		      enum efa_regs_reset_reason_types reset_reason);
+void efa_com_set_admin_polling_mode(struct efa_com_dev *edev, bool polling);
+void efa_com_admin_q_comp_intr_handler(struct efa_com_dev *edev);
+int efa_com_mmio_reg_read_init(struct efa_com_dev *edev);
+void efa_com_mmio_reg_read_destroy(struct efa_com_dev *edev);
+
+int efa_com_validate_version(struct efa_com_dev *edev);
+int efa_com_get_dma_width(struct efa_com_dev *edev);
+
+int efa_com_cmd_exec(struct efa_com_admin_queue *aq,
+		     struct efa_admin_aq_entry *cmd,
+		     size_t cmd_size,
+		     struct efa_admin_acq_entry *comp,
+		     size_t comp_size);
+void efa_com_aenq_intr_handler(struct efa_com_dev *edev, void *data);
+
+#endif /* _EFA_COM_H_ */