ead: fix array overrun
[openwrt.git] / package / mac80211 / patches / 407-ath9k-introduce-platform-driver-for-AHB-bus-support.patch
1 From 9456893748c407d9fed06046308177edaca38450 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Fri, 2 Jan 2009 16:12:30 +0100
4 Subject: [RFC 07/12] ath9k: introduce platform driver for AHB bus support
5
6 This patch adds the platform_driver itself, and modifies the main driver
7 to register it.
8
9 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
10 Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
11 ---
12 drivers/net/wireless/ath9k/Makefile | 1 +
13 drivers/net/wireless/ath9k/ahb.c | 258 +++++++++++++++++++++++++++++++++++
14 drivers/net/wireless/ath9k/core.h | 8 +
15 drivers/net/wireless/ath9k/main.c | 10 ++
16 4 files changed, 277 insertions(+), 0 deletions(-)
17
18 --- a/drivers/net/wireless/ath9k/Makefile
19 +++ b/drivers/net/wireless/ath9k/Makefile
20 @@ -12,6 +12,7 @@ ath9k-y += hw.o \
21 rc.o
22
23 ath9k-$(CONFIG_PCI) += pci.o
24 +ath9k-$(CONFIG_ATHEROS_AR71XX) += ahb.o
25 ath9k-$(CONFIG_ATH9K_DEBUG) += debug.o
26
27 obj-$(CONFIG_ATH9K) += ath9k.o
28 --- /dev/null
29 +++ b/drivers/net/wireless/ath9k/ahb.c
30 @@ -0,0 +1,258 @@
31 +/*
32 + * Copyright (c) 2008 Atheros Communications Inc.
33 + * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
34 + * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
35 + *
36 + * Permission to use, copy, modify, and/or distribute this software for any
37 + * purpose with or without fee is hereby granted, provided that the above
38 + * copyright notice and this permission notice appear in all copies.
39 + *
40 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
41 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
42 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
43 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
44 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
45 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
46 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
47 + */
48 +
49 +#include <linux/nl80211.h>
50 +#include <linux/platform_device.h>
51 +#include "core.h"
52 +#include "reg.h"
53 +#include "hw.h"
54 +
55 +static dma_addr_t ath_ahb_map_single_to_device(struct ath_softc *sc,
56 + void *p, size_t size)
57 +{
58 + return dma_map_single(NULL, p, size, DMA_TO_DEVICE);
59 +}
60 +
61 +static void ath_ahb_unmap_single_to_device(struct ath_softc *sc,
62 + dma_addr_t da, size_t size)
63 +{
64 + dma_unmap_single(NULL, da, size, DMA_TO_DEVICE);
65 +}
66 +
67 +static dma_addr_t ath_ahb_map_single_from_device(struct ath_softc *sc,
68 + void *p, size_t size)
69 +{
70 + return dma_map_single(NULL, p, size, DMA_FROM_DEVICE);
71 +}
72 +
73 +static void ath_ahb_unmap_single_from_device(struct ath_softc *sc,
74 + dma_addr_t da, size_t size)
75 +{
76 + dma_unmap_single(NULL, da, size, DMA_FROM_DEVICE);
77 +}
78 +
79 +static int ath_ahb_dma_mapping_error(struct ath_softc *sc, dma_addr_t da)
80 +{
81 + return dma_mapping_error(NULL, da);
82 +}
83 +
84 +static void ath_ahb_sync_single_for_cpu(struct ath_softc *sc, dma_addr_t da,
85 + size_t size)
86 +{
87 + dma_sync_single_for_cpu(NULL, da, size, DMA_FROM_DEVICE);
88 +}
89 +
90 +static void *ath_ahb_dma_alloc(struct ath_softc *sc, size_t size,
91 + dma_addr_t *pda)
92 +{
93 + return dma_alloc_coherent(NULL, size, pda, GFP_KERNEL);
94 +}
95 +
96 +static void ath_ahb_dma_free(struct ath_softc *sc, size_t size, void *p,
97 + dma_addr_t da)
98 +{
99 + dma_free_coherent(NULL, size, p, da);
100 +}
101 +
102 +static void ath_ahb_reg_write(struct ath_hal *ah, unsigned reg, u32 val)
103 +{
104 + __raw_writel(val, ah->ah_sh + reg);
105 +}
106 +
107 +static u32 ath_ahb_reg_read(struct ath_hal *ah, unsigned reg)
108 +{
109 + return __raw_readl(ah->ah_sh + reg);
110 +}
111 +
112 +/* return bus cachesize in 4B word units */
113 +static void ath_ahb_read_cachesize(struct ath_softc *sc, int *csz)
114 +{
115 + *csz = L1_CACHE_BYTES >> 2;
116 +}
117 +
118 +static void ath_ahb_cleanup(struct ath_softc *sc)
119 +{
120 + struct platform_device *pdev = to_platform_device(sc->dev);
121 + struct ieee80211_hw *hw = sc->hw;
122 + struct resource *res;
123 +
124 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
125 + if (res)
126 + free_irq(res->start, sc);
127 +
128 + ath_detach(sc);
129 + iounmap(sc->mem);
130 + ieee80211_free_hw(hw);
131 + platform_set_drvdata(pdev, NULL);
132 +}
133 +
134 +static struct ath_bus_ops ath_ahb_bus_ops = {
135 + .dma_map_single_to_device = ath_ahb_map_single_to_device,
136 + .dma_unmap_single_to_device = ath_ahb_unmap_single_to_device,
137 + .dma_map_single_from_device = ath_ahb_map_single_from_device,
138 + .dma_unmap_single_from_device = ath_ahb_unmap_single_from_device,
139 + .dma_map_single_to_device = ath_ahb_map_single_to_device,
140 + .dma_mapping_error = ath_ahb_dma_mapping_error,
141 + .dma_sync_single_for_cpu = ath_ahb_sync_single_for_cpu,
142 + .dma_alloc = ath_ahb_dma_alloc,
143 + .dma_free = ath_ahb_dma_free,
144 +
145 + .reg_read = ath_ahb_reg_read,
146 + .reg_write = ath_ahb_reg_write,
147 +
148 + .read_cachesize = ath_ahb_read_cachesize,
149 +
150 + .cleanup = ath_ahb_cleanup,
151 +};
152 +
153 +static int ath_ahb_probe(struct platform_device *pdev)
154 +{
155 + void __iomem *mem;
156 + struct ath_softc *sc;
157 + struct ieee80211_hw *hw;
158 + struct resource *res;
159 + int irq;
160 + int ret = 0;
161 + struct ath_hal *ah;
162 +
163 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
164 + if (res == NULL) {
165 + dev_err(&pdev->dev, "no memory resource found\n");
166 + ret = -ENXIO;
167 + goto err_out;
168 + }
169 +
170 + mem = ioremap_nocache(res->start, res->end - res->start + 1);
171 + if (mem == NULL) {
172 + dev_err(&pdev->dev, "ioremap failed\n");
173 + ret = -ENOMEM;
174 + goto err_out;
175 + }
176 +
177 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
178 + if (res == NULL) {
179 + dev_err(&pdev->dev, "no IRQ resource found\n");
180 + ret = -ENXIO;
181 + goto err_iounmap;
182 + }
183 +
184 + irq = res->start;
185 +
186 + hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
187 + if (hw == NULL) {
188 + dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
189 + ret = -ENOMEM;
190 + goto err_iounmap;
191 + }
192 +
193 + hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
194 + IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
195 + IEEE80211_HW_SIGNAL_DBM |
196 + IEEE80211_HW_NOISE_DBM;
197 +
198 + hw->wiphy->interface_modes =
199 + BIT(NL80211_IFTYPE_AP) |
200 + BIT(NL80211_IFTYPE_STATION) |
201 + BIT(NL80211_IFTYPE_ADHOC);
202 +
203 + SET_IEEE80211_DEV(hw, &pdev->dev);
204 + platform_set_drvdata(pdev, hw);
205 +
206 + sc = hw->priv;
207 + sc->hw = hw;
208 + sc->dev = &pdev->dev;
209 + sc->mem = mem;
210 + sc->bus_ops = &ath_ahb_bus_ops;
211 +
212 + ret = ath_attach(AR5416_AR9100_DEVID, sc);
213 + if (ret != 0) {
214 + dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
215 + ret = -ENODEV;
216 + goto err_free_hw;
217 + }
218 +
219 + ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
220 + if (ret) {
221 + dev_err(&pdev->dev, "request_irq failed, err=%d\n", ret);
222 + ret = -EIO;
223 + goto err_detach;
224 + }
225 +
226 + ah = sc->sc_ah;
227 + printk(KERN_INFO
228 + "%s: Atheros AR%s MAC/BB Rev:%x, "
229 + "AR%s RF Rev:%x, mem=0x%lx, irq=%d\n",
230 + wiphy_name(hw->wiphy),
231 + ath_mac_bb_name(ah->ah_macVersion),
232 + ah->ah_macRev,
233 + ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
234 + ah->ah_phyRev,
235 + (unsigned long)mem, irq);
236 +
237 + return 0;
238 +
239 + err_detach:
240 + ath_detach(sc);
241 + err_free_hw:
242 + ieee80211_free_hw(hw);
243 + platform_set_drvdata(pdev, NULL);
244 + err_iounmap:
245 + iounmap(mem);
246 + err_out:
247 + return ret;
248 +}
249 +
250 +static int ath_ahb_remove(struct platform_device *pdev)
251 +{
252 + struct ieee80211_hw *hw = platform_get_drvdata(pdev);
253 +
254 + if (hw) {
255 + struct resource *res;
256 + struct ath_softc *sc = hw->priv;
257 +
258 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
259 + if (res)
260 + free_irq(res->start, sc);
261 +
262 + ath_detach(sc);
263 + iounmap(sc->mem);
264 + ieee80211_free_hw(hw);
265 + platform_set_drvdata(pdev, NULL);
266 + }
267 +
268 + return 0;
269 +}
270 +
271 +static struct platform_driver ath_ahb_driver = {
272 + .probe = ath_ahb_probe,
273 + .remove = ath_ahb_remove,
274 + .driver = {
275 + .name = "ath9k",
276 + .owner = THIS_MODULE,
277 + },
278 +};
279 +
280 +int ath_ahb_init(void)
281 +{
282 + return platform_driver_register(&ath_ahb_driver);
283 +}
284 +
285 +void ath_ahb_exit(void)
286 +{
287 + platform_driver_register(&ath_ahb_driver);
288 +}
289 --- a/drivers/net/wireless/ath9k/core.h
290 +++ b/drivers/net/wireless/ath9k/core.h
291 @@ -874,4 +874,12 @@ static inline int ath_pci_init(void) { r
292 static inline void ath_pci_exit(void) {};
293 #endif
294
295 +#ifdef CONFIG_ATHEROS_AR71XX
296 +int ath_ahb_init(void);
297 +void ath_ahb_exit(void);
298 +#else
299 +static inline int ath_ahb_init(void) { return 0; };
300 +static inline void ath_ahb_exit(void) {};
301 +#endif
302 +
303 #endif /* CORE_H */
304 --- a/drivers/net/wireless/ath9k/main.c
305 +++ b/drivers/net/wireless/ath9k/main.c
306 @@ -2533,8 +2533,17 @@ static int __init ath9k_init(void)
307 goto err_rate_unregister;
308 }
309
310 + error = ath_ahb_init();
311 + if (error < 0) {
312 + error = -ENODEV;
313 + goto err_pci_exit;
314 + }
315 +
316 return 0;
317
318 + err_pci_exit:
319 + ath_pci_exit();
320 +
321 err_rate_unregister:
322 ath_rate_control_unregister();
323 err_out:
324 @@ -2544,6 +2553,7 @@ module_init(ath9k_init);
325
326 static void __exit ath9k_exit(void)
327 {
328 + ath_ahb_exit();
329 ath_pci_exit();
330 ath_rate_control_unregister();
331 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
This page took 0.052001 seconds and 5 git commands to generate.