1
0

077-10-bgmac-simplify-dma-init-cleanup.patch 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Date: Sun, 12 Apr 2015 23:19:32 +0200
  3. Subject: [PATCH] bgmac: simplify dma init/cleanup
  4. Instead of allocating buffers at device init time and initializing
  5. descriptors at device open, do both at the same time (during open).
  6. Free all buffers when closing the device.
  7. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  8. ---
  9. --- a/drivers/net/ethernet/broadcom/bgmac.c
  10. +++ b/drivers/net/ethernet/broadcom/bgmac.c
  11. @@ -562,18 +562,26 @@ static void bgmac_dma_ring_desc_free(str
  12. ring->dma_base);
  13. }
  14. -static void bgmac_dma_free(struct bgmac *bgmac)
  15. +static void bgmac_dma_cleanup(struct bgmac *bgmac)
  16. {
  17. int i;
  18. - for (i = 0; i < BGMAC_MAX_TX_RINGS; i++) {
  19. + for (i = 0; i < BGMAC_MAX_TX_RINGS; i++)
  20. bgmac_dma_tx_ring_free(bgmac, &bgmac->tx_ring[i]);
  21. - bgmac_dma_ring_desc_free(bgmac, &bgmac->tx_ring[i]);
  22. - }
  23. - for (i = 0; i < BGMAC_MAX_RX_RINGS; i++) {
  24. +
  25. + for (i = 0; i < BGMAC_MAX_RX_RINGS; i++)
  26. bgmac_dma_rx_ring_free(bgmac, &bgmac->rx_ring[i]);
  27. +}
  28. +
  29. +static void bgmac_dma_free(struct bgmac *bgmac)
  30. +{
  31. + int i;
  32. +
  33. + for (i = 0; i < BGMAC_MAX_TX_RINGS; i++)
  34. + bgmac_dma_ring_desc_free(bgmac, &bgmac->tx_ring[i]);
  35. +
  36. + for (i = 0; i < BGMAC_MAX_RX_RINGS; i++)
  37. bgmac_dma_ring_desc_free(bgmac, &bgmac->rx_ring[i]);
  38. - }
  39. }
  40. static int bgmac_dma_alloc(struct bgmac *bgmac)
  41. @@ -621,8 +629,6 @@ static int bgmac_dma_alloc(struct bgmac
  42. }
  43. for (i = 0; i < BGMAC_MAX_RX_RINGS; i++) {
  44. - int j;
  45. -
  46. ring = &bgmac->rx_ring[i];
  47. ring->num_slots = BGMAC_RX_RING_SLOTS;
  48. ring->mmio_base = ring_base[i];
  49. @@ -645,15 +651,6 @@ static int bgmac_dma_alloc(struct bgmac
  50. ring->index_base = lower_32_bits(ring->dma_base);
  51. else
  52. ring->index_base = 0;
  53. -
  54. - /* Alloc RX slots */
  55. - for (j = 0; j < ring->num_slots; j++) {
  56. - err = bgmac_dma_rx_skb_for_slot(bgmac, &ring->slots[j]);
  57. - if (err) {
  58. - bgmac_err(bgmac, "Can't allocate skb for slot in RX ring\n");
  59. - goto err_dma_free;
  60. - }
  61. - }
  62. }
  63. return 0;
  64. @@ -663,10 +660,10 @@ err_dma_free:
  65. return -ENOMEM;
  66. }
  67. -static void bgmac_dma_init(struct bgmac *bgmac)
  68. +static int bgmac_dma_init(struct bgmac *bgmac)
  69. {
  70. struct bgmac_dma_ring *ring;
  71. - int i;
  72. + int i, err;
  73. for (i = 0; i < BGMAC_MAX_TX_RINGS; i++) {
  74. ring = &bgmac->tx_ring[i];
  75. @@ -698,8 +695,13 @@ static void bgmac_dma_init(struct bgmac
  76. if (ring->unaligned)
  77. bgmac_dma_rx_enable(bgmac, ring);
  78. - for (j = 0; j < ring->num_slots; j++)
  79. + for (j = 0; j < ring->num_slots; j++) {
  80. + err = bgmac_dma_rx_skb_for_slot(bgmac, &ring->slots[j]);
  81. + if (err)
  82. + goto error;
  83. +
  84. bgmac_dma_rx_setup_desc(bgmac, ring, j);
  85. + }
  86. bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_RX_INDEX,
  87. ring->index_base +
  88. @@ -708,6 +710,12 @@ static void bgmac_dma_init(struct bgmac
  89. ring->start = 0;
  90. ring->end = 0;
  91. }
  92. +
  93. + return 0;
  94. +
  95. +error:
  96. + bgmac_dma_cleanup(bgmac);
  97. + return err;
  98. }
  99. /**************************************************
  100. @@ -1183,11 +1191,8 @@ static void bgmac_enable(struct bgmac *b
  101. }
  102. /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipinit */
  103. -static void bgmac_chip_init(struct bgmac *bgmac, bool full_init)
  104. +static void bgmac_chip_init(struct bgmac *bgmac)
  105. {
  106. - struct bgmac_dma_ring *ring;
  107. - int i;
  108. -
  109. /* 1 interrupt per received frame */
  110. bgmac_write(bgmac, BGMAC_INT_RECV_LAZY, 1 << BGMAC_IRL_FC_SHIFT);
  111. @@ -1205,16 +1210,7 @@ static void bgmac_chip_init(struct bgmac
  112. bgmac_write(bgmac, BGMAC_RXMAX_LENGTH, 32 + ETHER_MAX_LEN);
  113. - if (full_init) {
  114. - bgmac_dma_init(bgmac);
  115. - if (1) /* FIXME: is there any case we don't want IRQs? */
  116. - bgmac_chip_intrs_on(bgmac);
  117. - } else {
  118. - for (i = 0; i < BGMAC_MAX_RX_RINGS; i++) {
  119. - ring = &bgmac->rx_ring[i];
  120. - bgmac_dma_rx_enable(bgmac, ring);
  121. - }
  122. - }
  123. + bgmac_chip_intrs_on(bgmac);
  124. bgmac_enable(bgmac);
  125. }
  126. @@ -1274,23 +1270,27 @@ static int bgmac_open(struct net_device
  127. int err = 0;
  128. bgmac_chip_reset(bgmac);
  129. +
  130. + err = bgmac_dma_init(bgmac);
  131. + if (err)
  132. + return err;
  133. +
  134. /* Specs say about reclaiming rings here, but we do that in DMA init */
  135. - bgmac_chip_init(bgmac, true);
  136. + bgmac_chip_init(bgmac);
  137. err = request_irq(bgmac->core->irq, bgmac_interrupt, IRQF_SHARED,
  138. KBUILD_MODNAME, net_dev);
  139. if (err < 0) {
  140. bgmac_err(bgmac, "IRQ request error: %d!\n", err);
  141. - goto err_out;
  142. + bgmac_dma_cleanup(bgmac);
  143. + return err;
  144. }
  145. napi_enable(&bgmac->napi);
  146. phy_start(bgmac->phy_dev);
  147. netif_carrier_on(net_dev);
  148. -
  149. -err_out:
  150. - return err;
  151. + return 0;
  152. }
  153. static int bgmac_stop(struct net_device *net_dev)
  154. @@ -1306,6 +1306,7 @@ static int bgmac_stop(struct net_device
  155. free_irq(bgmac->core->irq, net_dev);
  156. bgmac_chip_reset(bgmac);
  157. + bgmac_dma_cleanup(bgmac);
  158. return 0;
  159. }