1 From 4803193b165c67abcd7cb10dd0c178dbcffb6cc7 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 v3 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 Changes-licensed-under: ISC
11 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
12 Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
14 drivers/net/wireless/ath9k/Makefile | 1 +
15 drivers/net/wireless/ath9k/core.h | 19 ++-
16 drivers/net/wireless/ath9k/main.c | 300 +++--------------------------------
17 drivers/net/wireless/ath9k/pci.c | 287 +++++++++++++++++++++++++++++++++
18 4 files changed, 328 insertions(+), 279 deletions(-)
19 create mode 100644 drivers/net/wireless/ath9k/pci.c
21 --- a/drivers/net/wireless/ath9k/Makefile
22 +++ b/drivers/net/wireless/ath9k/Makefile
23 @@ -11,6 +11,7 @@ ath9k-y += hw.o \
27 +ath9k-$(CONFIG_PCI) += pci.o
28 ath9k-$(CONFIG_ATH9K_DEBUG) += debug.o
30 obj-$(CONFIG_ATH9K) += ath9k.o
31 --- a/drivers/net/wireless/ath9k/core.h
32 +++ b/drivers/net/wireless/ath9k/core.h
36 #include <linux/etherdevice.h>
37 -#include <linux/pci.h>
38 +#include <linux/device.h>
39 #include <net/mac80211.h>
40 #include <linux/leds.h>
41 #include <linux/rfkill.h>
42 @@ -767,4 +767,21 @@ static inline void ath_bus_cleanup(struc
43 sc->bus_ops->cleanup(sc);
46 +extern struct ieee80211_ops ath9k_ops;
48 +irqreturn_t ath_isr(int irq, void *dev);
49 +void ath_cleanup(struct ath_softc *sc);
50 +int ath_attach(u16 devid, struct ath_softc *sc);
51 +void ath_detach(struct ath_softc *sc);
52 +const char *ath_mac_bb_name(u32 mac_bb_version);
53 +const char *ath_rf_name(u16 rf_version);
56 +int ath_pci_init(void);
57 +void ath_pci_exit(void);
59 +static inline int ath_pci_init(void) { return 0; };
60 +static inline void ath_pci_exit(void) {};
64 --- a/drivers/net/wireless/ath9k/main.c
65 +++ b/drivers/net/wireless/ath9k/main.c
66 @@ -28,39 +28,6 @@ MODULE_DESCRIPTION("Support for Atheros
67 MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
68 MODULE_LICENSE("Dual BSD/GPL");
70 -static struct pci_device_id ath_pci_id_table[] __devinitdata = {
71 - { PCI_VDEVICE(ATHEROS, 0x0023) }, /* PCI */
72 - { PCI_VDEVICE(ATHEROS, 0x0024) }, /* PCI-E */
73 - { PCI_VDEVICE(ATHEROS, 0x0027) }, /* PCI */
74 - { PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI */
75 - { PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */
76 - { PCI_VDEVICE(ATHEROS, 0x002B) }, /* PCI-E */
80 -static void ath_detach(struct ath_softc *sc);
81 -static void ath_cleanup(struct ath_softc *sc);
83 -/* return bus cachesize in 4B word units */
85 -static void ath_pci_read_cachesize(struct ath_softc *sc, int *csz)
89 - pci_read_config_byte(to_pci_dev(sc->dev), PCI_CACHE_LINE_SIZE,
94 - * This check was put in to avoid "unplesant" consequences if
95 - * the bootrom has not fully initialized all PCI devices.
96 - * Sometimes the cache line size register is not set
100 - *csz = DEFAULT_CACHELINE >> 2; /* Use the default size */
103 static void ath_cache_conf_rate(struct ath_softc *sc,
104 struct ieee80211_conf *conf)
106 @@ -500,7 +467,7 @@ static void ath9k_tasklet(unsigned long
107 ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_imask);
110 -static irqreturn_t ath_isr(int irq, void *dev)
111 +irqreturn_t ath_isr(int irq, void *dev)
113 struct ath_softc *sc = dev;
114 struct ath_hal *ah = sc->sc_ah;
115 @@ -1281,7 +1248,7 @@ static int ath_start_rfkill_poll(struct
117 #endif /* CONFIG_RFKILL */
119 -static void ath_cleanup(struct ath_softc *sc)
120 +void ath_cleanup(struct ath_softc *sc)
123 free_irq(sc->irq, sc);
124 @@ -1289,7 +1256,7 @@ static void ath_cleanup(struct ath_softc
125 ieee80211_free_hw(sc->hw);
128 -static void ath_detach(struct ath_softc *sc)
129 +void ath_detach(struct ath_softc *sc)
131 struct ieee80211_hw *hw = sc->hw;
133 @@ -1543,7 +1510,7 @@ bad:
137 -static int ath_attach(u16 devid, struct ath_softc *sc)
138 +int ath_attach(u16 devid, struct ath_softc *sc)
140 struct ieee80211_hw *hw = sc->hw;
142 @@ -2466,7 +2433,7 @@ static int ath9k_ampdu_action(struct iee
146 -static struct ieee80211_ops ath9k_ops = {
147 +struct ieee80211_ops ath9k_ops = {
149 .start = ath9k_start,
151 @@ -2510,7 +2477,7 @@ static struct {
153 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
157 ath_mac_bb_name(u32 mac_bb_version)
160 @@ -2527,7 +2494,7 @@ ath_mac_bb_name(u32 mac_bb_version)
162 * Return the RF name. "????" is returned if the RF is unknown.
166 ath_rf_name(u16 rf_version)
169 @@ -2541,234 +2508,7 @@ ath_rf_name(u16 rf_version)
173 -static void ath_pci_cleanup(struct ath_softc *sc)
175 - struct pci_dev *pdev = to_pci_dev(sc->dev);
177 - pci_iounmap(pdev, sc->mem);
178 - pci_release_region(pdev, 0);
179 - pci_disable_device(pdev);
182 -static struct ath_bus_ops ath_pci_bus_ops = {
183 - .read_cachesize = ath_pci_read_cachesize,
184 - .cleanup = ath_pci_cleanup,
187 -static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
190 - struct ath_softc *sc;
191 - struct ieee80211_hw *hw;
195 - struct ath_hal *ah;
197 - if (pci_enable_device(pdev))
200 - ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
203 - printk(KERN_ERR "ath9k: 32-bit DMA not available\n");
207 - ret = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
210 - printk(KERN_ERR "ath9k: 32-bit DMA consistent "
211 - "DMA enable failed\n");
216 - * Cache line size is used to size and align various
217 - * structures used to communicate with the hardware.
219 - pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
222 - * Linux 2.4.18 (at least) writes the cache line size
223 - * register as a 16-bit wide register which is wrong.
224 - * We must have this setup properly for rx buffer
225 - * DMA to work so force a reasonable value here if it
228 - csz = L1_CACHE_BYTES / sizeof(u32);
229 - pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
232 - * The default setting of latency timer yields poor results,
233 - * set it to the value used by other systems. It may be worth
234 - * tweaking this setting more.
236 - pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
238 - pci_set_master(pdev);
241 - * Disable the RETRY_TIMEOUT register (0x41) to keep
242 - * PCI Tx retries from interfering with C3 CPU state.
244 - pci_read_config_dword(pdev, 0x40, &val);
245 - if ((val & 0x0000ff00) != 0)
246 - pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
248 - ret = pci_request_region(pdev, 0, "ath9k");
250 - dev_err(&pdev->dev, "PCI memory region reserve error\n");
255 - mem = pci_iomap(pdev, 0, 0);
257 - printk(KERN_ERR "PCI memory map error\n") ;
262 - hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
264 - printk(KERN_ERR "ath_pci: no memory for ieee80211_hw\n");
268 - SET_IEEE80211_DEV(hw, &pdev->dev);
269 - pci_set_drvdata(pdev, hw);
273 - sc->dev = &pdev->dev;
275 - sc->bus_ops = &ath_pci_bus_ops;
277 - if (ath_attach(id->device, sc) != 0) {
282 - /* setup interrupt service routine */
284 - if (request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath", sc)) {
285 - printk(KERN_ERR "%s: request_irq failed\n",
286 - wiphy_name(hw->wiphy));
291 - sc->irq = pdev->irq;
295 - "%s: Atheros AR%s MAC/BB Rev:%x "
296 - "AR%s RF Rev:%x: mem=0x%lx, irq=%d\n",
297 - wiphy_name(hw->wiphy),
298 - ath_mac_bb_name(ah->ah_macVersion),
300 - ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
302 - (unsigned long)mem, pdev->irq);
308 - ieee80211_free_hw(hw);
310 - pci_iounmap(pdev, mem);
312 - pci_release_region(pdev, 0);
314 - pci_disable_device(pdev);
318 -static void ath_pci_remove(struct pci_dev *pdev)
320 - struct ieee80211_hw *hw = pci_get_drvdata(pdev);
321 - struct ath_softc *sc = hw->priv;
328 -static int ath_pci_suspend(struct pci_dev *pdev, pm_message_t state)
330 - struct ieee80211_hw *hw = pci_get_drvdata(pdev);
331 - struct ath_softc *sc = hw->priv;
333 - ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
335 -#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
336 - if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
337 - cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
340 - pci_save_state(pdev);
341 - pci_disable_device(pdev);
342 - pci_set_power_state(pdev, 3);
347 -static int ath_pci_resume(struct pci_dev *pdev)
349 - struct ieee80211_hw *hw = pci_get_drvdata(pdev);
350 - struct ath_softc *sc = hw->priv;
354 - err = pci_enable_device(pdev);
357 - pci_restore_state(pdev);
359 - * Suspend/Resume resets the PCI configuration space, so we have to
360 - * re-disable the RETRY_TIMEOUT register (0x41) to keep
361 - * PCI Tx retries from interfering with C3 CPU state
363 - pci_read_config_dword(pdev, 0x40, &val);
364 - if ((val & 0x0000ff00) != 0)
365 - pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
368 - ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
369 - AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
370 - ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
372 -#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
374 - * check the h/w rfkill state on resume
375 - * and start the rfkill poll timer
377 - if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
378 - queue_delayed_work(sc->hw->workqueue,
379 - &sc->rf_kill.rfkill_poll, 0);
385 -#endif /* CONFIG_PM */
387 -MODULE_DEVICE_TABLE(pci, ath_pci_id_table);
389 -static struct pci_driver ath_pci_driver = {
391 - .id_table = ath_pci_id_table,
392 - .probe = ath_pci_probe,
393 - .remove = ath_pci_remove,
395 - .suspend = ath_pci_suspend,
396 - .resume = ath_pci_resume,
397 -#endif /* CONFIG_PM */
400 -static int __init init_ath_pci(void)
401 +static int __init ath9k_init(void)
405 @@ -2780,26 +2520,30 @@ static int __init init_ath_pci(void)
407 "Unable to register rate control algorithm: %d\n",
409 - ath_rate_control_unregister();
414 - if (pci_register_driver(&ath_pci_driver) < 0) {
415 + error = ath_pci_init();
418 "ath_pci: No devices found, driver not installed.\n");
419 - ath_rate_control_unregister();
420 - pci_unregister_driver(&ath_pci_driver);
423 + goto err_rate_unregister;
428 + err_rate_unregister:
429 + ath_rate_control_unregister();
433 -module_init(init_ath_pci);
434 +module_init(ath9k_init);
436 -static void __exit exit_ath_pci(void)
437 +static void __exit ath9k_exit(void)
440 ath_rate_control_unregister();
441 - pci_unregister_driver(&ath_pci_driver);
442 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
444 -module_exit(exit_ath_pci);
445 +module_exit(ath9k_exit);
447 +++ b/drivers/net/wireless/ath9k/pci.c
450 + * Copyright (c) 2008 Atheros Communications Inc.
452 + * Permission to use, copy, modify, and/or distribute this software for any
453 + * purpose with or without fee is hereby granted, provided that the above
454 + * copyright notice and this permission notice appear in all copies.
456 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
457 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
458 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
459 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
460 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
461 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
462 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
465 +#include <linux/nl80211.h>
466 +#include <linux/pci.h>
471 +static struct pci_device_id ath_pci_id_table[] __devinitdata = {
472 + { PCI_VDEVICE(ATHEROS, 0x0023) }, /* PCI */
473 + { PCI_VDEVICE(ATHEROS, 0x0024) }, /* PCI-E */
474 + { PCI_VDEVICE(ATHEROS, 0x0027) }, /* PCI */
475 + { PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI */
476 + { PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */
477 + { PCI_VDEVICE(ATHEROS, 0x002B) }, /* PCI-E */
481 +/* return bus cachesize in 4B word units */
482 +static void ath_pci_read_cachesize(struct ath_softc *sc, int *csz)
486 + pci_read_config_byte(to_pci_dev(sc->dev), PCI_CACHE_LINE_SIZE,
491 + * This check was put in to avoid "unplesant" consequences if
492 + * the bootrom has not fully initialized all PCI devices.
493 + * Sometimes the cache line size register is not set
497 + *csz = DEFAULT_CACHELINE >> 2; /* Use the default size */
500 +static void ath_pci_cleanup(struct ath_softc *sc)
502 + struct pci_dev *pdev = to_pci_dev(sc->dev);
504 + pci_iounmap(pdev, sc->mem);
505 + pci_release_region(pdev, 0);
506 + pci_disable_device(pdev);
509 +static struct ath_bus_ops ath_pci_bus_ops = {
510 + .read_cachesize = ath_pci_read_cachesize,
511 + .cleanup = ath_pci_cleanup,
514 +static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
517 + struct ath_softc *sc;
518 + struct ieee80211_hw *hw;
522 + struct ath_hal *ah;
524 + if (pci_enable_device(pdev))
527 + ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
530 + printk(KERN_ERR "ath9k: 32-bit DMA not available\n");
534 + ret = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
537 + printk(KERN_ERR "ath9k: 32-bit DMA consistent "
538 + "DMA enable failed\n");
543 + * Cache line size is used to size and align various
544 + * structures used to communicate with the hardware.
546 + pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
549 + * Linux 2.4.18 (at least) writes the cache line size
550 + * register as a 16-bit wide register which is wrong.
551 + * We must have this setup properly for rx buffer
552 + * DMA to work so force a reasonable value here if it
555 + csz = L1_CACHE_BYTES / sizeof(u32);
556 + pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
559 + * The default setting of latency timer yields poor results,
560 + * set it to the value used by other systems. It may be worth
561 + * tweaking this setting more.
563 + pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
565 + pci_set_master(pdev);
568 + * Disable the RETRY_TIMEOUT register (0x41) to keep
569 + * PCI Tx retries from interfering with C3 CPU state.
571 + pci_read_config_dword(pdev, 0x40, &val);
572 + if ((val & 0x0000ff00) != 0)
573 + pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
575 + ret = pci_request_region(pdev, 0, "ath9k");
577 + dev_err(&pdev->dev, "PCI memory region reserve error\n");
582 + mem = pci_iomap(pdev, 0, 0);
584 + printk(KERN_ERR "PCI memory map error\n") ;
589 + hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
591 + printk(KERN_ERR "ath_pci: no memory for ieee80211_hw\n");
595 + SET_IEEE80211_DEV(hw, &pdev->dev);
596 + pci_set_drvdata(pdev, hw);
600 + sc->dev = &pdev->dev;
602 + sc->bus_ops = &ath_pci_bus_ops;
604 + if (ath_attach(id->device, sc) != 0) {
609 + /* setup interrupt service routine */
611 + if (request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath", sc)) {
612 + printk(KERN_ERR "%s: request_irq failed\n",
613 + wiphy_name(hw->wiphy));
618 + sc->irq = pdev->irq;
622 + "%s: Atheros AR%s MAC/BB Rev:%x "
623 + "AR%s RF Rev:%x: mem=0x%lx, irq=%d\n",
624 + wiphy_name(hw->wiphy),
625 + ath_mac_bb_name(ah->ah_macVersion),
627 + ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
629 + (unsigned long)mem, pdev->irq);
635 + ieee80211_free_hw(hw);
637 + pci_iounmap(pdev, mem);
639 + pci_release_region(pdev, 0);
641 + pci_disable_device(pdev);
645 +static void ath_pci_remove(struct pci_dev *pdev)
647 + struct ieee80211_hw *hw = pci_get_drvdata(pdev);
648 + struct ath_softc *sc = hw->priv;
655 +static int ath_pci_suspend(struct pci_dev *pdev, pm_message_t state)
657 + struct ieee80211_hw *hw = pci_get_drvdata(pdev);
658 + struct ath_softc *sc = hw->priv;
660 + ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
662 +#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
663 + if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
664 + cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
667 + pci_save_state(pdev);
668 + pci_disable_device(pdev);
669 + pci_set_power_state(pdev, 3);
674 +static int ath_pci_resume(struct pci_dev *pdev)
676 + struct ieee80211_hw *hw = pci_get_drvdata(pdev);
677 + struct ath_softc *sc = hw->priv;
681 + err = pci_enable_device(pdev);
684 + pci_restore_state(pdev);
686 + * Suspend/Resume resets the PCI configuration space, so we have to
687 + * re-disable the RETRY_TIMEOUT register (0x41) to keep
688 + * PCI Tx retries from interfering with C3 CPU state
690 + pci_read_config_dword(pdev, 0x40, &val);
691 + if ((val & 0x0000ff00) != 0)
692 + pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
695 + ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
696 + AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
697 + ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
699 +#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
701 + * check the h/w rfkill state on resume
702 + * and start the rfkill poll timer
704 + if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
705 + queue_delayed_work(sc->hw->workqueue,
706 + &sc->rf_kill.rfkill_poll, 0);
712 +#endif /* CONFIG_PM */
714 +MODULE_DEVICE_TABLE(pci, ath_pci_id_table);
716 +static struct pci_driver ath_pci_driver = {
718 + .id_table = ath_pci_id_table,
719 + .probe = ath_pci_probe,
720 + .remove = ath_pci_remove,
722 + .suspend = ath_pci_suspend,
723 + .resume = ath_pci_resume,
724 +#endif /* CONFIG_PM */
727 +int __init ath_pci_init(void)
729 + return pci_register_driver(&ath_pci_driver);
732 +void ath_pci_exit(void)
734 + pci_unregister_driver(&ath_pci_driver);