]> git.itanic.dy.fi Git - linux-stable/commitdiff
net: dsa: sja1105: complete tc-cbs offload support on SJA1110
authorVladimir Oltean <vladimir.oltean@nxp.com>
Tue, 5 Sep 2023 21:53:38 +0000 (00:53 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 6 Sep 2023 05:23:05 +0000 (06:23 +0100)
The blamed commit left this delta behind:

  struct sja1105_cbs_entry {
 - u64 port;
 - u64 prio;
 + u64 port; /* Not used for SJA1110 */
 + u64 prio; /* Not used for SJA1110 */
   u64 credit_hi;
   u64 credit_lo;
   u64 send_slope;
   u64 idle_slope;
  };

but did not actually implement tc-cbs offload fully for the new switch.
The offload is accepted, but it doesn't work.

The difference compared to earlier switch generations is that now, the
table of CBS shapers is sparse, because there are many more shapers, so
the mapping between a {port, prio} and a table index is static, rather
than requiring us to store the port and prio into the sja1105_cbs_entry.

So, the problem is that the code programs the CBS shaper parameters at a
dynamic table index which is incorrect.

All that needs to be done for SJA1110 CBS shapers to work is to bypass
the logic which allocates shapers in a dense manner, as for SJA1105, and
use the fixed mapping instead.

Fixes: 3e77e59bf8cf ("net: dsa: sja1105: add support for the SJA1110 switch family")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/sja1105/sja1105.h
drivers/net/dsa/sja1105/sja1105_main.c
drivers/net/dsa/sja1105/sja1105_spi.c

index dee35ba924ad2f5fe97be4865be825393f42bc58..0617d5ccd3ff104b63bac4711a8686f2ad2179f2 100644 (file)
@@ -132,6 +132,8 @@ struct sja1105_info {
        int max_frame_mem;
        int num_ports;
        bool multiple_cascade_ports;
+       /* Every {port, TXQ} has its own CBS shaper */
+       bool fixed_cbs_mapping;
        enum dsa_tag_protocol tag_proto;
        const struct sja1105_dynamic_table_ops *dyn_ops;
        const struct sja1105_table_ops *static_ops;
index d7f57f22303198100ce7bad4678c2c1865fcde11..a23d980d28f5d190de5896ff79b106f529db566b 100644 (file)
@@ -2115,12 +2115,22 @@ static void sja1105_bridge_leave(struct dsa_switch *ds, int port,
 }
 
 #define BYTES_PER_KBIT (1000LL / 8)
+/* Port 0 (the uC port) does not have CBS shapers */
+#define SJA1110_FIXED_CBS(port, prio) ((((port) - 1) * SJA1105_NUM_TC) + (prio))
 
 static int sja1105_find_cbs_shaper(struct sja1105_private *priv,
                                   int port, int prio)
 {
        int i;
 
+       if (priv->info->fixed_cbs_mapping) {
+               i = SJA1110_FIXED_CBS(port, prio);
+               if (i >= 0 && i < priv->info->num_cbs_shapers)
+                       return i;
+
+               return -1;
+       }
+
        for (i = 0; i < priv->info->num_cbs_shapers; i++)
                if (priv->cbs[i].port == port && priv->cbs[i].prio == prio)
                        return i;
@@ -2132,6 +2142,9 @@ static int sja1105_find_unused_cbs_shaper(struct sja1105_private *priv)
 {
        int i;
 
+       if (priv->info->fixed_cbs_mapping)
+               return -1;
+
        for (i = 0; i < priv->info->num_cbs_shapers; i++)
                if (!priv->cbs[i].idle_slope && !priv->cbs[i].send_slope)
                        return i;
index 5ce29c8057a4181510abcb7397cc5ddc3a45d84c..834b5c1b4db0cbeb180d0c6118d589e4a5bba292 100644 (file)
@@ -781,6 +781,7 @@ const struct sja1105_info sja1110a_info = {
        .tag_proto              = DSA_TAG_PROTO_SJA1110,
        .can_limit_mcast_flood  = true,
        .multiple_cascade_ports = true,
+       .fixed_cbs_mapping      = true,
        .ptp_ts_bits            = 32,
        .ptpegr_ts_bytes        = 8,
        .max_frame_mem          = SJA1110_MAX_FRAME_MEMORY,
@@ -831,6 +832,7 @@ const struct sja1105_info sja1110b_info = {
        .tag_proto              = DSA_TAG_PROTO_SJA1110,
        .can_limit_mcast_flood  = true,
        .multiple_cascade_ports = true,
+       .fixed_cbs_mapping      = true,
        .ptp_ts_bits            = 32,
        .ptpegr_ts_bytes        = 8,
        .max_frame_mem          = SJA1110_MAX_FRAME_MEMORY,
@@ -881,6 +883,7 @@ const struct sja1105_info sja1110c_info = {
        .tag_proto              = DSA_TAG_PROTO_SJA1110,
        .can_limit_mcast_flood  = true,
        .multiple_cascade_ports = true,
+       .fixed_cbs_mapping      = true,
        .ptp_ts_bits            = 32,
        .ptpegr_ts_bytes        = 8,
        .max_frame_mem          = SJA1110_MAX_FRAME_MEMORY,
@@ -931,6 +934,7 @@ const struct sja1105_info sja1110d_info = {
        .tag_proto              = DSA_TAG_PROTO_SJA1110,
        .can_limit_mcast_flood  = true,
        .multiple_cascade_ports = true,
+       .fixed_cbs_mapping      = true,
        .ptp_ts_bits            = 32,
        .ptpegr_ts_bytes        = 8,
        .max_frame_mem          = SJA1110_MAX_FRAME_MEMORY,