mtk_eth_soc: fixes and performance improvements
Subsystems (4)
v2 cover mtk_eth_soc: fixes and performance improvements
Most of these changes come from OpenWrt where they have been present and tested for months.
First three patches are bug fixes. The rest are performance improvements. The last patch is a cleanup to use the iopoll.h macro for busy-waiting instead of a custom loop.
v2:
- Reverse christmas tree in "use iopoll.h macro for DMA init"
- Use cond_resched() instead of iopoll.h macro in "reduce MDIO bus access latency"
- Use napi_complete_done and rework NAPI callbacks in a new patch
Felix Fietkau (12):
net: ethernet: mtk_eth_soc: fix RX VLAN offload
net: ethernet: mtk_eth_soc: unmap RX data before calling build_skb
net: ethernet: mtk_eth_soc: use napi_consume_skb
net: ethernet: mtk_eth_soc: reduce MDIO bus access latency
net: ethernet: mtk_eth_soc: remove unnecessary TX queue stops
net: ethernet: mtk_eth_soc: use larger burst size for QDMA TX
net: ethernet: mtk_eth_soc: increase DMA ring sizes
net: ethernet: mtk_eth_soc: implement dynamic interrupt moderation
net: ethernet: mtk_eth_soc: cache HW pointer of last freed TX
descriptor
net: ethernet: mtk_eth_soc: only read the full RX descriptor if DMA is
done
net: ethernet: mtk_eth_soc: reduce unnecessary interrupts
net: ethernet: mtk_eth_soc: set PPE flow hash as skb hash if present
Ilya Lipnitskiy (3):
net: ethernet: mtk_eth_soc: fix build_skb cleanup
net: ethernet: mtk_eth_soc: rework NAPI callbacks
net: ethernet: mtk_eth_soc: use iopoll.h macro for DMA init
drivers/net/ethernet/mediatek/Kconfig | 1 + drivers/net/ethernet/mediatek/mtk_eth_soc.c | 262 +++++++++++++------- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 50 +++- 3 files changed, 213 insertions(+), 100 deletions(-)
Signature · 1 line
2.31.1
PATCH v2 1/15 net: ethernet: mtk_eth_soc: fix RX VLAN offload
From: Felix Fietkau <[email protected]>
The VLAN ID in the rx descriptor is only valid if the RX_DMA_VTAG bit is set. Fixes frames wrongly marked with VLAN tags.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +1 -1
@@ -1319,7 +1319,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, skb->protocol =eth_type_trans (skb, netdev);if (netdev->features &NETIF_F_HW_VLAN_CTAG_RX && -RX_DMA_VID (trxd.rxd3)) + (trxd.rxd2 &RX_DMA_VTAG ))__vlan_hwaccel_put_tag (skb,htons (ETH_P_8021Q ),RX_DMA_VID (trxd.rxd3));skb_record_rx_queue (skb,0 );
drivers/net/ethernet/mediatek/mtk_eth_soc.h +1 -0
@@ -301,6 +301,7 @@#define RX_DMA_LSO BIT(30)#define RX_DMA_PLEN0 (_x) (((_x) & 0x3fff) << 16)#define RX_DMA_GET_PLEN0 (_x) (((_x) >> 16) & 0x3fff) +#define RX_DMA_VTAG BIT(15)/* QDMA descriptor rxd3 */ #define RX_DMA_VID (_x) ((_x) & 0xfff)
Signature · 1 line
2.31.1
PATCH v2 2/15 net: ethernet: mtk_eth_soc: unmap RX data before calling build_skb
In reply to Ilya LipnitskiyFrom: Felix Fietkau <[email protected]>
Since build_skb accesses the data area (for initializing shinfo), dma unmap needs to happen before that call
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +3 -2
@@ -1298,6 +1298,9 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, goto release_desc; } +dma_unmap_single (eth->dev, trxd.rxd1, + ring->buf_size,DMA_FROM_DEVICE ); +/* receive data */ skb =build_skb (data, ring->frag_size);if (unlikely (!skb)) {
@@ -1307,8 +1310,6 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, }skb_reserve (skb,NET_SKB_PAD +NET_IP_ALIGN ); -dma_unmap_single (eth->dev, trxd.rxd1, - ring->buf_size,DMA_FROM_DEVICE ); pktlen =RX_DMA_GET_PLEN0 (trxd.rxd2); skb->dev = netdev;skb_put (skb, pktlen);
Signature · 1 line
2.31.1
PATCH v2 3/15 net: ethernet: mtk_eth_soc: fix build_skb cleanup
In reply to Ilya LipnitskiyIn case build_skb fails, call skb_free_frag on the correct pointer. Also update the DMA structures with the new mapping before exiting, because the mapping was successful
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +3 -2
@@ -1304,9 +1304,9 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,/* receive data */ skb =build_skb (data, ring->frag_size);if (unlikely (!skb)) { -skb_free_frag (new_data); +skb_free_frag (data); netdev->stats.rx_dropped++; - goto release_desc; + goto skip_rx; }skb_reserve (skb,NET_SKB_PAD +NET_IP_ALIGN );
@@ -1326,6 +1326,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,skb_record_rx_queue (skb,0 );napi_gro_receive (napi, skb); +skip_rx: ring->data[idx] = new_data; rxd->rxd1 = (unsigned int )dma_addr;
Signature · 1 line
2.31.1
PATCH v2 4/15 net: ethernet: mtk_eth_soc: use napi_consume_skb
In reply to Ilya LipnitskiyFrom: Felix Fietkau <[email protected]>
Should improve performance, since it can use bulk free
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +12 -7
@@ -858,7 +858,8 @@ static int txd_to_idx(struct mtk_tx_ring *ring, struct mtk_tx_dma *dma)return ((void *)dma - (void *)ring->dma) /sizeof (*dma); } -static void mtk_tx_unmap (struct mtk_eth *eth,struct mtk_tx_buf *tx_buf) +static void mtk_tx_unmap (struct mtk_eth *eth,struct mtk_tx_buf *tx_buf, +bool napi) {if (MTK_HAS_CAPS (eth->soc->caps,MTK_QDMA )) {if (tx_buf->flags &MTK_TX_FLAGS_SINGLE0 ) {
@@ -890,8 +891,12 @@ static void mtk_tx_unmap(struct mtk_eth *eth, struct mtk_tx_buf *tx_buf) tx_buf->flags =0 ;if (tx_buf->skb && - (tx_buf->skb != (struct sk_buff *)MTK_DMA_DUMMY_DESC )) -dev_kfree_skb_any (tx_buf->skb); + (tx_buf->skb != (struct sk_buff *)MTK_DMA_DUMMY_DESC )) { +if (napi) +napi_consume_skb (tx_buf->skb, napi); +else +dev_kfree_skb_any (tx_buf->skb); + } tx_buf->skb =NULL ; }
@@ -1069,7 +1074,7 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev, tx_buf =mtk_desc_to_tx_buf (ring, itxd);/* unmap dma */ -mtk_tx_unmap (eth, tx_buf); +mtk_tx_unmap (eth, tx_buf, false); itxd->txd3 =TX_DMA_LS0 |TX_DMA_OWNER_CPU ;if (!MTK_HAS_CAPS (eth->soc->caps,MTK_QDMA ))
@@ -1388,7 +1393,7 @@ static int mtk_poll_tx_qdma(struct mtk_eth *eth, int budget, done[mac]++; budget--; } -mtk_tx_unmap (eth, tx_buf); +mtk_tx_unmap (eth, tx_buf, true); ring->last_free = desc;atomic_inc (&ring->free_count);
@@ -1425,7 +1430,7 @@ static int mtk_poll_tx_pdma(struct mtk_eth *eth, int budget, budget--; } -mtk_tx_unmap (eth, tx_buf); +mtk_tx_unmap (eth, tx_buf, true); desc = &ring->dma[cpu]; ring->last_free = desc;
@@ -1627,7 +1632,7 @@ static void mtk_tx_clean(struct mtk_eth *eth)if (ring->buf) {for (i =0 ; i <MTK_DMA_SIZE ; i++) -mtk_tx_unmap (eth, &ring->buf[i]); +mtk_tx_unmap (eth, &ring->buf[i], false);kfree (ring->buf); ring->buf =NULL ; }
Signature · 1 line
2.31.1
PATCH v2 5/15 net: ethernet: mtk_eth_soc: reduce MDIO bus access latency
In reply to Ilya LipnitskiyFrom: Felix Fietkau <[email protected]>
usleep_range often ends up sleeping much longer than the 10-20us provided as a range here. This causes significant latency in mdio bus acceses, which easily adds multiple seconds to the boot time on MT7621 when polling DSA slave ports.
Use cond_resched instead of usleep_range, since the MDIO access does not take much time
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +1 -1
@@ -86,7 +86,7 @@ static int mtk_mdio_busy_wait(struct mtk_eth *eth)return 0 ;if (time_after (jiffies, t_start +PHY_IAC_TIMEOUT ))break ; -usleep_range (10 ,20 ); +cond_resched (); }dev_err (eth->dev,"mdio: MDIO timeout\n" );
Signature · 1 line
2.31.1
PATCH v2 6/15 net: ethernet: mtk_eth_soc: remove unnecessary TX queue stops
In reply to Ilya LipnitskiyFrom: Felix Fietkau <[email protected]>
When running short on descriptors, only stop the queue for the netdev that tx was attempted for. By the time something tries to send on the other netdev, the ring might have some more room already.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +2 -13
@@ -1131,17 +1131,6 @@ static void mtk_wake_queue(struct mtk_eth *eth) } } -static void mtk_stop_queue (struct mtk_eth *eth) -{ -int i; - -for (i =0 ; i <MTK_MAC_COUNT ; i++) { -if (!eth->netdev[i]) -continue ; -netif_stop_queue (eth->netdev[i]); - } -} -static netdev_tx_t mtk_start_xmit (struct sk_buff *skb,struct net_device *dev) {struct mtk_mac *mac =netdev_priv (dev);
@@ -1162,7 +1151,7 @@ static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev) tx_num =mtk_cal_txd_req (skb);if (unlikely (atomic_read (&ring->free_count) <= tx_num)) { -mtk_stop_queue (eth); +netif_stop_queue (dev);netif_err (eth, tx_queued, dev,"Tx Ring full when queue awake!\n" );spin_unlock (ð->page_lock);
@@ -1188,7 +1177,7 @@ static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev) goto drop;if (unlikely (atomic_read (&ring->free_count) <= ring->thresh)) -mtk_stop_queue (eth); +netif_stop_queue (dev);spin_unlock (ð->page_lock);
Signature · 1 line
2.31.1
PATCH v2 7/15 net: ethernet: mtk_eth_soc: use larger burst size for QDMA TX
In reply to Ilya LipnitskiyFrom: Felix Fietkau <[email protected]>
Improves tx performance
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +1 -1
@@ -2193,7 +2193,7 @@ static int mtk_start_dma(struct mtk_eth *eth)if (MTK_HAS_CAPS (eth->soc->caps,MTK_QDMA )) {mtk_w32 (eth,MTK_TX_WB_DDONE |MTK_TX_DMA_EN | -MTK_DMA_SIZE_16DWORDS |MTK_NDP_CO_PRO | +MTK_TX_BT_32DWORDS |MTK_NDP_CO_PRO |MTK_RX_DMA_EN |MTK_RX_2B_OFFSET |MTK_RX_BT_32DWORDS ,MTK_QDMA_GLO_CFG );
drivers/net/ethernet/mediatek/mtk_eth_soc.h +1 -1
@@ -203,7 +203,7 @@#define MTK_RX_BT_32DWORDS (3 << 11)#define MTK_NDP_CO_PRO BIT(10)#define MTK_TX_WB_DDONE BIT(6) -#define MTK_DMA_SIZE_16DWORDS (2 << 4) +#define MTK_TX_BT_32DWORDS (3 << 4)#define MTK_RX_DMA_BUSY BIT(3)#define MTK_TX_DMA_BUSY BIT(1)#define MTK_RX_DMA_EN BIT(2)
Signature · 1 line
2.31.1
PATCH v2 8/15 net: ethernet: mtk_eth_soc: increase DMA ring sizes
In reply to Ilya LipnitskiyFrom: Felix Fietkau <[email protected]>
256 descriptors is not enough for multi-gigabit traffic under load on MT7622. Bump it to 512 to improve performance.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.h +1 -1
@@ -22,7 +22,7 @@#define MTK_MAX_RX_LENGTH 1536#define MTK_MAX_RX_LENGTH_2K 2048#define MTK_TX_DMA_BUF_LEN 0x3fff -#define MTK_DMA_SIZE 256 +#define MTK_DMA_SIZE 512#define MTK_NAPI_WEIGHT 64#define MTK_MAC_COUNT 2#define MTK_RX_ETH_HLEN (ETH_HLEN + ETH_FCS_LEN)
Signature · 1 line
2.31.1
PATCH v2 9/15 net: ethernet: mtk_eth_soc: implement dynamic interrupt moderation
In reply to Ilya LipnitskiyFrom: Felix Fietkau <[email protected]>
Reduces the number of interrupts under load
--- drivers/net/ethernet/mediatek/Kconfig | 1 + drivers/net/ethernet/mediatek/mtk_eth_soc.c | 96 +++++++++++++++++++-- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 41 +++++++-- 3 files changed, 124 insertions(+), 14 deletions(-)
drivers/net/ethernet/mediatek/Kconfig +1 -0
@@ -11,6 +11,7 @@ config NET_MEDIATEK_SOC tristate "MediaTek SoC Gigabit Ethernet support" depends on NET_DSA || !NET_DSA select PHYLINK + select DIMLIB help This driver supports the gigabit ethernet MACs in the MediaTek SoC family.
drivers/net/ethernet/mediatek/mtk_eth_soc.c +89 -7
177 lines not on this page · raw message
drivers/net/ethernet/mediatek/mtk_eth_soc.h +34 -7
85 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v2 10/15 net: ethernet: mtk_eth_soc: cache HW pointer of last freed TX descriptor
In reply to Ilya LipnitskiyFrom: Felix Fietkau <[email protected]>
The value is only updated by the CPU, so it is cheaper to access from the ring data structure than from a hardware register.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 ++++---- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +4 -4
@@ -1364,7 +1364,7 @@ static int mtk_poll_tx_qdma(struct mtk_eth *eth, int budget,struct mtk_tx_buf *tx_buf;u32 cpu, dma; - cpu =mtk_r32 (eth,MTK_QTX_CRX_PTR ); + cpu = ring->last_free_ptr; dma =mtk_r32 (eth,MTK_QTX_DRX_PTR ); desc =mtk_qdma_phys_to_virt (ring, cpu);
@@ -1398,6 +1398,7 @@ static int mtk_poll_tx_qdma(struct mtk_eth *eth, int budget, cpu = next_cpu; } + ring->last_free_ptr = cpu;mtk_w32 (eth, cpu,MTK_QTX_CRX_PTR );return budget;
@@ -1598,6 +1599,7 @@ static int mtk_tx_alloc(struct mtk_eth *eth)atomic_set (&ring->free_count,MTK_DMA_SIZE -2 ); ring->next_free = &ring->dma[0 ]; ring->last_free = &ring->dma[MTK_DMA_SIZE -1 ]; + ring->last_free_ptr = (u32)(ring->phys + ((MTK_DMA_SIZE -1 ) * sz)); ring->thresh =MAX_SKB_FRAGS ;/* make sure that all changes to the dma ring are flushed before we
@@ -1611,9 +1613,7 @@ static int mtk_tx_alloc(struct mtk_eth *eth)mtk_w32 (eth, ring->phys + ((MTK_DMA_SIZE -1 ) * sz),MTK_QTX_CRX_PTR ); -mtk_w32 (eth, - ring->phys + ((MTK_DMA_SIZE -1 ) * sz), -MTK_QTX_DRX_PTR ); +mtk_w32 (eth, ring->last_free_ptr,MTK_QTX_DRX_PTR );mtk_w32 (eth, (QDMA_RES_THRES <<8 ) |QDMA_RES_THRES ,MTK_QTX_CFG (0 )); }else {
drivers/net/ethernet/mediatek/mtk_eth_soc.h +2 -0
@@ -642,6 +642,7 @@ struct mtk_tx_buf {* @phys: The physical addr of tx_buf * @next_free: Pointer to the next free descriptor * @last_free: Pointer to the last free descriptor +* @last_free_ptr: Hardware pointer value of the last free descriptor * @thresh: The threshold of minimum amount of free descriptors * @free_count: QDMA uses a linked list. Track how many free descriptors * are present
@@ -652,6 +653,7 @@ struct mtk_tx_ring {dma_addr_t phys;struct mtk_tx_dma *next_free;struct mtk_tx_dma *last_free; +u32 last_free_ptr;u16 thresh;atomic_t free_count;int dma_size;
Signature · 1 line
2.31.1
PATCH v2 11/15 net: ethernet: mtk_eth_soc: only read the full RX descriptor if DMA is done
In reply to Ilya LipnitskiyFrom: Felix Fietkau <[email protected]>
Uncached memory access is expensive, and there is no need to access all descriptor words if we can't process them anyway
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +8 -4
@@ -777,13 +777,18 @@ static inline int mtk_max_buf_size(int frag_size)return buf_size; } -static inline void mtk_rx_get_desc (struct mtk_rx_dma *rxd, +static inline bool mtk_rx_get_desc (struct mtk_rx_dma *rxd,struct mtk_rx_dma *dma_rxd) { - rxd->rxd1 =READ_ONCE (dma_rxd->rxd1); rxd->rxd2 =READ_ONCE (dma_rxd->rxd2); +if (!(rxd->rxd2 &RX_DMA_DONE )) +return false; + + rxd->rxd1 =READ_ONCE (dma_rxd->rxd1); rxd->rxd3 =READ_ONCE (dma_rxd->rxd3); rxd->rxd4 =READ_ONCE (dma_rxd->rxd4); + +return true; }/* the qdma core needs scratch memory to be setup */
@@ -1255,8 +1260,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, rxd = &ring->dma[idx]; data = ring->data[idx]; -mtk_rx_get_desc (&trxd, rxd); -if (!(trxd.rxd2 &RX_DMA_DONE )) +if (!mtk_rx_get_desc (&trxd, rxd))break ;/* find out which mac the packet come from. values start at 1 */
Signature · 1 line
2.31.1
PATCH v2 12/15 net: ethernet: mtk_eth_soc: reduce unnecessary interrupts
In reply to Ilya LipnitskiyFrom: Felix Fietkau <[email protected]>
Avoid rearming interrupt if napi_complete returns false
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +5 -4
@@ -1519,8 +1519,8 @@ static int mtk_napi_tx(struct napi_struct *napi, int budget)if (status &MTK_TX_DONE_INT )return budget; -napi_complete (napi); -mtk_tx_irq_enable (eth,MTK_TX_DONE_INT ); +if (napi_complete (napi)) +mtk_tx_irq_enable (eth,MTK_TX_DONE_INT );return tx_done; }
@@ -1553,8 +1553,9 @@ static int mtk_napi_rx(struct napi_struct *napi, int budget) remain_budget -= rx_done; goto poll_again; } -napi_complete (napi); -mtk_rx_irq_enable (eth,MTK_RX_DONE_INT ); + +if (napi_complete (napi)) +mtk_rx_irq_enable (eth,MTK_RX_DONE_INT );return rx_done + budget - remain_budget; }
Signature · 1 line
2.31.1
PATCH v2 13/15 net: ethernet: mtk_eth_soc: rework NAPI callbacks
In reply to Ilya LipnitskiyUse napi_complete_done to communicate total TX and RX work done to NAPI. Count total RX work up instead of remaining work down for clarity. Remove unneeded local variables for clarity. Use do {} while instead of goto for clarity.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 54 +++++++++------------ 1 file changed, 24 insertions(+), 30 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +24 -30
@@ -1496,7 +1496,6 @@ static void mtk_handle_status_irq(struct mtk_eth *eth)static int mtk_napi_tx (struct napi_struct *napi,int budget) { struct mtk_eth *eth = container_of(napi, struct mtk_eth, tx_napi); -u32 status, mask;int tx_done =0 ;if (MTK_HAS_CAPS (eth->soc->caps,MTK_QDMA ))
@@ -1505,21 +1504,19 @@ static int mtk_napi_tx(struct napi_struct *napi, int budget) tx_done =mtk_poll_tx (eth, budget);if (unlikely (netif_msg_intr (eth))) { - status =mtk_r32 (eth, eth->tx_int_status_reg); - mask =mtk_r32 (eth, eth->tx_int_mask_reg);dev_info (eth->dev, -"done tx %d, intr 0x%08x/0x%x\n" , - tx_done, status, mask); +"done tx %d, intr 0x%08x/0x%x\n" , tx_done, +mtk_r32 (eth, eth->tx_int_status_reg), +mtk_r32 (eth, eth->tx_int_mask_reg)); }if (tx_done == budget)return budget; - status =mtk_r32 (eth, eth->tx_int_status_reg); -if (status &MTK_TX_DONE_INT ) +if (mtk_r32 (eth, eth->tx_int_status_reg) &MTK_TX_DONE_INT )return budget; -if (napi_complete (napi)) +if (napi_complete_done (napi, tx_done))mtk_tx_irq_enable (eth,MTK_TX_DONE_INT );return tx_done;
@@ -1528,36 +1525,33 @@ static int mtk_napi_tx(struct napi_struct *napi, int budget)static int mtk_napi_rx (struct napi_struct *napi,int budget) { struct mtk_eth *eth = container_of(napi, struct mtk_eth, rx_napi); -u32 status, mask; -int rx_done =0 ; -int remain_budget = budget; +int rx_done_total =0 ;mtk_handle_status_irq (eth); -poll_again: -mtk_w32 (eth,MTK_RX_DONE_INT ,MTK_PDMA_INT_STATUS ); - rx_done =mtk_poll_rx (napi, remain_budget, eth); +do { +int rx_done; -if (unlikely (netif_msg_intr (eth))) { - status =mtk_r32 (eth,MTK_PDMA_INT_STATUS ); - mask =mtk_r32 (eth,MTK_PDMA_INT_MASK ); -dev_info (eth->dev, -"done rx %d, intr 0x%08x/0x%x\n" , - rx_done, status, mask); - } -if (rx_done == remain_budget) -return budget; +mtk_w32 (eth,MTK_RX_DONE_INT ,MTK_PDMA_INT_STATUS ); + rx_done =mtk_poll_rx (napi, budget - rx_done_total, eth); + rx_done_total += rx_done; - status =mtk_r32 (eth,MTK_PDMA_INT_STATUS ); -if (status &MTK_RX_DONE_INT ) { - remain_budget -= rx_done; - goto poll_again; - } +if (unlikely (netif_msg_intr (eth))) { +dev_info (eth->dev, +"done rx %d, intr 0x%08x/0x%x\n" , rx_done, +mtk_r32 (eth,MTK_PDMA_INT_STATUS ), +mtk_r32 (eth,MTK_PDMA_INT_MASK )); + } + +if (rx_done_total == budget) +return budget; + + }while (mtk_r32 (eth,MTK_PDMA_INT_STATUS ) &MTK_RX_DONE_INT ); -if (napi_complete (napi)) +if (napi_complete_done (napi, rx_done_total))mtk_rx_irq_enable (eth,MTK_RX_DONE_INT ); -return rx_done + budget - remain_budget; +return rx_done_total; }static int mtk_tx_alloc (struct mtk_eth *eth)
Signature · 1 line
2.31.1
PATCH v2 14/15 net: ethernet: mtk_eth_soc: set PPE flow hash as skb hash if present
In reply to Ilya LipnitskiyFrom: Felix Fietkau <[email protected]>
This improves GRO performance
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +8 -0
@@ -19,6 +19,7 @@#include <linux/interrupt.h> #include <linux/pinctrl/devinfo.h> #include <linux/phylink.h> +#include <linux/jhash.h> #include <net/dsa.h> #include "mtk_eth_soc.h"
@@ -1250,6 +1251,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,struct net_device *netdev;unsigned int pktlen;dma_addr_t dma_addr; +u32 hash;int mac; ring =mtk_get_rx_ring (eth);
@@ -1319,6 +1321,12 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, skb->protocol =eth_type_trans (skb, netdev); bytes += pktlen; + hash = trxd.rxd4 &MTK_RXD4_FOE_ENTRY ; +if (hash !=MTK_RXD4_FOE_ENTRY ) { + hash =jhash_1word (hash,0 ); +skb_set_hash (skb, hash,PKT_HASH_TYPE_L4 ); + } +if (netdev->features &NETIF_F_HW_VLAN_CTAG_RX && (trxd.rxd2 &RX_DMA_VTAG )) __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
Signature · 1 line
2.31.1
PATCH v2 15/15 net: ethernet: mtk_eth_soc: use iopoll.h macro for DMA init
In reply to Ilya LipnitskiyReplace a tight busy-wait loop without a pause with a standard readx_poll_timeout_atomic routine with a 5 us poll period.
Tested by booting a MT7621 device to ensure the driver initializes properly.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 29 +++++++++------------ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +13 -16
@@ -2033,25 +2033,22 @@ static int mtk_set_features(struct net_device *dev, netdev_features_t features)/* wait for DMA to finish whatever it is doing before we start using it again */ static int mtk_dma_busy_wait (struct mtk_eth *eth) { -unsigned long t_start = jiffies; +unsigned int reg; +int ret; +u32 val; -while (1 ) { -if (MTK_HAS_CAPS (eth->soc->caps,MTK_QDMA )) { -if (!(mtk_r32 (eth,MTK_QDMA_GLO_CFG ) & - (MTK_RX_DMA_BUSY |MTK_TX_DMA_BUSY ))) -return 0 ; - }else { -if (!(mtk_r32 (eth,MTK_PDMA_GLO_CFG ) & - (MTK_RX_DMA_BUSY |MTK_TX_DMA_BUSY ))) -return 0 ; - } +if (MTK_HAS_CAPS (eth->soc->caps,MTK_QDMA )) + reg =MTK_QDMA_GLO_CFG ; +else + reg =MTK_PDMA_GLO_CFG ; -if (time_after (jiffies, t_start +MTK_DMA_BUSY_TIMEOUT )) -break ; - } + ret =readx_poll_timeout_atomic (__raw_readl, eth->base + reg, val, + !(val & (MTK_RX_DMA_BUSY |MTK_TX_DMA_BUSY )), +5 ,MTK_DMA_BUSY_TIMEOUT_US ); +if (ret) +dev_err (eth->dev,"DMA init timeout\n" ); -dev_err (eth->dev,"DMA init timeout\n" ); -return -1 ; +return ret; }static int mtk_dma_init (struct mtk_eth *eth)
drivers/net/ethernet/mediatek/mtk_eth_soc.h +1 -1
@@ -214,7 +214,7 @@#define MTK_TX_DMA_BUSY BIT(1)#define MTK_RX_DMA_EN BIT(2)#define MTK_TX_DMA_EN BIT(0) -#define MTK_DMA_BUSY_TIMEOUT HZ +#define MTK_DMA_BUSY_TIMEOUT_US 1000000/* QDMA Reset Index Register */ #define MTK_QDMA_RST_IDX 0x1A08
Signature · 1 line
2.31.1
This series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 8 lines · On Thu, 22 Apr 2021 22:20:53 -0700 you wrote:
Most of these changes come from OpenWrt where they have been present and tested for months.
First three patches are bug fixes. The rest are performance improvements. The last patch is a cleanup to use the
iopoll.hmacro for busy-waiting instead of a custom loop.[...]
Here is the summary with links:
- [net-next,v2,01/15] net: ethernet: mtk_eth_soc: fix RX VLAN offload
https://git.kernel.org/netdev/net-next/c/3f57d8c40fea - [net-next,v2,02/15] net: ethernet: mtk_eth_soc: unmap RX data before calling build_skb https://git.kernel.org/netdev/net-next/c/5196c4178549 - [net-next,v2,03/15] net: ethernet: mtk_eth_soc: fix build_skb cleanup https://git.kernel.org/netdev/net-next/c/787082ab9f7b - [net-next,v2,04/15] net: ethernet: mtk_eth_soc: use napi_consume_skb https://git.kernel.org/netdev/net-next/c/c30c4a827390 - [net-next,v2,05/15] net: ethernet: mtk_eth_soc: reduce MDIO bus access latency https://git.kernel.org/netdev/net-next/c/3630d519d7c3 - [net-next,v2,06/15] net: ethernet: mtk_eth_soc: remove unnecessary TX queue stops https://git.kernel.org/netdev/net-next/c/16ef670789b2 - [net-next,v2,07/15] net: ethernet: mtk_eth_soc: use larger burst size for QDMA TX https://git.kernel.org/netdev/net-next/c/59555a8d0dd3 - [net-next,v2,08/15] net: ethernet: mtk_eth_soc: increase DMA ring sizes https://git.kernel.org/netdev/net-next/c/6b4423b258b9 - [net-next,v2,09/15] net: ethernet: mtk_eth_soc: implement dynamic interrupt moderation https://git.kernel.org/netdev/net-next/c/e9229ffd550b - [net-next,v2,10/15] net: ethernet: mtk_eth_soc: cache HW pointer of last freed TX descriptor https://git.kernel.org/netdev/net-next/c/4e6bf609569c - [net-next,v2,11/15] net: ethernet: mtk_eth_soc: only read the full RX descriptor if DMA is done https://git.kernel.org/netdev/net-next/c/816ac3e6e67b - [net-next,v2,12/15] net: ethernet: mtk_eth_soc: reduce unnecessary interrupts https://git.kernel.org/netdev/net-next/c/16769a8923fa - [net-next,v2,13/15] net: ethernet: mtk_eth_soc: rework NAPI callbacks https://git.kernel.org/netdev/net-next/c/db2c7b353db3 - [net-next,v2,14/15] net: ethernet: mtk_eth_soc: set PPE flow hash as skb hash if present https://git.kernel.org/netdev/net-next/c/fa817272c37e - [net-next,v2,15/15] net: ethernet: mtk_eth_soc: use iopoll.h macro for DMA init https://git.kernel.org/netdev/net-next/c/3bc8e0aff23b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html