Merge pull request #580 from wigyori/cc-libpcap
[15.05/openwrt.git] / target / linux / generic / patches-3.18 / 077-12-bgmac-drop-ring-num_slots.patch
1 From: Felix Fietkau <nbd@openwrt.org>
2 Date: Sun, 12 Apr 2015 23:28:38 +0200
3 Subject: [PATCH] bgmac: drop ring->num_slots
4
5 The ring size is always known at compile time, so make the code a bit
6 more efficient
7
8 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 ---
10
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;
15         u32 ctl1;
16  
17 -       if (i == ring->num_slots - 1)
18 +       if (i == BGMAC_TX_RING_SLOTS - 1)
19                 ctl0 |= BGMAC_DESC_CTL0_EOT;
20  
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;
25  
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;
33         int i;
34  
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;
38  
39                 slot = &ring->slots[i];
40 @@ -546,7 +546,7 @@ static void bgmac_dma_rx_ring_free(struc
41         struct bgmac_slot_info *slot;
42         int i;
43  
44 -       for (i = 0; i < ring->num_slots; i++) {
45 +       for (i = 0; i < BGMAC_RX_RING_SLOTS; i++) {
46                 slot = &ring->slots[i];
47                 if (!slot->dma_addr)
48                         continue;
49 @@ -560,7 +560,8 @@ static void bgmac_dma_rx_ring_free(struc
50  }
51  
52  static void bgmac_dma_ring_desc_free(struct bgmac *bgmac,
53 -                                    struct bgmac_dma_ring *ring)
54 +                                    struct bgmac_dma_ring *ring,
55 +                                    int num_slots)
56  {
57         struct device *dma_dev = bgmac->core->dma_dev;
58         int size;
59 @@ -569,7 +570,7 @@ static void bgmac_dma_ring_desc_free(str
60             return;
61  
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,
66                           ring->dma_base);
67  }
68 @@ -590,10 +591,12 @@ static void bgmac_dma_free(struct bgmac
69         int i;
70  
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);
75  
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);
80  }
81  
82  static int bgmac_dma_alloc(struct bgmac *bgmac)
83 @@ -616,11 +619,10 @@ static int bgmac_dma_alloc(struct bgmac
84  
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];
89  
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,
94                                                      &ring->dma_base,
95                                                      GFP_KERNEL);
96 @@ -642,11 +644,10 @@ static int bgmac_dma_alloc(struct bgmac
97  
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];
102  
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,
107                                                      &ring->dma_base,
108                                                      GFP_KERNEL);
109 @@ -709,7 +710,7 @@ static int bgmac_dma_init(struct bgmac *
110  
111                 ring->start = 0;
112                 ring->end = 0;
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]);
116                         if (err)
117                                 goto error;
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 {
121         u32 start;
122         u32 end;
123  
124 -       u16 num_slots;
125 -       u16 mmio_base;
126         struct bgmac_dma_desc *cpu_base;
127         dma_addr_t dma_base;
128         u32 index_base; /* Used for unaligned rings only, otherwise 0 */
129 +       u16 mmio_base;
130         bool unaligned;
131  
132         struct bgmac_slot_info slots[BGMAC_RX_RING_SLOTS];