net: stmmac: Add support to Ethtool get/set ring parameters
Subsystems (4)
PATCH 1/1 net: stmmac: Add support to Ethtool get/set ring parameters
From: "Song, Yoong Siang" <[email protected]>
This patch add support to --show-ring & --set-ring Ethtool functions:
- Adding min, max, power of two check to new ring parameter's value.
- Bring down the network interface before changing the value of ring parameters.
- Bring up the network interface after changing the value of ring parameters.
--- .../net/ethernet/stmicro/stmmac/chain_mode.c | 7 +- drivers/net/ethernet/stmicro/stmmac/common.h | 13 +- .../net/ethernet/stmicro/stmmac/ring_mode.c | 2 +- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 3 + .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 29 ++++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 135 +++++++++++------- .../stmicro/stmmac/stmmac_selftests.c | 2 +- 7 files changed, 132 insertions(+), 59 deletions(-)
drivers/net/ethernet/stmicro/stmmac/chain_mode.c +4 -3
@@ -46,7 +46,7 @@ static int jumbo_frm(void *p, struct sk_buff *skb, int csum)while (len !=0 ) { tx_q->tx_skbuff[entry] =NULL ; - entry =STMMAC_GET_ENTRY (entry,DMA_TX_SIZE ); + entry =STMMAC_GET_ENTRY (entry, priv->dma_tx_size); desc = tx_q->dma_tx + entry;if (len > bmax) {
@@ -137,7 +137,7 @@ static void refill_desc3(void *priv_ptr, struct dma_desc *p)*/ p->des3 =cpu_to_le32 ((unsigned int )(rx_q->dma_rx_phy + (((rx_q->dirty_rx) +1 ) % -DMA_RX_SIZE ) * + priv->dma_rx_size) *sizeof (struct dma_desc ))); }
@@ -154,7 +154,8 @@ static void clean_desc3(void *priv_ptr, struct dma_desc *p)* to keep explicit chaining in the descriptor. */ p->des3 =cpu_to_le32 ((unsigned int )((tx_q->dma_tx_phy + - ((tx_q->dirty_tx +1 ) %DMA_TX_SIZE )) + ((tx_q->dirty_tx +1 ) % + priv->dma_tx_size)) *sizeof (struct dma_desc ))); }
drivers/net/ethernet/stmicro/stmmac/common.h +10 -3
@@ -42,9 +42,16 @@#define STMMAC_CHAN0 0/* Always supported and default for all chips */ -/* These need to be power of two, and >= 4 */ -#define DMA_TX_SIZE 512 -#define DMA_RX_SIZE 512 +/* TX and RX Descriptor Length, these need to be power of two. +* TX descriptor length less than 64 may cause transmit queue timed out error. +* RX descriptor length less than 64 may cause inconsistent Rx chain error. +*/ +#define DMA_MIN_TX_SIZE 64 +#define DMA_MAX_TX_SIZE 1024 +#define DMA_DEFAULT_TX_SIZE 512 +#define DMA_MIN_RX_SIZE 64 +#define DMA_MAX_RX_SIZE 1024 +#define DMA_DEFAULT_RX_SIZE 512#define STMMAC_GET_ENTRY (x, size) ((x + 1) & (size - 1))#undef FRAME_FILTER_DEBUG
drivers/net/ethernet/stmicro/stmmac/ring_mode.c +1 -1
@@ -51,7 +51,7 @@ static int jumbo_frm(void *p, struct sk_buff *skb, int csum)stmmac_prepare_tx_desc (priv, desc,1 , bmax, csum,STMMAC_RING_MODE ,0 , false, skb->len); tx_q->tx_skbuff[entry] =NULL ; - entry =STMMAC_GET_ENTRY (entry,DMA_TX_SIZE ); + entry =STMMAC_GET_ENTRY (entry, priv->dma_tx_size);if (priv->extend_desc) desc = (struct dma_desc *)(tx_q->dma_etx + entry);
drivers/net/ethernet/stmicro/stmmac/stmmac.h +3 -0
@@ -171,9 +171,11 @@ struct stmmac_priv {/* RX Queue */ struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES ]; +unsigned int dma_rx_size;/* TX Queue */ struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES ]; +unsigned int dma_tx_size;/* Generic channel for NAPI */ struct stmmac_channel channel[STMMAC_CH_MAX ];
@@ -265,6 +267,7 @@ int stmmac_dvr_probe(struct device *device,void stmmac_disable_eee_mode (struct stmmac_priv *priv);bool stmmac_eee_init (struct stmmac_priv *priv);int stmmac_reinit_queues (struct net_device *dev,u32 rx_cnt,u32 tx_cnt); +int stmmac_reinit_ringparam (struct net_device *dev,u32 rx_size,u32 tx_size);#if IS_ENABLED (CONFIG_STMMAC_SELFTESTS ) void stmmac_selftest_run(struct net_device *dev,
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +29 -0
@@ -440,6 +440,33 @@ static int stmmac_nway_reset(struct net_device *dev)return phylink_ethtool_nway_reset (priv->phylink); } +static void stmmac_get_ringparam (struct net_device *netdev, +struct ethtool_ringparam *ring) +{ +struct stmmac_priv *priv =netdev_priv (netdev); + + ring->rx_max_pending =DMA_MAX_RX_SIZE ; + ring->tx_max_pending =DMA_MAX_TX_SIZE ; + ring->rx_pending = priv->dma_rx_size; + ring->tx_pending = priv->dma_tx_size; +} + +static int stmmac_set_ringparam (struct net_device *netdev, +struct ethtool_ringparam *ring) +{ +if (ring->rx_mini_pending || ring->rx_jumbo_pending || + ring->rx_pending <DMA_MIN_RX_SIZE || + ring->rx_pending >DMA_MAX_RX_SIZE || + !is_power_of_2 (ring->rx_pending) || + ring->tx_pending <DMA_MIN_TX_SIZE || + ring->tx_pending >DMA_MAX_TX_SIZE || + !is_power_of_2 (ring->tx_pending)) +return -EINVAL ; + +return stmmac_reinit_ringparam (netdev, ring->rx_pending, + ring->tx_pending); +} +static void stmmac_get_pauseparam (struct net_device *netdev,struct ethtool_pauseparam *pause)
@@ -947,6 +974,8 @@ static const struct ethtool_ops stmmac_ethtool_ops = { .get_regs_len = stmmac_ethtool_get_regs_len, .get_link = ethtool_op_get_link, .nway_reset = stmmac_nway_reset, + .get_ringparam = stmmac_get_ringparam, + .set_ringparam = stmmac_set_ringparam, .get_pauseparam = stmmac_get_pauseparam, .set_pauseparam = stmmac_set_pauseparam, .self_test = stmmac_selftest_run,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +84 -51
404 lines not on this page · raw message
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +1 -1
@@ -796,7 +796,7 @@ static int stmmac_test_flowctrl(struct stmmac_priv *priv)u32 tail; tail = priv->rx_queue[i].dma_rx_phy + - (DMA_RX_SIZE *sizeof (struct dma_desc )); + (priv->dma_rx_size *sizeof (struct dma_desc ));stmmac_set_rx_tail_ptr (priv, priv->ioaddr, tail, i);stmmac_start_rx (priv, priv->ioaddr, i);
Signature · 7 lines
2.17.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
David Miller
maintainerFrom: Wong Vee Khee <[email protected]>
Date: Wed, 16 Sep 2020 15:40:20 +0800
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7
-0+int stmmac_reinit_ringparam (struct net_device *dev,u32 rx_size,u32 tx_size) +{ +struct stmmac_priv *priv =netdev_priv (dev); +int ret =0 ; + +if (netif_running (dev)) +stmmac_release (dev);
...
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt) · line 4810
Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-0+if (netif_running (dev)) + ret =stmmac_open (dev); +
I've applied this patch but this approach is so fragile, but everyone does it initially because it is so easy.
The problem here is that for so many reasons the stmmac_open() can fail, and instead of just the ringparam() operation failing, the interface becomes down and unusable.
Can you please eventually implement this properly? Allocate the new ring resources, and only commit the new configuration if it is guaranteed to succeed. Otherwise, backout the ringparam change and keep the old configuration.
This way the device stays up regardless of whether the resources (memory, DMA mappings, etc.) can be allocated fully.
Right now, if you do a ringparam under hard memory pressure, this will take the inteface down as stmmac_open() fails.