Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /******************************************************************************
0003  * usb_intf.c
0004  *
0005  * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
0006  * Linux device driver for RTL8192SU
0007  *
0008  * Modifications for inclusion into the Linux staging tree are
0009  * Copyright(c) 2010 Larry Finger. All rights reserved.
0010  *
0011  * Contact information:
0012  * WLAN FAE <wlanfae@realtek.com>
0013  * Larry Finger <Larry.Finger@lwfinger.net>
0014  *
0015  ******************************************************************************/
0016 
0017 #define _HCI_INTF_C_
0018 
0019 #include <linux/usb.h>
0020 #include <linux/module.h>
0021 #include <linux/firmware.h>
0022 
0023 #include "osdep_service.h"
0024 #include "drv_types.h"
0025 #include "recv_osdep.h"
0026 #include "xmit_osdep.h"
0027 #include "rtl8712_efuse.h"
0028 #include "usb_ops.h"
0029 #include "usb_osintf.h"
0030 
0031 static struct usb_interface *pintf;
0032 
0033 static int r871xu_drv_init(struct usb_interface *pusb_intf,
0034                const struct usb_device_id *pdid);
0035 
0036 static void r871xu_dev_remove(struct usb_interface *pusb_intf);
0037 
0038 static const struct usb_device_id rtl871x_usb_id_tbl[] = {
0039 /* RTL8188SU */
0040     /* Realtek */
0041     {USB_DEVICE(0x0BDA, 0x8171)},
0042     {USB_DEVICE(0x0bda, 0x8173)},
0043     {USB_DEVICE(0x0bda, 0x8712)},
0044     {USB_DEVICE(0x0bda, 0x8713)},
0045     {USB_DEVICE(0x0bda, 0xC512)},
0046     /* Abocom */
0047     {USB_DEVICE(0x07B8, 0x8188)},
0048     /* ASUS */
0049     {USB_DEVICE(0x0B05, 0x1786)},
0050     {USB_DEVICE(0x0B05, 0x1791)}, /* 11n mode disable */
0051     /* Belkin */
0052     {USB_DEVICE(0x050D, 0x945A)},
0053     /* ISY IWL - Belkin clone */
0054     {USB_DEVICE(0x050D, 0x11F1)},
0055     /* Corega */
0056     {USB_DEVICE(0x07AA, 0x0047)},
0057     /* D-Link */
0058     {USB_DEVICE(0x2001, 0x3306)},
0059     {USB_DEVICE(0x07D1, 0x3306)}, /* 11n mode disable */
0060     /* Edimax */
0061     {USB_DEVICE(0x7392, 0x7611)},
0062     /* EnGenius */
0063     {USB_DEVICE(0x1740, 0x9603)},
0064     /* Hawking */
0065     {USB_DEVICE(0x0E66, 0x0016)},
0066     /* Hercules */
0067     {USB_DEVICE(0x06F8, 0xE034)},
0068     {USB_DEVICE(0x06F8, 0xE032)},
0069     /* Logitec */
0070     {USB_DEVICE(0x0789, 0x0167)},
0071     /* PCI */
0072     {USB_DEVICE(0x2019, 0xAB28)},
0073     {USB_DEVICE(0x2019, 0xED16)},
0074     /* Sitecom */
0075     {USB_DEVICE(0x0DF6, 0x0057)},
0076     {USB_DEVICE(0x0DF6, 0x0045)},
0077     {USB_DEVICE(0x0DF6, 0x0059)}, /* 11n mode disable */
0078     {USB_DEVICE(0x0DF6, 0x004B)},
0079     {USB_DEVICE(0x0DF6, 0x005B)},
0080     {USB_DEVICE(0x0DF6, 0x005D)},
0081     {USB_DEVICE(0x0DF6, 0x0063)},
0082     /* Sweex */
0083     {USB_DEVICE(0x177F, 0x0154)},
0084     /* Thinkware */
0085     {USB_DEVICE(0x0BDA, 0x5077)},
0086     /* Toshiba */
0087     {USB_DEVICE(0x1690, 0x0752)},
0088     /* - */
0089     {USB_DEVICE(0x20F4, 0x646B)},
0090     {USB_DEVICE(0x083A, 0xC512)},
0091     {USB_DEVICE(0x25D4, 0x4CA1)},
0092     {USB_DEVICE(0x25D4, 0x4CAB)},
0093 
0094 /* RTL8191SU */
0095     /* Realtek */
0096     {USB_DEVICE(0x0BDA, 0x8172)},
0097     {USB_DEVICE(0x0BDA, 0x8192)},
0098     /* Amigo */
0099     {USB_DEVICE(0x0EB0, 0x9061)},
0100     /* ASUS/EKB */
0101     {USB_DEVICE(0x13D3, 0x3323)},
0102     {USB_DEVICE(0x13D3, 0x3311)}, /* 11n mode disable */
0103     {USB_DEVICE(0x13D3, 0x3342)},
0104     /* ASUS/EKBLenovo */
0105     {USB_DEVICE(0x13D3, 0x3333)},
0106     {USB_DEVICE(0x13D3, 0x3334)},
0107     {USB_DEVICE(0x13D3, 0x3335)}, /* 11n mode disable */
0108     {USB_DEVICE(0x13D3, 0x3336)}, /* 11n mode disable */
0109     /* ASUS/Media BOX */
0110     {USB_DEVICE(0x13D3, 0x3309)},
0111     /* Belkin */
0112     {USB_DEVICE(0x050D, 0x815F)},
0113     /* D-Link */
0114     {USB_DEVICE(0x07D1, 0x3302)},
0115     {USB_DEVICE(0x07D1, 0x3300)},
0116     {USB_DEVICE(0x07D1, 0x3303)},
0117     /* Edimax */
0118     {USB_DEVICE(0x7392, 0x7612)},
0119     /* EnGenius */
0120     {USB_DEVICE(0x1740, 0x9605)},
0121     /* Guillemot */
0122     {USB_DEVICE(0x06F8, 0xE031)},
0123     /* Hawking */
0124     {USB_DEVICE(0x0E66, 0x0015)},
0125     /* Mediao */
0126     {USB_DEVICE(0x13D3, 0x3306)},
0127     /* PCI */
0128     {USB_DEVICE(0x2019, 0xED18)},
0129     {USB_DEVICE(0x2019, 0x4901)},
0130     /* Sitecom */
0131     {USB_DEVICE(0x0DF6, 0x0058)},
0132     {USB_DEVICE(0x0DF6, 0x0049)},
0133     {USB_DEVICE(0x0DF6, 0x004C)},
0134     {USB_DEVICE(0x0DF6, 0x006C)},
0135     {USB_DEVICE(0x0DF6, 0x0064)},
0136     /* Skyworth */
0137     {USB_DEVICE(0x14b2, 0x3300)},
0138     {USB_DEVICE(0x14b2, 0x3301)},
0139     {USB_DEVICE(0x14B2, 0x3302)},
0140     /* - */
0141     {USB_DEVICE(0x04F2, 0xAFF2)},
0142     {USB_DEVICE(0x04F2, 0xAFF5)},
0143     {USB_DEVICE(0x04F2, 0xAFF6)},
0144     {USB_DEVICE(0x13D3, 0x3339)},
0145     {USB_DEVICE(0x13D3, 0x3340)}, /* 11n mode disable */
0146     {USB_DEVICE(0x13D3, 0x3341)}, /* 11n mode disable */
0147     {USB_DEVICE(0x13D3, 0x3310)},
0148     {USB_DEVICE(0x13D3, 0x3325)},
0149 
0150 /* RTL8192SU */
0151     /* Realtek */
0152     {USB_DEVICE(0x0BDA, 0x8174)},
0153     /* Belkin */
0154     {USB_DEVICE(0x050D, 0x845A)},
0155     /* Corega */
0156     {USB_DEVICE(0x07AA, 0x0051)},
0157     /* Edimax */
0158     {USB_DEVICE(0x7392, 0x7622)},
0159     /* NEC */
0160     {USB_DEVICE(0x0409, 0x02B6)},
0161     {}
0162 };
0163 
0164 MODULE_DEVICE_TABLE(usb, rtl871x_usb_id_tbl);
0165 
0166 static struct specific_device_id specific_device_id_tbl[] = {
0167     {.idVendor = 0x0b05, .idProduct = 0x1791,
0168          .flags = SPEC_DEV_ID_DISABLE_HT},
0169     {.idVendor = 0x0df6, .idProduct = 0x0059,
0170          .flags = SPEC_DEV_ID_DISABLE_HT},
0171     {.idVendor = 0x13d3, .idProduct = 0x3306,
0172          .flags = SPEC_DEV_ID_DISABLE_HT},
0173     {.idVendor = 0x13D3, .idProduct = 0x3311,
0174          .flags = SPEC_DEV_ID_DISABLE_HT},
0175     {.idVendor = 0x13d3, .idProduct = 0x3335,
0176          .flags = SPEC_DEV_ID_DISABLE_HT},
0177     {.idVendor = 0x13d3, .idProduct = 0x3336,
0178          .flags = SPEC_DEV_ID_DISABLE_HT},
0179     {.idVendor = 0x13d3, .idProduct = 0x3340,
0180          .flags = SPEC_DEV_ID_DISABLE_HT},
0181     {.idVendor = 0x13d3, .idProduct = 0x3341,
0182          .flags = SPEC_DEV_ID_DISABLE_HT},
0183     {}
0184 };
0185 
0186 struct drv_priv {
0187     struct usb_driver r871xu_drv;
0188     int drv_registered;
0189 };
0190 
0191 #ifdef CONFIG_PM
0192 static int r871x_suspend(struct usb_interface *pusb_intf, pm_message_t state)
0193 {
0194     struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
0195     struct _adapter *padapter = netdev_priv(pnetdev);
0196 
0197     netdev_info(pnetdev, "Suspending...\n");
0198     padapter->suspended = true;
0199     rtl871x_intf_stop(padapter);
0200     if (pnetdev->netdev_ops->ndo_stop)
0201         pnetdev->netdev_ops->ndo_stop(pnetdev);
0202     mdelay(10);
0203     netif_device_detach(pnetdev);
0204     return 0;
0205 }
0206 
0207 static void rtl871x_intf_resume(struct _adapter *padapter)
0208 {
0209     if (padapter->dvobjpriv.inirp_init)
0210         padapter->dvobjpriv.inirp_init(padapter);
0211 }
0212 
0213 static int r871x_resume(struct usb_interface *pusb_intf)
0214 {
0215     struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
0216     struct _adapter *padapter = netdev_priv(pnetdev);
0217 
0218     netdev_info(pnetdev,  "Resuming...\n");
0219     netif_device_attach(pnetdev);
0220     if (pnetdev->netdev_ops->ndo_open)
0221         pnetdev->netdev_ops->ndo_open(pnetdev);
0222     padapter->suspended = false;
0223     rtl871x_intf_resume(padapter);
0224     return 0;
0225 }
0226 #endif
0227 
0228 static struct drv_priv drvpriv = {
0229     .r871xu_drv.name = "r8712u",
0230     .r871xu_drv.id_table = rtl871x_usb_id_tbl,
0231     .r871xu_drv.probe = r871xu_drv_init,
0232     .r871xu_drv.disconnect = r871xu_dev_remove,
0233 #ifdef CONFIG_PM
0234     .r871xu_drv.suspend = r871x_suspend,
0235     .r871xu_drv.resume = r871x_resume,
0236 #endif
0237 };
0238 
0239 static uint r8712_usb_dvobj_init(struct _adapter *padapter)
0240 {
0241     uint    status = _SUCCESS;
0242     struct  usb_host_interface      *phost_iface;
0243     struct  usb_interface_descriptor    *piface_desc;
0244     struct dvobj_priv *pdvobjpriv = &padapter->dvobjpriv;
0245     struct usb_device *pusbd = pdvobjpriv->pusbdev;
0246 
0247     pdvobjpriv->padapter = padapter;
0248     padapter->eeprom_address_size = 6;
0249     phost_iface = pintf->cur_altsetting;
0250     piface_desc = &phost_iface->desc;
0251     pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
0252     if (pusbd->speed == USB_SPEED_HIGH) {
0253         pdvobjpriv->ishighspeed = true;
0254         dev_info(&pusbd->dev, "r8712u: USB_SPEED_HIGH with %d endpoints\n",
0255              pdvobjpriv->nr_endpoint);
0256     } else {
0257         pdvobjpriv->ishighspeed = false;
0258         dev_info(&pusbd->dev, "r8712u: USB_SPEED_LOW with %d endpoints\n",
0259              pdvobjpriv->nr_endpoint);
0260     }
0261     if ((r8712_alloc_io_queue(padapter)) == _FAIL)
0262         status = _FAIL;
0263     return status;
0264 }
0265 
0266 static void r8712_usb_dvobj_deinit(struct _adapter *padapter)
0267 {
0268     r8712_free_io_queue(padapter);
0269 }
0270 
0271 void rtl871x_intf_stop(struct _adapter *padapter)
0272 {
0273     /*disable_hw_interrupt*/
0274     if (!padapter->surprise_removed) {
0275         /*device still exists, so driver can do i/o operation
0276          * TODO:
0277          */
0278     }
0279 
0280     /* cancel in irp */
0281     if (padapter->dvobjpriv.inirp_deinit)
0282         padapter->dvobjpriv.inirp_deinit(padapter);
0283     /* cancel out irp */
0284     r8712_usb_write_port_cancel(padapter);
0285     /* TODO:cancel other irps */
0286 }
0287 
0288 void r871x_dev_unload(struct _adapter *padapter)
0289 {
0290     if (padapter->bup) {
0291         /*s1.*/
0292         padapter->driver_stopped = true;
0293 
0294         /*s3.*/
0295         rtl871x_intf_stop(padapter);
0296 
0297         /*s4.*/
0298         r8712_stop_drv_threads(padapter);
0299 
0300         /*s5.*/
0301         if (!padapter->surprise_removed) {
0302             padapter->hw_init_completed = false;
0303             rtl8712_hal_deinit(padapter);
0304         }
0305 
0306         padapter->bup = false;
0307     }
0308 }
0309 
0310 static void disable_ht_for_spec_devid(const struct usb_device_id *pdid,
0311                       struct _adapter *padapter)
0312 {
0313     u16 vid, pid;
0314     u32 flags;
0315     int i;
0316     int num = ARRAY_SIZE(specific_device_id_tbl);
0317 
0318     for (i = 0; i < num; i++) {
0319         vid = specific_device_id_tbl[i].idVendor;
0320         pid = specific_device_id_tbl[i].idProduct;
0321         flags = specific_device_id_tbl[i].flags;
0322 
0323         if ((pdid->idVendor == vid) && (pdid->idProduct == pid) &&
0324             (flags & SPEC_DEV_ID_DISABLE_HT)) {
0325             padapter->registrypriv.ht_enable = 0;
0326             padapter->registrypriv.cbw40_enable = 0;
0327             padapter->registrypriv.ampdu_enable = 0;
0328         }
0329     }
0330 }
0331 
0332 static const struct device_type wlan_type = {
0333     .name = "wlan",
0334 };
0335 
0336 /*
0337  * drv_init() - a device potentially for us
0338  *
0339  * notes: drv_init() is called when the bus driver has located a card for us
0340  * to support. We accept the new device by returning 0.
0341  */
0342 static int r871xu_drv_init(struct usb_interface *pusb_intf,
0343                const struct usb_device_id *pdid)
0344 {
0345     uint status;
0346     struct _adapter *padapter = NULL;
0347     struct dvobj_priv *pdvobjpriv;
0348     struct net_device *pnetdev;
0349     struct usb_device *udev;
0350 
0351     /* In this probe function, O.S. will provide the usb interface pointer
0352      * to driver. We have to increase the reference count of the usb device
0353      * structure by using the usb_get_dev function.
0354      */
0355     udev = interface_to_usbdev(pusb_intf);
0356     usb_get_dev(udev);
0357     pintf = pusb_intf;
0358     /* step 1. */
0359     pnetdev = r8712_init_netdev();
0360     if (!pnetdev)
0361         goto put_dev;
0362     padapter = netdev_priv(pnetdev);
0363     disable_ht_for_spec_devid(pdid, padapter);
0364     pdvobjpriv = &padapter->dvobjpriv;
0365     pdvobjpriv->padapter = padapter;
0366     padapter->dvobjpriv.pusbdev = udev;
0367     padapter->pusb_intf = pusb_intf;
0368     usb_set_intfdata(pusb_intf, pnetdev);
0369     SET_NETDEV_DEV(pnetdev, &pusb_intf->dev);
0370     pnetdev->dev.type = &wlan_type;
0371     /* step 2. */
0372     padapter->dvobj_init = r8712_usb_dvobj_init;
0373     padapter->dvobj_deinit = r8712_usb_dvobj_deinit;
0374     padapter->halpriv.hal_bus_init = r8712_usb_hal_bus_init;
0375     padapter->dvobjpriv.inirp_init = r8712_usb_inirp_init;
0376     padapter->dvobjpriv.inirp_deinit = r8712_usb_inirp_deinit;
0377     /* step 3.
0378      * initialize the dvobj_priv
0379      */
0380 
0381     status = padapter->dvobj_init(padapter);
0382     if (status != _SUCCESS)
0383         goto free_netdev;
0384 
0385     /* step 4. */
0386     status = r8712_init_drv_sw(padapter);
0387     if (status)
0388         goto dvobj_deinit;
0389     /* step 5. read efuse/eeprom data and get mac_addr */
0390     {
0391         int i, offset;
0392         u8 mac[6];
0393         u8 tmpU1b, AutoloadFail, eeprom_CustomerID;
0394         u8 *pdata = padapter->eeprompriv.efuse_eeprom_data;
0395 
0396         tmpU1b = r8712_read8(padapter, EE_9346CR);/*CR9346*/
0397 
0398         /* To check system boot selection.*/
0399         dev_info(&udev->dev, "r8712u: Boot from %s: Autoload %s\n",
0400              (tmpU1b & _9356SEL) ? "EEPROM" : "EFUSE",
0401              (tmpU1b & _EEPROM_EN) ? "OK" : "Failed");
0402 
0403         /* To check autoload success or not.*/
0404         if (tmpU1b & _EEPROM_EN) {
0405             AutoloadFail = true;
0406             /* The following operations prevent Efuse leakage by
0407              * turning on 2.5V.
0408              */
0409             tmpU1b = r8712_read8(padapter, EFUSE_TEST + 3);
0410             r8712_write8(padapter, EFUSE_TEST + 3, tmpU1b | 0x80);
0411             msleep(20);
0412             r8712_write8(padapter, EFUSE_TEST + 3,
0413                      (tmpU1b & (~BIT(7))));
0414 
0415             /* Retrieve Chip version.
0416              * Recognize IC version by Reg0x4 BIT15.
0417              */
0418             tmpU1b = (u8)((r8712_read32(padapter, PMC_FSM) >> 15) &
0419                             0x1F);
0420             if (tmpU1b == 0x3)
0421                 padapter->registrypriv.chip_version =
0422                      RTL8712_3rdCUT;
0423             else
0424                 padapter->registrypriv.chip_version =
0425                      (tmpU1b >> 1) + 1;
0426             switch (padapter->registrypriv.chip_version) {
0427             case RTL8712_1stCUT:
0428             case RTL8712_2ndCUT:
0429             case RTL8712_3rdCUT:
0430                 break;
0431             default:
0432                 padapter->registrypriv.chip_version =
0433                      RTL8712_2ndCUT;
0434                 break;
0435             }
0436 
0437             for (i = 0, offset = 0; i < 128; i += 8, offset++)
0438                 r8712_efuse_pg_packet_read(padapter, offset,
0439                              &pdata[i]);
0440 
0441             if (!r8712_initmac || !mac_pton(r8712_initmac, mac)) {
0442                 /* Use the mac address stored in the Efuse
0443                  * offset = 0x12 for usb in efuse
0444                  */
0445                 ether_addr_copy(mac, &pdata[0x12]);
0446             }
0447             eeprom_CustomerID = pdata[0x52];
0448             switch (eeprom_CustomerID) {
0449             case EEPROM_CID_ALPHA:
0450                 padapter->eeprompriv.CustomerID =
0451                          RT_CID_819x_ALPHA;
0452                 break;
0453             case EEPROM_CID_CAMEO:
0454                 padapter->eeprompriv.CustomerID =
0455                          RT_CID_819x_CAMEO;
0456                 break;
0457             case EEPROM_CID_SITECOM:
0458                 padapter->eeprompriv.CustomerID =
0459                          RT_CID_819x_Sitecom;
0460                 break;
0461             case EEPROM_CID_COREGA:
0462                 padapter->eeprompriv.CustomerID =
0463                          RT_CID_COREGA;
0464                 break;
0465             case EEPROM_CID_Senao:
0466                 padapter->eeprompriv.CustomerID =
0467                          RT_CID_819x_Senao;
0468                 break;
0469             case EEPROM_CID_EDIMAX_BELKIN:
0470                 padapter->eeprompriv.CustomerID =
0471                          RT_CID_819x_Edimax_Belkin;
0472                 break;
0473             case EEPROM_CID_SERCOMM_BELKIN:
0474                 padapter->eeprompriv.CustomerID =
0475                          RT_CID_819x_Sercomm_Belkin;
0476                 break;
0477             case EEPROM_CID_WNC_COREGA:
0478                 padapter->eeprompriv.CustomerID =
0479                          RT_CID_819x_WNC_COREGA;
0480                 break;
0481             case EEPROM_CID_WHQL:
0482                 break;
0483             case EEPROM_CID_NetCore:
0484                 padapter->eeprompriv.CustomerID =
0485                          RT_CID_819x_Netcore;
0486                 break;
0487             case EEPROM_CID_CAMEO1:
0488                 padapter->eeprompriv.CustomerID =
0489                          RT_CID_819x_CAMEO1;
0490                 break;
0491             case EEPROM_CID_CLEVO:
0492                 padapter->eeprompriv.CustomerID =
0493                          RT_CID_819x_CLEVO;
0494                 break;
0495             default:
0496                 padapter->eeprompriv.CustomerID =
0497                          RT_CID_DEFAULT;
0498                 break;
0499             }
0500             dev_info(&udev->dev, "r8712u: CustomerID = 0x%.4x\n",
0501                  padapter->eeprompriv.CustomerID);
0502             /* Led mode */
0503             switch (padapter->eeprompriv.CustomerID) {
0504             case RT_CID_DEFAULT:
0505             case RT_CID_819x_ALPHA:
0506             case RT_CID_819x_CAMEO:
0507                 padapter->ledpriv.LedStrategy = SW_LED_MODE1;
0508                 padapter->ledpriv.bRegUseLed = true;
0509                 break;
0510             case RT_CID_819x_Sitecom:
0511                 padapter->ledpriv.LedStrategy = SW_LED_MODE2;
0512                 padapter->ledpriv.bRegUseLed = true;
0513                 break;
0514             case RT_CID_COREGA:
0515             case RT_CID_819x_Senao:
0516                 padapter->ledpriv.LedStrategy = SW_LED_MODE3;
0517                 padapter->ledpriv.bRegUseLed = true;
0518                 break;
0519             case RT_CID_819x_Edimax_Belkin:
0520                 padapter->ledpriv.LedStrategy = SW_LED_MODE4;
0521                 padapter->ledpriv.bRegUseLed = true;
0522                 break;
0523             case RT_CID_819x_Sercomm_Belkin:
0524                 padapter->ledpriv.LedStrategy = SW_LED_MODE5;
0525                 padapter->ledpriv.bRegUseLed = true;
0526                 break;
0527             case RT_CID_819x_WNC_COREGA:
0528                 padapter->ledpriv.LedStrategy = SW_LED_MODE6;
0529                 padapter->ledpriv.bRegUseLed = true;
0530                 break;
0531             default:
0532                 padapter->ledpriv.LedStrategy = SW_LED_MODE0;
0533                 padapter->ledpriv.bRegUseLed = false;
0534                 break;
0535             }
0536         } else {
0537             AutoloadFail = false;
0538         }
0539         if ((!AutoloadFail) ||
0540             ((mac[0] == 0xff) && (mac[1] == 0xff) &&
0541              (mac[2] == 0xff) && (mac[3] == 0xff) &&
0542              (mac[4] == 0xff) && (mac[5] == 0xff)) ||
0543             ((mac[0] == 0x00) && (mac[1] == 0x00) &&
0544              (mac[2] == 0x00) && (mac[3] == 0x00) &&
0545              (mac[4] == 0x00) && (mac[5] == 0x00))) {
0546             mac[0] = 0x00;
0547             mac[1] = 0xe0;
0548             mac[2] = 0x4c;
0549             mac[3] = 0x87;
0550             mac[4] = 0x00;
0551             mac[5] = 0x00;
0552         }
0553         if (r8712_initmac) {
0554             /* Make sure the user did not select a multicast
0555              * address by setting bit 1 of first octet.
0556              */
0557             mac[0] &= 0xFE;
0558             dev_info(&udev->dev,
0559                 "r8712u: MAC Address from user = %pM\n", mac);
0560         } else {
0561             dev_info(&udev->dev,
0562                 "r8712u: MAC Address from efuse = %pM\n", mac);
0563         }
0564         eth_hw_addr_set(pnetdev, mac);
0565     }
0566     /* step 6. Load the firmware asynchronously */
0567     if (rtl871x_load_fw(padapter))
0568         goto deinit_drv_sw;
0569     init_completion(&padapter->rx_filter_ready);
0570     mutex_init(&padapter->mutex_start);
0571     return 0;
0572 
0573 deinit_drv_sw:
0574     r8712_free_drv_sw(padapter);
0575 dvobj_deinit:
0576     padapter->dvobj_deinit(padapter);
0577 free_netdev:
0578     free_netdev(pnetdev);
0579 put_dev:
0580     usb_put_dev(udev);
0581     usb_set_intfdata(pusb_intf, NULL);
0582     return -ENODEV;
0583 }
0584 
0585 /* rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove()
0586  * => how to recognize both
0587  */
0588 static void r871xu_dev_remove(struct usb_interface *pusb_intf)
0589 {
0590     struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
0591     struct usb_device *udev = interface_to_usbdev(pusb_intf);
0592     struct _adapter *padapter = netdev_priv(pnetdev);
0593 
0594     /* never exit with a firmware callback pending */
0595     wait_for_completion(&padapter->rtl8712_fw_ready);
0596     if (pnetdev->reg_state != NETREG_UNINITIALIZED)
0597         unregister_netdev(pnetdev); /* will call netdev_close() */
0598     usb_set_intfdata(pusb_intf, NULL);
0599     release_firmware(padapter->fw);
0600     if (drvpriv.drv_registered)
0601         padapter->surprise_removed = true;
0602     r8712_flush_rwctrl_works(padapter);
0603     r8712_flush_led_works(padapter);
0604     udelay(1);
0605     /* Stop driver mlme relation timer */
0606     r8712_stop_drv_timers(padapter);
0607     r871x_dev_unload(padapter);
0608     if (padapter->dvobj_deinit)
0609         padapter->dvobj_deinit(padapter);
0610     r8712_free_drv_sw(padapter);
0611     free_netdev(pnetdev);
0612 
0613     /* decrease the reference count of the usb device structure
0614      * when disconnect
0615      */
0616     usb_put_dev(udev);
0617 
0618     /* If we didn't unplug usb dongle and remove/insert module, driver
0619      * fails on sitesurvey for the first time when device is up.
0620      * Reset usb port for sitesurvey fail issue.
0621      */
0622     if (udev->state != USB_STATE_NOTATTACHED)
0623         usb_reset_device(udev);
0624 }
0625 
0626 static int __init r8712u_drv_entry(void)
0627 {
0628     drvpriv.drv_registered = true;
0629     return usb_register(&drvpriv.r871xu_drv);
0630 }
0631 
0632 static void __exit r8712u_drv_halt(void)
0633 {
0634     drvpriv.drv_registered = false;
0635     usb_deregister(&drvpriv.r871xu_drv);
0636 }
0637 
0638 module_init(r8712u_drv_entry);
0639 module_exit(r8712u_drv_halt);