commit cfa315c963ba834a30f6699d2dcff460f3fa6547 Author: Jiri Slaby Date: Mon Jun 18 10:35:35 2007 +0200 ath/if_ath_pci cleanup diff --git a/ath/if_ath_pci.c b/ath/if_ath_pci.c index e946fcf..2934afd 100644 --- a/ath/if_ath_pci.c +++ b/ath/if_ath_pci.c @@ -44,57 +44,60 @@ static char *ifname = "ath"; module_param(ifname, charp, 0); MODULE_PARM_DESC(ifname, "Interface name prefix (default: ath)"); -struct ath_pci_softc { - struct ath_softc aps_sc; -#ifdef CONFIG_PM - u32 aps_pmstate[16]; -#endif -}; - /* * User a static table of PCI id's for now. While this is the * "new way" to do things, we may want to switch back to having * the HAL check them by defining a probe method. */ static struct pci_device_id ath_pci_id_table[] __devinitdata = { - { 0x168c, 0x0207, PCI_ANY_ID, PCI_ANY_ID }, /* 5210 early */ - { 0x168c, 0x0007, PCI_ANY_ID, PCI_ANY_ID }, /* 5210 */ - { 0x168c, 0x0011, PCI_ANY_ID, PCI_ANY_ID }, /* 5311 */ - { 0x168c, 0x0012, PCI_ANY_ID, PCI_ANY_ID }, /* 5211 */ - { 0x168c, 0x0013, PCI_ANY_ID, PCI_ANY_ID }, /* 5212 */ - { 0xa727, 0x0013, PCI_ANY_ID, PCI_ANY_ID }, /* 3com 5212 */ - { 0x10b7, 0x0013, PCI_ANY_ID, PCI_ANY_ID }, /* 3com 3CRDAG675 5212 */ - { 0x168c, 0x1014, PCI_ANY_ID, PCI_ANY_ID }, /* IBM minipci 5212 */ - { 0x168c, 0x0014, PCI_ANY_ID, PCI_ANY_ID }, /* 5212 combatible */ - { 0x168c, 0x0015, PCI_ANY_ID, PCI_ANY_ID }, /* 5212 combatible */ - { 0x168c, 0x0016, PCI_ANY_ID, PCI_ANY_ID }, /* 5212 combatible */ - { 0x168c, 0x0017, PCI_ANY_ID, PCI_ANY_ID }, /* 5212 combatible */ - { 0x168c, 0x0018, PCI_ANY_ID, PCI_ANY_ID }, /* 5212 combatible */ - { 0x168c, 0x0019, PCI_ANY_ID, PCI_ANY_ID }, /* 5212 combatible */ - { 0x168c, 0x001a, PCI_ANY_ID, PCI_ANY_ID }, /* 2413 Griffin-lite */ - { 0x168c, 0x001b, PCI_ANY_ID, PCI_ANY_ID }, /* 5413 Eagle */ - { 0x168c, 0x001c, PCI_ANY_ID, PCI_ANY_ID }, /* 5424 Condor (PCI-E)*/ + { PCI_VDEVICE(ATHEROS, 0x0207) }, /* 5210 early */ + { PCI_VDEVICE(ATHEROS, 0x0007) }, /* 5210 */ + { PCI_VDEVICE(ATHEROS, 0x0011) }, /* 5311 */ + { PCI_VDEVICE(ATHEROS, 0x0012) }, /* 5211 */ + { PCI_VDEVICE(ATHEROS, 0x0013) }, /* 5212 */ + { PCI_VDEVICE(3COM_2, 0x0013) }, /* 3com 5212 */ + { PCI_VDEVICE(3COM, 0x0013) }, /* 3com 3CRDAG675 5212 */ + { PCI_VDEVICE(ATHEROS, 0x1014) }, /* IBM minipci 5212 */ + { PCI_VDEVICE(ATHEROS, 0x0014) }, /* 5212 combatible */ + { PCI_VDEVICE(ATHEROS, 0x0015) }, /* 5212 combatible */ + { PCI_VDEVICE(ATHEROS, 0x0016) }, /* 5212 combatible */ + { PCI_VDEVICE(ATHEROS, 0x0017) }, /* 5212 combatible */ + { PCI_VDEVICE(ATHEROS, 0x0018) }, /* 5212 combatible */ + { PCI_VDEVICE(ATHEROS, 0x0019) }, /* 5212 combatible */ + { PCI_VDEVICE(ATHEROS, 0x001a) }, /* 2413 Griffin-lite */ + { PCI_VDEVICE(ATHEROS, 0x001b) }, /* 5413 Eagle */ + { PCI_VDEVICE(ATHEROS, 0x001c) }, /* 5424 Condor (PCI-E)*/ { 0 } }; +MODULE_DEVICE_TABLE(pci, ath_pci_id_table); + +/* return bus cachesize in 4B word units */ +void bus_read_cachesize(struct ath_softc *sc, u8 *csz) +{ + pci_read_config_byte(sc->sc_bdev, PCI_CACHE_LINE_SIZE, csz); +} -static int -ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) +static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { - unsigned long phymem; void __iomem *mem; - struct ath_pci_softc *sc; + struct ath_softc *sc; struct net_device *dev; const char *athname; - u_int8_t csz; + int retval; u32 val; + u8 csz; - if (pci_enable_device(pdev)) - return (-EIO); + retval = pci_enable_device(pdev); + if (retval) { + dev_err(&pdev->dev, "can't enable device\n"); + goto err; + } /* XXX 32-bit addressing only */ - if (pci_set_dma_mask(pdev, 0xffffffff)) { - printk(KERN_ERR "ath_pci: 32-bit DMA not available\n"); - goto bad; + retval = pci_set_dma_mask(pdev, DMA_32BIT_MASK); + if (retval) { + dev_err(&pdev->dev, "32-bit DMA not available\n"); + goto err_dis; } /* @@ -110,7 +113,7 @@ ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) * DMA to work so force a reasonable value here if it * comes up zero. */ - csz = L1_CACHE_BYTES / sizeof(u_int32_t); + csz = L1_CACHE_BYTES / sizeof(u32); pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz); } /* @@ -132,32 +135,31 @@ ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if ((val & 0x0000ff00) != 0) pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); - phymem = pci_resource_start(pdev, 0); - if (!request_mem_region(phymem, pci_resource_len(pdev, 0), "ath")) { - printk(KERN_ERR "ath_pci: cannot reserve PCI memory region\n"); - goto bad; + retval = pci_request_region(pdev, 0, "ath"); + if (retval) { + dev_err(&pdev->dev, "cannot reserve PCI memory region\n"); + goto err_dis; } - mem = ioremap(phymem, pci_resource_len(pdev, 0)); + mem = pci_iomap(pdev, 0, 0); if (!mem) { - printk(KERN_ERR "ath_pci: cannot remap PCI memory region\n") ; - goto bad1; + dev_err(&pdev->dev, "cannot remap PCI memory region\n") ; + goto err_reg; } - sc = kmalloc(sizeof(struct ath_pci_softc), GFP_KERNEL); + sc = kzalloc(sizeof(struct ath_softc), GFP_KERNEL); if (sc == NULL) { - printk(KERN_ERR "ath_pci: no memory for device state\n"); - goto bad2; + dev_err(&pdev->dev, "no memory for device state\n"); + goto err_map; } - memset(sc, 0, sizeof(struct ath_pci_softc)); /* * Mark the device as detached to avoid processing * interrupts until setup is complete. */ - sc->aps_sc.sc_invalid = 1; + sc->sc_invalid = 1; - dev = &sc->aps_sc.sc_dev; /* XXX blech, violate layering */ + dev = &sc->sc_dev; /* use variable interface name prefix */ strncpy(dev->name, ifname, IFNAMSIZ - sizeof("%d") - 1); @@ -165,81 +167,72 @@ ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) dev->irq = pdev->irq; dev->priv = sc; - sc->aps_sc.sc_iobase = mem; + sc->sc_iobase = mem; SET_MODULE_OWNER(dev); SET_NETDEV_DEV(dev, &pdev->dev); - sc->aps_sc.sc_bdev = (void *) pdev; + sc->sc_bdev = pdev; pci_set_drvdata(pdev, dev); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) if (request_irq(dev->irq, ath_intr, IRQF_SHARED, dev->name, dev)) { -#else - if (request_irq(dev->irq, ath_intr, SA_SHIRQ, dev->name, dev)) { -#endif - printk(KERN_WARNING "%s: request_irq failed\n", dev->name); - goto bad3; + dev_err(&pdev->dev, "request_irq failed\n"); + goto err_free; } if (ath_attach(id->device, dev) != 0) - goto bad4; + goto err_irq; athname = ath_hal_probe(id->vendor, id->device); - printk(KERN_INFO "%s: %s: mem=0x%lx, irq=%d\n", - dev->name, athname ? athname : "Atheros ???", phymem, dev->irq); + dev_info(&pdev->dev, "%s: irq=%d\n", + athname ? athname : "Atheros ???", dev->irq); /* ready to process interrupts */ - sc->aps_sc.sc_invalid = 0; + sc->sc_invalid = 0; return 0; -bad4: +err_irq: free_irq(dev->irq, dev); -bad3: +err_free: kfree(sc); -bad2: - iounmap(mem); -bad1: - release_mem_region(phymem, pci_resource_len(pdev, 0)); -bad: +err_map: + pci_iounmap(pdev, mem); +err_reg: + pci_release_region(pdev, 0); +err_dis: pci_disable_device(pdev); - return (-ENODEV); +err: + return retval; } -static void -ath_pci_remove(struct pci_dev *pdev) +static void ath_pci_remove(struct pci_dev *pdev) { struct net_device *dev = pci_get_drvdata(pdev); - struct ath_pci_softc *sc = dev->priv; + struct ath_softc *sc = dev->priv; ath_detach(dev); - if (dev->irq) - free_irq(dev->irq, dev); - iounmap(sc->aps_sc.sc_iobase); - release_mem_region(pci_resource_start(pdev, 0), - pci_resource_len(pdev, 0)); + free_irq(dev->irq, dev); + pci_iounmap(pdev, sc->sc_iobase); + pci_release_region(pdev, 0); pci_disable_device(pdev); free_netdev(dev); } #ifdef CONFIG_PM -static int -ath_pci_suspend(struct pci_dev *pdev, pm_message_t state) +static int ath_pci_suspend(struct pci_dev *pdev, pm_message_t state) { struct net_device *dev = pci_get_drvdata(pdev); ath_suspend(dev); - PCI_SAVE_STATE(pdev, - ((struct ath_pci_softc *)dev->priv)->aps_pmstate); + pci_save_state(pdev); pci_disable_device(pdev); pci_set_power_state(pdev, PCI_D3hot); - return (0); + return 0; } -static int -ath_pci_resume(struct pci_dev *pdev) +static int ath_pci_resume(struct pci_dev *pdev) { struct net_device *dev = pci_get_drvdata(pdev); u32 val; @@ -253,8 +246,7 @@ ath_pci_resume(struct pci_dev *pdev) if (err) return err; - PCI_RESTORE_STATE(pdev, - ((struct ath_pci_softc *)dev->priv)->aps_pmstate); + pci_restore_state(pdev); /* * Suspend/Resume resets the PCI configuration space, so we have to * re-disable the RETRY_TIMEOUT register (0x41) to keep @@ -267,15 +259,13 @@ ath_pci_resume(struct pci_dev *pdev) pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); ath_resume(dev); - return (0); + return 0; } #else #define ath_pci_suspend NULL #define ath_pci_resume NULL #endif /* CONFIG_PM */ -MODULE_DEVICE_TABLE(pci, ath_pci_id_table); - static struct pci_driver ath_pci_drv_id = { .name = "ath_pci", .id_table = ath_pci_id_table, @@ -288,11 +278,10 @@ static struct pci_driver ath_pci_drv_id = { /* * Module glue. */ -static char *version = ATH_PCI_VERSION " (EXPERIMENTAL)"; -static char *dev_info = "ath_pci"; +static char version[] = ATH_PCI_VERSION " (EXPERIMENTAL)"; +static char dev_info[] = "ath_pci"; -int -ath_ioctl_ethtool(struct ath_softc *sc, int cmd, void __user *addr) +int ath_ioctl_ethtool(struct ath_softc *sc, int cmd, void __user *addr) { struct ethtool_drvinfo info; @@ -302,49 +291,41 @@ ath_ioctl_ethtool(struct ath_softc *sc, int cmd, void __user *addr) info.cmd = cmd; strncpy(info.driver, dev_info, sizeof(info.driver)-1); strncpy(info.version, version, sizeof(info.version)-1); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,22) + /* include the device name so later versions of kudzu DTRT */ - strncpy(info.bus_info, pci_name((struct pci_dev *)sc->sc_bdev), - sizeof(info.bus_info)-1); -#endif + strncpy(info.bus_info, pci_name(sc->sc_bdev), sizeof(info.bus_info)-1); + return copy_to_user(addr, &info, sizeof(info)) ? -EFAULT : 0; } -MODULE_AUTHOR("Errno Consulting, Sam Leffler"); -MODULE_DESCRIPTION("Support for Atheros 802.11 wireless LAN cards."); -MODULE_SUPPORTED_DEVICE("Atheros WLAN cards"); -#ifdef MODULE_LICENSE -MODULE_LICENSE("Dual BSD/GPL"); -#endif - -static int __init -init_ath_pci(void) +static int __init init_ath_pci(void) { + int ret; + printk(KERN_INFO "%s: %s\n", dev_info, version); - if (pci_register_driver(&ath_pci_drv_id) < 0) { - printk("ath_pci: No devices found, driver not installed.\n"); - pci_unregister_driver(&ath_pci_drv_id); - return (-ENODEV); + ret = pci_register_driver(&ath_pci_drv_id); + if (ret) { + printk(KERN_ERR "ath_pci: can't register pci driver\n"); + return ret; } ath_sysctl_register(); - return (0); + + return 0; } -module_init(init_ath_pci); -static void __exit -exit_ath_pci(void) +static void __exit exit_ath_pci(void) { ath_sysctl_unregister(); pci_unregister_driver(&ath_pci_drv_id); printk(KERN_INFO "%s: driver unloaded\n", dev_info); } + +module_init(init_ath_pci); module_exit(exit_ath_pci); -/* return bus cachesize in 4B word units */ -void -bus_read_cachesize(struct ath_softc *sc, u_int8_t *csz) -{ - pci_read_config_byte(sc->sc_bdev, PCI_CACHE_LINE_SIZE, csz); -} +MODULE_AUTHOR("Errno Consulting, Sam Leffler"); +MODULE_DESCRIPTION("Support for Atheros 802.11 wireless LAN cards."); +MODULE_SUPPORTED_DEVICE("Atheros WLAN cards"); +MODULE_LICENSE("Dual BSD/GPL"); diff --git a/ath/if_ath_pci.h b/ath/if_ath_pci.h index 613d954..1d152bd 100644 --- a/ath/if_ath_pci.h +++ b/ath/if_ath_pci.h @@ -21,55 +21,20 @@ * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * - * NO WARRANTY - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGES. - * - * $Id: if_ath_pci.h 2046 2007-01-31 06:38:07Z proski $ */ #ifndef _DEV_ATH_PCI_H_ #define _DEV_ATH_PCI_H_ #include + #define bus_map_single pci_map_single #define bus_unmap_single pci_unmap_single -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9) #define bus_dma_sync_single pci_dma_sync_single_for_cpu #define BUS_DMA_MAP_ERROR(a) pci_dma_mapping_error(a) -#define PCI_SAVE_STATE(a,b) pci_save_state(a) -#define PCI_RESTORE_STATE(a,b) pci_restore_state(a) -#else -#define bus_dma_sync_single pci_dma_sync_single -/* AFAIK we can't reliably check for DMA mapping errors on 2.4 kernels */ -#define BUS_DMA_MAP_ERROR(a) 0 -#define PCI_SAVE_STATE(a,b) pci_save_state(a,b) -#define PCI_RESTORE_STATE(a,b) pci_restore_state(a,b) -#endif #define bus_alloc_consistent pci_alloc_consistent #define bus_free_consistent pci_free_consistent #define BUS_DMA_FROMDEVICE PCI_DMA_FROMDEVICE #define BUS_DMA_TODEVICE PCI_DMA_TODEVICE -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11) -#define pm_message_t u32 -#endif - -#ifndef PCI_D0 -#define PCI_D0 0 -#endif - -#ifndef PCI_D3hot -#define PCI_D3hot 3 -#endif - #endif /* _DEV_ATH_PCI_H_ */