0703-v5.16-net-lantiq_xrx200-increase-buffer-reservation.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. From 1488fc204568f707fe2a42a913788c00a95af30e Mon Sep 17 00:00:00 2001
  2. From: Aleksander Jan Bajkowski <[email protected]>
  3. Date: Fri, 17 Dec 2021 01:07:40 +0100
  4. Subject: [PATCH] net: lantiq_xrx200: increase buffer reservation
  5. If the user sets a lower mtu on the CPU port than on the switch,
  6. then DMA inserts a few more bytes into the buffer than expected.
  7. In the worst case, it may exceed the size of the buffer. The
  8. experiments showed that the buffer should be a multiple of the
  9. burst length value. This patch rounds the length of the rx buffer
  10. upwards and fixes this bug. The reservation of FCS space in the
  11. buffer has been removed as PMAC strips the FCS.
  12. Fixes: 998ac358019e ("net: lantiq: add support for jumbo frames")
  13. Reported-by: Thomas Nixon <[email protected]>
  14. Signed-off-by: Aleksander Jan Bajkowski <[email protected]>
  15. Signed-off-by: Jakub Kicinski <[email protected]>
  16. ---
  17. drivers/net/ethernet/lantiq_xrx200.c | 34 ++++++++++++++++++++--------
  18. 1 file changed, 24 insertions(+), 10 deletions(-)
  19. --- a/drivers/net/ethernet/lantiq_xrx200.c
  20. +++ b/drivers/net/ethernet/lantiq_xrx200.c
  21. @@ -70,6 +70,8 @@ struct xrx200_priv {
  22. struct xrx200_chan chan_tx;
  23. struct xrx200_chan chan_rx;
  24. + u16 rx_buf_size;
  25. +
  26. struct net_device *net_dev;
  27. struct device *dev;
  28. @@ -96,6 +98,16 @@ static void xrx200_pmac_mask(struct xrx2
  29. xrx200_pmac_w32(priv, val, offset);
  30. }
  31. +static int xrx200_max_frame_len(int mtu)
  32. +{
  33. + return VLAN_ETH_HLEN + mtu;
  34. +}
  35. +
  36. +static int xrx200_buffer_size(int mtu)
  37. +{
  38. + return round_up(xrx200_max_frame_len(mtu), 4 * XRX200_DMA_BURST_LEN);
  39. +}
  40. +
  41. /* drop all the packets from the DMA ring */
  42. static void xrx200_flush_dma(struct xrx200_chan *ch)
  43. {
  44. @@ -108,8 +120,7 @@ static void xrx200_flush_dma(struct xrx2
  45. break;
  46. desc->ctl = LTQ_DMA_OWN | LTQ_DMA_RX_OFFSET(NET_IP_ALIGN) |
  47. - (ch->priv->net_dev->mtu + VLAN_ETH_HLEN +
  48. - ETH_FCS_LEN);
  49. + ch->priv->rx_buf_size;
  50. ch->dma.desc++;
  51. ch->dma.desc %= LTQ_DESC_NUM;
  52. }
  53. @@ -157,21 +168,21 @@ static int xrx200_close(struct net_devic
  54. static int xrx200_alloc_skb(struct xrx200_chan *ch)
  55. {
  56. - int len = ch->priv->net_dev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
  57. struct sk_buff *skb = ch->skb[ch->dma.desc];
  58. + struct xrx200_priv *priv = ch->priv;
  59. dma_addr_t mapping;
  60. int ret = 0;
  61. - ch->skb[ch->dma.desc] = netdev_alloc_skb_ip_align(ch->priv->net_dev,
  62. - len);
  63. + ch->skb[ch->dma.desc] = netdev_alloc_skb_ip_align(priv->net_dev,
  64. + priv->rx_buf_size);
  65. if (!ch->skb[ch->dma.desc]) {
  66. ret = -ENOMEM;
  67. goto skip;
  68. }
  69. - mapping = dma_map_single(ch->priv->dev, ch->skb[ch->dma.desc]->data,
  70. - len, DMA_FROM_DEVICE);
  71. - if (unlikely(dma_mapping_error(ch->priv->dev, mapping))) {
  72. + mapping = dma_map_single(priv->dev, ch->skb[ch->dma.desc]->data,
  73. + priv->rx_buf_size, DMA_FROM_DEVICE);
  74. + if (unlikely(dma_mapping_error(priv->dev, mapping))) {
  75. dev_kfree_skb_any(ch->skb[ch->dma.desc]);
  76. ch->skb[ch->dma.desc] = skb;
  77. ret = -ENOMEM;
  78. @@ -183,7 +194,7 @@ static int xrx200_alloc_skb(struct xrx20
  79. wmb();
  80. skip:
  81. ch->dma.desc_base[ch->dma.desc].ctl =
  82. - LTQ_DMA_OWN | LTQ_DMA_RX_OFFSET(NET_IP_ALIGN) | len;
  83. + LTQ_DMA_OWN | LTQ_DMA_RX_OFFSET(NET_IP_ALIGN) | priv->rx_buf_size;
  84. return ret;
  85. }
  86. @@ -355,6 +366,7 @@ xrx200_change_mtu(struct net_device *net
  87. int ret = 0;
  88. net_dev->mtu = new_mtu;
  89. + priv->rx_buf_size = xrx200_buffer_size(new_mtu);
  90. if (new_mtu <= old_mtu)
  91. return ret;
  92. @@ -374,6 +386,7 @@ xrx200_change_mtu(struct net_device *net
  93. ret = xrx200_alloc_skb(ch_rx);
  94. if (ret) {
  95. net_dev->mtu = old_mtu;
  96. + priv->rx_buf_size = xrx200_buffer_size(old_mtu);
  97. break;
  98. }
  99. dev_kfree_skb_any(skb);
  100. @@ -504,7 +517,8 @@ static int xrx200_probe(struct platform_
  101. net_dev->netdev_ops = &xrx200_netdev_ops;
  102. SET_NETDEV_DEV(net_dev, dev);
  103. net_dev->min_mtu = ETH_ZLEN;
  104. - net_dev->max_mtu = XRX200_DMA_DATA_LEN - VLAN_ETH_HLEN - ETH_FCS_LEN;
  105. + net_dev->max_mtu = XRX200_DMA_DATA_LEN - xrx200_max_frame_len(0);
  106. + priv->rx_buf_size = xrx200_buffer_size(ETH_DATA_LEN);
  107. /* load the memory ranges */
  108. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);