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