Skip to contentSkip to conversation

net/mlx5: add indirect QUOTA create/query/modify

PATCH Superseded Gregory Etelson 3 participants 20 messages Jan 18, 2023 – May 25, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover net/mlx5: add indirect QUOTA create/query/modify

Add indirect quota flow action.
Add match on quota flow item.

Gregory Etelson (5):
net/mlx5: update query fields in async job structure net/mlx5: remove code duplication common/mlx5: update MTR ASO definitions net/mlx5: add indirect QUOTA create/query/modify
mlx5dr: Definer, translate RTE quota item

 drivers/common/mlx5/mlx5_prm.h        |   4 +
 drivers/net/mlx5/hws/mlx5dr_definer.c |  61 +++
 drivers/net/mlx5/meson.build          |   1 +
 drivers/net/mlx5/mlx5.h               |  88 +++-
 drivers/net/mlx5/mlx5_flow.c          |  62 +++
 drivers/net/mlx5/mlx5_flow.h          |  20 +-
 drivers/net/mlx5/mlx5_flow_aso.c      |  10 +-
 drivers/net/mlx5/mlx5_flow_hw.c       | 527 +++++++++++++------
 drivers/net/mlx5/mlx5_flow_quota.c    | 726 ++++++++++++++++++++++++++
 9 files changed, 1318 insertions(+), 181 deletions(-)
 create mode 100644 drivers/net/mlx5/mlx5_flow_quota.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/5 net/mlx5: update query fields in async job structure

Query fields defined in mlx5_hw_q_job target CT type only. The patch updates mlx5_hw_q_job for other query types as well.

---
 drivers/net/mlx5/mlx5.h          | 10 +++++-----
 drivers/net/mlx5/mlx5_flow_aso.c |  2 +-
 drivers/net/mlx5/mlx5_flow_hw.c  |  6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/net/mlx5/mlx5.h +5 -5
index 16b33e1548..eaf2ad69fb 100644
@@ -366,11 +366,11 @@ struct mlx5_hw_q_job {
 	struct rte_flow_item *items;
 	union {
 		struct {
-			/* Pointer to ct query user memory. */
-			struct rte_flow_action_conntrack *profile;
-			/* Pointer to ct ASO query out memory. */
-			void *out_data;
-		} __rte_packed;
+			/* User memory for query output */
+			void *user;
+			/* Data extracted from hardware */
+			void *hw;
+		} __rte_packed query;
 		struct rte_flow_item_ethdev port_spec;
 		struct rte_flow_item_tag tag_spec;
 	} __rte_packed;
drivers/net/mlx5/mlx5_flow_aso.c +1 -1
index 29bd7ce9e8..0eb91c570f 100644
@@ -1389,7 +1389,7 @@ mlx5_aso_ct_sq_query_single(struct mlx5_dev_ctx_shared *sh,
 		struct mlx5_hw_q_job *job = (struct mlx5_hw_q_job *)user_data;
 
 		sq->elts[wqe_idx].ct = user_data;
-		job->out_data = (char *)((uintptr_t)sq->mr.addr + wqe_idx * 64);
+		job->query.hw = (char *)((uintptr_t)sq->mr.addr + wqe_idx * 64);
 	} else {
 		sq->elts[wqe_idx].query_data = data;
 		sq->elts[wqe_idx].ct = ct;
drivers/net/mlx5/mlx5_flow_hw.c +3 -3
index 20c71ff7f0..df5883f340 100644
@@ -2730,8 +2730,8 @@ __flow_hw_pull_indir_action_comp(struct rte_eth_dev *dev,
 				idx = MLX5_ACTION_CTX_CT_GET_IDX
 					((uint32_t)(uintptr_t)job->action);
 				aso_ct = mlx5_ipool_get(priv->hws_ctpool->cts, idx);
-				mlx5_aso_ct_obj_analyze(job->profile,
-							job->out_data);
+				mlx5_aso_ct_obj_analyze(job->query.user,
+							job->query.hw);
 				aso_ct->state = ASO_CONNTRACK_READY;
 			}
 		}
@@ -8179,7 +8179,7 @@ flow_hw_action_handle_query(struct rte_eth_dev *dev, uint32_t queue,
 	case MLX5_INDIRECT_ACTION_TYPE_CT:
 		aso = true;
 		if (job)
-			job->profile = (struct rte_flow_action_conntrack *)data;
+			job->query.user = data;
 		ret = flow_hw_conntrack_query(dev, queue, act_idx, data,
 					      job, push, error);
 		break;
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/5 net/mlx5: remove code duplication

In reply to Gregory Etelson

Replace duplicated code with dedicated functions

---
 drivers/net/mlx5/mlx5.h         |   6 +-
 drivers/net/mlx5/mlx5_flow_hw.c | 182 ++++++++++++++++----------------
 2 files changed, 95 insertions(+), 93 deletions(-)
drivers/net/mlx5/mlx5.h +3 -3
index eaf2ad69fb..7c6bc91ddf 100644
@@ -344,11 +344,11 @@ struct mlx5_lb_ctx {
 };
 
 /* HW steering queue job descriptor type. */
-enum {
+enum mlx5_hw_job_type {
 	MLX5_HW_Q_JOB_TYPE_CREATE, /* Flow create job type. */
 	MLX5_HW_Q_JOB_TYPE_DESTROY, /* Flow destroy job type. */
-	MLX5_HW_Q_JOB_TYPE_UPDATE,
-	MLX5_HW_Q_JOB_TYPE_QUERY,
+	MLX5_HW_Q_JOB_TYPE_UPDATE, /* Flow update job type. */
+	MLX5_HW_Q_JOB_TYPE_QUERY, /* Flow query job type. */
 };
 
 #define MLX5_HW_MAX_ITEMS (16)
drivers/net/mlx5/mlx5_flow_hw.c +92 -90

251 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/5 common/mlx5: update MTR ASO definitions

In reply to Gregory Etelson

Update MTR ASO definitions for QUOTA flow action. Quota flow action requires WQE READ capability and access to token fields.

---
 drivers/common/mlx5/mlx5_prm.h | 4 ++++
 1 file changed, 4 insertions(+)
drivers/common/mlx5/mlx5_prm.h +4 -0
index 3790dc84b8..c25eb6b8c3 100644
@@ -3814,6 +3814,8 @@ enum mlx5_aso_op {
 	ASO_OPER_LOGICAL_OR = 0x1,
 };
 
+#define MLX5_ASO_CSEG_READ_ENABLE 1
+
 /* ASO WQE CTRL segment. */
 struct mlx5_aso_cseg {
 	uint32_t va_h;
@@ -3828,6 +3830,8 @@ struct mlx5_aso_cseg {
 	uint64_t data_mask;
 } __rte_packed;
 
+#define MLX5_MTR_MAX_TOKEN_VALUE INT32_MAX
+
 /* A meter data segment - 2 per ASO WQE. */
 struct mlx5_aso_mtr_dseg {
 	uint32_t v_bo_sc_bbog_mm;
Signature · 1 line
2.34.1
#4 lore raw

PATCH 4/5 net/mlx5: add indirect QUOTA create/query/modify

In reply to Gregory Etelson

Implement HWS functions for indirect QUOTA creation, modification and query.

---
 drivers/net/mlx5/meson.build       |   1 +
 drivers/net/mlx5/mlx5.h            |  72 +++
 drivers/net/mlx5/mlx5_flow.c       |  62 +++
 drivers/net/mlx5/mlx5_flow.h       |  20 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   8 +-
 drivers/net/mlx5/mlx5_flow_hw.c    | 343 +++++++++++---
 drivers/net/mlx5/mlx5_flow_quota.c | 726 +++++++++++++++++++++++++++++
 7 files changed, 1151 insertions(+), 81 deletions(-)
 create mode 100644 drivers/net/mlx5/mlx5_flow_quota.c
drivers/net/mlx5/meson.build +1 -0
index abd507bd88..323c381d2b 100644
@@ -23,6 +23,7 @@ sources = files(
         'mlx5_flow_dv.c',
         'mlx5_flow_aso.c',
         'mlx5_flow_flex.c',
+        'mlx5_flow_quota.c',
         'mlx5_mac.c',
         'mlx5_rss.c',
         'mlx5_rx.c',
drivers/net/mlx5/mlx5.h +72 -0

112 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +62 -0

92 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +19 -1
index e376dcae93..9235af960d 100644
@@ -70,6 +70,7 @@ enum {
 	MLX5_INDIRECT_ACTION_TYPE_COUNT,
 	MLX5_INDIRECT_ACTION_TYPE_CT,
 	MLX5_INDIRECT_ACTION_TYPE_METER_MARK,
+	MLX5_INDIRECT_ACTION_TYPE_QUOTA,
 };
 
 /* Now, the maximal ports will be supported is 16, action number is 32M. */
@@ -218,6 +219,8 @@ enum mlx5_feature_name {
 
 /* Meter color item */
 #define MLX5_FLOW_ITEM_METER_COLOR (UINT64_C(1) << 44)
+#define MLX5_FLOW_ITEM_QUOTA (UINT64_C(1) << 45)
+
 
 /* Outer Masks. */
 #define MLX5_FLOW_LAYER_OUTER_L3 \
@@ -303,6 +306,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_SEND_TO_KERNEL (1ull << 42)
 #define MLX5_FLOW_ACTION_INDIRECT_COUNT (1ull << 43)
 #define MLX5_FLOW_ACTION_INDIRECT_AGE (1ull << 44)
+#define MLX5_FLOW_ACTION_QUOTA (1ull << 46)
 
 #define MLX5_FLOW_DROP_INCLUSIVE_ACTIONS \
 	(MLX5_FLOW_ACTION_COUNT | MLX5_FLOW_ACTION_SAMPLE | MLX5_FLOW_ACTION_AGE)
@@ -1699,6 +1703,12 @@ typedef int (*mlx5_flow_action_query_t)
 			 const struct rte_flow_action_handle *action,
 			 void *data,
 			 struct rte_flow_error *error);
+typedef int (*mlx5_flow_action_query_update_t)
+			(struct rte_eth_dev *dev,
+			 struct rte_flow_action_handle *handle,
+			 const void *update, void *data,
+			 enum rte_flow_query_update_mode qu_mode,
+			 struct rte_flow_error *error);
 typedef int (*mlx5_flow_sync_domain_t)
 			(struct rte_eth_dev *dev,
 			 uint32_t domains,
@@ -1845,7 +1855,13 @@ typedef int (*mlx5_flow_async_action_handle_update_t)
 			 const void *update,
 			 void *user_data,
 			 struct rte_flow_error *error);
-
+typedef int (*mlx5_flow_async_action_handle_query_update_t)
+			(struct rte_eth_dev *dev, uint32_t queue_id,
+			 const struct rte_flow_op_attr *op_attr,
+			 struct rte_flow_action_handle *action_handle,
+			 const void *update, void *data,
+			 enum rte_flow_query_update_mode qu_mode,
+			 void *user_data, struct rte_flow_error *error);
 typedef int (*mlx5_flow_async_action_handle_query_t)
 			(struct rte_eth_dev *dev,
 			 uint32_t queue,
@@ -1896,6 +1912,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_action_destroy_t action_destroy;
 	mlx5_flow_action_update_t action_update;
 	mlx5_flow_action_query_t action_query;
+	mlx5_flow_action_query_update_t action_query_update;
 	mlx5_flow_sync_domain_t sync_domain;
 	mlx5_flow_discover_priorities_t discover_priorities;
 	mlx5_flow_item_create_t item_create;
@@ -1917,6 +1934,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_push_t push;
 	mlx5_flow_async_action_handle_create_t async_action_create;
 	mlx5_flow_async_action_handle_update_t async_action_update;
+	mlx5_flow_async_action_handle_query_update_t async_action_query_update;
 	mlx5_flow_async_action_handle_query_t async_action_query;
 	mlx5_flow_async_action_handle_destroy_t async_action_destroy;
 };
drivers/net/mlx5/mlx5_flow_aso.c +4 -4
index 0eb91c570f..3c08da0614 100644
@@ -74,7 +74,7 @@ mlx5_aso_reg_mr(struct mlx5_common_device *cdev, size_t length,
  * @param[in] sq
  *   ASO SQ to destroy.
  */
-static void
+void
 mlx5_aso_destroy_sq(struct mlx5_aso_sq *sq)
 {
 	mlx5_devx_sq_destroy(&sq->sq_obj);
@@ -148,7 +148,7 @@ mlx5_aso_age_init_sq(struct mlx5_aso_sq *sq)
  * @param[in] sq
  *   ASO SQ to initialize.
  */
-static void
+void
 mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq)
 {
 	volatile struct mlx5_aso_wqe *restrict wqe;
@@ -219,7 +219,7 @@ mlx5_aso_ct_init_sq(struct mlx5_aso_sq *sq)
  * @return
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
-static int
+int
 mlx5_aso_sq_create(struct mlx5_common_device *cdev, struct mlx5_aso_sq *sq,
 		   void *uar, uint16_t log_desc_n)
 {
@@ -504,7 +504,7 @@ mlx5_aso_dump_err_objs(volatile uint32_t *cqe, volatile uint32_t *wqe)
  * @param[in] sq
  *   ASO SQ to use.
  */
-static void
+void
 mlx5_aso_cqe_err_handle(struct mlx5_aso_sq *sq)
 {
 	struct mlx5_aso_cq *cq = &sq->cq;
drivers/net/mlx5/mlx5_flow_hw.c +267 -76

520 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_quota.c new file +726 -0

726 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

PATCH 5/5 mlx5dr: Definer, translate RTE quota item

In reply to Gregory Etelson

MLX5 PMD implements QUOTA with Meter object. PMD Quota action translation implicitly increments Meter register value after HW assigns it. Meter register values are:
HW QUOTA(HW+1) QUOTA state

RED        0        1 (01b)       BLOCK
YELLOW     1        2 (10b)       PASS
GREEN      2        3 (11b)       PASS

Quota item checks Meter register bit 1 value to determine state:
SPEC MASK

PASS     2 (10b)    2 (10b)
BLOCK    0 (00b)    2 (10b)
---
 drivers/net/mlx5/hws/mlx5dr_definer.c | 61 +++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
drivers/net/mlx5/hws/mlx5dr_definer.c +61 -0
index 6b98eb8c96..40ffb02be0 100644
@@ -19,6 +19,9 @@
 #define STE_UDP		0x2
 #define STE_ICMP	0x3
 
+#define MLX5DR_DEFINER_QUOTA_BLOCK 0
+#define MLX5DR_DEFINER_QUOTA_PASS  2
+
 /* Setter function based on bit offset and mask, for 32bit DW*/
 #define _DR_SET_32(p, v, byte_off, bit_off, mask) \
 	do { \
@@ -1134,6 +1137,60 @@ mlx5dr_definer_conv_item_tag(struct mlx5dr_definer_conv_data *cd,
 	return 0;
 }
 
+static void
+mlx5dr_definer_quota_set(struct mlx5dr_definer_fc *fc,
+			 const void *item_data, uint8_t *tag)
+{
+	/**
+	 * MLX5 PMD implements QUOTA with Meter object.
+	 * PMD Quota action translation implicitly increments
+	 * Meter register value after HW assigns it.
+	 * Meter register values are:
+	 *            HW     QUOTA(HW+1)  QUOTA state
+	 * RED        0        1 (01b)       BLOCK
+	 * YELLOW     1        2 (10b)       PASS
+	 * GREEN      2        3 (11b)       PASS
+	 *
+	 * Quota item checks Meter register bit 1 value to determine state:
+	 *            SPEC       MASK
+	 * PASS     2 (10b)    2 (10b)
+	 * BLOCK    0 (00b)    2 (10b)
+	 *
+	 * item_data is NULL when template quota item is non-masked:
+	 * .. / quota / ..
+	 */
+
+	const struct rte_flow_item_quota *quota = item_data;
+	uint32_t val;
+
+	if (quota && (quota->state == RTE_FLOW_QUOTA_STATE_BLOCK))
+		val = MLX5DR_DEFINER_QUOTA_BLOCK;
+	else
+		val = MLX5DR_DEFINER_QUOTA_PASS;
+
+	DR_SET(tag, val, fc->byte_off, fc->bit_off, fc->bit_mask);
+}
+
+static int
+mlx5dr_definer_conv_item_quota(struct mlx5dr_definer_conv_data *cd,
+			       __rte_unused struct rte_flow_item *item,
+			       int item_idx)
+{
+	int mtr_reg = flow_hw_get_reg_id(RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
+	struct mlx5dr_definer_fc *fc;
+
+	if (mtr_reg < 0)
+		return EINVAL;
+
+	fc = mlx5dr_definer_get_register_fc(cd, mtr_reg);
+	if (!fc)
+		return rte_errno;
+
+	fc->tag_set = &mlx5dr_definer_quota_set;
+	fc->item_idx = item_idx;
+	return 0;
+}
+
 static int
 mlx5dr_definer_conv_item_metadata(struct mlx5dr_definer_conv_data *cd,
 				  struct rte_flow_item *item,
@@ -1581,6 +1638,10 @@ mlx5dr_definer_conv_items_to_hl(struct mlx5dr_context *ctx,
 			ret = mlx5dr_definer_conv_item_meter_color(&cd, items, i);
 			item_flags |= MLX5_FLOW_ITEM_METER_COLOR;
 			break;
+		case RTE_FLOW_ITEM_TYPE_QUOTA:
+			ret = mlx5dr_definer_conv_item_quota(&cd, items, i);
+			item_flags |= MLX5_FLOW_ITEM_QUOTA;
+			break;
 		default:
 			DR_LOG(ERR, "Unsupported item type %d", items->type);
 			rte_errno = ENOTSUP;
Signature · 1 line
2.34.1
#6 lore raw
In reply to Gregory Etelson

Hi Gregory,

The code looks good to me. But I assume doc update is missing here. Can you please update the relevant doc and release notes?

BR,
Suanming Mou

Quoted 32 lines

-----Original Message-----
From: Gregory Etelson <[email protected]>
Sent: Wednesday, January 18, 2023 8:56 PM
To: [email protected]
Cc: Gregory Etelson <[email protected]>; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>
Subject: [PATCH 0/5] net/mlx5: add indirect QUOTA create/query/modify

Add indirect quota flow action.
Add match on quota flow item.

Gregory Etelson (5):
net/mlx5: update query fields in async job structure net/mlx5: remove code duplication common/mlx5: update MTR ASO definitions net/mlx5: add indirect QUOTA create/query/modify
mlx5dr: Definer, translate RTE quota item

 drivers/common/mlx5/mlx5_prm.h        |   4 +
 drivers/net/mlx5/hws/mlx5dr_definer.c |  61 +++
 drivers/net/mlx5/meson.build          |   1 +
 drivers/net/mlx5/mlx5.h               |  88 +++-
 drivers/net/mlx5/mlx5_flow.c          |  62 +++
 drivers/net/mlx5/mlx5_flow.h          |  20 +-
 drivers/net/mlx5/mlx5_flow_aso.c      |  10 +-
 drivers/net/mlx5/mlx5_flow_hw.c       | 527 +++++++++++++------
 drivers/net/mlx5/mlx5_flow_quota.c    | 726 ++++++++++++++++++++++++++
 9 files changed, 1318 insertions(+), 181 deletions(-)  create mode 100644

drivers/net/mlx5/mlx5_flow_quota.c

--
2.34.1

#7 lore raw

v2 cover net/mlx5: add indirect QUOTA create/query/modify

In reply to Gregory Etelson

Add indirect quota flow action.
Add match on quota flow item.

v2: rebase to the latest main branch.

Gregory Etelson (5):
net/mlx5: update query fields in async job structure net/mlx5: remove code duplication common/mlx5: update MTR ASO definitions net/mlx5: add indirect QUOTA create/query/modify
mlx5dr: Definer, translate RTE quota item

 drivers/common/mlx5/mlx5_prm.h        |   4 +
 drivers/net/mlx5/hws/mlx5dr_definer.c |  61 +++
 drivers/net/mlx5/meson.build          |   1 +
 drivers/net/mlx5/mlx5.h               |  88 ++++-
 drivers/net/mlx5/mlx5_flow.c          |  62 +++
 drivers/net/mlx5/mlx5_flow.h          |  20 +-
 drivers/net/mlx5/mlx5_flow_aso.c      |  10 +-
 drivers/net/mlx5/mlx5_flow_hw.c       | 527 ++++++++++++++++++--------
 8 files changed, 592 insertions(+), 181 deletions(-)
Signature · 1 line
2.34.1
#8 lore raw

PATCH v2 1/5 net/mlx5: update query fields in async job structure

Query fields defined in mlx5_hw_q_job target CT type only. The patch updates mlx5_hw_q_job for other query types as well.

---
 drivers/net/mlx5/mlx5.h          | 10 +++++-----
 drivers/net/mlx5/mlx5_flow_aso.c |  2 +-
 drivers/net/mlx5/mlx5_flow_hw.c  |  6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/net/mlx5/mlx5.h +5 -5
index a766fb408e..aa956ec1b7 100644
@@ -366,11 +366,11 @@ struct mlx5_hw_q_job {
 	struct rte_flow_item *items;
 	union {
 		struct {
-			/* Pointer to ct query user memory. */
-			struct rte_flow_action_conntrack *profile;
-			/* Pointer to ct ASO query out memory. */
-			void *out_data;
-		} __rte_packed;
+			/* User memory for query output */
+			void *user;
+			/* Data extracted from hardware */
+			void *hw;
+		} __rte_packed query;
 		struct rte_flow_item_ethdev port_spec;
 		struct rte_flow_item_tag tag_spec;
 	} __rte_packed;
drivers/net/mlx5/mlx5_flow_aso.c +1 -1
index 29bd7ce9e8..0eb91c570f 100644
@@ -1389,7 +1389,7 @@ mlx5_aso_ct_sq_query_single(struct mlx5_dev_ctx_shared *sh,
 		struct mlx5_hw_q_job *job = (struct mlx5_hw_q_job *)user_data;
 
 		sq->elts[wqe_idx].ct = user_data;
-		job->out_data = (char *)((uintptr_t)sq->mr.addr + wqe_idx * 64);
+		job->query.hw = (char *)((uintptr_t)sq->mr.addr + wqe_idx * 64);
 	} else {
 		sq->elts[wqe_idx].query_data = data;
 		sq->elts[wqe_idx].ct = ct;
drivers/net/mlx5/mlx5_flow_hw.c +3 -3
index a9c7045a3e..cd951019de 100644
@@ -2738,8 +2738,8 @@ __flow_hw_pull_indir_action_comp(struct rte_eth_dev *dev,
 				idx = MLX5_ACTION_CTX_CT_GET_IDX
 					((uint32_t)(uintptr_t)job->action);
 				aso_ct = mlx5_ipool_get(priv->hws_ctpool->cts, idx);
-				mlx5_aso_ct_obj_analyze(job->profile,
-							job->out_data);
+				mlx5_aso_ct_obj_analyze(job->query.user,
+							job->query.hw);
 				aso_ct->state = ASO_CONNTRACK_READY;
 			}
 		}
@@ -8275,7 +8275,7 @@ flow_hw_action_handle_query(struct rte_eth_dev *dev, uint32_t queue,
 	case MLX5_INDIRECT_ACTION_TYPE_CT:
 		aso = true;
 		if (job)
-			job->profile = (struct rte_flow_action_conntrack *)data;
+			job->query.user = data;
 		ret = flow_hw_conntrack_query(dev, queue, act_idx, data,
 					      job, push, error);
 		break;
Signature · 1 line
2.34.1
#9 lore raw

PATCH v2 2/5 net/mlx5: remove code duplication

In reply to Gregory Etelson

Replace duplicated code with dedicated functions

---
 drivers/net/mlx5/mlx5.h         |   6 +-
 drivers/net/mlx5/mlx5_flow_hw.c | 182 ++++++++++++++++----------------
 2 files changed, 95 insertions(+), 93 deletions(-)
drivers/net/mlx5/mlx5.h +3 -3
index aa956ec1b7..a4ed61e257 100644
@@ -344,11 +344,11 @@ struct mlx5_lb_ctx {
 };
 
 /* HW steering queue job descriptor type. */
-enum {
+enum mlx5_hw_job_type {
 	MLX5_HW_Q_JOB_TYPE_CREATE, /* Flow create job type. */
 	MLX5_HW_Q_JOB_TYPE_DESTROY, /* Flow destroy job type. */
-	MLX5_HW_Q_JOB_TYPE_UPDATE,
-	MLX5_HW_Q_JOB_TYPE_QUERY,
+	MLX5_HW_Q_JOB_TYPE_UPDATE, /* Flow update job type. */
+	MLX5_HW_Q_JOB_TYPE_QUERY, /* Flow query job type. */
 };
 
 #define MLX5_HW_MAX_ITEMS (16)
drivers/net/mlx5/mlx5_flow_hw.c +92 -90

251 lines not on this page · raw message

Signature · 1 line
2.34.1
#10 lore raw

PATCH v2 3/5 common/mlx5: update MTR ASO definitions

In reply to Gregory Etelson

Update MTR ASO definitions for QUOTA flow action. Quota flow action requires WQE READ capability and access to token fields.

---
 drivers/common/mlx5/mlx5_prm.h | 4 ++++
 1 file changed, 4 insertions(+)
drivers/common/mlx5/mlx5_prm.h +4 -0
index 75af636f59..525364d5e4 100644
@@ -3917,6 +3917,8 @@ enum mlx5_aso_op {
 	ASO_OPER_LOGICAL_OR = 0x1,
 };
 
+#define MLX5_ASO_CSEG_READ_ENABLE 1
+
 /* ASO WQE CTRL segment. */
 struct mlx5_aso_cseg {
 	uint32_t va_h;
@@ -3931,6 +3933,8 @@ struct mlx5_aso_cseg {
 	uint64_t data_mask;
 } __rte_packed;
 
+#define MLX5_MTR_MAX_TOKEN_VALUE INT32_MAX
+
 /* A meter data segment - 2 per ASO WQE. */
 struct mlx5_aso_mtr_dseg {
 	uint32_t v_bo_sc_bbog_mm;
Signature · 1 line
2.34.1
#11 lore raw

PATCH v2 4/5 net/mlx5: add indirect QUOTA create/query/modify

In reply to Gregory Etelson

Implement HWS functions for indirect QUOTA creation, modification and query.

---
 drivers/net/mlx5/meson.build     |   1 +
 drivers/net/mlx5/mlx5.h          |  72 +++++++
 drivers/net/mlx5/mlx5_flow.c     |  62 ++++++
 drivers/net/mlx5/mlx5_flow.h     |  20 +-
 drivers/net/mlx5/mlx5_flow_aso.c |   8 +-
 drivers/net/mlx5/mlx5_flow_hw.c  | 343 ++++++++++++++++++++++++-------
 6 files changed, 425 insertions(+), 81 deletions(-)
drivers/net/mlx5/meson.build +1 -0
index abd507bd88..323c381d2b 100644
@@ -23,6 +23,7 @@ sources = files(
         'mlx5_flow_dv.c',
         'mlx5_flow_aso.c',
         'mlx5_flow_flex.c',
+        'mlx5_flow_quota.c',
         'mlx5_mac.c',
         'mlx5_rss.c',
         'mlx5_rx.c',
drivers/net/mlx5/mlx5.h +72 -0

114 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +62 -0

92 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +19 -1
index 4bef2296b8..3ba178bd6c 100644
@@ -70,6 +70,7 @@ enum {
 	MLX5_INDIRECT_ACTION_TYPE_COUNT,
 	MLX5_INDIRECT_ACTION_TYPE_CT,
 	MLX5_INDIRECT_ACTION_TYPE_METER_MARK,
+	MLX5_INDIRECT_ACTION_TYPE_QUOTA,
 };
 
 /* Now, the maximal ports will be supported is 16, action number is 32M. */
@@ -218,6 +219,8 @@ enum mlx5_feature_name {
 
 /* Meter color item */
 #define MLX5_FLOW_ITEM_METER_COLOR (UINT64_C(1) << 44)
+#define MLX5_FLOW_ITEM_QUOTA (UINT64_C(1) << 45)
+
 
 /* IPv6 routing extension item */
 #define MLX5_FLOW_ITEM_OUTER_IPV6_ROUTING_EXT (UINT64_C(1) << 45)
@@ -307,6 +310,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_SEND_TO_KERNEL (1ull << 42)
 #define MLX5_FLOW_ACTION_INDIRECT_COUNT (1ull << 43)
 #define MLX5_FLOW_ACTION_INDIRECT_AGE (1ull << 44)
+#define MLX5_FLOW_ACTION_QUOTA (1ull << 46)
 
 #define MLX5_FLOW_DROP_INCLUSIVE_ACTIONS \
 	(MLX5_FLOW_ACTION_COUNT | MLX5_FLOW_ACTION_SAMPLE | MLX5_FLOW_ACTION_AGE)
@@ -1703,6 +1707,12 @@ typedef int (*mlx5_flow_action_query_t)
 			 const struct rte_flow_action_handle *action,
 			 void *data,
 			 struct rte_flow_error *error);
+typedef int (*mlx5_flow_action_query_update_t)
+			(struct rte_eth_dev *dev,
+			 struct rte_flow_action_handle *handle,
+			 const void *update, void *data,
+			 enum rte_flow_query_update_mode qu_mode,
+			 struct rte_flow_error *error);
 typedef int (*mlx5_flow_sync_domain_t)
 			(struct rte_eth_dev *dev,
 			 uint32_t domains,
@@ -1849,7 +1859,13 @@ typedef int (*mlx5_flow_async_action_handle_update_t)
 			 const void *update,
 			 void *user_data,
 			 struct rte_flow_error *error);
-
+typedef int (*mlx5_flow_async_action_handle_query_update_t)
+			(struct rte_eth_dev *dev, uint32_t queue_id,
+			 const struct rte_flow_op_attr *op_attr,
+			 struct rte_flow_action_handle *action_handle,
+			 const void *update, void *data,
+			 enum rte_flow_query_update_mode qu_mode,
+			 void *user_data, struct rte_flow_error *error);
 typedef int (*mlx5_flow_async_action_handle_query_t)
 			(struct rte_eth_dev *dev,
 			 uint32_t queue,
@@ -1900,6 +1916,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_action_destroy_t action_destroy;
 	mlx5_flow_action_update_t action_update;
 	mlx5_flow_action_query_t action_query;
+	mlx5_flow_action_query_update_t action_query_update;
 	mlx5_flow_sync_domain_t sync_domain;
 	mlx5_flow_discover_priorities_t discover_priorities;
 	mlx5_flow_item_create_t item_create;
@@ -1921,6 +1938,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_push_t push;
 	mlx5_flow_async_action_handle_create_t async_action_create;
 	mlx5_flow_async_action_handle_update_t async_action_update;
+	mlx5_flow_async_action_handle_query_update_t async_action_query_update;
 	mlx5_flow_async_action_handle_query_t async_action_query;
 	mlx5_flow_async_action_handle_destroy_t async_action_destroy;
 };
drivers/net/mlx5/mlx5_flow_aso.c +4 -4
index 0eb91c570f..3c08da0614 100644
@@ -74,7 +74,7 @@ mlx5_aso_reg_mr(struct mlx5_common_device *cdev, size_t length,
  * @param[in] sq
  *   ASO SQ to destroy.
  */
-static void
+void
 mlx5_aso_destroy_sq(struct mlx5_aso_sq *sq)
 {
 	mlx5_devx_sq_destroy(&sq->sq_obj);
@@ -148,7 +148,7 @@ mlx5_aso_age_init_sq(struct mlx5_aso_sq *sq)
  * @param[in] sq
  *   ASO SQ to initialize.
  */
-static void
+void
 mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq)
 {
 	volatile struct mlx5_aso_wqe *restrict wqe;
@@ -219,7 +219,7 @@ mlx5_aso_ct_init_sq(struct mlx5_aso_sq *sq)
  * @return
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
-static int
+int
 mlx5_aso_sq_create(struct mlx5_common_device *cdev, struct mlx5_aso_sq *sq,
 		   void *uar, uint16_t log_desc_n)
 {
@@ -504,7 +504,7 @@ mlx5_aso_dump_err_objs(volatile uint32_t *cqe, volatile uint32_t *wqe)
  * @param[in] sq
  *   ASO SQ to use.
  */
-static void
+void
 mlx5_aso_cqe_err_handle(struct mlx5_aso_sq *sq)
 {
 	struct mlx5_aso_cq *cq = &sq->cq;
drivers/net/mlx5/mlx5_flow_hw.c +267 -76

520 lines not on this page · raw message

Signature · 1 line
2.34.1
#12 lore raw

PATCH v2 5/5 mlx5dr: Definer, translate RTE quota item

In reply to Gregory Etelson

MLX5 PMD implements QUOTA with Meter object. PMD Quota action translation implicitly increments Meter register value after HW assigns it. Meter register values are:
HW QUOTA(HW+1) QUOTA state

RED        0        1 (01b)       BLOCK
YELLOW     1        2 (10b)       PASS
GREEN      2        3 (11b)       PASS

Quota item checks Meter register bit 1 value to determine state:
SPEC MASK

PASS     2 (10b)    2 (10b)
BLOCK    0 (00b)    2 (10b)
---
 drivers/net/mlx5/hws/mlx5dr_definer.c | 63 +++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
drivers/net/mlx5/hws/mlx5dr_definer.c +63 -0
index 6374f9df33..dc9e50ee0f 100644
@@ -19,6 +19,9 @@
 #define STE_UDP		0x2
 #define STE_ICMP	0x3
 
+#define MLX5DR_DEFINER_QUOTA_BLOCK 0
+#define MLX5DR_DEFINER_QUOTA_PASS  2
+
 /* Setter function based on bit offset and mask, for 32bit DW*/
 #define _DR_SET_32(p, v, byte_off, bit_off, mask) \
 	do { \
@@ -1247,6 +1250,62 @@ mlx5dr_definer_conv_item_tag(struct mlx5dr_definer_conv_data *cd,
 	return 0;
 }
 
+static void
+mlx5dr_definer_quota_set(struct mlx5dr_definer_fc *fc,
+			 const void *item_data, uint8_t *tag)
+{
+	/**
+	 * MLX5 PMD implements QUOTA with Meter object.
+	 * PMD Quota action translation implicitly increments
+	 * Meter register value after HW assigns it.
+	 * Meter register values are:
+	 *            HW     QUOTA(HW+1)  QUOTA state
+	 * RED        0        1 (01b)       BLOCK
+	 * YELLOW     1        2 (10b)       PASS
+	 * GREEN      2        3 (11b)       PASS
+	 *
+	 * Quota item checks Meter register bit 1 value to determine state:
+	 *            SPEC       MASK
+	 * PASS     2 (10b)    2 (10b)
+	 * BLOCK    0 (00b)    2 (10b)
+	 *
+	 * item_data is NULL when template quota item is non-masked:
+	 * .. / quota / ..
+	 */
+
+	const struct rte_flow_item_quota *quota = item_data;
+	uint32_t val;
+
+	if (quota && quota->state == RTE_FLOW_QUOTA_STATE_BLOCK)
+		val = MLX5DR_DEFINER_QUOTA_BLOCK;
+	else
+		val = MLX5DR_DEFINER_QUOTA_PASS;
+
+	DR_SET(tag, val, fc->byte_off, fc->bit_off, fc->bit_mask);
+}
+
+static int
+mlx5dr_definer_conv_item_quota(struct mlx5dr_definer_conv_data *cd,
+			       __rte_unused struct rte_flow_item *item,
+			       int item_idx)
+{
+	int mtr_reg = flow_hw_get_reg_id(RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
+	struct mlx5dr_definer_fc *fc;
+
+	if (mtr_reg < 0) {
+		rte_errno = EINVAL;
+		return rte_errno;
+	}
+
+	fc = mlx5dr_definer_get_register_fc(cd, mtr_reg);
+	if (!fc)
+		return rte_errno;
+
+	fc->tag_set = &mlx5dr_definer_quota_set;
+	fc->item_idx = item_idx;
+	return 0;
+}
+
 static int
 mlx5dr_definer_conv_item_metadata(struct mlx5dr_definer_conv_data *cd,
 				  struct rte_flow_item *item,
@@ -1904,6 +1963,10 @@ mlx5dr_definer_conv_items_to_hl(struct mlx5dr_context *ctx,
 			ret = mlx5dr_definer_conv_item_meter_color(&cd, items, i);
 			item_flags |= MLX5_FLOW_ITEM_METER_COLOR;
 			break;
+		case RTE_FLOW_ITEM_TYPE_QUOTA:
+			ret = mlx5dr_definer_conv_item_quota(&cd, items, i);
+			item_flags |= MLX5_FLOW_ITEM_QUOTA;
+			break;
 		case RTE_FLOW_ITEM_TYPE_IPV6_ROUTING_EXT:
 			ret = mlx5dr_definer_conv_item_ipv6_routing_ext(&cd, items, i);
 			item_flags |= cd.tunnel ? MLX5_FLOW_ITEM_INNER_IPV6_ROUTING_EXT :
Signature · 1 line
2.34.1
#13 lore raw

v3 cover net/mlx5: support indirect quota flow action

In reply to Gregory Etelson

1. Prepare MLX5 PMD for upcoming indirect quota action.
2. Support query_update API.
3. Support indirect quota action.

v3: prepare patches for dpdk-23.07

Gregory Etelson (5):
net/mlx5: update query fields in async job structure net/mlx5: remove code duplication common/mlx5: update MTR ASO definitions net/mlx5: add indirect QUOTA create/query/modify
mlx5dr: Definer, translate RTE quota item

 doc/guides/nics/features/mlx5.ini      |   2 +
 doc/guides/nics/mlx5.rst               |  10 +
 doc/guides/rel_notes/release_23_07.rst |   4 +
 drivers/common/mlx5/mlx5_prm.h         |   4 +
 drivers/net/mlx5/hws/mlx5dr_definer.c  |  63 +++
 drivers/net/mlx5/meson.build           |   1 +
 drivers/net/mlx5/mlx5.h                |  88 ++-
 drivers/net/mlx5/mlx5_flow.c           |  62 +++
 drivers/net/mlx5/mlx5_flow.h           |  20 +-
 drivers/net/mlx5/mlx5_flow_aso.c       |  10 +-
 drivers/net/mlx5/mlx5_flow_hw.c        | 526 ++++++++++++------
 drivers/net/mlx5/mlx5_flow_quota.c     | 726 +++++++++++++++++++++++++
 12 files changed, 1335 insertions(+), 181 deletions(-)
 create mode 100644 drivers/net/mlx5/mlx5_flow_quota.c
Signature · 1 line
2.34.1
#14 lore raw

PATCH v3 1/5 net/mlx5: update query fields in async job structure

Query fields defined in mlx5_hw_q_job target CT type only. The patch updates mlx5_hw_q_job for other query types as well.

---
 drivers/net/mlx5/mlx5.h          | 10 +++++-----
 drivers/net/mlx5/mlx5_flow_aso.c |  2 +-
 drivers/net/mlx5/mlx5_flow_hw.c  |  6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/net/mlx5/mlx5.h +5 -5
index 9eae692037..18ac90dfe2 100644
@@ -368,11 +368,11 @@ struct mlx5_hw_q_job {
 	struct rte_flow_item *items;
 	union {
 		struct {
-			/* Pointer to ct query user memory. */
-			struct rte_flow_action_conntrack *profile;
-			/* Pointer to ct ASO query out memory. */
-			void *out_data;
-		} __rte_packed;
+			/* User memory for query output */
+			void *user;
+			/* Data extracted from hardware */
+			void *hw;
+		} __rte_packed query;
 		struct rte_flow_item_ethdev port_spec;
 		struct rte_flow_item_tag tag_spec;
 	} __rte_packed;
drivers/net/mlx5/mlx5_flow_aso.c +1 -1
index 29bd7ce9e8..0eb91c570f 100644
@@ -1389,7 +1389,7 @@ mlx5_aso_ct_sq_query_single(struct mlx5_dev_ctx_shared *sh,
 		struct mlx5_hw_q_job *job = (struct mlx5_hw_q_job *)user_data;
 
 		sq->elts[wqe_idx].ct = user_data;
-		job->out_data = (char *)((uintptr_t)sq->mr.addr + wqe_idx * 64);
+		job->query.hw = (char *)((uintptr_t)sq->mr.addr + wqe_idx * 64);
 	} else {
 		sq->elts[wqe_idx].query_data = data;
 		sq->elts[wqe_idx].ct = ct;
drivers/net/mlx5/mlx5_flow_hw.c +3 -3
index 853c94af9c..2a51d3ee19 100644
@@ -2876,8 +2876,8 @@ __flow_hw_pull_indir_action_comp(struct rte_eth_dev *dev,
 				idx = MLX5_ACTION_CTX_CT_GET_IDX
 					((uint32_t)(uintptr_t)job->action);
 				aso_ct = mlx5_ipool_get(priv->hws_ctpool->cts, idx);
-				mlx5_aso_ct_obj_analyze(job->profile,
-							job->out_data);
+				mlx5_aso_ct_obj_analyze(job->query.user,
+							job->query.hw);
 				aso_ct->state = ASO_CONNTRACK_READY;
 			}
 		}
@@ -8619,7 +8619,7 @@ flow_hw_action_handle_query(struct rte_eth_dev *dev, uint32_t queue,
 	case MLX5_INDIRECT_ACTION_TYPE_CT:
 		aso = true;
 		if (job)
-			job->profile = (struct rte_flow_action_conntrack *)data;
+			job->query.user = data;
 		ret = flow_hw_conntrack_query(dev, queue, act_idx, data,
 					      job, push, error);
 		break;
Signature · 1 line
2.34.1
#15 lore raw

PATCH v3 2/5 net/mlx5: remove code duplication

In reply to Gregory Etelson

Replace duplicated code with dedicated functions

---
 drivers/net/mlx5/mlx5.h         |   6 +-
 drivers/net/mlx5/mlx5_flow_hw.c | 182 ++++++++++++++++----------------
 2 files changed, 95 insertions(+), 93 deletions(-)
drivers/net/mlx5/mlx5.h +3 -3
index 18ac90dfe2..c12149b7e7 100644
@@ -346,11 +346,11 @@ struct mlx5_lb_ctx {
 };
 
 /* HW steering queue job descriptor type. */
-enum {
+enum mlx5_hw_job_type {
 	MLX5_HW_Q_JOB_TYPE_CREATE, /* Flow create job type. */
 	MLX5_HW_Q_JOB_TYPE_DESTROY, /* Flow destroy job type. */
-	MLX5_HW_Q_JOB_TYPE_UPDATE,
-	MLX5_HW_Q_JOB_TYPE_QUERY,
+	MLX5_HW_Q_JOB_TYPE_UPDATE, /* Flow update job type. */
+	MLX5_HW_Q_JOB_TYPE_QUERY, /* Flow query job type. */
 };
 
 #define MLX5_HW_MAX_ITEMS (16)
drivers/net/mlx5/mlx5_flow_hw.c +92 -90

251 lines not on this page · raw message

Signature · 1 line
2.34.1
#16 lore raw

PATCH v3 3/5 common/mlx5: update MTR ASO definitions

In reply to Gregory Etelson

Update MTR ASO definitions for QUOTA flow action. Quota flow action requires WQE READ capability and access to token fields.

---
 drivers/common/mlx5/mlx5_prm.h | 4 ++++
 1 file changed, 4 insertions(+)
drivers/common/mlx5/mlx5_prm.h +4 -0
index ed3d5efbb7..9ba3c5d008 100644
@@ -3949,6 +3949,8 @@ enum mlx5_aso_op {
 	ASO_OPER_LOGICAL_OR = 0x1,
 };
 
+#define MLX5_ASO_CSEG_READ_ENABLE 1
+
 /* ASO WQE CTRL segment. */
 struct mlx5_aso_cseg {
 	uint32_t va_h;
@@ -3963,6 +3965,8 @@ struct mlx5_aso_cseg {
 	uint64_t data_mask;
 } __rte_packed;
 
+#define MLX5_MTR_MAX_TOKEN_VALUE INT32_MAX
+
 /* A meter data segment - 2 per ASO WQE. */
 struct mlx5_aso_mtr_dseg {
 	uint32_t v_bo_sc_bbog_mm;
Signature · 1 line
2.34.1
#17 lore raw

PATCH v3 4/5 net/mlx5: add indirect QUOTA create/query/modify

In reply to Gregory Etelson

Implement HWS functions for indirect QUOTA creation, modification and query.

---
 doc/guides/nics/features/mlx5.ini      |   2 +
 doc/guides/nics/mlx5.rst               |  10 +
 doc/guides/rel_notes/release_23_07.rst |   4 +
 drivers/net/mlx5/meson.build           |   1 +
 drivers/net/mlx5/mlx5.h                |  72 +++
 drivers/net/mlx5/mlx5_flow.c           |  62 +++
 drivers/net/mlx5/mlx5_flow.h           |  20 +-
 drivers/net/mlx5/mlx5_flow_aso.c       |   8 +-
 drivers/net/mlx5/mlx5_flow_hw.c        | 342 +++++++++---
 drivers/net/mlx5/mlx5_flow_quota.c     | 726 +++++++++++++++++++++++++
 10 files changed, 1166 insertions(+), 81 deletions(-)
 create mode 100644 drivers/net/mlx5/mlx5_flow_quota.c
doc/guides/nics/features/mlx5.ini +2 -0
index 0650e02e2d..83d2f25660 100644
@@ -84,6 +84,7 @@ mpls                 = Y
 nvgre                = Y
 port_id              = Y
 port_representor     = Y
+quota                = Y
 tag                  = Y
 tcp                  = Y
 udp                  = Y
@@ -115,6 +116,7 @@ of_push_vlan         = Y
 of_set_vlan_pcp      = Y
 of_set_vlan_vid      = Y
 port_id              = Y
+quota                = I
 queue                = Y
 raw_decap            = Y
 raw_encap            = Y
doc/guides/nics/mlx5.rst +10 -0
index 7a137d5f6a..db089591ab 100644
@@ -162,6 +162,7 @@ Features
 - Sub-Function.
 - Matching on represented port.
 - Matching on aggregated affinity.
+- Flow quota.
 
 
 Limitations
@@ -694,6 +695,15 @@ Limitations
   The flow engine of a process cannot move from active to standby mode
   if preceding active application rules are still present and vice versa.
 
+- Quota:
+
+  - Quota implemented for HWS / template API.
+  - Maximal value for quota SET and ADD operations in INT32_MAX (2GB).
+  - Application cannot use 2 consecutive ADD updates.
+    Next tokens update after ADD must always be SET.
+  - Quota flow action cannot be used with Meter or CT flow actions in the same rule.
+  - Quota flow action and item supported in non-root HWS tables.
+  - Maximal number of HW quota and HW meter objects <= 16e6.
 
 Statistics
 ----------
doc/guides/rel_notes/release_23_07.rst +4 -0
index a9b1293689..e9c41c4027 100644
@@ -55,6 +55,10 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+   *  **Updated NVIDIA mlx5 driver.**
+
+      * Added support for quota flow action and item.
+
 
 Removed Items
 -------------
drivers/net/mlx5/meson.build +1 -0
index 623d60c1a2..6ef5083ea4 100644
@@ -47,6 +47,7 @@ if is_linux
     sources += files(
             'mlx5_flow_hw.c',
             'mlx5_hws_cnt.c',
+            'mlx5_flow_quota.c',
             'mlx5_flow_verbs.c',
     )
 endif
drivers/net/mlx5/mlx5.h +72 -0

114 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +62 -0

92 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +19 -1
index 1d116ea0f6..22363fb0b7 100644
@@ -71,6 +71,7 @@ enum {
 	MLX5_INDIRECT_ACTION_TYPE_COUNT,
 	MLX5_INDIRECT_ACTION_TYPE_CT,
 	MLX5_INDIRECT_ACTION_TYPE_METER_MARK,
+	MLX5_INDIRECT_ACTION_TYPE_QUOTA,
 };
 
 /* Now, the maximal ports will be supported is 16, action number is 32M. */
@@ -219,6 +220,8 @@ enum mlx5_feature_name {
 
 /* Meter color item */
 #define MLX5_FLOW_ITEM_METER_COLOR (UINT64_C(1) << 44)
+#define MLX5_FLOW_ITEM_QUOTA (UINT64_C(1) << 45)
+
 
 /* IPv6 routing extension item */
 #define MLX5_FLOW_ITEM_OUTER_IPV6_ROUTING_EXT (UINT64_C(1) << 45)
@@ -311,6 +314,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_SEND_TO_KERNEL (1ull << 42)
 #define MLX5_FLOW_ACTION_INDIRECT_COUNT (1ull << 43)
 #define MLX5_FLOW_ACTION_INDIRECT_AGE (1ull << 44)
+#define MLX5_FLOW_ACTION_QUOTA (1ull << 46)
 
 #define MLX5_FLOW_DROP_INCLUSIVE_ACTIONS \
 	(MLX5_FLOW_ACTION_COUNT | MLX5_FLOW_ACTION_SAMPLE | MLX5_FLOW_ACTION_AGE)
@@ -1714,6 +1718,12 @@ typedef int (*mlx5_flow_action_query_t)
 			 const struct rte_flow_action_handle *action,
 			 void *data,
 			 struct rte_flow_error *error);
+typedef int (*mlx5_flow_action_query_update_t)
+			(struct rte_eth_dev *dev,
+			 struct rte_flow_action_handle *handle,
+			 const void *update, void *data,
+			 enum rte_flow_query_update_mode qu_mode,
+			 struct rte_flow_error *error);
 typedef int (*mlx5_flow_sync_domain_t)
 			(struct rte_eth_dev *dev,
 			 uint32_t domains,
@@ -1870,7 +1880,13 @@ typedef int (*mlx5_flow_async_action_handle_update_t)
 			 const void *update,
 			 void *user_data,
 			 struct rte_flow_error *error);
-
+typedef int (*mlx5_flow_async_action_handle_query_update_t)
+			(struct rte_eth_dev *dev, uint32_t queue_id,
+			 const struct rte_flow_op_attr *op_attr,
+			 struct rte_flow_action_handle *action_handle,
+			 const void *update, void *data,
+			 enum rte_flow_query_update_mode qu_mode,
+			 void *user_data, struct rte_flow_error *error);
 typedef int (*mlx5_flow_async_action_handle_query_t)
 			(struct rte_eth_dev *dev,
 			 uint32_t queue,
@@ -1921,6 +1937,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_action_destroy_t action_destroy;
 	mlx5_flow_action_update_t action_update;
 	mlx5_flow_action_query_t action_query;
+	mlx5_flow_action_query_update_t action_query_update;
 	mlx5_flow_sync_domain_t sync_domain;
 	mlx5_flow_discover_priorities_t discover_priorities;
 	mlx5_flow_item_create_t item_create;
@@ -1943,6 +1960,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_push_t push;
 	mlx5_flow_async_action_handle_create_t async_action_create;
 	mlx5_flow_async_action_handle_update_t async_action_update;
+	mlx5_flow_async_action_handle_query_update_t async_action_query_update;
 	mlx5_flow_async_action_handle_query_t async_action_query;
 	mlx5_flow_async_action_handle_destroy_t async_action_destroy;
 };
drivers/net/mlx5/mlx5_flow_aso.c +4 -4
index 0eb91c570f..3c08da0614 100644
@@ -74,7 +74,7 @@ mlx5_aso_reg_mr(struct mlx5_common_device *cdev, size_t length,
  * @param[in] sq
  *   ASO SQ to destroy.
  */
-static void
+void
 mlx5_aso_destroy_sq(struct mlx5_aso_sq *sq)
 {
 	mlx5_devx_sq_destroy(&sq->sq_obj);
@@ -148,7 +148,7 @@ mlx5_aso_age_init_sq(struct mlx5_aso_sq *sq)
  * @param[in] sq
  *   ASO SQ to initialize.
  */
-static void
+void
 mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq)
 {
 	volatile struct mlx5_aso_wqe *restrict wqe;
@@ -219,7 +219,7 @@ mlx5_aso_ct_init_sq(struct mlx5_aso_sq *sq)
  * @return
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
-static int
+int
 mlx5_aso_sq_create(struct mlx5_common_device *cdev, struct mlx5_aso_sq *sq,
 		   void *uar, uint16_t log_desc_n)
 {
@@ -504,7 +504,7 @@ mlx5_aso_dump_err_objs(volatile uint32_t *cqe, volatile uint32_t *wqe)
  * @param[in] sq
  *   ASO SQ to use.
  */
-static void
+void
 mlx5_aso_cqe_err_handle(struct mlx5_aso_sq *sq)
 {
 	struct mlx5_aso_cq *cq = &sq->cq;
drivers/net/mlx5/mlx5_flow_hw.c +266 -76

519 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_quota.c new file +726 -0

726 lines not on this page · raw message

Signature · 1 line
2.34.1
#18 lore raw

PATCH v3 5/5 mlx5dr: Definer, translate RTE quota item

In reply to Gregory Etelson

MLX5 PMD implements QUOTA with Meter object. PMD Quota action translation implicitly increments Meter register value after HW assigns it. Meter register values are:
HW QUOTA(HW+1) QUOTA state

RED        0        1 (01b)       BLOCK
YELLOW     1        2 (10b)       PASS
GREEN      2        3 (11b)       PASS

Quota item checks Meter register bit 1 value to determine state:
SPEC MASK

PASS     2 (10b)    2 (10b)
BLOCK    0 (00b)    2 (10b)
---
 drivers/net/mlx5/hws/mlx5dr_definer.c | 63 +++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
drivers/net/mlx5/hws/mlx5dr_definer.c +63 -0
index f92d3e8e1f..2d505f1908 100644
@@ -21,6 +21,9 @@
 #define STE_UDP		0x2
 #define STE_ICMP	0x3
 
+#define MLX5DR_DEFINER_QUOTA_BLOCK 0
+#define MLX5DR_DEFINER_QUOTA_PASS  2
+
 /* Setter function based on bit offset and mask, for 32bit DW*/
 #define _DR_SET_32(p, v, byte_off, bit_off, mask) \
 	do { \
@@ -1447,6 +1450,62 @@ mlx5dr_definer_conv_item_tag(struct mlx5dr_definer_conv_data *cd,
 	return 0;
 }
 
+static void
+mlx5dr_definer_quota_set(struct mlx5dr_definer_fc *fc,
+			 const void *item_data, uint8_t *tag)
+{
+	/**
+	 * MLX5 PMD implements QUOTA with Meter object.
+	 * PMD Quota action translation implicitly increments
+	 * Meter register value after HW assigns it.
+	 * Meter register values are:
+	 *            HW     QUOTA(HW+1)  QUOTA state
+	 * RED        0        1 (01b)       BLOCK
+	 * YELLOW     1        2 (10b)       PASS
+	 * GREEN      2        3 (11b)       PASS
+	 *
+	 * Quota item checks Meter register bit 1 value to determine state:
+	 *            SPEC       MASK
+	 * PASS     2 (10b)    2 (10b)
+	 * BLOCK    0 (00b)    2 (10b)
+	 *
+	 * item_data is NULL when template quota item is non-masked:
+	 * .. / quota / ..
+	 */
+
+	const struct rte_flow_item_quota *quota = item_data;
+	uint32_t val;
+
+	if (quota && quota->state == RTE_FLOW_QUOTA_STATE_BLOCK)
+		val = MLX5DR_DEFINER_QUOTA_BLOCK;
+	else
+		val = MLX5DR_DEFINER_QUOTA_PASS;
+
+	DR_SET(tag, val, fc->byte_off, fc->bit_off, fc->bit_mask);
+}
+
+static int
+mlx5dr_definer_conv_item_quota(struct mlx5dr_definer_conv_data *cd,
+			       __rte_unused struct rte_flow_item *item,
+			       int item_idx)
+{
+	int mtr_reg = flow_hw_get_reg_id(RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
+	struct mlx5dr_definer_fc *fc;
+
+	if (mtr_reg < 0) {
+		rte_errno = EINVAL;
+		return rte_errno;
+	}
+
+	fc = mlx5dr_definer_get_register_fc(cd, mtr_reg);
+	if (!fc)
+		return rte_errno;
+
+	fc->tag_set = &mlx5dr_definer_quota_set;
+	fc->item_idx = item_idx;
+	return 0;
+}
+
 static int
 mlx5dr_definer_conv_item_metadata(struct mlx5dr_definer_conv_data *cd,
 				  struct rte_flow_item *item,
@@ -2163,6 +2222,10 @@ mlx5dr_definer_conv_items_to_hl(struct mlx5dr_context *ctx,
 			ret = mlx5dr_definer_conv_item_meter_color(&cd, items, i);
 			item_flags |= MLX5_FLOW_ITEM_METER_COLOR;
 			break;
+		case RTE_FLOW_ITEM_TYPE_QUOTA:
+			ret = mlx5dr_definer_conv_item_quota(&cd, items, i);
+			item_flags |= MLX5_FLOW_ITEM_QUOTA;
+			break;
 		case RTE_FLOW_ITEM_TYPE_IPV6_ROUTING_EXT:
 			ret = mlx5dr_definer_conv_item_ipv6_routing_ext(&cd, items, i);
 			item_flags |= cd.tunnel ? MLX5_FLOW_ITEM_INNER_IPV6_ROUTING_EXT :
Signature · 1 line
2.34.1
#19 lore raw

RE: [PATCH v3 0/5] net/mlx5: support indirect quota flow action

In reply to Gregory Etelson

Hi,

Quoted 12 lines

-----Original Message-----
From: Gregory Etelson <[email protected]>
Sent: Sunday, May 7, 2023 10:40 AM
To: [email protected]
Cc: Gregory Etelson <[email protected]>; Maayan Kashani <[email protected]>; Raslan Darawsheh <[email protected]>
Subject: [PATCH v3 0/5] net/mlx5: support indirect quota flow action

1. Prepare MLX5 PMD for upcoming indirect quota action.
2. Support query_update API.
3. Support indirect quota action.

Quoted 8 lines

v3: prepare patches for dpdk-23.07

Gregory Etelson (5):
net/mlx5: update query fields in async job structure net/mlx5: remove code duplication common/mlx5: update MTR ASO definitions net/mlx5: add indirect QUOTA create/query/modify
mlx5dr: Definer, translate RTE quota item

Changed title for this commit

Quoted 15 lines
 doc/guides/nics/features/mlx5.ini      |   2 +
 doc/guides/nics/mlx5.rst               |  10 +
 doc/guides/rel_notes/release_23_07.rst |   4 +
 drivers/common/mlx5/mlx5_prm.h         |   4 +
 drivers/net/mlx5/hws/mlx5dr_definer.c  |  63 +++
 drivers/net/mlx5/meson.build           |   1 +
 drivers/net/mlx5/mlx5.h                |  88 ++-
 drivers/net/mlx5/mlx5_flow.c           |  62 +++
 drivers/net/mlx5/mlx5_flow.h           |  20 +-
 drivers/net/mlx5/mlx5_flow_aso.c       |  10 +-
 drivers/net/mlx5/mlx5_flow_hw.c        | 526 ++++++++++++------
 drivers/net/mlx5/mlx5_flow_quota.c     | 726
+++++++++++++++++++++++++
 12 files changed, 1335 insertions(+), 181 deletions(-)  create mode 100644
Quoted 4 lines

drivers/net/mlx5/mlx5_flow_quota.c

--
2.34.1

Series applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh