linux/drivers/staging/rtl8712/usb_intf.c
<<
>>
Prefs
   1/******************************************************************************
   2 * usb_intf.c
   3 *
   4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
   5 * Linux device driver for RTL8192SU
   6 *
   7 * This program is free software; you can redistribute it and/or modify it
   8 * under the terms of version 2 of the GNU General Public License as
   9 * published by the Free Software Foundation.
  10 *
  11 * This program is distributed in the hope that it will be useful, but WITHOUT
  12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  14 * more details.
  15 *
  16 * You should have received a copy of the GNU General Public License along with
  17 * this program; if not, write to the Free Software Foundation, Inc.,
  18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  19 *
  20 * Modifications for inclusion into the Linux staging tree are
  21 * Copyright(c) 2010 Larry Finger. All rights reserved.
  22 *
  23 * Contact information:
  24 * WLAN FAE <wlanfae@realtek.com>
  25 * Larry Finger <Larry.Finger@lwfinger.net>
  26 *
  27 ******************************************************************************/
  28
  29#define _HCI_INTF_C_
  30
  31#include <linux/usb.h>
  32#include <linux/module.h>
  33
  34#include "osdep_service.h"
  35#include "drv_types.h"
  36#include "recv_osdep.h"
  37#include "xmit_osdep.h"
  38#include "rtl8712_efuse.h"
  39#include "usb_vendor_req.h"
  40#include "usb_ops.h"
  41#include "usb_osintf.h"
  42
  43#define DRVER  "v7_0.20100831"
  44
  45static struct usb_interface *pintf;
  46
  47static int r871xu_drv_init(struct usb_interface *pusb_intf,
  48                           const struct usb_device_id *pdid);
  49
  50static void r871xu_dev_remove(struct usb_interface *pusb_intf);
  51
  52static struct usb_device_id rtl871x_usb_id_tbl[] = {
  53
  54/* RTL8188SU */
  55        /* Realtek */
  56        {USB_DEVICE(0x0BDA, 0x8171)},
  57        {USB_DEVICE(0x0bda, 0x8173)},
  58        {USB_DEVICE(0x0bda, 0x8712)},
  59        {USB_DEVICE(0x0bda, 0x8713)},
  60        {USB_DEVICE(0x0bda, 0xC512)},
  61        /* Abocom */
  62        {USB_DEVICE(0x07B8, 0x8188)},
  63        /* ASUS */
  64        {USB_DEVICE(0x0B05, 0x1786)},
  65        {USB_DEVICE(0x0B05, 0x1791)}, /* 11n mode disable */
  66        /* Belkin */
  67        {USB_DEVICE(0x050D, 0x945A)},
  68        /* Corega */
  69        {USB_DEVICE(0x07AA, 0x0047)},
  70        /* D-Link */
  71        {USB_DEVICE(0x2001, 0x3306)},
  72        {USB_DEVICE(0x07D1, 0x3306)}, /* 11n mode disable */
  73        /* Edimax */
  74        {USB_DEVICE(0x7392, 0x7611)},
  75        /* EnGenius */
  76        {USB_DEVICE(0x1740, 0x9603)},
  77        /* Hawking */
  78        {USB_DEVICE(0x0E66, 0x0016)},
  79        /* Hercules */
  80        {USB_DEVICE(0x06F8, 0xE034)},
  81        {USB_DEVICE(0x06F8, 0xE032)},
  82        /* Logitec */
  83        {USB_DEVICE(0x0789, 0x0167)},
  84        /* PCI */
  85        {USB_DEVICE(0x2019, 0xAB28)},
  86        {USB_DEVICE(0x2019, 0xED16)},
  87        /* Sitecom */
  88        {USB_DEVICE(0x0DF6, 0x0057)},
  89        {USB_DEVICE(0x0DF6, 0x0045)},
  90        {USB_DEVICE(0x0DF6, 0x0059)}, /* 11n mode disable */
  91        {USB_DEVICE(0x0DF6, 0x004B)},
  92        {USB_DEVICE(0x0DF6, 0x005D)},
  93        {USB_DEVICE(0x0DF6, 0x0063)},
  94        /* Sweex */
  95        {USB_DEVICE(0x177F, 0x0154)},
  96        /* Thinkware */
  97        {USB_DEVICE(0x0BDA, 0x5077)},
  98        /* Toshiba */
  99        {USB_DEVICE(0x1690, 0x0752)},
 100        /* - */
 101        {USB_DEVICE(0x20F4, 0x646B)},
 102        {USB_DEVICE(0x083A, 0xC512)},
 103
 104/* RTL8191SU */
 105        /* Realtek */
 106        {USB_DEVICE(0x0BDA, 0x8172)},
 107        /* Amigo */
 108        {USB_DEVICE(0x0EB0, 0x9061)},
 109        /* ASUS/EKB */
 110        {USB_DEVICE(0x0BDA, 0x8172)},
 111        {USB_DEVICE(0x13D3, 0x3323)},
 112        {USB_DEVICE(0x13D3, 0x3311)}, /* 11n mode disable */
 113        {USB_DEVICE(0x13D3, 0x3342)},
 114        /* ASUS/EKBLenovo */
 115        {USB_DEVICE(0x13D3, 0x3333)},
 116        {USB_DEVICE(0x13D3, 0x3334)},
 117        {USB_DEVICE(0x13D3, 0x3335)}, /* 11n mode disable */
 118        {USB_DEVICE(0x13D3, 0x3336)}, /* 11n mode disable */
 119        /* ASUS/Media BOX */
 120        {USB_DEVICE(0x13D3, 0x3309)},
 121        /* Belkin */
 122        {USB_DEVICE(0x050D, 0x815F)},
 123        /* D-Link */
 124        {USB_DEVICE(0x07D1, 0x3302)},
 125        {USB_DEVICE(0x07D1, 0x3300)},
 126        {USB_DEVICE(0x07D1, 0x3303)},
 127        /* Edimax */
 128        {USB_DEVICE(0x7392, 0x7612)},
 129        /* EnGenius */
 130        {USB_DEVICE(0x1740, 0x9605)},
 131        /* Guillemot */
 132        {USB_DEVICE(0x06F8, 0xE031)},
 133        /* Hawking */
 134        {USB_DEVICE(0x0E66, 0x0015)},
 135        /* Mediao */
 136        {USB_DEVICE(0x13D3, 0x3306)},
 137        /* PCI */
 138        {USB_DEVICE(0x2019, 0xED18)},
 139        {USB_DEVICE(0x2019, 0x4901)},
 140        /* Sitecom */
 141        {USB_DEVICE(0x0DF6, 0x0058)},
 142        {USB_DEVICE(0x0DF6, 0x0049)},
 143        {USB_DEVICE(0x0DF6, 0x004C)},
 144        {USB_DEVICE(0x0DF6, 0x0064)},
 145        /* Skyworth */
 146        {USB_DEVICE(0x14b2, 0x3300)},
 147        {USB_DEVICE(0x14b2, 0x3301)},
 148        {USB_DEVICE(0x14B2, 0x3302)},
 149        /* - */
 150        {USB_DEVICE(0x04F2, 0xAFF2)},
 151        {USB_DEVICE(0x04F2, 0xAFF5)},
 152        {USB_DEVICE(0x04F2, 0xAFF6)},
 153        {USB_DEVICE(0x13D3, 0x3339)},
 154        {USB_DEVICE(0x13D3, 0x3340)}, /* 11n mode disable */
 155        {USB_DEVICE(0x13D3, 0x3341)}, /* 11n mode disable */
 156        {USB_DEVICE(0x13D3, 0x3310)},
 157        {USB_DEVICE(0x13D3, 0x3325)},
 158
 159/* RTL8192SU */
 160        /* Realtek */
 161        {USB_DEVICE(0x0BDA, 0x8174)},
 162        {USB_DEVICE(0x0BDA, 0x8174)},
 163        /* Belkin */
 164        {USB_DEVICE(0x050D, 0x845A)},
 165        /* Corega */
 166        {USB_DEVICE(0x07AA, 0x0051)},
 167        /* Edimax */
 168        {USB_DEVICE(0x7392, 0x7622)},
 169        /* NEC */
 170        {USB_DEVICE(0x0409, 0x02B6)},
 171        {}
 172};
 173
 174MODULE_DEVICE_TABLE(usb, rtl871x_usb_id_tbl);
 175
 176static struct specific_device_id specific_device_id_tbl[] = {
 177        {.idVendor = 0x0b05, .idProduct = 0x1791,
 178                 .flags = SPEC_DEV_ID_DISABLE_HT},
 179        {.idVendor = 0x0df6, .idProduct = 0x0059,
 180                 .flags = SPEC_DEV_ID_DISABLE_HT},
 181        {.idVendor = 0x13d3, .idProduct = 0x3306,
 182                 .flags = SPEC_DEV_ID_DISABLE_HT},
 183        {.idVendor = 0x13D3, .idProduct = 0x3311,
 184                 .flags = SPEC_DEV_ID_DISABLE_HT},
 185        {.idVendor = 0x13d3, .idProduct = 0x3335,
 186                 .flags = SPEC_DEV_ID_DISABLE_HT},
 187        {.idVendor = 0x13d3, .idProduct = 0x3336,
 188                 .flags = SPEC_DEV_ID_DISABLE_HT},
 189        {.idVendor = 0x13d3, .idProduct = 0x3340,
 190                 .flags = SPEC_DEV_ID_DISABLE_HT},
 191        {.idVendor = 0x13d3, .idProduct = 0x3341,
 192                 .flags = SPEC_DEV_ID_DISABLE_HT},
 193        {}
 194};
 195
 196struct drv_priv {
 197        struct usb_driver r871xu_drv;
 198        int drv_registered;
 199};
 200
 201#ifdef CONFIG_PM
 202static int r871x_suspend(struct usb_interface *pusb_intf, pm_message_t state)
 203{
 204        struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
 205
 206        printk(KERN_INFO "r8712: suspending...\n");
 207        if (!pnetdev || !netif_running(pnetdev)) {
 208                printk(KERN_INFO "r8712: unable to suspend\n");
 209                return 0;
 210        }
 211        if (pnetdev->netdev_ops->ndo_stop)
 212                pnetdev->netdev_ops->ndo_stop(pnetdev);
 213        mdelay(10);
 214        netif_device_detach(pnetdev);
 215        return 0;
 216}
 217
 218static int r871x_resume(struct usb_interface *pusb_intf)
 219{
 220        struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
 221
 222        printk(KERN_INFO "r8712: resuming...\n");
 223        if (!pnetdev || !netif_running(pnetdev)) {
 224                printk(KERN_INFO "r8712: unable to resume\n");
 225                return 0;
 226        }
 227        netif_device_attach(pnetdev);
 228        if (pnetdev->netdev_ops->ndo_open)
 229                pnetdev->netdev_ops->ndo_open(pnetdev);
 230        return 0;
 231}
 232
 233static int r871x_reset_resume(struct usb_interface *pusb_intf)
 234{
 235        /* dummy routine */
 236        return 0;
 237}
 238
 239#endif
 240
 241static struct drv_priv drvpriv = {
 242        .r871xu_drv.name = "r8712u",
 243        .r871xu_drv.id_table = rtl871x_usb_id_tbl,
 244        .r871xu_drv.probe = r871xu_drv_init,
 245        .r871xu_drv.disconnect = r871xu_dev_remove,
 246#ifdef CONFIG_PM
 247        .r871xu_drv.suspend = r871x_suspend,
 248        .r871xu_drv.resume = r871x_resume,
 249        .r871xu_drv.reset_resume = r871x_reset_resume,
 250#endif
 251};
 252
 253static uint r8712_usb_dvobj_init(struct _adapter *padapter)
 254{
 255        uint    status = _SUCCESS;
 256        struct  usb_device_descriptor           *pdev_desc;
 257        struct  usb_host_config                 *phost_conf;
 258        struct  usb_config_descriptor           *pconf_desc;
 259        struct  usb_host_interface              *phost_iface;
 260        struct  usb_interface_descriptor        *piface_desc;
 261        struct dvobj_priv *pdvobjpriv = &padapter->dvobjpriv;
 262        struct usb_device *pusbd = pdvobjpriv->pusbdev;
 263
 264        pdvobjpriv->padapter = padapter;
 265        padapter->EepromAddressSize = 6;
 266        pdev_desc = &pusbd->descriptor;
 267        phost_conf = pusbd->actconfig;
 268        pconf_desc = &phost_conf->desc;
 269        phost_iface = &pintf->altsetting[0];
 270        piface_desc = &phost_iface->desc;
 271        pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
 272        if (pusbd->speed == USB_SPEED_HIGH) {
 273                pdvobjpriv->ishighspeed = true;
 274                printk(KERN_INFO "r8712u: USB_SPEED_HIGH with %d endpoints\n",
 275                       pdvobjpriv->nr_endpoint);
 276        } else {
 277                pdvobjpriv->ishighspeed = false;
 278                printk(KERN_INFO "r8712u: USB_SPEED_LOW with %d endpoints\n",
 279                       pdvobjpriv->nr_endpoint);
 280        }
 281        if ((r8712_alloc_io_queue(padapter)) == _FAIL)
 282                status = _FAIL;
 283        sema_init(&(padapter->dvobjpriv.usb_suspend_sema), 0);
 284        return status;
 285}
 286
 287static void r8712_usb_dvobj_deinit(struct _adapter *padapter)
 288{
 289}
 290
 291void rtl871x_intf_stop(struct _adapter *padapter)
 292{
 293        /*disable_hw_interrupt*/
 294        if (padapter->bSurpriseRemoved == false) {
 295                /*device still exists, so driver can do i/o operation
 296                 * TODO: */
 297        }
 298
 299        /* cancel in irp */
 300        if (padapter->dvobjpriv.inirp_deinit != NULL)
 301                padapter->dvobjpriv.inirp_deinit(padapter);
 302        /* cancel out irp */
 303        r8712_usb_write_port_cancel(padapter);
 304        /* TODO:cancel other irps */
 305}
 306
 307void r871x_dev_unload(struct _adapter *padapter)
 308{
 309        if (padapter->bup == true) {
 310                /*s1.*/
 311                padapter->bDriverStopped = true;
 312
 313                /*s3.*/
 314                rtl871x_intf_stop(padapter);
 315
 316                /*s4.*/
 317                r8712_stop_drv_threads(padapter);
 318
 319                /*s5.*/
 320                if (padapter->bSurpriseRemoved == false) {
 321                        padapter->hw_init_completed = false;
 322                        rtl8712_hal_deinit(padapter);
 323                }
 324
 325                /*s6.*/
 326                if (padapter->dvobj_deinit)
 327                        padapter->dvobj_deinit(padapter);
 328                padapter->bup = false;
 329        }
 330}
 331
 332static void disable_ht_for_spec_devid(const struct usb_device_id *pdid,
 333                                      struct _adapter *padapter)
 334{
 335        u16 vid, pid;
 336        u32 flags;
 337        int i;
 338        int num = sizeof(specific_device_id_tbl) /
 339                  sizeof(struct specific_device_id);
 340
 341        for (i = 0; i < num; i++) {
 342                vid = specific_device_id_tbl[i].idVendor;
 343                pid = specific_device_id_tbl[i].idProduct;
 344                flags = specific_device_id_tbl[i].flags;
 345
 346                if ((pdid->idVendor == vid) && (pdid->idProduct == pid) &&
 347                    (flags&SPEC_DEV_ID_DISABLE_HT)) {
 348                        padapter->registrypriv.ht_enable = 0;
 349                        padapter->registrypriv.cbw40_enable = 0;
 350                        padapter->registrypriv.ampdu_enable = 0;
 351                }
 352        }
 353}
 354
 355static u8 key_2char2num(u8 hch, u8 lch)
 356{
 357        return (hex_to_bin(hch) << 4) | hex_to_bin(lch);
 358}
 359
 360/*
 361 * drv_init() - a device potentially for us
 362 *
 363 * notes: drv_init() is called when the bus driver has located a card for us
 364 * to support. We accept the new device by returning 0.
 365*/
 366static int r871xu_drv_init(struct usb_interface *pusb_intf,
 367                           const struct usb_device_id *pdid)
 368{
 369        uint status;
 370        struct _adapter *padapter = NULL;
 371        struct dvobj_priv *pdvobjpriv;
 372        struct net_device *pnetdev;
 373        struct usb_device *udev;
 374
 375        printk(KERN_INFO "r8712u: DriverVersion: %s\n", DRVER);
 376        /* In this probe function, O.S. will provide the usb interface pointer
 377         * to driver. We have to increase the reference count of the usb device
 378         * structure by using the usb_get_dev function.
 379         */
 380        udev = interface_to_usbdev(pusb_intf);
 381        usb_get_dev(udev);
 382        pintf = pusb_intf;
 383        /* step 1. */
 384        pnetdev = r8712_init_netdev();
 385        if (!pnetdev)
 386                goto error;
 387        padapter = netdev_priv(pnetdev);
 388        disable_ht_for_spec_devid(pdid, padapter);
 389        pdvobjpriv = &padapter->dvobjpriv;
 390        pdvobjpriv->padapter = padapter;
 391        padapter->dvobjpriv.pusbdev = udev;
 392        usb_set_intfdata(pusb_intf, pnetdev);
 393        SET_NETDEV_DEV(pnetdev, &pusb_intf->dev);
 394        /* step 2. */
 395        padapter->dvobj_init = &r8712_usb_dvobj_init;
 396        padapter->dvobj_deinit = &r8712_usb_dvobj_deinit;
 397        padapter->halpriv.hal_bus_init = &r8712_usb_hal_bus_init;
 398        padapter->dvobjpriv.inirp_init = &r8712_usb_inirp_init;
 399        padapter->dvobjpriv.inirp_deinit = &r8712_usb_inirp_deinit;
 400        /* step 3.
 401         * initialize the dvobj_priv
 402         */
 403        if (padapter->dvobj_init == NULL)
 404                        goto error;
 405        else {
 406                status = padapter->dvobj_init(padapter);
 407                if (status != _SUCCESS)
 408                        goto error;
 409        }
 410        /* step 4. */
 411        status = r8712_init_drv_sw(padapter);
 412        if (status == _FAIL)
 413                goto error;
 414        /* step 5. read efuse/eeprom data and get mac_addr */
 415        {
 416                int i, offset;
 417                u8 mac[6];
 418                u8 tmpU1b, AutoloadFail, eeprom_CustomerID;
 419                u8 *pdata = padapter->eeprompriv.efuse_eeprom_data;
 420
 421                tmpU1b = r8712_read8(padapter, EE_9346CR);/*CR9346*/
 422
 423                /* To check system boot selection.*/
 424                printk(KERN_INFO "r8712u: Boot from %s: Autoload %s\n",
 425                       (tmpU1b & _9356SEL) ? "EEPROM" : "EFUSE",
 426                       (tmpU1b & _EEPROM_EN) ? "OK" : "Failed");
 427
 428                /* To check autoload success or not.*/
 429                if (tmpU1b & _EEPROM_EN) {
 430                        AutoloadFail = true;
 431                        /* The following operations prevent Efuse leakage by
 432                         * turning on 2.5V.
 433                         */
 434                        tmpU1b = r8712_read8(padapter, EFUSE_TEST+3);
 435                        r8712_write8(padapter, EFUSE_TEST + 3, tmpU1b | 0x80);
 436                        msleep(20);
 437                        r8712_write8(padapter, EFUSE_TEST + 3,
 438                                     (tmpU1b & (~BIT(7))));
 439
 440                        /* Retrieve Chip version.
 441                         * Recognize IC version by Reg0x4 BIT15.
 442                         */
 443                        tmpU1b = (u8)((r8712_read32(padapter, PMC_FSM) >> 15) &
 444                                                    0x1F);
 445                        if (tmpU1b == 0x3)
 446                                padapter->registrypriv.chip_version =
 447                                     RTL8712_3rdCUT;
 448                        else
 449                                padapter->registrypriv.chip_version =
 450                                     (tmpU1b >> 1) + 1;
 451                        switch (padapter->registrypriv.chip_version) {
 452                        case RTL8712_1stCUT:
 453                        case RTL8712_2ndCUT:
 454                        case RTL8712_3rdCUT:
 455                                break;
 456                        default:
 457                                padapter->registrypriv.chip_version =
 458                                     RTL8712_2ndCUT;
 459                                break;
 460                        }
 461
 462                        for (i = 0, offset = 0; i < 128; i += 8, offset++)
 463                                r8712_efuse_pg_packet_read(padapter, offset,
 464                                                     &pdata[i]);
 465
 466                        if (r8712_initmac) {
 467                                /* Users specify the mac address */
 468                                int jj, kk;
 469
 470                                for (jj = 0, kk = 0; jj < ETH_ALEN;
 471                                     jj++, kk += 3)
 472                                        mac[jj] =
 473                                           key_2char2num(r8712_initmac[kk],
 474                                           r8712_initmac[kk + 1]);
 475                        } else {
 476                                /* Use the mac address stored in the Efuse
 477                                 * offset = 0x12 for usb in efuse
 478                                 */
 479                                memcpy(mac, &pdata[0x12], ETH_ALEN);
 480                        }
 481                        eeprom_CustomerID = pdata[0x52];
 482                        switch (eeprom_CustomerID) {
 483                        case EEPROM_CID_ALPHA:
 484                                padapter->eeprompriv.CustomerID =
 485                                                 RT_CID_819x_ALPHA;
 486                                break;
 487                        case EEPROM_CID_CAMEO:
 488                                padapter->eeprompriv.CustomerID =
 489                                                 RT_CID_819x_CAMEO;
 490                                break;
 491                        case EEPROM_CID_SITECOM:
 492                                padapter->eeprompriv.CustomerID =
 493                                                 RT_CID_819x_Sitecom;
 494                                break;
 495                        case EEPROM_CID_COREGA:
 496                                padapter->eeprompriv.CustomerID =
 497                                                 RT_CID_COREGA;
 498                                break;
 499                        case EEPROM_CID_Senao:
 500                                padapter->eeprompriv.CustomerID =
 501                                                 RT_CID_819x_Senao;
 502                                break;
 503                        case EEPROM_CID_EDIMAX_BELKIN:
 504                                padapter->eeprompriv.CustomerID =
 505                                                 RT_CID_819x_Edimax_Belkin;
 506                                break;
 507                        case EEPROM_CID_SERCOMM_BELKIN:
 508                                padapter->eeprompriv.CustomerID =
 509                                                 RT_CID_819x_Sercomm_Belkin;
 510                                break;
 511                        case EEPROM_CID_WNC_COREGA:
 512                                padapter->eeprompriv.CustomerID =
 513                                                 RT_CID_819x_WNC_COREGA;
 514                                break;
 515                        case EEPROM_CID_WHQL:
 516                                break;
 517                        case EEPROM_CID_NetCore:
 518                                padapter->eeprompriv.CustomerID =
 519                                                 RT_CID_819x_Netcore;
 520                                break;
 521                        case EEPROM_CID_CAMEO1:
 522                                padapter->eeprompriv.CustomerID =
 523                                                 RT_CID_819x_CAMEO1;
 524                                break;
 525                        case EEPROM_CID_CLEVO:
 526                                padapter->eeprompriv.CustomerID =
 527                                                 RT_CID_819x_CLEVO;
 528                                break;
 529                        default:
 530                                padapter->eeprompriv.CustomerID =
 531                                                 RT_CID_DEFAULT;
 532                                break;
 533                        }
 534                        printk(KERN_INFO "r8712u: CustomerID = 0x%.4x\n",
 535                             padapter->eeprompriv.CustomerID);
 536                        /* Led mode */
 537                        switch (padapter->eeprompriv.CustomerID) {
 538                        case RT_CID_DEFAULT:
 539                        case RT_CID_819x_ALPHA:
 540                        case RT_CID_819x_CAMEO:
 541                                padapter->ledpriv.LedStrategy = SW_LED_MODE1;
 542                                padapter->ledpriv.bRegUseLed = true;
 543                                break;
 544                        case RT_CID_819x_Sitecom:
 545                                padapter->ledpriv.LedStrategy = SW_LED_MODE2;
 546                                padapter->ledpriv.bRegUseLed = true;
 547                                break;
 548                        case RT_CID_COREGA:
 549                        case RT_CID_819x_Senao:
 550                                padapter->ledpriv.LedStrategy = SW_LED_MODE3;
 551                                padapter->ledpriv.bRegUseLed = true;
 552                                break;
 553                        case RT_CID_819x_Edimax_Belkin:
 554                                padapter->ledpriv.LedStrategy = SW_LED_MODE4;
 555                                padapter->ledpriv.bRegUseLed = true;
 556                                break;
 557                        case RT_CID_819x_Sercomm_Belkin:
 558                                padapter->ledpriv.LedStrategy = SW_LED_MODE5;
 559                                padapter->ledpriv.bRegUseLed = true;
 560                                break;
 561                        case RT_CID_819x_WNC_COREGA:
 562                                padapter->ledpriv.LedStrategy = SW_LED_MODE6;
 563                                padapter->ledpriv.bRegUseLed = true;
 564                                break;
 565                        default:
 566                                padapter->ledpriv.LedStrategy = SW_LED_MODE0;
 567                                padapter->ledpriv.bRegUseLed = false;
 568                                break;
 569                        }
 570                } else
 571                        AutoloadFail = false;
 572                if (((mac[0] == 0xff) && (mac[1] == 0xff) &&
 573                     (mac[2] == 0xff) && (mac[3] == 0xff) &&
 574                     (mac[4] == 0xff) && (mac[5] == 0xff)) ||
 575                    ((mac[0] == 0x00) && (mac[1] == 0x00) &&
 576                     (mac[2] == 0x00) && (mac[3] == 0x00) &&
 577                     (mac[4] == 0x00) && (mac[5] == 0x00)) ||
 578                     (AutoloadFail == false)) {
 579                        mac[0] = 0x00;
 580                        mac[1] = 0xe0;
 581                        mac[2] = 0x4c;
 582                        mac[3] = 0x87;
 583                        mac[4] = 0x00;
 584                        mac[5] = 0x00;
 585                }
 586                if (r8712_initmac) {
 587                        /* Make sure the user did not select a multicast
 588                         * address by setting bit 1 of first octet.
 589                         */
 590                        mac[0] &= 0xFE;
 591                        printk(KERN_INFO "r8712u: MAC Address from user = "
 592                               "%pM\n", mac);
 593                } else
 594                        printk(KERN_INFO "r8712u: MAC Address from efuse = "
 595                               "%pM\n", mac);
 596                memcpy(pnetdev->dev_addr, mac, ETH_ALEN);
 597        }
 598        /* step 6. Tell the network stack we exist */
 599        if (register_netdev(pnetdev) != 0)
 600                goto error;
 601        spin_lock_init(&padapter->lockRxFF0Filter);
 602        return 0;
 603error:
 604        usb_put_dev(udev);
 605        usb_set_intfdata(pusb_intf, NULL);
 606        if (padapter->dvobj_deinit != NULL)
 607                padapter->dvobj_deinit(padapter);
 608        if (pnetdev)
 609                free_netdev(pnetdev);
 610        return -ENODEV;
 611}
 612
 613/* rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove()
 614 * => how to recognize both */
 615static void r871xu_dev_remove(struct usb_interface *pusb_intf)
 616{
 617        struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
 618        struct _adapter *padapter = netdev_priv(pnetdev);
 619        struct usb_device *udev = interface_to_usbdev(pusb_intf);
 620
 621        usb_set_intfdata(pusb_intf, NULL);
 622        if (padapter) {
 623                if (drvpriv.drv_registered == true)
 624                        padapter->bSurpriseRemoved = true;
 625                if (pnetdev != NULL) {
 626                        /* will call netdev_close() */
 627                        unregister_netdev(pnetdev);
 628                }
 629                flush_scheduled_work();
 630                udelay(1);
 631                /*Stop driver mlme relation timer */
 632                r8712_stop_drv_timers(padapter);
 633                r871x_dev_unload(padapter);
 634                r8712_free_drv_sw(padapter);
 635        }
 636        usb_set_intfdata(pusb_intf, NULL);
 637        /* decrease the reference count of the usb device structure
 638         * when disconnect */
 639        usb_put_dev(udev);
 640        /* If we didn't unplug usb dongle and remove/insert modlue, driver
 641         * fails on sitesurvey for the first time when device is up.
 642         * Reset usb port for sitesurvey fail issue. */
 643        if (udev->state != USB_STATE_NOTATTACHED)
 644                usb_reset_device(udev);
 645        return;
 646}
 647
 648static int __init r8712u_drv_entry(void)
 649{
 650        drvpriv.drv_registered = true;
 651        return usb_register(&drvpriv.r871xu_drv);
 652}
 653
 654static void __exit r8712u_drv_halt(void)
 655{
 656        drvpriv.drv_registered = false;
 657        usb_deregister(&drvpriv.r871xu_drv);
 658        printk(KERN_INFO "r8712u: Driver unloaded\n");
 659}
 660
 661module_init(r8712u_drv_entry);
 662module_exit(r8712u_drv_halt);
 663