net/mlx5: create advanced RxQ object via DevX
authorDekel Peled <dekelp@mellanox.com>
Mon, 22 Jul 2019 14:52:06 +0000 (14:52 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 23 Jul 2019 12:31:36 +0000 (14:31 +0200)
Implement function mlx5_devx_cmd_create_rq() to create RQ object using
DevX API.
Add related structs in mlx5.h and mlx5_prm.h.

Signed-off-by: Dekel Peled <dekelp@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
drivers/net/mlx5/mlx5.h
drivers/net/mlx5/mlx5_devx_cmds.c
drivers/net/mlx5/mlx5_prm.h

index 84975ed..4f4c4a7 100644 (file)
@@ -260,6 +260,52 @@ struct mlx5_dev_config {
        struct mlx5_lro_config lro; /* LRO configuration. */
 };
 
+struct mlx5_devx_wq_attr {
+       uint32_t wq_type:4;
+       uint32_t wq_signature:1;
+       uint32_t end_padding_mode:2;
+       uint32_t cd_slave:1;
+       uint32_t hds_skip_first_sge:1;
+       uint32_t log2_hds_buf_size:3;
+       uint32_t page_offset:5;
+       uint32_t lwm:16;
+       uint32_t pd:24;
+       uint32_t uar_page:24;
+       uint64_t dbr_addr;
+       uint32_t hw_counter;
+       uint32_t sw_counter;
+       uint32_t log_wq_stride:4;
+       uint32_t log_wq_pg_sz:5;
+       uint32_t log_wq_sz:5;
+       uint32_t dbr_umem_valid:1;
+       uint32_t wq_umem_valid:1;
+       uint32_t log_hairpin_num_packets:5;
+       uint32_t log_hairpin_data_sz:5;
+       uint32_t single_wqe_log_num_of_strides:4;
+       uint32_t two_byte_shift_en:1;
+       uint32_t single_stride_log_num_of_bytes:3;
+       uint32_t dbr_umem_id;
+       uint32_t wq_umem_id;
+       uint64_t wq_umem_offset;
+};
+
+/* Create RQ attributes structure, used by create RQ operation. */
+struct mlx5_devx_create_rq_attr {
+       uint32_t rlky:1;
+       uint32_t delay_drop_en:1;
+       uint32_t scatter_fcs:1;
+       uint32_t vsd:1;
+       uint32_t mem_rq_type:4;
+       uint32_t state:4;
+       uint32_t flush_in_error_en:1;
+       uint32_t hairpin:1;
+       uint32_t user_index:24;
+       uint32_t cqn:24;
+       uint32_t counter_set_id:8;
+       uint32_t rmpn:24;
+       struct mlx5_devx_wq_attr wq_attr;
+};
+
 /**
  * Type of object being allocated.
  */
@@ -740,4 +786,8 @@ struct mlx5_devx_obj *mlx5_devx_cmd_mkey_create(struct ibv_context *ctx,
 int mlx5_devx_get_out_command_status(void *out);
 int mlx5_devx_cmd_qp_query_tis_td(struct ibv_qp *qp, uint32_t tis_num,
                                  uint32_t *tis_td);
+struct mlx5_devx_obj *mlx5_devx_cmd_create_rq(struct ibv_context *ctx,
+                               struct mlx5_devx_create_rq_attr *rq_attr,
+                               int socket);
+
 #endif /* RTE_PMD_MLX5_H_ */
index 3d07fcf..f68c94b 100644 (file)
@@ -424,3 +424,105 @@ mlx5_devx_cmd_qp_query_tis_td(struct ibv_qp *qp, uint32_t tis_num,
        *tis_td = MLX5_GET(tisc, tis_ctx, transport_domain);
        return 0;
 }
+
+/**
+ * Fill WQ data for DevX API command.
+ * Utility function for use when creating DevX objects containing a WQ.
+ *
+ * @param[in] wq_ctx
+ *   Pointer to WQ context to fill with data.
+ * @param [in] wq_attr
+ *   Pointer to WQ attributes structure to fill in WQ context.
+ */
+static void
+devx_cmd_fill_wq_data(void *wq_ctx, struct mlx5_devx_wq_attr *wq_attr)
+{
+       MLX5_SET(wq, wq_ctx, wq_type, wq_attr->wq_type);
+       MLX5_SET(wq, wq_ctx, wq_signature, wq_attr->wq_signature);
+       MLX5_SET(wq, wq_ctx, end_padding_mode, wq_attr->end_padding_mode);
+       MLX5_SET(wq, wq_ctx, cd_slave, wq_attr->cd_slave);
+       MLX5_SET(wq, wq_ctx, hds_skip_first_sge, wq_attr->hds_skip_first_sge);
+       MLX5_SET(wq, wq_ctx, log2_hds_buf_size, wq_attr->log2_hds_buf_size);
+       MLX5_SET(wq, wq_ctx, page_offset, wq_attr->page_offset);
+       MLX5_SET(wq, wq_ctx, lwm, wq_attr->lwm);
+       MLX5_SET(wq, wq_ctx, pd, wq_attr->pd);
+       MLX5_SET(wq, wq_ctx, uar_page, wq_attr->uar_page);
+       MLX5_SET64(wq, wq_ctx, dbr_addr, wq_attr->dbr_addr);
+       MLX5_SET(wq, wq_ctx, hw_counter, wq_attr->hw_counter);
+       MLX5_SET(wq, wq_ctx, sw_counter, wq_attr->sw_counter);
+       MLX5_SET(wq, wq_ctx, log_wq_stride, wq_attr->log_wq_stride);
+       MLX5_SET(wq, wq_ctx, log_wq_pg_sz, wq_attr->log_wq_pg_sz);
+       MLX5_SET(wq, wq_ctx, log_wq_sz, wq_attr->log_wq_sz);
+       MLX5_SET(wq, wq_ctx, dbr_umem_valid, wq_attr->dbr_umem_valid);
+       MLX5_SET(wq, wq_ctx, wq_umem_valid, wq_attr->wq_umem_valid);
+       MLX5_SET(wq, wq_ctx, log_hairpin_num_packets,
+                wq_attr->log_hairpin_num_packets);
+       MLX5_SET(wq, wq_ctx, log_hairpin_data_sz, wq_attr->log_hairpin_data_sz);
+       MLX5_SET(wq, wq_ctx, single_wqe_log_num_of_strides,
+                wq_attr->single_wqe_log_num_of_strides);
+       MLX5_SET(wq, wq_ctx, two_byte_shift_en, wq_attr->two_byte_shift_en);
+       MLX5_SET(wq, wq_ctx, single_stride_log_num_of_bytes,
+                wq_attr->single_stride_log_num_of_bytes);
+       MLX5_SET(wq, wq_ctx, dbr_umem_id, wq_attr->dbr_umem_id);
+       MLX5_SET(wq, wq_ctx, wq_umem_id, wq_attr->wq_umem_id);
+       MLX5_SET64(wq, wq_ctx, wq_umem_offset, wq_attr->wq_umem_offset);
+}
+
+/**
+ * Create RQ using DevX API.
+ *
+ * @param[in] ctx
+ *   ibv_context returned from mlx5dv_open_device.
+ * @param [in] rq_attr
+ *   Pointer to create RQ attributes structure.
+ * @param [in] socket
+ *   CPU socket ID for allocations.
+ *
+ * @return
+ *   The DevX object created, NULL otherwise and rte_errno is set.
+ */
+struct mlx5_devx_obj *
+mlx5_devx_cmd_create_rq(struct ibv_context *ctx,
+                       struct mlx5_devx_create_rq_attr *rq_attr,
+                       int socket)
+{
+       uint32_t in[MLX5_ST_SZ_DW(create_rq_in)] = {0};
+       uint32_t out[MLX5_ST_SZ_DW(create_rq_out)] = {0};
+       void *rq_ctx, *wq_ctx;
+       struct mlx5_devx_wq_attr *wq_attr;
+       struct mlx5_devx_obj *rq = NULL;
+
+       rq = rte_calloc_socket(__func__, 1, sizeof(*rq), 0, socket);
+       if (!rq) {
+               DRV_LOG(ERR, "Failed to allocate RQ data");
+               rte_errno = ENOMEM;
+               return NULL;
+       }
+       MLX5_SET(create_rq_in, in, opcode, MLX5_CMD_OP_CREATE_RQ);
+       rq_ctx = MLX5_ADDR_OF(create_rq_in, in, ctx);
+       MLX5_SET(rqc, rq_ctx, rlky, rq_attr->rlky);
+       MLX5_SET(rqc, rq_ctx, delay_drop_en, rq_attr->delay_drop_en);
+       MLX5_SET(rqc, rq_ctx, scatter_fcs, rq_attr->scatter_fcs);
+       MLX5_SET(rqc, rq_ctx, vsd, rq_attr->vsd);
+       MLX5_SET(rqc, rq_ctx, mem_rq_type, rq_attr->mem_rq_type);
+       MLX5_SET(rqc, rq_ctx, state, rq_attr->state);
+       MLX5_SET(rqc, rq_ctx, flush_in_error_en, rq_attr->flush_in_error_en);
+       MLX5_SET(rqc, rq_ctx, hairpin, rq_attr->hairpin);
+       MLX5_SET(rqc, rq_ctx, user_index, rq_attr->user_index);
+       MLX5_SET(rqc, rq_ctx, cqn, rq_attr->cqn);
+       MLX5_SET(rqc, rq_ctx, counter_set_id, rq_attr->counter_set_id);
+       MLX5_SET(rqc, rq_ctx, rmpn, rq_attr->rmpn);
+       wq_ctx = MLX5_ADDR_OF(rqc, rq_ctx, wq);
+       wq_attr = &rq_attr->wq_attr;
+       devx_cmd_fill_wq_data(wq_ctx, wq_attr);
+       rq->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
+                                                 out, sizeof(out));
+       if (!rq->obj) {
+               DRV_LOG(ERR, "Failed to create RQ using DevX");
+               rte_errno = errno;
+               rte_free(rq);
+               return NULL;
+       }
+       rq->id = MLX5_GET(create_rq_out, out, rqn);
+       return rq;
+}
index b5de0c3..fbf00a0 100644 (file)
@@ -627,6 +627,7 @@ enum {
        MLX5_CMD_OP_QUERY_HCA_CAP = 0x100,
        MLX5_CMD_OP_CREATE_MKEY = 0x200,
        MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT = 0x754,
+       MLX5_CMD_OP_CREATE_RQ = 0x908,
        MLX5_CMD_OP_QUERY_TIS = 0x915,
        MLX5_CMD_OP_ALLOC_FLOW_COUNTER = 0x939,
        MLX5_CMD_OP_QUERY_FLOW_COUNTER = 0x93b,
@@ -1268,6 +1269,115 @@ struct mlx5_ifc_query_tis_in_bits {
        u8 reserved_at_60[0x20];
 };
 
+enum {
+       MLX5_WQ_TYPE_LINKED_LIST                = 0x0,
+       MLX5_WQ_TYPE_CYCLIC                     = 0x1,
+       MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ    = 0x2,
+       MLX5_WQ_TYPE_CYCLIC_STRIDING_RQ         = 0x3,
+};
+
+enum {
+       MLX5_WQ_END_PAD_MODE_NONE  = 0x0,
+       MLX5_WQ_END_PAD_MODE_ALIGN = 0x1,
+};
+
+struct mlx5_ifc_wq_bits {
+       u8 wq_type[0x4];
+       u8 wq_signature[0x1];
+       u8 end_padding_mode[0x2];
+       u8 cd_slave[0x1];
+       u8 reserved_at_8[0x18];
+       u8 hds_skip_first_sge[0x1];
+       u8 log2_hds_buf_size[0x3];
+       u8 reserved_at_24[0x7];
+       u8 page_offset[0x5];
+       u8 lwm[0x10];
+       u8 reserved_at_40[0x8];
+       u8 pd[0x18];
+       u8 reserved_at_60[0x8];
+       u8 uar_page[0x18];
+       u8 dbr_addr[0x40];
+       u8 hw_counter[0x20];
+       u8 sw_counter[0x20];
+       u8 reserved_at_100[0xc];
+       u8 log_wq_stride[0x4];
+       u8 reserved_at_110[0x3];
+       u8 log_wq_pg_sz[0x5];
+       u8 reserved_at_118[0x3];
+       u8 log_wq_sz[0x5];
+       u8 dbr_umem_valid[0x1];
+       u8 wq_umem_valid[0x1];
+       u8 reserved_at_122[0x1];
+       u8 log_hairpin_num_packets[0x5];
+       u8 reserved_at_128[0x3];
+       u8 log_hairpin_data_sz[0x5];
+       u8 reserved_at_130[0x4];
+       u8 single_wqe_log_num_of_strides[0x4];
+       u8 two_byte_shift_en[0x1];
+       u8 reserved_at_139[0x4];
+       u8 single_stride_log_num_of_bytes[0x3];
+       u8 dbr_umem_id[0x20];
+       u8 wq_umem_id[0x20];
+       u8 wq_umem_offset[0x40];
+       u8 reserved_at_1c0[0x440];
+};
+
+enum {
+       MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE  = 0x0,
+       MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_RMP     = 0x1,
+};
+
+enum {
+       MLX5_RQC_STATE_RST  = 0x0,
+       MLX5_RQC_STATE_RDY  = 0x1,
+       MLX5_RQC_STATE_ERR  = 0x3,
+};
+
+struct mlx5_ifc_rqc_bits {
+       u8 rlky[0x1];
+       u8 delay_drop_en[0x1];
+       u8 scatter_fcs[0x1];
+       u8 vsd[0x1];
+       u8 mem_rq_type[0x4];
+       u8 state[0x4];
+       u8 reserved_at_c[0x1];
+       u8 flush_in_error_en[0x1];
+       u8 hairpin[0x1];
+       u8 reserved_at_f[0x11];
+       u8 reserved_at_20[0x8];
+       u8 user_index[0x18];
+       u8 reserved_at_40[0x8];
+       u8 cqn[0x18];
+       u8 counter_set_id[0x8];
+       u8 reserved_at_68[0x18];
+       u8 reserved_at_80[0x8];
+       u8 rmpn[0x18];
+       u8 reserved_at_a0[0x8];
+       u8 hairpin_peer_sq[0x18];
+       u8 reserved_at_c0[0x10];
+       u8 hairpin_peer_vhca[0x10];
+       u8 reserved_at_e0[0xa0];
+       struct mlx5_ifc_wq_bits wq; /* Not used in LRO RQ. */
+};
+
+struct mlx5_ifc_create_rq_out_bits {
+       u8 status[0x8];
+       u8 reserved_at_8[0x18];
+       u8 syndrome[0x20];
+       u8 reserved_at_40[0x8];
+       u8 rqn[0x18];
+       u8 reserved_at_60[0x20];
+};
+
+struct mlx5_ifc_create_rq_in_bits {
+       u8 opcode[0x10];
+       u8 uid[0x10];
+       u8 reserved_at_20[0x10];
+       u8 op_mod[0x10];
+       u8 reserved_at_40[0xc0];
+       struct mlx5_ifc_rqc_bits ctx;
+};
+
 /* CQE format mask. */
 #define MLX5E_CQE_FORMAT_MASK 0xc