]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
net: dsa: sja1105: implement a common frame memory partitioning function
authorVladimir Oltean <vladimir.oltean@nxp.com>
Tue, 12 May 2020 17:20:37 +0000 (20:20 +0300)
committerDavid S. Miller <davem@davemloft.net>
Tue, 12 May 2020 20:08:08 +0000 (13:08 -0700)
There are 2 different features that require some reserved frame memory
space: VLAN retagging and virtual links. Create a central function that
modifies the static config and ensures frame memory is never
overcommitted.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.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_static_config.h
drivers/net/dsa/sja1105/sja1105_vl.c

index 1ecdfd6be4c204cf6878afba3f9c9f516aa00499..198d2a7d7f9582700e6e3a987a8d07411f44e1da 100644 (file)
@@ -244,6 +244,8 @@ enum sja1105_reset_reason {
 int sja1105_static_config_reload(struct sja1105_private *priv,
                                 enum sja1105_reset_reason reason);
 
+void sja1105_frame_memory_partitioning(struct sja1105_private *priv);
+
 /* From sja1105_spi.c */
 int sja1105_xfer_buf(const struct sja1105_private *priv,
                     sja1105_spi_rw_mode_t rw, u64 reg_addr,
index 775a6766288eb484bcbc213056ed8547cc16cc10..77462219261e0b5e68b06af9c960bc94473a618b 100644 (file)
@@ -432,6 +432,41 @@ static int sja1105_init_l2_forwarding_params(struct sja1105_private *priv)
        return 0;
 }
 
+void sja1105_frame_memory_partitioning(struct sja1105_private *priv)
+{
+       struct sja1105_l2_forwarding_params_entry *l2_fwd_params;
+       struct sja1105_vl_forwarding_params_entry *vl_fwd_params;
+       struct sja1105_table *table;
+       int max_mem;
+
+       /* VLAN retagging is implemented using a loopback port that consumes
+        * frame buffers. That leaves less for us.
+        */
+       if (priv->vlan_state == SJA1105_VLAN_BEST_EFFORT)
+               max_mem = SJA1105_MAX_FRAME_MEMORY_RETAGGING;
+       else
+               max_mem = SJA1105_MAX_FRAME_MEMORY;
+
+       table = &priv->static_config.tables[BLK_IDX_L2_FORWARDING_PARAMS];
+       l2_fwd_params = table->entries;
+       l2_fwd_params->part_spc[0] = max_mem;
+
+       /* If we have any critical-traffic virtual links, we need to reserve
+        * some frame buffer memory for them. At the moment, hardcode the value
+        * at 100 blocks of 128 bytes of memory each. This leaves 829 blocks
+        * remaining for best-effort traffic. TODO: figure out a more flexible
+        * way to perform the frame buffer partitioning.
+        */
+       if (!priv->static_config.tables[BLK_IDX_VL_FORWARDING].entry_count)
+               return;
+
+       table = &priv->static_config.tables[BLK_IDX_VL_FORWARDING_PARAMS];
+       vl_fwd_params = table->entries;
+
+       l2_fwd_params->part_spc[0] -= SJA1105_VL_FRAME_MEMORY;
+       vl_fwd_params->partspc[0] = SJA1105_VL_FRAME_MEMORY;
+}
+
 static int sja1105_init_general_params(struct sja1105_private *priv)
 {
        struct sja1105_general_params_entry default_general_params = {
@@ -2213,6 +2248,8 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)
        l2_lookup_params = table->entries;
        l2_lookup_params->shared_learn = want_tagging;
 
+       sja1105_frame_memory_partitioning(priv);
+
        rc = sja1105_static_config_reload(priv, SJA1105_VLAN_FILTERING);
        if (rc)
                dev_err(ds->dev, "Failed to change VLAN Ethertype\n");
index d96044d86b11fec692a4c0ab9cbe73bc96e009ae..5946847bb5b919a4bc9c9ab4bd2f0152c1b12b06 100644 (file)
@@ -108,6 +108,7 @@ enum sja1105_blk_idx {
 
 #define SJA1105_MAX_FRAME_MEMORY                       929
 #define SJA1105_MAX_FRAME_MEMORY_RETAGGING             910
+#define SJA1105_VL_FRAME_MEMORY                                100
 
 #define SJA1105E_DEVICE_ID                             0x9C00000Cull
 #define SJA1105T_DEVICE_ID                             0x9E00030Eull
index 312401995b54a9a97efa6fd0376487c5f6cf0ce7..f37611885376e8d7f8c20f73dca9bcc626f7d93d 100644 (file)
@@ -5,7 +5,6 @@
 #include <linux/dsa/8021q.h>
 #include "sja1105.h"
 
-#define SJA1105_VL_FRAME_MEMORY                        100
 #define SJA1105_SIZE_VL_STATUS                 8
 
 /* The switch flow classification core implements TTEthernet, which 'thinks' in
@@ -141,8 +140,6 @@ static bool sja1105_vl_key_lower(struct sja1105_vl_lookup_entry *a,
 static int sja1105_init_virtual_links(struct sja1105_private *priv,
                                      struct netlink_ext_ack *extack)
 {
-       struct sja1105_l2_forwarding_params_entry *l2_fwd_params;
-       struct sja1105_vl_forwarding_params_entry *vl_fwd_params;
        struct sja1105_vl_policing_entry *vl_policing;
        struct sja1105_vl_forwarding_entry *vl_fwd;
        struct sja1105_vl_lookup_entry *vl_lookup;
@@ -153,10 +150,6 @@ static int sja1105_init_virtual_links(struct sja1105_private *priv,
        int max_sharindx = 0;
        int i, j, k;
 
-       table = &priv->static_config.tables[BLK_IDX_L2_FORWARDING_PARAMS];
-       l2_fwd_params = table->entries;
-       l2_fwd_params->part_spc[0] = SJA1105_MAX_FRAME_MEMORY;
-
        /* Figure out the dimensioning of the problem */
        list_for_each_entry(rule, &priv->flow_block.rules, list) {
                if (rule->type != SJA1105_RULE_VL)
@@ -308,17 +301,6 @@ static int sja1105_init_virtual_links(struct sja1105_private *priv,
        if (!table->entries)
                return -ENOMEM;
        table->entry_count = 1;
-       vl_fwd_params = table->entries;
-
-       /* Reserve some frame buffer memory for the critical-traffic virtual
-        * links (this needs to be done). At the moment, hardcode the value
-        * at 100 blocks of 128 bytes of memory each. This leaves 829 blocks
-        * remaining for best-effort traffic. TODO: figure out a more flexible
-        * way to perform the frame buffer partitioning.
-        */
-       l2_fwd_params->part_spc[0] = SJA1105_MAX_FRAME_MEMORY -
-                                    SJA1105_VL_FRAME_MEMORY;
-       vl_fwd_params->partspc[0] = SJA1105_VL_FRAME_MEMORY;
 
        for (i = 0; i < num_virtual_links; i++) {
                unsigned long cookie = vl_lookup[i].flow_cookie;
@@ -342,6 +324,8 @@ static int sja1105_init_virtual_links(struct sja1105_private *priv,
                }
        }
 
+       sja1105_frame_memory_partitioning(priv);
+
        return 0;
 }