0081-net-next-mediatek-fix-DQL-support.patch 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. From 81cdbda2a08375b9d5915567d2210bf2433e7332 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <john@phrozen.org>
  3. Date: Sat, 23 Apr 2016 11:57:21 +0200
  4. Subject: [PATCH 081/102] net-next: mediatek: fix DQL support
  5. The MTK ethernet core has 2 MACs both sitting on the same DMA ring. The
  6. current code will assign the TX traffic of each MAC to its own DQL. This
  7. results in the amount of data, that DQL says is in the queue incorrect. As
  8. the data from multiple devices is infact enqueued. This makes any decision
  9. based on these value non deterministic. Fix this by tracking all TX
  10. traffic, regardless of the MAC it belongs to in the DQL of all devices
  11. using the DMA.
  12. Signed-off-by: John Crispin <john@phrozen.org>
  13. ---
  14. drivers/net/ethernet/mediatek/mtk_eth_soc.c | 33 ++++++++++++++++-----------
  15. 1 file changed, 20 insertions(+), 13 deletions(-)
  16. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  17. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  18. @@ -656,7 +656,16 @@ static int mtk_tx_map(struct sk_buff *sk
  19. WRITE_ONCE(itxd->txd3, (TX_DMA_SWC | TX_DMA_PLEN0(skb_headlen(skb)) |
  20. (!nr_frags * TX_DMA_LS0)));
  21. - netdev_sent_queue(dev, skb->len);
  22. + /* we have a single DMA ring so BQL needs to be updated for all devices
  23. + * sitting on this ring
  24. + */
  25. + for (i = 0; i < MTK_MAC_COUNT; i++) {
  26. + if (!eth->netdev[i])
  27. + continue;
  28. +
  29. + netdev_sent_queue(eth->netdev[i], skb->len);
  30. + }
  31. +
  32. skb_tx_timestamp(skb);
  33. ring->next_free = mtk_qdma_phys_to_virt(ring, txd->txd2);
  34. @@ -884,21 +893,18 @@ static int mtk_poll_tx(struct mtk_eth *e
  35. struct mtk_tx_dma *desc;
  36. struct sk_buff *skb;
  37. struct mtk_tx_buf *tx_buf;
  38. - int total = 0, done[MTK_MAX_DEVS];
  39. - unsigned int bytes[MTK_MAX_DEVS];
  40. + int total = 0, done = 0;
  41. + unsigned int bytes = 0;
  42. u32 cpu, dma;
  43. static int condition;
  44. int i;
  45. - memset(done, 0, sizeof(done));
  46. - memset(bytes, 0, sizeof(bytes));
  47. -
  48. cpu = mtk_r32(eth, MTK_QTX_CRX_PTR);
  49. dma = mtk_r32(eth, MTK_QTX_DRX_PTR);
  50. desc = mtk_qdma_phys_to_virt(ring, cpu);
  51. - while ((cpu != dma) && budget) {
  52. + while ((cpu != dma) && done < budget) {
  53. u32 next_cpu = desc->txd2;
  54. int mac;
  55. @@ -918,9 +924,8 @@ static int mtk_poll_tx(struct mtk_eth *e
  56. }
  57. if (skb != (struct sk_buff *)MTK_DMA_DUMMY_DESC) {
  58. - bytes[mac] += skb->len;
  59. - done[mac]++;
  60. - budget--;
  61. + bytes += skb->len;
  62. + done++;
  63. }
  64. mtk_tx_unmap(eth->dev, tx_buf);
  65. @@ -933,11 +938,13 @@ static int mtk_poll_tx(struct mtk_eth *e
  66. mtk_w32(eth, cpu, MTK_QTX_CRX_PTR);
  67. + /* we have a single DMA ring so BQL needs to be updated for all devices
  68. + * sitting on this ring
  69. + */
  70. for (i = 0; i < MTK_MAC_COUNT; i++) {
  71. - if (!eth->netdev[i] || !done[i])
  72. + if (!eth->netdev[i])
  73. continue;
  74. - netdev_completed_queue(eth->netdev[i], done[i], bytes[i]);
  75. - total += done[i];
  76. + netdev_completed_queue(eth->netdev[i], done, bytes);
  77. }
  78. /* read hw index again make sure no new tx packet */