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
5 The ring size is always known at compile time, so make the code a bit
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 --- a/drivers/net/ethernet/broadcom/bgmac.c
12 +++ b/drivers/net/ethernet/broadcom/bgmac.c
13 @@ -123,7 +123,7 @@ bgmac_dma_tx_add_buf(struct bgmac *bgmac
14 struct bgmac_dma_desc *dma_desc;
17 - if (i == ring->num_slots - 1)
18 + if (i == BGMAC_TX_RING_SLOTS - 1)
19 ctl0 |= BGMAC_DESC_CTL0_EOT;
21 ctl1 = len & BGMAC_DESC_CTL1_LEN;
22 @@ -382,7 +382,7 @@ static void bgmac_dma_rx_setup_desc(stru
23 struct bgmac_dma_desc *dma_desc = ring->cpu_base + desc_idx;
24 u32 ctl0 = 0, ctl1 = 0;
26 - if (desc_idx == ring->num_slots - 1)
27 + if (desc_idx == BGMAC_RX_RING_SLOTS - 1)
28 ctl0 |= BGMAC_DESC_CTL0_EOT;
29 ctl1 |= BGMAC_RX_BUF_SIZE & BGMAC_DESC_CTL1_LEN;
30 /* Is there any BGMAC device that requires extension? */
31 @@ -521,7 +521,7 @@ static void bgmac_dma_tx_ring_free(struc
32 struct bgmac_slot_info *slot;
35 - for (i = 0; i < ring->num_slots; i++) {
36 + for (i = 0; i < BGMAC_TX_RING_SLOTS; i++) {
37 int len = dma_desc[i].ctl1 & BGMAC_DESC_CTL1_LEN;
39 slot = &ring->slots[i];
40 @@ -546,7 +546,7 @@ static void bgmac_dma_rx_ring_free(struc
41 struct bgmac_slot_info *slot;
44 - for (i = 0; i < ring->num_slots; i++) {
45 + for (i = 0; i < BGMAC_RX_RING_SLOTS; i++) {
46 slot = &ring->slots[i];
49 @@ -560,7 +560,8 @@ static void bgmac_dma_rx_ring_free(struc
52 static void bgmac_dma_ring_desc_free(struct bgmac *bgmac,
53 - struct bgmac_dma_ring *ring)
54 + struct bgmac_dma_ring *ring,
57 struct device *dma_dev = bgmac->core->dma_dev;
59 @@ -569,7 +570,7 @@ static void bgmac_dma_ring_desc_free(str
62 /* Free ring of descriptors */
63 - size = ring->num_slots * sizeof(struct bgmac_dma_desc);
64 + size = num_slots * sizeof(struct bgmac_dma_desc);
65 dma_free_coherent(dma_dev, size, ring->cpu_base,
68 @@ -590,10 +591,12 @@ static void bgmac_dma_free(struct bgmac
71 for (i = 0; i < BGMAC_MAX_TX_RINGS; i++)
72 - bgmac_dma_ring_desc_free(bgmac, &bgmac->tx_ring[i]);
73 + bgmac_dma_ring_desc_free(bgmac, &bgmac->tx_ring[i],
74 + BGMAC_TX_RING_SLOTS);
76 for (i = 0; i < BGMAC_MAX_RX_RINGS; i++)
77 - bgmac_dma_ring_desc_free(bgmac, &bgmac->rx_ring[i]);
78 + bgmac_dma_ring_desc_free(bgmac, &bgmac->rx_ring[i],
79 + BGMAC_RX_RING_SLOTS);
82 static int bgmac_dma_alloc(struct bgmac *bgmac)
83 @@ -616,11 +619,10 @@ static int bgmac_dma_alloc(struct bgmac
85 for (i = 0; i < BGMAC_MAX_TX_RINGS; i++) {
86 ring = &bgmac->tx_ring[i];
87 - ring->num_slots = BGMAC_TX_RING_SLOTS;
88 ring->mmio_base = ring_base[i];
90 /* Alloc ring of descriptors */
91 - size = ring->num_slots * sizeof(struct bgmac_dma_desc);
92 + size = BGMAC_TX_RING_SLOTS * sizeof(struct bgmac_dma_desc);
93 ring->cpu_base = dma_zalloc_coherent(dma_dev, size,
96 @@ -642,11 +644,10 @@ static int bgmac_dma_alloc(struct bgmac
98 for (i = 0; i < BGMAC_MAX_RX_RINGS; i++) {
99 ring = &bgmac->rx_ring[i];
100 - ring->num_slots = BGMAC_RX_RING_SLOTS;
101 ring->mmio_base = ring_base[i];
103 /* Alloc ring of descriptors */
104 - size = ring->num_slots * sizeof(struct bgmac_dma_desc);
105 + size = BGMAC_RX_RING_SLOTS * sizeof(struct bgmac_dma_desc);
106 ring->cpu_base = dma_zalloc_coherent(dma_dev, size,
109 @@ -709,7 +710,7 @@ static int bgmac_dma_init(struct bgmac *
113 - for (j = 0; j < ring->num_slots; j++) {
114 + for (j = 0; j < BGMAC_RX_RING_SLOTS; j++) {
115 err = bgmac_dma_rx_skb_for_slot(bgmac, &ring->slots[j]);
118 --- a/drivers/net/ethernet/broadcom/bgmac.h
119 +++ b/drivers/net/ethernet/broadcom/bgmac.h
120 @@ -419,11 +419,10 @@ struct bgmac_dma_ring {
126 struct bgmac_dma_desc *cpu_base;
128 u32 index_base; /* Used for unaligned rings only, otherwise 0 */
132 struct bgmac_slot_info slots[BGMAC_RX_RING_SLOTS];