]> git.itanic.dy.fi Git - linux-stable/commitdiff
net: dpaa: Adjust queue depth on rate change
authorSean Anderson <sean.anderson@seco.com>
Fri, 2 Sep 2022 21:57:36 +0000 (17:57 -0400)
committerDavid S. Miller <davem@davemloft.net>
Mon, 5 Sep 2022 13:27:39 +0000 (14:27 +0100)
Instead of setting the queue depth once during probe, adjust it on the
fly whenever we configure the link. This is a bit unusal, since usually
the DPAA driver calls into the FMAN driver, but here we do the opposite.
We need to add a netdev to struct mac_device for this, but it will soon
live in the phylink config.

I haven't tested this extensively, but it doesn't seem to break
anything. We could possibly optimize this a bit by keeping track of the
last rate, but for now we just update every time. 10GEC probably doesn't
need to call into this at all, but I've added it for consistency.

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Acked-by: Camelia Groza <camelia.groza@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
drivers/net/ethernet/freescale/fman/fman_dtsec.c
drivers/net/ethernet/freescale/fman/fman_memac.c
drivers/net/ethernet/freescale/fman/fman_tgec.c
drivers/net/ethernet/freescale/fman/mac.h

index 7df3bf5a9c03f4aac4aca4a9ffed7a876cda8841..0a180d17121c55253e1e6a5ead4c7126bb78cd0c 100644 (file)
@@ -197,6 +197,8 @@ static int dpaa_rx_extra_headroom;
 #define dpaa_get_max_mtu()     \
        (dpaa_max_frm - (VLAN_ETH_HLEN + ETH_FCS_LEN))
 
+static void dpaa_eth_cgr_set_speed(struct mac_device *mac_dev, int speed);
+
 static int dpaa_netdev_init(struct net_device *net_dev,
                            const struct net_device_ops *dpaa_ops,
                            u16 tx_timeout)
@@ -262,6 +264,9 @@ static int dpaa_netdev_init(struct net_device *net_dev,
        net_dev->needed_headroom = priv->tx_headroom;
        net_dev->watchdog_timeo = msecs_to_jiffies(tx_timeout);
 
+       mac_dev->net_dev = net_dev;
+       mac_dev->update_speed = dpaa_eth_cgr_set_speed;
+
        /* start without the RUNNING flag, phylib controls it later */
        netif_carrier_off(net_dev);
 
@@ -826,10 +831,10 @@ static int dpaa_eth_cgr_init(struct dpaa_priv *priv)
        initcgr.we_mask = cpu_to_be16(QM_CGR_WE_CSCN_EN | QM_CGR_WE_CS_THRES);
        initcgr.cgr.cscn_en = QM_CGR_EN;
 
-       /* Set different thresholds based on the MAC speed.
-        * This may turn suboptimal if the MAC is reconfigured at a speed
-        * lower than its max, e.g. if a dTSEC later negotiates a 100Mbps link.
-        * In such cases, we ought to reconfigure the threshold, too.
+       /* Set different thresholds based on the configured MAC speed.
+        * This may turn suboptimal if the MAC is reconfigured at another
+        * speed, so MACs must call dpaa_eth_cgr_set_speed in their adjust_link
+        * callback.
         */
        if (priv->mac_dev->if_support & SUPPORTED_10000baseT_Full)
                cs_th = DPAA_CS_THRESHOLD_10G;
@@ -858,6 +863,31 @@ static int dpaa_eth_cgr_init(struct dpaa_priv *priv)
        return err;
 }
 
+static void dpaa_eth_cgr_set_speed(struct mac_device *mac_dev, int speed)
+{
+       struct net_device *net_dev = mac_dev->net_dev;
+       struct dpaa_priv *priv = netdev_priv(net_dev);
+       struct qm_mcc_initcgr opts = { };
+       u32 cs_th;
+       int err;
+
+       opts.we_mask = cpu_to_be16(QM_CGR_WE_CS_THRES);
+       switch (speed) {
+       case SPEED_10000:
+               cs_th = DPAA_CS_THRESHOLD_10G;
+               break;
+       case SPEED_1000:
+       default:
+               cs_th = DPAA_CS_THRESHOLD_1G;
+               break;
+       }
+       qm_cgr_cs_thres_set64(&opts.cgr.cs_thres, cs_th, 1);
+
+       err = qman_update_cgr_safe(&priv->cgr_data.cgr, &opts);
+       if (err)
+               netdev_err(net_dev, "could not update speed: %d\n", err);
+}
+
 static inline void dpaa_setup_ingress(const struct dpaa_priv *priv,
                                      struct dpaa_fq *fq,
                                      const struct qman_fq *template)
index f2dd07b714eace708a03955b22bf40fbcb7ef4eb..6617932fd3fdc4ba9623eb531449191f76bdfe7e 100644 (file)
@@ -1244,6 +1244,7 @@ static void adjust_link_dtsec(struct mac_device *mac_dev)
        }
 
        dtsec_adjust_link(fman_mac, phy_dev->speed);
+       mac_dev->update_speed(mac_dev, phy_dev->speed);
        fman_get_pause_cfg(mac_dev, &rx_pause, &tx_pause);
        err = fman_set_mac_active_pause(mac_dev, rx_pause, tx_pause);
        if (err < 0)
index fc79abd1f204fe0d58cce62db0a292e45f89f9cf..32d26cf178437d7a0b7e6577276cf0a62b54a5f4 100644 (file)
@@ -782,6 +782,7 @@ static void adjust_link_memac(struct mac_device *mac_dev)
 
        fman_mac = mac_dev->fman_mac;
        memac_adjust_link(fman_mac, phy_dev->speed);
+       mac_dev->update_speed(mac_dev, phy_dev->speed);
 
        fman_get_pause_cfg(mac_dev, &rx_pause, &tx_pause);
        err = fman_set_mac_active_pause(mac_dev, rx_pause, tx_pause);
index 1b60239d5fc76a041b85fe57f60251a0bbc278be..5a4be54ad459114efe0f3102c50b4c301d52d9d0 100644 (file)
@@ -601,8 +601,11 @@ static int tgec_del_hash_mac_address(struct fman_mac *tgec,
        return 0;
 }
 
-static void adjust_link_void(struct mac_device *mac_dev)
+static void tgec_adjust_link(struct mac_device *mac_dev)
 {
+       struct phy_device *phy_dev = mac_dev->phy_dev;
+
+       mac_dev->update_speed(mac_dev, phy_dev->speed);
 }
 
 static int tgec_set_exception(struct fman_mac *tgec,
@@ -795,7 +798,7 @@ int tgec_initialization(struct mac_device *mac_dev,
        mac_dev->set_allmulti           = tgec_set_allmulti;
        mac_dev->set_tstamp             = tgec_set_tstamp;
        mac_dev->set_multi              = fman_set_multi;
-       mac_dev->adjust_link            = adjust_link_void;
+       mac_dev->adjust_link            = tgec_adjust_link;
        mac_dev->enable                 = tgec_enable;
        mac_dev->disable                = tgec_disable;
 
index a55efcb7998c0cc0dff6c094374bb459f8eda384..b95d384271bd621919d4190853a08453c429cf79 100644 (file)
@@ -28,6 +28,7 @@ struct mac_device {
        struct phy_device       *phy_dev;
        phy_interface_t         phy_if;
        struct device_node      *phy_node;
+       struct net_device       *net_dev;
 
        bool autoneg_pause;
        bool rx_pause_req;
@@ -56,6 +57,8 @@ struct mac_device {
        int (*remove_hash_mac_addr)(struct fman_mac *mac_dev,
                                    enet_addr_t *eth_addr);
 
+       void (*update_speed)(struct mac_device *mac_dev, int speed);
+
        struct fman_mac         *fman_mac;
        struct mac_priv_s       *priv;
 };