[v4,33/34] common/sfc_efx/base: support conntrack assistance counters

Message ID 20230607130245.8048-34-ivan.malov@arknetworks.am (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series net/sfc: support HW conntrack assistance |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ivan Malov June 7, 2023, 1:02 p.m. UTC
  Counters that can be referenced by HW conntrack assistance
table work similar to those of the action rules. However,
their IDs belong to a separate (CT-specific) namespace.

These are 1-bit saturating counters with no byte count.

Signed-off-by: Ivan Malov <ivan.malov@arknetworks.am>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
---
 drivers/common/sfc_efx/base/efx.h      |  2 ++
 drivers/common/sfc_efx/base/efx_impl.h |  1 +
 drivers/common/sfc_efx/base/efx_mae.c  | 35 +++++++++++++++++++++++---
 3 files changed, 34 insertions(+), 4 deletions(-)
  

Patch

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index 5a2e05134a..df4ed82780 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4195,6 +4195,7 @@  typedef struct efx_mae_limits_s {
 		uint32_t		eml_max_n_counters;
 		uint32_t		eml_max_n_action_counters;
 	};
+	uint32_t			eml_max_n_conntrack_counters;
 } efx_mae_limits_t;
 
 LIBEFX_API
@@ -4789,6 +4790,7 @@  efx_mae_action_set_fill_in_eh_id(
  */
 typedef enum efx_counter_type_e {
 	EFX_COUNTER_TYPE_ACTION = 0,
+	EFX_COUNTER_TYPE_CONNTRACK,
 } efx_counter_type_t;
 
 typedef struct efx_counter_s {
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index f6b472c160..a0dde1b1b4 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -842,6 +842,7 @@  typedef struct efx_mae_s {
 	efx_mae_field_cap_t		*em_outer_rule_field_caps;
 	size_t				em_outer_rule_field_caps_size;
 	uint32_t			em_max_n_action_counters;
+	uint32_t			em_max_n_conntrack_counters;
 } efx_mae_t;
 
 #endif /* EFSYS_OPT_MAE */
diff --git a/drivers/common/sfc_efx/base/efx_mae.c b/drivers/common/sfc_efx/base/efx_mae.c
index 4078146741..6457f39ccf 100644
--- a/drivers/common/sfc_efx/base/efx_mae.c
+++ b/drivers/common/sfc_efx/base/efx_mae.c
@@ -16,7 +16,7 @@  efx_mae_get_capabilities(
 	efx_mcdi_req_t req;
 	EFX_MCDI_DECLARE_BUF(payload,
 	    MC_CMD_MAE_GET_CAPS_IN_LEN,
-	    MC_CMD_MAE_GET_CAPS_OUT_LEN);
+	    MC_CMD_MAE_GET_CAPS_V2_OUT_LEN);
 	struct efx_mae_s *maep = enp->en_maep;
 	efx_rc_t rc;
 
@@ -24,7 +24,7 @@  efx_mae_get_capabilities(
 	req.emr_in_buf = payload;
 	req.emr_in_length = MC_CMD_MAE_GET_CAPS_IN_LEN;
 	req.emr_out_buf = payload;
-	req.emr_out_length = MC_CMD_MAE_GET_CAPS_OUT_LEN;
+	req.emr_out_length = MC_CMD_MAE_GET_CAPS_V2_OUT_LEN;
 
 	efx_mcdi_execute(enp, &req);
 
@@ -70,6 +70,13 @@  efx_mae_get_capabilities(
 	maep->em_max_n_action_counters =
 	    MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_AR_COUNTERS);
 
+	if (req.emr_out_length_used >= MC_CMD_MAE_GET_CAPS_V2_OUT_LEN) {
+		maep->em_max_n_conntrack_counters =
+		    MCDI_OUT_DWORD(req, MAE_GET_CAPS_V2_OUT_CT_COUNTERS);
+	} else {
+		maep->em_max_n_conntrack_counters = 0;
+	}
+
 	return (0);
 
 fail2:
@@ -375,6 +382,7 @@  efx_mae_get_limits(
 	emlp->eml_encap_header_size_limit =
 	    MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_MAXNUM_MCDI2;
 	emlp->eml_max_n_action_counters = maep->em_max_n_action_counters;
+	emlp->eml_max_n_conntrack_counters = maep->em_max_n_conntrack_counters;
 
 	return (0);
 
@@ -3275,11 +3283,15 @@  efx_mae_counters_alloc_type(
 	efx_rc_t rc;
 
 	EFX_STATIC_ASSERT(EFX_COUNTER_TYPE_ACTION == MAE_COUNTER_TYPE_AR);
+	EFX_STATIC_ASSERT(EFX_COUNTER_TYPE_CONNTRACK == MAE_COUNTER_TYPE_CT);
 
 	switch (type) {
 	case EFX_COUNTER_TYPE_ACTION:
 		max_n_counters = maep->em_max_n_action_counters;
 		break;
+	case EFX_COUNTER_TYPE_CONNTRACK:
+		max_n_counters = maep->em_max_n_conntrack_counters;
+		break;
 	default:
 		rc = EINVAL;
 		goto fail1;
@@ -3396,6 +3408,9 @@  efx_mae_counters_free_type(
 	case EFX_COUNTER_TYPE_ACTION:
 		max_n_counters = maep->em_max_n_action_counters;
 		break;
+	case EFX_COUNTER_TYPE_CONNTRACK:
+		max_n_counters = maep->em_max_n_conntrack_counters;
+		break;
 	default:
 		rc = EINVAL;
 		goto fail1;
@@ -3498,8 +3513,11 @@  efx_mae_counters_stream_start(
 	__out				uint32_t *flags_out)
 {
 	efx_mcdi_req_t req;
-	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_MAE_COUNTERS_STREAM_START_IN_LEN,
+	EFX_MCDI_DECLARE_BUF(payload,
+			     MC_CMD_MAE_COUNTERS_STREAM_START_V2_IN_LEN,
 			     MC_CMD_MAE_COUNTERS_STREAM_START_OUT_LEN);
+	struct efx_mae_s *maep = enp->en_maep;
+	uint32_t counter_types;
 	efx_rc_t rc;
 
 	EFX_STATIC_ASSERT(EFX_MAE_COUNTERS_STREAM_IN_ZERO_SQUASH_DISABLE ==
@@ -3510,7 +3528,7 @@  efx_mae_counters_stream_start(
 
 	req.emr_cmd = MC_CMD_MAE_COUNTERS_STREAM_START;
 	req.emr_in_buf = payload;
-	req.emr_in_length = MC_CMD_MAE_COUNTERS_STREAM_START_IN_LEN;
+	req.emr_in_length = MC_CMD_MAE_COUNTERS_STREAM_START_V2_IN_LEN;
 	req.emr_out_buf = payload;
 	req.emr_out_length = MC_CMD_MAE_COUNTERS_STREAM_START_OUT_LEN;
 
@@ -3519,6 +3537,15 @@  efx_mae_counters_stream_start(
 			 packet_size);
 	MCDI_IN_SET_DWORD(req, MAE_COUNTERS_STREAM_START_IN_FLAGS, flags_in);
 
+	counter_types = (1U << MAE_COUNTER_TYPE_AR);
+
+	if (maep->em_max_n_conntrack_counters != 0)
+		counter_types |= (1U << MAE_COUNTER_TYPE_CT);
+
+	MCDI_IN_SET_DWORD(req,
+			  MAE_COUNTERS_STREAM_START_V2_IN_COUNTER_TYPES_MASK,
+			  counter_types);
+
 	efx_mcdi_execute(enp, &req);
 
 	if (req.emr_rc != 0) {