[package] kernel: added GPIO driver for CS5535/CS5536 companion chip. Thanks Markus...
[openwrt.git] / package / mac80211 / patches / 401-ath9k-introduce-bus-specific-DMA-routines.patch
1 From d6f9b4eb74f8be1be90ee315ed3895e6b0265c42 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Fri, 2 Jan 2009 16:07:21 +0100
4 Subject: [RFC 01/12] ath9k: introduce bus specific DMA routines
5
6 In the AR913x SoCs, the WMAC devices are connected to the CPU through
7 the internal AHB bus instead of PCI. We first patch ath9k driver to use
8 replaceable DMA routines, so we can use different code for the AHB bus.
9
10 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
11 Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
12 ---
13  drivers/net/wireless/ath9k/beacon.c |   29 +++++---------
14  drivers/net/wireless/ath9k/core.h   |   75 +++++++++++++++++++++++++++++++++++
15  drivers/net/wireless/ath9k/main.c   |   71 +++++++++++++++++++++++++++++---
16  drivers/net/wireless/ath9k/recv.c   |   30 ++++++--------
17  drivers/net/wireless/ath9k/xmit.c   |   12 ++----
18  5 files changed, 166 insertions(+), 51 deletions(-)
19
20 --- a/drivers/net/wireless/ath9k/beacon.c
21 +++ b/drivers/net/wireless/ath9k/beacon.c
22 @@ -164,9 +164,7 @@ static struct ath_buf *ath_beacon_genera
23         bf = avp->av_bcbuf;
24         skb = (struct sk_buff *)bf->bf_mpdu;
25         if (skb) {
26 -               pci_unmap_single(sc->pdev, bf->bf_dmacontext,
27 -                                skb->len,
28 -                                PCI_DMA_TODEVICE);
29 +               ath_unmap_single_to_device(sc, bf->bf_dmacontext, skb->len);
30                 dev_kfree_skb_any(skb);
31         }
32  
33 @@ -188,14 +186,12 @@ static struct ath_buf *ath_beacon_genera
34         }
35  
36         bf->bf_buf_addr = bf->bf_dmacontext =
37 -               pci_map_single(sc->pdev, skb->data,
38 -                              skb->len,
39 -                              PCI_DMA_TODEVICE);
40 -       if (unlikely(pci_dma_mapping_error(sc->pdev, bf->bf_buf_addr))) {
41 +               ath_map_single_to_device(sc, skb->data, skb->len);
42 +       if (unlikely(ath_dma_mapping_error(sc, bf->bf_buf_addr))) {
43                 dev_kfree_skb_any(skb);
44                 bf->bf_mpdu = NULL;
45                 DPRINTF(sc, ATH_DBG_CONFIG,
46 -                       "pci_dma_mapping_error() on beaconing\n");
47 +                       "dma_mapping_error() on beaconing\n");
48                 return NULL;
49         }
50  
51 @@ -343,9 +339,7 @@ int ath_beacon_alloc(struct ath_softc *s
52         bf = avp->av_bcbuf;
53         if (bf->bf_mpdu != NULL) {
54                 skb = (struct sk_buff *)bf->bf_mpdu;
55 -               pci_unmap_single(sc->pdev, bf->bf_dmacontext,
56 -                                skb->len,
57 -                                PCI_DMA_TODEVICE);
58 +               ath_unmap_single_to_device(sc, bf->bf_dmacontext, skb->len);
59                 dev_kfree_skb_any(skb);
60                 bf->bf_mpdu = NULL;
61         }
62 @@ -402,14 +396,12 @@ int ath_beacon_alloc(struct ath_softc *s
63  
64         bf->bf_mpdu = skb;
65         bf->bf_buf_addr = bf->bf_dmacontext =
66 -               pci_map_single(sc->pdev, skb->data,
67 -                              skb->len,
68 -                              PCI_DMA_TODEVICE);
69 -       if (unlikely(pci_dma_mapping_error(sc->pdev, bf->bf_buf_addr))) {
70 +               ath_map_single_to_device(sc, skb->data, skb->len);
71 +       if (unlikely(ath_dma_mapping_error(sc, bf->bf_buf_addr))) {
72                 dev_kfree_skb_any(skb);
73                 bf->bf_mpdu = NULL;
74                 DPRINTF(sc, ATH_DBG_CONFIG,
75 -                       "pci_dma_mapping_error() on beacon alloc\n");
76 +                       "dma_mapping_error() on beacon alloc\n");
77                 return -ENOMEM;
78         }
79  
80 @@ -429,9 +421,8 @@ void ath_beacon_return(struct ath_softc 
81                 bf = avp->av_bcbuf;
82                 if (bf->bf_mpdu != NULL) {
83                         struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
84 -                       pci_unmap_single(sc->pdev, bf->bf_dmacontext,
85 -                                        skb->len,
86 -                                        PCI_DMA_TODEVICE);
87 +                       ath_unmap_single_to_device(sc, bf->bf_dmacontext,
88 +                                                  skb->len);
89                         dev_kfree_skb_any(skb);
90                         bf->bf_mpdu = NULL;
91                 }
92 --- a/drivers/net/wireless/ath9k/core.h
93 +++ b/drivers/net/wireless/ath9k/core.h
94 @@ -693,6 +693,33 @@ enum PROT_MODE {
95  #define SC_OP_RFKILL_SW_BLOCKED        BIT(12)
96  #define SC_OP_RFKILL_HW_BLOCKED        BIT(13)
97  
98 +struct ath_bus_ops {
99 +       dma_addr_t      (*dma_map_single_to_device)(struct ath_softc *sc,
100 +                                               void *p,
101 +                                               size_t size);
102 +       void            (*dma_unmap_single_to_device)(struct ath_softc *sc,
103 +                                                     dma_addr_t da,
104 +                                                     size_t size);
105 +       dma_addr_t      (*dma_map_single_from_device)(struct ath_softc *sc,
106 +                                                     void *p,
107 +                                                     size_t size);
108 +       void            (*dma_unmap_single_from_device)(struct ath_softc *sc,
109 +                                                       dma_addr_t da,
110 +                                                       size_t size);
111 +       int             (*dma_mapping_error)(struct ath_softc *sc,
112 +                                            dma_addr_t da);
113 +       void            (*dma_sync_single_for_cpu)(struct ath_softc *sc,
114 +                                                  dma_addr_t da,
115 +                                                  size_t size);
116 +       void            *(*dma_alloc)(struct ath_softc *sc,
117 +                                     size_t size,
118 +                                     dma_addr_t *pda);
119 +       void            (*dma_free)(struct ath_softc *sc,
120 +                                   size_t size,
121 +                                   void *p,
122 +                                   dma_addr_t da);
123 +};
124 +
125  struct ath_softc {
126         struct ieee80211_hw *hw;
127         struct pci_dev *pdev;
128 @@ -744,6 +771,7 @@ struct ath_softc {
129  #ifdef CONFIG_ATH9K_DEBUG
130         struct ath9k_debug sc_debug;
131  #endif
132 +       struct ath_bus_ops *bus_ops;
133  };
134  
135  int ath_reset(struct ath_softc *sc, bool retry_tx);
136 @@ -751,4 +779,51 @@ int ath_get_hal_qnum(u16 queue, struct a
137  int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc);
138  int ath_cabq_update(struct ath_softc *);
139  
140 +static inline dma_addr_t ath_map_single_to_device(struct ath_softc *sc,
141 +                                                 void *p, size_t size)
142 +{
143 +       return sc->bus_ops->dma_map_single_to_device(sc, p, size);
144 +}
145 +
146 +static inline void ath_unmap_single_to_device(struct ath_softc *sc,
147 +                                             dma_addr_t da, size_t size)
148 +{
149 +       sc->bus_ops->dma_unmap_single_to_device(sc, da, size);
150 +}
151 +
152 +static inline dma_addr_t ath_map_single_from_device(struct ath_softc *sc,
153 +                                                   void *p, size_t size)
154 +{
155 +       return sc->bus_ops->dma_map_single_from_device(sc, p, size);
156 +}
157 +
158 +static inline void ath_unmap_single_from_device(struct ath_softc *sc,
159 +                                               dma_addr_t da, size_t size)
160 +{
161 +       sc->bus_ops->dma_unmap_single_from_device(sc, da, size);
162 +}
163 +
164 +static inline int ath_dma_mapping_error(struct ath_softc *sc, dma_addr_t da)
165 +{
166 +       return sc->bus_ops->dma_mapping_error(sc, da);
167 +}
168 +
169 +static inline void ath_sync_single_for_cpu(struct ath_softc *sc, dma_addr_t da,
170 +                                          size_t size)
171 +{
172 +       sc->bus_ops->dma_sync_single_for_cpu(sc, da, size);
173 +}
174 +
175 +static inline void *ath_dma_alloc(struct ath_softc *sc, size_t size,
176 +                                 dma_addr_t *pda)
177 +{
178 +       return sc->bus_ops->dma_alloc(sc, size, pda);
179 +}
180 +
181 +static inline void ath_dma_free(struct ath_softc *sc, size_t size,
182 +                               void *p, dma_addr_t da)
183 +{
184 +       sc->bus_ops->dma_free(sc, size, p, da);
185 +}
186 +
187  #endif /* CORE_H */
188 --- a/drivers/net/wireless/ath9k/main.c
189 +++ b/drivers/net/wireless/ath9k/main.c
190 @@ -1722,9 +1722,7 @@ int ath_descdma_setup(struct ath_softc *
191         }
192  
193         /* allocate descriptors */
194 -       dd->dd_desc = pci_alloc_consistent(sc->pdev,
195 -                             dd->dd_desc_len,
196 -                             &dd->dd_desc_paddr);
197 +       dd->dd_desc = ath_dma_alloc(sc, dd->dd_desc_len, &dd->dd_desc_paddr);
198         if (dd->dd_desc == NULL) {
199                 error = -ENOMEM;
200                 goto fail;
201 @@ -1770,8 +1768,7 @@ int ath_descdma_setup(struct ath_softc *
202         }
203         return 0;
204  fail2:
205 -       pci_free_consistent(sc->pdev,
206 -               dd->dd_desc_len, dd->dd_desc, dd->dd_desc_paddr);
207 +       ath_dma_free(sc, dd->dd_desc_len, dd->dd_desc, dd->dd_desc_paddr);
208  fail:
209         memset(dd, 0, sizeof(*dd));
210         return error;
211 @@ -1784,8 +1781,7 @@ void ath_descdma_cleanup(struct ath_soft
212                          struct ath_descdma *dd,
213                          struct list_head *head)
214  {
215 -       pci_free_consistent(sc->pdev,
216 -               dd->dd_desc_len, dd->dd_desc, dd->dd_desc_paddr);
217 +       ath_dma_free(sc, dd->dd_desc_len, dd->dd_desc, dd->dd_desc_paddr);
218  
219         INIT_LIST_HEAD(head);
220         kfree(dd->dd_bufptr);
221 @@ -2551,6 +2547,66 @@ ath_rf_name(u16 rf_version)
222         return "????";
223  }
224  
225 +static dma_addr_t ath_pci_map_single_to_device(struct ath_softc *sc,
226 +                                              void *p, size_t size)
227 +{
228 +       return pci_map_single(sc->pdev, p, size, PCI_DMA_TODEVICE);
229 +}
230 +
231 +static void ath_pci_unmap_single_to_device(struct ath_softc *sc,
232 +                                          dma_addr_t da, size_t size)
233 +{
234 +       pci_unmap_single(sc->pdev, da, size, PCI_DMA_TODEVICE);
235 +}
236 +
237 +static dma_addr_t ath_pci_map_single_from_device(struct ath_softc *sc,
238 +                                                void *p, size_t size)
239 +{
240 +       return pci_map_single(sc->pdev, p, size, PCI_DMA_FROMDEVICE);
241 +}
242 +
243 +static void ath_pci_unmap_single_from_device(struct ath_softc *sc,
244 +                                            dma_addr_t da, size_t size)
245 +{
246 +       pci_unmap_single(sc->pdev, da, size, PCI_DMA_FROMDEVICE);
247 +}
248 +
249 +static int ath_pci_dma_mapping_error(struct ath_softc *sc, dma_addr_t da)
250 +{
251 +       return pci_dma_mapping_error(sc->pdev, da);
252 +}
253 +
254 +static void ath_pci_sync_single_for_cpu(struct ath_softc *sc, dma_addr_t da,
255 +                                      size_t size)
256 +{
257 +       pci_dma_sync_single_for_cpu(sc->pdev, da, size,
258 +                                   PCI_DMA_FROMDEVICE);
259 +}
260 +
261 +static void *ath_pci_dma_alloc(struct ath_softc *sc, size_t size,
262 +                                      dma_addr_t *pda)
263 +{
264 +       return pci_alloc_consistent(sc->pdev, size, pda);
265 +}
266 +
267 +static void ath_pci_dma_free(struct ath_softc *sc, size_t size,
268 +                                   void *p, dma_addr_t da)
269 +{
270 +       pci_free_consistent(sc->pdev, size, p, da);
271 +}
272 +
273 +static struct ath_bus_ops ath_pci_bus_ops  = {
274 +       .dma_map_single_to_device = ath_pci_map_single_to_device,
275 +       .dma_unmap_single_to_device = ath_pci_unmap_single_to_device,
276 +       .dma_map_single_from_device = ath_pci_map_single_from_device,
277 +       .dma_unmap_single_from_device = ath_pci_unmap_single_from_device,
278 +       .dma_map_single_to_device = ath_pci_map_single_to_device,
279 +       .dma_mapping_error = ath_pci_dma_mapping_error,
280 +       .dma_sync_single_for_cpu = ath_pci_sync_single_for_cpu,
281 +       .dma_alloc = ath_pci_dma_alloc,
282 +       .dma_free = ath_pci_dma_free,
283 +};
284 +
285  static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
286  {
287         void __iomem *mem;
288 @@ -2639,6 +2695,7 @@ static int ath_pci_probe(struct pci_dev 
289         sc->hw = hw;
290         sc->pdev = pdev;
291         sc->mem = mem;
292 +       sc->bus_ops = &ath_pci_bus_ops;
293  
294         if (ath_attach(id->device, sc) != 0) {
295                 ret = -ENODEV;
296 --- a/drivers/net/wireless/ath9k/recv.c
297 +++ b/drivers/net/wireless/ath9k/recv.c
298 @@ -291,15 +291,14 @@ int ath_rx_init(struct ath_softc *sc, in
299                         }
300  
301                         bf->bf_mpdu = skb;
302 -                       bf->bf_buf_addr = pci_map_single(sc->pdev, skb->data,
303 -                                                        sc->rx.bufsize,
304 -                                                        PCI_DMA_FROMDEVICE);
305 -                       if (unlikely(pci_dma_mapping_error(sc->pdev,
306 -                                 bf->bf_buf_addr))) {
307 +                       bf->bf_buf_addr = ath_map_single_from_device(sc,
308 +                                               skb->data, sc->rx.bufsize);
309 +                       if (unlikely(ath_dma_mapping_error(sc,
310 +                                               bf->bf_buf_addr))) {
311                                 dev_kfree_skb_any(skb);
312                                 bf->bf_mpdu = NULL;
313                                 DPRINTF(sc, ATH_DBG_CONFIG,
314 -                                       "pci_dma_mapping_error() on RX init\n");
315 +                                       "dma_mapping_error() on RX init\n");
316                                 error = -ENOMEM;
317                                 break;
318                         }
319 @@ -524,9 +523,7 @@ int ath_rx_tasklet(struct ath_softc *sc,
320                  * 1. accessing the frame
321                  * 2. requeueing the same buffer to h/w
322                  */
323 -               pci_dma_sync_single_for_cpu(sc->pdev, bf->bf_buf_addr,
324 -                               sc->rx.bufsize,
325 -                               PCI_DMA_FROMDEVICE);
326 +               ath_sync_single_for_cpu(sc, bf->bf_buf_addr, sc->rx.bufsize);
327  
328                 /*
329                  * If we're asked to flush receive queue, directly
330 @@ -557,9 +554,8 @@ int ath_rx_tasklet(struct ath_softc *sc,
331                         goto requeue;
332  
333                 /* Unmap the frame */
334 -               pci_unmap_single(sc->pdev, bf->bf_buf_addr,
335 -                                sc->rx.bufsize,
336 -                                PCI_DMA_FROMDEVICE);
337 +               ath_unmap_single_from_device(sc, bf->bf_buf_addr,
338 +                                            sc->rx.bufsize);
339  
340                 skb_put(skb, ds->ds_rxstat.rs_datalen);
341                 skb->protocol = cpu_to_be16(ETH_P_CONTROL);
342 @@ -599,15 +595,15 @@ int ath_rx_tasklet(struct ath_softc *sc,
343  
344                 /* We will now give hardware our shiny new allocated skb */
345                 bf->bf_mpdu = requeue_skb;
346 -               bf->bf_buf_addr = pci_map_single(sc->pdev, requeue_skb->data,
347 -                                        sc->rx.bufsize,
348 -                                        PCI_DMA_FROMDEVICE);
349 -               if (unlikely(pci_dma_mapping_error(sc->pdev,
350 +               bf->bf_buf_addr = ath_map_single_from_device(sc,
351 +                                               requeue_skb->data,
352 +                                               sc->rx.bufsize);
353 +               if (unlikely(ath_dma_mapping_error(sc,
354                           bf->bf_buf_addr))) {
355                         dev_kfree_skb_any(requeue_skb);
356                         bf->bf_mpdu = NULL;
357                         DPRINTF(sc, ATH_DBG_CONFIG,
358 -                               "pci_dma_mapping_error() on RX\n");
359 +                               "dma_mapping_error() on RX\n");
360                         break;
361                 }
362                 bf->bf_dmacontext = bf->bf_buf_addr;
363 --- a/drivers/net/wireless/ath9k/xmit.c
364 +++ b/drivers/net/wireless/ath9k/xmit.c
365 @@ -340,10 +340,7 @@ static void ath_tx_complete_buf(struct a
366         }
367  
368         /* Unmap this frame */
369 -       pci_unmap_single(sc->pdev,
370 -                        bf->bf_dmacontext,
371 -                        skb->len,
372 -                        PCI_DMA_TODEVICE);
373 +       ath_unmap_single_to_device(sc, bf->bf_dmacontext, skb->len);
374         /* complete this frame */
375         ath_tx_complete(sc, skb, &tx_status);
376  
377 @@ -1713,12 +1710,11 @@ static int ath_tx_setup_buffer(struct at
378         /* DMA setup */
379         bf->bf_mpdu = skb;
380  
381 -       bf->bf_dmacontext = pci_map_single(sc->pdev, skb->data,
382 -                                          skb->len, PCI_DMA_TODEVICE);
383 -       if (unlikely(pci_dma_mapping_error(sc->pdev, bf->bf_dmacontext))) {
384 +       bf->bf_dmacontext = ath_map_single_to_device(sc, skb->data, skb->len);
385 +       if (unlikely(ath_dma_mapping_error(sc, bf->bf_dmacontext))) {
386                 bf->bf_mpdu = NULL;
387                 DPRINTF(sc, ATH_DBG_CONFIG,
388 -                       "pci_dma_mapping_error() on TX\n");
389 +                       "dma_mapping_error() on TX\n");
390                 return -ENOMEM;
391         }
392