2
0

077-06-bgmac-set-received-skb-headroom-to-NET_SKB_PAD.patch 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Date: Sun, 12 Apr 2015 10:13:28 +0200
  3. Subject: [PATCH] bgmac: set received skb headroom to NET_SKB_PAD
  4. A packet buffer offset of 30 bytes is inefficient, because the first 2
  5. bytes end up in a different cacheline.
  6. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  7. ---
  8. --- a/drivers/net/ethernet/broadcom/bgmac.c
  9. +++ b/drivers/net/ethernet/broadcom/bgmac.c
  10. @@ -346,13 +346,13 @@ static int bgmac_dma_rx_skb_for_slot(str
  11. return -ENOMEM;
  12. /* Poison - if everything goes fine, hardware will overwrite it */
  13. - rx = buf;
  14. + rx = buf + BGMAC_RX_BUF_OFFSET;
  15. rx->len = cpu_to_le16(0xdead);
  16. rx->flags = cpu_to_le16(0xbeef);
  17. /* Map skb for the DMA */
  18. - dma_addr = dma_map_single(dma_dev, buf, BGMAC_RX_BUF_SIZE,
  19. - DMA_FROM_DEVICE);
  20. + dma_addr = dma_map_single(dma_dev, buf + BGMAC_RX_BUF_OFFSET,
  21. + BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE);
  22. if (dma_mapping_error(dma_dev, dma_addr)) {
  23. bgmac_err(bgmac, "DMA mapping error\n");
  24. put_page(virt_to_head_page(buf));
  25. @@ -403,7 +403,7 @@ static int bgmac_dma_rx_read(struct bgma
  26. while (ring->start != ring->end) {
  27. struct device *dma_dev = bgmac->core->dma_dev;
  28. struct bgmac_slot_info *slot = &ring->slots[ring->start];
  29. - struct bgmac_rx_header *rx = slot->buf;
  30. + struct bgmac_rx_header *rx = slot->buf + BGMAC_RX_BUF_OFFSET;
  31. struct sk_buff *skb;
  32. void *buf = slot->buf;
  33. u16 len, flags;
  34. @@ -454,8 +454,10 @@ static int bgmac_dma_rx_read(struct bgma
  35. BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE);
  36. skb = build_skb(buf, BGMAC_RX_ALLOC_SIZE);
  37. - skb_put(skb, BGMAC_RX_FRAME_OFFSET + len);
  38. - skb_pull(skb, BGMAC_RX_FRAME_OFFSET);
  39. + skb_put(skb, BGMAC_RX_FRAME_OFFSET +
  40. + BGMAC_RX_BUF_OFFSET + len);
  41. + skb_pull(skb, BGMAC_RX_FRAME_OFFSET +
  42. + BGMAC_RX_BUF_OFFSET);
  43. skb_checksum_none_assert(skb);
  44. skb->protocol = eth_type_trans(skb, bgmac->net_dev);
  45. --- a/drivers/net/ethernet/broadcom/bgmac.h
  46. +++ b/drivers/net/ethernet/broadcom/bgmac.h
  47. @@ -360,9 +360,11 @@
  48. #define BGMAC_RX_HEADER_LEN 28 /* Last 24 bytes are unused. Well... */
  49. #define BGMAC_RX_FRAME_OFFSET 30 /* There are 2 unused bytes between header and real data */
  50. +#define BGMAC_RX_BUF_OFFSET (NET_SKB_PAD + NET_IP_ALIGN - \
  51. + BGMAC_RX_FRAME_OFFSET)
  52. #define BGMAC_RX_MAX_FRAME_SIZE 1536 /* Copied from b44/tg3 */
  53. #define BGMAC_RX_BUF_SIZE (BGMAC_RX_FRAME_OFFSET + BGMAC_RX_MAX_FRAME_SIZE)
  54. -#define BGMAC_RX_ALLOC_SIZE (SKB_DATA_ALIGN(BGMAC_RX_BUF_SIZE) + \
  55. +#define BGMAC_RX_ALLOC_SIZE (SKB_DATA_ALIGN(BGMAC_RX_BUF_SIZE + BGMAC_RX_BUF_OFFSET) + \
  56. SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
  57. #define BGMAC_BFL_ENETROBO 0x0010 /* has ephy roboswitch spi */