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
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.
10 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
11 Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
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(-)
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
24 skb = (struct sk_buff *)bf->bf_mpdu;
26 - pci_unmap_single(sc->pdev, bf->bf_dmacontext,
29 + ath_unmap_single_to_device(sc, bf->bf_dmacontext, skb->len);
30 dev_kfree_skb_any(skb);
33 @@ -188,14 +186,12 @@ static struct ath_buf *ath_beacon_genera
36 bf->bf_buf_addr = bf->bf_dmacontext =
37 - pci_map_single(sc->pdev, skb->data,
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);
45 DPRINTF(sc, ATH_DBG_CONFIG,
46 - "pci_dma_mapping_error() on beaconing\n");
47 + "dma_mapping_error() on beaconing\n");
51 @@ -343,9 +339,7 @@ int ath_beacon_alloc(struct ath_softc *s
53 if (bf->bf_mpdu != NULL) {
54 skb = (struct sk_buff *)bf->bf_mpdu;
55 - pci_unmap_single(sc->pdev, bf->bf_dmacontext,
58 + ath_unmap_single_to_device(sc, bf->bf_dmacontext, skb->len);
59 dev_kfree_skb_any(skb);
62 @@ -402,14 +396,12 @@ int ath_beacon_alloc(struct ath_softc *s
65 bf->bf_buf_addr = bf->bf_dmacontext =
66 - pci_map_single(sc->pdev, skb->data,
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);
74 DPRINTF(sc, ATH_DBG_CONFIG,
75 - "pci_dma_mapping_error() on beacon alloc\n");
76 + "dma_mapping_error() on beacon alloc\n");
80 @@ -429,9 +421,8 @@ void ath_beacon_return(struct ath_softc
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,
87 + ath_unmap_single_to_device(sc, bf->bf_dmacontext,
89 dev_kfree_skb_any(skb);
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)
99 + dma_addr_t (*dma_map_single_to_device)(struct ath_softc *sc,
102 + void (*dma_unmap_single_to_device)(struct ath_softc *sc,
105 + dma_addr_t (*dma_map_single_from_device)(struct ath_softc *sc,
108 + void (*dma_unmap_single_from_device)(struct ath_softc *sc,
111 + int (*dma_mapping_error)(struct ath_softc *sc,
113 + void (*dma_sync_single_for_cpu)(struct ath_softc *sc,
116 + void *(*dma_alloc)(struct ath_softc *sc,
119 + void (*dma_free)(struct ath_softc *sc,
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;
132 + struct ath_bus_ops *bus_ops;
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 *);
140 +static inline dma_addr_t ath_map_single_to_device(struct ath_softc *sc,
141 + void *p, size_t size)
143 + return sc->bus_ops->dma_map_single_to_device(sc, p, size);
146 +static inline void ath_unmap_single_to_device(struct ath_softc *sc,
147 + dma_addr_t da, size_t size)
149 + sc->bus_ops->dma_unmap_single_to_device(sc, da, size);
152 +static inline dma_addr_t ath_map_single_from_device(struct ath_softc *sc,
153 + void *p, size_t size)
155 + return sc->bus_ops->dma_map_single_from_device(sc, p, size);
158 +static inline void ath_unmap_single_from_device(struct ath_softc *sc,
159 + dma_addr_t da, size_t size)
161 + sc->bus_ops->dma_unmap_single_from_device(sc, da, size);
164 +static inline int ath_dma_mapping_error(struct ath_softc *sc, dma_addr_t da)
166 + return sc->bus_ops->dma_mapping_error(sc, da);
169 +static inline void ath_sync_single_for_cpu(struct ath_softc *sc, dma_addr_t da,
172 + sc->bus_ops->dma_sync_single_for_cpu(sc, da, size);
175 +static inline void *ath_dma_alloc(struct ath_softc *sc, size_t size,
178 + return sc->bus_ops->dma_alloc(sc, size, pda);
181 +static inline void ath_dma_free(struct ath_softc *sc, size_t size,
182 + void *p, dma_addr_t da)
184 + sc->bus_ops->dma_free(sc, size, p, da);
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 *
193 /* allocate descriptors */
194 - dd->dd_desc = pci_alloc_consistent(sc->pdev,
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) {
201 @@ -1770,8 +1768,7 @@ int ath_descdma_setup(struct ath_softc *
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);
209 memset(dd, 0, sizeof(*dd));
211 @@ -1784,8 +1781,7 @@ void ath_descdma_cleanup(struct ath_soft
212 struct ath_descdma *dd,
213 struct list_head *head)
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);
219 INIT_LIST_HEAD(head);
220 kfree(dd->dd_bufptr);
221 @@ -2551,6 +2547,66 @@ ath_rf_name(u16 rf_version)
225 +static dma_addr_t ath_pci_map_single_to_device(struct ath_softc *sc,
226 + void *p, size_t size)
228 + return pci_map_single(sc->pdev, p, size, PCI_DMA_TODEVICE);
231 +static void ath_pci_unmap_single_to_device(struct ath_softc *sc,
232 + dma_addr_t da, size_t size)
234 + pci_unmap_single(sc->pdev, da, size, PCI_DMA_TODEVICE);
237 +static dma_addr_t ath_pci_map_single_from_device(struct ath_softc *sc,
238 + void *p, size_t size)
240 + return pci_map_single(sc->pdev, p, size, PCI_DMA_FROMDEVICE);
243 +static void ath_pci_unmap_single_from_device(struct ath_softc *sc,
244 + dma_addr_t da, size_t size)
246 + pci_unmap_single(sc->pdev, da, size, PCI_DMA_FROMDEVICE);
249 +static int ath_pci_dma_mapping_error(struct ath_softc *sc, dma_addr_t da)
251 + return pci_dma_mapping_error(sc->pdev, da);
254 +static void ath_pci_sync_single_for_cpu(struct ath_softc *sc, dma_addr_t da,
257 + pci_dma_sync_single_for_cpu(sc->pdev, da, size,
258 + PCI_DMA_FROMDEVICE);
261 +static void *ath_pci_dma_alloc(struct ath_softc *sc, size_t size,
264 + return pci_alloc_consistent(sc->pdev, size, pda);
267 +static void ath_pci_dma_free(struct ath_softc *sc, size_t size,
268 + void *p, dma_addr_t da)
270 + pci_free_consistent(sc->pdev, size, p, da);
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,
285 static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
288 @@ -2639,6 +2695,7 @@ static int ath_pci_probe(struct pci_dev
292 + sc->bus_ops = &ath_pci_bus_ops;
294 if (ath_attach(id->device, sc) != 0) {
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
302 - bf->bf_buf_addr = pci_map_single(sc->pdev, skb->data,
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);
313 DPRINTF(sc, ATH_DBG_CONFIG,
314 - "pci_dma_mapping_error() on RX init\n");
315 + "dma_mapping_error() on RX init\n");
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
323 - pci_dma_sync_single_for_cpu(sc->pdev, bf->bf_buf_addr,
325 - PCI_DMA_FROMDEVICE);
326 + ath_sync_single_for_cpu(sc, bf->bf_buf_addr, sc->rx.bufsize);
329 * If we're asked to flush receive queue, directly
330 @@ -557,9 +554,8 @@ int ath_rx_tasklet(struct ath_softc *sc,
333 /* Unmap the frame */
334 - pci_unmap_single(sc->pdev, bf->bf_buf_addr,
336 - PCI_DMA_FROMDEVICE);
337 + ath_unmap_single_from_device(sc, bf->bf_buf_addr,
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,
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,
348 - PCI_DMA_FROMDEVICE);
349 - if (unlikely(pci_dma_mapping_error(sc->pdev,
350 + bf->bf_buf_addr = ath_map_single_from_device(sc,
353 + if (unlikely(ath_dma_mapping_error(sc,
355 dev_kfree_skb_any(requeue_skb);
357 DPRINTF(sc, ATH_DBG_CONFIG,
358 - "pci_dma_mapping_error() on RX\n");
359 + "dma_mapping_error() on RX\n");
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
368 /* Unmap this frame */
369 - pci_unmap_single(sc->pdev,
373 + ath_unmap_single_to_device(sc, bf->bf_dmacontext, skb->len);
374 /* complete this frame */
375 ath_tx_complete(sc, skb, &tx_status);
377 @@ -1713,12 +1710,11 @@ static int ath_tx_setup_buffer(struct at
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))) {
387 DPRINTF(sc, ATH_DBG_CONFIG,
388 - "pci_dma_mapping_error() on TX\n");
389 + "dma_mapping_error() on TX\n");