Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2002 Intersil Americas Inc. |
| 4 | * Copyright (C) 2003 Herbert Valerio Riedel <hvr@gnu.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | * |
| 19 | */ |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | #include <linux/pci.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/init.h> /* For __init, __exit */ |
Matthias Gehre | 910638a | 2006-03-28 01:56:48 -0800 | [diff] [blame] | 25 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #include "prismcompat.h" |
| 28 | #include "islpci_dev.h" |
| 29 | #include "islpci_mgt.h" /* for pc_debug */ |
| 30 | #include "isl_oid.h" |
| 31 | |
| 32 | #define DRV_NAME "prism54" |
| 33 | #define DRV_VERSION "1.2" |
| 34 | |
| 35 | MODULE_AUTHOR("[Intersil] R.Bastings and W.Termorshuizen, The prism54.org Development Team <prism54-devel@prism54.org>"); |
| 36 | MODULE_DESCRIPTION("The Prism54 802.11 Wireless LAN adapter"); |
| 37 | MODULE_LICENSE("GPL"); |
| 38 | |
| 39 | static int init_pcitm = 0; |
| 40 | module_param(init_pcitm, int, 0); |
| 41 | |
| 42 | /* In this order: vendor, device, subvendor, subdevice, class, class_mask, |
| 43 | * driver_data |
| 44 | * If you have an update for this please contact prism54-devel@prism54.org |
| 45 | * The latest list can be found at http://prism54.org/supported_cards.php */ |
| 46 | static const struct pci_device_id prism54_id_tbl[] = { |
| 47 | /* Intersil PRISM Duette/Prism GT Wireless LAN adapter */ |
| 48 | { |
| 49 | 0x1260, 0x3890, |
| 50 | PCI_ANY_ID, PCI_ANY_ID, |
| 51 | 0, 0, 0 |
| 52 | }, |
| 53 | |
| 54 | /* 3COM 3CRWE154G72 Wireless LAN adapter */ |
| 55 | { |
| 56 | 0x10b7, 0x6001, |
| 57 | PCI_ANY_ID, PCI_ANY_ID, |
| 58 | 0, 0, 0 |
| 59 | }, |
| 60 | |
| 61 | /* Intersil PRISM Indigo Wireless LAN adapter */ |
| 62 | { |
| 63 | 0x1260, 0x3877, |
| 64 | PCI_ANY_ID, PCI_ANY_ID, |
| 65 | 0, 0, 0 |
| 66 | }, |
| 67 | |
| 68 | /* Intersil PRISM Javelin/Xbow Wireless LAN adapter */ |
| 69 | { |
| 70 | 0x1260, 0x3886, |
| 71 | PCI_ANY_ID, PCI_ANY_ID, |
| 72 | 0, 0, 0 |
| 73 | }, |
| 74 | |
| 75 | /* End of list */ |
| 76 | {0,0,0,0,0,0,0} |
| 77 | }; |
| 78 | |
| 79 | /* register the device with the Hotplug facilities of the kernel */ |
| 80 | MODULE_DEVICE_TABLE(pci, prism54_id_tbl); |
| 81 | |
| 82 | static int prism54_probe(struct pci_dev *, const struct pci_device_id *); |
| 83 | static void prism54_remove(struct pci_dev *); |
Pavel Machek | 05adc3b | 2005-04-16 15:25:25 -0700 | [diff] [blame] | 84 | static int prism54_suspend(struct pci_dev *, pm_message_t state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | static int prism54_resume(struct pci_dev *); |
| 86 | |
| 87 | static struct pci_driver prism54_driver = { |
| 88 | .name = DRV_NAME, |
| 89 | .id_table = prism54_id_tbl, |
| 90 | .probe = prism54_probe, |
| 91 | .remove = prism54_remove, |
| 92 | .suspend = prism54_suspend, |
| 93 | .resume = prism54_resume, |
| 94 | /* .enable_wake ; we don't support this yet */ |
| 95 | }; |
| 96 | |
| 97 | /****************************************************************************** |
| 98 | Module initialization functions |
| 99 | ******************************************************************************/ |
| 100 | |
| 101 | int |
| 102 | prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 103 | { |
| 104 | struct net_device *ndev; |
| 105 | u8 latency_tmr; |
| 106 | u32 mem_addr; |
| 107 | islpci_private *priv; |
| 108 | int rvalue; |
| 109 | |
| 110 | /* Enable the pci device */ |
| 111 | if (pci_enable_device(pdev)) { |
| 112 | printk(KERN_ERR "%s: pci_enable_device() failed.\n", DRV_NAME); |
| 113 | return -ENODEV; |
| 114 | } |
| 115 | |
| 116 | /* check whether the latency timer is set correctly */ |
| 117 | pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency_tmr); |
| 118 | #if VERBOSE > SHOW_ERROR_MESSAGES |
| 119 | DEBUG(SHOW_TRACING, "latency timer: %x\n", latency_tmr); |
| 120 | #endif |
| 121 | if (latency_tmr < PCIDEVICE_LATENCY_TIMER_MIN) { |
| 122 | /* set the latency timer */ |
| 123 | pci_write_config_byte(pdev, PCI_LATENCY_TIMER, |
| 124 | PCIDEVICE_LATENCY_TIMER_VAL); |
| 125 | } |
| 126 | |
| 127 | /* enable PCI DMA */ |
Matthias Gehre | 910638a | 2006-03-28 01:56:48 -0800 | [diff] [blame] | 128 | if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME); |
| 130 | goto do_pci_disable_device; |
| 131 | } |
| 132 | |
| 133 | /* 0x40 is the programmable timer to configure the response timeout (TRDY_TIMEOUT) |
| 134 | * 0x41 is the programmable timer to configure the retry timeout (RETRY_TIMEOUT) |
| 135 | * The RETRY_TIMEOUT is used to set the number of retries that the core, as a |
| 136 | * Master, will perform before abandoning a cycle. The default value for |
| 137 | * RETRY_TIMEOUT is 0x80, which far exceeds the PCI 2.1 requirement for new |
| 138 | * devices. A write of zero to the RETRY_TIMEOUT register disables this |
| 139 | * function to allow use with any non-compliant legacy devices that may |
| 140 | * execute more retries. |
| 141 | * |
| 142 | * Writing zero to both these two registers will disable both timeouts and |
| 143 | * *can* solve problems caused by devices that are slow to respond. |
| 144 | * Make this configurable - MSW |
| 145 | */ |
| 146 | if ( init_pcitm >= 0 ) { |
| 147 | pci_write_config_byte(pdev, 0x40, (u8)init_pcitm); |
| 148 | pci_write_config_byte(pdev, 0x41, (u8)init_pcitm); |
| 149 | } else { |
| 150 | printk(KERN_INFO "PCI TRDY/RETRY unchanged\n"); |
| 151 | } |
| 152 | |
| 153 | /* request the pci device I/O regions */ |
| 154 | rvalue = pci_request_regions(pdev, DRV_NAME); |
| 155 | if (rvalue) { |
| 156 | printk(KERN_ERR "%s: pci_request_regions failure (rc=%d)\n", |
| 157 | DRV_NAME, rvalue); |
| 158 | goto do_pci_disable_device; |
| 159 | } |
| 160 | |
| 161 | /* check if the memory window is indeed set */ |
| 162 | rvalue = pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &mem_addr); |
| 163 | if (rvalue || !mem_addr) { |
| 164 | printk(KERN_ERR "%s: PCI device memory region not configured; fix your BIOS or CardBus bridge/drivers\n", |
| 165 | DRV_NAME); |
| 166 | goto do_pci_release_regions; |
| 167 | } |
| 168 | |
| 169 | /* enable PCI bus-mastering */ |
| 170 | DEBUG(SHOW_TRACING, "%s: pci_set_master(pdev)\n", DRV_NAME); |
| 171 | pci_set_master(pdev); |
| 172 | |
| 173 | /* enable MWI */ |
| 174 | pci_set_mwi(pdev); |
| 175 | |
| 176 | /* setup the network device interface and its structure */ |
| 177 | if (!(ndev = islpci_setup(pdev))) { |
| 178 | /* error configuring the driver as a network device */ |
| 179 | printk(KERN_ERR "%s: could not configure network device\n", |
| 180 | DRV_NAME); |
| 181 | goto do_pci_release_regions; |
| 182 | } |
| 183 | |
| 184 | priv = netdev_priv(ndev); |
| 185 | islpci_set_state(priv, PRV_STATE_PREBOOT); /* we are attempting to boot */ |
| 186 | |
| 187 | /* card is in unknown state yet, might have some interrupts pending */ |
| 188 | isl38xx_disable_interrupts(priv->device_base); |
| 189 | |
| 190 | /* request for the interrupt before uploading the firmware */ |
| 191 | rvalue = request_irq(pdev->irq, &islpci_interrupt, |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 192 | IRQF_SHARED, ndev->name, priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | if (rvalue) { |
| 195 | /* error, could not hook the handler to the irq */ |
| 196 | printk(KERN_ERR "%s: could not install IRQ handler\n", |
| 197 | ndev->name); |
| 198 | goto do_unregister_netdev; |
| 199 | } |
| 200 | |
| 201 | /* firmware upload is triggered in islpci_open */ |
| 202 | |
| 203 | return 0; |
| 204 | |
| 205 | do_unregister_netdev: |
| 206 | unregister_netdev(ndev); |
| 207 | islpci_free_memory(priv); |
| 208 | pci_set_drvdata(pdev, NULL); |
| 209 | free_netdev(ndev); |
| 210 | priv = NULL; |
| 211 | do_pci_release_regions: |
| 212 | pci_release_regions(pdev); |
| 213 | do_pci_disable_device: |
| 214 | pci_disable_device(pdev); |
| 215 | return -EIO; |
| 216 | } |
| 217 | |
| 218 | /* set by cleanup_module */ |
| 219 | static volatile int __in_cleanup_module = 0; |
| 220 | |
| 221 | /* this one removes one(!!) instance only */ |
| 222 | void |
| 223 | prism54_remove(struct pci_dev *pdev) |
| 224 | { |
| 225 | struct net_device *ndev = pci_get_drvdata(pdev); |
| 226 | islpci_private *priv = ndev ? netdev_priv(ndev) : NULL; |
| 227 | BUG_ON(!priv); |
| 228 | |
| 229 | if (!__in_cleanup_module) { |
| 230 | printk(KERN_DEBUG "%s: hot unplug detected\n", ndev->name); |
| 231 | islpci_set_state(priv, PRV_STATE_OFF); |
| 232 | } |
| 233 | |
| 234 | printk(KERN_DEBUG "%s: removing device\n", ndev->name); |
| 235 | |
| 236 | unregister_netdev(ndev); |
| 237 | |
| 238 | /* free the interrupt request */ |
| 239 | |
| 240 | if (islpci_get_state(priv) != PRV_STATE_OFF) { |
| 241 | isl38xx_disable_interrupts(priv->device_base); |
| 242 | islpci_set_state(priv, PRV_STATE_OFF); |
| 243 | /* This bellow causes a lockup at rmmod time. It might be |
| 244 | * because some interrupts still linger after rmmod time, |
| 245 | * see bug #17 */ |
| 246 | /* pci_set_power_state(pdev, 3);*/ /* try to power-off */ |
| 247 | } |
| 248 | |
| 249 | free_irq(pdev->irq, priv); |
| 250 | |
| 251 | /* free the PCI memory and unmap the remapped page */ |
| 252 | islpci_free_memory(priv); |
| 253 | |
| 254 | pci_set_drvdata(pdev, NULL); |
| 255 | free_netdev(ndev); |
| 256 | priv = NULL; |
| 257 | |
| 258 | pci_release_regions(pdev); |
| 259 | |
| 260 | pci_disable_device(pdev); |
| 261 | } |
| 262 | |
| 263 | int |
Pavel Machek | 05adc3b | 2005-04-16 15:25:25 -0700 | [diff] [blame] | 264 | prism54_suspend(struct pci_dev *pdev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
| 266 | struct net_device *ndev = pci_get_drvdata(pdev); |
| 267 | islpci_private *priv = ndev ? netdev_priv(ndev) : NULL; |
| 268 | BUG_ON(!priv); |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
| 271 | pci_save_state(pdev); |
| 272 | |
| 273 | /* tell the device not to trigger interrupts for now... */ |
| 274 | isl38xx_disable_interrupts(priv->device_base); |
| 275 | |
| 276 | /* from now on assume the hardware was already powered down |
| 277 | and don't touch it anymore */ |
| 278 | islpci_set_state(priv, PRV_STATE_OFF); |
| 279 | |
| 280 | netif_stop_queue(ndev); |
| 281 | netif_device_detach(ndev); |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | int |
| 287 | prism54_resume(struct pci_dev *pdev) |
| 288 | { |
| 289 | struct net_device *ndev = pci_get_drvdata(pdev); |
| 290 | islpci_private *priv = ndev ? netdev_priv(ndev) : NULL; |
| 291 | BUG_ON(!priv); |
| 292 | |
| 293 | pci_enable_device(pdev); |
| 294 | |
| 295 | printk(KERN_NOTICE "%s: got resume request\n", ndev->name); |
| 296 | |
| 297 | pci_restore_state(pdev); |
| 298 | |
| 299 | /* alright let's go into the PREBOOT state */ |
| 300 | islpci_reset(priv, 1); |
| 301 | |
| 302 | netif_device_attach(ndev); |
| 303 | netif_start_queue(ndev); |
| 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | static int __init |
| 309 | prism54_module_init(void) |
| 310 | { |
| 311 | printk(KERN_INFO "Loaded %s driver, version %s\n", |
| 312 | DRV_NAME, DRV_VERSION); |
| 313 | |
| 314 | __bug_on_wrong_struct_sizes (); |
| 315 | |
| 316 | return pci_module_init(&prism54_driver); |
| 317 | } |
| 318 | |
| 319 | /* by the time prism54_module_exit() terminates, as a postcondition |
| 320 | * all instances will have been destroyed by calls to |
| 321 | * prism54_remove() */ |
| 322 | static void __exit |
| 323 | prism54_module_exit(void) |
| 324 | { |
| 325 | __in_cleanup_module = 1; |
| 326 | |
| 327 | pci_unregister_driver(&prism54_driver); |
| 328 | |
| 329 | printk(KERN_INFO "Unloaded %s driver\n", DRV_NAME); |
| 330 | |
| 331 | __in_cleanup_module = 0; |
| 332 | } |
| 333 | |
| 334 | /* register entry points */ |
| 335 | module_init(prism54_module_init); |
| 336 | module_exit(prism54_module_exit); |
| 337 | /* EOF */ |