Skip to content

Commit

Permalink
net: dpaa: Adjust queue depth on rate change
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
sean-anderson-seco authored and davem330 committed Sep 5, 2022
1 parent 914f8b2 commit ef2a8d5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
38 changes: 34 additions & 4 deletions drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/freescale/fman/fman_dtsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/freescale/fman/fman_memac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions drivers/net/ethernet/freescale/fman/fman_tgec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions drivers/net/ethernet/freescale/fman/mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit ef2a8d5

Please sign in to comment.