610-v5.13-46-net-ethernet-mtk_eth_soc-cache-HW-pointer-of-last-fr.patch 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. From 4e6bf609569c59b6bd6acf4a607c096cbd820d79 Mon Sep 17 00:00:00 2001
  2. From: Felix Fietkau <[email protected]>
  3. Date: Thu, 22 Apr 2021 22:21:03 -0700
  4. Subject: [PATCH] net: ethernet: mtk_eth_soc: cache HW pointer of last freed TX
  5. descriptor
  6. The value is only updated by the CPU, so it is cheaper to access from the
  7. ring data structure than from a hardware register.
  8. Signed-off-by: Felix Fietkau <[email protected]>
  9. Signed-off-by: Ilya Lipnitskiy <[email protected]>
  10. Signed-off-by: David S. Miller <[email protected]>
  11. ---
  12. drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 ++++----
  13. drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 ++
  14. 2 files changed, 6 insertions(+), 4 deletions(-)
  15. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  16. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  17. @@ -1400,7 +1400,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
  18. struct mtk_tx_buf *tx_buf;
  19. u32 cpu, dma;
  20. - cpu = mtk_r32(eth, MTK_QTX_CRX_PTR);
  21. + cpu = ring->last_free_ptr;
  22. dma = mtk_r32(eth, MTK_QTX_DRX_PTR);
  23. desc = mtk_qdma_phys_to_virt(ring, cpu);
  24. @@ -1434,6 +1434,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
  25. cpu = next_cpu;
  26. }
  27. + ring->last_free_ptr = cpu;
  28. mtk_w32(eth, cpu, MTK_QTX_CRX_PTR);
  29. return budget;
  30. @@ -1634,6 +1635,7 @@ static int mtk_tx_alloc(struct mtk_eth *
  31. atomic_set(&ring->free_count, MTK_DMA_SIZE - 2);
  32. ring->next_free = &ring->dma[0];
  33. ring->last_free = &ring->dma[MTK_DMA_SIZE - 1];
  34. + ring->last_free_ptr = (u32)(ring->phys + ((MTK_DMA_SIZE - 1) * sz));
  35. ring->thresh = MAX_SKB_FRAGS;
  36. /* make sure that all changes to the dma ring are flushed before we
  37. @@ -1647,9 +1649,7 @@ static int mtk_tx_alloc(struct mtk_eth *
  38. mtk_w32(eth,
  39. ring->phys + ((MTK_DMA_SIZE - 1) * sz),
  40. MTK_QTX_CRX_PTR);
  41. - mtk_w32(eth,
  42. - ring->phys + ((MTK_DMA_SIZE - 1) * sz),
  43. - MTK_QTX_DRX_PTR);
  44. + mtk_w32(eth, ring->last_free_ptr, MTK_QTX_DRX_PTR);
  45. mtk_w32(eth, (QDMA_RES_THRES << 8) | QDMA_RES_THRES,
  46. MTK_QTX_CFG(0));
  47. } else {
  48. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  49. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  50. @@ -657,6 +657,7 @@ struct mtk_tx_buf {
  51. * @phys: The physical addr of tx_buf
  52. * @next_free: Pointer to the next free descriptor
  53. * @last_free: Pointer to the last free descriptor
  54. + * @last_free_ptr: Hardware pointer value of the last free descriptor
  55. * @thresh: The threshold of minimum amount of free descriptors
  56. * @free_count: QDMA uses a linked list. Track how many free descriptors
  57. * are present
  58. @@ -667,6 +668,7 @@ struct mtk_tx_ring {
  59. dma_addr_t phys;
  60. struct mtk_tx_dma *next_free;
  61. struct mtk_tx_dma *last_free;
  62. + u32 last_free_ptr;
  63. u16 thresh;
  64. atomic_t free_count;
  65. int dma_size;