2
0

077-12-bgmac-drop-ring-num_slots.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Date: Sun, 12 Apr 2015 23:28:38 +0200
  3. Subject: [PATCH] bgmac: drop ring->num_slots
  4. The ring size is always known at compile time, so make the code a bit
  5. more efficient
  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. @@ -123,7 +123,7 @@ bgmac_dma_tx_add_buf(struct bgmac *bgmac
  11. struct bgmac_dma_desc *dma_desc;
  12. u32 ctl1;
  13. - if (i == ring->num_slots - 1)
  14. + if (i == BGMAC_TX_RING_SLOTS - 1)
  15. ctl0 |= BGMAC_DESC_CTL0_EOT;
  16. ctl1 = len & BGMAC_DESC_CTL1_LEN;
  17. @@ -382,7 +382,7 @@ static void bgmac_dma_rx_setup_desc(stru
  18. struct bgmac_dma_desc *dma_desc = ring->cpu_base + desc_idx;
  19. u32 ctl0 = 0, ctl1 = 0;
  20. - if (desc_idx == ring->num_slots - 1)
  21. + if (desc_idx == BGMAC_RX_RING_SLOTS - 1)
  22. ctl0 |= BGMAC_DESC_CTL0_EOT;
  23. ctl1 |= BGMAC_RX_BUF_SIZE & BGMAC_DESC_CTL1_LEN;
  24. /* Is there any BGMAC device that requires extension? */
  25. @@ -521,7 +521,7 @@ static void bgmac_dma_tx_ring_free(struc
  26. struct bgmac_slot_info *slot;
  27. int i;
  28. - for (i = 0; i < ring->num_slots; i++) {
  29. + for (i = 0; i < BGMAC_TX_RING_SLOTS; i++) {
  30. int len = dma_desc[i].ctl1 & BGMAC_DESC_CTL1_LEN;
  31. slot = &ring->slots[i];
  32. @@ -546,7 +546,7 @@ static void bgmac_dma_rx_ring_free(struc
  33. struct bgmac_slot_info *slot;
  34. int i;
  35. - for (i = 0; i < ring->num_slots; i++) {
  36. + for (i = 0; i < BGMAC_RX_RING_SLOTS; i++) {
  37. slot = &ring->slots[i];
  38. if (!slot->dma_addr)
  39. continue;
  40. @@ -560,7 +560,8 @@ static void bgmac_dma_rx_ring_free(struc
  41. }
  42. static void bgmac_dma_ring_desc_free(struct bgmac *bgmac,
  43. - struct bgmac_dma_ring *ring)
  44. + struct bgmac_dma_ring *ring,
  45. + int num_slots)
  46. {
  47. struct device *dma_dev = bgmac->core->dma_dev;
  48. int size;
  49. @@ -569,7 +570,7 @@ static void bgmac_dma_ring_desc_free(str
  50. return;
  51. /* Free ring of descriptors */
  52. - size = ring->num_slots * sizeof(struct bgmac_dma_desc);
  53. + size = num_slots * sizeof(struct bgmac_dma_desc);
  54. dma_free_coherent(dma_dev, size, ring->cpu_base,
  55. ring->dma_base);
  56. }
  57. @@ -590,10 +591,12 @@ static void bgmac_dma_free(struct bgmac
  58. int i;
  59. for (i = 0; i < BGMAC_MAX_TX_RINGS; i++)
  60. - bgmac_dma_ring_desc_free(bgmac, &bgmac->tx_ring[i]);
  61. + bgmac_dma_ring_desc_free(bgmac, &bgmac->tx_ring[i],
  62. + BGMAC_TX_RING_SLOTS);
  63. for (i = 0; i < BGMAC_MAX_RX_RINGS; i++)
  64. - bgmac_dma_ring_desc_free(bgmac, &bgmac->rx_ring[i]);
  65. + bgmac_dma_ring_desc_free(bgmac, &bgmac->rx_ring[i],
  66. + BGMAC_RX_RING_SLOTS);
  67. }
  68. static int bgmac_dma_alloc(struct bgmac *bgmac)
  69. @@ -616,11 +619,10 @@ static int bgmac_dma_alloc(struct bgmac
  70. for (i = 0; i < BGMAC_MAX_TX_RINGS; i++) {
  71. ring = &bgmac->tx_ring[i];
  72. - ring->num_slots = BGMAC_TX_RING_SLOTS;
  73. ring->mmio_base = ring_base[i];
  74. /* Alloc ring of descriptors */
  75. - size = ring->num_slots * sizeof(struct bgmac_dma_desc);
  76. + size = BGMAC_TX_RING_SLOTS * sizeof(struct bgmac_dma_desc);
  77. ring->cpu_base = dma_zalloc_coherent(dma_dev, size,
  78. &ring->dma_base,
  79. GFP_KERNEL);
  80. @@ -642,11 +644,10 @@ static int bgmac_dma_alloc(struct bgmac
  81. for (i = 0; i < BGMAC_MAX_RX_RINGS; i++) {
  82. ring = &bgmac->rx_ring[i];
  83. - ring->num_slots = BGMAC_RX_RING_SLOTS;
  84. ring->mmio_base = ring_base[i];
  85. /* Alloc ring of descriptors */
  86. - size = ring->num_slots * sizeof(struct bgmac_dma_desc);
  87. + size = BGMAC_RX_RING_SLOTS * sizeof(struct bgmac_dma_desc);
  88. ring->cpu_base = dma_zalloc_coherent(dma_dev, size,
  89. &ring->dma_base,
  90. GFP_KERNEL);
  91. @@ -709,7 +710,7 @@ static int bgmac_dma_init(struct bgmac *
  92. ring->start = 0;
  93. ring->end = 0;
  94. - for (j = 0; j < ring->num_slots; j++) {
  95. + for (j = 0; j < BGMAC_RX_RING_SLOTS; j++) {
  96. err = bgmac_dma_rx_skb_for_slot(bgmac, &ring->slots[j]);
  97. if (err)
  98. goto error;
  99. --- a/drivers/net/ethernet/broadcom/bgmac.h
  100. +++ b/drivers/net/ethernet/broadcom/bgmac.h
  101. @@ -419,11 +419,10 @@ struct bgmac_dma_ring {
  102. u32 start;
  103. u32 end;
  104. - u16 num_slots;
  105. - u16 mmio_base;
  106. struct bgmac_dma_desc *cpu_base;
  107. dma_addr_t dma_base;
  108. u32 index_base; /* Used for unaligned rings only, otherwise 0 */
  109. + u16 mmio_base;
  110. bool unaligned;
  111. struct bgmac_slot_info slots[BGMAC_RX_RING_SLOTS];