From: Jun Yang <[email protected]>

Pick up the v2 version of the DPNI SET_RX_TC_POLICING MC command and
expose the new policer features it brings, while keeping support
for older MC firmwares that only speak the v1 command.

Signed-off-by: Jun Yang <[email protected]>
---
 drivers/net/dpaa2/mc/dpni.c     | 54 +++++++++++++++++++++------------
 drivers/net/dpaa2/mc/fsl_dpni.h | 23 +++++++++++---
 2 files changed, 53 insertions(+), 24 deletions(-)

diff --git a/drivers/net/dpaa2/mc/dpni.c b/drivers/net/dpaa2/mc/dpni.c
index 54df66416a..8e4114e604 100644
--- a/drivers/net/dpaa2/mc/dpni.c
+++ b/drivers/net/dpaa2/mc/dpni.c
@@ -2210,30 +2210,16 @@ int dpni_clear_fs_entries(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
-/**
- * dpni_set_rx_tc_policing() - Set Rx traffic class policing configuration
- * @mc_io:     Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token:     Token of DPNI object
- * @tc_id:     Traffic class selection (0-7)
- * @cfg:       Traffic class policing configuration
- *
- * Return:     '0' on Success; error code otherwise.
- */
-int dpni_set_rx_tc_policing(struct fsl_mc_io *mc_io,
-                           uint32_t cmd_flags,
-                           uint16_t token,
-                           uint8_t tc_id,
-                           const struct dpni_rx_tc_policing_cfg *cfg)
+static int
+_dpni_set_rx_tc_policing(struct fsl_mc_io *mc_io,
+       uint32_t cmd_flags, uint16_t token, uint8_t tc_id,
+       const struct dpni_rx_tc_policing_cfg *cfg, uint16_t cmd_id)
 {
        struct dpni_cmd_set_rx_tc_policing *cmd_params;
        struct mc_command cmd = { 0 };
 
-       /* prepare command */
-       cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_POLICING,
-                                         cmd_flags,
-                                         token);
-       cmd_params = (struct dpni_cmd_set_rx_tc_policing *)cmd.params;
+       cmd.header = mc_encode_cmd_header(cmd_id, cmd_flags, token);
+       cmd_params = (void *)cmd.params;
        dpni_set_field(cmd_params->mode_color, COLOR, cfg->default_color);
        dpni_set_field(cmd_params->mode_color, MODE, cfg->mode);
        dpni_set_field(cmd_params->units, UNITS, cfg->units);
@@ -2248,6 +2234,34 @@ int dpni_set_rx_tc_policing(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dpni_set_rx_tc_policing() - Set Rx traffic class policing configuration
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPNI object
+ * @tc_id:     Traffic class selection (0-7)
+ * @cfg:       Traffic class policing configuration
+ *
+ * Return:     '0' on Success; error code otherwise.
+ */
+int
+dpni_set_rx_tc_policing(struct fsl_mc_io *mc_io,
+       uint32_t cmd_flags, uint16_t token, uint8_t tc_id,
+       const struct dpni_rx_tc_policing_cfg *cfg)
+{
+       return _dpni_set_rx_tc_policing(mc_io, cmd_flags, token, tc_id, cfg,
+               DPNI_CMDID_SET_RX_TC_POLICING);
+}
+
+int
+dpni_set_rx_tc_policing_v1(struct fsl_mc_io *mc_io,
+       uint32_t cmd_flags, uint16_t token, uint8_t tc_id,
+       const struct dpni_rx_tc_policing_cfg *cfg)
+{
+       return _dpni_set_rx_tc_policing(mc_io, cmd_flags, token, tc_id, cfg,
+               DPNI_CMDID_SET_RX_TC_POLICING_V1);
+}
+
 /**
  * dpni_get_rx_tc_policing() - Get Rx traffic class policing configuration
  * @mc_io:     Pointer to MC portal's I/O object
diff --git a/drivers/net/dpaa2/mc/fsl_dpni.h b/drivers/net/dpaa2/mc/fsl_dpni.h
index 4bec348545..9e6dc23f66 100644
--- a/drivers/net/dpaa2/mc/fsl_dpni.h
+++ b/drivers/net/dpaa2/mc/fsl_dpni.h
@@ -1141,6 +1141,11 @@ int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
  */
 #define DPNI_POLICER_OPT_DISCARD_RED   0x00000002
 
+/**
+ * Do NOT reset counters generally for policer update
+ */
+#define DPNI_POLICER_OPT_DO_NOT_RESET_COUNTERS 0x00000004
+
 /**
  * enum dpni_policer_mode - selecting the policer mode
  * @DPNI_POLICER_MODE_NONE: Policer is disabled
@@ -1157,12 +1162,17 @@ enum dpni_policer_mode {
 
 /**
  * enum dpni_policer_unit - DPNI policer units
- * @DPNI_POLICER_UNIT_BYTES: bytes units
+ * @DPNI_POLICER_UNIT_BYTES_L3: bytes units (for each frame takes into account
+ * FD length - L3 offset)
  * @DPNI_POLICER_UNIT_FRAMES: frames units
+ * @DPNI_POLICER_UNIT_BYTES_L2_WITHOUT_FCS: bytes units (for each frame takes
+ * into account FD length - L2 offset, which means L2 size without the 4 bytes
+ * for the FCS)
  */
 enum dpni_policer_unit {
-       DPNI_POLICER_UNIT_BYTES = 0,
-       DPNI_POLICER_UNIT_FRAMES
+       DPNI_POLICER_UNIT_BYTES_L3 = 0,
+       DPNI_POLICER_UNIT_FRAMES,
+       DPNI_POLICER_UNIT_BYTES_L2_WITHOUT_FCS,
 };
 
 /**
@@ -1203,13 +1213,18 @@ struct dpni_rx_tc_policing_cfg {
        uint32_t ebs;
 };
 
-
 int dpni_set_rx_tc_policing(struct fsl_mc_io *mc_io,
                            uint32_t cmd_flags,
                            uint16_t token,
                            uint8_t tc_id,
                            const struct dpni_rx_tc_policing_cfg *cfg);
 
+int dpni_set_rx_tc_policing_v1(struct fsl_mc_io *mc_io,
+                           uint32_t cmd_flags,
+                           uint16_t token,
+                           uint8_t tc_id,
+                           const struct dpni_rx_tc_policing_cfg *cfg);
+
 int dpni_get_rx_tc_policing(struct fsl_mc_io *mc_io,
                            uint32_t cmd_flags,
                            uint16_t token,
-- 
2.43.0

Reply via email to