stmmac multi-queue fixes and cleanups
Subsystems (4)
cover stmmac multi-queue fixes and cleanups
stmmac multi-queue fixes and cleanups
Niklas Cassel (7):
net: stmmac: set MSS for each tx DMA channel
net: stmmac: do not clear tx_skbuff entries in
stmmac_xmit()/stmmac_tso_xmit()
net: stmmac: WARN if tx_skbuff entries are reused before cleared
net: stmmac: rename dwmac4_tx_queue_routing() to match reality
net: stmmac: call correct function in
stmmac_mac_config_rx_queues_routing()
net: stmmac: add error handling in stmmac_mtl_setup()
net: stmmac: honor error code from stmmac_dt_phy()
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 6 ++-- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 23 +++++++-------- .../net/ethernet/stmicro/stmmac/stmmac_platform.c | 34 +++++++++++++++++----- 4 files changed, 42 insertions(+), 23 deletions(-)
Signature · 1 line
2.14.2
PATCH 1/7 net: stmmac: set MSS for each tx DMA channel
The DMA engine in dwmac4 can segment a large TSO packet to several smaller packets of (max) size Maximum Segment Size (MSS).
The DMA engine fetches and saves the MSS via a context descriptor.
This context decriptor has to be provided to each tx DMA channel. To ensure that this is done, move struct member mss from stmmac_priv to stmmac_tx_queue.
stmmac_reset_queues_param() now also resets mss, together with other queue parameters, so reset of mss value can be removed from stmmac_resume().
init_dma_tx_desc_rings() now also resets mss, together with other queue parameters, so reset of mss value can be removed from stmmac_open().
This fixes tx queue timeouts for dwmac4, with DT property snps,tx-queues-to-use > 1, when running iperf3 with multiple threads.
--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +1 -1
@@ -58,6 +58,7 @@ struct stmmac_tx_queue {unsigned int dirty_tx;dma_addr_t dma_tx_phy;u32 tx_tail_addr; +u32 mss; };struct stmmac_rx_queue {
@@ -138,7 +139,6 @@ struct stmmac_priv {spinlock_t ptp_lock;void __iomem *mmcaddr;void __iomem *ptpaddr; -u32 mss;#ifdef CONFIG_DEBUG_FS struct dentry *dbgfs_dir;
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +5 -8
@@ -1355,6 +1355,7 @@ static int init_dma_tx_desc_rings(struct net_device *dev) tx_q->dirty_tx =0 ; tx_q->cur_tx =0 ; + tx_q->mss =0 ;netdev_tx_reset_queue (netdev_get_tx_queue (priv->dev, queue)); }
@@ -1946,6 +1947,7 @@ static void stmmac_tx_err(struct stmmac_priv *priv, u32 chan) (i == DMA_TX_SIZE - 1)); tx_q->dirty_tx =0 ; tx_q->cur_tx =0 ; + tx_q->mss =0 ;netdev_tx_reset_queue (netdev_get_tx_queue (priv->dev, chan));stmmac_start_tx_dma (priv, chan);
@@ -2632,7 +2634,6 @@ static int stmmac_open(struct net_device *dev) priv->dma_buf_sz =STMMAC_ALIGN (buf_sz); priv->rx_copybreak =STMMAC_RX_COPYBREAK ; - priv->mss =0 ; ret =alloc_dma_desc_resources (priv);if (ret <0 ) {
@@ -2872,10 +2873,10 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) mss =skb_shinfo (skb)->gso_size;/* set new MSS value if needed */ -if (mss != priv->mss) { +if (mss != tx_q->mss) { mss_desc = tx_q->dma_tx + tx_q->cur_tx; priv->hw->desc->set_mss (mss_desc, mss); - priv->mss = mss; + tx_q->mss = mss; tx_q->cur_tx =STMMAC_GET_ENTRY (tx_q->cur_tx,DMA_TX_SIZE ); }
@@ -4436,6 +4437,7 @@ static void stmmac_reset_queues_param(struct stmmac_priv *priv) tx_q->cur_tx =0 ; tx_q->dirty_tx =0 ; + tx_q->mss =0 ; } }
@@ -4481,11 +4483,6 @@ int stmmac_resume(struct device *dev)stmmac_reset_queues_param (priv); -/* reset private mss value to force mss context settings at -* next tso xmit (only used for gmac4). -*/ - priv->mss =0 ; -stmmac_clear_descriptors (priv);stmmac_hw_setup (ndev, false);
Signature · 1 line
2.14.2
Re: [PATCH net-next 1/7] net: stmmac: set MSS for each tx DMA channel
Hi Niklas
I had a look at this series that looks ok for me.
Quoted 108 lines · Niklas Cassel
The DMA engine in dwmac4 can segment a large TSO packet to several smaller packets of (max) size Maximum Segment Size (MSS).
The DMA engine fetches and saves the MSS via a context descriptor.
This context decriptor has to be provided to each tx DMA channel. To ensure that this is done, move struct member mss from
stmmac_privtostmmac_tx_queue.
stmmac_reset_queues_param()now also resets mss, together with other queue parameters, so reset of mss value can be removed fromstmmac_resume().
init_dma_tx_desc_rings()now also resets mss, together with other queue parameters, so reset of mss value can be removed fromstmmac_open().This fixes tx queue timeouts for dwmac4, with DT property snps,tx-queues-to-use > 1, when running iperf3 with multiple threads.
Fixes ce736788e8a9 ("net: stmmac: adding multiple buffers for TX")Signed-off-by Niklas Cassel <[email protected]>--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-)drivers/net/ethernet/stmicro/stmmac/stmmac.h +1
-1@@ -58,6 +58,7 @@ struct stmmac_tx_queue {unsigned int dirty_tx;dma_addr_t dma_tx_phy;u32 tx_tail_addr; +u32 mss; };struct stmmac_rx_queue {@@ -138,7 +139,6 @@ struct stmmac_priv {spinlock_t ptp_lock;void __iomem *mmcaddr;void __iomem *ptpaddr; -u32 mss;#ifdef CONFIG_DEBUG_FS struct dentry *dbgfs_dir;drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +5
-8@@ -1355,6 +1355,7 @@ static int init_dma_tx_desc_rings(struct net_device *dev) tx_q->dirty_tx =0 ; tx_q->cur_tx =0 ; + tx_q->mss =0 ;netdev_tx_reset_queue (netdev_get_tx_queue (priv->dev, queue)); }@@ -1946,6 +1947,7 @@ static void stmmac_tx_err(struct stmmac_priv *priv, u32 chan) (i == DMA_TX_SIZE - 1)); tx_q->dirty_tx =0 ; tx_q->cur_tx =0 ; + tx_q->mss =0 ;netdev_tx_reset_queue (netdev_get_tx_queue (priv->dev, chan));stmmac_start_tx_dma (priv, chan);@@ -2632,7 +2634,6 @@ static int stmmac_open(struct net_device *dev) priv->dma_buf_sz =STMMAC_ALIGN (buf_sz); priv->rx_copybreak =STMMAC_RX_COPYBREAK ; - priv->mss =0 ; ret =alloc_dma_desc_resources (priv);if (ret <0 ) {@@ -2872,10 +2873,10 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) mss =skb_shinfo (skb)->gso_size;/* set new MSS value if needed */ -if (mss != priv->mss) { +if (mss != tx_q->mss) { mss_desc = tx_q->dma_tx + tx_q->cur_tx; priv->hw->desc->set_mss (mss_desc, mss); - priv->mss = mss; + tx_q->mss = mss; tx_q->cur_tx =STMMAC_GET_ENTRY (tx_q->cur_tx,DMA_TX_SIZE ); }@@ -4436,6 +4437,7 @@ static void stmmac_reset_queues_param(struct stmmac_priv *priv) tx_q->cur_tx =0 ; tx_q->dirty_tx =0 ; + tx_q->mss =0 ; } }@@ -4481,11 +4483,6 @@ int stmmac_resume(struct device *dev)stmmac_reset_queues_param (priv); -/* reset private mss value to force mss context settings at -* next tso xmit (only used for gmac4). -*/ - priv->mss =0 ; -stmmac_clear_descriptors (priv);stmmac_hw_setup (ndev, false);
PATCH 2/7 net: stmmac: do not clear tx_skbuff entries in stmmac_xmit()/stmmac_tso_xmit()
In reply to Niklas Casseltx_skbuff is initialized to NULL in init_dma_tx_desc_rings(), which is called from ndo_open().
stmmac_tx_clean() frees any non-NULL skb, and sets the tx_skbuff entry to NULL. Hence, there is no need to set skbuff entries to NULL in stmmac_xmit()/stmmac_tso_xmit(), and doing so falsely gives the reader the impression that it is needed.
Do not clear tx_skbuff entries in stmmac_xmit()/stmmac_tso_xmit().
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 --- 1 file changed, 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -3
@@ -2927,7 +2927,6 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) tx_q->tx_skbuff_dma[tx_q->cur_tx].buf = des; tx_q->tx_skbuff_dma[tx_q->cur_tx].len =skb_frag_size (frag); - tx_q->tx_skbuff[tx_q->cur_tx] =NULL ; tx_q->tx_skbuff_dma[tx_q->cur_tx].map_as_page = true; }
@@ -3102,8 +3101,6 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)if (dma_mapping_error (priv->device, des)) goto dma_map_err;/* should reuse desc w/o issues */ - tx_q->tx_skbuff[entry] =NULL ; - tx_q->tx_skbuff_dma[entry].buf = des;if (unlikely (priv->synopsys_id >=DWMAC_CORE_4_00 )) desc->des0 =cpu_to_le32 (des);
Signature · 1 line
2.14.2
PATCH 3/7 net: stmmac: WARN if tx_skbuff entries are reused before cleared
In reply to Niklas CasselThe current code assumes that a tx_skbuff entry has been cleared by stmmac_tx_clean() before stmmac_xmit()/stmmac_tso_xmit() assigns a new skb to that entry. However, since we never check the current value before overwriting it, it is theoretically possible that a non-NULL value is overwritten.
Add WARN_ONs to verify that each entry in tx_skbuff is NULL before it is assigned a new value.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +5 -0
@@ -2794,6 +2794,7 @@ static void stmmac_tso_allocator(struct stmmac_priv *priv, unsigned int des,while (tmp_len >0 ) { tx_q->cur_tx =STMMAC_GET_ENTRY (tx_q->cur_tx,DMA_TX_SIZE ); +WARN_ON (tx_q->tx_skbuff[tx_q->cur_tx]); desc = tx_q->dma_tx + tx_q->cur_tx; desc->des0 =cpu_to_le32 (des + (total_len - tmp_len));
@@ -2878,6 +2879,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) priv->hw->desc->set_mss (mss_desc, mss); tx_q->mss = mss; tx_q->cur_tx =STMMAC_GET_ENTRY (tx_q->cur_tx,DMA_TX_SIZE ); +WARN_ON (tx_q->tx_skbuff[tx_q->cur_tx]); }if (netif_msg_tx_queued (priv)) {
@@ -2888,6 +2890,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) } first_entry = tx_q->cur_tx; +WARN_ON (tx_q->tx_skbuff[first_entry]); desc = tx_q->dma_tx + first_entry; first = desc;
@@ -3062,6 +3065,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) entry = tx_q->cur_tx; first_entry = entry; +WARN_ON (tx_q->tx_skbuff[first_entry]); csum_insertion = (skb->ip_summed ==CHECKSUM_PARTIAL );
@@ -3090,6 +3094,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)bool last_segment = (i == (nfrags -1 )); entry =STMMAC_GET_ENTRY (entry,DMA_TX_SIZE ); +WARN_ON (tx_q->tx_skbuff[entry]);if (likely (priv->extend_desc)) desc = (struct dma_desc *)(tx_q->dma_etx + entry);
Signature · 1 line
2.14.2
PATCH 4/7 net: stmmac: rename dwmac4_tx_queue_routing() to match reality
In reply to Niklas CasselLooking at dwmac4_tx_queue_routing(), it is obvious that it sets up rx queue routing.
Rename dwmac4_tx_queue_routing() to dwmac4_rx_queue_routing() to better match reality.
--- drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +3 -3
@@ -120,7 +120,7 @@ static void dwmac4_tx_queue_priority(struct mac_device_info *hw,writel (value, ioaddr + base_register); } -static void dwmac4_tx_queue_routing (struct mac_device_info *hw, +static void dwmac4_rx_queue_routing (struct mac_device_info *hw,u8 packet,u32 queue) {void __iomem *ioaddr = hw->pcsr;
@@ -713,7 +713,7 @@ static const struct stmmac_ops dwmac4_ops = { .rx_queue_enable = dwmac4_rx_queue_enable, .rx_queue_prio = dwmac4_rx_queue_priority, .tx_queue_prio = dwmac4_tx_queue_priority, - .rx_queue_routing = dwmac4_tx_queue_routing, + .rx_queue_routing = dwmac4_rx_queue_routing, .prog_mtl_rx_algorithms = dwmac4_prog_mtl_rx_algorithms, .prog_mtl_tx_algorithms = dwmac4_prog_mtl_tx_algorithms, .set_mtl_tx_queue_weight = dwmac4_set_mtl_tx_queue_weight,
@@ -744,7 +744,7 @@ static const struct stmmac_ops dwmac410_ops = { .rx_queue_enable = dwmac4_rx_queue_enable, .rx_queue_prio = dwmac4_rx_queue_priority, .tx_queue_prio = dwmac4_tx_queue_priority, - .rx_queue_routing = dwmac4_tx_queue_routing, + .rx_queue_routing = dwmac4_rx_queue_routing, .prog_mtl_rx_algorithms = dwmac4_prog_mtl_rx_algorithms, .prog_mtl_tx_algorithms = dwmac4_prog_mtl_tx_algorithms, .set_mtl_tx_queue_weight = dwmac4_set_mtl_tx_queue_weight,
Signature · 1 line
2.14.2
PATCH 5/7 net: stmmac: call correct function in stmmac_mac_config_rx_queues_routing()
In reply to Niklas Casselstmmac_mac_config_rx_queues_routing() incorrectly calls rx_queue_prio() instead of rx_queue_routing().
This looks like a copy paste issue, since stmmac_mac_config_rx_queues_prio() already calls rx_queue_prio(), and both stmmac_mac_config_rx_queues_routing() and stmmac_mac_config_rx_queues_prio() are very similar in structure.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
@@ -2432,7 +2432,7 @@ static void stmmac_mac_config_rx_queues_routing(struct stmmac_priv *priv)continue ; packet = priv->plat->rx_queues_cfg[queue].pkt_route; - priv->hw->mac->rx_queue_prio (priv->hw, packet, queue); + priv->hw->mac->rx_queue_routing (priv->hw, packet, queue); } }
Signature · 1 line
2.14.2
PATCH 6/7 net: stmmac: add error handling in stmmac_mtl_setup()
In reply to Niklas CasselThe device tree binding for stmmac says:
- Multiple TX Queues parameters: below the list of all the parameters to configure the multiple TX queues:
- snps,tx-queues-to-use: number of TX queues to be used in the driver [...]
- For each TX queue
[...]
However, if one specifies snps,tx-queues-to-use = 2, but omits the queue subnodes, or defines just one queue subnode, since the driver appears to initialize queues with sane default values, we will get tx queue timeouts.
This is because the initialization code only initializes as many queues as it finds subnodes. Potentially leaving some queues uninitialized.
To avoid hard to debug issues, return an error if the number of subnodes differ from snps,tx-queues-to-use/snps,rx-queues-to-use.
--- .../net/ethernet/stmicro/stmmac/stmmac_platform.c | 29 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +24 -5
@@ -135,13 +135,14 @@ static struct stmmac_axi *stmmac_axi_setup(struct platform_device *pdev)* stmmac_mtl_setup - parse DT parameters for multiple queues configuration * @pdev: platform device */ -static void stmmac_mtl_setup (struct platform_device *pdev, -struct plat_stmmacenet_data *plat) +static int stmmac_mtl_setup (struct platform_device *pdev, +struct plat_stmmacenet_data *plat) {struct device_node *q_node;struct device_node *rx_node;struct device_node *tx_node;u8 queue =0 ; +int ret =0 ;/* For backwards-compatibility with device trees that don't have any * snps,mtl-rx-config or snps,mtl-tx-config properties, we fall back
@@ -159,12 +160,12 @@ static void stmmac_mtl_setup(struct platform_device *pdev, rx_node =of_parse_phandle (pdev->dev.of_node,"snps,mtl-rx-config" ,0 );if (!rx_node) -return ; +return ret; tx_node =of_parse_phandle (pdev->dev.of_node,"snps,mtl-tx-config" ,0 );if (!tx_node) {of_node_put (rx_node); -return ; +return ret; }/* Processing RX queues common config */
@@ -220,6 +221,11 @@ static void stmmac_mtl_setup(struct platform_device *pdev, queue++; } +if (queue != plat->rx_queues_to_use) { + ret = -EINVAL ; +dev_err (&pdev->dev,"Not all RX queues were configured\n" ); + goto out; + }/* Processing TX queues common config */ if (of_property_read_u32(tx_node, "snps,tx-queues-to-use",
@@ -281,10 +287,18 @@ static void stmmac_mtl_setup(struct platform_device *pdev, queue++; } +if (queue != plat->tx_queues_to_use) { + ret = -EINVAL ; +dev_err (&pdev->dev,"Not all TX queues were configured\n" ); + goto out; + } +out:of_node_put (rx_node);of_node_put (tx_node);of_node_put (q_node); + +return ret; }/**
@@ -376,6 +390,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)struct device_node *np = pdev->dev.of_node;struct plat_stmmacenet_data *plat;struct stmmac_dma_cfg *dma_cfg; +int rc; plat =devm_kzalloc (&pdev->dev,sizeof (*plat),GFP_KERNEL );if (!plat)
@@ -499,7 +514,11 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) plat->axi =stmmac_axi_setup (pdev); -stmmac_mtl_setup (pdev, plat); + rc =stmmac_mtl_setup (pdev, plat); +if (rc) { +stmmac_remove_config_dt (pdev, plat); +return ERR_PTR (rc); + }/* clock setup */ plat->stmmac_clk = devm_clk_get(&pdev->dev,
Signature · 1 line
2.14.2
PATCH 7/7 net: stmmac: honor error code from stmmac_dt_phy()
In reply to Niklas CasselHonor error code from stmmac_dt_phy() instead of always returning -ENODEV.
No functional change intended.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +3 -2
@@ -417,8 +417,9 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)dev_warn (&pdev->dev,"snps,phy-addr property is deprecated\n" );/* To Configure PHY by using all device-tree supported properties */ -if (stmmac_dt_phy (plat, np, &pdev->dev)) -return ERR_PTR (-ENODEV ); + rc =stmmac_dt_phy (plat, np, &pdev->dev); +if (rc) +return ERR_PTR (rc);of_property_read_u32 (np,"tx-fifo-depth" , &plat->tx_fifo_size);
Signature · 1 line
2.14.2
Hi Niklas,
Quoted 5 lines · Niklas Cassel
stmmac multi-queue fixes and cleanups
Niklas Cassel (7):
net: stmmac: set MSS for each tx DMA channel
net: stmmac: do not cleartx_skbuffentries in
Quoted 7 lines
stmmac_xmit()/stmmac_tso_xmit()net: stmmac: WARN if
tx_skbuffentries are reused before cleared
net: stmmac: renamedwmac4_tx_queue_routing()to match reality
net: stmmac: call correct function in
stmmac_mac_config_rx_queues_routing()
net: stmmac: add error handling instmmac_mtl_setup()
net: stmmac: honor error code fromstmmac_dt_phy()
Thanks! The whole series is:
Best Regards,
Jose Miguel Abreu
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 6 ++-- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 23 +++++++-------- .../net/ethernet/stmicro/stmmac/stmmac_platform.c | 34 +++++++++++++++++----- 4 files changed, 42 insertions(+), 23 deletions(-)
David Miller
maintainerFrom: Niklas Cassel <[email protected]>
Date: Mon, 19 Feb 2018 18:11:08 +0100
Quoted 1 line
stmmac multi-queue fixes and cleanups
Looks good to me, series applied, thanks Niklas.