conntrack support in mlx5 PMD
Subsystems (2)
cover conntrack support in mlx5 PMD
This patch set adds the connection tracking offload support in the mlx5 driver.
Bing Zhao (17):
common/mlx5: add connection tracking object definition common/mlx5: add CT offload capability checking net/mlx5: use meter color reg for CT net/mlx5: initialization of CT management common/mlx5: add Dexv CT objects creation net/mlx5: add modify support for CT
net/mlx5: add actions creating for CT net/mlx5: close CT management structure net/mlx5: add ASO CT query implementation net/mlx5: add ASO CT destroy handling net/mlx5: add translation for CT action net/mlx5: add translation of CT item net/mlx5: add CT context update
net/mlx5: validation of CT action
net/mlx5: validation of CT item
net/mlx5: reduce the reference count of CT net/mlx5: add support of CT between two ports
drivers/common/mlx5/linux/meson.build | 2 + drivers/common/mlx5/mlx5_devx_cmds.c | 53 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 5 + drivers/common/mlx5/mlx5_prm.h | 88 +++++ drivers/common/mlx5/version.map | 1 + drivers/net/mlx5/linux/mlx5_os.c | 13 + drivers/net/mlx5/mlx5.c | 92 ++++++ drivers/net/mlx5/mlx5.h | 72 +++++ drivers/net/mlx5/mlx5_flow.c | 44 ++- drivers/net/mlx5/mlx5_flow.h | 99 +++++- drivers/net/mlx5/mlx5_flow_aso.c | 586 ++++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 571 ++++++++++++++++++++++++++++++++- 12 files changed, 1623 insertions(+), 3 deletions(-)
Signature · 1 line
2.5.5
PATCH 1/17 common/mlx5: add connection tracking object definition
The structures of ASO connection tracking offload object are added based on the definitions in the PRM. One CT object context will be loaded into the cache completely in a reversed order of dwords. The valid bit should be the MSB of the last dword. This is used for the conntrack context creation and update, as well as the query.
The capabilities 2 (HCA_CAP_2) layout is also added. The connection tracking related capabilities could be queried via the HCA_CAP_2.
--- drivers/common/mlx5/mlx5_prm.h | 85 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
drivers/common/mlx5/mlx5_prm.h +85 -0
@@ -1119,6 +1119,7 @@ enum {MLX5_GET_HCA_CAP_OP_MOD_ROCE =0x4 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE =0x7 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_VDPA_EMULATION =0x13 <<1 , + MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE_2 = 0x20 << 1, };#define MLX5_GENERAL_OBJ_TYPES_CAP_VIRTQ_NET_Q \
@@ -1661,6 +1662,29 @@ struct mlx5_ifc_flow_table_nic_cap_bits {struct mlx5_ifc_flow_table_prop_layout_bits flow_table_properties; }; +struct mlx5_ifc_cmd_hca_cap_2_bits { +u8 reserved_at_0[0x80 ];/* End of DW4. */ +u8 reserved_at_80[0xb ]; +u8 log_max_num_reserved_qpn[0x5 ]; +u8 reserved_at_90[0x3 ]; +u8 log_reserved_qpn_granularity[0x5 ]; +u8 reserved_at_98[0x3 ]; +u8 log_reserved_qpn_max_alloc[0x5 ];/* End of DW5. */ +u8 max_reformat_insert_size[0x8 ]; +u8 max_reformat_insert_offset[0x8 ]; +u8 max_reformat_remove_size[0x8 ]; +u8 max_reformat_remove_offset[0x8 ];/* End of DW6. */ +u8 aso_conntrack_reg_id[0x8 ]; +u8 reserved_at_c8[0x3 ]; +u8 log_conn_track_granularity[0x5 ]; +u8 reserved_at_d0[0x3 ]; +u8 log_conn_track_max_alloc[0x5 ]; +u8 reserved_at_d8[0x3 ]; +u8 log_max_conn_track_offload[0x5 ]; +u8 reserved_at_e0[0x20 ];/* End of DW7. */ +u8 reserved_at_100[0x700 ]; +}; +union mlx5_ifc_hca_cap_union_bits {struct mlx5_ifc_cmd_hca_cap_bits cmd_hca_cap;struct mlx5_ifc_per_protocol_networking_offload_caps_bits
@@ -2592,6 +2616,67 @@ struct mlx5_ifc_create_flow_meter_aso_in_bits {struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr;struct mlx5_ifc_flow_meter_aso_bits flow_meter_aso; }; + +struct mlx5_ifc_tcp_window_params_bits { +u8 max_ack[0x20 ]; +u8 max_win[0x20 ]; +u8 reply_end[0x20 ]; +u8 sent_end[0x20 ]; +}; + +struct mlx5_ifc_conn_track_aso_bits { +struct mlx5_ifc_tcp_window_params_bits reply_dir;/* End of DW3. */ +struct mlx5_ifc_tcp_window_params_bits original_dir;/* End of DW7. */ +u8 last_end[0x20 ];/* End of DW8. */ +u8 last_ack[0x20 ];/* End of DW9. */ +u8 last_seq[0x20 ];/* End of DW10. */ +u8 last_win[0x10 ]; +u8 reserved_at_170[0xa ]; +u8 last_dir[0x1 ]; +u8 last_index[0x5 ];/* End of DW11. */ +u8 reserved_at_180[0x40 ];/* End of DW13. */ +u8 reply_dircetion_tcp_scale[0x4 ]; +u8 reply_dircetion_tcp_close_initiated[0x1 ]; +u8 reply_dircetion_tcp_liberal_enabled[0x1 ]; +u8 reply_dircetion_tcp_data_unacked[0x1 ]; +u8 reply_dircetion_tcp_max_ack[0x1 ]; +u8 reserved_at_1c8[0x8 ]; +u8 original_dircetion_tcp_scale[0x4 ]; +u8 original_dircetion_tcp_close_initiated[0x1 ]; +u8 original_dircetion_tcp_liberal_enabled[0x1 ]; +u8 original_dircetion_tcp_data_unacked[0x1 ]; +u8 original_dircetion_tcp_max_ack[0x1 ]; +u8 reserved_at_1d8[0x8 ];/* End of DW14. */ +u8 valid[0x1 ]; +u8 state[0x3 ]; +u8 freeze_track[0x1 ]; +u8 reserved_at_1e5[0xb ]; +u8 reserved_at_1f0[0x1 ]; +u8 connection_assured[0x1 ]; +u8 sack_permitted[0x1 ]; +u8 challenged_acked[0x1 ]; +u8 heartbeat[0x1 ]; +u8 max_ack_window[0x3 ]; +u8 reserved_at_1f8[0x1 ]; +u8 retransmission_counter[0x3 ]; +u8 retranmission_limit_exceeded[0x1 ]; +u8 retranmission_limit[0x3 ];/* End of DW15. */ +}; + +struct mlx5_ifc_conn_track_offload_bits { +u8 modify_field_select[0x40 ]; +u8 reserved_at_40[0x40 ]; +u8 reserved_at_80[0x8 ]; +u8 conn_track_aso_access_pd[0x18 ]; +u8 reserved_at_a0[0x160 ]; +struct mlx5_ifc_conn_track_aso_bits conn_track_aso; +}; + +struct mlx5_ifc_create_conn_track_aso_in_bits { +struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr; +struct mlx5_ifc_conn_track_offload_bits conn_track_offload; +}; +enum mlx5_access_aso_opc_mod {ASO_OPC_MOD_IPSEC =0x0 ,ASO_OPC_MOD_CONNECTION_TRACKING =0x1 ,
Signature · 1 line
2.5.5
PATCH 2/17 common/mlx5: add CT offload capability checking
In reply to Bing ZhaoDuring startup, the ASO connection tracking offload capability could be queried via HCA_CAP_QUERY command. If the HW doesn't support ASO CT, the value would be 0 by default. The following initialization should be skipped and the creation of the CT object should return a failure directly.
The following CT creation should also check this capability. With the old driver, the pre-processing macro should be used in order to make the compiling pass.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/mlx5_devx_cmds.c | 3 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 3 +++ 4 files changed, 9 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -189,6 +189,8 @@ has_sym_args = [ 'MLX5_WQE_UMR_CTRL_FLAG_INLINE' ], [ 'HAVE_MLX5_DR_FLOW_DUMP_RULE', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_rule' ], + [ 'HAVE_MLX5_DR_ACTION_ASO_CT', 'infiniband/mlx5dv.h', + 'MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR' ], ] config = configuration_data() foreach arg:has_sym_args
drivers/common/mlx5/mlx5_devx_cmds.c +3 -0
@@ -760,6 +760,9 @@ mlx5_devx_cmd_query_hca_attr(void *ctx,MLX5_GET (cmd_hca_cap, hcattr, umr_indirect_mkey_disabled); attr->umr_modify_entity_size_disabled =MLX5_GET (cmd_hca_cap, hcattr, umr_modify_entity_size_disabled); + attr->ct_offload = !!(MLX5_GET64 (cmd_hca_cap, hcattr, + general_obj_types) & +MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD );if (attr->qos.sup) { MLX5_SET(query_hca_cap_in, in, op_mod, MLX5_GET_HCA_CAP_OP_MOD_QOS_CAP |
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -136,6 +136,7 @@ struct mlx5_hca_attr { uint32_t qp_ts_format:2; uint32_t regex:1; uint32_t reg_c_preserve:1; + uint32_t ct_offload:1; /* General obj type ASO CT offload supported. */uint32_t regexp_num_of_engines; uint32_t log_max_ft_sampler_num:8;uint32_t geneve_tlv_opt;
drivers/common/mlx5/mlx5_prm.h +3 -0
@@ -1134,6 +1134,8 @@ enum { (1ULL << MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO)#define MLX5_GENERAL_OBJ_TYPES_CAP_GENEVE_TLV_OPT \ (1ULL << MLX5_OBJ_TYPE_GENEVE_TLV_OPT) +#define MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD \ + (1ULL << MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD)enum {MLX5_HCA_CAP_OPMOD_GET_MAX =0 ,
@@ -2449,6 +2451,7 @@ enum {MLX5_GENERAL_OBJ_TYPE_FLEX_PARSE_GRAPH =0x0022 ,MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO =0x0024 ,MLX5_GENERAL_OBJ_TYPE_FLOW_HIT_ASO =0x0025 , + MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD = 0x0031, }; struct mlx5_ifc_general_obj_in_cmd_hdr_bits {
Signature · 1 line
2.5.5
PATCH 3/17 net/mlx5: use meter color reg for CT
In reply to Bing ZhaoBased on the capacity, 3 registers could be used. Due to the register allocation, only the one REG_C_3 for meter color could be reused right now.
Then in the same flow, no more than one ASO action can be supported.
--- drivers/net/mlx5/mlx5_flow.c | 4 +++- drivers/net/mlx5/mlx5_flow.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow.c +3 -1
@@ -759,7 +759,9 @@ mlx5_flow_get_reg_id(struct rte_eth_dev *dev,return priv->mtr_color_reg !=REG_C_2 ?REG_C_2 :REG_C_3 ;case MLX5_MTR_COLOR : -case MLX5_ASO_FLOW_HIT :/* Both features use the same REG_C. */ +case MLX5_ASO_FLOW_HIT : +case MLX5_ASO_CONNTRACK : +/* All features use the same REG_C. */ MLX5_ASSERT (priv->mtr_color_reg !=REG_NON );return priv->mtr_color_reg;case MLX5_COPY_MARK :
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -84,6 +84,7 @@ enum mlx5_feature_name {MLX5_MTR_COLOR ,MLX5_MTR_ID ,MLX5_ASO_FLOW_HIT , + MLX5_ASO_CONNTRACK, };/* Default queue number. */
Signature · 1 line
2.5.5
PATCH 4/17 net/mlx5: initialization of CT management
In reply to Bing ZhaoThe definitions of ASO connection tracking objects management structures are added.
Considering performance, the bulk allocation of ASO CT objects should be used. The maximal value per bulk and the granularity could be fetched from HCA capabilities 2. Right now, a fixed number of 64 is used for each bulk for a better management purpose.
The ASO QP for CT is initialized, the SQ will be used for both modify and query command.
--- drivers/net/mlx5/linux/mlx5_os.c | 13 +++++++++++ drivers/net/mlx5/mlx5.c | 36 +++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 50 ++++++++++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 49 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +13 -0
@@ -1322,6 +1322,19 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,DRV_LOG (DEBUG ,"Flow Hit ASO is supported." ); }#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */ +#if defined(HAVE_MLX5_DR_CREATE_ACTION_ASO ) && \ + defined(HAVE_MLX5_DR_ACTION_ASO_CT ) +if (config->hca_attr.ct_offload && + priv->mtr_color_reg ==REG_C_3 ) { + err =mlx5_flow_aso_ct_mng_init (sh); +if (err) { + err = -err; + goto error; + } +DRV_LOG (DEBUG ,"CT ASO is supported." ); + sh->ct_aso_en =1 ; + } +#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO && HAVE_MLX5_DR_ACTION_ASO_CT */ #if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE )if (config->hca_attr.log_max_ft_sampler_num >0 && config->dv_flow_en) {
drivers/net/mlx5/mlx5.c +36 -0
@@ -670,6 +670,42 @@ mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh) } } +/* +* Initialize the ASO connection tracking structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_flow_aso_ct_mng_init (struct mlx5_dev_ctx_shared *sh) +{ +int err; + +if (sh->ct_mng) +return 0 ; + sh->ct_mng =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*sh->ct_mng), +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +if (!sh->ct_mng) { +DRV_LOG (ERR ,"ASO CT management allocation failed." ); + rte_errno =ENOMEM ; +return -rte_errno; + } + err =mlx5_aso_queue_init (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); +if (err) { +mlx5_free (sh->ct_mng); +/* rte_errno should be extracted from the failure. */ + rte_errno =EINVAL ; +return -rte_errno; + } +rte_spinlock_init (&sh->ct_mng->ct_sl); +rte_rwlock_init (&sh->ct_mng->resize_rwl); +LIST_INIT (&sh->ct_mng->free_cts); +return 0 ; +} +/** * Initialize the flow resources' indexed mempool. *
drivers/net/mlx5/mlx5.h +50 -0
74 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_aso.c +49 -0
61 lines not on this page · raw message
Signature · 1 line
2.5.5
PATCH 5/17 common/mlx5: add Dexv CT objects creation
In reply to Bing ZhaoAdding support for connection tracking ASO creation via Devx command. Right now only bulk creation is supported.
By default, the objects with zero contents will be created. Before using a single object, the modification via posting a WQE to the ASO CT SQ is needed.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 50 ++++++++++++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 4 +++ drivers/common/mlx5/version.map | 1 + 3 files changed, 55 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +50 -0
@@ -2230,6 +2230,56 @@ mlx5_devx_cmd_create_flow_meter_aso_obj(void *ctx, uint32_t pd,return flow_meter_aso_obj; } +/* +* Create general object of type CONN_TRACK_OFFLOAD using DevX API. +* +* @param[in] ctx +* Context returned from mlx5 open_device() glue function. +* @param [in] pd +* PD value to associate the CONN_TRACK_OFFLOAD ASO object with. +* @param [in] log_obj_size +* log_obj_size to allocate its power of 2 * objects +* in one CONN_TRACK_OFFLOAD bulk allocation. +* +* @return +* The DevX object created, NULL otherwise and rte_errno is set. +*/ +struct mlx5_devx_obj * +mlx5_devx_cmd_create_conn_track_offload_obj (void *ctx,uint32_t pd, +uint32_t log_obj_size) +{ +uint32_t in[MLX5_ST_SZ_DW (create_conn_track_aso_in)] = {0 }; +uint32_t out[MLX5_ST_SZ_DW (general_obj_out_cmd_hdr)]; +struct mlx5_devx_obj *ct_aso_obj; +void *ptr; + + ct_aso_obj =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*ct_aso_obj), +0 ,SOCKET_ID_ANY ); +if (!ct_aso_obj) { +DRV_LOG (ERR ,"Failed to allocate CONN_TRACK_OFFLOAD object." ); + rte_errno =ENOMEM ; +return NULL ; + } + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, hdr); +MLX5_SET (general_obj_in_cmd_hdr, ptr, opcode, +MLX5_CMD_OP_CREATE_GENERAL_OBJECT ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, obj_type, +MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, log_obj_range, log_obj_size); + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, conn_track_offload); +MLX5_SET (conn_track_offload, ptr, conn_track_aso_access_pd, pd); + ct_aso_obj->obj = mlx5_glue->devx_obj_create (ctx, in,sizeof (in), + out,sizeof (out)); +if (!ct_aso_obj->obj) { + rte_errno = errno; +DRV_LOG (ERR ,"Failed to create CONN_TRACK_OFFLOAD obj by using DevX." ); +mlx5_free (ct_aso_obj); +return NULL ; + } + ct_aso_obj->id =MLX5_GET (general_obj_out_cmd_hdr, out, obj_id); +return ct_aso_obj; +} +/** * Create general object of type GENEVE TLV option using DevX API. *
drivers/common/mlx5/mlx5_devx_cmds.h +4 -0
@@ -568,6 +568,10 @@ struct mlx5_devx_obj *mlx5_devx_cmd_queue_counter_alloc(void *ctx);__rte_internal int mlx5_devx_cmd_queue_counter_query(struct mlx5_devx_obj *dcs, int clear,uint32_t *out_of_buffers); +__rte_internal +struct mlx5_devx_obj *mlx5_devx_cmd_create_conn_track_offload_obj(void *ctx, +uint32_t pd,uint32_t log_obj_size); +/** * Create general object of type FLOW_METER_ASO using DevX API.. *
drivers/common/mlx5/version.map +1 -0
@@ -13,6 +13,7 @@ INTERNAL { mlx5_dev_to_pci_addr; # WINDOWS_NO_EXPORT mlx5_devx_cmd_alloc_pd; + mlx5_devx_cmd_create_conn_track_offload_obj; mlx5_devx_cmd_create_cq; mlx5_devx_cmd_create_flex_parser; mlx5_devx_cmd_create_qp;
Signature · 1 line
2.5.5
PATCH 6/17 net/mlx5: add modify support for CT
In reply to Bing ZhaoAfter the connection tracking object bulk is allocated, all the objects' contents are filled with zero by default. One object must be modified via WQE operation before using it.
In order to reduce the latency for the flow creation, an asynchronous way is used instead of busy waiting for the CQE to be generated.
--- drivers/net/mlx5/mlx5.h | 6 + drivers/net/mlx5/mlx5_flow.h | 3 + drivers/net/mlx5/mlx5_flow_aso.c | 288 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+)
drivers/net/mlx5/mlx5.h +6 -0
@@ -498,6 +498,7 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; +struct mlx5_aso_ct_action *ct; }; };
@@ -1700,5 +1701,10 @@ int mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh, struct mlx5_aso_mtr *mtr);int mlx5_aso_mtr_wait (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_mtr *mtr); +int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +const struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_wait_ready (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -45,6 +45,7 @@ enum mlx5_rte_flow_action_type {enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE , +MLX5_INDIRECT_ACTION_TYPE_AGE , };/* Matches on selected register. */
@@ -828,6 +829,8 @@ struct mlx5_flow {#define MLX5_ASO_WQE_CQE_RESPONSE_DELAY 10u#define MLX5_MTR_POLL_WQE_CQE_TIMES 100000u +#define MLX5_CT_POLL_WQE_CQE_TIMES MLX5_MTR_POLL_WQE_CQE_TIMES +#define MLX5_MAN_WIDTH 8/* Legacy Meter parameter structure. */ struct mlx5_legacy_flow_meter {
drivers/net/mlx5/mlx5_flow_aso.c +288 -0
291 lines not on this page · raw message
Signature · 1 line
2.5.5
PATCH 7/17 net/mlx5: add actions creating for CT
In reply to Bing ZhaoAllocating a CT from the management pools and creating the DR actions for both directions by default.
If there is no available connection tracking action, a new pool will be created with a fixed size bulk allocation. Right now, all the resources are controlled by the linked list.
The ASO connection tracking context associated with these actions need to be updated via WQE before using for steering.
--- drivers/net/mlx5/mlx5.h | 4 + drivers/net/mlx5/mlx5_flow.h | 27 ++++- drivers/net/mlx5/mlx5_flow_dv.c | 261 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 291 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +4 -0
@@ -995,6 +995,10 @@ struct mlx5_bond_info {/* Number of connection tracking objects per pool: must be a power of 2. */ #define MLX5_ASO_CT_ACTIONS_PER_POOL 64 +/* Generate incremental and unique CT index from pool and offset. */ +#define MLX5_MAKE_CT_IDX (pool, offset) \ + ((pool) * MLX5_ASO_CT_ACTIONS_PER_POOL + (offset) + 1) +/* ASO Conntrack state. */ enum mlx5_aso_ct_state {ASO_CONNTRACK_FREE ,/* Inactive, in the free list. */
drivers/net/mlx5/mlx5_flow.h +26 -1
@@ -45,7 +45,7 @@ enum mlx5_rte_flow_action_type {enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE , -MLX5_INDIRECT_ACTION_TYPE_AGE , +MLX5_INDIRECT_ACTION_TYPE_CT , };/* Matches on selected register. */
@@ -1286,6 +1286,31 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)return &pool->mtrs[idx %MLX5_ASO_MTRS_PER_POOL ]; } +/* +* Get ASO CT action by index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +struct mlx5_aso_ct_pool *pool; + + idx--; +MLX5_ASSERT ((idx /MLX5_ASO_CT_ACTIONS_PER_POOL ) < mng->n); +/* Bit operation AND could be used. */ + pool = mng->pools[idx /MLX5_ASO_CT_ACTIONS_PER_POOL ]; +return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +261 -0
279 lines not on this page · raw message
Signature · 1 line
2.5.5
PATCH 8/17 net/mlx5: close CT management structure
In reply to Bing ZhaoWhen freeing the IB shared context during stopping a device, the ASO connection tracking management structure should also be cleaned up.
All the DR actions created should be destroyed. The structures need to be freed and ASO CT QP should be released. In the meanwhile, the allocated and registered memory region for query should also be deregistered and then freed.
--- drivers/net/mlx5/mlx5.c | 56 ++++++++++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 4 +++ 2 files changed, 60 insertions(+)
drivers/net/mlx5/mlx5.c +56 -0
@@ -706,6 +706,60 @@ mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh)return 0 ; } +/* +* Close and release all the resources of the +* ASO connection tracking management structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object to free. +*/ +static void +mlx5_flow_aso_ct_mng_close (struct mlx5_dev_ctx_shared *sh) +{ +struct mlx5_aso_ct_pools_mng *mng = sh->ct_mng; +struct mlx5_aso_ct_pool *ct_pool; +struct mlx5_aso_ct_action *ct; +uint32_t idx; +uint32_t val; +uint32_t cnt; +int i; + +mlx5_aso_queue_uninit (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); + idx = mng->next; +while (idx--) { + cnt =0 ; + ct_pool = mng->pools[idx]; +for (i =0 ; i <MLX5_ASO_CT_ACTIONS_PER_POOL ; i++) { + ct = &ct_pool->actions[i]; + val =__atomic_sub_fetch (&ct->refcnt,1 , + __ATOMIC_RELAXED); +MLX5_ASSERT (val <=1 ); +if (val >1 ) + cnt++; +#ifdef HAVE_MLX5_DR_ACTION_ASO_CT +if (ct->dr_action_orig) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_orig)); +if (ct->dr_action_rply) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_rply)); +#endif + } +claim_zero (mlx5_devx_cmd_destroy (ct_pool->devx_obj)); +if (cnt) { +DRV_LOG (WARNING ,"%u ASO CT objects are being used in the pool %u" , + cnt, i); + } +mlx5_free (ct_pool); +/* in case of failure. */ + mng->next--; + } +mlx5_free (mng->pools); +mlx5_free (mng); +/* Management structure must be cleared to 0s during allocation. */ + sh->ct_mng =NULL ; +} +/** * Initialize the flow resources' indexed mempool. *
@@ -1238,6 +1292,8 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh) }if (sh->mtrmng)mlx5_aso_flow_mtrs_mng_close (sh); +if (sh->ct_mng) +mlx5_flow_aso_ct_mng_close (sh);mlx5_flow_ipool_destroy (sh);mlx5_os_dev_shared_handler_uninstall (sh);if (sh->cnt_id_tbl) {
drivers/net/mlx5/mlx5_flow_aso.c +4 -0
@@ -393,6 +393,10 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,case ASO_OPC_MOD_POLICER : sq = &sh->mtrmng->pools_mng.sq;break ; +case ASO_OPC_MOD_CONNECTION_TRACKING : +mlx5_aso_devx_dereg_mr (&sh->ct_mng->aso_sq.mr); + sq = &sh->ct_mng->aso_sq; +break ;default :DRV_LOG (ERR ,"Unknown ASO operation mode" );return ;
Signature · 1 line
2.5.5
PATCH 9/17 net/mlx5: add ASO CT query implementation
In reply to Bing ZhaoAfter the connection tracking context is created and being used by the flows, the context will be updated by the HW automatically after a packet passed the CT validation. E.g., the ACK, SEQ, window and state of CT can be updated with both direction traffic.
In order to query the updated contents of this context, a WQE should be posted to the SQ with a return buffer. The data will be filled into the buffer. And the profile will be filled with specific value.
During the execution of query command, the context may be updated. The result of the query command may not be the latest one.
--- drivers/net/mlx5/mlx5.h | 9 +- drivers/net/mlx5/mlx5_flow_aso.c | 205 +++++++++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 10 ++ 3 files changed, 223 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +8 -1
@@ -498,7 +498,10 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; -struct mlx5_aso_ct_action *ct; +struct { +struct mlx5_aso_ct_action *ct; +char *query_data; + }; }; };
@@ -1710,5 +1713,9 @@ int mlx5_aso_ct_update_by_wqe(struct mlx5_dev_ctx_shared *sh, const struct rte_flow_action_conntrack *profile);int mlx5_aso_ct_wait_ready (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct); +int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +struct rte_flow_action_conntrack *profile); +#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow_aso.c +205 -0
224 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +10 -0
@@ -13765,6 +13765,8 @@ flow_dv_action_query(struct rte_eth_dev *dev,uint32_t act_idx = (uint32_t )(uintptr_t )handle;uint32_t type = act_idx >>MLX5_INDIRECT_ACTION_TYPE_OFFSET ;uint32_t idx = act_idx & ((1u <<MLX5_INDIRECT_ACTION_TYPE_OFFSET ) -1 ); +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct;switch (type) {case MLX5_INDIRECT_ACTION_TYPE_AGE :
@@ -13778,6 +13780,14 @@ flow_dv_action_query(struct rte_eth_dev *dev, resp->sec_since_last_hit =__atomic_load_n (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,ENOMEM , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); +return mlx5_aso_ct_query_by_wqe (priv->sh, ct, data);default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.5.5
PATCH 10/17 net/mlx5: add ASO CT destroy handling
In reply to Bing ZhaoWhen trying to destroy an ASO connection tracking context, the DR action created on this context should also be destroyed. Before inserting the related software object into the management free list, the reference count should be checked.
Right now, the context object will not be freed to the system and will be reused directly from the free list.
--- drivers/net/mlx5/mlx5_flow_dv.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/mlx5/mlx5_flow_dv.c +9 -0
@@ -11153,6 +11153,9 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx)#endif ct->dr_action_rply =NULL ; } +/* Clear the state to free, no need in 1st allocation. */ +__atomic_store_n (&ct->state,ASO_CONNTRACK_FREE , + __ATOMIC_RELAXED);rte_spinlock_lock (&mng->ct_sl);LIST_INSERT_HEAD (&mng->free_cts, ct, next);rte_spinlock_unlock (&mng->ct_sl);
@@ -13638,6 +13641,12 @@ flow_dv_action_destroy(struct rte_eth_dev *dev,DRV_LOG (DEBUG ,"Indirect age action %" PRIu32" was" " released with references %d." , idx, ret);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ret =flow_dv_aso_ct_release (dev, idx); +if (ret) +DRV_LOG (DEBUG ,"Connection tracking object %u still " +"has references %d." , idx, ret); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.5.5
PATCH 11/17 net/mlx5: add translation for CT action
In reply to Bing ZhaoWhen creating a flow with this action context for CT, it needs to be translated in 2 levels.
First, retrieve from action context to RTE_FLOW action. Second, translate it to the correct DR action with traffic direction.
Before using the DR action in a flow, the CT context should be available to use in the hardware.
--- drivers/net/mlx5/mlx5.h | 3 ++- drivers/net/mlx5/mlx5_flow.c | 9 +++++++++ drivers/net/mlx5/mlx5_flow.h | 1 + drivers/net/mlx5/mlx5_flow_aso.c | 40 ++++++++++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 18 ++++++++++++++++++ 5 files changed, 70 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +2 -1
@@ -1716,6 +1716,7 @@ int mlx5_aso_ct_wait_ready(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,struct rte_flow_action_conntrack *profile); - +int mlx5_aso_ct_available (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.c +9 -0
@@ -3552,6 +3552,15 @@ flow_action_handles_translate(struct rte_eth_dev *dev,break ; }/* Fall-through */ +case MLX5_INDIRECT_ACTION_TYPE_CT : +if (priv->sh->ct_aso_en) { + translated[handle->index].type = +RTE_FLOW_ACTION_TYPE_CONNTRACK ; + translated[handle->index].conf = + (void *)(uintptr_t )idx; +break ; + } +/* Fall-through */ default :mlx5_free (translated);return rte_flow_error_set
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -226,6 +226,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)#define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40) +#define MLX5_FLOW_ACTION_CT (1ull << 41)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_aso.c +40 -0
@@ -1394,3 +1394,43 @@ mlx5_aso_ct_query_by_wqe(struct mlx5_dev_ctx_shared *sh,mlx5_aso_ct_obj_analyze (profile, out_data);return ret; } + +/* +* Make sure the conntrack context is synchronized with hardware before +* creating a flow rule that uses it. +* +* @param[in] sh +* Pointer to shared device context. +* @param[in] ct +* Pointer to connection tracking offload object. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_aso_ct_available (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct) +{ +struct mlx5_aso_ct_pools_mng *mng = sh->ct_mng; +uint32_t poll_cqe_times =MLX5_CT_POLL_WQE_CQE_TIMES ; +uint8_t state =__atomic_load_n (&ct->state, __ATOMIC_RELAXED); + +if (state ==ASO_CONNTRACK_FREE ) { + rte_errno =ENXIO ; +return -rte_errno; + }else if (state ==ASO_CONNTRACK_READY || + state ==ASO_CONNTRACK_QUERY ) { +return 0 ; + } +do { +mlx5_aso_ct_completion_handle (mng); + state =__atomic_load_n (&ct->state, __ATOMIC_RELAXED); +if (state ==ASO_CONNTRACK_READY || + state ==ASO_CONNTRACK_QUERY ) +return 0 ; +/* Waiting for CQE ready, consider should block or sleep. */ +rte_delay_us_sleep (MLX5_ASO_WQE_CQE_RESPONSE_DELAY ); + }while (--poll_cqe_times); + rte_errno =EBUSY ; +return -rte_errno; +}
drivers/net/mlx5/mlx5_flow_dv.c +18 -0
@@ -11373,6 +11373,7 @@ flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,return rte_flow_error_set (error,EBUSY ,RTE_FLOW_ERROR_TYPE_ACTION ,NULL ,"Failed to update CT" ); + ct->is_original = !!pro->is_original_dir;return idx; }
@@ -11529,6 +11530,8 @@ flow_dv_translate(struct rte_eth_dev *dev,const struct rte_flow_action *found_action =NULL ;uint32_t jump_group =0 ;struct mlx5_flow_counter *cnt; +uint32_t ct_idx; +struct mlx5_aso_ct_action *ct;if (!mlx5_flow_os_action_supported (action_type)) return rte_flow_error_set(error, ENOTSUP,
@@ -12002,6 +12005,21 @@ flow_dv_translate(struct rte_eth_dev *dev,return -rte_errno; action_flags |=MLX5_FLOW_ACTION_MODIFY_FIELD ;break ; +case RTE_FLOW_ACTION_TYPE_CONNTRACK : + ct_idx = (uint32_t )(uintptr_t )action->conf; + ct =flow_aso_ct_get_by_idx (dev, ct_idx); +if (mlx5_aso_ct_available (priv->sh, ct)) +return -rte_errno; +if (ct->is_original) + dev_flow->dv.actions[actions_n] = + ct->dr_action_orig; +else + dev_flow->dv.actions[actions_n] = + ct->dr_action_rply; +__atomic_fetch_add (&ct->refcnt,1 , __ATOMIC_RELAXED); + actions_n++; + action_flags |=MLX5_FLOW_ACTION_CT ; +break ;case RTE_FLOW_ACTION_TYPE_END : actions_end = true;if (mhdr_res->actions_num) {
Signature · 1 line
2.5.5
PATCH 12/17 net/mlx5: add translation of CT item
In reply to Bing ZhaoThe return register of the DR action will be used for matching. After the ASO CT checking of a TCP packet, the syndrome is filled in the register. Only the 8 LSB should be used. A converting from RTE_FLOW_CONNTRACK_FLAG* to the syndrome should be done after checing the spec and mask fields.
--- drivers/net/mlx5/mlx5_flow.h | 7 +++++ drivers/net/mlx5/mlx5_flow_dv.c | 62 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
drivers/net/mlx5/mlx5_flow.h +7 -0
@@ -405,6 +405,13 @@ enum mlx5_feature_name {/* Maximum number of fields to modify in MODIFY_FIELD */ #define MLX5_ACT_MAX_MOD_FIELDS 5 +/* Syndrome bits definition for connection tracking. */ +#define MLX5_CT_SYNDROME_VALID (0x0 << 6) +#define MLX5_CT_SYNDROME_INVALID (0x1 << 6) +#define MLX5_CT_SYNDROME_TRAP (0x2 << 6) +#define MLX5_CT_SYNDROME_STATE_CHANGE (0x1 << 1) +#define MLX5_CT_SYNDROME_BAD_PACKET (0x1 << 0) +enum mlx5_flow_drv_type {MLX5_FLOW_TYPE_MIN ,MLX5_FLOW_TYPE_DV ,
drivers/net/mlx5/mlx5_flow_dv.c +62 -0
74 lines not on this page · raw message
Signature · 1 line
2.5.5
PATCH 13/17 net/mlx5: add CT context update
In reply to Bing ZhaoWhen updating a connection tracking context, two separate parts could be updated.
First, the direction. This will only update the traffic direction recorded in the software for flow creation.
Second, the TCP parameters. The hardware context will be updated via the WQE. This update will be blocked until the hardware status is updated and ready for the next flow creation.
--- drivers/net/mlx5/mlx5_flow_dv.c | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
drivers/net/mlx5/mlx5_flow_dv.c +47 -0
@@ -13801,6 +13801,51 @@ __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,return ret; } +/* +* Updates in place conntrack context or direction. +* Context update should be synchronized. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* The conntrack object ID to be updated. +* @param[in] update +* Pointer to the structure of information to update. +* @param[out] error +* Perform verbose error reporting if not NULL. Initialized in case of +* error only. +* +* @return +* 0 on success, otherwise negative errno value. +*/ +static int +__flow_dv_action_ct_update (struct rte_eth_dev *dev,uint32_t idx, +const struct rte_flow_modify_conntrack *update, +struct rte_flow_error *error) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +const struct rte_flow_action_conntrack *new_prf; +int ret =0 ; + + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,ENOMEM , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + new_prf = &update->new_ct; +if (update->direction) + ct->is_original = !!new_prf->is_original_dir; +if (update->state) { + ret =mlx5_aso_ct_update_by_wqe (priv->sh, ct, new_prf); +/* Block until ready or a failure. */ +if (!ret) + ret =mlx5_aso_ct_available (priv->sh, ct); + } +return ret; +} +/** * Updates in place shared action configuration, lock free, * (mutex should be acquired by caller).
@@ -13836,6 +13881,8 @@ flow_dv_action_update(struct rte_eth_dev *dev,case MLX5_INDIRECT_ACTION_TYPE_RSS : action_conf = ((const struct rte_flow_action *)update)->conf;return __flow_dv_action_rss_update (dev, idx, action_conf, err); +case MLX5_INDIRECT_ACTION_TYPE_CT : +return __flow_dv_action_ct_update (dev, idx, update, err);default : return rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.5.5
PATCH 14/17 net/mlx5: validation of CT action
In reply to Bing ZhaoThe validation of a CT action contains two parts. The first is the CT action configurations parameter. When creating a CT action context, some members need to be verified.
The second is that when creating a flow, the DR action of CT should be validated with other actions and items as well. Currently, only the TCP protocol support connection tracking.
--- drivers/net/mlx5/mlx5.h | 4 +++ drivers/net/mlx5/mlx5_flow.c | 31 +++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 68 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+)
drivers/net/mlx5/mlx5.h +4 -0
@@ -1617,6 +1617,10 @@ int mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow,void mlx5_flow_rxq_dynf_metadata_set (struct rte_eth_dev *dev);int mlx5_flow_get_aged_flows (struct rte_eth_dev *dev,void **contexts,uint32_t nb_contexts,struct rte_flow_error *error); +int mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error); +/* mlx5_mp_os.c */
drivers/net/mlx5/mlx5_flow.c +31 -0
@@ -1687,6 +1687,37 @@ mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,return 0 ; } +/* +* Validate the ASO CT action. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] conntrack +* Pointer to the CT action profile. +* @param[out] error +* Pointer to error structure. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error) +{ +RTE_SET_USED (dev); + +if (conntrack->state >RTE_FLOW_CONNTRACK_STATE_TIME_WAIT ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid CT state" ); +if (conntrack->last_index >RTE_FLOW_CONNTRACK_FLAG_RST ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid last TCP packet flag" ); +return 0 ; +} +/** * Verify the @p attributes will be correctly understood by the NIC and store * them in the @p flow if everything is correct.
drivers/net/mlx5/mlx5_flow_dv.c +68 -0
92 lines not on this page · raw message
Signature · 1 line
2.5.5
PATCH 15/17 net/mlx5: validation of CT item
In reply to Bing ZhaoThe item of ASO connection tracking will be translated into the register value when matching. The validation of this item has no dependency on other layers, since the flow including this item should be jumped from another group. All the layers checking was already done in the previous groups. Only the state bits conflict should be checked.
It is assumed that the flow with CT item will always work on the TCP traffic.
--- drivers/net/mlx5/mlx5_flow.h | 3 +++ drivers/net/mlx5/mlx5_flow_dv.c | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+)
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -147,6 +147,9 @@ enum mlx5_feature_name {#define MLX5_FLOW_LAYER_GENEVE_OPT (UINT64_C(1) << 32)#define MLX5_FLOW_LAYER_GTP_PSC (UINT64_C(1) << 33) +/* Conntrack item. */ +#define MLX5_FLOW_LAYER_ASO_CT (UINT64_C(1) << 34) +/* Outer Masks. */ #define MLX5_FLOW_LAYER_OUTER_L3 \ (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6)
drivers/net/mlx5/mlx5_flow_dv.c +52 -0
64 lines not on this page · raw message
Signature · 1 line
2.5.5
PATCH 16/17 net/mlx5: reduce the reference count of CT
In reply to Bing ZhaoIn order to release the DR actions and reuse the context of a CT, the reference count should be handled correctly, especially in the flow destroying.
The CT index will be recorded in the rte_flow by reusing the age index. The action context type should be saved for CT also. When destroying a flow, if the context type is CT and the index valid. The release process should be handled.
By default, the handling will fall back to release the age.
--- drivers/net/mlx5/mlx5_flow.h | 6 +++++- drivers/net/mlx5/mlx5_flow_dv.c | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5_flow.h +5 -1
@@ -977,11 +977,15 @@ struct rte_flow { uint32_t drv_type:2; /**< Driver type. */ uint32_t tunnel:1; uint32_t meter:24; /**< Holds flow meter id. */ + uint32_t indirect_type:2; /**< Indirect action type. */uint32_t rix_mreg_copy;/**< Index to metadata register copy table resource. */ uint32_t counter;/**< Holds flow counter. */ uint32_t tunnel_id;/**< Tunnel id */ -uint32_t age;/**< Holds ASO age bit index. */ +union { +uint32_t age;/**< Holds ASO age bit index. */ +uint32_t ct;/**< Holds ASO CT index. */ + };uint32_t geneve_tlv_option;/**< Holds Geneve TLV option id. > */ } __rte_packed;
drivers/net/mlx5/mlx5_flow_dv.c +6 -1
@@ -12185,6 +12185,8 @@ flow_dv_translate(struct rte_eth_dev *dev,else dev_flow->dv.actions[actions_n] = ct->dr_action_rply; + flow->indirect_type =MLX5_INDIRECT_ACTION_TYPE_CT ; + flow->ct = ct_idx;__atomic_fetch_add (&ct->refcnt,1 , __ATOMIC_RELAXED); actions_n++; action_flags |=MLX5_FLOW_ACTION_CT ;
@@ -13328,7 +13330,10 @@ flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)mlx5_flow_meter_detach (priv, fm); flow->meter =0 ; } -if (flow->age) +/* Keep the current age handling by default. */ +if (flow->indirect_type ==MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct) +flow_dv_aso_ct_release (dev, flow->ct); +else if (flow->age)flow_dv_aso_age_release (dev, flow->age);if (flow->geneve_tlv_option) {flow_dv_geneve_tlv_option_resource_release (dev);
Signature · 1 line
2.5.5
PATCH 17/17 net/mlx5: add support of CT between two ports
In reply to Bing ZhaoAfter creating a connection tracking context, it could be used between two ports. For each port, the flow for one direction traffic will be created.
The context can only be shared between the owner port and the peer port that specified when creating. Only the owner port could update the context or query it right now.
--- drivers/net/mlx5/mlx5_flow.h | 57 ++++++++++++++++++++++++++++++++-- drivers/net/mlx5/mlx5_flow_dv.c | 69 +++++++++++++++++++++++++++++++---------- 2 files changed, 108 insertions(+), 18 deletions(-)
drivers/net/mlx5/mlx5_flow.h +55 -2
@@ -48,6 +48,25 @@ enum { MLX5_INDIRECT_ACTION_TYPE_CT, }; +/* Now, the maximal ports will be supported is 256, action number is 4M. */ +#define MLX5_INDIRECT_ACT_CT_MAX_PORT 0x100 + +#define MLX5_INDIRECT_ACT_CT_OWNER_SHIFT 22 +#define MLX5_INDIRECT_ACT_CT_OWNER_MASK (MLX5_INDIRECT_ACT_CT_MAX_PORT - 1) + +/* 30-31: type, 22-29: owner port, 0-21: index. */ +#define MLX5_INDIRECT_ACT_CT_GEN_IDX (owner, index) \ + ((MLX5_INDIRECT_ACTION_TYPE_CT << MLX5_INDIRECT_ACTION_TYPE_OFFSET) | \ + (((owner) & MLX5_INDIRECT_ACT_CT_OWNER_MASK) << \ + MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) | (index)) + +#define MLX5_INDIRECT_ACT_CT_GET_OWNER (index) \ + (((index) >> MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) & \ + MLX5_INDIRECT_ACT_CT_OWNER_MASK) + +#define MLX5_INDIRECT_ACT_CT_GET_IDX (index) \ + ((index) & ((1 << MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) - 1)) +/* Matches on selected register. */ struct mlx5_rte_flow_item_tag {enum modify_reg id;
@@ -1302,7 +1321,7 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx) }/* -* Get ASO CT action by index. +* Get ASO CT action by device and index. * * @param[in] dev * Pointer to the Ethernet device structure.
@@ -1313,7 +1332,7 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)* The specified ASO CT action pointer. */ static inline struct mlx5_aso_ct_action * -flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +flow_aso_ct_get_by_dev_idx (struct rte_eth_dev *dev,uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
@@ -1326,6 +1345,40 @@ flow_aso_ct_get_by_idx(struct rte_eth_dev *dev, uint32_t idx)return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; } +/* +* Get ASO CT action by owner & index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action and owner port combination. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t own_idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +uint16_t owner = (uint16_t )MLX5_INDIRECT_ACT_CT_GET_OWNER (own_idx); +uint32_t idx =MLX5_INDIRECT_ACT_CT_GET_IDX (own_idx); + +if (owner ==PORT_ID (priv)) { + ct =flow_aso_ct_get_by_dev_idx (dev, idx); + }else { +struct rte_eth_dev *owndev = &rte_eth_devices[owner]; + +MLX5_ASSERT (owner <RTE_MAX_ETHPORTS ); +if (dev->data->dev_started !=1 ) +return NULL ; + ct =flow_aso_ct_get_by_dev_idx (owndev, idx); +if (ct->peer !=PORT_ID (priv)) +return NULL ; + } +return ct; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +53 -16
162 lines not on this page · raw message
Signature · 1 line
2.5.5
v2 cover conntrack support in mlx5 PMD
In reply to Bing ZhaoThis patch set adds the connection tracking offload support in the mlx5 driver, as well as the documents update.
---
v2: code bug fixes, commits clean up and doc update.
---
Bing Zhao (17):
common/mlx5: add connection tracking object definition common/mlx5: add CT offload capability checking net/mlx5: use meter color reg for CT net/mlx5: initialization of CT management common/mlx5: add Dexv CT objects creation net/mlx5: add modify support for CT
net/mlx5: add actions creating for CT net/mlx5: close CT management structure net/mlx5: add ASO CT query implementation net/mlx5: add ASO CT destroy handling net/mlx5: add translation of CT action net/mlx5: add translation of CT item net/mlx5: add CT context update
net/mlx5: validation of CT action
net/mlx5: validation of CT item
net/mlx5: add support of CT between two ports
doc: update mlx5 support for conntrack
doc/guides/nics/features/default.ini | 1 + doc/guides/nics/features/mlx5.ini | 1 + doc/guides/nics/mlx5.rst | 14 + doc/guides/rel_notes/release_21_05.rst | 2 + drivers/common/mlx5/linux/meson.build | 2 + drivers/common/mlx5/mlx5_devx_cmds.c | 53 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 5 + drivers/common/mlx5/mlx5_prm.h | 88 ++++ drivers/common/mlx5/version.map | 1 + drivers/net/mlx5/linux/mlx5_os.c | 13 + drivers/net/mlx5/mlx5.c | 92 ++++ drivers/net/mlx5/mlx5.h | 76 ++++ drivers/net/mlx5/mlx5_flow.c | 44 +- drivers/net/mlx5/mlx5_flow.h | 101 ++++- drivers/net/mlx5/mlx5_flow_aso.c | 592 ++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 601 ++++++++++++++++++++++++- 16 files changed, 1683 insertions(+), 3 deletions(-)
Signature · 1 line
2.27.0
PATCH v2 1/17 common/mlx5: add connection tracking object definition
The structures of ASO connection tracking offload object are added based on the definitions in the PRM. One CT object context will be loaded into the cache completely in a reversed order of dwords. The valid bit should be the MSB of the last dword. This is used for the conntrack context creation and update, as well as for the query.
The capabilities 2 (HCA_CAP_2) layout is also added. The connection tracking related capabilities could be queried via the HCA_CAP_2.
--- drivers/common/mlx5/mlx5_prm.h | 85 ++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
drivers/common/mlx5/mlx5_prm.h +85 -0
@@ -1119,6 +1119,7 @@ enum {MLX5_GET_HCA_CAP_OP_MOD_ROCE =0x4 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE =0x7 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_VDPA_EMULATION =0x13 <<1 , + MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE_2 = 0x20 << 1, };#define MLX5_GENERAL_OBJ_TYPES_CAP_VIRTQ_NET_Q \
@@ -1661,6 +1662,29 @@ struct mlx5_ifc_flow_table_nic_cap_bits {struct mlx5_ifc_flow_table_prop_layout_bits flow_table_properties; }; +struct mlx5_ifc_cmd_hca_cap_2_bits { +u8 reserved_at_0[0x80 ];/* End of DW4. */ +u8 reserved_at_80[0xb ]; +u8 log_max_num_reserved_qpn[0x5 ]; +u8 reserved_at_90[0x3 ]; +u8 log_reserved_qpn_granularity[0x5 ]; +u8 reserved_at_98[0x3 ]; +u8 log_reserved_qpn_max_alloc[0x5 ];/* End of DW5. */ +u8 max_reformat_insert_size[0x8 ]; +u8 max_reformat_insert_offset[0x8 ]; +u8 max_reformat_remove_size[0x8 ]; +u8 max_reformat_remove_offset[0x8 ];/* End of DW6. */ +u8 aso_conntrack_reg_id[0x8 ]; +u8 reserved_at_c8[0x3 ]; +u8 log_conn_track_granularity[0x5 ]; +u8 reserved_at_d0[0x3 ]; +u8 log_conn_track_max_alloc[0x5 ]; +u8 reserved_at_d8[0x3 ]; +u8 log_max_conn_track_offload[0x5 ]; +u8 reserved_at_e0[0x20 ];/* End of DW7. */ +u8 reserved_at_100[0x700 ]; +}; +union mlx5_ifc_hca_cap_union_bits {struct mlx5_ifc_cmd_hca_cap_bits cmd_hca_cap;struct mlx5_ifc_per_protocol_networking_offload_caps_bits
@@ -2599,6 +2623,67 @@ struct mlx5_ifc_create_flow_meter_aso_in_bits {struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr;struct mlx5_ifc_flow_meter_aso_bits flow_meter_aso; }; + +struct mlx5_ifc_tcp_window_params_bits { +u8 max_ack[0x20 ]; +u8 max_win[0x20 ]; +u8 reply_end[0x20 ]; +u8 sent_end[0x20 ]; +}; + +struct mlx5_ifc_conn_track_aso_bits { +struct mlx5_ifc_tcp_window_params_bits reply_dir;/* End of DW3. */ +struct mlx5_ifc_tcp_window_params_bits original_dir;/* End of DW7. */ +u8 last_end[0x20 ];/* End of DW8. */ +u8 last_ack[0x20 ];/* End of DW9. */ +u8 last_seq[0x20 ];/* End of DW10. */ +u8 last_win[0x10 ]; +u8 reserved_at_170[0xa ]; +u8 last_dir[0x1 ]; +u8 last_index[0x5 ];/* End of DW11. */ +u8 reserved_at_180[0x40 ];/* End of DW13. */ +u8 reply_direction_tcp_scale[0x4 ]; +u8 reply_direction_tcp_close_initiated[0x1 ]; +u8 reply_direction_tcp_liberal_enabled[0x1 ]; +u8 reply_direction_tcp_data_unacked[0x1 ]; +u8 reply_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1c8[0x8 ]; +u8 original_direction_tcp_scale[0x4 ]; +u8 original_direction_tcp_close_initiated[0x1 ]; +u8 original_direction_tcp_liberal_enabled[0x1 ]; +u8 original_direction_tcp_data_unacked[0x1 ]; +u8 original_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1d8[0x8 ];/* End of DW14. */ +u8 valid[0x1 ]; +u8 state[0x3 ]; +u8 freeze_track[0x1 ]; +u8 reserved_at_1e5[0xb ]; +u8 reserved_at_1f0[0x1 ]; +u8 connection_assured[0x1 ]; +u8 sack_permitted[0x1 ]; +u8 challenged_acked[0x1 ]; +u8 heartbeat[0x1 ]; +u8 max_ack_window[0x3 ]; +u8 reserved_at_1f8[0x1 ]; +u8 retransmission_counter[0x3 ]; +u8 retranmission_limit_exceeded[0x1 ]; +u8 retranmission_limit[0x3 ];/* End of DW15. */ +}; + +struct mlx5_ifc_conn_track_offload_bits { +u8 modify_field_select[0x40 ]; +u8 reserved_at_40[0x40 ]; +u8 reserved_at_80[0x8 ]; +u8 conn_track_aso_access_pd[0x18 ]; +u8 reserved_at_a0[0x160 ]; +struct mlx5_ifc_conn_track_aso_bits conn_track_aso; +}; + +struct mlx5_ifc_create_conn_track_aso_in_bits { +struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr; +struct mlx5_ifc_conn_track_offload_bits conn_track_offload; +}; +enum mlx5_access_aso_opc_mod {ASO_OPC_MOD_IPSEC =0x0 ,ASO_OPC_MOD_CONNECTION_TRACKING =0x1 ,
Signature · 1 line
2.27.0
PATCH v2 2/17 common/mlx5: add CT offload capability checking
In reply to Bing ZhaoDuring startup, the ASO connection tracking offload capability could be queried via HCA_CAP_QUERY command. If the HW doesn't support ASO CT, the value would be 0 by default. The following initialization should be skipped and the creation of the CT object should return a failure directly.
The following CT creation should also check this capability. With the old driver, the pre-processing macro should be used in order to make the compiling pass.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/mlx5_devx_cmds.c | 3 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 3 +++ 4 files changed, 9 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -189,6 +189,8 @@ has_sym_args = [ 'MLX5_WQE_UMR_CTRL_FLAG_INLINE' ], [ 'HAVE_MLX5_DR_FLOW_DUMP_RULE', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_rule' ], + [ 'HAVE_MLX5_DR_ACTION_ASO_CT', 'infiniband/mlx5dv.h', + 'MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR' ], ] config = configuration_data() foreach arg:has_sym_args
drivers/common/mlx5/mlx5_devx_cmds.c +3 -0
@@ -760,6 +760,9 @@ mlx5_devx_cmd_query_hca_attr(void *ctx,MLX5_GET (cmd_hca_cap, hcattr, umr_indirect_mkey_disabled); attr->umr_modify_entity_size_disabled =MLX5_GET (cmd_hca_cap, hcattr, umr_modify_entity_size_disabled); + attr->ct_offload = !!(MLX5_GET64 (cmd_hca_cap, hcattr, + general_obj_types) & +MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD );if (attr->qos.sup) { MLX5_SET(query_hca_cap_in, in, op_mod, MLX5_GET_HCA_CAP_OP_MOD_QOS_CAP |
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -137,6 +137,7 @@ struct mlx5_hca_attr { uint32_t qp_ts_format:2; uint32_t regex:1; uint32_t reg_c_preserve:1; + uint32_t ct_offload:1; /* General obj type ASO CT offload supported. */uint32_t regexp_num_of_engines; uint32_t log_max_ft_sampler_num:8;uint32_t geneve_tlv_opt;
drivers/common/mlx5/mlx5_prm.h +3 -0
@@ -1134,6 +1134,8 @@ enum { (1ULL << MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO)#define MLX5_GENERAL_OBJ_TYPES_CAP_GENEVE_TLV_OPT \ (1ULL << MLX5_OBJ_TYPE_GENEVE_TLV_OPT) +#define MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD \ + (1ULL << MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD)enum {MLX5_HCA_CAP_OPMOD_GET_MAX =0 ,
@@ -2456,6 +2458,7 @@ enum {MLX5_GENERAL_OBJ_TYPE_FLEX_PARSE_GRAPH =0x0022 ,MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO =0x0024 ,MLX5_GENERAL_OBJ_TYPE_FLOW_HIT_ASO =0x0025 , + MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD = 0x0031, }; struct mlx5_ifc_general_obj_in_cmd_hdr_bits {
Signature · 1 line
2.27.0
PATCH v2 3/17 net/mlx5: use meter color reg for CT
In reply to Bing ZhaoBased on the capacity, 3 registers could be used. Due to the register allocation, only the one REG_C_3 for meter color could be reused right now.
Then in the same flow, no more than one ASO action can be supported.
--- drivers/net/mlx5/mlx5_flow.c | 4 +++- drivers/net/mlx5/mlx5_flow.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow.c +3 -1
@@ -760,7 +760,9 @@ mlx5_flow_get_reg_id(struct rte_eth_dev *dev,return priv->mtr_color_reg !=REG_C_2 ?REG_C_2 :REG_C_3 ;case MLX5_MTR_COLOR : -case MLX5_ASO_FLOW_HIT :/* Both features use the same REG_C. */ +case MLX5_ASO_FLOW_HIT : +case MLX5_ASO_CONNTRACK : +/* All features use the same REG_C. */ MLX5_ASSERT (priv->mtr_color_reg !=REG_NON );return priv->mtr_color_reg;case MLX5_COPY_MARK :
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -84,6 +84,7 @@ enum mlx5_feature_name {MLX5_MTR_COLOR ,MLX5_MTR_ID ,MLX5_ASO_FLOW_HIT , + MLX5_ASO_CONNTRACK, };/* Default queue number. */
Signature · 1 line
2.27.0
PATCH v2 4/17 net/mlx5: initialization of CT management
In reply to Bing ZhaoThe definitions of ASO connection tracking objects management structures are added.
Considering performance, the bulk allocation of ASO CT objects should be used. The maximal value per bulk and the granularity could be fetched from HCA capabilities 2. Right now, a fixed number of 64 is used for each bulk for a better management purpose.
The ASO QP for CT is initialized, the SQ will be used for both modify and query command.
--- drivers/net/mlx5/linux/mlx5_os.c | 13 +++++++++ drivers/net/mlx5/mlx5.c | 36 +++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 50 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 50 ++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +13 -0
@@ -1323,6 +1323,19 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,DRV_LOG (DEBUG ,"Flow Hit ASO is supported." ); }#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */ +#if defined(HAVE_MLX5_DR_CREATE_ACTION_ASO ) && \ + defined(HAVE_MLX5_DR_ACTION_ASO_CT ) +if (config->hca_attr.ct_offload && + priv->mtr_color_reg ==REG_C_3 ) { + err =mlx5_flow_aso_ct_mng_init (sh); +if (err) { + err = -err; + goto error; + } +DRV_LOG (DEBUG ,"CT ASO is supported." ); + sh->ct_aso_en =1 ; + } +#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO && HAVE_MLX5_DR_ACTION_ASO_CT */ #if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE )if (config->hca_attr.log_max_ft_sampler_num >0 && config->dv_flow_en) {
drivers/net/mlx5/mlx5.c +36 -0
@@ -670,6 +670,42 @@ mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh) } } +/* +* Initialize the ASO connection tracking structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_flow_aso_ct_mng_init (struct mlx5_dev_ctx_shared *sh) +{ +int err; + +if (sh->ct_mng) +return 0 ; + sh->ct_mng =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*sh->ct_mng), +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +if (!sh->ct_mng) { +DRV_LOG (ERR ,"ASO CT management allocation failed." ); + rte_errno =ENOMEM ; +return -rte_errno; + } + err =mlx5_aso_queue_init (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); +if (err) { +mlx5_free (sh->ct_mng); +/* rte_errno should be extracted from the failure. */ + rte_errno =EINVAL ; +return -rte_errno; + } +rte_spinlock_init (&sh->ct_mng->ct_sl); +rte_rwlock_init (&sh->ct_mng->resize_rwl); +LIST_INIT (&sh->ct_mng->free_cts); +return 0 ; +} +/** * Initialize the flow resources' indexed mempool. *
drivers/net/mlx5/mlx5.h +50 -0
74 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_aso.c +50 -0
62 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v2 5/17 common/mlx5: add Dexv CT objects creation
In reply to Bing ZhaoAdding support for connection tracking ASO creation via Devx command. Right now only bulk creation is supported.
By default, the objects with zero contents will be created. Before using a single object, the modification via posting a WQE to the ASO CT SQ is needed.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 50 ++++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 4 +++ drivers/common/mlx5/version.map | 1 + 3 files changed, 55 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +50 -0
@@ -2232,6 +2232,56 @@ mlx5_devx_cmd_create_flow_meter_aso_obj(void *ctx, uint32_t pd,return flow_meter_aso_obj; } +/* +* Create general object of type CONN_TRACK_OFFLOAD using DevX API. +* +* @param[in] ctx +* Context returned from mlx5 open_device() glue function. +* @param [in] pd +* PD value to associate the CONN_TRACK_OFFLOAD ASO object with. +* @param [in] log_obj_size +* log_obj_size to allocate its power of 2 * objects +* in one CONN_TRACK_OFFLOAD bulk allocation. +* +* @return +* The DevX object created, NULL otherwise and rte_errno is set. +*/ +struct mlx5_devx_obj * +mlx5_devx_cmd_create_conn_track_offload_obj (void *ctx,uint32_t pd, +uint32_t log_obj_size) +{ +uint32_t in[MLX5_ST_SZ_DW (create_conn_track_aso_in)] = {0 }; +uint32_t out[MLX5_ST_SZ_DW (general_obj_out_cmd_hdr)]; +struct mlx5_devx_obj *ct_aso_obj; +void *ptr; + + ct_aso_obj =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*ct_aso_obj), +0 ,SOCKET_ID_ANY ); +if (!ct_aso_obj) { +DRV_LOG (ERR ,"Failed to allocate CONN_TRACK_OFFLOAD object." ); + rte_errno =ENOMEM ; +return NULL ; + } + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, hdr); +MLX5_SET (general_obj_in_cmd_hdr, ptr, opcode, +MLX5_CMD_OP_CREATE_GENERAL_OBJECT ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, obj_type, +MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, log_obj_range, log_obj_size); + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, conn_track_offload); +MLX5_SET (conn_track_offload, ptr, conn_track_aso_access_pd, pd); + ct_aso_obj->obj = mlx5_glue->devx_obj_create (ctx, in,sizeof (in), + out,sizeof (out)); +if (!ct_aso_obj->obj) { + rte_errno = errno; +DRV_LOG (ERR ,"Failed to create CONN_TRACK_OFFLOAD obj by using DevX." ); +mlx5_free (ct_aso_obj); +return NULL ; + } + ct_aso_obj->id =MLX5_GET (general_obj_out_cmd_hdr, out, obj_id); +return ct_aso_obj; +} +/** * Create general object of type GENEVE TLV option using DevX API. *
drivers/common/mlx5/mlx5_devx_cmds.h +4 -0
@@ -569,6 +569,10 @@ struct mlx5_devx_obj *mlx5_devx_cmd_queue_counter_alloc(void *ctx);__rte_internal int mlx5_devx_cmd_queue_counter_query(struct mlx5_devx_obj *dcs, int clear,uint32_t *out_of_buffers); +__rte_internal +struct mlx5_devx_obj *mlx5_devx_cmd_create_conn_track_offload_obj(void *ctx, +uint32_t pd,uint32_t log_obj_size); +/** * Create general object of type FLOW_METER_ASO using DevX API.. *
drivers/common/mlx5/version.map +1 -0
@@ -13,6 +13,7 @@ INTERNAL { mlx5_dev_to_pci_addr; # WINDOWS_NO_EXPORT mlx5_devx_cmd_alloc_pd; + mlx5_devx_cmd_create_conn_track_offload_obj; mlx5_devx_cmd_create_cq; mlx5_devx_cmd_create_flex_parser; mlx5_devx_cmd_create_qp;
Signature · 1 line
2.27.0
PATCH v2 6/17 net/mlx5: add modify support for CT
In reply to Bing ZhaoAfter the connection tracking object bulk is allocated, all the objects' contents are filled with zero by default. Every new-allocated object must be modified via WQE operation before it is used.
In order to reduce the latency for the flow creation, an asynchronous way is used instead of busy waiting for the CQE to be generated.
--- drivers/net/mlx5/mlx5.h | 8 + drivers/net/mlx5/mlx5_flow.h | 3 + drivers/net/mlx5/mlx5_flow_aso.c | 252 +++++++++++++++++++++++++++++++ 3 files changed, 263 insertions(+)
drivers/net/mlx5/mlx5.h +8 -0
@@ -490,6 +490,7 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; +struct mlx5_aso_ct_action *ct; }; };
@@ -1007,6 +1008,10 @@ struct mlx5_aso_ct_action {bool is_original;/* The direction of the DR action to be used. */ }; +/* CT action object state update. */ +#define MLX5_ASO_CT_UPDATE_STATE (c, s) \ + __atomic_store_n(&((c)->state), (s), __ATOMIC_RELAXED) +/* ASO connection tracking software pool definition. */ struct mlx5_aso_ct_pool {uint16_t index;/* Pool index in pools array. */
@@ -1690,5 +1695,8 @@ int mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh, struct mlx5_aso_mtr *mtr);int mlx5_aso_mtr_wait (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_mtr *mtr); +int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +const struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -45,6 +45,7 @@ enum mlx5_rte_flow_action_type {enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE , +MLX5_INDIRECT_ACTION_TYPE_AGE , };/* Matches on selected register. */
@@ -839,6 +840,8 @@ struct mlx5_flow {#define MLX5_ASO_WQE_CQE_RESPONSE_DELAY 10u#define MLX5_MTR_POLL_WQE_CQE_TIMES 100000u +#define MLX5_CT_POLL_WQE_CQE_TIMES MLX5_MTR_POLL_WQE_CQE_TIMES +#define MLX5_MAN_WIDTH 8/* Legacy Meter parameter structure. */ struct mlx5_legacy_flow_meter {
drivers/net/mlx5/mlx5_flow_aso.c +252 -0
255 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v2 7/17 net/mlx5: add actions creating for CT
In reply to Bing ZhaoAllocating a CT from the management pools and creating the DR actions for both directions by default.
If there is no available connection tracking action, a new pool will be created with a fixed size bulk allocation. Right now, all the resources are controlled by the linked list.
The ASO connection tracking context associated with these actions need to be updated via WQE before using for steering.
--- drivers/net/mlx5/mlx5.h | 4 + drivers/net/mlx5/mlx5_flow.h | 29 +++- drivers/net/mlx5/mlx5_flow_dv.c | 263 ++++++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +4 -0
@@ -987,6 +987,10 @@ struct mlx5_bond_info {/* Number of connection tracking objects per pool: must be a power of 2. */ #define MLX5_ASO_CT_ACTIONS_PER_POOL 64 +/* Generate incremental and unique CT index from pool and offset. */ +#define MLX5_MAKE_CT_IDX (pool, offset) \ + ((pool) * MLX5_ASO_CT_ACTIONS_PER_POOL + (offset) + 1) +/* ASO Conntrack state. */ enum mlx5_aso_ct_state {ASO_CONNTRACK_FREE ,/* Inactive, in the free list. */
drivers/net/mlx5/mlx5_flow.h +28 -1
@@ -45,7 +45,7 @@ enum mlx5_rte_flow_action_type {enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE , -MLX5_INDIRECT_ACTION_TYPE_AGE , +MLX5_INDIRECT_ACTION_TYPE_CT , };/* Matches on selected register. */
@@ -1288,6 +1288,33 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)return &pool->mtrs[idx %MLX5_ASO_MTRS_PER_POOL ]; } +/* +* Get ASO CT action by index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +struct mlx5_aso_ct_pool *pool; + + idx--; +MLX5_ASSERT ((idx /MLX5_ASO_CT_ACTIONS_PER_POOL ) < mng->n); +/* Bit operation AND could be used. */ +rte_rwlock_read_lock (&mng->resize_rwl); + pool = mng->pools[idx /MLX5_ASO_CT_ACTIONS_PER_POOL ]; +rte_rwlock_read_unlock (&mng->resize_rwl); +return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +263 -0
281 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v2 8/17 net/mlx5: close CT management structure
In reply to Bing ZhaoWhen freeing the IB shared context during stopping a device, the ASO connection tracking management structure should also be cleaned up.
All the DR actions created should be destroyed. The structures need to be freed and ASO CT QP should be released. In the meanwhile, the allocated and registered memory region for query should also be deregistered and then freed.
--- drivers/net/mlx5/mlx5.c | 56 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 4 +++ 2 files changed, 60 insertions(+)
drivers/net/mlx5/mlx5.c +56 -0
@@ -706,6 +706,60 @@ mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh)return 0 ; } +/* +* Close and release all the resources of the +* ASO connection tracking management structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object to free. +*/ +static void +mlx5_flow_aso_ct_mng_close (struct mlx5_dev_ctx_shared *sh) +{ +struct mlx5_aso_ct_pools_mng *mng = sh->ct_mng; +struct mlx5_aso_ct_pool *ct_pool; +struct mlx5_aso_ct_action *ct; +uint32_t idx; +uint32_t val; +uint32_t cnt; +int i; + +mlx5_aso_queue_uninit (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); + idx = mng->next; +while (idx--) { + cnt =0 ; + ct_pool = mng->pools[idx]; +for (i =0 ; i <MLX5_ASO_CT_ACTIONS_PER_POOL ; i++) { + ct = &ct_pool->actions[i]; + val =__atomic_fetch_sub (&ct->refcnt,1 , + __ATOMIC_RELAXED); +MLX5_ASSERT (val ==1 ); +if (val >1 ) + cnt++; +#ifdef HAVE_MLX5_DR_ACTION_ASO_CT +if (ct->dr_action_orig) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_orig)); +if (ct->dr_action_rply) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_rply)); +#endif + } +claim_zero (mlx5_devx_cmd_destroy (ct_pool->devx_obj)); +if (cnt) { +DRV_LOG (DEBUG ,"%u ASO CT objects are being used in the pool %u" , + cnt, i); + } +mlx5_free (ct_pool); +/* in case of failure. */ + mng->next--; + } +mlx5_free (mng->pools); +mlx5_free (mng); +/* Management structure must be cleared to 0s during allocation. */ + sh->ct_mng =NULL ; +} +/** * Initialize the flow resources' indexed mempool. *
@@ -1508,6 +1562,8 @@ mlx5_dev_close(struct rte_eth_dev *dev)if (priv->mreg_cp_tbl)mlx5_hlist_destroy (priv->mreg_cp_tbl);mlx5_mprq_free_mp (dev); +if (priv->sh->ct_mng) +mlx5_flow_aso_ct_mng_close (priv->sh);mlx5_os_free_shared_dr (priv);if (priv->rss_conf.rss_key !=NULL )mlx5_free (priv->rss_conf.rss_key);
drivers/net/mlx5/mlx5_flow_aso.c +4 -0
@@ -372,6 +372,10 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,case ASO_OPC_MOD_POLICER : sq = &sh->mtrmng->pools_mng.sq;break ; +case ASO_OPC_MOD_CONNECTION_TRACKING : +mlx5_aso_dereg_mr (sh, &sh->ct_mng->aso_sq.mr); + sq = &sh->ct_mng->aso_sq; +break ;default :DRV_LOG (ERR ,"Unknown ASO operation mode" );return ;
Signature · 1 line
2.27.0
PATCH v2 9/17 net/mlx5: add ASO CT query implementation
In reply to Bing ZhaoAfter the connection tracking context is created and being used by the flows, the context will be updated by the HW automatically after a packet passed the CT validation. E.g., the ACK, SEQ, window and state of CT can be updated with both direction traffic.
In order to query the updated contents of this context, a WQE should be posted to the SQ with a return buffer. The data will be filled into the buffer. And the profile will be filled with specific value.
During the execution of query command, the context may be updated. The result of the query command may not be the latest one.
--- drivers/net/mlx5/mlx5.h | 10 +- drivers/net/mlx5/mlx5_flow_aso.c | 245 +++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 19 +++ 3 files changed, 273 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +9 -1
@@ -490,7 +490,10 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; -struct mlx5_aso_ct_action *ct; +struct { +struct mlx5_aso_ct_action *ct; +char *query_data; + }; }; };
@@ -1702,5 +1705,10 @@ int mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,const struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_wait_ready (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct); +int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow_aso.c +245 -0
263 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +19 -0
@@ -13775,6 +13775,8 @@ flow_dv_action_query(struct rte_eth_dev *dev,uint32_t act_idx = (uint32_t )(uintptr_t )handle;uint32_t type = act_idx >>MLX5_INDIRECT_ACTION_TYPE_OFFSET ;uint32_t idx = act_idx & ((1u <<MLX5_INDIRECT_ACTION_TYPE_OFFSET ) -1 ); +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct;switch (type) {case MLX5_INDIRECT_ACTION_TYPE_AGE :
@@ -13788,6 +13790,23 @@ flow_dv_action_query(struct rte_eth_dev *dev, resp->sec_since_last_hit =__atomic_load_n (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,EFAULT , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + ((struct rte_flow_action_conntrack *)data)->peer_port = + ct->peer; + ((struct rte_flow_action_conntrack *)data)->is_original_dir = + ct->is_original; +if (mlx5_aso_ct_query_by_wqe (priv->sh, ct, data)) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to query CT context" ); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v2 10/17 net/mlx5: add ASO CT destroy handling
In reply to Bing ZhaoWhen trying to destroy an ASO connection tracking context, the DR action created on this context should also be destroyed. Before inserting the related software object into the management free list, the reference count should be checked.
Right now, the context object will not be freed to the system and will be reused directly from the free list.
--- drivers/net/mlx5/mlx5_flow_dv.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +15 -1
@@ -11136,9 +11136,15 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +uint32_t ret;struct mlx5_aso_ct_action *ct =flow_aso_ct_get_by_idx (dev, idx); -uint32_t ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED); +enum mlx5_aso_ct_state state = +__atomic_load_n (&ct->state, __ATOMIC_RELAXED); +/* Cannot release when CT is in the ASO SQ. */ +if (state ==ASO_CONNTRACK_WAIT || state ==ASO_CONNTRACK_QUERY ) +return -1 ; + ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED);if (!ret) {if (ct->dr_action_orig) {#ifdef HAVE_MLX5_DR_ACTION_ASO_CT
@@ -11154,6 +11160,8 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx)#endif ct->dr_action_rply =NULL ; } +/* Clear the state to free, no need in 1st allocation. */ +MLX5_ASO_CT_UPDATE_STATE (ct,ASO_CONNTRACK_FREE );rte_spinlock_lock (&mng->ct_sl);LIST_INSERT_HEAD (&mng->free_cts, ct, next);rte_spinlock_unlock (&mng->ct_sl);
@@ -13648,6 +13656,12 @@ flow_dv_action_destroy(struct rte_eth_dev *dev,DRV_LOG (DEBUG ,"Indirect age action %" PRIu32" was" " released with references %d." , idx, ret);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ret =flow_dv_aso_ct_release (dev, idx); +if (ret) +DRV_LOG (DEBUG ,"Connection tracking object %u still " +"has references %d." , idx, ret); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v2 11/17 net/mlx5: add translation of CT action
In reply to Bing ZhaoWhen creating a flow with this action context for CT, it needs to be translated in 2 levels.
First, retrieve from action context to rte_flow action. Second, translate it to the corresponding DR action with traffic direction that was specified when creating or updating via rte_flow_action_handle* API.
Before using the DR action in a flow, the CT context should be available to use in the hardware. A synchronization is done before inserting the flow rule with CT action to check the HW availability of this CT context.
In order to release the DR actions and reuse the context of a CT, the reference count should also be handled in the the flow destroying.
The CT index will be recorded in the rte_flow by reusing the ASO age index to save memory, since only one ASO action is supported in one flow rule currently. The action context type should also be saved for CT. When destroying a flow rule, if the context type is CT and the index is valid (non-zero), the release process should be handled. By default, the handling will fall back to try to release the ASO age if any.
--- drivers/net/mlx5/mlx5.h | 2 ++ drivers/net/mlx5/mlx5_flow.c | 9 +++++++ drivers/net/mlx5/mlx5_flow.h | 7 +++++- drivers/net/mlx5/mlx5_flow_aso.c | 41 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 28 +++++++++++++++++++++- 5 files changed, 85 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.h +2 -0
@@ -1710,5 +1710,7 @@ int mlx5_aso_ct_wait_ready(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_available (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.c +9 -0
@@ -3553,6 +3553,15 @@ flow_action_handles_translate(struct rte_eth_dev *dev,break ; }/* Fall-through */ +case MLX5_INDIRECT_ACTION_TYPE_CT : +if (priv->sh->ct_aso_en) { + translated[handle->index].type = +RTE_FLOW_ACTION_TYPE_CONNTRACK ; + translated[handle->index].conf = + (void *)(uintptr_t )idx; +break ; + } +/* Fall-through */ default :mlx5_free (translated);return rte_flow_error_set
drivers/net/mlx5/mlx5_flow.h +6 -1
@@ -226,6 +226,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)#define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40) +#define MLX5_FLOW_ACTION_CT (1ull << 41)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
@@ -969,11 +970,15 @@ struct rte_flow { uint32_t drv_type:2; /**< Driver type. */ uint32_t tunnel:1; uint32_t meter:24; /**< Holds flow meter id. */ + uint32_t indirect_type:2; /**< Indirect action type. */uint32_t rix_mreg_copy;/**< Index to metadata register copy table resource. */ uint32_t counter;/**< Holds flow counter. */ uint32_t tunnel_id;/**< Tunnel id */ -uint32_t age;/**< Holds ASO age bit index. */ +union { +uint32_t age;/**< Holds ASO age bit index. */ +uint32_t ct;/**< Holds ASO CT index. */ + };uint32_t geneve_tlv_option;/**< Holds Geneve TLV option id. > */ } __rte_packed;
drivers/net/mlx5/mlx5_flow_aso.c +41 -0
44 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +27 -1
@@ -11381,6 +11381,7 @@ flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,return rte_flow_error_set (error,EBUSY ,RTE_FLOW_ERROR_TYPE_ACTION ,NULL ,"Failed to update CT" ); + ct->is_original = !!pro->is_original_dir;return idx; }
@@ -11544,6 +11545,8 @@ flow_dv_translate(struct rte_eth_dev *dev,const struct rte_flow_action *found_action =NULL ;uint32_t jump_group =0 ;struct mlx5_flow_counter *cnt; +uint32_t ct_idx; +struct mlx5_aso_ct_action *ct;if (!mlx5_flow_os_action_supported (action_type)) return rte_flow_error_set(error, ENOTSUP,
@@ -12017,6 +12020,26 @@ flow_dv_translate(struct rte_eth_dev *dev,return -rte_errno; action_flags |=MLX5_FLOW_ACTION_MODIFY_FIELD ;break ; +case RTE_FLOW_ACTION_TYPE_CONNTRACK : + ct_idx = (uint32_t )(uintptr_t )action->conf; + ct =flow_aso_ct_get_by_idx (dev, ct_idx); +if (mlx5_aso_ct_available (priv->sh, ct)) +return rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_ACTION , +NULL , +"CT is unavailable." ); +if (ct->is_original) + dev_flow->dv.actions[actions_n] = + ct->dr_action_orig; +else + dev_flow->dv.actions[actions_n] = + ct->dr_action_rply; + flow->indirect_type =MLX5_INDIRECT_ACTION_TYPE_CT ; + flow->ct = ct_idx; +__atomic_fetch_add (&ct->refcnt,1 , __ATOMIC_RELAXED); + actions_n++; + action_flags |=MLX5_FLOW_ACTION_CT ; +break ;case RTE_FLOW_ACTION_TYPE_END : actions_end = true;if (mhdr_res->actions_num) {
@@ -13152,7 +13175,10 @@ flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)mlx5_flow_meter_detach (priv, fm); flow->meter =0 ; } -if (flow->age) +/* Keep the current age handling by default. */ +if (flow->indirect_type ==MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct) +flow_dv_aso_ct_release (dev, flow->ct); +else if (flow->age)flow_dv_aso_age_release (dev, flow->age);if (flow->geneve_tlv_option) {flow_dv_geneve_tlv_option_resource_release (dev);
Signature · 1 line
2.27.0
PATCH v2 12/17 net/mlx5: add translation of CT item
In reply to Bing ZhaoThe return register of the DR action will be used for matching. After the ASO CT checking of a TCP packet, the syndrome is filled in the register. Only the 8 LSB should be used. A converting from RTE_FLOW_CONNTRACK_FLAG* to the syndrome should be done after checing the spec and mask fields.
--- drivers/net/mlx5/mlx5_flow.h | 7 ++++ drivers/net/mlx5/mlx5_flow_dv.c | 62 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
drivers/net/mlx5/mlx5_flow.h +7 -0
@@ -405,6 +405,13 @@ enum mlx5_feature_name {/* Maximum number of fields to modify in MODIFY_FIELD */ #define MLX5_ACT_MAX_MOD_FIELDS 5 +/* Syndrome bits definition for connection tracking. */ +#define MLX5_CT_SYNDROME_VALID (0x0 << 6) +#define MLX5_CT_SYNDROME_INVALID (0x1 << 6) +#define MLX5_CT_SYNDROME_TRAP (0x2 << 6) +#define MLX5_CT_SYNDROME_STATE_CHANGE (0x1 << 1) +#define MLX5_CT_SYNDROME_BAD_PACKET (0x1 << 0) +enum mlx5_flow_drv_type {MLX5_FLOW_TYPE_MIN ,MLX5_FLOW_TYPE_DV ,
drivers/net/mlx5/mlx5_flow_dv.c +62 -0
74 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v2 13/17 net/mlx5: add CT context update
In reply to Bing ZhaoWhen updating a connection tracking context, two separate parts could be updated.
First, the direction. This will only update the traffic direction recorded in the software for flow creation.
Second, the TCP parameters. The hardware context will be updated via the WQE. This update will be blocked until the hardware status is updated and ready for the next flow creation.
--- drivers/net/mlx5/mlx5_flow_dv.c | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
drivers/net/mlx5/mlx5_flow_dv.c +56 -0
@@ -13824,6 +13824,60 @@ __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,return ret; } +/* +* Updates in place conntrack context or direction. +* Context update should be synchronized. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* The conntrack object ID to be updated. +* @param[in] update +* Pointer to the structure of information to update. +* @param[out] error +* Perform verbose error reporting if not NULL. Initialized in case of +* error only. +* +* @return +* 0 on success, otherwise negative errno value. +*/ +static int +__flow_dv_action_ct_update (struct rte_eth_dev *dev,uint32_t idx, +const struct rte_flow_modify_conntrack *update, +struct rte_flow_error *error) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +const struct rte_flow_action_conntrack *new_prf; +int ret =0 ; + + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,ENOMEM , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + new_prf = &update->new_ct; +if (update->direction) + ct->is_original = !!new_prf->is_original_dir; +if (update->state) { + ret =mlx5_aso_ct_update_by_wqe (priv->sh, ct, new_prf); +if (ret) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to send CT context update WQE" ); +/* Block until ready or a failure. */ + ret =mlx5_aso_ct_available (priv->sh, ct); +if (ret) +rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Timeout to get the CT update" ); + } +return ret; +} +/** * Updates in place shared action configuration, lock free, * (mutex should be acquired by caller).
@@ -13859,6 +13913,8 @@ flow_dv_action_update(struct rte_eth_dev *dev,case MLX5_INDIRECT_ACTION_TYPE_RSS : action_conf = ((const struct rte_flow_action *)update)->conf;return __flow_dv_action_rss_update (dev, idx, action_conf, err); +case MLX5_INDIRECT_ACTION_TYPE_CT : +return __flow_dv_action_ct_update (dev, idx, update, err);default : return rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v2 14/17 net/mlx5: validation of CT action
In reply to Bing ZhaoThe validation of a CT action contains two parts. The first is the CT action configurations parameter. When creating a CT action context, some members need to be verified.
The second is that when creating a flow, the DR action of CT should be validated with other actions and items as well. Currently, only the TCP protocol support connection tracking.
--- drivers/net/mlx5/mlx5.h | 4 ++ drivers/net/mlx5/mlx5_flow.c | 31 +++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 69 +++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+)
drivers/net/mlx5/mlx5.h +4 -0
@@ -1611,6 +1611,10 @@ int mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow,void mlx5_flow_rxq_dynf_metadata_set (struct rte_eth_dev *dev);int mlx5_flow_get_aged_flows (struct rte_eth_dev *dev,void **contexts,uint32_t nb_contexts,struct rte_flow_error *error); +int mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error); +/* mlx5_mp_os.c */
drivers/net/mlx5/mlx5_flow.c +31 -0
@@ -1688,6 +1688,37 @@ mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,return 0 ; } +/* +* Validate the ASO CT action. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] conntrack +* Pointer to the CT action profile. +* @param[out] error +* Pointer to error structure. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error) +{ +RTE_SET_USED (dev); + +if (conntrack->state >RTE_FLOW_CONNTRACK_STATE_TIME_WAIT ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid CT state" ); +if (conntrack->last_index >RTE_FLOW_CONNTRACK_FLAG_RST ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid last TCP packet flag" ); +return 0 ; +} +/** * Verify the @p attributes will be correctly understood by the NIC and store * them in the @p flow if everything is correct.
drivers/net/mlx5/mlx5_flow_dv.c +69 -0
93 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v2 15/17 net/mlx5: validation of CT item
In reply to Bing ZhaoThe item of ASO connection tracking will be translated into the register value when matching. The validation of this item has no dependency on other layers, since the flow including this item should be jumped from another group. All the layers checking was already done in the previous groups. Only the state bits conflict should be checked.
It is assumed that the flow with CT item will always work on the TCP traffic.
--- drivers/net/mlx5/mlx5_flow.h | 3 ++ drivers/net/mlx5/mlx5_flow_dv.c | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -147,6 +147,9 @@ enum mlx5_feature_name {#define MLX5_FLOW_LAYER_GENEVE_OPT (UINT64_C(1) << 32)#define MLX5_FLOW_LAYER_GTP_PSC (UINT64_C(1) << 33) +/* Conntrack item. */ +#define MLX5_FLOW_LAYER_ASO_CT (UINT64_C(1) << 34) +/* Outer Masks. */ #define MLX5_FLOW_LAYER_OUTER_L3 \ (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6)
drivers/net/mlx5/mlx5_flow_dv.c +51 -0
63 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v2 16/17 net/mlx5: add support of CT between two ports
In reply to Bing ZhaoAfter creating a connection tracking context, it can be used between two ports. For each port, the flow for one direction traffic will be created.
The context can only be shared between the owner port and the peer port that was specified when being created. Only the owner port could update the context or query it in current implementation.
--- drivers/net/mlx5/mlx5_flow.h | 57 +++++++++++++++++++++++++- drivers/net/mlx5/mlx5_flow_dv.c | 71 +++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 18 deletions(-)
drivers/net/mlx5/mlx5_flow.h +55 -2
@@ -48,6 +48,25 @@ enum { MLX5_INDIRECT_ACTION_TYPE_CT, }; +/* Now, the maximal ports will be supported is 256, action number is 4M. */ +#define MLX5_INDIRECT_ACT_CT_MAX_PORT 0x100 + +#define MLX5_INDIRECT_ACT_CT_OWNER_SHIFT 22 +#define MLX5_INDIRECT_ACT_CT_OWNER_MASK (MLX5_INDIRECT_ACT_CT_MAX_PORT - 1) + +/* 30-31: type, 22-29: owner port, 0-21: index. */ +#define MLX5_INDIRECT_ACT_CT_GEN_IDX (owner, index) \ + ((MLX5_INDIRECT_ACTION_TYPE_CT << MLX5_INDIRECT_ACTION_TYPE_OFFSET) | \ + (((owner) & MLX5_INDIRECT_ACT_CT_OWNER_MASK) << \ + MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) | (index)) + +#define MLX5_INDIRECT_ACT_CT_GET_OWNER (index) \ + (((index) >> MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) & \ + MLX5_INDIRECT_ACT_CT_OWNER_MASK) + +#define MLX5_INDIRECT_ACT_CT_GET_IDX (index) \ + ((index) & ((1 << MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) - 1)) +/* Matches on selected register. */ struct mlx5_rte_flow_item_tag {enum modify_reg id;
@@ -1304,7 +1323,7 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx) }/* -* Get ASO CT action by index. +* Get ASO CT action by device and index. * * @param[in] dev * Pointer to the Ethernet device structure.
@@ -1315,7 +1334,7 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)* The specified ASO CT action pointer. */ static inline struct mlx5_aso_ct_action * -flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +flow_aso_ct_get_by_dev_idx (struct rte_eth_dev *dev,uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
@@ -1330,6 +1349,40 @@ flow_aso_ct_get_by_idx(struct rte_eth_dev *dev, uint32_t idx)return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; } +/* +* Get ASO CT action by owner & index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action and owner port combination. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t own_idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +uint16_t owner = (uint16_t )MLX5_INDIRECT_ACT_CT_GET_OWNER (own_idx); +uint32_t idx =MLX5_INDIRECT_ACT_CT_GET_IDX (own_idx); + +if (owner ==PORT_ID (priv)) { + ct =flow_aso_ct_get_by_dev_idx (dev, idx); + }else { +struct rte_eth_dev *owndev = &rte_eth_devices[owner]; + +MLX5_ASSERT (owner <RTE_MAX_ETHPORTS ); +if (dev->data->dev_started !=1 ) +return NULL ; + ct =flow_aso_ct_get_by_dev_idx (owndev, idx); +if (ct->peer !=PORT_ID (priv)) +return NULL ; + } +return ct; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +55 -16
165 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v2 17/17 doc: update mlx5 support for conntrack
In reply to Bing ZhaoIn the release notes and mlx5 NIC document, the support and limitation of connection tracking are added.
--- doc/guides/nics/features/default.ini | 1 + doc/guides/nics/features/mlx5.ini | 1 + doc/guides/nics/mlx5.rst | 14 ++++++++++++++ doc/guides/rel_notes/release_21_05.rst | 2 ++ 4 files changed, 18 insertions(+)
doc/guides/nics/features/default.ini +1 -0
@@ -66,6 +66,7 @@ Module EEPROM dump = Registers dump = LED = Multiprocess aware = +Connection tracking = FreeBSD = Linux = Windows =
doc/guides/nics/features/mlx5.ini +1 -0
@@ -45,6 +45,7 @@ Stats per queue = Y FW version = Y Module EEPROM dump = Y Multiprocess aware = Y +Connection tracking = Y Linux = Y Windows = P ARMv8 = Y
doc/guides/nics/mlx5.rst +14 -0
@@ -107,6 +107,7 @@ Features - 21844 flow priorities for ingress or egress flow groups greater than 0 and for any transfer flow group. - Flow metering, including meter policy API. +- Connection tracking. Limitations -----------
@@ -418,6 +419,14 @@ Limitations - RED: must be DROP. - meter profile packet mode is supported. +- Connection tracking: + + - connection tracking (conntrack) couldn't co-exist with ASO meter, ASO age action in a single flow rule. + - Flow rules insertion rate and memory consumption. + - software limitation: + - ports: a maximal number of 256. + - conntrack: a maximal number of 4M. + Statistics ----------
@@ -1680,6 +1689,11 @@ Supported hardware offloads | | | rdma-core 35 | | rdma-core 35 | | | | ConnectX-5 | | ConnectX-5 | +-----------------------+-----------------+-----------------+ + | Connection tracking | | | | DPDK 21.05 | + | | | N/A | | OFED 5.3 | + | | | | | rdma-core 35 | + | | | | | ConnectX-6 Dx | + +-----------------------+-----------------+-----------------+ .. table:: Minimal SW/HW versions for shared action offload :name: sact
doc/guides/rel_notes/release_21_05.rst +2 -0
@@ -166,6 +166,8 @@ New Features * Added support for ASO (Advanced Steering Operation) meter. * Added support for ASO metering by PPS (packet per second). * Added support for the monitor policy of Power Management API. + * Added support for connection tracking action and item as well as context create, + destroy, update and query. * **Updated NXP DPAA driver.**
Signature · 1 line
2.27.0
Quoted 10 lines
-----Original Message-----
From: Bing Zhao <[email protected]>
Sent: Wednesday, May 5, 2021 7:20
To: Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>
Cc: [email protected]; Ori Kam <[email protected]>; Raslan Darawsheh <[email protected]>
Subject: [PATCH v2 00/17] conntrack support in mlx5 PMD
Quoted 5 lines
This patch set adds the connection tracking offload support in the mlx5 driver, as well as the documents update.
---
v2: code bug fixes, commits clean up and doc update.
For the series:
Quoted 41 lines
---
Bing Zhao (17):
common/mlx5: add connection tracking object definition common/mlx5: add CT offload capability checking net/mlx5: use meter color reg for CT net/mlx5: initialization of CT management common/mlx5: add Dexv CT objects creation net/mlx5: add modify support for CT
net/mlx5: add actions creating for CT net/mlx5: close CT management structure net/mlx5: add ASO CT query implementation net/mlx5: add ASO CT destroy handling net/mlx5: add translation of CT action net/mlx5: add translation of CT item net/mlx5: add CT context update
net/mlx5: validation of CT action
net/mlx5: validation of CT item
net/mlx5: add support of CT between two ports
doc: update mlx5 support for conntrackdoc/guides/nics/features/default.ini | 1 + doc/guides/nics/features/mlx5.ini | 1 + doc/guides/nics/mlx5.rst | 14 + doc/guides/rel_notes/release_21_05.rst | 2 + drivers/common/mlx5/linux/meson.build | 2 + drivers/common/mlx5/mlx5_devx_cmds.c | 53 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 5 + drivers/common/mlx5/mlx5_prm.h | 88 ++++ drivers/common/mlx5/version.map | 1 + drivers/net/mlx5/linux/mlx5_os.c | 13 + drivers/net/mlx5/mlx5.c | 92 ++++ drivers/net/mlx5/mlx5.h | 76 ++++ drivers/net/mlx5/mlx5_flow.c | 44 +- drivers/net/mlx5/mlx5_flow.h | 101 ++++- drivers/net/mlx5/mlx5_flow_aso.c | 592 ++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 601 ++++++++++++++++++++++++- 16 files changed, 1683 insertions(+), 3 deletions(-)--
2.27.0
v3 cover conntrack support in mlx5 PMD
In reply to Bing ZhaoThis patch set adds the connection tracking offload support in the mlx5 driver, as well as the documents update.
---
v2: code bug fixes, commits clean up and doc update.
v3: fix error input pointer for CT MR registering
---
Bing Zhao (17):
common/mlx5: add connection tracking object definition common/mlx5: add CT offload capability checking net/mlx5: use meter color reg for CT net/mlx5: initialization of CT management common/mlx5: add Dexv CT objects creation net/mlx5: add modify support for CT
net/mlx5: add actions creating for CT net/mlx5: close CT management structure net/mlx5: add ASO CT query implementation net/mlx5: add ASO CT destroy handling net/mlx5: add translation of CT action net/mlx5: add translation of CT item net/mlx5: add CT context update
net/mlx5: validation of CT action
net/mlx5: validation of CT item
net/mlx5: add support of CT between two ports
doc: update mlx5 support for conntrack
doc/guides/nics/features/default.ini | 1 + doc/guides/nics/features/mlx5.ini | 1 + doc/guides/nics/mlx5.rst | 14 + doc/guides/rel_notes/release_21_05.rst | 2 + drivers/common/mlx5/linux/meson.build | 2 + drivers/common/mlx5/mlx5_devx_cmds.c | 53 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 5 + drivers/common/mlx5/mlx5_prm.h | 88 ++++ drivers/common/mlx5/version.map | 1 + drivers/net/mlx5/linux/mlx5_os.c | 13 + drivers/net/mlx5/mlx5.c | 92 ++++ drivers/net/mlx5/mlx5.h | 76 ++++ drivers/net/mlx5/mlx5_flow.c | 44 +- drivers/net/mlx5/mlx5_flow.h | 101 ++++- drivers/net/mlx5/mlx5_flow_aso.c | 592 ++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 601 ++++++++++++++++++++++++- 16 files changed, 1683 insertions(+), 3 deletions(-)
Signature · 1 line
2.27.0
PATCH v3 1/17 common/mlx5: add connection tracking object definition
The structures of ASO connection tracking offload object are added based on the definitions in the PRM. One CT object context will be loaded into the cache completely in a reversed order of dwords. The valid bit should be the MSB of the last dword. This is used for the conntrack context creation and update, as well as for the query.
The capabilities 2 (HCA_CAP_2) layout is also added. The connection tracking related capabilities could be queried via the HCA_CAP_2.
--- drivers/common/mlx5/mlx5_prm.h | 85 ++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
drivers/common/mlx5/mlx5_prm.h +85 -0
@@ -1119,6 +1119,7 @@ enum {MLX5_GET_HCA_CAP_OP_MOD_ROCE =0x4 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE =0x7 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_VDPA_EMULATION =0x13 <<1 , + MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE_2 = 0x20 << 1, };#define MLX5_GENERAL_OBJ_TYPES_CAP_VIRTQ_NET_Q \
@@ -1661,6 +1662,29 @@ struct mlx5_ifc_flow_table_nic_cap_bits {struct mlx5_ifc_flow_table_prop_layout_bits flow_table_properties; }; +struct mlx5_ifc_cmd_hca_cap_2_bits { +u8 reserved_at_0[0x80 ];/* End of DW4. */ +u8 reserved_at_80[0xb ]; +u8 log_max_num_reserved_qpn[0x5 ]; +u8 reserved_at_90[0x3 ]; +u8 log_reserved_qpn_granularity[0x5 ]; +u8 reserved_at_98[0x3 ]; +u8 log_reserved_qpn_max_alloc[0x5 ];/* End of DW5. */ +u8 max_reformat_insert_size[0x8 ]; +u8 max_reformat_insert_offset[0x8 ]; +u8 max_reformat_remove_size[0x8 ]; +u8 max_reformat_remove_offset[0x8 ];/* End of DW6. */ +u8 aso_conntrack_reg_id[0x8 ]; +u8 reserved_at_c8[0x3 ]; +u8 log_conn_track_granularity[0x5 ]; +u8 reserved_at_d0[0x3 ]; +u8 log_conn_track_max_alloc[0x5 ]; +u8 reserved_at_d8[0x3 ]; +u8 log_max_conn_track_offload[0x5 ]; +u8 reserved_at_e0[0x20 ];/* End of DW7. */ +u8 reserved_at_100[0x700 ]; +}; +union mlx5_ifc_hca_cap_union_bits {struct mlx5_ifc_cmd_hca_cap_bits cmd_hca_cap;struct mlx5_ifc_per_protocol_networking_offload_caps_bits
@@ -2599,6 +2623,67 @@ struct mlx5_ifc_create_flow_meter_aso_in_bits {struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr;struct mlx5_ifc_flow_meter_aso_bits flow_meter_aso; }; + +struct mlx5_ifc_tcp_window_params_bits { +u8 max_ack[0x20 ]; +u8 max_win[0x20 ]; +u8 reply_end[0x20 ]; +u8 sent_end[0x20 ]; +}; + +struct mlx5_ifc_conn_track_aso_bits { +struct mlx5_ifc_tcp_window_params_bits reply_dir;/* End of DW3. */ +struct mlx5_ifc_tcp_window_params_bits original_dir;/* End of DW7. */ +u8 last_end[0x20 ];/* End of DW8. */ +u8 last_ack[0x20 ];/* End of DW9. */ +u8 last_seq[0x20 ];/* End of DW10. */ +u8 last_win[0x10 ]; +u8 reserved_at_170[0xa ]; +u8 last_dir[0x1 ]; +u8 last_index[0x5 ];/* End of DW11. */ +u8 reserved_at_180[0x40 ];/* End of DW13. */ +u8 reply_direction_tcp_scale[0x4 ]; +u8 reply_direction_tcp_close_initiated[0x1 ]; +u8 reply_direction_tcp_liberal_enabled[0x1 ]; +u8 reply_direction_tcp_data_unacked[0x1 ]; +u8 reply_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1c8[0x8 ]; +u8 original_direction_tcp_scale[0x4 ]; +u8 original_direction_tcp_close_initiated[0x1 ]; +u8 original_direction_tcp_liberal_enabled[0x1 ]; +u8 original_direction_tcp_data_unacked[0x1 ]; +u8 original_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1d8[0x8 ];/* End of DW14. */ +u8 valid[0x1 ]; +u8 state[0x3 ]; +u8 freeze_track[0x1 ]; +u8 reserved_at_1e5[0xb ]; +u8 reserved_at_1f0[0x1 ]; +u8 connection_assured[0x1 ]; +u8 sack_permitted[0x1 ]; +u8 challenged_acked[0x1 ]; +u8 heartbeat[0x1 ]; +u8 max_ack_window[0x3 ]; +u8 reserved_at_1f8[0x1 ]; +u8 retransmission_counter[0x3 ]; +u8 retranmission_limit_exceeded[0x1 ]; +u8 retranmission_limit[0x3 ];/* End of DW15. */ +}; + +struct mlx5_ifc_conn_track_offload_bits { +u8 modify_field_select[0x40 ]; +u8 reserved_at_40[0x40 ]; +u8 reserved_at_80[0x8 ]; +u8 conn_track_aso_access_pd[0x18 ]; +u8 reserved_at_a0[0x160 ]; +struct mlx5_ifc_conn_track_aso_bits conn_track_aso; +}; + +struct mlx5_ifc_create_conn_track_aso_in_bits { +struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr; +struct mlx5_ifc_conn_track_offload_bits conn_track_offload; +}; +enum mlx5_access_aso_opc_mod {ASO_OPC_MOD_IPSEC =0x0 ,ASO_OPC_MOD_CONNECTION_TRACKING =0x1 ,
Signature · 1 line
2.27.0
PATCH v3 2/17 common/mlx5: add CT offload capability checking
In reply to Bing ZhaoDuring startup, the ASO connection tracking offload capability could be queried via HCA_CAP_QUERY command. If the HW doesn't support ASO CT, the value would be 0 by default. The following initialization should be skipped and the creation of the CT object should return a failure directly.
The following CT creation should also check this capability. With the old driver, the pre-processing macro should be used in order to make the compiling pass.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/mlx5_devx_cmds.c | 3 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 3 +++ 4 files changed, 9 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -189,6 +189,8 @@ has_sym_args = [ 'MLX5_WQE_UMR_CTRL_FLAG_INLINE' ], [ 'HAVE_MLX5_DR_FLOW_DUMP_RULE', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_rule' ], + [ 'HAVE_MLX5_DR_ACTION_ASO_CT', 'infiniband/mlx5dv.h', + 'MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR' ], ] config = configuration_data() foreach arg:has_sym_args
drivers/common/mlx5/mlx5_devx_cmds.c +3 -0
@@ -760,6 +760,9 @@ mlx5_devx_cmd_query_hca_attr(void *ctx,MLX5_GET (cmd_hca_cap, hcattr, umr_indirect_mkey_disabled); attr->umr_modify_entity_size_disabled =MLX5_GET (cmd_hca_cap, hcattr, umr_modify_entity_size_disabled); + attr->ct_offload = !!(MLX5_GET64 (cmd_hca_cap, hcattr, + general_obj_types) & +MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD );if (attr->qos.sup) { MLX5_SET(query_hca_cap_in, in, op_mod, MLX5_GET_HCA_CAP_OP_MOD_QOS_CAP |
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -137,6 +137,7 @@ struct mlx5_hca_attr { uint32_t qp_ts_format:2; uint32_t regex:1; uint32_t reg_c_preserve:1; + uint32_t ct_offload:1; /* General obj type ASO CT offload supported. */uint32_t regexp_num_of_engines; uint32_t log_max_ft_sampler_num:8;uint32_t geneve_tlv_opt;
drivers/common/mlx5/mlx5_prm.h +3 -0
@@ -1134,6 +1134,8 @@ enum { (1ULL << MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO)#define MLX5_GENERAL_OBJ_TYPES_CAP_GENEVE_TLV_OPT \ (1ULL << MLX5_OBJ_TYPE_GENEVE_TLV_OPT) +#define MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD \ + (1ULL << MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD)enum {MLX5_HCA_CAP_OPMOD_GET_MAX =0 ,
@@ -2456,6 +2458,7 @@ enum {MLX5_GENERAL_OBJ_TYPE_FLEX_PARSE_GRAPH =0x0022 ,MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO =0x0024 ,MLX5_GENERAL_OBJ_TYPE_FLOW_HIT_ASO =0x0025 , + MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD = 0x0031, }; struct mlx5_ifc_general_obj_in_cmd_hdr_bits {
Signature · 1 line
2.27.0
PATCH v3 3/17 net/mlx5: use meter color reg for CT
In reply to Bing ZhaoBased on the capacity, 3 registers could be used. Due to the register allocation, only the one REG_C_3 for meter color could be reused right now.
Then in the same flow, no more than one ASO action can be supported.
--- drivers/net/mlx5/mlx5_flow.c | 4 +++- drivers/net/mlx5/mlx5_flow.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow.c +3 -1
@@ -760,7 +760,9 @@ mlx5_flow_get_reg_id(struct rte_eth_dev *dev,return priv->mtr_color_reg !=REG_C_2 ?REG_C_2 :REG_C_3 ;case MLX5_MTR_COLOR : -case MLX5_ASO_FLOW_HIT :/* Both features use the same REG_C. */ +case MLX5_ASO_FLOW_HIT : +case MLX5_ASO_CONNTRACK : +/* All features use the same REG_C. */ MLX5_ASSERT (priv->mtr_color_reg !=REG_NON );return priv->mtr_color_reg;case MLX5_COPY_MARK :
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -84,6 +84,7 @@ enum mlx5_feature_name {MLX5_MTR_COLOR ,MLX5_MTR_ID ,MLX5_ASO_FLOW_HIT , + MLX5_ASO_CONNTRACK, };/* Default queue number. */
Signature · 1 line
2.27.0
PATCH v3 4/17 net/mlx5: initialization of CT management
In reply to Bing ZhaoThe definitions of ASO connection tracking objects management structures are added.
Considering performance, the bulk allocation of ASO CT objects should be used. The maximal value per bulk and the granularity could be fetched from HCA capabilities 2. Right now, a fixed number of 64 is used for each bulk for a better management purpose.
The ASO QP for CT is initialized, the SQ will be used for both modify and query command.
--- drivers/net/mlx5/linux/mlx5_os.c | 13 +++++++++ drivers/net/mlx5/mlx5.c | 36 +++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 50 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 50 ++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +13 -0
@@ -1323,6 +1323,19 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,DRV_LOG (DEBUG ,"Flow Hit ASO is supported." ); }#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */ +#if defined(HAVE_MLX5_DR_CREATE_ACTION_ASO ) && \ + defined(HAVE_MLX5_DR_ACTION_ASO_CT ) +if (config->hca_attr.ct_offload && + priv->mtr_color_reg ==REG_C_3 ) { + err =mlx5_flow_aso_ct_mng_init (sh); +if (err) { + err = -err; + goto error; + } +DRV_LOG (DEBUG ,"CT ASO is supported." ); + sh->ct_aso_en =1 ; + } +#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO && HAVE_MLX5_DR_ACTION_ASO_CT */ #if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE )if (config->hca_attr.log_max_ft_sampler_num >0 && config->dv_flow_en) {
drivers/net/mlx5/mlx5.c +36 -0
@@ -670,6 +670,42 @@ mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh) } } +/* +* Initialize the ASO connection tracking structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_flow_aso_ct_mng_init (struct mlx5_dev_ctx_shared *sh) +{ +int err; + +if (sh->ct_mng) +return 0 ; + sh->ct_mng =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*sh->ct_mng), +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +if (!sh->ct_mng) { +DRV_LOG (ERR ,"ASO CT management allocation failed." ); + rte_errno =ENOMEM ; +return -rte_errno; + } + err =mlx5_aso_queue_init (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); +if (err) { +mlx5_free (sh->ct_mng); +/* rte_errno should be extracted from the failure. */ + rte_errno =EINVAL ; +return -rte_errno; + } +rte_spinlock_init (&sh->ct_mng->ct_sl); +rte_rwlock_init (&sh->ct_mng->resize_rwl); +LIST_INIT (&sh->ct_mng->free_cts); +return 0 ; +} +/** * Initialize the flow resources' indexed mempool. *
drivers/net/mlx5/mlx5.h +50 -0
74 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_aso.c +50 -0
62 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 5/17 common/mlx5: add Dexv CT objects creation
In reply to Bing ZhaoAdding support for connection tracking ASO creation via Devx command. Right now only bulk creation is supported.
By default, the objects with zero contents will be created. Before using a single object, the modification via posting a WQE to the ASO CT SQ is needed.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 50 ++++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 4 +++ drivers/common/mlx5/version.map | 1 + 3 files changed, 55 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +50 -0
@@ -2232,6 +2232,56 @@ mlx5_devx_cmd_create_flow_meter_aso_obj(void *ctx, uint32_t pd,return flow_meter_aso_obj; } +/* +* Create general object of type CONN_TRACK_OFFLOAD using DevX API. +* +* @param[in] ctx +* Context returned from mlx5 open_device() glue function. +* @param [in] pd +* PD value to associate the CONN_TRACK_OFFLOAD ASO object with. +* @param [in] log_obj_size +* log_obj_size to allocate its power of 2 * objects +* in one CONN_TRACK_OFFLOAD bulk allocation. +* +* @return +* The DevX object created, NULL otherwise and rte_errno is set. +*/ +struct mlx5_devx_obj * +mlx5_devx_cmd_create_conn_track_offload_obj (void *ctx,uint32_t pd, +uint32_t log_obj_size) +{ +uint32_t in[MLX5_ST_SZ_DW (create_conn_track_aso_in)] = {0 }; +uint32_t out[MLX5_ST_SZ_DW (general_obj_out_cmd_hdr)]; +struct mlx5_devx_obj *ct_aso_obj; +void *ptr; + + ct_aso_obj =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*ct_aso_obj), +0 ,SOCKET_ID_ANY ); +if (!ct_aso_obj) { +DRV_LOG (ERR ,"Failed to allocate CONN_TRACK_OFFLOAD object." ); + rte_errno =ENOMEM ; +return NULL ; + } + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, hdr); +MLX5_SET (general_obj_in_cmd_hdr, ptr, opcode, +MLX5_CMD_OP_CREATE_GENERAL_OBJECT ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, obj_type, +MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, log_obj_range, log_obj_size); + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, conn_track_offload); +MLX5_SET (conn_track_offload, ptr, conn_track_aso_access_pd, pd); + ct_aso_obj->obj = mlx5_glue->devx_obj_create (ctx, in,sizeof (in), + out,sizeof (out)); +if (!ct_aso_obj->obj) { + rte_errno = errno; +DRV_LOG (ERR ,"Failed to create CONN_TRACK_OFFLOAD obj by using DevX." ); +mlx5_free (ct_aso_obj); +return NULL ; + } + ct_aso_obj->id =MLX5_GET (general_obj_out_cmd_hdr, out, obj_id); +return ct_aso_obj; +} +/** * Create general object of type GENEVE TLV option using DevX API. *
drivers/common/mlx5/mlx5_devx_cmds.h +4 -0
@@ -569,6 +569,10 @@ struct mlx5_devx_obj *mlx5_devx_cmd_queue_counter_alloc(void *ctx);__rte_internal int mlx5_devx_cmd_queue_counter_query(struct mlx5_devx_obj *dcs, int clear,uint32_t *out_of_buffers); +__rte_internal +struct mlx5_devx_obj *mlx5_devx_cmd_create_conn_track_offload_obj(void *ctx, +uint32_t pd,uint32_t log_obj_size); +/** * Create general object of type FLOW_METER_ASO using DevX API.. *
drivers/common/mlx5/version.map +1 -0
@@ -13,6 +13,7 @@ INTERNAL { mlx5_dev_to_pci_addr; # WINDOWS_NO_EXPORT mlx5_devx_cmd_alloc_pd; + mlx5_devx_cmd_create_conn_track_offload_obj; mlx5_devx_cmd_create_cq; mlx5_devx_cmd_create_flex_parser; mlx5_devx_cmd_create_qp;
Signature · 1 line
2.27.0
PATCH v3 6/17 net/mlx5: add modify support for CT
In reply to Bing ZhaoAfter the connection tracking object bulk is allocated, all the objects' contents are filled with zero by default. Every new-allocated object must be modified via WQE operation before it is used.
In order to reduce the latency for the flow creation, an asynchronous way is used instead of busy waiting for the CQE to be generated.
--- drivers/net/mlx5/mlx5.h | 8 + drivers/net/mlx5/mlx5_flow.h | 3 + drivers/net/mlx5/mlx5_flow_aso.c | 252 +++++++++++++++++++++++++++++++ 3 files changed, 263 insertions(+)
drivers/net/mlx5/mlx5.h +8 -0
@@ -490,6 +490,7 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; +struct mlx5_aso_ct_action *ct; }; };
@@ -1007,6 +1008,10 @@ struct mlx5_aso_ct_action {bool is_original;/* The direction of the DR action to be used. */ }; +/* CT action object state update. */ +#define MLX5_ASO_CT_UPDATE_STATE (c, s) \ + __atomic_store_n(&((c)->state), (s), __ATOMIC_RELAXED) +/* ASO connection tracking software pool definition. */ struct mlx5_aso_ct_pool {uint16_t index;/* Pool index in pools array. */
@@ -1690,5 +1695,8 @@ int mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh, struct mlx5_aso_mtr *mtr);int mlx5_aso_mtr_wait (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_mtr *mtr); +int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +const struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -45,6 +45,7 @@ enum mlx5_rte_flow_action_type {enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE , +MLX5_INDIRECT_ACTION_TYPE_AGE , };/* Matches on selected register. */
@@ -839,6 +840,8 @@ struct mlx5_flow {#define MLX5_ASO_WQE_CQE_RESPONSE_DELAY 10u#define MLX5_MTR_POLL_WQE_CQE_TIMES 100000u +#define MLX5_CT_POLL_WQE_CQE_TIMES MLX5_MTR_POLL_WQE_CQE_TIMES +#define MLX5_MAN_WIDTH 8/* Legacy Meter parameter structure. */ struct mlx5_legacy_flow_meter {
drivers/net/mlx5/mlx5_flow_aso.c +252 -0
255 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 7/17 net/mlx5: add actions creating for CT
In reply to Bing ZhaoAllocating a CT from the management pools and creating the DR actions for both directions by default.
If there is no available connection tracking action, a new pool will be created with a fixed size bulk allocation. Right now, all the resources are controlled by the linked list.
The ASO connection tracking context associated with these actions need to be updated via WQE before using for steering.
--- drivers/net/mlx5/mlx5.h | 4 + drivers/net/mlx5/mlx5_flow.h | 29 +++- drivers/net/mlx5/mlx5_flow_dv.c | 263 ++++++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +4 -0
@@ -987,6 +987,10 @@ struct mlx5_bond_info {/* Number of connection tracking objects per pool: must be a power of 2. */ #define MLX5_ASO_CT_ACTIONS_PER_POOL 64 +/* Generate incremental and unique CT index from pool and offset. */ +#define MLX5_MAKE_CT_IDX (pool, offset) \ + ((pool) * MLX5_ASO_CT_ACTIONS_PER_POOL + (offset) + 1) +/* ASO Conntrack state. */ enum mlx5_aso_ct_state {ASO_CONNTRACK_FREE ,/* Inactive, in the free list. */
drivers/net/mlx5/mlx5_flow.h +28 -1
@@ -45,7 +45,7 @@ enum mlx5_rte_flow_action_type {enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE , -MLX5_INDIRECT_ACTION_TYPE_AGE , +MLX5_INDIRECT_ACTION_TYPE_CT , };/* Matches on selected register. */
@@ -1288,6 +1288,33 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)return &pool->mtrs[idx %MLX5_ASO_MTRS_PER_POOL ]; } +/* +* Get ASO CT action by index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +struct mlx5_aso_ct_pool *pool; + + idx--; +MLX5_ASSERT ((idx /MLX5_ASO_CT_ACTIONS_PER_POOL ) < mng->n); +/* Bit operation AND could be used. */ +rte_rwlock_read_lock (&mng->resize_rwl); + pool = mng->pools[idx /MLX5_ASO_CT_ACTIONS_PER_POOL ]; +rte_rwlock_read_unlock (&mng->resize_rwl); +return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +263 -0
281 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 8/17 net/mlx5: close CT management structure
In reply to Bing ZhaoWhen freeing the IB shared context during stopping a device, the ASO connection tracking management structure should also be cleaned up.
All the DR actions created should be destroyed. The structures need to be freed and ASO CT QP should be released. In the meanwhile, the allocated and registered memory region for query should also be deregistered and then freed.
--- drivers/net/mlx5/mlx5.c | 56 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 4 +++ 2 files changed, 60 insertions(+)
drivers/net/mlx5/mlx5.c +56 -0
@@ -706,6 +706,60 @@ mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh)return 0 ; } +/* +* Close and release all the resources of the +* ASO connection tracking management structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object to free. +*/ +static void +mlx5_flow_aso_ct_mng_close (struct mlx5_dev_ctx_shared *sh) +{ +struct mlx5_aso_ct_pools_mng *mng = sh->ct_mng; +struct mlx5_aso_ct_pool *ct_pool; +struct mlx5_aso_ct_action *ct; +uint32_t idx; +uint32_t val; +uint32_t cnt; +int i; + +mlx5_aso_queue_uninit (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); + idx = mng->next; +while (idx--) { + cnt =0 ; + ct_pool = mng->pools[idx]; +for (i =0 ; i <MLX5_ASO_CT_ACTIONS_PER_POOL ; i++) { + ct = &ct_pool->actions[i]; + val =__atomic_fetch_sub (&ct->refcnt,1 , + __ATOMIC_RELAXED); +MLX5_ASSERT (val ==1 ); +if (val >1 ) + cnt++; +#ifdef HAVE_MLX5_DR_ACTION_ASO_CT +if (ct->dr_action_orig) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_orig)); +if (ct->dr_action_rply) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_rply)); +#endif + } +claim_zero (mlx5_devx_cmd_destroy (ct_pool->devx_obj)); +if (cnt) { +DRV_LOG (DEBUG ,"%u ASO CT objects are being used in the pool %u" , + cnt, i); + } +mlx5_free (ct_pool); +/* in case of failure. */ + mng->next--; + } +mlx5_free (mng->pools); +mlx5_free (mng); +/* Management structure must be cleared to 0s during allocation. */ + sh->ct_mng =NULL ; +} +/** * Initialize the flow resources' indexed mempool. *
@@ -1508,6 +1562,8 @@ mlx5_dev_close(struct rte_eth_dev *dev)if (priv->mreg_cp_tbl)mlx5_hlist_destroy (priv->mreg_cp_tbl);mlx5_mprq_free_mp (dev); +if (priv->sh->ct_mng) +mlx5_flow_aso_ct_mng_close (priv->sh);mlx5_os_free_shared_dr (priv);if (priv->rss_conf.rss_key !=NULL )mlx5_free (priv->rss_conf.rss_key);
drivers/net/mlx5/mlx5_flow_aso.c +4 -0
@@ -372,6 +372,10 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,case ASO_OPC_MOD_POLICER : sq = &sh->mtrmng->pools_mng.sq;break ; +case ASO_OPC_MOD_CONNECTION_TRACKING : +mlx5_aso_dereg_mr (sh, &sh->ct_mng->aso_sq.mr); + sq = &sh->ct_mng->aso_sq; +break ;default :DRV_LOG (ERR ,"Unknown ASO operation mode" );return ;
Signature · 1 line
2.27.0
PATCH v3 9/17 net/mlx5: add ASO CT query implementation
In reply to Bing ZhaoAfter the connection tracking context is created and being used by the flows, the context will be updated by the HW automatically after a packet passed the CT validation. E.g., the ACK, SEQ, window and state of CT can be updated with both direction traffic.
In order to query the updated contents of this context, a WQE should be posted to the SQ with a return buffer. The data will be filled into the buffer. And the profile will be filled with specific value.
During the execution of query command, the context may be updated. The result of the query command may not be the latest one.
--- drivers/net/mlx5/mlx5.h | 10 +- drivers/net/mlx5/mlx5_flow_aso.c | 245 +++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 19 +++ 3 files changed, 273 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +9 -1
@@ -490,7 +490,10 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; -struct mlx5_aso_ct_action *ct; +struct { +struct mlx5_aso_ct_action *ct; +char *query_data; + }; }; };
@@ -1702,5 +1705,10 @@ int mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,const struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_wait_ready (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct); +int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow_aso.c +245 -0
263 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +19 -0
@@ -13775,6 +13775,8 @@ flow_dv_action_query(struct rte_eth_dev *dev,uint32_t act_idx = (uint32_t )(uintptr_t )handle;uint32_t type = act_idx >>MLX5_INDIRECT_ACTION_TYPE_OFFSET ;uint32_t idx = act_idx & ((1u <<MLX5_INDIRECT_ACTION_TYPE_OFFSET ) -1 ); +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct;switch (type) {case MLX5_INDIRECT_ACTION_TYPE_AGE :
@@ -13788,6 +13790,23 @@ flow_dv_action_query(struct rte_eth_dev *dev, resp->sec_since_last_hit =__atomic_load_n (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,EFAULT , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + ((struct rte_flow_action_conntrack *)data)->peer_port = + ct->peer; + ((struct rte_flow_action_conntrack *)data)->is_original_dir = + ct->is_original; +if (mlx5_aso_ct_query_by_wqe (priv->sh, ct, data)) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to query CT context" ); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v3 10/17 net/mlx5: add ASO CT destroy handling
In reply to Bing ZhaoWhen trying to destroy an ASO connection tracking context, the DR action created on this context should also be destroyed. Before inserting the related software object into the management free list, the reference count should be checked.
Right now, the context object will not be freed to the system and will be reused directly from the free list.
--- drivers/net/mlx5/mlx5_flow_dv.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +15 -1
@@ -11136,9 +11136,15 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +uint32_t ret;struct mlx5_aso_ct_action *ct =flow_aso_ct_get_by_idx (dev, idx); -uint32_t ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED); +enum mlx5_aso_ct_state state = +__atomic_load_n (&ct->state, __ATOMIC_RELAXED); +/* Cannot release when CT is in the ASO SQ. */ +if (state ==ASO_CONNTRACK_WAIT || state ==ASO_CONNTRACK_QUERY ) +return -1 ; + ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED);if (!ret) {if (ct->dr_action_orig) {#ifdef HAVE_MLX5_DR_ACTION_ASO_CT
@@ -11154,6 +11160,8 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx)#endif ct->dr_action_rply =NULL ; } +/* Clear the state to free, no need in 1st allocation. */ +MLX5_ASO_CT_UPDATE_STATE (ct,ASO_CONNTRACK_FREE );rte_spinlock_lock (&mng->ct_sl);LIST_INSERT_HEAD (&mng->free_cts, ct, next);rte_spinlock_unlock (&mng->ct_sl);
@@ -13648,6 +13656,12 @@ flow_dv_action_destroy(struct rte_eth_dev *dev,DRV_LOG (DEBUG ,"Indirect age action %" PRIu32" was" " released with references %d." , idx, ret);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ret =flow_dv_aso_ct_release (dev, idx); +if (ret) +DRV_LOG (DEBUG ,"Connection tracking object %u still " +"has references %d." , idx, ret); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v3 11/17 net/mlx5: add translation of CT action
In reply to Bing ZhaoWhen creating a flow with this action context for CT, it needs to be translated in 2 levels.
First, retrieve from action context to rte_flow action. Second, translate it to the corresponding DR action with traffic direction that was specified when creating or updating via rte_flow_action_handle* API.
Before using the DR action in a flow, the CT context should be available to use in the hardware. A synchronization is done before inserting the flow rule with CT action to check the HW availability of this CT context.
In order to release the DR actions and reuse the context of a CT, the reference count should also be handled in the the flow destroying.
The CT index will be recorded in the rte_flow by reusing the ASO age index to save memory, since only one ASO action is supported in one flow rule currently. The action context type should also be saved for CT. When destroying a flow rule, if the context type is CT and the index is valid (non-zero), the release process should be handled. By default, the handling will fall back to try to release the ASO age if any.
--- drivers/net/mlx5/mlx5.h | 2 ++ drivers/net/mlx5/mlx5_flow.c | 9 +++++++ drivers/net/mlx5/mlx5_flow.h | 7 +++++- drivers/net/mlx5/mlx5_flow_aso.c | 41 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 28 +++++++++++++++++++++- 5 files changed, 85 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.h +2 -0
@@ -1710,5 +1710,7 @@ int mlx5_aso_ct_wait_ready(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_available (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.c +9 -0
@@ -3553,6 +3553,15 @@ flow_action_handles_translate(struct rte_eth_dev *dev,break ; }/* Fall-through */ +case MLX5_INDIRECT_ACTION_TYPE_CT : +if (priv->sh->ct_aso_en) { + translated[handle->index].type = +RTE_FLOW_ACTION_TYPE_CONNTRACK ; + translated[handle->index].conf = + (void *)(uintptr_t )idx; +break ; + } +/* Fall-through */ default :mlx5_free (translated);return rte_flow_error_set
drivers/net/mlx5/mlx5_flow.h +6 -1
@@ -226,6 +226,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)#define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40) +#define MLX5_FLOW_ACTION_CT (1ull << 41)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
@@ -969,11 +970,15 @@ struct rte_flow { uint32_t drv_type:2; /**< Driver type. */ uint32_t tunnel:1; uint32_t meter:24; /**< Holds flow meter id. */ + uint32_t indirect_type:2; /**< Indirect action type. */uint32_t rix_mreg_copy;/**< Index to metadata register copy table resource. */ uint32_t counter;/**< Holds flow counter. */ uint32_t tunnel_id;/**< Tunnel id */ -uint32_t age;/**< Holds ASO age bit index. */ +union { +uint32_t age;/**< Holds ASO age bit index. */ +uint32_t ct;/**< Holds ASO CT index. */ + };uint32_t geneve_tlv_option;/**< Holds Geneve TLV option id. > */ } __rte_packed;
drivers/net/mlx5/mlx5_flow_aso.c +41 -0
44 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +27 -1
@@ -11381,6 +11381,7 @@ flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,return rte_flow_error_set (error,EBUSY ,RTE_FLOW_ERROR_TYPE_ACTION ,NULL ,"Failed to update CT" ); + ct->is_original = !!pro->is_original_dir;return idx; }
@@ -11544,6 +11545,8 @@ flow_dv_translate(struct rte_eth_dev *dev,const struct rte_flow_action *found_action =NULL ;uint32_t jump_group =0 ;struct mlx5_flow_counter *cnt; +uint32_t ct_idx; +struct mlx5_aso_ct_action *ct;if (!mlx5_flow_os_action_supported (action_type)) return rte_flow_error_set(error, ENOTSUP,
@@ -12017,6 +12020,26 @@ flow_dv_translate(struct rte_eth_dev *dev,return -rte_errno; action_flags |=MLX5_FLOW_ACTION_MODIFY_FIELD ;break ; +case RTE_FLOW_ACTION_TYPE_CONNTRACK : + ct_idx = (uint32_t )(uintptr_t )action->conf; + ct =flow_aso_ct_get_by_idx (dev, ct_idx); +if (mlx5_aso_ct_available (priv->sh, ct)) +return rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_ACTION , +NULL , +"CT is unavailable." ); +if (ct->is_original) + dev_flow->dv.actions[actions_n] = + ct->dr_action_orig; +else + dev_flow->dv.actions[actions_n] = + ct->dr_action_rply; + flow->indirect_type =MLX5_INDIRECT_ACTION_TYPE_CT ; + flow->ct = ct_idx; +__atomic_fetch_add (&ct->refcnt,1 , __ATOMIC_RELAXED); + actions_n++; + action_flags |=MLX5_FLOW_ACTION_CT ; +break ;case RTE_FLOW_ACTION_TYPE_END : actions_end = true;if (mhdr_res->actions_num) {
@@ -13152,7 +13175,10 @@ flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)mlx5_flow_meter_detach (priv, fm); flow->meter =0 ; } -if (flow->age) +/* Keep the current age handling by default. */ +if (flow->indirect_type ==MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct) +flow_dv_aso_ct_release (dev, flow->ct); +else if (flow->age)flow_dv_aso_age_release (dev, flow->age);if (flow->geneve_tlv_option) {flow_dv_geneve_tlv_option_resource_release (dev);
Signature · 1 line
2.27.0
PATCH v3 12/17 net/mlx5: add translation of CT item
In reply to Bing ZhaoThe return register of the DR action will be used for matching. After the ASO CT checking of a TCP packet, the syndrome is filled in the register. Only the 8 LSB should be used. A converting from RTE_FLOW_CONNTRACK_FLAG* to the syndrome should be done after checing the spec and mask fields.
--- drivers/net/mlx5/mlx5_flow.h | 7 ++++ drivers/net/mlx5/mlx5_flow_dv.c | 62 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
drivers/net/mlx5/mlx5_flow.h +7 -0
@@ -405,6 +405,13 @@ enum mlx5_feature_name {/* Maximum number of fields to modify in MODIFY_FIELD */ #define MLX5_ACT_MAX_MOD_FIELDS 5 +/* Syndrome bits definition for connection tracking. */ +#define MLX5_CT_SYNDROME_VALID (0x0 << 6) +#define MLX5_CT_SYNDROME_INVALID (0x1 << 6) +#define MLX5_CT_SYNDROME_TRAP (0x2 << 6) +#define MLX5_CT_SYNDROME_STATE_CHANGE (0x1 << 1) +#define MLX5_CT_SYNDROME_BAD_PACKET (0x1 << 0) +enum mlx5_flow_drv_type {MLX5_FLOW_TYPE_MIN ,MLX5_FLOW_TYPE_DV ,
drivers/net/mlx5/mlx5_flow_dv.c +62 -0
74 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 13/17 net/mlx5: add CT context update
In reply to Bing ZhaoWhen updating a connection tracking context, two separate parts could be updated.
First, the direction. This will only update the traffic direction recorded in the software for flow creation.
Second, the TCP parameters. The hardware context will be updated via the WQE. This update will be blocked until the hardware status is updated and ready for the next flow creation.
--- drivers/net/mlx5/mlx5_flow_dv.c | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
drivers/net/mlx5/mlx5_flow_dv.c +56 -0
@@ -13824,6 +13824,60 @@ __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,return ret; } +/* +* Updates in place conntrack context or direction. +* Context update should be synchronized. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* The conntrack object ID to be updated. +* @param[in] update +* Pointer to the structure of information to update. +* @param[out] error +* Perform verbose error reporting if not NULL. Initialized in case of +* error only. +* +* @return +* 0 on success, otherwise negative errno value. +*/ +static int +__flow_dv_action_ct_update (struct rte_eth_dev *dev,uint32_t idx, +const struct rte_flow_modify_conntrack *update, +struct rte_flow_error *error) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +const struct rte_flow_action_conntrack *new_prf; +int ret =0 ; + + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,ENOMEM , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + new_prf = &update->new_ct; +if (update->direction) + ct->is_original = !!new_prf->is_original_dir; +if (update->state) { + ret =mlx5_aso_ct_update_by_wqe (priv->sh, ct, new_prf); +if (ret) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to send CT context update WQE" ); +/* Block until ready or a failure. */ + ret =mlx5_aso_ct_available (priv->sh, ct); +if (ret) +rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Timeout to get the CT update" ); + } +return ret; +} +/** * Updates in place shared action configuration, lock free, * (mutex should be acquired by caller).
@@ -13859,6 +13913,8 @@ flow_dv_action_update(struct rte_eth_dev *dev,case MLX5_INDIRECT_ACTION_TYPE_RSS : action_conf = ((const struct rte_flow_action *)update)->conf;return __flow_dv_action_rss_update (dev, idx, action_conf, err); +case MLX5_INDIRECT_ACTION_TYPE_CT : +return __flow_dv_action_ct_update (dev, idx, update, err);default : return rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v3 14/17 net/mlx5: validation of CT action
In reply to Bing ZhaoThe validation of a CT action contains two parts. The first is the CT action configurations parameter. When creating a CT action context, some members need to be verified.
The second is that when creating a flow, the DR action of CT should be validated with other actions and items as well. Currently, only the TCP protocol support connection tracking.
--- drivers/net/mlx5/mlx5.h | 4 ++ drivers/net/mlx5/mlx5_flow.c | 31 +++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 69 +++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+)
drivers/net/mlx5/mlx5.h +4 -0
@@ -1611,6 +1611,10 @@ int mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow,void mlx5_flow_rxq_dynf_metadata_set (struct rte_eth_dev *dev);int mlx5_flow_get_aged_flows (struct rte_eth_dev *dev,void **contexts,uint32_t nb_contexts,struct rte_flow_error *error); +int mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error); +/* mlx5_mp_os.c */
drivers/net/mlx5/mlx5_flow.c +31 -0
@@ -1688,6 +1688,37 @@ mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,return 0 ; } +/* +* Validate the ASO CT action. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] conntrack +* Pointer to the CT action profile. +* @param[out] error +* Pointer to error structure. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error) +{ +RTE_SET_USED (dev); + +if (conntrack->state >RTE_FLOW_CONNTRACK_STATE_TIME_WAIT ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid CT state" ); +if (conntrack->last_index >RTE_FLOW_CONNTRACK_FLAG_RST ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid last TCP packet flag" ); +return 0 ; +} +/** * Verify the @p attributes will be correctly understood by the NIC and store * them in the @p flow if everything is correct.
drivers/net/mlx5/mlx5_flow_dv.c +69 -0
93 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 15/17 net/mlx5: validation of CT item
In reply to Bing ZhaoThe item of ASO connection tracking will be translated into the register value when matching. The validation of this item has no dependency on other layers, since the flow including this item should be jumped from another group. All the layers checking was already done in the previous groups. Only the state bits conflict should be checked.
It is assumed that the flow with CT item will always work on the TCP traffic.
--- drivers/net/mlx5/mlx5_flow.h | 3 ++ drivers/net/mlx5/mlx5_flow_dv.c | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -147,6 +147,9 @@ enum mlx5_feature_name {#define MLX5_FLOW_LAYER_GENEVE_OPT (UINT64_C(1) << 32)#define MLX5_FLOW_LAYER_GTP_PSC (UINT64_C(1) << 33) +/* Conntrack item. */ +#define MLX5_FLOW_LAYER_ASO_CT (UINT64_C(1) << 34) +/* Outer Masks. */ #define MLX5_FLOW_LAYER_OUTER_L3 \ (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6)
drivers/net/mlx5/mlx5_flow_dv.c +51 -0
63 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 16/17 net/mlx5: add support of CT between two ports
In reply to Bing ZhaoAfter creating a connection tracking context, it can be used between two ports. For each port, the flow for one direction traffic will be created.
The context can only be shared between the owner port and the peer port that was specified when being created. Only the owner port could update the context or query it in current implementation.
--- drivers/net/mlx5/mlx5_flow.h | 57 +++++++++++++++++++++++++- drivers/net/mlx5/mlx5_flow_dv.c | 71 +++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 18 deletions(-)
drivers/net/mlx5/mlx5_flow.h +55 -2
@@ -48,6 +48,25 @@ enum { MLX5_INDIRECT_ACTION_TYPE_CT, }; +/* Now, the maximal ports will be supported is 256, action number is 4M. */ +#define MLX5_INDIRECT_ACT_CT_MAX_PORT 0x100 + +#define MLX5_INDIRECT_ACT_CT_OWNER_SHIFT 22 +#define MLX5_INDIRECT_ACT_CT_OWNER_MASK (MLX5_INDIRECT_ACT_CT_MAX_PORT - 1) + +/* 30-31: type, 22-29: owner port, 0-21: index. */ +#define MLX5_INDIRECT_ACT_CT_GEN_IDX (owner, index) \ + ((MLX5_INDIRECT_ACTION_TYPE_CT << MLX5_INDIRECT_ACTION_TYPE_OFFSET) | \ + (((owner) & MLX5_INDIRECT_ACT_CT_OWNER_MASK) << \ + MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) | (index)) + +#define MLX5_INDIRECT_ACT_CT_GET_OWNER (index) \ + (((index) >> MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) & \ + MLX5_INDIRECT_ACT_CT_OWNER_MASK) + +#define MLX5_INDIRECT_ACT_CT_GET_IDX (index) \ + ((index) & ((1 << MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) - 1)) +/* Matches on selected register. */ struct mlx5_rte_flow_item_tag {enum modify_reg id;
@@ -1304,7 +1323,7 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx) }/* -* Get ASO CT action by index. +* Get ASO CT action by device and index. * * @param[in] dev * Pointer to the Ethernet device structure.
@@ -1315,7 +1334,7 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)* The specified ASO CT action pointer. */ static inline struct mlx5_aso_ct_action * -flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +flow_aso_ct_get_by_dev_idx (struct rte_eth_dev *dev,uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
@@ -1330,6 +1349,40 @@ flow_aso_ct_get_by_idx(struct rte_eth_dev *dev, uint32_t idx)return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; } +/* +* Get ASO CT action by owner & index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action and owner port combination. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t own_idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +uint16_t owner = (uint16_t )MLX5_INDIRECT_ACT_CT_GET_OWNER (own_idx); +uint32_t idx =MLX5_INDIRECT_ACT_CT_GET_IDX (own_idx); + +if (owner ==PORT_ID (priv)) { + ct =flow_aso_ct_get_by_dev_idx (dev, idx); + }else { +struct rte_eth_dev *owndev = &rte_eth_devices[owner]; + +MLX5_ASSERT (owner <RTE_MAX_ETHPORTS ); +if (dev->data->dev_started !=1 ) +return NULL ; + ct =flow_aso_ct_get_by_dev_idx (owndev, idx); +if (ct->peer !=PORT_ID (priv)) +return NULL ; + } +return ct; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +55 -16
165 lines not on this page · raw message
Signature · 1 line
2.27.0
v3 cover conntrack support in mlx5 PMD
In reply to Bing ZhaoThis patch set adds the connection tracking offload support in the mlx5 driver, as well as the documents update.
---
v2: code bug fixes, commits clean up and doc update.
v3: fix error input pointer for CT MR registering
---
Bing Zhao (17):
common/mlx5: add connection tracking object definition common/mlx5: add CT offload capability checking net/mlx5: use meter color reg for CT net/mlx5: initialization of CT management common/mlx5: add Dexv CT objects creation net/mlx5: add modify support for CT
net/mlx5: add actions creating for CT net/mlx5: close CT management structure net/mlx5: add ASO CT query implementation net/mlx5: add ASO CT destroy handling net/mlx5: add translation of CT action net/mlx5: add translation of CT item net/mlx5: add CT context update
net/mlx5: validation of CT action
net/mlx5: validation of CT item
net/mlx5: add support of CT between two ports
doc: update mlx5 support for conntrack
doc/guides/nics/features/default.ini | 1 + doc/guides/nics/features/mlx5.ini | 1 + doc/guides/nics/mlx5.rst | 14 + doc/guides/rel_notes/release_21_05.rst | 2 + drivers/common/mlx5/linux/meson.build | 2 + drivers/common/mlx5/mlx5_devx_cmds.c | 53 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 5 + drivers/common/mlx5/mlx5_prm.h | 88 ++++ drivers/common/mlx5/version.map | 1 + drivers/net/mlx5/linux/mlx5_os.c | 13 + drivers/net/mlx5/mlx5.c | 92 ++++ drivers/net/mlx5/mlx5.h | 76 ++++ drivers/net/mlx5/mlx5_flow.c | 44 +- drivers/net/mlx5/mlx5_flow.h | 101 ++++- drivers/net/mlx5/mlx5_flow_aso.c | 592 ++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 601 ++++++++++++++++++++++++- 16 files changed, 1683 insertions(+), 3 deletions(-)
Signature · 1 line
2.27.0
PATCH v3 1/17 common/mlx5: add connection tracking object definition
The structures of ASO connection tracking offload object are added based on the definitions in the PRM. One CT object context will be loaded into the cache completely in a reversed order of dwords. The valid bit should be the MSB of the last dword. This is used for the conntrack context creation and update, as well as for the query.
The capabilities 2 (HCA_CAP_2) layout is also added. The connection tracking related capabilities could be queried via the HCA_CAP_2.
--- drivers/common/mlx5/mlx5_prm.h | 85 ++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
drivers/common/mlx5/mlx5_prm.h +85 -0
@@ -1119,6 +1119,7 @@ enum {MLX5_GET_HCA_CAP_OP_MOD_ROCE =0x4 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE =0x7 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_VDPA_EMULATION =0x13 <<1 , + MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE_2 = 0x20 << 1, };#define MLX5_GENERAL_OBJ_TYPES_CAP_VIRTQ_NET_Q \
@@ -1661,6 +1662,29 @@ struct mlx5_ifc_flow_table_nic_cap_bits {struct mlx5_ifc_flow_table_prop_layout_bits flow_table_properties; }; +struct mlx5_ifc_cmd_hca_cap_2_bits { +u8 reserved_at_0[0x80 ];/* End of DW4. */ +u8 reserved_at_80[0xb ]; +u8 log_max_num_reserved_qpn[0x5 ]; +u8 reserved_at_90[0x3 ]; +u8 log_reserved_qpn_granularity[0x5 ]; +u8 reserved_at_98[0x3 ]; +u8 log_reserved_qpn_max_alloc[0x5 ];/* End of DW5. */ +u8 max_reformat_insert_size[0x8 ]; +u8 max_reformat_insert_offset[0x8 ]; +u8 max_reformat_remove_size[0x8 ]; +u8 max_reformat_remove_offset[0x8 ];/* End of DW6. */ +u8 aso_conntrack_reg_id[0x8 ]; +u8 reserved_at_c8[0x3 ]; +u8 log_conn_track_granularity[0x5 ]; +u8 reserved_at_d0[0x3 ]; +u8 log_conn_track_max_alloc[0x5 ]; +u8 reserved_at_d8[0x3 ]; +u8 log_max_conn_track_offload[0x5 ]; +u8 reserved_at_e0[0x20 ];/* End of DW7. */ +u8 reserved_at_100[0x700 ]; +}; +union mlx5_ifc_hca_cap_union_bits {struct mlx5_ifc_cmd_hca_cap_bits cmd_hca_cap;struct mlx5_ifc_per_protocol_networking_offload_caps_bits
@@ -2599,6 +2623,67 @@ struct mlx5_ifc_create_flow_meter_aso_in_bits {struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr;struct mlx5_ifc_flow_meter_aso_bits flow_meter_aso; }; + +struct mlx5_ifc_tcp_window_params_bits { +u8 max_ack[0x20 ]; +u8 max_win[0x20 ]; +u8 reply_end[0x20 ]; +u8 sent_end[0x20 ]; +}; + +struct mlx5_ifc_conn_track_aso_bits { +struct mlx5_ifc_tcp_window_params_bits reply_dir;/* End of DW3. */ +struct mlx5_ifc_tcp_window_params_bits original_dir;/* End of DW7. */ +u8 last_end[0x20 ];/* End of DW8. */ +u8 last_ack[0x20 ];/* End of DW9. */ +u8 last_seq[0x20 ];/* End of DW10. */ +u8 last_win[0x10 ]; +u8 reserved_at_170[0xa ]; +u8 last_dir[0x1 ]; +u8 last_index[0x5 ];/* End of DW11. */ +u8 reserved_at_180[0x40 ];/* End of DW13. */ +u8 reply_direction_tcp_scale[0x4 ]; +u8 reply_direction_tcp_close_initiated[0x1 ]; +u8 reply_direction_tcp_liberal_enabled[0x1 ]; +u8 reply_direction_tcp_data_unacked[0x1 ]; +u8 reply_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1c8[0x8 ]; +u8 original_direction_tcp_scale[0x4 ]; +u8 original_direction_tcp_close_initiated[0x1 ]; +u8 original_direction_tcp_liberal_enabled[0x1 ]; +u8 original_direction_tcp_data_unacked[0x1 ]; +u8 original_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1d8[0x8 ];/* End of DW14. */ +u8 valid[0x1 ]; +u8 state[0x3 ]; +u8 freeze_track[0x1 ]; +u8 reserved_at_1e5[0xb ]; +u8 reserved_at_1f0[0x1 ]; +u8 connection_assured[0x1 ]; +u8 sack_permitted[0x1 ]; +u8 challenged_acked[0x1 ]; +u8 heartbeat[0x1 ]; +u8 max_ack_window[0x3 ]; +u8 reserved_at_1f8[0x1 ]; +u8 retransmission_counter[0x3 ]; +u8 retranmission_limit_exceeded[0x1 ]; +u8 retranmission_limit[0x3 ];/* End of DW15. */ +}; + +struct mlx5_ifc_conn_track_offload_bits { +u8 modify_field_select[0x40 ]; +u8 reserved_at_40[0x40 ]; +u8 reserved_at_80[0x8 ]; +u8 conn_track_aso_access_pd[0x18 ]; +u8 reserved_at_a0[0x160 ]; +struct mlx5_ifc_conn_track_aso_bits conn_track_aso; +}; + +struct mlx5_ifc_create_conn_track_aso_in_bits { +struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr; +struct mlx5_ifc_conn_track_offload_bits conn_track_offload; +}; +enum mlx5_access_aso_opc_mod {ASO_OPC_MOD_IPSEC =0x0 ,ASO_OPC_MOD_CONNECTION_TRACKING =0x1 ,
Signature · 1 line
2.27.0
PATCH v3 2/17 common/mlx5: add CT offload capability checking
In reply to Bing ZhaoDuring startup, the ASO connection tracking offload capability could be queried via HCA_CAP_QUERY command. If the HW doesn't support ASO CT, the value would be 0 by default. The following initialization should be skipped and the creation of the CT object should return a failure directly.
The following CT creation should also check this capability. With the old driver, the pre-processing macro should be used in order to make the compiling pass.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/mlx5_devx_cmds.c | 3 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 3 +++ 4 files changed, 9 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -189,6 +189,8 @@ has_sym_args = [ 'MLX5_WQE_UMR_CTRL_FLAG_INLINE' ], [ 'HAVE_MLX5_DR_FLOW_DUMP_RULE', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_rule' ], + [ 'HAVE_MLX5_DR_ACTION_ASO_CT', 'infiniband/mlx5dv.h', + 'MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR' ], ] config = configuration_data() foreach arg:has_sym_args
drivers/common/mlx5/mlx5_devx_cmds.c +3 -0
@@ -760,6 +760,9 @@ mlx5_devx_cmd_query_hca_attr(void *ctx,MLX5_GET (cmd_hca_cap, hcattr, umr_indirect_mkey_disabled); attr->umr_modify_entity_size_disabled =MLX5_GET (cmd_hca_cap, hcattr, umr_modify_entity_size_disabled); + attr->ct_offload = !!(MLX5_GET64 (cmd_hca_cap, hcattr, + general_obj_types) & +MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD );if (attr->qos.sup) { MLX5_SET(query_hca_cap_in, in, op_mod, MLX5_GET_HCA_CAP_OP_MOD_QOS_CAP |
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -137,6 +137,7 @@ struct mlx5_hca_attr { uint32_t qp_ts_format:2; uint32_t regex:1; uint32_t reg_c_preserve:1; + uint32_t ct_offload:1; /* General obj type ASO CT offload supported. */uint32_t regexp_num_of_engines; uint32_t log_max_ft_sampler_num:8;uint32_t geneve_tlv_opt;
drivers/common/mlx5/mlx5_prm.h +3 -0
@@ -1134,6 +1134,8 @@ enum { (1ULL << MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO)#define MLX5_GENERAL_OBJ_TYPES_CAP_GENEVE_TLV_OPT \ (1ULL << MLX5_OBJ_TYPE_GENEVE_TLV_OPT) +#define MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD \ + (1ULL << MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD)enum {MLX5_HCA_CAP_OPMOD_GET_MAX =0 ,
@@ -2456,6 +2458,7 @@ enum {MLX5_GENERAL_OBJ_TYPE_FLEX_PARSE_GRAPH =0x0022 ,MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO =0x0024 ,MLX5_GENERAL_OBJ_TYPE_FLOW_HIT_ASO =0x0025 , + MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD = 0x0031, }; struct mlx5_ifc_general_obj_in_cmd_hdr_bits {
Signature · 1 line
2.27.0
PATCH v3 3/17 net/mlx5: use meter color reg for CT
In reply to Bing ZhaoBased on the capacity, 3 registers could be used. Due to the register allocation, only the one REG_C_3 for meter color could be reused right now.
Then in the same flow, no more than one ASO action can be supported.
--- drivers/net/mlx5/mlx5_flow.c | 4 +++- drivers/net/mlx5/mlx5_flow.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow.c +3 -1
@@ -760,7 +760,9 @@ mlx5_flow_get_reg_id(struct rte_eth_dev *dev,return priv->mtr_color_reg !=REG_C_2 ?REG_C_2 :REG_C_3 ;case MLX5_MTR_COLOR : -case MLX5_ASO_FLOW_HIT :/* Both features use the same REG_C. */ +case MLX5_ASO_FLOW_HIT : +case MLX5_ASO_CONNTRACK : +/* All features use the same REG_C. */ MLX5_ASSERT (priv->mtr_color_reg !=REG_NON );return priv->mtr_color_reg;case MLX5_COPY_MARK :
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -84,6 +84,7 @@ enum mlx5_feature_name {MLX5_MTR_COLOR ,MLX5_MTR_ID ,MLX5_ASO_FLOW_HIT , + MLX5_ASO_CONNTRACK, };/* Default queue number. */
Signature · 1 line
2.27.0
PATCH v3 4/17 net/mlx5: initialization of CT management
In reply to Bing ZhaoThe definitions of ASO connection tracking objects management structures are added.
Considering performance, the bulk allocation of ASO CT objects should be used. The maximal value per bulk and the granularity could be fetched from HCA capabilities 2. Right now, a fixed number of 64 is used for each bulk for a better management purpose.
The ASO QP for CT is initialized, the SQ will be used for both modify and query command.
--- drivers/net/mlx5/linux/mlx5_os.c | 13 +++++++++ drivers/net/mlx5/mlx5.c | 36 +++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 50 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 50 ++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +13 -0
@@ -1323,6 +1323,19 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,DRV_LOG (DEBUG ,"Flow Hit ASO is supported." ); }#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */ +#if defined(HAVE_MLX5_DR_CREATE_ACTION_ASO ) && \ + defined(HAVE_MLX5_DR_ACTION_ASO_CT ) +if (config->hca_attr.ct_offload && + priv->mtr_color_reg ==REG_C_3 ) { + err =mlx5_flow_aso_ct_mng_init (sh); +if (err) { + err = -err; + goto error; + } +DRV_LOG (DEBUG ,"CT ASO is supported." ); + sh->ct_aso_en =1 ; + } +#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO && HAVE_MLX5_DR_ACTION_ASO_CT */ #if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE )if (config->hca_attr.log_max_ft_sampler_num >0 && config->dv_flow_en) {
drivers/net/mlx5/mlx5.c +36 -0
@@ -670,6 +670,42 @@ mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh) } } +/* +* Initialize the ASO connection tracking structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_flow_aso_ct_mng_init (struct mlx5_dev_ctx_shared *sh) +{ +int err; + +if (sh->ct_mng) +return 0 ; + sh->ct_mng =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*sh->ct_mng), +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +if (!sh->ct_mng) { +DRV_LOG (ERR ,"ASO CT management allocation failed." ); + rte_errno =ENOMEM ; +return -rte_errno; + } + err =mlx5_aso_queue_init (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); +if (err) { +mlx5_free (sh->ct_mng); +/* rte_errno should be extracted from the failure. */ + rte_errno =EINVAL ; +return -rte_errno; + } +rte_spinlock_init (&sh->ct_mng->ct_sl); +rte_rwlock_init (&sh->ct_mng->resize_rwl); +LIST_INIT (&sh->ct_mng->free_cts); +return 0 ; +} +/** * Initialize the flow resources' indexed mempool. *
drivers/net/mlx5/mlx5.h +50 -0
74 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_aso.c +50 -0
62 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 5/17 common/mlx5: add Dexv CT objects creation
In reply to Bing ZhaoAdding support for connection tracking ASO creation via Devx command. Right now only bulk creation is supported.
By default, the objects with zero contents will be created. Before using a single object, the modification via posting a WQE to the ASO CT SQ is needed.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 50 ++++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 4 +++ drivers/common/mlx5/version.map | 1 + 3 files changed, 55 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +50 -0
@@ -2232,6 +2232,56 @@ mlx5_devx_cmd_create_flow_meter_aso_obj(void *ctx, uint32_t pd,return flow_meter_aso_obj; } +/* +* Create general object of type CONN_TRACK_OFFLOAD using DevX API. +* +* @param[in] ctx +* Context returned from mlx5 open_device() glue function. +* @param [in] pd +* PD value to associate the CONN_TRACK_OFFLOAD ASO object with. +* @param [in] log_obj_size +* log_obj_size to allocate its power of 2 * objects +* in one CONN_TRACK_OFFLOAD bulk allocation. +* +* @return +* The DevX object created, NULL otherwise and rte_errno is set. +*/ +struct mlx5_devx_obj * +mlx5_devx_cmd_create_conn_track_offload_obj (void *ctx,uint32_t pd, +uint32_t log_obj_size) +{ +uint32_t in[MLX5_ST_SZ_DW (create_conn_track_aso_in)] = {0 }; +uint32_t out[MLX5_ST_SZ_DW (general_obj_out_cmd_hdr)]; +struct mlx5_devx_obj *ct_aso_obj; +void *ptr; + + ct_aso_obj =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*ct_aso_obj), +0 ,SOCKET_ID_ANY ); +if (!ct_aso_obj) { +DRV_LOG (ERR ,"Failed to allocate CONN_TRACK_OFFLOAD object." ); + rte_errno =ENOMEM ; +return NULL ; + } + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, hdr); +MLX5_SET (general_obj_in_cmd_hdr, ptr, opcode, +MLX5_CMD_OP_CREATE_GENERAL_OBJECT ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, obj_type, +MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, log_obj_range, log_obj_size); + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, conn_track_offload); +MLX5_SET (conn_track_offload, ptr, conn_track_aso_access_pd, pd); + ct_aso_obj->obj = mlx5_glue->devx_obj_create (ctx, in,sizeof (in), + out,sizeof (out)); +if (!ct_aso_obj->obj) { + rte_errno = errno; +DRV_LOG (ERR ,"Failed to create CONN_TRACK_OFFLOAD obj by using DevX." ); +mlx5_free (ct_aso_obj); +return NULL ; + } + ct_aso_obj->id =MLX5_GET (general_obj_out_cmd_hdr, out, obj_id); +return ct_aso_obj; +} +/** * Create general object of type GENEVE TLV option using DevX API. *
drivers/common/mlx5/mlx5_devx_cmds.h +4 -0
@@ -569,6 +569,10 @@ struct mlx5_devx_obj *mlx5_devx_cmd_queue_counter_alloc(void *ctx);__rte_internal int mlx5_devx_cmd_queue_counter_query(struct mlx5_devx_obj *dcs, int clear,uint32_t *out_of_buffers); +__rte_internal +struct mlx5_devx_obj *mlx5_devx_cmd_create_conn_track_offload_obj(void *ctx, +uint32_t pd,uint32_t log_obj_size); +/** * Create general object of type FLOW_METER_ASO using DevX API.. *
drivers/common/mlx5/version.map +1 -0
@@ -13,6 +13,7 @@ INTERNAL { mlx5_dev_to_pci_addr; # WINDOWS_NO_EXPORT mlx5_devx_cmd_alloc_pd; + mlx5_devx_cmd_create_conn_track_offload_obj; mlx5_devx_cmd_create_cq; mlx5_devx_cmd_create_flex_parser; mlx5_devx_cmd_create_qp;
Signature · 1 line
2.27.0
PATCH v3 6/17 net/mlx5: add modify support for CT
In reply to Bing ZhaoAfter the connection tracking object bulk is allocated, all the objects' contents are filled with zero by default. Every new-allocated object must be modified via WQE operation before it is used.
In order to reduce the latency for the flow creation, an asynchronous way is used instead of busy waiting for the CQE to be generated.
--- drivers/net/mlx5/mlx5.h | 8 + drivers/net/mlx5/mlx5_flow.h | 3 + drivers/net/mlx5/mlx5_flow_aso.c | 252 +++++++++++++++++++++++++++++++ 3 files changed, 263 insertions(+)
drivers/net/mlx5/mlx5.h +8 -0
@@ -490,6 +490,7 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; +struct mlx5_aso_ct_action *ct; }; };
@@ -1007,6 +1008,10 @@ struct mlx5_aso_ct_action {bool is_original;/* The direction of the DR action to be used. */ }; +/* CT action object state update. */ +#define MLX5_ASO_CT_UPDATE_STATE (c, s) \ + __atomic_store_n(&((c)->state), (s), __ATOMIC_RELAXED) +/* ASO connection tracking software pool definition. */ struct mlx5_aso_ct_pool {uint16_t index;/* Pool index in pools array. */
@@ -1690,5 +1695,8 @@ int mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh, struct mlx5_aso_mtr *mtr);int mlx5_aso_mtr_wait (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_mtr *mtr); +int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +const struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -45,6 +45,7 @@ enum mlx5_rte_flow_action_type {enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE , +MLX5_INDIRECT_ACTION_TYPE_AGE , };/* Matches on selected register. */
@@ -839,6 +840,8 @@ struct mlx5_flow {#define MLX5_ASO_WQE_CQE_RESPONSE_DELAY 10u#define MLX5_MTR_POLL_WQE_CQE_TIMES 100000u +#define MLX5_CT_POLL_WQE_CQE_TIMES MLX5_MTR_POLL_WQE_CQE_TIMES +#define MLX5_MAN_WIDTH 8/* Legacy Meter parameter structure. */ struct mlx5_legacy_flow_meter {
drivers/net/mlx5/mlx5_flow_aso.c +252 -0
255 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 7/17 net/mlx5: add actions creating for CT
In reply to Bing ZhaoAllocating a CT from the management pools and creating the DR actions for both directions by default.
If there is no available connection tracking action, a new pool will be created with a fixed size bulk allocation. Right now, all the resources are controlled by the linked list.
The ASO connection tracking context associated with these actions need to be updated via WQE before using for steering.
--- drivers/net/mlx5/mlx5.h | 4 + drivers/net/mlx5/mlx5_flow.h | 29 +++- drivers/net/mlx5/mlx5_flow_dv.c | 263 ++++++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +4 -0
@@ -987,6 +987,10 @@ struct mlx5_bond_info {/* Number of connection tracking objects per pool: must be a power of 2. */ #define MLX5_ASO_CT_ACTIONS_PER_POOL 64 +/* Generate incremental and unique CT index from pool and offset. */ +#define MLX5_MAKE_CT_IDX (pool, offset) \ + ((pool) * MLX5_ASO_CT_ACTIONS_PER_POOL + (offset) + 1) +/* ASO Conntrack state. */ enum mlx5_aso_ct_state {ASO_CONNTRACK_FREE ,/* Inactive, in the free list. */
drivers/net/mlx5/mlx5_flow.h +28 -1
@@ -45,7 +45,7 @@ enum mlx5_rte_flow_action_type {enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE , -MLX5_INDIRECT_ACTION_TYPE_AGE , +MLX5_INDIRECT_ACTION_TYPE_CT , };/* Matches on selected register. */
@@ -1288,6 +1288,33 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)return &pool->mtrs[idx %MLX5_ASO_MTRS_PER_POOL ]; } +/* +* Get ASO CT action by index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +struct mlx5_aso_ct_pool *pool; + + idx--; +MLX5_ASSERT ((idx /MLX5_ASO_CT_ACTIONS_PER_POOL ) < mng->n); +/* Bit operation AND could be used. */ +rte_rwlock_read_lock (&mng->resize_rwl); + pool = mng->pools[idx /MLX5_ASO_CT_ACTIONS_PER_POOL ]; +rte_rwlock_read_unlock (&mng->resize_rwl); +return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +263 -0
281 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 8/17 net/mlx5: close CT management structure
In reply to Bing ZhaoWhen freeing the IB shared context during stopping a device, the ASO connection tracking management structure should also be cleaned up.
All the DR actions created should be destroyed. The structures need to be freed and ASO CT QP should be released. In the meanwhile, the allocated and registered memory region for query should also be deregistered and then freed.
--- drivers/net/mlx5/mlx5.c | 56 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 4 +++ 2 files changed, 60 insertions(+)
drivers/net/mlx5/mlx5.c +56 -0
@@ -706,6 +706,60 @@ mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh)return 0 ; } +/* +* Close and release all the resources of the +* ASO connection tracking management structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object to free. +*/ +static void +mlx5_flow_aso_ct_mng_close (struct mlx5_dev_ctx_shared *sh) +{ +struct mlx5_aso_ct_pools_mng *mng = sh->ct_mng; +struct mlx5_aso_ct_pool *ct_pool; +struct mlx5_aso_ct_action *ct; +uint32_t idx; +uint32_t val; +uint32_t cnt; +int i; + +mlx5_aso_queue_uninit (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); + idx = mng->next; +while (idx--) { + cnt =0 ; + ct_pool = mng->pools[idx]; +for (i =0 ; i <MLX5_ASO_CT_ACTIONS_PER_POOL ; i++) { + ct = &ct_pool->actions[i]; + val =__atomic_fetch_sub (&ct->refcnt,1 , + __ATOMIC_RELAXED); +MLX5_ASSERT (val ==1 ); +if (val >1 ) + cnt++; +#ifdef HAVE_MLX5_DR_ACTION_ASO_CT +if (ct->dr_action_orig) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_orig)); +if (ct->dr_action_rply) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_rply)); +#endif + } +claim_zero (mlx5_devx_cmd_destroy (ct_pool->devx_obj)); +if (cnt) { +DRV_LOG (DEBUG ,"%u ASO CT objects are being used in the pool %u" , + cnt, i); + } +mlx5_free (ct_pool); +/* in case of failure. */ + mng->next--; + } +mlx5_free (mng->pools); +mlx5_free (mng); +/* Management structure must be cleared to 0s during allocation. */ + sh->ct_mng =NULL ; +} +/** * Initialize the flow resources' indexed mempool. *
@@ -1508,6 +1562,8 @@ mlx5_dev_close(struct rte_eth_dev *dev)if (priv->mreg_cp_tbl)mlx5_hlist_destroy (priv->mreg_cp_tbl);mlx5_mprq_free_mp (dev); +if (priv->sh->ct_mng) +mlx5_flow_aso_ct_mng_close (priv->sh);mlx5_os_free_shared_dr (priv);if (priv->rss_conf.rss_key !=NULL )mlx5_free (priv->rss_conf.rss_key);
drivers/net/mlx5/mlx5_flow_aso.c +4 -0
@@ -372,6 +372,10 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,case ASO_OPC_MOD_POLICER : sq = &sh->mtrmng->pools_mng.sq;break ; +case ASO_OPC_MOD_CONNECTION_TRACKING : +mlx5_aso_dereg_mr (sh, &sh->ct_mng->aso_sq.mr); + sq = &sh->ct_mng->aso_sq; +break ;default :DRV_LOG (ERR ,"Unknown ASO operation mode" );return ;
Signature · 1 line
2.27.0
PATCH v3 9/17 net/mlx5: add ASO CT query implementation
In reply to Bing ZhaoAfter the connection tracking context is created and being used by the flows, the context will be updated by the HW automatically after a packet passed the CT validation. E.g., the ACK, SEQ, window and state of CT can be updated with both direction traffic.
In order to query the updated contents of this context, a WQE should be posted to the SQ with a return buffer. The data will be filled into the buffer. And the profile will be filled with specific value.
During the execution of query command, the context may be updated. The result of the query command may not be the latest one.
--- drivers/net/mlx5/mlx5.h | 10 +- drivers/net/mlx5/mlx5_flow_aso.c | 245 +++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 19 +++ 3 files changed, 273 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +9 -1
@@ -490,7 +490,10 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; -struct mlx5_aso_ct_action *ct; +struct { +struct mlx5_aso_ct_action *ct; +char *query_data; + }; }; };
@@ -1702,5 +1705,10 @@ int mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,const struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_wait_ready (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct); +int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow_aso.c +245 -0
263 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +19 -0
@@ -13775,6 +13775,8 @@ flow_dv_action_query(struct rte_eth_dev *dev,uint32_t act_idx = (uint32_t )(uintptr_t )handle;uint32_t type = act_idx >>MLX5_INDIRECT_ACTION_TYPE_OFFSET ;uint32_t idx = act_idx & ((1u <<MLX5_INDIRECT_ACTION_TYPE_OFFSET ) -1 ); +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct;switch (type) {case MLX5_INDIRECT_ACTION_TYPE_AGE :
@@ -13788,6 +13790,23 @@ flow_dv_action_query(struct rte_eth_dev *dev, resp->sec_since_last_hit =__atomic_load_n (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,EFAULT , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + ((struct rte_flow_action_conntrack *)data)->peer_port = + ct->peer; + ((struct rte_flow_action_conntrack *)data)->is_original_dir = + ct->is_original; +if (mlx5_aso_ct_query_by_wqe (priv->sh, ct, data)) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to query CT context" ); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v3 10/17 net/mlx5: add ASO CT destroy handling
In reply to Bing ZhaoWhen trying to destroy an ASO connection tracking context, the DR action created on this context should also be destroyed. Before inserting the related software object into the management free list, the reference count should be checked.
Right now, the context object will not be freed to the system and will be reused directly from the free list.
--- drivers/net/mlx5/mlx5_flow_dv.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +15 -1
@@ -11136,9 +11136,15 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +uint32_t ret;struct mlx5_aso_ct_action *ct =flow_aso_ct_get_by_idx (dev, idx); -uint32_t ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED); +enum mlx5_aso_ct_state state = +__atomic_load_n (&ct->state, __ATOMIC_RELAXED); +/* Cannot release when CT is in the ASO SQ. */ +if (state ==ASO_CONNTRACK_WAIT || state ==ASO_CONNTRACK_QUERY ) +return -1 ; + ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED);if (!ret) {if (ct->dr_action_orig) {#ifdef HAVE_MLX5_DR_ACTION_ASO_CT
@@ -11154,6 +11160,8 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx)#endif ct->dr_action_rply =NULL ; } +/* Clear the state to free, no need in 1st allocation. */ +MLX5_ASO_CT_UPDATE_STATE (ct,ASO_CONNTRACK_FREE );rte_spinlock_lock (&mng->ct_sl);LIST_INSERT_HEAD (&mng->free_cts, ct, next);rte_spinlock_unlock (&mng->ct_sl);
@@ -13648,6 +13656,12 @@ flow_dv_action_destroy(struct rte_eth_dev *dev,DRV_LOG (DEBUG ,"Indirect age action %" PRIu32" was" " released with references %d." , idx, ret);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ret =flow_dv_aso_ct_release (dev, idx); +if (ret) +DRV_LOG (DEBUG ,"Connection tracking object %u still " +"has references %d." , idx, ret); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v3 11/17 net/mlx5: add translation of CT action
In reply to Bing ZhaoWhen creating a flow with this action context for CT, it needs to be translated in 2 levels.
First, retrieve from action context to rte_flow action. Second, translate it to the corresponding DR action with traffic direction that was specified when creating or updating via rte_flow_action_handle* API.
Before using the DR action in a flow, the CT context should be available to use in the hardware. A synchronization is done before inserting the flow rule with CT action to check the HW availability of this CT context.
In order to release the DR actions and reuse the context of a CT, the reference count should also be handled in the flow rule destroying.
The CT index will be recorded in the rte_flow by reusing the ASO age index to save memory, since only one ASO action is supported in one flow rule currently. The action context type should also be saved for CT. When destroying a flow rule, if the context type is CT and the index is valid (non-zero), the release process should be handled. By default, the handling will fall back to try to release the ASO age if any.
--- drivers/net/mlx5/mlx5.h | 2 ++ drivers/net/mlx5/mlx5_flow.c | 9 +++++++ drivers/net/mlx5/mlx5_flow.h | 7 +++++- drivers/net/mlx5/mlx5_flow_aso.c | 41 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 28 +++++++++++++++++++++- 5 files changed, 85 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.h +2 -0
@@ -1710,5 +1710,7 @@ int mlx5_aso_ct_wait_ready(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_available (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.c +9 -0
@@ -3553,6 +3553,15 @@ flow_action_handles_translate(struct rte_eth_dev *dev,break ; }/* Fall-through */ +case MLX5_INDIRECT_ACTION_TYPE_CT : +if (priv->sh->ct_aso_en) { + translated[handle->index].type = +RTE_FLOW_ACTION_TYPE_CONNTRACK ; + translated[handle->index].conf = + (void *)(uintptr_t )idx; +break ; + } +/* Fall-through */ default :mlx5_free (translated);return rte_flow_error_set
drivers/net/mlx5/mlx5_flow.h +6 -1
@@ -226,6 +226,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)#define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40) +#define MLX5_FLOW_ACTION_CT (1ull << 41)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
@@ -969,11 +970,15 @@ struct rte_flow { uint32_t drv_type:2; /**< Driver type. */ uint32_t tunnel:1; uint32_t meter:24; /**< Holds flow meter id. */ + uint32_t indirect_type:2; /**< Indirect action type. */uint32_t rix_mreg_copy;/**< Index to metadata register copy table resource. */ uint32_t counter;/**< Holds flow counter. */ uint32_t tunnel_id;/**< Tunnel id */ -uint32_t age;/**< Holds ASO age bit index. */ +union { +uint32_t age;/**< Holds ASO age bit index. */ +uint32_t ct;/**< Holds ASO CT index. */ + };uint32_t geneve_tlv_option;/**< Holds Geneve TLV option id. > */ } __rte_packed;
drivers/net/mlx5/mlx5_flow_aso.c +41 -0
44 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +27 -1
@@ -11381,6 +11381,7 @@ flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,return rte_flow_error_set (error,EBUSY ,RTE_FLOW_ERROR_TYPE_ACTION ,NULL ,"Failed to update CT" ); + ct->is_original = !!pro->is_original_dir;return idx; }
@@ -11544,6 +11545,8 @@ flow_dv_translate(struct rte_eth_dev *dev,const struct rte_flow_action *found_action =NULL ;uint32_t jump_group =0 ;struct mlx5_flow_counter *cnt; +uint32_t ct_idx; +struct mlx5_aso_ct_action *ct;if (!mlx5_flow_os_action_supported (action_type)) return rte_flow_error_set(error, ENOTSUP,
@@ -12017,6 +12020,26 @@ flow_dv_translate(struct rte_eth_dev *dev,return -rte_errno; action_flags |=MLX5_FLOW_ACTION_MODIFY_FIELD ;break ; +case RTE_FLOW_ACTION_TYPE_CONNTRACK : + ct_idx = (uint32_t )(uintptr_t )action->conf; + ct =flow_aso_ct_get_by_idx (dev, ct_idx); +if (mlx5_aso_ct_available (priv->sh, ct)) +return rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_ACTION , +NULL , +"CT is unavailable." ); +if (ct->is_original) + dev_flow->dv.actions[actions_n] = + ct->dr_action_orig; +else + dev_flow->dv.actions[actions_n] = + ct->dr_action_rply; + flow->indirect_type =MLX5_INDIRECT_ACTION_TYPE_CT ; + flow->ct = ct_idx; +__atomic_fetch_add (&ct->refcnt,1 , __ATOMIC_RELAXED); + actions_n++; + action_flags |=MLX5_FLOW_ACTION_CT ; +break ;case RTE_FLOW_ACTION_TYPE_END : actions_end = true;if (mhdr_res->actions_num) {
@@ -13152,7 +13175,10 @@ flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)mlx5_flow_meter_detach (priv, fm); flow->meter =0 ; } -if (flow->age) +/* Keep the current age handling by default. */ +if (flow->indirect_type ==MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct) +flow_dv_aso_ct_release (dev, flow->ct); +else if (flow->age)flow_dv_aso_age_release (dev, flow->age);if (flow->geneve_tlv_option) {flow_dv_geneve_tlv_option_resource_release (dev);
Signature · 1 line
2.27.0
PATCH v3 12/17 net/mlx5: add translation of CT item
In reply to Bing ZhaoThe return register of the DR action will be used for matching. After the ASO CT checking of a TCP packet, the syndrome is filled in the register. Only the 8 LSB should be used. A converting from RTE_FLOW_CONNTRACK_FLAG* to the syndrome should be done after checing the spec and mask fields.
--- drivers/net/mlx5/mlx5_flow.h | 7 ++++ drivers/net/mlx5/mlx5_flow_dv.c | 62 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
drivers/net/mlx5/mlx5_flow.h +7 -0
@@ -405,6 +405,13 @@ enum mlx5_feature_name {/* Maximum number of fields to modify in MODIFY_FIELD */ #define MLX5_ACT_MAX_MOD_FIELDS 5 +/* Syndrome bits definition for connection tracking. */ +#define MLX5_CT_SYNDROME_VALID (0x0 << 6) +#define MLX5_CT_SYNDROME_INVALID (0x1 << 6) +#define MLX5_CT_SYNDROME_TRAP (0x2 << 6) +#define MLX5_CT_SYNDROME_STATE_CHANGE (0x1 << 1) +#define MLX5_CT_SYNDROME_BAD_PACKET (0x1 << 0) +enum mlx5_flow_drv_type {MLX5_FLOW_TYPE_MIN ,MLX5_FLOW_TYPE_DV ,
drivers/net/mlx5/mlx5_flow_dv.c +62 -0
74 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 13/17 net/mlx5: add CT context update
In reply to Bing ZhaoWhen updating a connection tracking context, two separate parts could be updated.
First, the direction. This will only update the traffic direction recorded in the software for flow creation.
Second, the TCP parameters. The hardware context will be updated via the WQE. This update will be blocked until the hardware status is updated and ready for the next flow creation.
--- drivers/net/mlx5/mlx5_flow_dv.c | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
drivers/net/mlx5/mlx5_flow_dv.c +56 -0
@@ -13824,6 +13824,60 @@ __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,return ret; } +/* +* Updates in place conntrack context or direction. +* Context update should be synchronized. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* The conntrack object ID to be updated. +* @param[in] update +* Pointer to the structure of information to update. +* @param[out] error +* Perform verbose error reporting if not NULL. Initialized in case of +* error only. +* +* @return +* 0 on success, otherwise negative errno value. +*/ +static int +__flow_dv_action_ct_update (struct rte_eth_dev *dev,uint32_t idx, +const struct rte_flow_modify_conntrack *update, +struct rte_flow_error *error) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +const struct rte_flow_action_conntrack *new_prf; +int ret =0 ; + + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,ENOMEM , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + new_prf = &update->new_ct; +if (update->direction) + ct->is_original = !!new_prf->is_original_dir; +if (update->state) { + ret =mlx5_aso_ct_update_by_wqe (priv->sh, ct, new_prf); +if (ret) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to send CT context update WQE" ); +/* Block until ready or a failure. */ + ret =mlx5_aso_ct_available (priv->sh, ct); +if (ret) +rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Timeout to get the CT update" ); + } +return ret; +} +/** * Updates in place shared action configuration, lock free, * (mutex should be acquired by caller).
@@ -13859,6 +13913,8 @@ flow_dv_action_update(struct rte_eth_dev *dev,case MLX5_INDIRECT_ACTION_TYPE_RSS : action_conf = ((const struct rte_flow_action *)update)->conf;return __flow_dv_action_rss_update (dev, idx, action_conf, err); +case MLX5_INDIRECT_ACTION_TYPE_CT : +return __flow_dv_action_ct_update (dev, idx, update, err);default : return rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v3 14/17 net/mlx5: validation of CT action
In reply to Bing ZhaoThe validation of a CT action contains two parts. The first is the CT action configurations parameter. When creating a CT action context, some members need to be verified.
The second is that when creating a flow, the DR action of CT should be validated with other actions and items as well. Currently, only the TCP protocol support connection tracking.
--- drivers/net/mlx5/mlx5.h | 4 ++ drivers/net/mlx5/mlx5_flow.c | 31 +++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 69 +++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+)
drivers/net/mlx5/mlx5.h +4 -0
@@ -1611,6 +1611,10 @@ int mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow,void mlx5_flow_rxq_dynf_metadata_set (struct rte_eth_dev *dev);int mlx5_flow_get_aged_flows (struct rte_eth_dev *dev,void **contexts,uint32_t nb_contexts,struct rte_flow_error *error); +int mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error); +/* mlx5_mp_os.c */
drivers/net/mlx5/mlx5_flow.c +31 -0
@@ -1688,6 +1688,37 @@ mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,return 0 ; } +/* +* Validate the ASO CT action. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] conntrack +* Pointer to the CT action profile. +* @param[out] error +* Pointer to error structure. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error) +{ +RTE_SET_USED (dev); + +if (conntrack->state >RTE_FLOW_CONNTRACK_STATE_TIME_WAIT ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid CT state" ); +if (conntrack->last_index >RTE_FLOW_CONNTRACK_FLAG_RST ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid last TCP packet flag" ); +return 0 ; +} +/** * Verify the @p attributes will be correctly understood by the NIC and store * them in the @p flow if everything is correct.
drivers/net/mlx5/mlx5_flow_dv.c +69 -0
93 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 15/17 net/mlx5: validation of CT item
In reply to Bing ZhaoThe item of ASO connection tracking will be translated into the register value when matching. The validation of this item has no dependency on other layers, since the flow including this item should be jumped from another group. All the layers checking was already done in the previous groups. Only the state bits conflict should be checked.
It is assumed that the flow with CT item will always work on the TCP traffic.
--- drivers/net/mlx5/mlx5_flow.h | 3 ++ drivers/net/mlx5/mlx5_flow_dv.c | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -147,6 +147,9 @@ enum mlx5_feature_name {#define MLX5_FLOW_LAYER_GENEVE_OPT (UINT64_C(1) << 32)#define MLX5_FLOW_LAYER_GTP_PSC (UINT64_C(1) << 33) +/* Conntrack item. */ +#define MLX5_FLOW_LAYER_ASO_CT (UINT64_C(1) << 34) +/* Outer Masks. */ #define MLX5_FLOW_LAYER_OUTER_L3 \ (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6)
drivers/net/mlx5/mlx5_flow_dv.c +51 -0
63 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 16/17 net/mlx5: add support of CT between two ports
In reply to Bing ZhaoAfter creating a connection tracking context, it can be used between two ports. For each port, the flow for one direction traffic will be created.
The context can only be shared between the owner port and the peer port that was specified when being created. Only the owner port could update the context or query it in current implementation.
--- drivers/net/mlx5/mlx5_flow.h | 57 +++++++++++++++++++++++++- drivers/net/mlx5/mlx5_flow_dv.c | 71 +++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 18 deletions(-)
drivers/net/mlx5/mlx5_flow.h +55 -2
@@ -48,6 +48,25 @@ enum { MLX5_INDIRECT_ACTION_TYPE_CT, }; +/* Now, the maximal ports will be supported is 256, action number is 4M. */ +#define MLX5_INDIRECT_ACT_CT_MAX_PORT 0x100 + +#define MLX5_INDIRECT_ACT_CT_OWNER_SHIFT 22 +#define MLX5_INDIRECT_ACT_CT_OWNER_MASK (MLX5_INDIRECT_ACT_CT_MAX_PORT - 1) + +/* 30-31: type, 22-29: owner port, 0-21: index. */ +#define MLX5_INDIRECT_ACT_CT_GEN_IDX (owner, index) \ + ((MLX5_INDIRECT_ACTION_TYPE_CT << MLX5_INDIRECT_ACTION_TYPE_OFFSET) | \ + (((owner) & MLX5_INDIRECT_ACT_CT_OWNER_MASK) << \ + MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) | (index)) + +#define MLX5_INDIRECT_ACT_CT_GET_OWNER (index) \ + (((index) >> MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) & \ + MLX5_INDIRECT_ACT_CT_OWNER_MASK) + +#define MLX5_INDIRECT_ACT_CT_GET_IDX (index) \ + ((index) & ((1 << MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) - 1)) +/* Matches on selected register. */ struct mlx5_rte_flow_item_tag {enum modify_reg id;
@@ -1304,7 +1323,7 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx) }/* -* Get ASO CT action by index. +* Get ASO CT action by device and index. * * @param[in] dev * Pointer to the Ethernet device structure.
@@ -1315,7 +1334,7 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)* The specified ASO CT action pointer. */ static inline struct mlx5_aso_ct_action * -flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +flow_aso_ct_get_by_dev_idx (struct rte_eth_dev *dev,uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
@@ -1330,6 +1349,40 @@ flow_aso_ct_get_by_idx(struct rte_eth_dev *dev, uint32_t idx)return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; } +/* +* Get ASO CT action by owner & index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action and owner port combination. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t own_idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +uint16_t owner = (uint16_t )MLX5_INDIRECT_ACT_CT_GET_OWNER (own_idx); +uint32_t idx =MLX5_INDIRECT_ACT_CT_GET_IDX (own_idx); + +if (owner ==PORT_ID (priv)) { + ct =flow_aso_ct_get_by_dev_idx (dev, idx); + }else { +struct rte_eth_dev *owndev = &rte_eth_devices[owner]; + +MLX5_ASSERT (owner <RTE_MAX_ETHPORTS ); +if (dev->data->dev_started !=1 ) +return NULL ; + ct =flow_aso_ct_get_by_dev_idx (owndev, idx); +if (ct->peer !=PORT_ID (priv)) +return NULL ; + } +return ct; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +55 -16
165 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 17/17 doc: update mlx5 support for conntrack
In reply to Bing ZhaoIn the release notes and mlx5 NIC document, the support and limitation of connection tracking are added.
--- doc/guides/nics/features/default.ini | 1 + doc/guides/nics/features/mlx5.ini | 1 + doc/guides/nics/mlx5.rst | 14 ++++++++++++++ doc/guides/rel_notes/release_21_05.rst | 2 ++ 4 files changed, 18 insertions(+)
doc/guides/nics/features/default.ini +1 -0
@@ -66,6 +66,7 @@ Module EEPROM dump = Registers dump = LED = Multiprocess aware = +Connection tracking = FreeBSD = Linux = Windows =
doc/guides/nics/features/mlx5.ini +1 -0
@@ -45,6 +45,7 @@ Stats per queue = Y FW version = Y Module EEPROM dump = Y Multiprocess aware = Y +Connection tracking = Y Linux = Y Windows = P ARMv8 = Y
doc/guides/nics/mlx5.rst +14 -0
@@ -107,6 +107,7 @@ Features - 21844 flow priorities for ingress or egress flow groups greater than 0 and for any transfer flow group. - Flow metering, including meter policy API. +- Connection tracking. Limitations -----------
@@ -418,6 +419,14 @@ Limitations - RED: must be DROP. - meter profile packet mode is supported. +- Connection tracking: + + - connection tracking (conntrack) couldn't co-exist with ASO meter, ASO age action in a single flow rule. + - Flow rules insertion rate and memory consumption. + - software limitation: + - ports: a maximal number of 256. + - conntrack: a maximal number of 4M. + Statistics ----------
@@ -1680,6 +1689,11 @@ Supported hardware offloads | | | rdma-core 35 | | rdma-core 35 | | | | ConnectX-5 | | ConnectX-5 | +-----------------------+-----------------+-----------------+ + | Connection tracking | | | | DPDK 21.05 | + | | | N/A | | OFED 5.3 | + | | | | | rdma-core 35 | + | | | | | ConnectX-6 Dx | + +-----------------------+-----------------+-----------------+ .. table:: Minimal SW/HW versions for shared action offload :name: sact
doc/guides/rel_notes/release_21_05.rst +2 -0
@@ -166,6 +166,8 @@ New Features * Added support for ASO (Advanced Steering Operation) meter. * Added support for ASO metering by PPS (packet per second). * Added support for the monitor policy of Power Management API. + * Added support for connection tracking action and item as well as context create, + destroy, update and query. * **Updated NXP DPAA driver.**
Signature · 1 line
2.27.0
v4 cover conntrack support in mlx5 PMD
In reply to Bing ZhaoThis patch set adds the connection tracking offload support in the mlx5 driver, as well as the documents update.
---
v2: code bug fixes, commits clean up and doc update.
v3: fix error input pointer for CT MR registering
v4: fix typo in commit message of patch 11
---
Bing Zhao (17):
common/mlx5: add connection tracking object definition common/mlx5: add CT offload capability checking net/mlx5: use meter color reg for CT net/mlx5: initialization of CT management common/mlx5: add Dexv CT objects creation net/mlx5: add modify support for CT
net/mlx5: add actions creating for CT net/mlx5: close CT management structure net/mlx5: add ASO CT query implementation net/mlx5: add ASO CT destroy handling net/mlx5: add translation of CT action net/mlx5: add translation of CT item net/mlx5: add CT context update
net/mlx5: validation of CT action
net/mlx5: validation of CT item
net/mlx5: add support of CT between two ports
doc: update mlx5 support for conntrack
doc/guides/nics/features/default.ini | 1 + doc/guides/nics/features/mlx5.ini | 1 + doc/guides/nics/mlx5.rst | 14 + doc/guides/rel_notes/release_21_05.rst | 2 + drivers/common/mlx5/linux/meson.build | 2 + drivers/common/mlx5/mlx5_devx_cmds.c | 53 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 5 + drivers/common/mlx5/mlx5_prm.h | 88 ++++ drivers/common/mlx5/version.map | 1 + drivers/net/mlx5/linux/mlx5_os.c | 13 + drivers/net/mlx5/mlx5.c | 92 ++++ drivers/net/mlx5/mlx5.h | 76 ++++ drivers/net/mlx5/mlx5_flow.c | 44 +- drivers/net/mlx5/mlx5_flow.h | 101 ++++- drivers/net/mlx5/mlx5_flow_aso.c | 592 ++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 601 ++++++++++++++++++++++++- 16 files changed, 1683 insertions(+), 3 deletions(-)
Signature · 1 line
2.27.0
PATCH v4 1/17 common/mlx5: add connection tracking object definition
The structures of ASO connection tracking offload object are added based on the definitions in the PRM. One CT object context will be loaded into the cache completely in a reversed order of dwords. The valid bit should be the MSB of the last dword. This is used for the conntrack context creation and update, as well as for the query.
The capabilities 2 (HCA_CAP_2) layout is also added. The connection tracking related capabilities could be queried via the HCA_CAP_2.
--- drivers/common/mlx5/mlx5_prm.h | 85 ++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
drivers/common/mlx5/mlx5_prm.h +85 -0
@@ -1119,6 +1119,7 @@ enum {MLX5_GET_HCA_CAP_OP_MOD_ROCE =0x4 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE =0x7 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_VDPA_EMULATION =0x13 <<1 , + MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE_2 = 0x20 << 1, };#define MLX5_GENERAL_OBJ_TYPES_CAP_VIRTQ_NET_Q \
@@ -1661,6 +1662,29 @@ struct mlx5_ifc_flow_table_nic_cap_bits {struct mlx5_ifc_flow_table_prop_layout_bits flow_table_properties; }; +struct mlx5_ifc_cmd_hca_cap_2_bits { +u8 reserved_at_0[0x80 ];/* End of DW4. */ +u8 reserved_at_80[0xb ]; +u8 log_max_num_reserved_qpn[0x5 ]; +u8 reserved_at_90[0x3 ]; +u8 log_reserved_qpn_granularity[0x5 ]; +u8 reserved_at_98[0x3 ]; +u8 log_reserved_qpn_max_alloc[0x5 ];/* End of DW5. */ +u8 max_reformat_insert_size[0x8 ]; +u8 max_reformat_insert_offset[0x8 ]; +u8 max_reformat_remove_size[0x8 ]; +u8 max_reformat_remove_offset[0x8 ];/* End of DW6. */ +u8 aso_conntrack_reg_id[0x8 ]; +u8 reserved_at_c8[0x3 ]; +u8 log_conn_track_granularity[0x5 ]; +u8 reserved_at_d0[0x3 ]; +u8 log_conn_track_max_alloc[0x5 ]; +u8 reserved_at_d8[0x3 ]; +u8 log_max_conn_track_offload[0x5 ]; +u8 reserved_at_e0[0x20 ];/* End of DW7. */ +u8 reserved_at_100[0x700 ]; +}; +union mlx5_ifc_hca_cap_union_bits {struct mlx5_ifc_cmd_hca_cap_bits cmd_hca_cap;struct mlx5_ifc_per_protocol_networking_offload_caps_bits
@@ -2599,6 +2623,67 @@ struct mlx5_ifc_create_flow_meter_aso_in_bits {struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr;struct mlx5_ifc_flow_meter_aso_bits flow_meter_aso; }; + +struct mlx5_ifc_tcp_window_params_bits { +u8 max_ack[0x20 ]; +u8 max_win[0x20 ]; +u8 reply_end[0x20 ]; +u8 sent_end[0x20 ]; +}; + +struct mlx5_ifc_conn_track_aso_bits { +struct mlx5_ifc_tcp_window_params_bits reply_dir;/* End of DW3. */ +struct mlx5_ifc_tcp_window_params_bits original_dir;/* End of DW7. */ +u8 last_end[0x20 ];/* End of DW8. */ +u8 last_ack[0x20 ];/* End of DW9. */ +u8 last_seq[0x20 ];/* End of DW10. */ +u8 last_win[0x10 ]; +u8 reserved_at_170[0xa ]; +u8 last_dir[0x1 ]; +u8 last_index[0x5 ];/* End of DW11. */ +u8 reserved_at_180[0x40 ];/* End of DW13. */ +u8 reply_direction_tcp_scale[0x4 ]; +u8 reply_direction_tcp_close_initiated[0x1 ]; +u8 reply_direction_tcp_liberal_enabled[0x1 ]; +u8 reply_direction_tcp_data_unacked[0x1 ]; +u8 reply_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1c8[0x8 ]; +u8 original_direction_tcp_scale[0x4 ]; +u8 original_direction_tcp_close_initiated[0x1 ]; +u8 original_direction_tcp_liberal_enabled[0x1 ]; +u8 original_direction_tcp_data_unacked[0x1 ]; +u8 original_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1d8[0x8 ];/* End of DW14. */ +u8 valid[0x1 ]; +u8 state[0x3 ]; +u8 freeze_track[0x1 ]; +u8 reserved_at_1e5[0xb ]; +u8 reserved_at_1f0[0x1 ]; +u8 connection_assured[0x1 ]; +u8 sack_permitted[0x1 ]; +u8 challenged_acked[0x1 ]; +u8 heartbeat[0x1 ]; +u8 max_ack_window[0x3 ]; +u8 reserved_at_1f8[0x1 ]; +u8 retransmission_counter[0x3 ]; +u8 retranmission_limit_exceeded[0x1 ]; +u8 retranmission_limit[0x3 ];/* End of DW15. */ +}; + +struct mlx5_ifc_conn_track_offload_bits { +u8 modify_field_select[0x40 ]; +u8 reserved_at_40[0x40 ]; +u8 reserved_at_80[0x8 ]; +u8 conn_track_aso_access_pd[0x18 ]; +u8 reserved_at_a0[0x160 ]; +struct mlx5_ifc_conn_track_aso_bits conn_track_aso; +}; + +struct mlx5_ifc_create_conn_track_aso_in_bits { +struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr; +struct mlx5_ifc_conn_track_offload_bits conn_track_offload; +}; +enum mlx5_access_aso_opc_mod {ASO_OPC_MOD_IPSEC =0x0 ,ASO_OPC_MOD_CONNECTION_TRACKING =0x1 ,
Signature · 1 line
2.27.0
PATCH v4 2/17 common/mlx5: add CT offload capability checking
In reply to Bing ZhaoDuring startup, the ASO connection tracking offload capability could be queried via HCA_CAP_QUERY command. If the HW doesn't support ASO CT, the value would be 0 by default. The following initialization should be skipped and the creation of the CT object should return a failure directly.
The following CT creation should also check this capability. With the old driver, the pre-processing macro should be used in order to make the compiling pass.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/mlx5_devx_cmds.c | 3 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 3 +++ 4 files changed, 9 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -189,6 +189,8 @@ has_sym_args = [ 'MLX5_WQE_UMR_CTRL_FLAG_INLINE' ], [ 'HAVE_MLX5_DR_FLOW_DUMP_RULE', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_rule' ], + [ 'HAVE_MLX5_DR_ACTION_ASO_CT', 'infiniband/mlx5dv.h', + 'MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR' ], ] config = configuration_data() foreach arg:has_sym_args
drivers/common/mlx5/mlx5_devx_cmds.c +3 -0
@@ -760,6 +760,9 @@ mlx5_devx_cmd_query_hca_attr(void *ctx,MLX5_GET (cmd_hca_cap, hcattr, umr_indirect_mkey_disabled); attr->umr_modify_entity_size_disabled =MLX5_GET (cmd_hca_cap, hcattr, umr_modify_entity_size_disabled); + attr->ct_offload = !!(MLX5_GET64 (cmd_hca_cap, hcattr, + general_obj_types) & +MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD );if (attr->qos.sup) { MLX5_SET(query_hca_cap_in, in, op_mod, MLX5_GET_HCA_CAP_OP_MOD_QOS_CAP |
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -137,6 +137,7 @@ struct mlx5_hca_attr { uint32_t qp_ts_format:2; uint32_t regex:1; uint32_t reg_c_preserve:1; + uint32_t ct_offload:1; /* General obj type ASO CT offload supported. */uint32_t regexp_num_of_engines; uint32_t log_max_ft_sampler_num:8;uint32_t geneve_tlv_opt;
drivers/common/mlx5/mlx5_prm.h +3 -0
@@ -1134,6 +1134,8 @@ enum { (1ULL << MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO)#define MLX5_GENERAL_OBJ_TYPES_CAP_GENEVE_TLV_OPT \ (1ULL << MLX5_OBJ_TYPE_GENEVE_TLV_OPT) +#define MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD \ + (1ULL << MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD)enum {MLX5_HCA_CAP_OPMOD_GET_MAX =0 ,
@@ -2456,6 +2458,7 @@ enum {MLX5_GENERAL_OBJ_TYPE_FLEX_PARSE_GRAPH =0x0022 ,MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO =0x0024 ,MLX5_GENERAL_OBJ_TYPE_FLOW_HIT_ASO =0x0025 , + MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD = 0x0031, }; struct mlx5_ifc_general_obj_in_cmd_hdr_bits {
Signature · 1 line
2.27.0
PATCH v4 3/17 net/mlx5: use meter color reg for CT
In reply to Bing ZhaoBased on the capacity, 3 registers could be used. Due to the register allocation, only the one REG_C_3 for meter color could be reused right now.
Then in the same flow, no more than one ASO action can be supported.
--- drivers/net/mlx5/mlx5_flow.c | 4 +++- drivers/net/mlx5/mlx5_flow.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow.c +3 -1
@@ -760,7 +760,9 @@ mlx5_flow_get_reg_id(struct rte_eth_dev *dev,return priv->mtr_color_reg !=REG_C_2 ?REG_C_2 :REG_C_3 ;case MLX5_MTR_COLOR : -case MLX5_ASO_FLOW_HIT :/* Both features use the same REG_C. */ +case MLX5_ASO_FLOW_HIT : +case MLX5_ASO_CONNTRACK : +/* All features use the same REG_C. */ MLX5_ASSERT (priv->mtr_color_reg !=REG_NON );return priv->mtr_color_reg;case MLX5_COPY_MARK :
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -84,6 +84,7 @@ enum mlx5_feature_name {MLX5_MTR_COLOR ,MLX5_MTR_ID ,MLX5_ASO_FLOW_HIT , + MLX5_ASO_CONNTRACK, };/* Default queue number. */
Signature · 1 line
2.27.0
PATCH v4 4/17 net/mlx5: initialization of CT management
In reply to Bing ZhaoThe definitions of ASO connection tracking objects management structures are added.
Considering performance, the bulk allocation of ASO CT objects should be used. The maximal value per bulk and the granularity could be fetched from HCA capabilities 2. Right now, a fixed number of 64 is used for each bulk for a better management purpose.
The ASO QP for CT is initialized, the SQ will be used for both modify and query command.
--- drivers/net/mlx5/linux/mlx5_os.c | 13 +++++++++ drivers/net/mlx5/mlx5.c | 36 +++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 50 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 50 ++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +13 -0
@@ -1323,6 +1323,19 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,DRV_LOG (DEBUG ,"Flow Hit ASO is supported." ); }#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */ +#if defined(HAVE_MLX5_DR_CREATE_ACTION_ASO ) && \ + defined(HAVE_MLX5_DR_ACTION_ASO_CT ) +if (config->hca_attr.ct_offload && + priv->mtr_color_reg ==REG_C_3 ) { + err =mlx5_flow_aso_ct_mng_init (sh); +if (err) { + err = -err; + goto error; + } +DRV_LOG (DEBUG ,"CT ASO is supported." ); + sh->ct_aso_en =1 ; + } +#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO && HAVE_MLX5_DR_ACTION_ASO_CT */ #if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE )if (config->hca_attr.log_max_ft_sampler_num >0 && config->dv_flow_en) {
drivers/net/mlx5/mlx5.c +36 -0
@@ -670,6 +670,42 @@ mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh) } } +/* +* Initialize the ASO connection tracking structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_flow_aso_ct_mng_init (struct mlx5_dev_ctx_shared *sh) +{ +int err; + +if (sh->ct_mng) +return 0 ; + sh->ct_mng =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*sh->ct_mng), +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +if (!sh->ct_mng) { +DRV_LOG (ERR ,"ASO CT management allocation failed." ); + rte_errno =ENOMEM ; +return -rte_errno; + } + err =mlx5_aso_queue_init (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); +if (err) { +mlx5_free (sh->ct_mng); +/* rte_errno should be extracted from the failure. */ + rte_errno =EINVAL ; +return -rte_errno; + } +rte_spinlock_init (&sh->ct_mng->ct_sl); +rte_rwlock_init (&sh->ct_mng->resize_rwl); +LIST_INIT (&sh->ct_mng->free_cts); +return 0 ; +} +/** * Initialize the flow resources' indexed mempool. *
drivers/net/mlx5/mlx5.h +50 -0
74 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_aso.c +50 -0
62 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v4 5/17 common/mlx5: add Dexv CT objects creation
In reply to Bing ZhaoAdding support for connection tracking ASO creation via Devx command. Right now only bulk creation is supported.
By default, the objects with zero contents will be created. Before using a single object, the modification via posting a WQE to the ASO CT SQ is needed.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 50 ++++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 4 +++ drivers/common/mlx5/version.map | 1 + 3 files changed, 55 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +50 -0
@@ -2232,6 +2232,56 @@ mlx5_devx_cmd_create_flow_meter_aso_obj(void *ctx, uint32_t pd,return flow_meter_aso_obj; } +/* +* Create general object of type CONN_TRACK_OFFLOAD using DevX API. +* +* @param[in] ctx +* Context returned from mlx5 open_device() glue function. +* @param [in] pd +* PD value to associate the CONN_TRACK_OFFLOAD ASO object with. +* @param [in] log_obj_size +* log_obj_size to allocate its power of 2 * objects +* in one CONN_TRACK_OFFLOAD bulk allocation. +* +* @return +* The DevX object created, NULL otherwise and rte_errno is set. +*/ +struct mlx5_devx_obj * +mlx5_devx_cmd_create_conn_track_offload_obj (void *ctx,uint32_t pd, +uint32_t log_obj_size) +{ +uint32_t in[MLX5_ST_SZ_DW (create_conn_track_aso_in)] = {0 }; +uint32_t out[MLX5_ST_SZ_DW (general_obj_out_cmd_hdr)]; +struct mlx5_devx_obj *ct_aso_obj; +void *ptr; + + ct_aso_obj =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*ct_aso_obj), +0 ,SOCKET_ID_ANY ); +if (!ct_aso_obj) { +DRV_LOG (ERR ,"Failed to allocate CONN_TRACK_OFFLOAD object." ); + rte_errno =ENOMEM ; +return NULL ; + } + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, hdr); +MLX5_SET (general_obj_in_cmd_hdr, ptr, opcode, +MLX5_CMD_OP_CREATE_GENERAL_OBJECT ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, obj_type, +MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, log_obj_range, log_obj_size); + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, conn_track_offload); +MLX5_SET (conn_track_offload, ptr, conn_track_aso_access_pd, pd); + ct_aso_obj->obj = mlx5_glue->devx_obj_create (ctx, in,sizeof (in), + out,sizeof (out)); +if (!ct_aso_obj->obj) { + rte_errno = errno; +DRV_LOG (ERR ,"Failed to create CONN_TRACK_OFFLOAD obj by using DevX." ); +mlx5_free (ct_aso_obj); +return NULL ; + } + ct_aso_obj->id =MLX5_GET (general_obj_out_cmd_hdr, out, obj_id); +return ct_aso_obj; +} +/** * Create general object of type GENEVE TLV option using DevX API. *
drivers/common/mlx5/mlx5_devx_cmds.h +4 -0
@@ -569,6 +569,10 @@ struct mlx5_devx_obj *mlx5_devx_cmd_queue_counter_alloc(void *ctx);__rte_internal int mlx5_devx_cmd_queue_counter_query(struct mlx5_devx_obj *dcs, int clear,uint32_t *out_of_buffers); +__rte_internal +struct mlx5_devx_obj *mlx5_devx_cmd_create_conn_track_offload_obj(void *ctx, +uint32_t pd,uint32_t log_obj_size); +/** * Create general object of type FLOW_METER_ASO using DevX API.. *
drivers/common/mlx5/version.map +1 -0
@@ -13,6 +13,7 @@ INTERNAL { mlx5_dev_to_pci_addr; # WINDOWS_NO_EXPORT mlx5_devx_cmd_alloc_pd; + mlx5_devx_cmd_create_conn_track_offload_obj; mlx5_devx_cmd_create_cq; mlx5_devx_cmd_create_flex_parser; mlx5_devx_cmd_create_qp;
Signature · 1 line
2.27.0
PATCH v4 6/17 net/mlx5: add modify support for CT
In reply to Bing ZhaoAfter the connection tracking object bulk is allocated, all the objects' contents are filled with zero by default. Every new-allocated object must be modified via WQE operation before it is used.
In order to reduce the latency for the flow creation, an asynchronous way is used instead of busy waiting for the CQE to be generated.
--- drivers/net/mlx5/mlx5.h | 8 + drivers/net/mlx5/mlx5_flow.h | 3 + drivers/net/mlx5/mlx5_flow_aso.c | 252 +++++++++++++++++++++++++++++++ 3 files changed, 263 insertions(+)
drivers/net/mlx5/mlx5.h +8 -0
@@ -490,6 +490,7 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; +struct mlx5_aso_ct_action *ct; }; };
@@ -1007,6 +1008,10 @@ struct mlx5_aso_ct_action {bool is_original;/* The direction of the DR action to be used. */ }; +/* CT action object state update. */ +#define MLX5_ASO_CT_UPDATE_STATE (c, s) \ + __atomic_store_n(&((c)->state), (s), __ATOMIC_RELAXED) +/* ASO connection tracking software pool definition. */ struct mlx5_aso_ct_pool {uint16_t index;/* Pool index in pools array. */
@@ -1690,5 +1695,8 @@ int mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh, struct mlx5_aso_mtr *mtr);int mlx5_aso_mtr_wait (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_mtr *mtr); +int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +const struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -45,6 +45,7 @@ enum mlx5_rte_flow_action_type {enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE , +MLX5_INDIRECT_ACTION_TYPE_AGE , };/* Matches on selected register. */
@@ -839,6 +840,8 @@ struct mlx5_flow {#define MLX5_ASO_WQE_CQE_RESPONSE_DELAY 10u#define MLX5_MTR_POLL_WQE_CQE_TIMES 100000u +#define MLX5_CT_POLL_WQE_CQE_TIMES MLX5_MTR_POLL_WQE_CQE_TIMES +#define MLX5_MAN_WIDTH 8/* Legacy Meter parameter structure. */ struct mlx5_legacy_flow_meter {
drivers/net/mlx5/mlx5_flow_aso.c +252 -0
255 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v4 7/17 net/mlx5: add actions creating for CT
In reply to Bing ZhaoAllocating a CT from the management pools and creating the DR actions for both directions by default.
If there is no available connection tracking action, a new pool will be created with a fixed size bulk allocation. Right now, all the resources are controlled by the linked list.
The ASO connection tracking context associated with these actions need to be updated via WQE before using for steering.
--- drivers/net/mlx5/mlx5.h | 4 + drivers/net/mlx5/mlx5_flow.h | 29 +++- drivers/net/mlx5/mlx5_flow_dv.c | 263 ++++++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +4 -0
@@ -987,6 +987,10 @@ struct mlx5_bond_info {/* Number of connection tracking objects per pool: must be a power of 2. */ #define MLX5_ASO_CT_ACTIONS_PER_POOL 64 +/* Generate incremental and unique CT index from pool and offset. */ +#define MLX5_MAKE_CT_IDX (pool, offset) \ + ((pool) * MLX5_ASO_CT_ACTIONS_PER_POOL + (offset) + 1) +/* ASO Conntrack state. */ enum mlx5_aso_ct_state {ASO_CONNTRACK_FREE ,/* Inactive, in the free list. */
drivers/net/mlx5/mlx5_flow.h +28 -1
@@ -45,7 +45,7 @@ enum mlx5_rte_flow_action_type {enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE , -MLX5_INDIRECT_ACTION_TYPE_AGE , +MLX5_INDIRECT_ACTION_TYPE_CT , };/* Matches on selected register. */
@@ -1288,6 +1288,33 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)return &pool->mtrs[idx %MLX5_ASO_MTRS_PER_POOL ]; } +/* +* Get ASO CT action by index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +struct mlx5_aso_ct_pool *pool; + + idx--; +MLX5_ASSERT ((idx /MLX5_ASO_CT_ACTIONS_PER_POOL ) < mng->n); +/* Bit operation AND could be used. */ +rte_rwlock_read_lock (&mng->resize_rwl); + pool = mng->pools[idx /MLX5_ASO_CT_ACTIONS_PER_POOL ]; +rte_rwlock_read_unlock (&mng->resize_rwl); +return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +263 -0
281 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v4 8/17 net/mlx5: close CT management structure
In reply to Bing ZhaoWhen freeing the IB shared context during stopping a device, the ASO connection tracking management structure should also be cleaned up.
All the DR actions created should be destroyed. The structures need to be freed and ASO CT QP should be released. In the meanwhile, the allocated and registered memory region for query should also be deregistered and then freed.
--- drivers/net/mlx5/mlx5.c | 56 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 4 +++ 2 files changed, 60 insertions(+)
drivers/net/mlx5/mlx5.c +56 -0
@@ -706,6 +706,60 @@ mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh)return 0 ; } +/* +* Close and release all the resources of the +* ASO connection tracking management structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object to free. +*/ +static void +mlx5_flow_aso_ct_mng_close (struct mlx5_dev_ctx_shared *sh) +{ +struct mlx5_aso_ct_pools_mng *mng = sh->ct_mng; +struct mlx5_aso_ct_pool *ct_pool; +struct mlx5_aso_ct_action *ct; +uint32_t idx; +uint32_t val; +uint32_t cnt; +int i; + +mlx5_aso_queue_uninit (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); + idx = mng->next; +while (idx--) { + cnt =0 ; + ct_pool = mng->pools[idx]; +for (i =0 ; i <MLX5_ASO_CT_ACTIONS_PER_POOL ; i++) { + ct = &ct_pool->actions[i]; + val =__atomic_fetch_sub (&ct->refcnt,1 , + __ATOMIC_RELAXED); +MLX5_ASSERT (val ==1 ); +if (val >1 ) + cnt++; +#ifdef HAVE_MLX5_DR_ACTION_ASO_CT +if (ct->dr_action_orig) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_orig)); +if (ct->dr_action_rply) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_rply)); +#endif + } +claim_zero (mlx5_devx_cmd_destroy (ct_pool->devx_obj)); +if (cnt) { +DRV_LOG (DEBUG ,"%u ASO CT objects are being used in the pool %u" , + cnt, i); + } +mlx5_free (ct_pool); +/* in case of failure. */ + mng->next--; + } +mlx5_free (mng->pools); +mlx5_free (mng); +/* Management structure must be cleared to 0s during allocation. */ + sh->ct_mng =NULL ; +} +/** * Initialize the flow resources' indexed mempool. *
@@ -1508,6 +1562,8 @@ mlx5_dev_close(struct rte_eth_dev *dev)if (priv->mreg_cp_tbl)mlx5_hlist_destroy (priv->mreg_cp_tbl);mlx5_mprq_free_mp (dev); +if (priv->sh->ct_mng) +mlx5_flow_aso_ct_mng_close (priv->sh);mlx5_os_free_shared_dr (priv);if (priv->rss_conf.rss_key !=NULL )mlx5_free (priv->rss_conf.rss_key);
drivers/net/mlx5/mlx5_flow_aso.c +4 -0
@@ -372,6 +372,10 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,case ASO_OPC_MOD_POLICER : sq = &sh->mtrmng->pools_mng.sq;break ; +case ASO_OPC_MOD_CONNECTION_TRACKING : +mlx5_aso_dereg_mr (sh, &sh->ct_mng->aso_sq.mr); + sq = &sh->ct_mng->aso_sq; +break ;default :DRV_LOG (ERR ,"Unknown ASO operation mode" );return ;
Signature · 1 line
2.27.0
PATCH v4 9/17 net/mlx5: add ASO CT query implementation
In reply to Bing ZhaoAfter the connection tracking context is created and being used by the flows, the context will be updated by the HW automatically after a packet passed the CT validation. E.g., the ACK, SEQ, window and state of CT can be updated with both direction traffic.
In order to query the updated contents of this context, a WQE should be posted to the SQ with a return buffer. The data will be filled into the buffer. And the profile will be filled with specific value.
During the execution of query command, the context may be updated. The result of the query command may not be the latest one.
--- drivers/net/mlx5/mlx5.h | 10 +- drivers/net/mlx5/mlx5_flow_aso.c | 245 +++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 19 +++ 3 files changed, 273 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +9 -1
@@ -490,7 +490,10 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; -struct mlx5_aso_ct_action *ct; +struct { +struct mlx5_aso_ct_action *ct; +char *query_data; + }; }; };
@@ -1702,5 +1705,10 @@ int mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,const struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_wait_ready (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct); +int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow_aso.c +245 -0
263 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +19 -0
@@ -13775,6 +13775,8 @@ flow_dv_action_query(struct rte_eth_dev *dev,uint32_t act_idx = (uint32_t )(uintptr_t )handle;uint32_t type = act_idx >>MLX5_INDIRECT_ACTION_TYPE_OFFSET ;uint32_t idx = act_idx & ((1u <<MLX5_INDIRECT_ACTION_TYPE_OFFSET ) -1 ); +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct;switch (type) {case MLX5_INDIRECT_ACTION_TYPE_AGE :
@@ -13788,6 +13790,23 @@ flow_dv_action_query(struct rte_eth_dev *dev, resp->sec_since_last_hit =__atomic_load_n (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,EFAULT , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + ((struct rte_flow_action_conntrack *)data)->peer_port = + ct->peer; + ((struct rte_flow_action_conntrack *)data)->is_original_dir = + ct->is_original; +if (mlx5_aso_ct_query_by_wqe (priv->sh, ct, data)) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to query CT context" ); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v4 10/17 net/mlx5: add ASO CT destroy handling
In reply to Bing ZhaoWhen trying to destroy an ASO connection tracking context, the DR action created on this context should also be destroyed. Before inserting the related software object into the management free list, the reference count should be checked.
Right now, the context object will not be freed to the system and will be reused directly from the free list.
--- drivers/net/mlx5/mlx5_flow_dv.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +15 -1
@@ -11136,9 +11136,15 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +uint32_t ret;struct mlx5_aso_ct_action *ct =flow_aso_ct_get_by_idx (dev, idx); -uint32_t ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED); +enum mlx5_aso_ct_state state = +__atomic_load_n (&ct->state, __ATOMIC_RELAXED); +/* Cannot release when CT is in the ASO SQ. */ +if (state ==ASO_CONNTRACK_WAIT || state ==ASO_CONNTRACK_QUERY ) +return -1 ; + ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED);if (!ret) {if (ct->dr_action_orig) {#ifdef HAVE_MLX5_DR_ACTION_ASO_CT
@@ -11154,6 +11160,8 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx)#endif ct->dr_action_rply =NULL ; } +/* Clear the state to free, no need in 1st allocation. */ +MLX5_ASO_CT_UPDATE_STATE (ct,ASO_CONNTRACK_FREE );rte_spinlock_lock (&mng->ct_sl);LIST_INSERT_HEAD (&mng->free_cts, ct, next);rte_spinlock_unlock (&mng->ct_sl);
@@ -13648,6 +13656,12 @@ flow_dv_action_destroy(struct rte_eth_dev *dev,DRV_LOG (DEBUG ,"Indirect age action %" PRIu32" was" " released with references %d." , idx, ret);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ret =flow_dv_aso_ct_release (dev, idx); +if (ret) +DRV_LOG (DEBUG ,"Connection tracking object %u still " +"has references %d." , idx, ret); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v4 11/17 net/mlx5: add translation of CT action
In reply to Bing ZhaoWhen creating a flow with this action context for CT, it needs to be translated in 2 levels.
First, retrieve from action context to rte_flow action. Second, translate it to the corresponding DR action with traffic direction that was specified when creating or updating via rte_flow_action_handle* API.
Before using the DR action in a flow, the CT context should be available to use in the hardware. A synchronization is done before inserting the flow rule with CT action to check the HW availability of this CT context.
In order to release the DR actions and reuse the context of a CT, the reference count should also be handled in the flow rule destroying.
The CT index will be recorded in the rte_flow by reusing the ASO age index to save memory, since only one ASO action is supported in one flow rule currently. The action context type should also be saved for CT. When destroying a flow rule, if the context type is CT and the index is valid (non-zero), the release process should be handled. By default, the handling will fall back to try to release the ASO age if any.
--- drivers/net/mlx5/mlx5.h | 2 ++ drivers/net/mlx5/mlx5_flow.c | 9 +++++++ drivers/net/mlx5/mlx5_flow.h | 7 +++++- drivers/net/mlx5/mlx5_flow_aso.c | 41 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 28 +++++++++++++++++++++- 5 files changed, 85 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.h +2 -0
@@ -1710,5 +1710,7 @@ int mlx5_aso_ct_wait_ready(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_available (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.c +9 -0
@@ -3553,6 +3553,15 @@ flow_action_handles_translate(struct rte_eth_dev *dev,break ; }/* Fall-through */ +case MLX5_INDIRECT_ACTION_TYPE_CT : +if (priv->sh->ct_aso_en) { + translated[handle->index].type = +RTE_FLOW_ACTION_TYPE_CONNTRACK ; + translated[handle->index].conf = + (void *)(uintptr_t )idx; +break ; + } +/* Fall-through */ default :mlx5_free (translated);return rte_flow_error_set
drivers/net/mlx5/mlx5_flow.h +6 -1
@@ -226,6 +226,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)#define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40) +#define MLX5_FLOW_ACTION_CT (1ull << 41)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
@@ -969,11 +970,15 @@ struct rte_flow { uint32_t drv_type:2; /**< Driver type. */ uint32_t tunnel:1; uint32_t meter:24; /**< Holds flow meter id. */ + uint32_t indirect_type:2; /**< Indirect action type. */uint32_t rix_mreg_copy;/**< Index to metadata register copy table resource. */ uint32_t counter;/**< Holds flow counter. */ uint32_t tunnel_id;/**< Tunnel id */ -uint32_t age;/**< Holds ASO age bit index. */ +union { +uint32_t age;/**< Holds ASO age bit index. */ +uint32_t ct;/**< Holds ASO CT index. */ + };uint32_t geneve_tlv_option;/**< Holds Geneve TLV option id. > */ } __rte_packed;
drivers/net/mlx5/mlx5_flow_aso.c +41 -0
44 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +27 -1
@@ -11381,6 +11381,7 @@ flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,return rte_flow_error_set (error,EBUSY ,RTE_FLOW_ERROR_TYPE_ACTION ,NULL ,"Failed to update CT" ); + ct->is_original = !!pro->is_original_dir;return idx; }
@@ -11544,6 +11545,8 @@ flow_dv_translate(struct rte_eth_dev *dev,const struct rte_flow_action *found_action =NULL ;uint32_t jump_group =0 ;struct mlx5_flow_counter *cnt; +uint32_t ct_idx; +struct mlx5_aso_ct_action *ct;if (!mlx5_flow_os_action_supported (action_type)) return rte_flow_error_set(error, ENOTSUP,
@@ -12017,6 +12020,26 @@ flow_dv_translate(struct rte_eth_dev *dev,return -rte_errno; action_flags |=MLX5_FLOW_ACTION_MODIFY_FIELD ;break ; +case RTE_FLOW_ACTION_TYPE_CONNTRACK : + ct_idx = (uint32_t )(uintptr_t )action->conf; + ct =flow_aso_ct_get_by_idx (dev, ct_idx); +if (mlx5_aso_ct_available (priv->sh, ct)) +return rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_ACTION , +NULL , +"CT is unavailable." ); +if (ct->is_original) + dev_flow->dv.actions[actions_n] = + ct->dr_action_orig; +else + dev_flow->dv.actions[actions_n] = + ct->dr_action_rply; + flow->indirect_type =MLX5_INDIRECT_ACTION_TYPE_CT ; + flow->ct = ct_idx; +__atomic_fetch_add (&ct->refcnt,1 , __ATOMIC_RELAXED); + actions_n++; + action_flags |=MLX5_FLOW_ACTION_CT ; +break ;case RTE_FLOW_ACTION_TYPE_END : actions_end = true;if (mhdr_res->actions_num) {
@@ -13152,7 +13175,10 @@ flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)mlx5_flow_meter_detach (priv, fm); flow->meter =0 ; } -if (flow->age) +/* Keep the current age handling by default. */ +if (flow->indirect_type ==MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct) +flow_dv_aso_ct_release (dev, flow->ct); +else if (flow->age)flow_dv_aso_age_release (dev, flow->age);if (flow->geneve_tlv_option) {flow_dv_geneve_tlv_option_resource_release (dev);
Signature · 1 line
2.27.0
PATCH v4 12/17 net/mlx5: add translation of CT item
In reply to Bing ZhaoThe return register of the DR action will be used for matching. After the ASO CT checking of a TCP packet, the syndrome is filled in the register. Only the 8 LSB should be used. A converting from RTE_FLOW_CONNTRACK_FLAG* to the syndrome should be done after checing the spec and mask fields.
--- drivers/net/mlx5/mlx5_flow.h | 7 ++++ drivers/net/mlx5/mlx5_flow_dv.c | 62 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
drivers/net/mlx5/mlx5_flow.h +7 -0
@@ -405,6 +405,13 @@ enum mlx5_feature_name {/* Maximum number of fields to modify in MODIFY_FIELD */ #define MLX5_ACT_MAX_MOD_FIELDS 5 +/* Syndrome bits definition for connection tracking. */ +#define MLX5_CT_SYNDROME_VALID (0x0 << 6) +#define MLX5_CT_SYNDROME_INVALID (0x1 << 6) +#define MLX5_CT_SYNDROME_TRAP (0x2 << 6) +#define MLX5_CT_SYNDROME_STATE_CHANGE (0x1 << 1) +#define MLX5_CT_SYNDROME_BAD_PACKET (0x1 << 0) +enum mlx5_flow_drv_type {MLX5_FLOW_TYPE_MIN ,MLX5_FLOW_TYPE_DV ,
drivers/net/mlx5/mlx5_flow_dv.c +62 -0
74 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v4 13/17 net/mlx5: add CT context update
In reply to Bing ZhaoWhen updating a connection tracking context, two separate parts could be updated.
First, the direction. This will only update the traffic direction recorded in the software for flow creation.
Second, the TCP parameters. The hardware context will be updated via the WQE. This update will be blocked until the hardware status is updated and ready for the next flow creation.
--- drivers/net/mlx5/mlx5_flow_dv.c | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
drivers/net/mlx5/mlx5_flow_dv.c +56 -0
@@ -13824,6 +13824,60 @@ __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,return ret; } +/* +* Updates in place conntrack context or direction. +* Context update should be synchronized. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* The conntrack object ID to be updated. +* @param[in] update +* Pointer to the structure of information to update. +* @param[out] error +* Perform verbose error reporting if not NULL. Initialized in case of +* error only. +* +* @return +* 0 on success, otherwise negative errno value. +*/ +static int +__flow_dv_action_ct_update (struct rte_eth_dev *dev,uint32_t idx, +const struct rte_flow_modify_conntrack *update, +struct rte_flow_error *error) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +const struct rte_flow_action_conntrack *new_prf; +int ret =0 ; + + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,ENOMEM , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + new_prf = &update->new_ct; +if (update->direction) + ct->is_original = !!new_prf->is_original_dir; +if (update->state) { + ret =mlx5_aso_ct_update_by_wqe (priv->sh, ct, new_prf); +if (ret) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to send CT context update WQE" ); +/* Block until ready or a failure. */ + ret =mlx5_aso_ct_available (priv->sh, ct); +if (ret) +rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Timeout to get the CT update" ); + } +return ret; +} +/** * Updates in place shared action configuration, lock free, * (mutex should be acquired by caller).
@@ -13859,6 +13913,8 @@ flow_dv_action_update(struct rte_eth_dev *dev,case MLX5_INDIRECT_ACTION_TYPE_RSS : action_conf = ((const struct rte_flow_action *)update)->conf;return __flow_dv_action_rss_update (dev, idx, action_conf, err); +case MLX5_INDIRECT_ACTION_TYPE_CT : +return __flow_dv_action_ct_update (dev, idx, update, err);default : return rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v4 14/17 net/mlx5: validation of CT action
In reply to Bing ZhaoThe validation of a CT action contains two parts. The first is the CT action configurations parameter. When creating a CT action context, some members need to be verified.
The second is that when creating a flow, the DR action of CT should be validated with other actions and items as well. Currently, only the TCP protocol support connection tracking.
--- drivers/net/mlx5/mlx5.h | 4 ++ drivers/net/mlx5/mlx5_flow.c | 31 +++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 69 +++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+)
drivers/net/mlx5/mlx5.h +4 -0
@@ -1611,6 +1611,10 @@ int mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow,void mlx5_flow_rxq_dynf_metadata_set (struct rte_eth_dev *dev);int mlx5_flow_get_aged_flows (struct rte_eth_dev *dev,void **contexts,uint32_t nb_contexts,struct rte_flow_error *error); +int mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error); +/* mlx5_mp_os.c */
drivers/net/mlx5/mlx5_flow.c +31 -0
@@ -1688,6 +1688,37 @@ mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,return 0 ; } +/* +* Validate the ASO CT action. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] conntrack +* Pointer to the CT action profile. +* @param[out] error +* Pointer to error structure. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error) +{ +RTE_SET_USED (dev); + +if (conntrack->state >RTE_FLOW_CONNTRACK_STATE_TIME_WAIT ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid CT state" ); +if (conntrack->last_index >RTE_FLOW_CONNTRACK_FLAG_RST ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid last TCP packet flag" ); +return 0 ; +} +/** * Verify the @p attributes will be correctly understood by the NIC and store * them in the @p flow if everything is correct.
drivers/net/mlx5/mlx5_flow_dv.c +69 -0
93 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v4 15/17 net/mlx5: validation of CT item
In reply to Bing ZhaoThe item of ASO connection tracking will be translated into the register value when matching. The validation of this item has no dependency on other layers, since the flow including this item should be jumped from another group. All the layers checking was already done in the previous groups. Only the state bits conflict should be checked.
It is assumed that the flow with CT item will always work on the TCP traffic.
--- drivers/net/mlx5/mlx5_flow.h | 3 ++ drivers/net/mlx5/mlx5_flow_dv.c | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -147,6 +147,9 @@ enum mlx5_feature_name {#define MLX5_FLOW_LAYER_GENEVE_OPT (UINT64_C(1) << 32)#define MLX5_FLOW_LAYER_GTP_PSC (UINT64_C(1) << 33) +/* Conntrack item. */ +#define MLX5_FLOW_LAYER_ASO_CT (UINT64_C(1) << 34) +/* Outer Masks. */ #define MLX5_FLOW_LAYER_OUTER_L3 \ (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6)
drivers/net/mlx5/mlx5_flow_dv.c +51 -0
63 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v4 16/17 net/mlx5: add support of CT between two ports
In reply to Bing ZhaoAfter creating a connection tracking context, it can be used between two ports. For each port, the flow for one direction traffic will be created.
The context can only be shared between the owner port and the peer port that was specified when being created. Only the owner port could update the context or query it in current implementation.
--- drivers/net/mlx5/mlx5_flow.h | 57 +++++++++++++++++++++++++- drivers/net/mlx5/mlx5_flow_dv.c | 71 +++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 18 deletions(-)
drivers/net/mlx5/mlx5_flow.h +55 -2
@@ -48,6 +48,25 @@ enum { MLX5_INDIRECT_ACTION_TYPE_CT, }; +/* Now, the maximal ports will be supported is 256, action number is 4M. */ +#define MLX5_INDIRECT_ACT_CT_MAX_PORT 0x100 + +#define MLX5_INDIRECT_ACT_CT_OWNER_SHIFT 22 +#define MLX5_INDIRECT_ACT_CT_OWNER_MASK (MLX5_INDIRECT_ACT_CT_MAX_PORT - 1) + +/* 30-31: type, 22-29: owner port, 0-21: index. */ +#define MLX5_INDIRECT_ACT_CT_GEN_IDX (owner, index) \ + ((MLX5_INDIRECT_ACTION_TYPE_CT << MLX5_INDIRECT_ACTION_TYPE_OFFSET) | \ + (((owner) & MLX5_INDIRECT_ACT_CT_OWNER_MASK) << \ + MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) | (index)) + +#define MLX5_INDIRECT_ACT_CT_GET_OWNER (index) \ + (((index) >> MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) & \ + MLX5_INDIRECT_ACT_CT_OWNER_MASK) + +#define MLX5_INDIRECT_ACT_CT_GET_IDX (index) \ + ((index) & ((1 << MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) - 1)) +/* Matches on selected register. */ struct mlx5_rte_flow_item_tag {enum modify_reg id;
@@ -1304,7 +1323,7 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx) }/* -* Get ASO CT action by index. +* Get ASO CT action by device and index. * * @param[in] dev * Pointer to the Ethernet device structure.
@@ -1315,7 +1334,7 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)* The specified ASO CT action pointer. */ static inline struct mlx5_aso_ct_action * -flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +flow_aso_ct_get_by_dev_idx (struct rte_eth_dev *dev,uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
@@ -1330,6 +1349,40 @@ flow_aso_ct_get_by_idx(struct rte_eth_dev *dev, uint32_t idx)return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; } +/* +* Get ASO CT action by owner & index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action and owner port combination. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t own_idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +uint16_t owner = (uint16_t )MLX5_INDIRECT_ACT_CT_GET_OWNER (own_idx); +uint32_t idx =MLX5_INDIRECT_ACT_CT_GET_IDX (own_idx); + +if (owner ==PORT_ID (priv)) { + ct =flow_aso_ct_get_by_dev_idx (dev, idx); + }else { +struct rte_eth_dev *owndev = &rte_eth_devices[owner]; + +MLX5_ASSERT (owner <RTE_MAX_ETHPORTS ); +if (dev->data->dev_started !=1 ) +return NULL ; + ct =flow_aso_ct_get_by_dev_idx (owndev, idx); +if (ct->peer !=PORT_ID (priv)) +return NULL ; + } +return ct; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +55 -16
165 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v4 17/17 doc: update mlx5 support for conntrack
In reply to Bing ZhaoIn the release notes and mlx5 NIC document, the support and limitation of connection tracking are added.
--- doc/guides/nics/features/default.ini | 1 + doc/guides/nics/features/mlx5.ini | 1 + doc/guides/nics/mlx5.rst | 14 ++++++++++++++ doc/guides/rel_notes/release_21_05.rst | 2 ++ 4 files changed, 18 insertions(+)
doc/guides/nics/features/default.ini +1 -0
@@ -66,6 +66,7 @@ Module EEPROM dump = Registers dump = LED = Multiprocess aware = +Connection tracking = FreeBSD = Linux = Windows =
doc/guides/nics/features/mlx5.ini +1 -0
@@ -45,6 +45,7 @@ Stats per queue = Y FW version = Y Module EEPROM dump = Y Multiprocess aware = Y +Connection tracking = Y Linux = Y Windows = P ARMv8 = Y
doc/guides/nics/mlx5.rst +14 -0
@@ -107,6 +107,7 @@ Features - 21844 flow priorities for ingress or egress flow groups greater than 0 and for any transfer flow group. - Flow metering, including meter policy API. +- Connection tracking. Limitations -----------
@@ -418,6 +419,14 @@ Limitations - RED: must be DROP. - meter profile packet mode is supported. +- Connection tracking: + + - connection tracking (conntrack) couldn't co-exist with ASO meter, ASO age action in a single flow rule. + - Flow rules insertion rate and memory consumption. + - software limitation: + - ports: a maximal number of 256. + - conntrack: a maximal number of 4M. + Statistics ----------
@@ -1680,6 +1689,11 @@ Supported hardware offloads | | | rdma-core 35 | | rdma-core 35 | | | | ConnectX-5 | | ConnectX-5 | +-----------------------+-----------------+-----------------+ + | Connection tracking | | | | DPDK 21.05 | + | | | N/A | | OFED 5.3 | + | | | | | rdma-core 35 | + | | | | | ConnectX-6 Dx | + +-----------------------+-----------------+-----------------+ .. table:: Minimal SW/HW versions for shared action offload :name: sact
doc/guides/rel_notes/release_21_05.rst +2 -0
@@ -166,6 +166,8 @@ New Features * Added support for ASO (Advanced Steering Operation) meter. * Added support for ASO metering by PPS (packet per second). * Added support for the monitor policy of Power Management API. + * Added support for connection tracking action and item as well as context create, + destroy, update and query. * **Updated NXP DPAA driver.**
Signature · 1 line
2.27.0
v5 cover conntrack support in mlx5 PMD
In reply to Bing ZhaoThis patch set adds the connection tracking offload support in the mlx5 driver, as well as the documents update.
---
v2: code bug fixes, commits clean up and doc update
v3: fix error input pointer for CT MR registering
v4: fix typo in commit message of patch 11
v5: adjust mkey to lkey in SQ initialization
---
Bing Zhao (17):
common/mlx5: add connection tracking object definition common/mlx5: add CT offload capability checking net/mlx5: use meter color reg for CT net/mlx5: initialization of CT management common/mlx5: add Dexv CT objects creation net/mlx5: add modify support for CT
net/mlx5: add actions creating for CT net/mlx5: close CT management structure net/mlx5: add ASO CT query implementation net/mlx5: add ASO CT destroy handling net/mlx5: add translation of CT action net/mlx5: add translation of CT item net/mlx5: add CT context update
net/mlx5: validation of CT action
net/mlx5: validation of CT item
net/mlx5: add support of CT between two ports
doc: update mlx5 support for conntrack
doc/guides/nics/features/default.ini | 1 + doc/guides/nics/features/mlx5.ini | 1 + doc/guides/nics/mlx5.rst | 14 + doc/guides/rel_notes/release_21_05.rst | 2 + drivers/common/mlx5/linux/meson.build | 2 + drivers/common/mlx5/mlx5_devx_cmds.c | 53 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 5 + drivers/common/mlx5/mlx5_prm.h | 88 ++++ drivers/common/mlx5/version.map | 1 + drivers/net/mlx5/linux/mlx5_os.c | 13 + drivers/net/mlx5/mlx5.c | 92 ++++ drivers/net/mlx5/mlx5.h | 76 ++++ drivers/net/mlx5/mlx5_flow.c | 44 +- drivers/net/mlx5/mlx5_flow.h | 101 ++++- drivers/net/mlx5/mlx5_flow_aso.c | 592 ++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 601 ++++++++++++++++++++++++- 16 files changed, 1683 insertions(+), 3 deletions(-)
Signature · 1 line
2.27.0
PATCH v5 1/17 common/mlx5: add connection tracking object definition
The structures of ASO connection tracking offload object are added based on the definitions in the PRM. One CT object context will be loaded into the cache completely in a reversed order of dwords. The valid bit should be the MSB of the last dword. This is used for the conntrack context creation and update, as well as for the query.
The capabilities 2 (HCA_CAP_2) layout is also added. The connection tracking related capabilities could be queried via the HCA_CAP_2.
--- drivers/common/mlx5/mlx5_prm.h | 85 ++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
drivers/common/mlx5/mlx5_prm.h +85 -0
@@ -1119,6 +1119,7 @@ enum {MLX5_GET_HCA_CAP_OP_MOD_ROCE =0x4 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE =0x7 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_VDPA_EMULATION =0x13 <<1 , + MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE_2 = 0x20 << 1, };#define MLX5_GENERAL_OBJ_TYPES_CAP_VIRTQ_NET_Q \
@@ -1661,6 +1662,29 @@ struct mlx5_ifc_flow_table_nic_cap_bits {struct mlx5_ifc_flow_table_prop_layout_bits flow_table_properties; }; +struct mlx5_ifc_cmd_hca_cap_2_bits { +u8 reserved_at_0[0x80 ];/* End of DW4. */ +u8 reserved_at_80[0xb ]; +u8 log_max_num_reserved_qpn[0x5 ]; +u8 reserved_at_90[0x3 ]; +u8 log_reserved_qpn_granularity[0x5 ]; +u8 reserved_at_98[0x3 ]; +u8 log_reserved_qpn_max_alloc[0x5 ];/* End of DW5. */ +u8 max_reformat_insert_size[0x8 ]; +u8 max_reformat_insert_offset[0x8 ]; +u8 max_reformat_remove_size[0x8 ]; +u8 max_reformat_remove_offset[0x8 ];/* End of DW6. */ +u8 aso_conntrack_reg_id[0x8 ]; +u8 reserved_at_c8[0x3 ]; +u8 log_conn_track_granularity[0x5 ]; +u8 reserved_at_d0[0x3 ]; +u8 log_conn_track_max_alloc[0x5 ]; +u8 reserved_at_d8[0x3 ]; +u8 log_max_conn_track_offload[0x5 ]; +u8 reserved_at_e0[0x20 ];/* End of DW7. */ +u8 reserved_at_100[0x700 ]; +}; +union mlx5_ifc_hca_cap_union_bits {struct mlx5_ifc_cmd_hca_cap_bits cmd_hca_cap;struct mlx5_ifc_per_protocol_networking_offload_caps_bits
@@ -2599,6 +2623,67 @@ struct mlx5_ifc_create_flow_meter_aso_in_bits {struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr;struct mlx5_ifc_flow_meter_aso_bits flow_meter_aso; }; + +struct mlx5_ifc_tcp_window_params_bits { +u8 max_ack[0x20 ]; +u8 max_win[0x20 ]; +u8 reply_end[0x20 ]; +u8 sent_end[0x20 ]; +}; + +struct mlx5_ifc_conn_track_aso_bits { +struct mlx5_ifc_tcp_window_params_bits reply_dir;/* End of DW3. */ +struct mlx5_ifc_tcp_window_params_bits original_dir;/* End of DW7. */ +u8 last_end[0x20 ];/* End of DW8. */ +u8 last_ack[0x20 ];/* End of DW9. */ +u8 last_seq[0x20 ];/* End of DW10. */ +u8 last_win[0x10 ]; +u8 reserved_at_170[0xa ]; +u8 last_dir[0x1 ]; +u8 last_index[0x5 ];/* End of DW11. */ +u8 reserved_at_180[0x40 ];/* End of DW13. */ +u8 reply_direction_tcp_scale[0x4 ]; +u8 reply_direction_tcp_close_initiated[0x1 ]; +u8 reply_direction_tcp_liberal_enabled[0x1 ]; +u8 reply_direction_tcp_data_unacked[0x1 ]; +u8 reply_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1c8[0x8 ]; +u8 original_direction_tcp_scale[0x4 ]; +u8 original_direction_tcp_close_initiated[0x1 ]; +u8 original_direction_tcp_liberal_enabled[0x1 ]; +u8 original_direction_tcp_data_unacked[0x1 ]; +u8 original_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1d8[0x8 ];/* End of DW14. */ +u8 valid[0x1 ]; +u8 state[0x3 ]; +u8 freeze_track[0x1 ]; +u8 reserved_at_1e5[0xb ]; +u8 reserved_at_1f0[0x1 ]; +u8 connection_assured[0x1 ]; +u8 sack_permitted[0x1 ]; +u8 challenged_acked[0x1 ]; +u8 heartbeat[0x1 ]; +u8 max_ack_window[0x3 ]; +u8 reserved_at_1f8[0x1 ]; +u8 retransmission_counter[0x3 ]; +u8 retranmission_limit_exceeded[0x1 ]; +u8 retranmission_limit[0x3 ];/* End of DW15. */ +}; + +struct mlx5_ifc_conn_track_offload_bits { +u8 modify_field_select[0x40 ]; +u8 reserved_at_40[0x40 ]; +u8 reserved_at_80[0x8 ]; +u8 conn_track_aso_access_pd[0x18 ]; +u8 reserved_at_a0[0x160 ]; +struct mlx5_ifc_conn_track_aso_bits conn_track_aso; +}; + +struct mlx5_ifc_create_conn_track_aso_in_bits { +struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr; +struct mlx5_ifc_conn_track_offload_bits conn_track_offload; +}; +enum mlx5_access_aso_opc_mod {ASO_OPC_MOD_IPSEC =0x0 ,ASO_OPC_MOD_CONNECTION_TRACKING =0x1 ,
Signature · 1 line
2.27.0
PATCH v5 2/17 common/mlx5: add CT offload capability checking
In reply to Bing ZhaoDuring startup, the ASO connection tracking offload capability could be queried via HCA_CAP_QUERY command. If the HW doesn't support ASO CT, the value would be 0 by default. The following initialization should be skipped and the creation of the CT object should return a failure directly.
The following CT creation should also check this capability. With the old driver, the pre-processing macro should be used in order to make the compiling pass.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/mlx5_devx_cmds.c | 3 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 3 +++ 4 files changed, 9 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -189,6 +189,8 @@ has_sym_args = [ 'MLX5_WQE_UMR_CTRL_FLAG_INLINE' ], [ 'HAVE_MLX5_DR_FLOW_DUMP_RULE', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_rule' ], + [ 'HAVE_MLX5_DR_ACTION_ASO_CT', 'infiniband/mlx5dv.h', + 'MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR' ], ] config = configuration_data() foreach arg:has_sym_args
drivers/common/mlx5/mlx5_devx_cmds.c +3 -0
@@ -760,6 +760,9 @@ mlx5_devx_cmd_query_hca_attr(void *ctx,MLX5_GET (cmd_hca_cap, hcattr, umr_indirect_mkey_disabled); attr->umr_modify_entity_size_disabled =MLX5_GET (cmd_hca_cap, hcattr, umr_modify_entity_size_disabled); + attr->ct_offload = !!(MLX5_GET64 (cmd_hca_cap, hcattr, + general_obj_types) & +MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD );if (attr->qos.sup) { MLX5_SET(query_hca_cap_in, in, op_mod, MLX5_GET_HCA_CAP_OP_MOD_QOS_CAP |
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -137,6 +137,7 @@ struct mlx5_hca_attr { uint32_t qp_ts_format:2; uint32_t regex:1; uint32_t reg_c_preserve:1; + uint32_t ct_offload:1; /* General obj type ASO CT offload supported. */uint32_t regexp_num_of_engines; uint32_t log_max_ft_sampler_num:8;uint32_t geneve_tlv_opt;
drivers/common/mlx5/mlx5_prm.h +3 -0
@@ -1134,6 +1134,8 @@ enum { (1ULL << MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO)#define MLX5_GENERAL_OBJ_TYPES_CAP_GENEVE_TLV_OPT \ (1ULL << MLX5_OBJ_TYPE_GENEVE_TLV_OPT) +#define MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD \ + (1ULL << MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD)enum {MLX5_HCA_CAP_OPMOD_GET_MAX =0 ,
@@ -2456,6 +2458,7 @@ enum {MLX5_GENERAL_OBJ_TYPE_FLEX_PARSE_GRAPH =0x0022 ,MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO =0x0024 ,MLX5_GENERAL_OBJ_TYPE_FLOW_HIT_ASO =0x0025 , + MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD = 0x0031, }; struct mlx5_ifc_general_obj_in_cmd_hdr_bits {
Signature · 1 line
2.27.0
PATCH v5 3/17 net/mlx5: use meter color reg for CT
In reply to Bing ZhaoBased on the capacity, 3 registers could be used. Due to the register allocation, only the one REG_C_3 for meter color could be reused right now.
Then in the same flow, no more than one ASO action can be supported.
--- drivers/net/mlx5/mlx5_flow.c | 4 +++- drivers/net/mlx5/mlx5_flow.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow.c +3 -1
@@ -760,7 +760,9 @@ mlx5_flow_get_reg_id(struct rte_eth_dev *dev,return priv->mtr_color_reg !=REG_C_2 ?REG_C_2 :REG_C_3 ;case MLX5_MTR_COLOR : -case MLX5_ASO_FLOW_HIT :/* Both features use the same REG_C. */ +case MLX5_ASO_FLOW_HIT : +case MLX5_ASO_CONNTRACK : +/* All features use the same REG_C. */ MLX5_ASSERT (priv->mtr_color_reg !=REG_NON );return priv->mtr_color_reg;case MLX5_COPY_MARK :
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -84,6 +84,7 @@ enum mlx5_feature_name {MLX5_MTR_COLOR ,MLX5_MTR_ID ,MLX5_ASO_FLOW_HIT , + MLX5_ASO_CONNTRACK, };/* Default queue number. */
Signature · 1 line
2.27.0
PATCH v5 4/17 net/mlx5: initialization of CT management
In reply to Bing ZhaoThe definitions of ASO connection tracking objects management structures are added.
Considering performance, the bulk allocation of ASO CT objects should be used. The maximal value per bulk and the granularity could be fetched from HCA capabilities 2. Right now, a fixed number of 64 is used for each bulk for a better management purpose.
The ASO QP for CT is initialized, the SQ will be used for both modify and query command.
--- drivers/net/mlx5/linux/mlx5_os.c | 13 +++++++++ drivers/net/mlx5/mlx5.c | 36 +++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 50 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 50 ++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +13 -0
@@ -1323,6 +1323,19 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,DRV_LOG (DEBUG ,"Flow Hit ASO is supported." ); }#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */ +#if defined(HAVE_MLX5_DR_CREATE_ACTION_ASO ) && \ + defined(HAVE_MLX5_DR_ACTION_ASO_CT ) +if (config->hca_attr.ct_offload && + priv->mtr_color_reg ==REG_C_3 ) { + err =mlx5_flow_aso_ct_mng_init (sh); +if (err) { + err = -err; + goto error; + } +DRV_LOG (DEBUG ,"CT ASO is supported." ); + sh->ct_aso_en =1 ; + } +#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO && HAVE_MLX5_DR_ACTION_ASO_CT */ #if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE )if (config->hca_attr.log_max_ft_sampler_num >0 && config->dv_flow_en) {
drivers/net/mlx5/mlx5.c +36 -0
@@ -670,6 +670,42 @@ mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh) } } +/* +* Initialize the ASO connection tracking structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_flow_aso_ct_mng_init (struct mlx5_dev_ctx_shared *sh) +{ +int err; + +if (sh->ct_mng) +return 0 ; + sh->ct_mng =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*sh->ct_mng), +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +if (!sh->ct_mng) { +DRV_LOG (ERR ,"ASO CT management allocation failed." ); + rte_errno =ENOMEM ; +return -rte_errno; + } + err =mlx5_aso_queue_init (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); +if (err) { +mlx5_free (sh->ct_mng); +/* rte_errno should be extracted from the failure. */ + rte_errno =EINVAL ; +return -rte_errno; + } +rte_spinlock_init (&sh->ct_mng->ct_sl); +rte_rwlock_init (&sh->ct_mng->resize_rwl); +LIST_INIT (&sh->ct_mng->free_cts); +return 0 ; +} +/** * Initialize the flow resources' indexed mempool. *
drivers/net/mlx5/mlx5.h +50 -0
74 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_aso.c +50 -0
62 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v5 5/17 common/mlx5: add Dexv CT objects creation
In reply to Bing ZhaoAdding support for connection tracking ASO creation via Devx command. Right now only bulk creation is supported.
By default, the objects with zero contents will be created. Before using a single object, the modification via posting a WQE to the ASO CT SQ is needed.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 50 ++++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 4 +++ drivers/common/mlx5/version.map | 1 + 3 files changed, 55 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +50 -0
@@ -2232,6 +2232,56 @@ mlx5_devx_cmd_create_flow_meter_aso_obj(void *ctx, uint32_t pd,return flow_meter_aso_obj; } +/* +* Create general object of type CONN_TRACK_OFFLOAD using DevX API. +* +* @param[in] ctx +* Context returned from mlx5 open_device() glue function. +* @param [in] pd +* PD value to associate the CONN_TRACK_OFFLOAD ASO object with. +* @param [in] log_obj_size +* log_obj_size to allocate its power of 2 * objects +* in one CONN_TRACK_OFFLOAD bulk allocation. +* +* @return +* The DevX object created, NULL otherwise and rte_errno is set. +*/ +struct mlx5_devx_obj * +mlx5_devx_cmd_create_conn_track_offload_obj (void *ctx,uint32_t pd, +uint32_t log_obj_size) +{ +uint32_t in[MLX5_ST_SZ_DW (create_conn_track_aso_in)] = {0 }; +uint32_t out[MLX5_ST_SZ_DW (general_obj_out_cmd_hdr)]; +struct mlx5_devx_obj *ct_aso_obj; +void *ptr; + + ct_aso_obj =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*ct_aso_obj), +0 ,SOCKET_ID_ANY ); +if (!ct_aso_obj) { +DRV_LOG (ERR ,"Failed to allocate CONN_TRACK_OFFLOAD object." ); + rte_errno =ENOMEM ; +return NULL ; + } + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, hdr); +MLX5_SET (general_obj_in_cmd_hdr, ptr, opcode, +MLX5_CMD_OP_CREATE_GENERAL_OBJECT ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, obj_type, +MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, log_obj_range, log_obj_size); + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, conn_track_offload); +MLX5_SET (conn_track_offload, ptr, conn_track_aso_access_pd, pd); + ct_aso_obj->obj = mlx5_glue->devx_obj_create (ctx, in,sizeof (in), + out,sizeof (out)); +if (!ct_aso_obj->obj) { + rte_errno = errno; +DRV_LOG (ERR ,"Failed to create CONN_TRACK_OFFLOAD obj by using DevX." ); +mlx5_free (ct_aso_obj); +return NULL ; + } + ct_aso_obj->id =MLX5_GET (general_obj_out_cmd_hdr, out, obj_id); +return ct_aso_obj; +} +/** * Create general object of type GENEVE TLV option using DevX API. *
drivers/common/mlx5/mlx5_devx_cmds.h +4 -0
@@ -569,6 +569,10 @@ struct mlx5_devx_obj *mlx5_devx_cmd_queue_counter_alloc(void *ctx);__rte_internal int mlx5_devx_cmd_queue_counter_query(struct mlx5_devx_obj *dcs, int clear,uint32_t *out_of_buffers); +__rte_internal +struct mlx5_devx_obj *mlx5_devx_cmd_create_conn_track_offload_obj(void *ctx, +uint32_t pd,uint32_t log_obj_size); +/** * Create general object of type FLOW_METER_ASO using DevX API.. *
drivers/common/mlx5/version.map +1 -0
@@ -13,6 +13,7 @@ INTERNAL { mlx5_dev_to_pci_addr; # WINDOWS_NO_EXPORT mlx5_devx_cmd_alloc_pd; + mlx5_devx_cmd_create_conn_track_offload_obj; mlx5_devx_cmd_create_cq; mlx5_devx_cmd_create_flex_parser; mlx5_devx_cmd_create_qp;
Signature · 1 line
2.27.0
PATCH v5 6/17 net/mlx5: add modify support for CT
In reply to Bing ZhaoAfter the connection tracking object bulk is allocated, all the objects' contents are filled with zero by default. Every new-allocated object must be modified via WQE operation before it is used.
In order to reduce the latency for the flow creation, an asynchronous way is used instead of busy waiting for the CQE to be generated.
--- drivers/net/mlx5/mlx5.h | 8 + drivers/net/mlx5/mlx5_flow.h | 3 + drivers/net/mlx5/mlx5_flow_aso.c | 252 +++++++++++++++++++++++++++++++ 3 files changed, 263 insertions(+)
drivers/net/mlx5/mlx5.h +8 -0
@@ -490,6 +490,7 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; +struct mlx5_aso_ct_action *ct; }; };
@@ -1007,6 +1008,10 @@ struct mlx5_aso_ct_action {bool is_original;/* The direction of the DR action to be used. */ }; +/* CT action object state update. */ +#define MLX5_ASO_CT_UPDATE_STATE (c, s) \ + __atomic_store_n(&((c)->state), (s), __ATOMIC_RELAXED) +/* ASO connection tracking software pool definition. */ struct mlx5_aso_ct_pool {uint16_t index;/* Pool index in pools array. */
@@ -1690,5 +1695,8 @@ int mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh, struct mlx5_aso_mtr *mtr);int mlx5_aso_mtr_wait (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_mtr *mtr); +int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +const struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -45,6 +45,7 @@ enum mlx5_rte_flow_action_type {enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE , +MLX5_INDIRECT_ACTION_TYPE_AGE , };/* Matches on selected register. */
@@ -839,6 +840,8 @@ struct mlx5_flow {#define MLX5_ASO_WQE_CQE_RESPONSE_DELAY 10u#define MLX5_MTR_POLL_WQE_CQE_TIMES 100000u +#define MLX5_CT_POLL_WQE_CQE_TIMES MLX5_MTR_POLL_WQE_CQE_TIMES +#define MLX5_MAN_WIDTH 8/* Legacy Meter parameter structure. */ struct mlx5_legacy_flow_meter {
drivers/net/mlx5/mlx5_flow_aso.c +252 -0
255 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v5 7/17 net/mlx5: add actions creating for CT
In reply to Bing ZhaoAllocating a CT from the management pools and creating the DR actions for both directions by default.
If there is no available connection tracking action, a new pool will be created with a fixed size bulk allocation. Right now, all the resources are controlled by the linked list.
The ASO connection tracking context associated with these actions need to be updated via WQE before using for steering.
--- drivers/net/mlx5/mlx5.h | 4 + drivers/net/mlx5/mlx5_flow.h | 29 +++- drivers/net/mlx5/mlx5_flow_dv.c | 263 ++++++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +4 -0
@@ -987,6 +987,10 @@ struct mlx5_bond_info {/* Number of connection tracking objects per pool: must be a power of 2. */ #define MLX5_ASO_CT_ACTIONS_PER_POOL 64 +/* Generate incremental and unique CT index from pool and offset. */ +#define MLX5_MAKE_CT_IDX (pool, offset) \ + ((pool) * MLX5_ASO_CT_ACTIONS_PER_POOL + (offset) + 1) +/* ASO Conntrack state. */ enum mlx5_aso_ct_state {ASO_CONNTRACK_FREE ,/* Inactive, in the free list. */
drivers/net/mlx5/mlx5_flow.h +28 -1
@@ -45,7 +45,7 @@ enum mlx5_rte_flow_action_type {enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE , -MLX5_INDIRECT_ACTION_TYPE_AGE , +MLX5_INDIRECT_ACTION_TYPE_CT , };/* Matches on selected register. */
@@ -1288,6 +1288,33 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)return &pool->mtrs[idx %MLX5_ASO_MTRS_PER_POOL ]; } +/* +* Get ASO CT action by index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +struct mlx5_aso_ct_pool *pool; + + idx--; +MLX5_ASSERT ((idx /MLX5_ASO_CT_ACTIONS_PER_POOL ) < mng->n); +/* Bit operation AND could be used. */ +rte_rwlock_read_lock (&mng->resize_rwl); + pool = mng->pools[idx /MLX5_ASO_CT_ACTIONS_PER_POOL ]; +rte_rwlock_read_unlock (&mng->resize_rwl); +return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +263 -0
281 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v5 8/17 net/mlx5: close CT management structure
In reply to Bing ZhaoWhen freeing the IB shared context during stopping a device, the ASO connection tracking management structure should also be cleaned up.
All the DR actions created should be destroyed. The structures need to be freed and ASO CT QP should be released. In the meanwhile, the allocated and registered memory region for query should also be deregistered and then freed.
--- drivers/net/mlx5/mlx5.c | 56 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 4 +++ 2 files changed, 60 insertions(+)
drivers/net/mlx5/mlx5.c +56 -0
@@ -706,6 +706,60 @@ mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh)return 0 ; } +/* +* Close and release all the resources of the +* ASO connection tracking management structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object to free. +*/ +static void +mlx5_flow_aso_ct_mng_close (struct mlx5_dev_ctx_shared *sh) +{ +struct mlx5_aso_ct_pools_mng *mng = sh->ct_mng; +struct mlx5_aso_ct_pool *ct_pool; +struct mlx5_aso_ct_action *ct; +uint32_t idx; +uint32_t val; +uint32_t cnt; +int i; + +mlx5_aso_queue_uninit (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); + idx = mng->next; +while (idx--) { + cnt =0 ; + ct_pool = mng->pools[idx]; +for (i =0 ; i <MLX5_ASO_CT_ACTIONS_PER_POOL ; i++) { + ct = &ct_pool->actions[i]; + val =__atomic_fetch_sub (&ct->refcnt,1 , + __ATOMIC_RELAXED); +MLX5_ASSERT (val ==1 ); +if (val >1 ) + cnt++; +#ifdef HAVE_MLX5_DR_ACTION_ASO_CT +if (ct->dr_action_orig) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_orig)); +if (ct->dr_action_rply) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_rply)); +#endif + } +claim_zero (mlx5_devx_cmd_destroy (ct_pool->devx_obj)); +if (cnt) { +DRV_LOG (DEBUG ,"%u ASO CT objects are being used in the pool %u" , + cnt, i); + } +mlx5_free (ct_pool); +/* in case of failure. */ + mng->next--; + } +mlx5_free (mng->pools); +mlx5_free (mng); +/* Management structure must be cleared to 0s during allocation. */ + sh->ct_mng =NULL ; +} +/** * Initialize the flow resources' indexed mempool. *
@@ -1508,6 +1562,8 @@ mlx5_dev_close(struct rte_eth_dev *dev)if (priv->mreg_cp_tbl)mlx5_hlist_destroy (priv->mreg_cp_tbl);mlx5_mprq_free_mp (dev); +if (priv->sh->ct_mng) +mlx5_flow_aso_ct_mng_close (priv->sh);mlx5_os_free_shared_dr (priv);if (priv->rss_conf.rss_key !=NULL )mlx5_free (priv->rss_conf.rss_key);
drivers/net/mlx5/mlx5_flow_aso.c +4 -0
@@ -372,6 +372,10 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,case ASO_OPC_MOD_POLICER : sq = &sh->mtrmng->pools_mng.sq;break ; +case ASO_OPC_MOD_CONNECTION_TRACKING : +mlx5_aso_dereg_mr (sh, &sh->ct_mng->aso_sq.mr); + sq = &sh->ct_mng->aso_sq; +break ;default :DRV_LOG (ERR ,"Unknown ASO operation mode" );return ;
Signature · 1 line
2.27.0
PATCH v5 9/17 net/mlx5: add ASO CT query implementation
In reply to Bing ZhaoAfter the connection tracking context is created and being used by the flows, the context will be updated by the HW automatically after a packet passed the CT validation. E.g., the ACK, SEQ, window and state of CT can be updated with both direction traffic.
In order to query the updated contents of this context, a WQE should be posted to the SQ with a return buffer. The data will be filled into the buffer. And the profile will be filled with specific value.
During the execution of query command, the context may be updated. The result of the query command may not be the latest one.
--- drivers/net/mlx5/mlx5.h | 10 +- drivers/net/mlx5/mlx5_flow_aso.c | 245 +++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 19 +++ 3 files changed, 273 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +9 -1
@@ -490,7 +490,10 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; -struct mlx5_aso_ct_action *ct; +struct { +struct mlx5_aso_ct_action *ct; +char *query_data; + }; }; };
@@ -1702,5 +1705,10 @@ int mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,const struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_wait_ready (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct); +int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow_aso.c +245 -0
263 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +19 -0
@@ -13775,6 +13775,8 @@ flow_dv_action_query(struct rte_eth_dev *dev,uint32_t act_idx = (uint32_t )(uintptr_t )handle;uint32_t type = act_idx >>MLX5_INDIRECT_ACTION_TYPE_OFFSET ;uint32_t idx = act_idx & ((1u <<MLX5_INDIRECT_ACTION_TYPE_OFFSET ) -1 ); +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct;switch (type) {case MLX5_INDIRECT_ACTION_TYPE_AGE :
@@ -13788,6 +13790,23 @@ flow_dv_action_query(struct rte_eth_dev *dev, resp->sec_since_last_hit =__atomic_load_n (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,EFAULT , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + ((struct rte_flow_action_conntrack *)data)->peer_port = + ct->peer; + ((struct rte_flow_action_conntrack *)data)->is_original_dir = + ct->is_original; +if (mlx5_aso_ct_query_by_wqe (priv->sh, ct, data)) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to query CT context" ); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v5 10/17 net/mlx5: add ASO CT destroy handling
In reply to Bing ZhaoWhen trying to destroy an ASO connection tracking context, the DR action created on this context should also be destroyed. Before inserting the related software object into the management free list, the reference count should be checked.
Right now, the context object will not be freed to the system and will be reused directly from the free list.
--- drivers/net/mlx5/mlx5_flow_dv.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +15 -1
@@ -11136,9 +11136,15 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +uint32_t ret;struct mlx5_aso_ct_action *ct =flow_aso_ct_get_by_idx (dev, idx); -uint32_t ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED); +enum mlx5_aso_ct_state state = +__atomic_load_n (&ct->state, __ATOMIC_RELAXED); +/* Cannot release when CT is in the ASO SQ. */ +if (state ==ASO_CONNTRACK_WAIT || state ==ASO_CONNTRACK_QUERY ) +return -1 ; + ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED);if (!ret) {if (ct->dr_action_orig) {#ifdef HAVE_MLX5_DR_ACTION_ASO_CT
@@ -11154,6 +11160,8 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx)#endif ct->dr_action_rply =NULL ; } +/* Clear the state to free, no need in 1st allocation. */ +MLX5_ASO_CT_UPDATE_STATE (ct,ASO_CONNTRACK_FREE );rte_spinlock_lock (&mng->ct_sl);LIST_INSERT_HEAD (&mng->free_cts, ct, next);rte_spinlock_unlock (&mng->ct_sl);
@@ -13648,6 +13656,12 @@ flow_dv_action_destroy(struct rte_eth_dev *dev,DRV_LOG (DEBUG ,"Indirect age action %" PRIu32" was" " released with references %d." , idx, ret);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ret =flow_dv_aso_ct_release (dev, idx); +if (ret) +DRV_LOG (DEBUG ,"Connection tracking object %u still " +"has references %d." , idx, ret); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v5 11/17 net/mlx5: add translation of CT action
In reply to Bing ZhaoWhen creating a flow with this action context for CT, it needs to be translated in 2 levels.
First, retrieve from action context to rte_flow action. Second, translate it to the corresponding DR action with traffic direction that was specified when creating or updating via rte_flow_action_handle* API.
Before using the DR action in a flow, the CT context should be available to use in the hardware. A synchronization is done before inserting the flow rule with CT action to check the HW availability of this CT context.
In order to release the DR actions and reuse the context of a CT, the reference count should also be handled in the flow rule destroying.
The CT index will be recorded in the rte_flow by reusing the ASO age index to save memory, since only one ASO action is supported in one flow rule currently. The action context type should also be saved for CT. When destroying a flow rule, if the context type is CT and the index is valid (non-zero), the release process should be handled. By default, the handling will fall back to try to release the ASO age if any.
--- drivers/net/mlx5/mlx5.h | 2 ++ drivers/net/mlx5/mlx5_flow.c | 9 +++++++ drivers/net/mlx5/mlx5_flow.h | 7 +++++- drivers/net/mlx5/mlx5_flow_aso.c | 41 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 28 +++++++++++++++++++++- 5 files changed, 85 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.h +2 -0
@@ -1710,5 +1710,7 @@ int mlx5_aso_ct_wait_ready(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_available (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.c +9 -0
@@ -3553,6 +3553,15 @@ flow_action_handles_translate(struct rte_eth_dev *dev,break ; }/* Fall-through */ +case MLX5_INDIRECT_ACTION_TYPE_CT : +if (priv->sh->ct_aso_en) { + translated[handle->index].type = +RTE_FLOW_ACTION_TYPE_CONNTRACK ; + translated[handle->index].conf = + (void *)(uintptr_t )idx; +break ; + } +/* Fall-through */ default :mlx5_free (translated);return rte_flow_error_set
drivers/net/mlx5/mlx5_flow.h +6 -1
@@ -226,6 +226,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)#define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40) +#define MLX5_FLOW_ACTION_CT (1ull << 41)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
@@ -969,11 +970,15 @@ struct rte_flow { uint32_t drv_type:2; /**< Driver type. */ uint32_t tunnel:1; uint32_t meter:24; /**< Holds flow meter id. */ + uint32_t indirect_type:2; /**< Indirect action type. */uint32_t rix_mreg_copy;/**< Index to metadata register copy table resource. */ uint32_t counter;/**< Holds flow counter. */ uint32_t tunnel_id;/**< Tunnel id */ -uint32_t age;/**< Holds ASO age bit index. */ +union { +uint32_t age;/**< Holds ASO age bit index. */ +uint32_t ct;/**< Holds ASO CT index. */ + };uint32_t geneve_tlv_option;/**< Holds Geneve TLV option id. > */ } __rte_packed;
drivers/net/mlx5/mlx5_flow_aso.c +41 -0
44 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +27 -1
@@ -11381,6 +11381,7 @@ flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,return rte_flow_error_set (error,EBUSY ,RTE_FLOW_ERROR_TYPE_ACTION ,NULL ,"Failed to update CT" ); + ct->is_original = !!pro->is_original_dir;return idx; }
@@ -11544,6 +11545,8 @@ flow_dv_translate(struct rte_eth_dev *dev,const struct rte_flow_action *found_action =NULL ;uint32_t jump_group =0 ;struct mlx5_flow_counter *cnt; +uint32_t ct_idx; +struct mlx5_aso_ct_action *ct;if (!mlx5_flow_os_action_supported (action_type)) return rte_flow_error_set(error, ENOTSUP,
@@ -12017,6 +12020,26 @@ flow_dv_translate(struct rte_eth_dev *dev,return -rte_errno; action_flags |=MLX5_FLOW_ACTION_MODIFY_FIELD ;break ; +case RTE_FLOW_ACTION_TYPE_CONNTRACK : + ct_idx = (uint32_t )(uintptr_t )action->conf; + ct =flow_aso_ct_get_by_idx (dev, ct_idx); +if (mlx5_aso_ct_available (priv->sh, ct)) +return rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_ACTION , +NULL , +"CT is unavailable." ); +if (ct->is_original) + dev_flow->dv.actions[actions_n] = + ct->dr_action_orig; +else + dev_flow->dv.actions[actions_n] = + ct->dr_action_rply; + flow->indirect_type =MLX5_INDIRECT_ACTION_TYPE_CT ; + flow->ct = ct_idx; +__atomic_fetch_add (&ct->refcnt,1 , __ATOMIC_RELAXED); + actions_n++; + action_flags |=MLX5_FLOW_ACTION_CT ; +break ;case RTE_FLOW_ACTION_TYPE_END : actions_end = true;if (mhdr_res->actions_num) {
@@ -13152,7 +13175,10 @@ flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)mlx5_flow_meter_detach (priv, fm); flow->meter =0 ; } -if (flow->age) +/* Keep the current age handling by default. */ +if (flow->indirect_type ==MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct) +flow_dv_aso_ct_release (dev, flow->ct); +else if (flow->age)flow_dv_aso_age_release (dev, flow->age);if (flow->geneve_tlv_option) {flow_dv_geneve_tlv_option_resource_release (dev);
Signature · 1 line
2.27.0
PATCH v5 12/17 net/mlx5: add translation of CT item
In reply to Bing ZhaoThe return register of the DR action will be used for matching. After the ASO CT checking of a TCP packet, the syndrome is filled in the register. Only the 8 LSB should be used. A converting from RTE_FLOW_CONNTRACK_FLAG* to the syndrome should be done after checing the spec and mask fields.
--- drivers/net/mlx5/mlx5_flow.h | 7 ++++ drivers/net/mlx5/mlx5_flow_dv.c | 62 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
drivers/net/mlx5/mlx5_flow.h +7 -0
@@ -405,6 +405,13 @@ enum mlx5_feature_name {/* Maximum number of fields to modify in MODIFY_FIELD */ #define MLX5_ACT_MAX_MOD_FIELDS 5 +/* Syndrome bits definition for connection tracking. */ +#define MLX5_CT_SYNDROME_VALID (0x0 << 6) +#define MLX5_CT_SYNDROME_INVALID (0x1 << 6) +#define MLX5_CT_SYNDROME_TRAP (0x2 << 6) +#define MLX5_CT_SYNDROME_STATE_CHANGE (0x1 << 1) +#define MLX5_CT_SYNDROME_BAD_PACKET (0x1 << 0) +enum mlx5_flow_drv_type {MLX5_FLOW_TYPE_MIN ,MLX5_FLOW_TYPE_DV ,
drivers/net/mlx5/mlx5_flow_dv.c +62 -0
74 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v5 13/17 net/mlx5: add CT context update
In reply to Bing ZhaoWhen updating a connection tracking context, two separate parts could be updated.
First, the direction. This will only update the traffic direction recorded in the software for flow creation.
Second, the TCP parameters. The hardware context will be updated via the WQE. This update will be blocked until the hardware status is updated and ready for the next flow creation.
--- drivers/net/mlx5/mlx5_flow_dv.c | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
drivers/net/mlx5/mlx5_flow_dv.c +56 -0
@@ -13824,6 +13824,60 @@ __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,return ret; } +/* +* Updates in place conntrack context or direction. +* Context update should be synchronized. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* The conntrack object ID to be updated. +* @param[in] update +* Pointer to the structure of information to update. +* @param[out] error +* Perform verbose error reporting if not NULL. Initialized in case of +* error only. +* +* @return +* 0 on success, otherwise negative errno value. +*/ +static int +__flow_dv_action_ct_update (struct rte_eth_dev *dev,uint32_t idx, +const struct rte_flow_modify_conntrack *update, +struct rte_flow_error *error) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +const struct rte_flow_action_conntrack *new_prf; +int ret =0 ; + + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,ENOMEM , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + new_prf = &update->new_ct; +if (update->direction) + ct->is_original = !!new_prf->is_original_dir; +if (update->state) { + ret =mlx5_aso_ct_update_by_wqe (priv->sh, ct, new_prf); +if (ret) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to send CT context update WQE" ); +/* Block until ready or a failure. */ + ret =mlx5_aso_ct_available (priv->sh, ct); +if (ret) +rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Timeout to get the CT update" ); + } +return ret; +} +/** * Updates in place shared action configuration, lock free, * (mutex should be acquired by caller).
@@ -13859,6 +13913,8 @@ flow_dv_action_update(struct rte_eth_dev *dev,case MLX5_INDIRECT_ACTION_TYPE_RSS : action_conf = ((const struct rte_flow_action *)update)->conf;return __flow_dv_action_rss_update (dev, idx, action_conf, err); +case MLX5_INDIRECT_ACTION_TYPE_CT : +return __flow_dv_action_ct_update (dev, idx, update, err);default : return rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v5 14/17 net/mlx5: validation of CT action
In reply to Bing ZhaoThe validation of a CT action contains two parts. The first is the CT action configurations parameter. When creating a CT action context, some members need to be verified.
The second is that when creating a flow, the DR action of CT should be validated with other actions and items as well. Currently, only the TCP protocol support connection tracking.
--- drivers/net/mlx5/mlx5.h | 4 ++ drivers/net/mlx5/mlx5_flow.c | 31 +++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 69 +++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+)
drivers/net/mlx5/mlx5.h +4 -0
@@ -1611,6 +1611,10 @@ int mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow,void mlx5_flow_rxq_dynf_metadata_set (struct rte_eth_dev *dev);int mlx5_flow_get_aged_flows (struct rte_eth_dev *dev,void **contexts,uint32_t nb_contexts,struct rte_flow_error *error); +int mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error); +/* mlx5_mp_os.c */
drivers/net/mlx5/mlx5_flow.c +31 -0
@@ -1688,6 +1688,37 @@ mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,return 0 ; } +/* +* Validate the ASO CT action. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] conntrack +* Pointer to the CT action profile. +* @param[out] error +* Pointer to error structure. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error) +{ +RTE_SET_USED (dev); + +if (conntrack->state >RTE_FLOW_CONNTRACK_STATE_TIME_WAIT ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid CT state" ); +if (conntrack->last_index >RTE_FLOW_CONNTRACK_FLAG_RST ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid last TCP packet flag" ); +return 0 ; +} +/** * Verify the @p attributes will be correctly understood by the NIC and store * them in the @p flow if everything is correct.
drivers/net/mlx5/mlx5_flow_dv.c +69 -0
93 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v5 15/17 net/mlx5: validation of CT item
In reply to Bing ZhaoThe item of ASO connection tracking will be translated into the register value when matching. The validation of this item has no dependency on other layers, since the flow including this item should be jumped from another group. All the layers checking was already done in the previous groups. Only the state bits conflict should be checked.
It is assumed that the flow with CT item will always work on the TCP traffic.
--- drivers/net/mlx5/mlx5_flow.h | 3 ++ drivers/net/mlx5/mlx5_flow_dv.c | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -147,6 +147,9 @@ enum mlx5_feature_name {#define MLX5_FLOW_LAYER_GENEVE_OPT (UINT64_C(1) << 32)#define MLX5_FLOW_LAYER_GTP_PSC (UINT64_C(1) << 33) +/* Conntrack item. */ +#define MLX5_FLOW_LAYER_ASO_CT (UINT64_C(1) << 34) +/* Outer Masks. */ #define MLX5_FLOW_LAYER_OUTER_L3 \ (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6)
drivers/net/mlx5/mlx5_flow_dv.c +51 -0
63 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v5 16/17 net/mlx5: add support of CT between two ports
In reply to Bing ZhaoAfter creating a connection tracking context, it can be used between two ports. For each port, the flow for one direction traffic will be created.
The context can only be shared between the owner port and the peer port that was specified when being created. Only the owner port could update the context or query it in current implementation.
--- drivers/net/mlx5/mlx5_flow.h | 57 +++++++++++++++++++++++++- drivers/net/mlx5/mlx5_flow_dv.c | 71 +++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 18 deletions(-)
drivers/net/mlx5/mlx5_flow.h +55 -2
@@ -48,6 +48,25 @@ enum { MLX5_INDIRECT_ACTION_TYPE_CT, }; +/* Now, the maximal ports will be supported is 256, action number is 4M. */ +#define MLX5_INDIRECT_ACT_CT_MAX_PORT 0x100 + +#define MLX5_INDIRECT_ACT_CT_OWNER_SHIFT 22 +#define MLX5_INDIRECT_ACT_CT_OWNER_MASK (MLX5_INDIRECT_ACT_CT_MAX_PORT - 1) + +/* 30-31: type, 22-29: owner port, 0-21: index. */ +#define MLX5_INDIRECT_ACT_CT_GEN_IDX (owner, index) \ + ((MLX5_INDIRECT_ACTION_TYPE_CT << MLX5_INDIRECT_ACTION_TYPE_OFFSET) | \ + (((owner) & MLX5_INDIRECT_ACT_CT_OWNER_MASK) << \ + MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) | (index)) + +#define MLX5_INDIRECT_ACT_CT_GET_OWNER (index) \ + (((index) >> MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) & \ + MLX5_INDIRECT_ACT_CT_OWNER_MASK) + +#define MLX5_INDIRECT_ACT_CT_GET_IDX (index) \ + ((index) & ((1 << MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) - 1)) +/* Matches on selected register. */ struct mlx5_rte_flow_item_tag {enum modify_reg id;
@@ -1304,7 +1323,7 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx) }/* -* Get ASO CT action by index. +* Get ASO CT action by device and index. * * @param[in] dev * Pointer to the Ethernet device structure.
@@ -1315,7 +1334,7 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)* The specified ASO CT action pointer. */ static inline struct mlx5_aso_ct_action * -flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +flow_aso_ct_get_by_dev_idx (struct rte_eth_dev *dev,uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
@@ -1330,6 +1349,40 @@ flow_aso_ct_get_by_idx(struct rte_eth_dev *dev, uint32_t idx)return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; } +/* +* Get ASO CT action by owner & index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action and owner port combination. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t own_idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +uint16_t owner = (uint16_t )MLX5_INDIRECT_ACT_CT_GET_OWNER (own_idx); +uint32_t idx =MLX5_INDIRECT_ACT_CT_GET_IDX (own_idx); + +if (owner ==PORT_ID (priv)) { + ct =flow_aso_ct_get_by_dev_idx (dev, idx); + }else { +struct rte_eth_dev *owndev = &rte_eth_devices[owner]; + +MLX5_ASSERT (owner <RTE_MAX_ETHPORTS ); +if (dev->data->dev_started !=1 ) +return NULL ; + ct =flow_aso_ct_get_by_dev_idx (owndev, idx); +if (ct->peer !=PORT_ID (priv)) +return NULL ; + } +return ct; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +55 -16
165 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v5 17/17 doc: update mlx5 support for conntrack
In reply to Bing ZhaoIn the release notes and mlx5 NIC document, the support and limitation of connection tracking are added.
--- doc/guides/nics/features/default.ini | 1 + doc/guides/nics/features/mlx5.ini | 1 + doc/guides/nics/mlx5.rst | 14 ++++++++++++++ doc/guides/rel_notes/release_21_05.rst | 2 ++ 4 files changed, 18 insertions(+)
doc/guides/nics/features/default.ini +1 -0
@@ -66,6 +66,7 @@ Module EEPROM dump = Registers dump = LED = Multiprocess aware = +Connection tracking = FreeBSD = Linux = Windows =
doc/guides/nics/features/mlx5.ini +1 -0
@@ -45,6 +45,7 @@ Stats per queue = Y FW version = Y Module EEPROM dump = Y Multiprocess aware = Y +Connection tracking = Y Linux = Y Windows = P ARMv8 = Y
doc/guides/nics/mlx5.rst +14 -0
@@ -107,6 +107,7 @@ Features - 21844 flow priorities for ingress or egress flow groups greater than 0 and for any transfer flow group. - Flow metering, including meter policy API. +- Connection tracking. Limitations -----------
@@ -418,6 +419,14 @@ Limitations - RED: must be DROP. - meter profile packet mode is supported. +- Connection tracking: + + - connection tracking (conntrack) couldn't co-exist with ASO meter, ASO age action in a single flow rule. + - Flow rules insertion rate and memory consumption. + - software limitation: + - ports: a maximal number of 256. + - conntrack: a maximal number of 4M. + Statistics ----------
@@ -1680,6 +1689,11 @@ Supported hardware offloads | | | rdma-core 35 | | rdma-core 35 | | | | ConnectX-5 | | ConnectX-5 | +-----------------------+-----------------+-----------------+ + | Connection tracking | | | | DPDK 21.05 | + | | | N/A | | OFED 5.3 | + | | | | | rdma-core 35 | + | | | | | ConnectX-6 Dx | + +-----------------------+-----------------+-----------------+ .. table:: Minimal SW/HW versions for shared action offload :name: sact
doc/guides/rel_notes/release_21_05.rst +2 -0
@@ -166,6 +166,8 @@ New Features * Added support for ASO (Advanced Steering Operation) meter. * Added support for ASO metering by PPS (packet per second). * Added support for the monitor policy of Power Management API. + * Added support for connection tracking action and item as well as context create, + destroy, update and query. * **Updated NXP DPAA driver.**
Signature · 1 line
2.27.0
v6 cover conntrack support in mlx5 PMD
In reply to Bing ZhaoThis patch set adds the connection tracking offload support in the mlx5 driver, as well as the documents update.
---
v2: code bug fixes, commits clean up and doc update
v3: fix error input pointer for CT MR registering
v4: fix typo in commit message of patch 11
v5: adjust mkey to lkey in SQ initialization
v6: rebase and solve the conflict
---
Bing Zhao (17):
common/mlx5: add connection tracking object definition common/mlx5: add CT offload capability checking net/mlx5: use meter color reg for CT net/mlx5: initialization of CT management common/mlx5: add Dexv CT objects creation net/mlx5: add modify support for CT
net/mlx5: add actions creating for CT net/mlx5: close CT management structure net/mlx5: add ASO CT query implementation net/mlx5: add ASO CT destroy handling net/mlx5: add translation of CT action net/mlx5: add translation of CT item net/mlx5: add CT context update
net/mlx5: validation of CT action
net/mlx5: validation of CT item
net/mlx5: add support of CT between two ports
doc: update mlx5 support for conntrack
doc/guides/nics/features/default.ini | 1 + doc/guides/nics/features/mlx5.ini | 1 + doc/guides/nics/mlx5.rst | 14 + doc/guides/rel_notes/release_21_05.rst | 2 + drivers/common/mlx5/linux/meson.build | 2 + drivers/common/mlx5/mlx5_devx_cmds.c | 53 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 5 + drivers/common/mlx5/mlx5_prm.h | 88 ++++ drivers/common/mlx5/version.map | 1 + drivers/net/mlx5/linux/mlx5_os.c | 13 + drivers/net/mlx5/mlx5.c | 92 ++++ drivers/net/mlx5/mlx5.h | 76 ++++ drivers/net/mlx5/mlx5_flow.c | 44 +- drivers/net/mlx5/mlx5_flow.h | 101 ++++- drivers/net/mlx5/mlx5_flow_aso.c | 592 ++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 601 ++++++++++++++++++++++++- 16 files changed, 1683 insertions(+), 3 deletions(-)
Signature · 1 line
2.27.0
PATCH v6 1/17 common/mlx5: add connection tracking object definition
The structures of ASO connection tracking offload object are added based on the definitions in the PRM. One CT object context will be loaded into the cache completely in a reversed order of dwords. The valid bit should be the MSB of the last dword. This is used for the conntrack context creation and update, as well as for the query.
The capabilities 2 (HCA_CAP_2) layout is also added. The connection tracking related capabilities could be queried via the HCA_CAP_2.
--- drivers/common/mlx5/mlx5_prm.h | 85 ++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
drivers/common/mlx5/mlx5_prm.h +85 -0
@@ -1124,6 +1124,7 @@ enum {MLX5_GET_HCA_CAP_OP_MOD_ROCE =0x4 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE =0x7 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_VDPA_EMULATION =0x13 <<1 , + MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE_2 = 0x20 << 1, };#define MLX5_GENERAL_OBJ_TYPES_CAP_VIRTQ_NET_Q \
@@ -1692,6 +1693,29 @@ struct mlx5_ifc_flow_table_nic_cap_bits { ft_field_support_2_nic_receive; }; +struct mlx5_ifc_cmd_hca_cap_2_bits { +u8 reserved_at_0[0x80 ];/* End of DW4. */ +u8 reserved_at_80[0xb ]; +u8 log_max_num_reserved_qpn[0x5 ]; +u8 reserved_at_90[0x3 ]; +u8 log_reserved_qpn_granularity[0x5 ]; +u8 reserved_at_98[0x3 ]; +u8 log_reserved_qpn_max_alloc[0x5 ];/* End of DW5. */ +u8 max_reformat_insert_size[0x8 ]; +u8 max_reformat_insert_offset[0x8 ]; +u8 max_reformat_remove_size[0x8 ]; +u8 max_reformat_remove_offset[0x8 ];/* End of DW6. */ +u8 aso_conntrack_reg_id[0x8 ]; +u8 reserved_at_c8[0x3 ]; +u8 log_conn_track_granularity[0x5 ]; +u8 reserved_at_d0[0x3 ]; +u8 log_conn_track_max_alloc[0x5 ]; +u8 reserved_at_d8[0x3 ]; +u8 log_max_conn_track_offload[0x5 ]; +u8 reserved_at_e0[0x20 ];/* End of DW7. */ +u8 reserved_at_100[0x700 ]; +}; +union mlx5_ifc_hca_cap_union_bits {struct mlx5_ifc_cmd_hca_cap_bits cmd_hca_cap;struct mlx5_ifc_per_protocol_networking_offload_caps_bits
@@ -2630,6 +2654,67 @@ struct mlx5_ifc_create_flow_meter_aso_in_bits {struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr;struct mlx5_ifc_flow_meter_aso_bits flow_meter_aso; }; + +struct mlx5_ifc_tcp_window_params_bits { +u8 max_ack[0x20 ]; +u8 max_win[0x20 ]; +u8 reply_end[0x20 ]; +u8 sent_end[0x20 ]; +}; + +struct mlx5_ifc_conn_track_aso_bits { +struct mlx5_ifc_tcp_window_params_bits reply_dir;/* End of DW3. */ +struct mlx5_ifc_tcp_window_params_bits original_dir;/* End of DW7. */ +u8 last_end[0x20 ];/* End of DW8. */ +u8 last_ack[0x20 ];/* End of DW9. */ +u8 last_seq[0x20 ];/* End of DW10. */ +u8 last_win[0x10 ]; +u8 reserved_at_170[0xa ]; +u8 last_dir[0x1 ]; +u8 last_index[0x5 ];/* End of DW11. */ +u8 reserved_at_180[0x40 ];/* End of DW13. */ +u8 reply_direction_tcp_scale[0x4 ]; +u8 reply_direction_tcp_close_initiated[0x1 ]; +u8 reply_direction_tcp_liberal_enabled[0x1 ]; +u8 reply_direction_tcp_data_unacked[0x1 ]; +u8 reply_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1c8[0x8 ]; +u8 original_direction_tcp_scale[0x4 ]; +u8 original_direction_tcp_close_initiated[0x1 ]; +u8 original_direction_tcp_liberal_enabled[0x1 ]; +u8 original_direction_tcp_data_unacked[0x1 ]; +u8 original_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1d8[0x8 ];/* End of DW14. */ +u8 valid[0x1 ]; +u8 state[0x3 ]; +u8 freeze_track[0x1 ]; +u8 reserved_at_1e5[0xb ]; +u8 reserved_at_1f0[0x1 ]; +u8 connection_assured[0x1 ]; +u8 sack_permitted[0x1 ]; +u8 challenged_acked[0x1 ]; +u8 heartbeat[0x1 ]; +u8 max_ack_window[0x3 ]; +u8 reserved_at_1f8[0x1 ]; +u8 retransmission_counter[0x3 ]; +u8 retranmission_limit_exceeded[0x1 ]; +u8 retranmission_limit[0x3 ];/* End of DW15. */ +}; + +struct mlx5_ifc_conn_track_offload_bits { +u8 modify_field_select[0x40 ]; +u8 reserved_at_40[0x40 ]; +u8 reserved_at_80[0x8 ]; +u8 conn_track_aso_access_pd[0x18 ]; +u8 reserved_at_a0[0x160 ]; +struct mlx5_ifc_conn_track_aso_bits conn_track_aso; +}; + +struct mlx5_ifc_create_conn_track_aso_in_bits { +struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr; +struct mlx5_ifc_conn_track_offload_bits conn_track_offload; +}; +enum mlx5_access_aso_opc_mod {ASO_OPC_MOD_IPSEC =0x0 ,ASO_OPC_MOD_CONNECTION_TRACKING =0x1 ,
Signature · 1 line
2.27.0
PATCH v6 2/17 common/mlx5: add CT offload capability checking
In reply to Bing ZhaoDuring startup, the ASO connection tracking offload capability could be queried via HCA_CAP_QUERY command. If the HW doesn't support ASO CT, the value would be 0 by default. The following initialization should be skipped and the creation of the CT object should return a failure directly.
The following CT creation should also check this capability. With the old driver, the pre-processing macro should be used in order to make the compiling pass.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/mlx5_devx_cmds.c | 3 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 3 +++ 4 files changed, 9 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -189,6 +189,8 @@ has_sym_args = [ 'MLX5_WQE_UMR_CTRL_FLAG_INLINE' ], [ 'HAVE_MLX5_DR_FLOW_DUMP_RULE', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_rule' ], + [ 'HAVE_MLX5_DR_ACTION_ASO_CT', 'infiniband/mlx5dv.h', + 'MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR' ], ] config = configuration_data() foreach arg:has_sym_args
drivers/common/mlx5/mlx5_devx_cmds.c +3 -0
@@ -783,6 +783,9 @@ mlx5_devx_cmd_query_hca_attr(void *ctx,MLX5_GET (cmd_hca_cap, hcattr, umr_indirect_mkey_disabled); attr->umr_modify_entity_size_disabled =MLX5_GET (cmd_hca_cap, hcattr, umr_modify_entity_size_disabled); + attr->ct_offload = !!(MLX5_GET64 (cmd_hca_cap, hcattr, + general_obj_types) & +MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD );if (attr->qos.sup) { MLX5_SET(query_hca_cap_in, in, op_mod, MLX5_GET_HCA_CAP_OP_MOD_QOS_CAP |
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -137,6 +137,7 @@ struct mlx5_hca_attr { uint32_t qp_ts_format:2; uint32_t regex:1; uint32_t reg_c_preserve:1; + uint32_t ct_offload:1; /* General obj type ASO CT offload supported. */uint32_t regexp_num_of_engines; uint32_t log_max_ft_sampler_num:8;uint32_t geneve_tlv_opt;
drivers/common/mlx5/mlx5_prm.h +3 -0
@@ -1139,6 +1139,8 @@ enum { (1ULL << MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO)#define MLX5_GENERAL_OBJ_TYPES_CAP_GENEVE_TLV_OPT \ (1ULL << MLX5_OBJ_TYPE_GENEVE_TLV_OPT) +#define MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD \ + (1ULL << MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD)enum {MLX5_HCA_CAP_OPMOD_GET_MAX =0 ,
@@ -2487,6 +2489,7 @@ enum {MLX5_GENERAL_OBJ_TYPE_FLEX_PARSE_GRAPH =0x0022 ,MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO =0x0024 ,MLX5_GENERAL_OBJ_TYPE_FLOW_HIT_ASO =0x0025 , + MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD = 0x0031, }; struct mlx5_ifc_general_obj_in_cmd_hdr_bits {
Signature · 1 line
2.27.0
PATCH v6 3/17 net/mlx5: use meter color reg for CT
In reply to Bing ZhaoBased on the capacity, 3 registers could be used. Due to the register allocation, only the one REG_C_3 for meter color could be reused right now.
Then in the same flow, no more than one ASO action can be supported.
--- drivers/net/mlx5/mlx5_flow.c | 4 +++- drivers/net/mlx5/mlx5_flow.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow.c +3 -1
@@ -760,7 +760,9 @@ mlx5_flow_get_reg_id(struct rte_eth_dev *dev,return priv->mtr_color_reg !=REG_C_2 ?REG_C_2 :REG_C_3 ;case MLX5_MTR_COLOR : -case MLX5_ASO_FLOW_HIT :/* Both features use the same REG_C. */ +case MLX5_ASO_FLOW_HIT : +case MLX5_ASO_CONNTRACK : +/* All features use the same REG_C. */ MLX5_ASSERT (priv->mtr_color_reg !=REG_NON );return priv->mtr_color_reg;case MLX5_COPY_MARK :
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -85,6 +85,7 @@ enum mlx5_feature_name {MLX5_MTR_COLOR ,MLX5_MTR_ID ,MLX5_ASO_FLOW_HIT , + MLX5_ASO_CONNTRACK, };/* Default queue number. */
Signature · 1 line
2.27.0
PATCH v6 4/17 net/mlx5: initialization of CT management
In reply to Bing ZhaoThe definitions of ASO connection tracking objects management structures are added.
Considering performance, the bulk allocation of ASO CT objects should be used. The maximal value per bulk and the granularity could be fetched from HCA capabilities 2. Right now, a fixed number of 64 is used for each bulk for a better management purpose.
The ASO QP for CT is initialized, the SQ will be used for both modify and query command.
--- drivers/net/mlx5/linux/mlx5_os.c | 13 +++++++++ drivers/net/mlx5/mlx5.c | 36 +++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 50 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 50 ++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +13 -0
@@ -1323,6 +1323,19 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,DRV_LOG (DEBUG ,"Flow Hit ASO is supported." ); }#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */ +#if defined(HAVE_MLX5_DR_CREATE_ACTION_ASO ) && \ + defined(HAVE_MLX5_DR_ACTION_ASO_CT ) +if (config->hca_attr.ct_offload && + priv->mtr_color_reg ==REG_C_3 ) { + err =mlx5_flow_aso_ct_mng_init (sh); +if (err) { + err = -err; + goto error; + } +DRV_LOG (DEBUG ,"CT ASO is supported." ); + sh->ct_aso_en =1 ; + } +#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO && HAVE_MLX5_DR_ACTION_ASO_CT */ #if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE )if (config->hca_attr.log_max_ft_sampler_num >0 && config->dv_flow_en) {
drivers/net/mlx5/mlx5.c +36 -0
@@ -672,6 +672,42 @@ mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh) } } +/* +* Initialize the ASO connection tracking structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_flow_aso_ct_mng_init (struct mlx5_dev_ctx_shared *sh) +{ +int err; + +if (sh->ct_mng) +return 0 ; + sh->ct_mng =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*sh->ct_mng), +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +if (!sh->ct_mng) { +DRV_LOG (ERR ,"ASO CT management allocation failed." ); + rte_errno =ENOMEM ; +return -rte_errno; + } + err =mlx5_aso_queue_init (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); +if (err) { +mlx5_free (sh->ct_mng); +/* rte_errno should be extracted from the failure. */ + rte_errno =EINVAL ; +return -rte_errno; + } +rte_spinlock_init (&sh->ct_mng->ct_sl); +rte_rwlock_init (&sh->ct_mng->resize_rwl); +LIST_INIT (&sh->ct_mng->free_cts); +return 0 ; +} +/** * Initialize the flow resources' indexed mempool. *
drivers/net/mlx5/mlx5.h +50 -0
74 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_aso.c +50 -0
62 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v6 5/17 common/mlx5: add Dexv CT objects creation
In reply to Bing ZhaoAdding support for connection tracking ASO creation via Devx command. Right now only bulk creation is supported.
By default, the objects with zero contents will be created. Before using a single object, the modification via posting a WQE to the ASO CT SQ is needed.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 50 ++++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 4 +++ drivers/common/mlx5/version.map | 1 + 3 files changed, 55 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +50 -0
@@ -2255,6 +2255,56 @@ mlx5_devx_cmd_create_flow_meter_aso_obj(void *ctx, uint32_t pd,return flow_meter_aso_obj; } +/* +* Create general object of type CONN_TRACK_OFFLOAD using DevX API. +* +* @param[in] ctx +* Context returned from mlx5 open_device() glue function. +* @param [in] pd +* PD value to associate the CONN_TRACK_OFFLOAD ASO object with. +* @param [in] log_obj_size +* log_obj_size to allocate its power of 2 * objects +* in one CONN_TRACK_OFFLOAD bulk allocation. +* +* @return +* The DevX object created, NULL otherwise and rte_errno is set. +*/ +struct mlx5_devx_obj * +mlx5_devx_cmd_create_conn_track_offload_obj (void *ctx,uint32_t pd, +uint32_t log_obj_size) +{ +uint32_t in[MLX5_ST_SZ_DW (create_conn_track_aso_in)] = {0 }; +uint32_t out[MLX5_ST_SZ_DW (general_obj_out_cmd_hdr)]; +struct mlx5_devx_obj *ct_aso_obj; +void *ptr; + + ct_aso_obj =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*ct_aso_obj), +0 ,SOCKET_ID_ANY ); +if (!ct_aso_obj) { +DRV_LOG (ERR ,"Failed to allocate CONN_TRACK_OFFLOAD object." ); + rte_errno =ENOMEM ; +return NULL ; + } + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, hdr); +MLX5_SET (general_obj_in_cmd_hdr, ptr, opcode, +MLX5_CMD_OP_CREATE_GENERAL_OBJECT ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, obj_type, +MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, log_obj_range, log_obj_size); + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, conn_track_offload); +MLX5_SET (conn_track_offload, ptr, conn_track_aso_access_pd, pd); + ct_aso_obj->obj = mlx5_glue->devx_obj_create (ctx, in,sizeof (in), + out,sizeof (out)); +if (!ct_aso_obj->obj) { + rte_errno = errno; +DRV_LOG (ERR ,"Failed to create CONN_TRACK_OFFLOAD obj by using DevX." ); +mlx5_free (ct_aso_obj); +return NULL ; + } + ct_aso_obj->id =MLX5_GET (general_obj_out_cmd_hdr, out, obj_id); +return ct_aso_obj; +} +/** * Create general object of type GENEVE TLV option using DevX API. *
drivers/common/mlx5/mlx5_devx_cmds.h +4 -0
@@ -570,6 +570,10 @@ struct mlx5_devx_obj *mlx5_devx_cmd_queue_counter_alloc(void *ctx);__rte_internal int mlx5_devx_cmd_queue_counter_query(struct mlx5_devx_obj *dcs, int clear,uint32_t *out_of_buffers); +__rte_internal +struct mlx5_devx_obj *mlx5_devx_cmd_create_conn_track_offload_obj(void *ctx, +uint32_t pd,uint32_t log_obj_size); +/** * Create general object of type FLOW_METER_ASO using DevX API.. *
drivers/common/mlx5/version.map +1 -0
@@ -13,6 +13,7 @@ INTERNAL { mlx5_dev_to_pci_addr; # WINDOWS_NO_EXPORT mlx5_devx_cmd_alloc_pd; + mlx5_devx_cmd_create_conn_track_offload_obj; mlx5_devx_cmd_create_cq; mlx5_devx_cmd_create_flex_parser; mlx5_devx_cmd_create_qp;
Signature · 1 line
2.27.0
PATCH v6 6/17 net/mlx5: add modify support for CT
In reply to Bing ZhaoAfter the connection tracking object bulk is allocated, all the objects' contents are filled with zero by default. Every new-allocated object must be modified via WQE operation before it is used.
In order to reduce the latency for the flow creation, an asynchronous way is used instead of busy waiting for the CQE to be generated.
--- drivers/net/mlx5/mlx5.h | 8 + drivers/net/mlx5/mlx5_flow.h | 2 + drivers/net/mlx5/mlx5_flow_aso.c | 252 +++++++++++++++++++++++++++++++ 3 files changed, 262 insertions(+)
drivers/net/mlx5/mlx5.h +8 -0
@@ -493,6 +493,7 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; +struct mlx5_aso_ct_action *ct; }; };
@@ -1012,6 +1013,10 @@ struct mlx5_aso_ct_action {bool is_original;/* The direction of the DR action to be used. */ }; +/* CT action object state update. */ +#define MLX5_ASO_CT_UPDATE_STATE (c, s) \ + __atomic_store_n(&((c)->state), (s), __ATOMIC_RELAXED) +/* ASO connection tracking software pool definition. */ struct mlx5_aso_ct_pool {uint16_t index;/* Pool index in pools array. */
@@ -1695,5 +1700,8 @@ int mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh, struct mlx5_aso_mtr *mtr);int mlx5_aso_mtr_wait (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_mtr *mtr); +int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +const struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.h +2 -0
@@ -843,6 +843,8 @@ struct mlx5_flow {#define MLX5_ASO_WQE_CQE_RESPONSE_DELAY 10u#define MLX5_MTR_POLL_WQE_CQE_TIMES 100000u +#define MLX5_CT_POLL_WQE_CQE_TIMES MLX5_MTR_POLL_WQE_CQE_TIMES +#define MLX5_MAN_WIDTH 8/* Legacy Meter parameter structure. */ struct mlx5_legacy_flow_meter {
drivers/net/mlx5/mlx5_flow_aso.c +252 -0
255 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v6 7/17 net/mlx5: add actions creating for CT
In reply to Bing ZhaoAllocating a CT from the management pools and creating the DR actions for both directions by default.
If there is no available connection tracking action, a new pool will be created with a fixed size bulk allocation. Right now, all the resources are controlled by the linked list.
The ASO connection tracking context associated with these actions need to be updated via WQE before using for steering.
--- drivers/net/mlx5/mlx5.h | 4 + drivers/net/mlx5/mlx5_flow.h | 28 ++++ drivers/net/mlx5/mlx5_flow_dv.c | 263 ++++++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+)
drivers/net/mlx5/mlx5.h +4 -0
@@ -992,6 +992,10 @@ struct mlx5_bond_info {/* Number of connection tracking objects per pool: must be a power of 2. */ #define MLX5_ASO_CT_ACTIONS_PER_POOL 64 +/* Generate incremental and unique CT index from pool and offset. */ +#define MLX5_MAKE_CT_IDX (pool, offset) \ + ((pool) * MLX5_ASO_CT_ACTIONS_PER_POOL + (offset) + 1) +/* ASO Conntrack state. */ enum mlx5_aso_ct_state {ASO_CONNTRACK_FREE ,/* Inactive, in the free list. */
drivers/net/mlx5/mlx5_flow.h +28 -0
@@ -46,6 +46,7 @@ enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE ,MLX5_INDIRECT_ACTION_TYPE_COUNT , + MLX5_INDIRECT_ACTION_TYPE_CT, };/* Matches on selected register. */
@@ -1317,6 +1318,33 @@ mlx5_validate_integrity_item(const struct rte_flow_item_integrity *item)return (test.value ==0 ); } +/* +* Get ASO CT action by index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +struct mlx5_aso_ct_pool *pool; + + idx--; +MLX5_ASSERT ((idx /MLX5_ASO_CT_ACTIONS_PER_POOL ) < mng->n); +/* Bit operation AND could be used. */ +rte_rwlock_read_lock (&mng->resize_rwl); + pool = mng->pools[idx /MLX5_ASO_CT_ACTIONS_PER_POOL ]; +rte_rwlock_read_unlock (&mng->resize_rwl); +return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +263 -0
281 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v6 8/17 net/mlx5: close CT management structure
In reply to Bing ZhaoWhen freeing the IB shared context during stopping a device, the ASO connection tracking management structure should also be cleaned up.
All the DR actions created should be destroyed. The structures need to be freed and ASO CT QP should be released. In the meanwhile, the allocated and registered memory region for query should also be deregistered and then freed.
--- drivers/net/mlx5/mlx5.c | 56 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 4 +++ 2 files changed, 60 insertions(+)
drivers/net/mlx5/mlx5.c +56 -0
@@ -708,6 +708,60 @@ mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh)return 0 ; } +/* +* Close and release all the resources of the +* ASO connection tracking management structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object to free. +*/ +static void +mlx5_flow_aso_ct_mng_close (struct mlx5_dev_ctx_shared *sh) +{ +struct mlx5_aso_ct_pools_mng *mng = sh->ct_mng; +struct mlx5_aso_ct_pool *ct_pool; +struct mlx5_aso_ct_action *ct; +uint32_t idx; +uint32_t val; +uint32_t cnt; +int i; + +mlx5_aso_queue_uninit (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); + idx = mng->next; +while (idx--) { + cnt =0 ; + ct_pool = mng->pools[idx]; +for (i =0 ; i <MLX5_ASO_CT_ACTIONS_PER_POOL ; i++) { + ct = &ct_pool->actions[i]; + val =__atomic_fetch_sub (&ct->refcnt,1 , + __ATOMIC_RELAXED); +MLX5_ASSERT (val ==1 ); +if (val >1 ) + cnt++; +#ifdef HAVE_MLX5_DR_ACTION_ASO_CT +if (ct->dr_action_orig) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_orig)); +if (ct->dr_action_rply) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_rply)); +#endif + } +claim_zero (mlx5_devx_cmd_destroy (ct_pool->devx_obj)); +if (cnt) { +DRV_LOG (DEBUG ,"%u ASO CT objects are being used in the pool %u" , + cnt, i); + } +mlx5_free (ct_pool); +/* in case of failure. */ + mng->next--; + } +mlx5_free (mng->pools); +mlx5_free (mng); +/* Management structure must be cleared to 0s during allocation. */ + sh->ct_mng =NULL ; +} +/** * Initialize the flow resources' indexed mempool. *
@@ -1510,6 +1564,8 @@ mlx5_dev_close(struct rte_eth_dev *dev)if (priv->mreg_cp_tbl)mlx5_hlist_destroy (priv->mreg_cp_tbl);mlx5_mprq_free_mp (dev); +if (priv->sh->ct_mng) +mlx5_flow_aso_ct_mng_close (priv->sh);mlx5_os_free_shared_dr (priv);if (priv->rss_conf.rss_key !=NULL )mlx5_free (priv->rss_conf.rss_key);
drivers/net/mlx5/mlx5_flow_aso.c +4 -0
@@ -372,6 +372,10 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,case ASO_OPC_MOD_POLICER : sq = &sh->mtrmng->pools_mng.sq;break ; +case ASO_OPC_MOD_CONNECTION_TRACKING : +mlx5_aso_dereg_mr (sh, &sh->ct_mng->aso_sq.mr); + sq = &sh->ct_mng->aso_sq; +break ;default :DRV_LOG (ERR ,"Unknown ASO operation mode" );return ;
Signature · 1 line
2.27.0
PATCH v6 9/17 net/mlx5: add ASO CT query implementation
In reply to Bing ZhaoAfter the connection tracking context is created and being used by the flows, the context will be updated by the HW automatically after a packet passed the CT validation. E.g., the ACK, SEQ, window and state of CT can be updated with both direction traffic.
In order to query the updated contents of this context, a WQE should be posted to the SQ with a return buffer. The data will be filled into the buffer. And the profile will be filled with specific value.
During the execution of query command, the context may be updated. The result of the query command may not be the latest one.
--- drivers/net/mlx5/mlx5.h | 10 +- drivers/net/mlx5/mlx5_flow_aso.c | 245 +++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 19 +++ 3 files changed, 273 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +9 -1
@@ -493,7 +493,10 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; -struct mlx5_aso_ct_action *ct; +struct { +struct mlx5_aso_ct_action *ct; +char *query_data; + }; }; };
@@ -1707,5 +1710,10 @@ int mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,const struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_wait_ready (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct); +int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow_aso.c +245 -0
263 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +19 -0
@@ -14809,6 +14809,8 @@ flow_dv_action_query(struct rte_eth_dev *dev,uint32_t act_idx = (uint32_t )(uintptr_t )handle;uint32_t type = act_idx >>MLX5_INDIRECT_ACTION_TYPE_OFFSET ;uint32_t idx = act_idx & ((1u <<MLX5_INDIRECT_ACTION_TYPE_OFFSET ) -1 ); +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct;switch (type) {case MLX5_INDIRECT_ACTION_TYPE_AGE :
@@ -14824,6 +14826,23 @@ flow_dv_action_query(struct rte_eth_dev *dev,return 0 ;case MLX5_INDIRECT_ACTION_TYPE_COUNT :return flow_dv_query_count (dev, idx, data, error); +case MLX5_INDIRECT_ACTION_TYPE_CT : + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,EFAULT , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + ((struct rte_flow_action_conntrack *)data)->peer_port = + ct->peer; + ((struct rte_flow_action_conntrack *)data)->is_original_dir = + ct->is_original; +if (mlx5_aso_ct_query_by_wqe (priv->sh, ct, data)) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to query CT context" ); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, NULL,
Signature · 1 line
2.27.0
PATCH v6 10/17 net/mlx5: add ASO CT destroy handling
In reply to Bing ZhaoWhen trying to destroy an ASO connection tracking context, the DR action created on this context should also be destroyed. Before inserting the related software object into the management free list, the reference count should be checked.
Right now, the context object will not be freed to the system and will be reused directly from the free list.
--- drivers/net/mlx5/mlx5_flow_dv.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +15 -1
@@ -11531,9 +11531,15 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +uint32_t ret;struct mlx5_aso_ct_action *ct =flow_aso_ct_get_by_idx (dev, idx); -uint32_t ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED); +enum mlx5_aso_ct_state state = +__atomic_load_n (&ct->state, __ATOMIC_RELAXED); +/* Cannot release when CT is in the ASO SQ. */ +if (state ==ASO_CONNTRACK_WAIT || state ==ASO_CONNTRACK_QUERY ) +return -1 ; + ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED);if (!ret) {if (ct->dr_action_orig) {#ifdef HAVE_MLX5_DR_ACTION_ASO_CT
@@ -11549,6 +11555,8 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx)#endif ct->dr_action_rply =NULL ; } +/* Clear the state to free, no need in 1st allocation. */ +MLX5_ASO_CT_UPDATE_STATE (ct,ASO_CONNTRACK_FREE );rte_spinlock_lock (&mng->ct_sl);LIST_INSERT_HEAD (&mng->free_cts, ct, next);rte_spinlock_unlock (&mng->ct_sl);
@@ -14079,6 +14087,12 @@ flow_dv_action_destroy(struct rte_eth_dev *dev,DRV_LOG (DEBUG ,"Indirect age action %" PRIu32" was" " released with references %d." , idx, ret);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ret =flow_dv_aso_ct_release (dev, idx); +if (ret) +DRV_LOG (DEBUG ,"Connection tracking object %u still " +"has references %d." , idx, ret); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v6 11/17 net/mlx5: add translation of CT action
In reply to Bing ZhaoWhen creating a flow with this action context for CT, it needs to be translated in 2 levels.
First, retrieve from action context to rte_flow action. Second, translate it to the corresponding DR action with traffic direction that was specified when creating or updating via rte_flow_action_handle* API.
Before using the DR action in a flow, the CT context should be available to use in the hardware. A synchronization is done before inserting the flow rule with CT action to check the HW availability of this CT context.
In order to release the DR actions and reuse the context of a CT, the reference count should also be handled in the flow rule destroying.
The CT index will be recorded in the rte_flow by reusing the ASO age index to save memory, since only one ASO action is supported in one flow rule currently. The action context type should also be saved for CT. When destroying a flow rule, if the context type is CT and the index is valid (non-zero), the release process should be handled. By default, the handling will fall back to try to release the ASO age if any.
--- drivers/net/mlx5/mlx5.h | 2 ++ drivers/net/mlx5/mlx5_flow.c | 9 +++++++ drivers/net/mlx5/mlx5_flow.h | 7 +++++- drivers/net/mlx5/mlx5_flow_aso.c | 41 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 28 +++++++++++++++++++++- 5 files changed, 85 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.h +2 -0
@@ -1715,5 +1715,7 @@ int mlx5_aso_ct_wait_ready(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_available (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.c +9 -0
@@ -3559,6 +3559,15 @@ flow_action_handles_translate(struct rte_eth_dev *dev,break ; }/* Fall-through */ +case MLX5_INDIRECT_ACTION_TYPE_CT : +if (priv->sh->ct_aso_en) { + translated[handle->index].type = +RTE_FLOW_ACTION_TYPE_CONNTRACK ; + translated[handle->index].conf = + (void *)(uintptr_t )idx; +break ; + } +/* Fall-through */ default :mlx5_free (translated);return rte_flow_error_set
drivers/net/mlx5/mlx5_flow.h +6 -1
@@ -230,6 +230,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)#define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40) +#define MLX5_FLOW_ACTION_CT (1ull << 41)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
@@ -973,11 +974,15 @@ struct rte_flow { uint32_t drv_type:2; /**< Driver type. */ uint32_t tunnel:1; uint32_t meter:24; /**< Holds flow meter id. */ + uint32_t indirect_type:2; /**< Indirect action type. */uint32_t rix_mreg_copy;/**< Index to metadata register copy table resource. */ uint32_t counter;/**< Holds flow counter. */ uint32_t tunnel_id;/**< Tunnel id */ -uint32_t age;/**< Holds ASO age bit index. */ +union { +uint32_t age;/**< Holds ASO age bit index. */ +uint32_t ct;/**< Holds ASO CT index. */ + };uint32_t geneve_tlv_option;/**< Holds Geneve TLV option id. > */ } __rte_packed;
drivers/net/mlx5/mlx5_flow_aso.c +41 -0
44 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +27 -1
@@ -11776,6 +11776,7 @@ flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,return rte_flow_error_set (error,EBUSY ,RTE_FLOW_ERROR_TYPE_ACTION ,NULL ,"Failed to update CT" ); + ct->is_original = !!pro->is_original_dir;return idx; }
@@ -11941,6 +11942,8 @@ flow_dv_translate(struct rte_eth_dev *dev,int action_type = actions->type;const struct rte_flow_action *found_action =NULL ;uint32_t jump_group =0 ; +uint32_t ct_idx; +struct mlx5_aso_ct_action *ct;if (!mlx5_flow_os_action_supported (action_type)) return rte_flow_error_set(error, ENOTSUP,
@@ -12394,6 +12397,26 @@ flow_dv_translate(struct rte_eth_dev *dev,return -rte_errno; action_flags |=MLX5_FLOW_ACTION_MODIFY_FIELD ;break ; +case RTE_FLOW_ACTION_TYPE_CONNTRACK : + ct_idx = (uint32_t )(uintptr_t )action->conf; + ct =flow_aso_ct_get_by_idx (dev, ct_idx); +if (mlx5_aso_ct_available (priv->sh, ct)) +return rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_ACTION , +NULL , +"CT is unavailable." ); +if (ct->is_original) + dev_flow->dv.actions[actions_n] = + ct->dr_action_orig; +else + dev_flow->dv.actions[actions_n] = + ct->dr_action_rply; + flow->indirect_type =MLX5_INDIRECT_ACTION_TYPE_CT ; + flow->ct = ct_idx; +__atomic_fetch_add (&ct->refcnt,1 , __ATOMIC_RELAXED); + actions_n++; + action_flags |=MLX5_FLOW_ACTION_CT ; +break ;case RTE_FLOW_ACTION_TYPE_END : actions_end = true;if (mhdr_res->actions_num) {
@@ -13564,7 +13587,10 @@ flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)mlx5_flow_meter_detach (priv, fm); flow->meter =0 ; } -if (flow->age) +/* Keep the current age handling by default. */ +if (flow->indirect_type ==MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct) +flow_dv_aso_ct_release (dev, flow->ct); +else if (flow->age)flow_dv_aso_age_release (dev, flow->age);if (flow->geneve_tlv_option) {flow_dv_geneve_tlv_option_resource_release (dev);
Signature · 1 line
2.27.0
PATCH v6 12/17 net/mlx5: add translation of CT item
In reply to Bing ZhaoThe return register of the DR action will be used for matching. After the ASO CT checking of a TCP packet, the syndrome is filled in the register. Only the 8 LSB should be used. A converting from RTE_FLOW_CONNTRACK_FLAG* to the syndrome should be done after checing the spec and mask fields.
--- drivers/net/mlx5/mlx5_flow.h | 7 ++++ drivers/net/mlx5/mlx5_flow_dv.c | 62 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
drivers/net/mlx5/mlx5_flow.h +7 -0
@@ -409,6 +409,13 @@ enum mlx5_feature_name {/* Maximum number of fields to modify in MODIFY_FIELD */ #define MLX5_ACT_MAX_MOD_FIELDS 5 +/* Syndrome bits definition for connection tracking. */ +#define MLX5_CT_SYNDROME_VALID (0x0 << 6) +#define MLX5_CT_SYNDROME_INVALID (0x1 << 6) +#define MLX5_CT_SYNDROME_TRAP (0x2 << 6) +#define MLX5_CT_SYNDROME_STATE_CHANGE (0x1 << 1) +#define MLX5_CT_SYNDROME_BAD_PACKET (0x1 << 0) +enum mlx5_flow_drv_type {MLX5_FLOW_TYPE_MIN ,MLX5_FLOW_TYPE_DV ,
drivers/net/mlx5/mlx5_flow_dv.c +62 -0
74 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v6 13/17 net/mlx5: add CT context update
In reply to Bing ZhaoWhen updating a connection tracking context, two separate parts could be updated.
First, the direction. This will only update the traffic direction recorded in the software for flow creation.
Second, the TCP parameters. The hardware context will be updated via the WQE. This update will be blocked until the hardware status is updated and ready for the next flow creation.
--- drivers/net/mlx5/mlx5_flow_dv.c | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
drivers/net/mlx5/mlx5_flow_dv.c +56 -0
@@ -14255,6 +14255,60 @@ __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,return ret; } +/* +* Updates in place conntrack context or direction. +* Context update should be synchronized. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* The conntrack object ID to be updated. +* @param[in] update +* Pointer to the structure of information to update. +* @param[out] error +* Perform verbose error reporting if not NULL. Initialized in case of +* error only. +* +* @return +* 0 on success, otherwise negative errno value. +*/ +static int +__flow_dv_action_ct_update (struct rte_eth_dev *dev,uint32_t idx, +const struct rte_flow_modify_conntrack *update, +struct rte_flow_error *error) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +const struct rte_flow_action_conntrack *new_prf; +int ret =0 ; + + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,ENOMEM , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + new_prf = &update->new_ct; +if (update->direction) + ct->is_original = !!new_prf->is_original_dir; +if (update->state) { + ret =mlx5_aso_ct_update_by_wqe (priv->sh, ct, new_prf); +if (ret) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to send CT context update WQE" ); +/* Block until ready or a failure. */ + ret =mlx5_aso_ct_available (priv->sh, ct); +if (ret) +rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Timeout to get the CT update" ); + } +return ret; +} +/** * Updates in place shared action configuration, lock free, * (mutex should be acquired by caller).
@@ -14290,6 +14344,8 @@ flow_dv_action_update(struct rte_eth_dev *dev,case MLX5_INDIRECT_ACTION_TYPE_RSS : action_conf = ((const struct rte_flow_action *)update)->conf;return __flow_dv_action_rss_update (dev, idx, action_conf, err); +case MLX5_INDIRECT_ACTION_TYPE_CT : +return __flow_dv_action_ct_update (dev, idx, update, err);default : return rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.27.0
PATCH v6 14/17 net/mlx5: validation of CT action
In reply to Bing ZhaoThe validation of a CT action contains two parts. The first is the CT action configurations parameter. When creating a CT action context, some members need to be verified.
The second is that when creating a flow, the DR action of CT should be validated with other actions and items as well. Currently, only the TCP protocol support connection tracking.
--- drivers/net/mlx5/mlx5.h | 4 ++ drivers/net/mlx5/mlx5_flow.c | 31 +++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 69 +++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+)
drivers/net/mlx5/mlx5.h +4 -0
@@ -1616,6 +1616,10 @@ int mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow,void mlx5_flow_rxq_dynf_metadata_set (struct rte_eth_dev *dev);int mlx5_flow_get_aged_flows (struct rte_eth_dev *dev,void **contexts,uint32_t nb_contexts,struct rte_flow_error *error); +int mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error); +/* mlx5_mp_os.c */
drivers/net/mlx5/mlx5_flow.c +31 -0
@@ -1688,6 +1688,37 @@ mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,return 0 ; } +/* +* Validate the ASO CT action. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] conntrack +* Pointer to the CT action profile. +* @param[out] error +* Pointer to error structure. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error) +{ +RTE_SET_USED (dev); + +if (conntrack->state >RTE_FLOW_CONNTRACK_STATE_TIME_WAIT ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid CT state" ); +if (conntrack->last_index >RTE_FLOW_CONNTRACK_FLAG_RST ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid last TCP packet flag" ); +return 0 ; +} +/** * Verify the @p attributes will be correctly understood by the NIC and store * them in the @p flow if everything is correct.
drivers/net/mlx5/mlx5_flow_dv.c +69 -0
93 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v6 15/17 net/mlx5: validation of CT item
In reply to Bing ZhaoThe item of ASO connection tracking will be translated into the register value when matching. The validation of this item has no dependency on other layers, since the flow including this item should be jumped from another group. All the layers checking was already done in the previous groups. Only the state bits conflict should be checked.
It is assumed that the flow with CT item will always work on the TCP traffic.
--- drivers/net/mlx5/mlx5_flow.h | 3 ++ drivers/net/mlx5/mlx5_flow_dv.c | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -151,6 +151,9 @@ enum mlx5_feature_name {/* INTEGRITY item bit */ #define MLX5_FLOW_ITEM_INTEGRITY (UINT64_C(1) << 34) +/* Conntrack item. */ +#define MLX5_FLOW_LAYER_ASO_CT (UINT64_C(1) << 35) +/* Outer Masks. */ #define MLX5_FLOW_LAYER_OUTER_L3 \ (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6)
drivers/net/mlx5/mlx5_flow_dv.c +51 -0
63 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v6 16/17 net/mlx5: add support of CT between two ports
In reply to Bing ZhaoAfter creating a connection tracking context, it can be used between two ports. For each port, the flow for one direction traffic will be created.
The context can only be shared between the owner port and the peer port that was specified when being created. Only the owner port could update the context or query it in current implementation.
--- drivers/net/mlx5/mlx5_flow.h | 57 +++++++++++++++++++++++++- drivers/net/mlx5/mlx5_flow_dv.c | 71 +++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 18 deletions(-)
drivers/net/mlx5/mlx5_flow.h +55 -2
@@ -49,6 +49,25 @@ enum { MLX5_INDIRECT_ACTION_TYPE_CT, }; +/* Now, the maximal ports will be supported is 256, action number is 4M. */ +#define MLX5_INDIRECT_ACT_CT_MAX_PORT 0x100 + +#define MLX5_INDIRECT_ACT_CT_OWNER_SHIFT 22 +#define MLX5_INDIRECT_ACT_CT_OWNER_MASK (MLX5_INDIRECT_ACT_CT_MAX_PORT - 1) + +/* 30-31: type, 22-29: owner port, 0-21: index. */ +#define MLX5_INDIRECT_ACT_CT_GEN_IDX (owner, index) \ + ((MLX5_INDIRECT_ACTION_TYPE_CT << MLX5_INDIRECT_ACTION_TYPE_OFFSET) | \ + (((owner) & MLX5_INDIRECT_ACT_CT_OWNER_MASK) << \ + MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) | (index)) + +#define MLX5_INDIRECT_ACT_CT_GET_OWNER (index) \ + (((index) >> MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) & \ + MLX5_INDIRECT_ACT_CT_OWNER_MASK) + +#define MLX5_INDIRECT_ACT_CT_GET_IDX (index) \ + ((index) & ((1 << MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) - 1)) +/* Matches on selected register. */ struct mlx5_rte_flow_item_tag {enum modify_reg id;
@@ -1334,7 +1353,7 @@ mlx5_validate_integrity_item(const struct rte_flow_item_integrity *item) }/* -* Get ASO CT action by index. +* Get ASO CT action by device and index. * * @param[in] dev * Pointer to the Ethernet device structure.
@@ -1345,7 +1364,7 @@ mlx5_validate_integrity_item(const struct rte_flow_item_integrity *item)* The specified ASO CT action pointer. */ static inline struct mlx5_aso_ct_action * -flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +flow_aso_ct_get_by_dev_idx (struct rte_eth_dev *dev,uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
@@ -1360,6 +1379,40 @@ flow_aso_ct_get_by_idx(struct rte_eth_dev *dev, uint32_t idx)return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; } +/* +* Get ASO CT action by owner & index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action and owner port combination. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t own_idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +uint16_t owner = (uint16_t )MLX5_INDIRECT_ACT_CT_GET_OWNER (own_idx); +uint32_t idx =MLX5_INDIRECT_ACT_CT_GET_IDX (own_idx); + +if (owner ==PORT_ID (priv)) { + ct =flow_aso_ct_get_by_dev_idx (dev, idx); + }else { +struct rte_eth_dev *owndev = &rte_eth_devices[owner]; + +MLX5_ASSERT (owner <RTE_MAX_ETHPORTS ); +if (dev->data->dev_started !=1 ) +return NULL ; + ct =flow_aso_ct_get_by_dev_idx (owndev, idx); +if (ct->peer !=PORT_ID (priv)) +return NULL ; + } +return ct; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +55 -16
165 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v6 17/17 doc: update mlx5 support for conntrack
In reply to Bing ZhaoIn the release notes and mlx5 NIC document, the support and limitation of connection tracking are added.
--- doc/guides/nics/features/default.ini | 1 + doc/guides/nics/features/mlx5.ini | 1 + doc/guides/nics/mlx5.rst | 14 ++++++++++++++ doc/guides/rel_notes/release_21_05.rst | 2 ++ 4 files changed, 18 insertions(+)
doc/guides/nics/features/default.ini +1 -0
@@ -66,6 +66,7 @@ Module EEPROM dump = Registers dump = LED = Multiprocess aware = +Connection tracking = FreeBSD = Linux = Windows =
doc/guides/nics/features/mlx5.ini +1 -0
@@ -45,6 +45,7 @@ Stats per queue = Y FW version = Y Module EEPROM dump = Y Multiprocess aware = Y +Connection tracking = Y Linux = Y Windows = P ARMv8 = Y
doc/guides/nics/mlx5.rst +14 -0
@@ -108,6 +108,7 @@ Features flow group. - Flow metering, including meter policy API. - Flow integrity offload API. +- Connection tracking. Limitations -----------
@@ -433,6 +434,14 @@ Limitations or flow create 0 ingress pattern integrity level is 0 value mask l4_ok value spec 0 / eth / ipv4 proto is udp / end … +- Connection tracking: + + - connection tracking (conntrack) couldn't co-exist with ASO meter, ASO age action in a single flow rule. + - Flow rules insertion rate and memory consumption. + - software limitation: + - ports: a maximal number of 256. + - conntrack: a maximal number of 4M. + Statistics ----------
@@ -1695,6 +1704,11 @@ Supported hardware offloads | | | rdma-core 35 | | rdma-core 35 | | | | ConnectX-5 | | ConnectX-5 | +-----------------------+-----------------+-----------------+ + | Connection tracking | | | | DPDK 21.05 | + | | | N/A | | OFED 5.3 | + | | | | | rdma-core 35 | + | | | | | ConnectX-6 Dx | + +-----------------------+-----------------+-----------------+ .. table:: Minimal SW/HW versions for shared action offload :name: sact
doc/guides/rel_notes/release_21_05.rst +2 -0
@@ -167,6 +167,8 @@ New Features * Added support for ASO (Advanced Steering Operation) meter. * Added support for ASO metering by PPS (packet per second). * Added support for the monitor policy of Power Management API. + * Added support for connection tracking action and item as well as context create, + destroy, update and query. * **Updated NXP DPAA driver.**
Signature · 1 line
2.27.0
v7 cover conntrack support in mlx5 PMD
In reply to Bing ZhaoThis patch set adds the connection tracking offload support in the mlx5 driver, as well as the documents update.
---
v2: code bug fixes, commits clean up and doc update
v3: fix error input pointer for CT MR registering
v4: fix typo in commit message of patch 11
v5: adjust mkey to lkey in SQ initialization
v6: rebase and solve the conflict
v7: fix compiling for the commits series
---
Bing Zhao (17):
common/mlx5: add connection tracking object definition common/mlx5: add CT offload capability checking net/mlx5: use meter color reg for CT net/mlx5: initialization of CT management common/mlx5: add Dexv CT objects creation net/mlx5: add modify support for CT
net/mlx5: add actions creating for CT net/mlx5: close CT management structure net/mlx5: add ASO CT query implementation net/mlx5: add ASO CT destroy handling net/mlx5: add translation of CT action net/mlx5: add translation of CT item net/mlx5: add CT context update
net/mlx5: validation of CT action
net/mlx5: validation of CT item
net/mlx5: add support of CT between two ports
doc: update mlx5 support for conntrack
doc/guides/nics/features/default.ini | 1 + doc/guides/nics/features/mlx5.ini | 1 + doc/guides/nics/mlx5.rst | 14 + doc/guides/rel_notes/release_21_05.rst | 2 + drivers/common/mlx5/linux/meson.build | 2 + drivers/common/mlx5/mlx5_devx_cmds.c | 53 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 5 + drivers/common/mlx5/mlx5_prm.h | 88 ++++ drivers/common/mlx5/version.map | 1 + drivers/net/mlx5/linux/mlx5_os.c | 13 + drivers/net/mlx5/mlx5.c | 92 ++++ drivers/net/mlx5/mlx5.h | 76 ++++ drivers/net/mlx5/mlx5_flow.c | 44 +- drivers/net/mlx5/mlx5_flow.h | 101 ++++- drivers/net/mlx5/mlx5_flow_aso.c | 592 ++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 601 ++++++++++++++++++++++++- 16 files changed, 1683 insertions(+), 3 deletions(-)
Signature · 1 line
2.26.2
PATCH v7 1/17 common/mlx5: add connection tracking object definition
The structures of ASO connection tracking offload object are added based on the definitions in the PRM. One CT object context will be loaded into the cache completely in a reversed order of dwords. The valid bit should be the MSB of the last dword. This is used for the conntrack context creation and update, as well as for the query.
The capabilities 2 (HCA_CAP_2) layout is also added. The connection tracking related capabilities could be queried via the HCA_CAP_2.
--- drivers/common/mlx5/mlx5_prm.h | 85 ++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
drivers/common/mlx5/mlx5_prm.h +85 -0
@@ -1124,6 +1124,7 @@ enum {MLX5_GET_HCA_CAP_OP_MOD_ROCE =0x4 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE =0x7 <<1 ,MLX5_GET_HCA_CAP_OP_MOD_VDPA_EMULATION =0x13 <<1 , + MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE_2 = 0x20 << 1, };#define MLX5_GENERAL_OBJ_TYPES_CAP_VIRTQ_NET_Q \
@@ -1692,6 +1693,29 @@ struct mlx5_ifc_flow_table_nic_cap_bits { ft_field_support_2_nic_receive; }; +struct mlx5_ifc_cmd_hca_cap_2_bits { +u8 reserved_at_0[0x80 ];/* End of DW4. */ +u8 reserved_at_80[0xb ]; +u8 log_max_num_reserved_qpn[0x5 ]; +u8 reserved_at_90[0x3 ]; +u8 log_reserved_qpn_granularity[0x5 ]; +u8 reserved_at_98[0x3 ]; +u8 log_reserved_qpn_max_alloc[0x5 ];/* End of DW5. */ +u8 max_reformat_insert_size[0x8 ]; +u8 max_reformat_insert_offset[0x8 ]; +u8 max_reformat_remove_size[0x8 ]; +u8 max_reformat_remove_offset[0x8 ];/* End of DW6. */ +u8 aso_conntrack_reg_id[0x8 ]; +u8 reserved_at_c8[0x3 ]; +u8 log_conn_track_granularity[0x5 ]; +u8 reserved_at_d0[0x3 ]; +u8 log_conn_track_max_alloc[0x5 ]; +u8 reserved_at_d8[0x3 ]; +u8 log_max_conn_track_offload[0x5 ]; +u8 reserved_at_e0[0x20 ];/* End of DW7. */ +u8 reserved_at_100[0x700 ]; +}; +union mlx5_ifc_hca_cap_union_bits {struct mlx5_ifc_cmd_hca_cap_bits cmd_hca_cap;struct mlx5_ifc_per_protocol_networking_offload_caps_bits
@@ -2630,6 +2654,67 @@ struct mlx5_ifc_create_flow_meter_aso_in_bits {struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr;struct mlx5_ifc_flow_meter_aso_bits flow_meter_aso; }; + +struct mlx5_ifc_tcp_window_params_bits { +u8 max_ack[0x20 ]; +u8 max_win[0x20 ]; +u8 reply_end[0x20 ]; +u8 sent_end[0x20 ]; +}; + +struct mlx5_ifc_conn_track_aso_bits { +struct mlx5_ifc_tcp_window_params_bits reply_dir;/* End of DW3. */ +struct mlx5_ifc_tcp_window_params_bits original_dir;/* End of DW7. */ +u8 last_end[0x20 ];/* End of DW8. */ +u8 last_ack[0x20 ];/* End of DW9. */ +u8 last_seq[0x20 ];/* End of DW10. */ +u8 last_win[0x10 ]; +u8 reserved_at_170[0xa ]; +u8 last_dir[0x1 ]; +u8 last_index[0x5 ];/* End of DW11. */ +u8 reserved_at_180[0x40 ];/* End of DW13. */ +u8 reply_direction_tcp_scale[0x4 ]; +u8 reply_direction_tcp_close_initiated[0x1 ]; +u8 reply_direction_tcp_liberal_enabled[0x1 ]; +u8 reply_direction_tcp_data_unacked[0x1 ]; +u8 reply_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1c8[0x8 ]; +u8 original_direction_tcp_scale[0x4 ]; +u8 original_direction_tcp_close_initiated[0x1 ]; +u8 original_direction_tcp_liberal_enabled[0x1 ]; +u8 original_direction_tcp_data_unacked[0x1 ]; +u8 original_direction_tcp_max_ack[0x1 ]; +u8 reserved_at_1d8[0x8 ];/* End of DW14. */ +u8 valid[0x1 ]; +u8 state[0x3 ]; +u8 freeze_track[0x1 ]; +u8 reserved_at_1e5[0xb ]; +u8 reserved_at_1f0[0x1 ]; +u8 connection_assured[0x1 ]; +u8 sack_permitted[0x1 ]; +u8 challenged_acked[0x1 ]; +u8 heartbeat[0x1 ]; +u8 max_ack_window[0x3 ]; +u8 reserved_at_1f8[0x1 ]; +u8 retransmission_counter[0x3 ]; +u8 retranmission_limit_exceeded[0x1 ]; +u8 retranmission_limit[0x3 ];/* End of DW15. */ +}; + +struct mlx5_ifc_conn_track_offload_bits { +u8 modify_field_select[0x40 ]; +u8 reserved_at_40[0x40 ]; +u8 reserved_at_80[0x8 ]; +u8 conn_track_aso_access_pd[0x18 ]; +u8 reserved_at_a0[0x160 ]; +struct mlx5_ifc_conn_track_aso_bits conn_track_aso; +}; + +struct mlx5_ifc_create_conn_track_aso_in_bits { +struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr; +struct mlx5_ifc_conn_track_offload_bits conn_track_offload; +}; +enum mlx5_access_aso_opc_mod {ASO_OPC_MOD_IPSEC =0x0 ,ASO_OPC_MOD_CONNECTION_TRACKING =0x1 ,
Signature · 1 line
2.26.2
PATCH v7 2/17 common/mlx5: add CT offload capability checking
In reply to Bing ZhaoDuring startup, the ASO connection tracking offload capability could be queried via HCA_CAP_QUERY command. If the HW doesn't support ASO CT, the value would be 0 by default. The following initialization should be skipped and the creation of the CT object should return a failure directly.
The following CT creation should also check this capability. With the old driver, the pre-processing macro should be used in order to make the compiling pass.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/mlx5_devx_cmds.c | 3 +++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 3 +++ 4 files changed, 9 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -189,6 +189,8 @@ has_sym_args = [ 'MLX5_WQE_UMR_CTRL_FLAG_INLINE' ], [ 'HAVE_MLX5_DR_FLOW_DUMP_RULE', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_rule' ], + [ 'HAVE_MLX5_DR_ACTION_ASO_CT', 'infiniband/mlx5dv.h', + 'MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR' ], ] config = configuration_data() foreach arg:has_sym_args
drivers/common/mlx5/mlx5_devx_cmds.c +3 -0
@@ -783,6 +783,9 @@ mlx5_devx_cmd_query_hca_attr(void *ctx,MLX5_GET (cmd_hca_cap, hcattr, umr_indirect_mkey_disabled); attr->umr_modify_entity_size_disabled =MLX5_GET (cmd_hca_cap, hcattr, umr_modify_entity_size_disabled); + attr->ct_offload = !!(MLX5_GET64 (cmd_hca_cap, hcattr, + general_obj_types) & +MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD );if (attr->qos.sup) { MLX5_SET(query_hca_cap_in, in, op_mod, MLX5_GET_HCA_CAP_OP_MOD_QOS_CAP |
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -137,6 +137,7 @@ struct mlx5_hca_attr { uint32_t qp_ts_format:2; uint32_t regex:1; uint32_t reg_c_preserve:1; + uint32_t ct_offload:1; /* General obj type ASO CT offload supported. */uint32_t regexp_num_of_engines; uint32_t log_max_ft_sampler_num:8;uint32_t geneve_tlv_opt;
drivers/common/mlx5/mlx5_prm.h +3 -0
@@ -1139,6 +1139,8 @@ enum { (1ULL << MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO)#define MLX5_GENERAL_OBJ_TYPES_CAP_GENEVE_TLV_OPT \ (1ULL << MLX5_OBJ_TYPE_GENEVE_TLV_OPT) +#define MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD \ + (1ULL << MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD)enum {MLX5_HCA_CAP_OPMOD_GET_MAX =0 ,
@@ -2487,6 +2489,7 @@ enum {MLX5_GENERAL_OBJ_TYPE_FLEX_PARSE_GRAPH =0x0022 ,MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO =0x0024 ,MLX5_GENERAL_OBJ_TYPE_FLOW_HIT_ASO =0x0025 , + MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD = 0x0031, }; struct mlx5_ifc_general_obj_in_cmd_hdr_bits {
Signature · 1 line
2.26.2
PATCH v7 3/17 net/mlx5: use meter color reg for CT
In reply to Bing ZhaoBased on the capacity, 3 registers could be used. Due to the register allocation, only the one REG_C_3 for meter color could be reused right now.
Then in the same flow, no more than one ASO action can be supported.
--- drivers/net/mlx5/mlx5_flow.c | 4 +++- drivers/net/mlx5/mlx5_flow.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow.c +3 -1
@@ -760,7 +760,9 @@ mlx5_flow_get_reg_id(struct rte_eth_dev *dev,return priv->mtr_color_reg !=REG_C_2 ?REG_C_2 :REG_C_3 ;case MLX5_MTR_COLOR : -case MLX5_ASO_FLOW_HIT :/* Both features use the same REG_C. */ +case MLX5_ASO_FLOW_HIT : +case MLX5_ASO_CONNTRACK : +/* All features use the same REG_C. */ MLX5_ASSERT (priv->mtr_color_reg !=REG_NON );return priv->mtr_color_reg;case MLX5_COPY_MARK :
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -85,6 +85,7 @@ enum mlx5_feature_name {MLX5_MTR_COLOR ,MLX5_MTR_ID ,MLX5_ASO_FLOW_HIT , + MLX5_ASO_CONNTRACK, };/* Default queue number. */
Signature · 1 line
2.26.2
PATCH v7 4/17 net/mlx5: initialization of CT management
In reply to Bing ZhaoThe definitions of ASO connection tracking objects management structures are added.
Considering performance, the bulk allocation of ASO CT objects should be used. The maximal value per bulk and the granularity could be fetched from HCA capabilities 2. Right now, a fixed number of 64 is used for each bulk for a better management purpose.
The ASO QP for CT is initialized, the SQ will be used for both modify and query command.
--- drivers/net/mlx5/linux/mlx5_os.c | 13 +++++++++ drivers/net/mlx5/mlx5.c | 36 +++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 50 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 50 ++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +13 -0
@@ -1323,6 +1323,19 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,DRV_LOG (DEBUG ,"Flow Hit ASO is supported." ); }#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */ +#if defined(HAVE_MLX5_DR_CREATE_ACTION_ASO ) && \ + defined(HAVE_MLX5_DR_ACTION_ASO_CT ) +if (config->hca_attr.ct_offload && + priv->mtr_color_reg ==REG_C_3 ) { + err =mlx5_flow_aso_ct_mng_init (sh); +if (err) { + err = -err; + goto error; + } +DRV_LOG (DEBUG ,"CT ASO is supported." ); + sh->ct_aso_en =1 ; + } +#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO && HAVE_MLX5_DR_ACTION_ASO_CT */ #if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE )if (config->hca_attr.log_max_ft_sampler_num >0 && config->dv_flow_en) {
drivers/net/mlx5/mlx5.c +36 -0
@@ -672,6 +672,42 @@ mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh) } } +/* +* Initialize the ASO connection tracking structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_flow_aso_ct_mng_init (struct mlx5_dev_ctx_shared *sh) +{ +int err; + +if (sh->ct_mng) +return 0 ; + sh->ct_mng =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*sh->ct_mng), +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +if (!sh->ct_mng) { +DRV_LOG (ERR ,"ASO CT management allocation failed." ); + rte_errno =ENOMEM ; +return -rte_errno; + } + err =mlx5_aso_queue_init (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); +if (err) { +mlx5_free (sh->ct_mng); +/* rte_errno should be extracted from the failure. */ + rte_errno =EINVAL ; +return -rte_errno; + } +rte_spinlock_init (&sh->ct_mng->ct_sl); +rte_rwlock_init (&sh->ct_mng->resize_rwl); +LIST_INIT (&sh->ct_mng->free_cts); +return 0 ; +} +/** * Initialize the flow resources' indexed mempool. *
drivers/net/mlx5/mlx5.h +50 -0
74 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_aso.c +50 -0
62 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v7 5/17 common/mlx5: add Dexv CT objects creation
In reply to Bing ZhaoAdding support for connection tracking ASO creation via Devx command. Right now only bulk creation is supported.
By default, the objects with zero contents will be created. Before using a single object, the modification via posting a WQE to the ASO CT SQ is needed.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 50 ++++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 4 +++ drivers/common/mlx5/version.map | 1 + 3 files changed, 55 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +50 -0
@@ -2255,6 +2255,56 @@ mlx5_devx_cmd_create_flow_meter_aso_obj(void *ctx, uint32_t pd,return flow_meter_aso_obj; } +/* +* Create general object of type CONN_TRACK_OFFLOAD using DevX API. +* +* @param[in] ctx +* Context returned from mlx5 open_device() glue function. +* @param [in] pd +* PD value to associate the CONN_TRACK_OFFLOAD ASO object with. +* @param [in] log_obj_size +* log_obj_size to allocate its power of 2 * objects +* in one CONN_TRACK_OFFLOAD bulk allocation. +* +* @return +* The DevX object created, NULL otherwise and rte_errno is set. +*/ +struct mlx5_devx_obj * +mlx5_devx_cmd_create_conn_track_offload_obj (void *ctx,uint32_t pd, +uint32_t log_obj_size) +{ +uint32_t in[MLX5_ST_SZ_DW (create_conn_track_aso_in)] = {0 }; +uint32_t out[MLX5_ST_SZ_DW (general_obj_out_cmd_hdr)]; +struct mlx5_devx_obj *ct_aso_obj; +void *ptr; + + ct_aso_obj =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*ct_aso_obj), +0 ,SOCKET_ID_ANY ); +if (!ct_aso_obj) { +DRV_LOG (ERR ,"Failed to allocate CONN_TRACK_OFFLOAD object." ); + rte_errno =ENOMEM ; +return NULL ; + } + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, hdr); +MLX5_SET (general_obj_in_cmd_hdr, ptr, opcode, +MLX5_CMD_OP_CREATE_GENERAL_OBJECT ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, obj_type, +MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD ); +MLX5_SET (general_obj_in_cmd_hdr, ptr, log_obj_range, log_obj_size); + ptr =MLX5_ADDR_OF (create_conn_track_aso_in, in, conn_track_offload); +MLX5_SET (conn_track_offload, ptr, conn_track_aso_access_pd, pd); + ct_aso_obj->obj = mlx5_glue->devx_obj_create (ctx, in,sizeof (in), + out,sizeof (out)); +if (!ct_aso_obj->obj) { + rte_errno = errno; +DRV_LOG (ERR ,"Failed to create CONN_TRACK_OFFLOAD obj by using DevX." ); +mlx5_free (ct_aso_obj); +return NULL ; + } + ct_aso_obj->id =MLX5_GET (general_obj_out_cmd_hdr, out, obj_id); +return ct_aso_obj; +} +/** * Create general object of type GENEVE TLV option using DevX API. *
drivers/common/mlx5/mlx5_devx_cmds.h +4 -0
@@ -570,6 +570,10 @@ struct mlx5_devx_obj *mlx5_devx_cmd_queue_counter_alloc(void *ctx);__rte_internal int mlx5_devx_cmd_queue_counter_query(struct mlx5_devx_obj *dcs, int clear,uint32_t *out_of_buffers); +__rte_internal +struct mlx5_devx_obj *mlx5_devx_cmd_create_conn_track_offload_obj(void *ctx, +uint32_t pd,uint32_t log_obj_size); +/** * Create general object of type FLOW_METER_ASO using DevX API.. *
drivers/common/mlx5/version.map +1 -0
@@ -13,6 +13,7 @@ INTERNAL { mlx5_dev_to_pci_addr; # WINDOWS_NO_EXPORT mlx5_devx_cmd_alloc_pd; + mlx5_devx_cmd_create_conn_track_offload_obj; mlx5_devx_cmd_create_cq; mlx5_devx_cmd_create_flex_parser; mlx5_devx_cmd_create_qp;
Signature · 1 line
2.26.2
PATCH v7 6/17 net/mlx5: add modify support for CT
In reply to Bing ZhaoAfter the connection tracking object bulk is allocated, all the objects' contents are filled with zero by default. Every new-allocated object must be modified via WQE operation before it is used.
In order to reduce the latency for the flow creation, an asynchronous way is used instead of busy waiting for the CQE to be generated.
--- drivers/net/mlx5/mlx5.h | 8 + drivers/net/mlx5/mlx5_flow.h | 2 + drivers/net/mlx5/mlx5_flow_aso.c | 252 +++++++++++++++++++++++++++++++ 3 files changed, 262 insertions(+)
drivers/net/mlx5/mlx5.h +8 -0
@@ -493,6 +493,7 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; +struct mlx5_aso_ct_action *ct; }; };
@@ -1012,6 +1013,10 @@ struct mlx5_aso_ct_action {bool is_original;/* The direction of the DR action to be used. */ }; +/* CT action object state update. */ +#define MLX5_ASO_CT_UPDATE_STATE (c, s) \ + __atomic_store_n(&((c)->state), (s), __ATOMIC_RELAXED) +/* ASO connection tracking software pool definition. */ struct mlx5_aso_ct_pool {uint16_t index;/* Pool index in pools array. */
@@ -1695,5 +1700,8 @@ int mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh, struct mlx5_aso_mtr *mtr);int mlx5_aso_mtr_wait (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_mtr *mtr); +int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +const struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.h +2 -0
@@ -843,6 +843,8 @@ struct mlx5_flow {#define MLX5_ASO_WQE_CQE_RESPONSE_DELAY 10u#define MLX5_MTR_POLL_WQE_CQE_TIMES 100000u +#define MLX5_CT_POLL_WQE_CQE_TIMES MLX5_MTR_POLL_WQE_CQE_TIMES +#define MLX5_MAN_WIDTH 8/* Legacy Meter parameter structure. */ struct mlx5_legacy_flow_meter {
drivers/net/mlx5/mlx5_flow_aso.c +252 -0
255 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v7 7/17 net/mlx5: add actions creating for CT
In reply to Bing ZhaoAllocating a CT from the management pools and creating the DR actions for both directions by default.
If there is no available connection tracking action, a new pool will be created with a fixed size bulk allocation. Right now, all the resources are controlled by the linked list.
The ASO connection tracking context associated with these actions need to be updated via WQE before using for steering.
--- drivers/net/mlx5/mlx5.h | 4 + drivers/net/mlx5/mlx5_flow.h | 28 ++++ drivers/net/mlx5/mlx5_flow_dv.c | 262 ++++++++++++++++++++++++++++++++ 3 files changed, 294 insertions(+)
drivers/net/mlx5/mlx5.h +4 -0
@@ -992,6 +992,10 @@ struct mlx5_bond_info {/* Number of connection tracking objects per pool: must be a power of 2. */ #define MLX5_ASO_CT_ACTIONS_PER_POOL 64 +/* Generate incremental and unique CT index from pool and offset. */ +#define MLX5_MAKE_CT_IDX (pool, offset) \ + ((pool) * MLX5_ASO_CT_ACTIONS_PER_POOL + (offset) + 1) +/* ASO Conntrack state. */ enum mlx5_aso_ct_state {ASO_CONNTRACK_FREE ,/* Inactive, in the free list. */
drivers/net/mlx5/mlx5_flow.h +28 -0
@@ -46,6 +46,7 @@ enum {MLX5_INDIRECT_ACTION_TYPE_RSS ,MLX5_INDIRECT_ACTION_TYPE_AGE ,MLX5_INDIRECT_ACTION_TYPE_COUNT , + MLX5_INDIRECT_ACTION_TYPE_CT, };/* Matches on selected register. */
@@ -1317,6 +1318,33 @@ mlx5_validate_integrity_item(const struct rte_flow_item_integrity *item)return (test.value ==0 ); } +/* +* Get ASO CT action by index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +struct mlx5_aso_ct_pool *pool; + + idx--; +MLX5_ASSERT ((idx /MLX5_ASO_CT_ACTIONS_PER_POOL ) < mng->n); +/* Bit operation AND could be used. */ +rte_rwlock_read_lock (&mng->resize_rwl); + pool = mng->pools[idx /MLX5_ASO_CT_ACTIONS_PER_POOL ]; +rte_rwlock_read_unlock (&mng->resize_rwl); +return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +262 -0
274 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v7 8/17 net/mlx5: close CT management structure
In reply to Bing ZhaoWhen freeing the IB shared context during stopping a device, the ASO connection tracking management structure should also be cleaned up.
All the DR actions created should be destroyed. The structures need to be freed and ASO CT QP should be released. In the meanwhile, the allocated and registered memory region for query should also be deregistered and then freed.
--- drivers/net/mlx5/mlx5.c | 56 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 4 +++ 2 files changed, 60 insertions(+)
drivers/net/mlx5/mlx5.c +56 -0
@@ -708,6 +708,60 @@ mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh)return 0 ; } +/* +* Close and release all the resources of the +* ASO connection tracking management structure. +* +* @param[in] sh +* Pointer to mlx5_dev_ctx_shared object to free. +*/ +static void +mlx5_flow_aso_ct_mng_close (struct mlx5_dev_ctx_shared *sh) +{ +struct mlx5_aso_ct_pools_mng *mng = sh->ct_mng; +struct mlx5_aso_ct_pool *ct_pool; +struct mlx5_aso_ct_action *ct; +uint32_t idx; +uint32_t val; +uint32_t cnt; +int i; + +mlx5_aso_queue_uninit (sh,ASO_OPC_MOD_CONNECTION_TRACKING ); + idx = mng->next; +while (idx--) { + cnt =0 ; + ct_pool = mng->pools[idx]; +for (i =0 ; i <MLX5_ASO_CT_ACTIONS_PER_POOL ; i++) { + ct = &ct_pool->actions[i]; + val =__atomic_fetch_sub (&ct->refcnt,1 , + __ATOMIC_RELAXED); +MLX5_ASSERT (val ==1 ); +if (val >1 ) + cnt++; +#ifdef HAVE_MLX5_DR_ACTION_ASO_CT +if (ct->dr_action_orig) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_orig)); +if (ct->dr_action_rply) +claim_zero (mlx5_glue->destroy_flow_action + (ct->dr_action_rply)); +#endif + } +claim_zero (mlx5_devx_cmd_destroy (ct_pool->devx_obj)); +if (cnt) { +DRV_LOG (DEBUG ,"%u ASO CT objects are being used in the pool %u" , + cnt, i); + } +mlx5_free (ct_pool); +/* in case of failure. */ + mng->next--; + } +mlx5_free (mng->pools); +mlx5_free (mng); +/* Management structure must be cleared to 0s during allocation. */ + sh->ct_mng =NULL ; +} +/** * Initialize the flow resources' indexed mempool. *
@@ -1510,6 +1564,8 @@ mlx5_dev_close(struct rte_eth_dev *dev)if (priv->mreg_cp_tbl)mlx5_hlist_destroy (priv->mreg_cp_tbl);mlx5_mprq_free_mp (dev); +if (priv->sh->ct_mng) +mlx5_flow_aso_ct_mng_close (priv->sh);mlx5_os_free_shared_dr (priv);if (priv->rss_conf.rss_key !=NULL )mlx5_free (priv->rss_conf.rss_key);
drivers/net/mlx5/mlx5_flow_aso.c +4 -0
@@ -372,6 +372,10 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,case ASO_OPC_MOD_POLICER : sq = &sh->mtrmng->pools_mng.sq;break ; +case ASO_OPC_MOD_CONNECTION_TRACKING : +mlx5_aso_dereg_mr (sh, &sh->ct_mng->aso_sq.mr); + sq = &sh->ct_mng->aso_sq; +break ;default :DRV_LOG (ERR ,"Unknown ASO operation mode" );return ;
Signature · 1 line
2.26.2
PATCH v7 9/17 net/mlx5: add ASO CT query implementation
In reply to Bing ZhaoAfter the connection tracking context is created and being used by the flows, the context will be updated by the HW automatically after a packet passed the CT validation. E.g., the ACK, SEQ, window and state of CT can be updated with both direction traffic.
In order to query the updated contents of this context, a WQE should be posted to the SQ with a return buffer. The data will be filled into the buffer. And the profile will be filled with specific value.
During the execution of query command, the context may be updated. The result of the query command may not be the latest one.
--- drivers/net/mlx5/mlx5.h | 10 +- drivers/net/mlx5/mlx5_flow_aso.c | 245 +++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 19 +++ 3 files changed, 273 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5.h +9 -1
@@ -493,7 +493,10 @@ struct mlx5_aso_sq_elem {uint16_t burst_size; };struct mlx5_aso_mtr *mtr; -struct mlx5_aso_ct_action *ct; +struct { +struct mlx5_aso_ct_action *ct; +char *query_data; + }; }; };
@@ -1707,5 +1710,10 @@ int mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_update_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,const struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_wait_ready (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct); +int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct, +struct rte_flow_action_conntrack *profile);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow_aso.c +245 -0
263 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +19 -0
@@ -14808,6 +14808,8 @@ flow_dv_action_query(struct rte_eth_dev *dev,uint32_t act_idx = (uint32_t )(uintptr_t )handle;uint32_t type = act_idx >>MLX5_INDIRECT_ACTION_TYPE_OFFSET ;uint32_t idx = act_idx & ((1u <<MLX5_INDIRECT_ACTION_TYPE_OFFSET ) -1 ); +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct;switch (type) {case MLX5_INDIRECT_ACTION_TYPE_AGE :
@@ -14823,6 +14825,23 @@ flow_dv_action_query(struct rte_eth_dev *dev,return 0 ;case MLX5_INDIRECT_ACTION_TYPE_COUNT :return flow_dv_query_count (dev, idx, data, error); +case MLX5_INDIRECT_ACTION_TYPE_CT : + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,EFAULT , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + ((struct rte_flow_action_conntrack *)data)->peer_port = + ct->peer; + ((struct rte_flow_action_conntrack *)data)->is_original_dir = + ct->is_original; +if (mlx5_aso_ct_query_by_wqe (priv->sh, ct, data)) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to query CT context" ); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, NULL,
Signature · 1 line
2.26.2
PATCH v7 10/17 net/mlx5: add ASO CT destroy handling
In reply to Bing ZhaoWhen trying to destroy an ASO connection tracking context, the DR action created on this context should also be destroyed. Before inserting the related software object into the management free list, the reference count should be checked.
Right now, the context object will not be freed to the system and will be reused directly from the free list.
--- drivers/net/mlx5/mlx5_flow_dv.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +15 -1
@@ -11531,9 +11531,15 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; +uint32_t ret;struct mlx5_aso_ct_action *ct =flow_aso_ct_get_by_idx (dev, idx); -uint32_t ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED); +enum mlx5_aso_ct_state state = +__atomic_load_n (&ct->state, __ATOMIC_RELAXED); +/* Cannot release when CT is in the ASO SQ. */ +if (state ==ASO_CONNTRACK_WAIT || state ==ASO_CONNTRACK_QUERY ) +return -1 ; + ret =__atomic_sub_fetch (&ct->refcnt,1 , __ATOMIC_RELAXED);if (!ret) {if (ct->dr_action_orig) {#ifdef HAVE_MLX5_DR_ACTION_ASO_CT
@@ -11549,6 +11555,8 @@ flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx)#endif ct->dr_action_rply =NULL ; } +/* Clear the state to free, no need in 1st allocation. */ +MLX5_ASO_CT_UPDATE_STATE (ct,ASO_CONNTRACK_FREE );rte_spinlock_lock (&mng->ct_sl);LIST_INSERT_HEAD (&mng->free_cts, ct, next);rte_spinlock_unlock (&mng->ct_sl);
@@ -14078,6 +14086,12 @@ flow_dv_action_destroy(struct rte_eth_dev *dev,DRV_LOG (DEBUG ,"Indirect age action %" PRIu32" was" " released with references %d." , idx, ret);return 0 ; +case MLX5_INDIRECT_ACTION_TYPE_CT : + ret =flow_dv_aso_ct_release (dev, idx); +if (ret) +DRV_LOG (DEBUG ,"Connection tracking object %u still " +"has references %d." , idx, ret); +return 0 ;default : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.26.2
PATCH v7 11/17 net/mlx5: add translation of CT action
In reply to Bing ZhaoWhen creating a flow with this action context for CT, it needs to be translated in 2 levels.
First, retrieve from action context to rte_flow action. Second, translate it to the corresponding DR action with traffic direction that was specified when creating or updating via rte_flow_action_handle* API.
Before using the DR action in a flow, the CT context should be available to use in the hardware. A synchronization is done before inserting the flow rule with CT action to check the HW availability of this CT context.
In order to release the DR actions and reuse the context of a CT, the reference count should also be handled in the flow rule destroying.
The CT index will be recorded in the rte_flow by reusing the ASO age index to save memory, since only one ASO action is supported in one flow rule currently. The action context type should also be saved for CT. When destroying a flow rule, if the context type is CT and the index is valid (non-zero), the release process should be handled. By default, the handling will fall back to try to release the ASO age if any.
--- drivers/net/mlx5/mlx5.h | 2 ++ drivers/net/mlx5/mlx5_flow.c | 9 +++++++ drivers/net/mlx5/mlx5_flow.h | 7 +++++- drivers/net/mlx5/mlx5_flow_aso.c | 41 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 28 +++++++++++++++++++++- 5 files changed, 85 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.h +2 -0
@@ -1715,5 +1715,7 @@ int mlx5_aso_ct_wait_ready(struct mlx5_dev_ctx_shared *sh,int mlx5_aso_ct_query_by_wqe (struct mlx5_dev_ctx_shared *sh,struct mlx5_aso_ct_action *ct,struct rte_flow_action_conntrack *profile); +int mlx5_aso_ct_available (struct mlx5_dev_ctx_shared *sh, +struct mlx5_aso_ct_action *ct);#endif /* RTE_PMD_MLX5_H_ */
drivers/net/mlx5/mlx5_flow.c +9 -0
@@ -3559,6 +3559,15 @@ flow_action_handles_translate(struct rte_eth_dev *dev,break ; }/* Fall-through */ +case MLX5_INDIRECT_ACTION_TYPE_CT : +if (priv->sh->ct_aso_en) { + translated[handle->index].type = +RTE_FLOW_ACTION_TYPE_CONNTRACK ; + translated[handle->index].conf = + (void *)(uintptr_t )idx; +break ; + } +/* Fall-through */ default :mlx5_free (translated);return rte_flow_error_set
drivers/net/mlx5/mlx5_flow.h +6 -1
@@ -230,6 +230,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)#define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40) +#define MLX5_FLOW_ACTION_CT (1ull << 41)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
@@ -973,11 +974,15 @@ struct rte_flow { uint32_t drv_type:2; /**< Driver type. */ uint32_t tunnel:1; uint32_t meter:24; /**< Holds flow meter id. */ + uint32_t indirect_type:2; /**< Indirect action type. */uint32_t rix_mreg_copy;/**< Index to metadata register copy table resource. */ uint32_t counter;/**< Holds flow counter. */ uint32_t tunnel_id;/**< Tunnel id */ -uint32_t age;/**< Holds ASO age bit index. */ +union { +uint32_t age;/**< Holds ASO age bit index. */ +uint32_t ct;/**< Holds ASO CT index. */ + };uint32_t geneve_tlv_option;/**< Holds Geneve TLV option id. > */ } __rte_packed;
drivers/net/mlx5/mlx5_flow_aso.c +41 -0
44 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_dv.c +27 -1
@@ -11776,6 +11776,7 @@ flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,return rte_flow_error_set (error,EBUSY ,RTE_FLOW_ERROR_TYPE_ACTION ,NULL ,"Failed to update CT" ); + ct->is_original = !!pro->is_original_dir;return idx; }
@@ -11941,6 +11942,8 @@ flow_dv_translate(struct rte_eth_dev *dev,int action_type = actions->type;const struct rte_flow_action *found_action =NULL ;uint32_t jump_group =0 ; +uint32_t ct_idx; +struct mlx5_aso_ct_action *ct;if (!mlx5_flow_os_action_supported (action_type)) return rte_flow_error_set(error, ENOTSUP,
@@ -12394,6 +12397,26 @@ flow_dv_translate(struct rte_eth_dev *dev,return -rte_errno; action_flags |=MLX5_FLOW_ACTION_MODIFY_FIELD ;break ; +case RTE_FLOW_ACTION_TYPE_CONNTRACK : + ct_idx = (uint32_t )(uintptr_t )action->conf; + ct =flow_aso_ct_get_by_idx (dev, ct_idx); +if (mlx5_aso_ct_available (priv->sh, ct)) +return rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_ACTION , +NULL , +"CT is unavailable." ); +if (ct->is_original) + dev_flow->dv.actions[actions_n] = + ct->dr_action_orig; +else + dev_flow->dv.actions[actions_n] = + ct->dr_action_rply; + flow->indirect_type =MLX5_INDIRECT_ACTION_TYPE_CT ; + flow->ct = ct_idx; +__atomic_fetch_add (&ct->refcnt,1 , __ATOMIC_RELAXED); + actions_n++; + action_flags |=MLX5_FLOW_ACTION_CT ; +break ;case RTE_FLOW_ACTION_TYPE_END : actions_end = true;if (mhdr_res->actions_num) {
@@ -13564,7 +13587,10 @@ flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)mlx5_flow_meter_detach (priv, fm); flow->meter =0 ; } -if (flow->age) +/* Keep the current age handling by default. */ +if (flow->indirect_type ==MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct) +flow_dv_aso_ct_release (dev, flow->ct); +else if (flow->age)flow_dv_aso_age_release (dev, flow->age);if (flow->geneve_tlv_option) {flow_dv_geneve_tlv_option_resource_release (dev);
Signature · 1 line
2.26.2
PATCH v7 12/17 net/mlx5: add translation of CT item
In reply to Bing ZhaoThe return register of the DR action will be used for matching. After the ASO CT checking of a TCP packet, the syndrome is filled in the register. Only the 8 LSB should be used. A converting from RTE_FLOW_CONNTRACK_FLAG* to the syndrome should be done after checing the spec and mask fields.
--- drivers/net/mlx5/mlx5_flow.h | 7 ++++ drivers/net/mlx5/mlx5_flow_dv.c | 62 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
drivers/net/mlx5/mlx5_flow.h +7 -0
@@ -409,6 +409,13 @@ enum mlx5_feature_name {/* Maximum number of fields to modify in MODIFY_FIELD */ #define MLX5_ACT_MAX_MOD_FIELDS 5 +/* Syndrome bits definition for connection tracking. */ +#define MLX5_CT_SYNDROME_VALID (0x0 << 6) +#define MLX5_CT_SYNDROME_INVALID (0x1 << 6) +#define MLX5_CT_SYNDROME_TRAP (0x2 << 6) +#define MLX5_CT_SYNDROME_STATE_CHANGE (0x1 << 1) +#define MLX5_CT_SYNDROME_BAD_PACKET (0x1 << 0) +enum mlx5_flow_drv_type {MLX5_FLOW_TYPE_MIN ,MLX5_FLOW_TYPE_DV ,
drivers/net/mlx5/mlx5_flow_dv.c +62 -0
74 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v7 13/17 net/mlx5: add CT context update
In reply to Bing ZhaoWhen updating a connection tracking context, two separate parts could be updated.
First, the direction. This will only update the traffic direction recorded in the software for flow creation.
Second, the TCP parameters. The hardware context will be updated via the WQE. This update will be blocked until the hardware status is updated and ready for the next flow creation.
--- drivers/net/mlx5/mlx5_flow_dv.c | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
drivers/net/mlx5/mlx5_flow_dv.c +56 -0
@@ -14254,6 +14254,60 @@ __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,return ret; } +/* +* Updates in place conntrack context or direction. +* Context update should be synchronized. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* The conntrack object ID to be updated. +* @param[in] update +* Pointer to the structure of information to update. +* @param[out] error +* Perform verbose error reporting if not NULL. Initialized in case of +* error only. +* +* @return +* 0 on success, otherwise negative errno value. +*/ +static int +__flow_dv_action_ct_update (struct rte_eth_dev *dev,uint32_t idx, +const struct rte_flow_modify_conntrack *update, +struct rte_flow_error *error) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +const struct rte_flow_action_conntrack *new_prf; +int ret =0 ; + + ct =flow_aso_ct_get_by_idx (dev, idx); +if (!ct->refcnt) +return rte_flow_error_set (error,ENOMEM , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"CT object is inactive" ); + new_prf = &update->new_ct; +if (update->direction) + ct->is_original = !!new_prf->is_original_dir; +if (update->state) { + ret =mlx5_aso_ct_update_by_wqe (priv->sh, ct, new_prf); +if (ret) +return rte_flow_error_set (error,EIO , +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Failed to send CT context update WQE" ); +/* Block until ready or a failure. */ + ret =mlx5_aso_ct_available (priv->sh, ct); +if (ret) +rte_flow_error_set (error, rte_errno, +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"Timeout to get the CT update" ); + } +return ret; +} +/** * Updates in place shared action configuration, lock free, * (mutex should be acquired by caller).
@@ -14289,6 +14343,8 @@ flow_dv_action_update(struct rte_eth_dev *dev,case MLX5_INDIRECT_ACTION_TYPE_RSS : action_conf = ((const struct rte_flow_action *)update)->conf;return __flow_dv_action_rss_update (dev, idx, action_conf, err); +case MLX5_INDIRECT_ACTION_TYPE_CT : +return __flow_dv_action_ct_update (dev, idx, update, err);default : return rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
Signature · 1 line
2.26.2
PATCH v7 14/17 net/mlx5: validation of CT action
In reply to Bing ZhaoThe validation of a CT action contains two parts. The first is the CT action configurations parameter. When creating a CT action context, some members need to be verified.
The second is that when creating a flow, the DR action of CT should be validated with other actions and items as well. Currently, only the TCP protocol support connection tracking.
--- drivers/net/mlx5/mlx5.h | 4 ++ drivers/net/mlx5/mlx5_flow.c | 31 +++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 69 +++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+)
drivers/net/mlx5/mlx5.h +4 -0
@@ -1616,6 +1616,10 @@ int mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow,void mlx5_flow_rxq_dynf_metadata_set (struct rte_eth_dev *dev);int mlx5_flow_get_aged_flows (struct rte_eth_dev *dev,void **contexts,uint32_t nb_contexts,struct rte_flow_error *error); +int mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error); +/* mlx5_mp_os.c */
drivers/net/mlx5/mlx5_flow.c +31 -0
@@ -1688,6 +1688,37 @@ mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,return 0 ; } +/* +* Validate the ASO CT action. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] conntrack +* Pointer to the CT action profile. +* @param[out] error +* Pointer to error structure. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_validate_action_ct (struct rte_eth_dev *dev, +const struct rte_flow_action_conntrack *conntrack, +struct rte_flow_error *error) +{ +RTE_SET_USED (dev); + +if (conntrack->state >RTE_FLOW_CONNTRACK_STATE_TIME_WAIT ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid CT state" ); +if (conntrack->last_index >RTE_FLOW_CONNTRACK_FLAG_RST ) +return rte_flow_error_set (error,EINVAL , +RTE_FLOW_ERROR_TYPE_ACTION ,NULL , +"Invalid last TCP packet flag" ); +return 0 ; +} +/** * Verify the @p attributes will be correctly understood by the NIC and store * them in the @p flow if everything is correct.
drivers/net/mlx5/mlx5_flow_dv.c +69 -0
93 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v7 15/17 net/mlx5: validation of CT item
In reply to Bing ZhaoThe item of ASO connection tracking will be translated into the register value when matching. The validation of this item has no dependency on other layers, since the flow including this item should be jumped from another group. All the layers checking was already done in the previous groups. Only the state bits conflict should be checked.
It is assumed that the flow with CT item will always work on the TCP traffic.
--- drivers/net/mlx5/mlx5_flow.h | 3 ++ drivers/net/mlx5/mlx5_flow_dv.c | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
drivers/net/mlx5/mlx5_flow.h +3 -0
@@ -151,6 +151,9 @@ enum mlx5_feature_name {/* INTEGRITY item bit */ #define MLX5_FLOW_ITEM_INTEGRITY (UINT64_C(1) << 34) +/* Conntrack item. */ +#define MLX5_FLOW_LAYER_ASO_CT (UINT64_C(1) << 35) +/* Outer Masks. */ #define MLX5_FLOW_LAYER_OUTER_L3 \ (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6)
drivers/net/mlx5/mlx5_flow_dv.c +51 -0
63 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v7 16/17 net/mlx5: add support of CT between two ports
In reply to Bing ZhaoAfter creating a connection tracking context, it can be used between two ports. For each port, the flow for one direction traffic will be created.
The context can only be shared between the owner port and the peer port that was specified when being created. Only the owner port could update the context or query it in current implementation.
--- drivers/net/mlx5/mlx5_flow.h | 57 +++++++++++++++++++++++++- drivers/net/mlx5/mlx5_flow_dv.c | 72 +++++++++++++++++++++++++-------- 2 files changed, 111 insertions(+), 18 deletions(-)
drivers/net/mlx5/mlx5_flow.h +55 -2
@@ -49,6 +49,25 @@ enum { MLX5_INDIRECT_ACTION_TYPE_CT, }; +/* Now, the maximal ports will be supported is 256, action number is 4M. */ +#define MLX5_INDIRECT_ACT_CT_MAX_PORT 0x100 + +#define MLX5_INDIRECT_ACT_CT_OWNER_SHIFT 22 +#define MLX5_INDIRECT_ACT_CT_OWNER_MASK (MLX5_INDIRECT_ACT_CT_MAX_PORT - 1) + +/* 30-31: type, 22-29: owner port, 0-21: index. */ +#define MLX5_INDIRECT_ACT_CT_GEN_IDX (owner, index) \ + ((MLX5_INDIRECT_ACTION_TYPE_CT << MLX5_INDIRECT_ACTION_TYPE_OFFSET) | \ + (((owner) & MLX5_INDIRECT_ACT_CT_OWNER_MASK) << \ + MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) | (index)) + +#define MLX5_INDIRECT_ACT_CT_GET_OWNER (index) \ + (((index) >> MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) & \ + MLX5_INDIRECT_ACT_CT_OWNER_MASK) + +#define MLX5_INDIRECT_ACT_CT_GET_IDX (index) \ + ((index) & ((1 << MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) - 1)) +/* Matches on selected register. */ struct mlx5_rte_flow_item_tag {enum modify_reg id;
@@ -1334,7 +1353,7 @@ mlx5_validate_integrity_item(const struct rte_flow_item_integrity *item) }/* -* Get ASO CT action by index. +* Get ASO CT action by device and index. * * @param[in] dev * Pointer to the Ethernet device structure.
@@ -1345,7 +1364,7 @@ mlx5_validate_integrity_item(const struct rte_flow_item_integrity *item)* The specified ASO CT action pointer. */ static inline struct mlx5_aso_ct_action * -flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t idx) +flow_aso_ct_get_by_dev_idx (struct rte_eth_dev *dev,uint32_t idx) {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
@@ -1360,6 +1379,40 @@ flow_aso_ct_get_by_idx(struct rte_eth_dev *dev, uint32_t idx)return &pool->actions[idx %MLX5_ASO_CT_ACTIONS_PER_POOL ]; } +/* +* Get ASO CT action by owner & index. +* +* @param[in] dev +* Pointer to the Ethernet device structure. +* @param[in] idx +* Index to the ASO CT action and owner port combination. +* +* @return +* The specified ASO CT action pointer. +*/ +static inline struct mlx5_aso_ct_action * +flow_aso_ct_get_by_idx (struct rte_eth_dev *dev,uint32_t own_idx) +{ +struct mlx5_priv *priv = dev->data->dev_private; +struct mlx5_aso_ct_action *ct; +uint16_t owner = (uint16_t )MLX5_INDIRECT_ACT_CT_GET_OWNER (own_idx); +uint32_t idx =MLX5_INDIRECT_ACT_CT_GET_IDX (own_idx); + +if (owner ==PORT_ID (priv)) { + ct =flow_aso_ct_get_by_dev_idx (dev, idx); + }else { +struct rte_eth_dev *owndev = &rte_eth_devices[owner]; + +MLX5_ASSERT (owner <RTE_MAX_ETHPORTS ); +if (dev->data->dev_started !=1 ) +return NULL ; + ct =flow_aso_ct_get_by_dev_idx (owndev, idx); +if (ct->peer !=PORT_ID (priv)) +return NULL ; + } +return ct; +} + int mlx5_flow_group_to_table(struct rte_eth_dev *dev, const struct mlx5_flow_tunnel *tunnel, uint32_t group, uint32_t *table,
drivers/net/mlx5/mlx5_flow_dv.c +56 -16
172 lines not on this page · raw message
Signature · 1 line
2.26.2