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