1 From d95e670cd1395ffd8410bed809b6d060f2183d6b Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Mon, 5 Jan 2009 11:01:09 +0100
4 Subject: [PATCH 05/11] ath9k: move PCI code into separate file
6 Now that we have converted all bus specific routines to replaceable, we
7 can move the PCI specific codes into a separate file.
9 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
10 Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
12 drivers/net/wireless/ath9k/Makefile | 1 +
13 drivers/net/wireless/ath9k/core.h | 18 ++-
14 drivers/net/wireless/ath9k/main.c | 299 +++--------------------------------
15 drivers/net/wireless/ath9k/pci.c | 289 +++++++++++++++++++++++++++++++++
16 4 files changed, 328 insertions(+), 279 deletions(-)
18 --- a/drivers/net/wireless/ath9k/Makefile
19 +++ b/drivers/net/wireless/ath9k/Makefile
20 @@ -11,6 +11,7 @@ ath9k-y += hw.o \
24 +ath9k-$(CONFIG_PCI) += pci.o
25 ath9k-$(CONFIG_ATH9K_DEBUG) += debug.o
27 obj-$(CONFIG_ATH9K) += ath9k.o
28 --- a/drivers/net/wireless/ath9k/core.h
29 +++ b/drivers/net/wireless/ath9k/core.h
33 #include <linux/etherdevice.h>
34 -#include <linux/pci.h>
35 +#include <linux/device.h>
36 #include <net/mac80211.h>
37 #include <linux/leds.h>
38 #include <linux/rfkill.h>
39 @@ -766,4 +766,20 @@ static inline void ath_bus_cleanup(struc
40 sc->bus_ops->cleanup(sc);
43 +extern struct ieee80211_ops ath9k_ops;
45 +irqreturn_t ath_isr(int irq, void *dev);
46 +int ath_attach(u16 devid, struct ath_softc *sc);
47 +void ath_detach(struct ath_softc *sc);
48 +const char *ath_mac_bb_name(u32 mac_bb_version);
49 +const char *ath_rf_name(u16 rf_version);
52 +int ath_pci_init(void);
53 +void ath_pci_exit(void);
55 +static inline int ath_pci_init(void) { return 0; };
56 +static inline void ath_pci_exit(void) {};
60 --- a/drivers/net/wireless/ath9k/main.c
61 +++ b/drivers/net/wireless/ath9k/main.c
62 @@ -28,38 +28,6 @@ MODULE_DESCRIPTION("Support for Atheros
63 MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
64 MODULE_LICENSE("Dual BSD/GPL");
66 -static struct pci_device_id ath_pci_id_table[] __devinitdata = {
67 - { PCI_VDEVICE(ATHEROS, 0x0023) }, /* PCI */
68 - { PCI_VDEVICE(ATHEROS, 0x0024) }, /* PCI-E */
69 - { PCI_VDEVICE(ATHEROS, 0x0027) }, /* PCI */
70 - { PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI */
71 - { PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */
72 - { PCI_VDEVICE(ATHEROS, 0x002B) }, /* PCI-E */
76 -static void ath_detach(struct ath_softc *sc);
78 -/* return bus cachesize in 4B word units */
80 -static void ath_pci_read_cachesize(struct ath_softc *sc, int *csz)
84 - pci_read_config_byte(to_pci_dev(sc->dev), PCI_CACHE_LINE_SIZE,
89 - * This check was put in to avoid "unplesant" consequences if
90 - * the bootrom has not fully initialized all PCI devices.
91 - * Sometimes the cache line size register is not set
95 - *csz = DEFAULT_CACHELINE >> 2; /* Use the default size */
98 static void ath_cache_conf_rate(struct ath_softc *sc,
99 struct ieee80211_conf *conf)
101 @@ -497,7 +465,7 @@ static void ath9k_tasklet(unsigned long
102 ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_imask);
105 -static irqreturn_t ath_isr(int irq, void *dev)
106 +irqreturn_t ath_isr(int irq, void *dev)
108 struct ath_softc *sc = dev;
109 struct ath_hal *ah = sc->sc_ah;
110 @@ -1278,7 +1246,7 @@ static int ath_start_rfkill_poll(struct
112 #endif /* CONFIG_RFKILL */
114 -static void ath_detach(struct ath_softc *sc)
115 +void ath_detach(struct ath_softc *sc)
117 struct ieee80211_hw *hw = sc->hw;
119 @@ -1529,7 +1497,7 @@ bad:
123 -static int ath_attach(u16 devid, struct ath_softc *sc)
124 +int ath_attach(u16 devid, struct ath_softc *sc)
126 struct ieee80211_hw *hw = sc->hw;
128 @@ -2448,7 +2416,7 @@ static int ath9k_ampdu_action(struct iee
132 -static struct ieee80211_ops ath9k_ops = {
133 +struct ieee80211_ops ath9k_ops = {
135 .start = ath9k_start,
137 @@ -2492,7 +2460,7 @@ static struct {
139 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
143 ath_mac_bb_name(u32 mac_bb_version)
146 @@ -2509,7 +2477,7 @@ ath_mac_bb_name(u32 mac_bb_version)
148 * Return the RF name. "????" is returned if the RF is unknown.
152 ath_rf_name(u16 rf_version)
155 @@ -2523,236 +2491,7 @@ ath_rf_name(u16 rf_version)
159 -static void ath_pci_cleanup(struct ath_softc *sc)
161 - struct pci_dev *pdev = to_pci_dev(sc->dev);
165 - free_irq(pdev->irq, sc);
166 - pci_iounmap(pdev, sc->mem);
167 - pci_release_region(pdev, 0);
168 - pci_disable_device(pdev);
169 - ieee80211_free_hw(sc->hw);
172 -static struct ath_bus_ops ath_pci_bus_ops = {
173 - .read_cachesize = ath_pci_read_cachesize,
174 - .cleanup = ath_pci_cleanup,
177 -static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
180 - struct ath_softc *sc;
181 - struct ieee80211_hw *hw;
185 - struct ath_hal *ah;
187 - if (pci_enable_device(pdev))
190 - ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
193 - printk(KERN_ERR "ath9k: 32-bit DMA not available\n");
197 - ret = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
200 - printk(KERN_ERR "ath9k: 32-bit DMA consistent "
201 - "DMA enable failed\n");
206 - * Cache line size is used to size and align various
207 - * structures used to communicate with the hardware.
209 - pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
212 - * Linux 2.4.18 (at least) writes the cache line size
213 - * register as a 16-bit wide register which is wrong.
214 - * We must have this setup properly for rx buffer
215 - * DMA to work so force a reasonable value here if it
218 - csz = L1_CACHE_BYTES / sizeof(u32);
219 - pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
222 - * The default setting of latency timer yields poor results,
223 - * set it to the value used by other systems. It may be worth
224 - * tweaking this setting more.
226 - pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
228 - pci_set_master(pdev);
231 - * Disable the RETRY_TIMEOUT register (0x41) to keep
232 - * PCI Tx retries from interfering with C3 CPU state.
234 - pci_read_config_dword(pdev, 0x40, &val);
235 - if ((val & 0x0000ff00) != 0)
236 - pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
238 - ret = pci_request_region(pdev, 0, "ath9k");
240 - dev_err(&pdev->dev, "PCI memory region reserve error\n");
245 - mem = pci_iomap(pdev, 0, 0);
247 - printk(KERN_ERR "PCI memory map error\n") ;
252 - hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
254 - printk(KERN_ERR "ath_pci: no memory for ieee80211_hw\n");
258 - SET_IEEE80211_DEV(hw, &pdev->dev);
259 - pci_set_drvdata(pdev, hw);
263 - sc->dev = &pdev->dev;
265 - sc->bus_ops = &ath_pci_bus_ops;
267 - if (ath_attach(id->device, sc) != 0) {
272 - /* setup interrupt service routine */
274 - if (request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath", sc)) {
275 - printk(KERN_ERR "%s: request_irq failed\n",
276 - wiphy_name(hw->wiphy));
283 - "%s: Atheros AR%s MAC/BB Rev:%x "
284 - "AR%s RF Rev:%x: mem=0x%lx, irq=%d\n",
285 - wiphy_name(hw->wiphy),
286 - ath_mac_bb_name(ah->ah_macVersion),
288 - ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
290 - (unsigned long)mem, pdev->irq);
296 - ieee80211_free_hw(hw);
298 - pci_iounmap(pdev, mem);
300 - pci_release_region(pdev, 0);
302 - pci_disable_device(pdev);
306 -static void ath_pci_remove(struct pci_dev *pdev)
308 - struct ieee80211_hw *hw = pci_get_drvdata(pdev);
309 - struct ath_softc *sc = hw->priv;
311 - ath_pci_cleanup(sc);
316 -static int ath_pci_suspend(struct pci_dev *pdev, pm_message_t state)
318 - struct ieee80211_hw *hw = pci_get_drvdata(pdev);
319 - struct ath_softc *sc = hw->priv;
321 - ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
323 -#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
324 - if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
325 - cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
328 - pci_save_state(pdev);
329 - pci_disable_device(pdev);
330 - pci_set_power_state(pdev, 3);
335 -static int ath_pci_resume(struct pci_dev *pdev)
337 - struct ieee80211_hw *hw = pci_get_drvdata(pdev);
338 - struct ath_softc *sc = hw->priv;
342 - err = pci_enable_device(pdev);
345 - pci_restore_state(pdev);
347 - * Suspend/Resume resets the PCI configuration space, so we have to
348 - * re-disable the RETRY_TIMEOUT register (0x41) to keep
349 - * PCI Tx retries from interfering with C3 CPU state
351 - pci_read_config_dword(pdev, 0x40, &val);
352 - if ((val & 0x0000ff00) != 0)
353 - pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
356 - ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
357 - AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
358 - ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
360 -#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
362 - * check the h/w rfkill state on resume
363 - * and start the rfkill poll timer
365 - if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
366 - queue_delayed_work(sc->hw->workqueue,
367 - &sc->rf_kill.rfkill_poll, 0);
373 -#endif /* CONFIG_PM */
375 -MODULE_DEVICE_TABLE(pci, ath_pci_id_table);
377 -static struct pci_driver ath_pci_driver = {
379 - .id_table = ath_pci_id_table,
380 - .probe = ath_pci_probe,
381 - .remove = ath_pci_remove,
383 - .suspend = ath_pci_suspend,
384 - .resume = ath_pci_resume,
385 -#endif /* CONFIG_PM */
388 -static int __init init_ath_pci(void)
389 +static int __init ath9k_init(void)
393 @@ -2764,26 +2503,30 @@ static int __init init_ath_pci(void)
395 "Unable to register rate control algorithm: %d\n",
397 - ath_rate_control_unregister();
402 - if (pci_register_driver(&ath_pci_driver) < 0) {
403 + error = ath_pci_init();
406 "ath_pci: No devices found, driver not installed.\n");
407 - ath_rate_control_unregister();
408 - pci_unregister_driver(&ath_pci_driver);
411 + goto err_rate_unregister;
416 + err_rate_unregister:
417 + ath_rate_control_unregister();
421 -module_init(init_ath_pci);
422 +module_init(ath9k_init);
424 -static void __exit exit_ath_pci(void)
425 +static void __exit ath9k_exit(void)
428 ath_rate_control_unregister();
429 - pci_unregister_driver(&ath_pci_driver);
430 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
432 -module_exit(exit_ath_pci);
433 +module_exit(ath9k_exit);
435 +++ b/drivers/net/wireless/ath9k/pci.c
438 + * Copyright (c) 2008 Atheros Communications Inc.
440 + * Permission to use, copy, modify, and/or distribute this software for any
441 + * purpose with or without fee is hereby granted, provided that the above
442 + * copyright notice and this permission notice appear in all copies.
444 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
445 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
446 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
447 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
448 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
449 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
450 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
453 +#include <linux/nl80211.h>
454 +#include <linux/pci.h>
459 +static struct pci_device_id ath_pci_id_table[] __devinitdata = {
460 + { PCI_VDEVICE(ATHEROS, 0x0023) }, /* PCI */
461 + { PCI_VDEVICE(ATHEROS, 0x0024) }, /* PCI-E */
462 + { PCI_VDEVICE(ATHEROS, 0x0027) }, /* PCI */
463 + { PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI */
464 + { PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */
465 + { PCI_VDEVICE(ATHEROS, 0x002B) }, /* PCI-E */
469 +/* return bus cachesize in 4B word units */
470 +static void ath_pci_read_cachesize(struct ath_softc *sc, int *csz)
474 + pci_read_config_byte(to_pci_dev(sc->dev), PCI_CACHE_LINE_SIZE,
479 + * This check was put in to avoid "unplesant" consequences if
480 + * the bootrom has not fully initialized all PCI devices.
481 + * Sometimes the cache line size register is not set
485 + *csz = DEFAULT_CACHELINE >> 2; /* Use the default size */
488 +static void ath_pci_cleanup(struct ath_softc *sc)
490 + struct pci_dev *pdev = to_pci_dev(sc->dev);
494 + free_irq(pdev->irq, sc);
495 + pci_iounmap(pdev, sc->mem);
496 + pci_release_region(pdev, 0);
497 + pci_disable_device(pdev);
498 + ieee80211_free_hw(sc->hw);
501 +static struct ath_bus_ops ath_pci_bus_ops = {
502 + .read_cachesize = ath_pci_read_cachesize,
503 + .cleanup = ath_pci_cleanup,
506 +static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
509 + struct ath_softc *sc;
510 + struct ieee80211_hw *hw;
514 + struct ath_hal *ah;
516 + if (pci_enable_device(pdev))
519 + ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
522 + printk(KERN_ERR "ath9k: 32-bit DMA not available\n");
526 + ret = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
529 + printk(KERN_ERR "ath9k: 32-bit DMA consistent "
530 + "DMA enable failed\n");
535 + * Cache line size is used to size and align various
536 + * structures used to communicate with the hardware.
538 + pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
541 + * Linux 2.4.18 (at least) writes the cache line size
542 + * register as a 16-bit wide register which is wrong.
543 + * We must have this setup properly for rx buffer
544 + * DMA to work so force a reasonable value here if it
547 + csz = L1_CACHE_BYTES / sizeof(u32);
548 + pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
551 + * The default setting of latency timer yields poor results,
552 + * set it to the value used by other systems. It may be worth
553 + * tweaking this setting more.
555 + pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
557 + pci_set_master(pdev);
560 + * Disable the RETRY_TIMEOUT register (0x41) to keep
561 + * PCI Tx retries from interfering with C3 CPU state.
563 + pci_read_config_dword(pdev, 0x40, &val);
564 + if ((val & 0x0000ff00) != 0)
565 + pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
567 + ret = pci_request_region(pdev, 0, "ath9k");
569 + dev_err(&pdev->dev, "PCI memory region reserve error\n");
574 + mem = pci_iomap(pdev, 0, 0);
576 + printk(KERN_ERR "PCI memory map error\n") ;
581 + hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
583 + printk(KERN_ERR "ath_pci: no memory for ieee80211_hw\n");
587 + SET_IEEE80211_DEV(hw, &pdev->dev);
588 + pci_set_drvdata(pdev, hw);
592 + sc->dev = &pdev->dev;
594 + sc->bus_ops = &ath_pci_bus_ops;
596 + if (ath_attach(id->device, sc) != 0) {
601 + /* setup interrupt service routine */
603 + if (request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath", sc)) {
604 + printk(KERN_ERR "%s: request_irq failed\n",
605 + wiphy_name(hw->wiphy));
612 + "%s: Atheros AR%s MAC/BB Rev:%x "
613 + "AR%s RF Rev:%x: mem=0x%lx, irq=%d\n",
614 + wiphy_name(hw->wiphy),
615 + ath_mac_bb_name(ah->ah_macVersion),
617 + ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
619 + (unsigned long)mem, pdev->irq);
625 + ieee80211_free_hw(hw);
627 + pci_iounmap(pdev, mem);
629 + pci_release_region(pdev, 0);
631 + pci_disable_device(pdev);
635 +static void ath_pci_remove(struct pci_dev *pdev)
637 + struct ieee80211_hw *hw = pci_get_drvdata(pdev);
638 + struct ath_softc *sc = hw->priv;
640 + ath_pci_cleanup(sc);
645 +static int ath_pci_suspend(struct pci_dev *pdev, pm_message_t state)
647 + struct ieee80211_hw *hw = pci_get_drvdata(pdev);
648 + struct ath_softc *sc = hw->priv;
650 + ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
652 +#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
653 + if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
654 + cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
657 + pci_save_state(pdev);
658 + pci_disable_device(pdev);
659 + pci_set_power_state(pdev, 3);
664 +static int ath_pci_resume(struct pci_dev *pdev)
666 + struct ieee80211_hw *hw = pci_get_drvdata(pdev);
667 + struct ath_softc *sc = hw->priv;
671 + err = pci_enable_device(pdev);
674 + pci_restore_state(pdev);
676 + * Suspend/Resume resets the PCI configuration space, so we have to
677 + * re-disable the RETRY_TIMEOUT register (0x41) to keep
678 + * PCI Tx retries from interfering with C3 CPU state
680 + pci_read_config_dword(pdev, 0x40, &val);
681 + if ((val & 0x0000ff00) != 0)
682 + pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
685 + ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
686 + AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
687 + ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
689 +#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
691 + * check the h/w rfkill state on resume
692 + * and start the rfkill poll timer
694 + if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
695 + queue_delayed_work(sc->hw->workqueue,
696 + &sc->rf_kill.rfkill_poll, 0);
702 +#endif /* CONFIG_PM */
704 +MODULE_DEVICE_TABLE(pci, ath_pci_id_table);
706 +static struct pci_driver ath_pci_driver = {
708 + .id_table = ath_pci_id_table,
709 + .probe = ath_pci_probe,
710 + .remove = ath_pci_remove,
712 + .suspend = ath_pci_suspend,
713 + .resume = ath_pci_resume,
714 +#endif /* CONFIG_PM */
717 +int __init ath_pci_init(void)
719 + return pci_register_driver(&ath_pci_driver);
722 +void ath_pci_exit(void)
724 + pci_unregister_driver(&ath_pci_driver);