1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
53
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
60 {USB_DEVICE(0x07B8, 0x8188)},
61
62 {USB_DEVICE(0x0B05, 0x1786)},
63 {USB_DEVICE(0x0B05, 0x1791)},
64
65 {USB_DEVICE(0x050D, 0x945A)},
66
67 {USB_DEVICE(0x050D, 0x11F1)},
68
69 {USB_DEVICE(0x07AA, 0x0047)},
70
71 {USB_DEVICE(0x2001, 0x3306)},
72 {USB_DEVICE(0x07D1, 0x3306)},
73
74 {USB_DEVICE(0x7392, 0x7611)},
75
76 {USB_DEVICE(0x1740, 0x9603)},
77
78 {USB_DEVICE(0x0E66, 0x0016)},
79
80 {USB_DEVICE(0x06F8, 0xE034)},
81 {USB_DEVICE(0x06F8, 0xE032)},
82
83 {USB_DEVICE(0x0789, 0x0167)},
84
85 {USB_DEVICE(0x2019, 0xAB28)},
86 {USB_DEVICE(0x2019, 0xED16)},
87
88 {USB_DEVICE(0x0DF6, 0x0057)},
89 {USB_DEVICE(0x0DF6, 0x0045)},
90 {USB_DEVICE(0x0DF6, 0x0059)},
91 {USB_DEVICE(0x0DF6, 0x004B)},
92 {USB_DEVICE(0x0DF6, 0x005B)},
93 {USB_DEVICE(0x0DF6, 0x005D)},
94 {USB_DEVICE(0x0DF6, 0x0063)},
95
96 {USB_DEVICE(0x177F, 0x0154)},
97
98 {USB_DEVICE(0x0BDA, 0x5077)},
99
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
108
109 {USB_DEVICE(0x0BDA, 0x8172)},
110 {USB_DEVICE(0x0BDA, 0x8192)},
111
112 {USB_DEVICE(0x0EB0, 0x9061)},
113
114 {USB_DEVICE(0x13D3, 0x3323)},
115 {USB_DEVICE(0x13D3, 0x3311)},
116 {USB_DEVICE(0x13D3, 0x3342)},
117
118 {USB_DEVICE(0x13D3, 0x3333)},
119 {USB_DEVICE(0x13D3, 0x3334)},
120 {USB_DEVICE(0x13D3, 0x3335)},
121 {USB_DEVICE(0x13D3, 0x3336)},
122
123 {USB_DEVICE(0x13D3, 0x3309)},
124
125 {USB_DEVICE(0x050D, 0x815F)},
126
127 {USB_DEVICE(0x07D1, 0x3302)},
128 {USB_DEVICE(0x07D1, 0x3300)},
129 {USB_DEVICE(0x07D1, 0x3303)},
130
131 {USB_DEVICE(0x7392, 0x7612)},
132
133 {USB_DEVICE(0x1740, 0x9605)},
134
135 {USB_DEVICE(0x06F8, 0xE031)},
136
137 {USB_DEVICE(0x0E66, 0x0015)},
138
139 {USB_DEVICE(0x13D3, 0x3306)},
140
141 {USB_DEVICE(0x2019, 0xED18)},
142 {USB_DEVICE(0x2019, 0x4901)},
143
144 {USB_DEVICE(0x0DF6, 0x0058)},
145 {USB_DEVICE(0x0DF6, 0x0049)},
146 {USB_DEVICE(0x0DF6, 0x004C)},
147 {USB_DEVICE(0x0DF6, 0x0064)},
148
149 {USB_DEVICE(0x14b2, 0x3300)},
150 {USB_DEVICE(0x14b2, 0x3301)},
151 {USB_DEVICE(0x14B2, 0x3302)},
152
153 {USB_DEVICE(0x04F2, 0xAFF2)},
154 {USB_DEVICE(0x04F2, 0xAFF5)},
155 {USB_DEVICE(0x04F2, 0xAFF6)},
156 {USB_DEVICE(0x13D3, 0x3339)},
157 {USB_DEVICE(0x13D3, 0x3340)},
158 {USB_DEVICE(0x13D3, 0x3341)},
159 {USB_DEVICE(0x13D3, 0x3310)},
160 {USB_DEVICE(0x13D3, 0x3325)},
161
162
163
164 {USB_DEVICE(0x0BDA, 0x8174)},
165
166 {USB_DEVICE(0x050D, 0x845A)},
167
168 {USB_DEVICE(0x07AA, 0x0051)},
169
170 {USB_DEVICE(0x7392, 0x7622)},
171
172 {USB_DEVICE(0x0409, 0x02B6)},
173 {}
174};
175
176MODULE_DEVICE_TABLE(usb, rtl871x_usb_id_tbl);
177
178static struct specific_device_id specific_device_id_tbl[] = {
179 {.idVendor = 0x0b05, .idProduct = 0x1791,
180 .flags = SPEC_DEV_ID_DISABLE_HT},
181 {.idVendor = 0x0df6, .idProduct = 0x0059,
182 .flags = SPEC_DEV_ID_DISABLE_HT},
183 {.idVendor = 0x13d3, .idProduct = 0x3306,
184 .flags = SPEC_DEV_ID_DISABLE_HT},
185 {.idVendor = 0x13D3, .idProduct = 0x3311,
186 .flags = SPEC_DEV_ID_DISABLE_HT},
187 {.idVendor = 0x13d3, .idProduct = 0x3335,
188 .flags = SPEC_DEV_ID_DISABLE_HT},
189 {.idVendor = 0x13d3, .idProduct = 0x3336,
190 .flags = SPEC_DEV_ID_DISABLE_HT},
191 {.idVendor = 0x13d3, .idProduct = 0x3340,
192 .flags = SPEC_DEV_ID_DISABLE_HT},
193 {.idVendor = 0x13d3, .idProduct = 0x3341,
194 .flags = SPEC_DEV_ID_DISABLE_HT},
195 {}
196};
197
198struct drv_priv {
199 struct usb_driver r871xu_drv;
200 int drv_registered;
201};
202
203#ifdef CONFIG_PM
204static int r871x_suspend(struct usb_interface *pusb_intf, pm_message_t state)
205{
206 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
207
208 netdev_info(pnetdev, "Suspending...\n");
209 if (!pnetdev || !netif_running(pnetdev)) {
210 netdev_info(pnetdev, "Unable to suspend\n");
211 return 0;
212 }
213 if (pnetdev->netdev_ops->ndo_stop)
214 pnetdev->netdev_ops->ndo_stop(pnetdev);
215 mdelay(10);
216 netif_device_detach(pnetdev);
217 return 0;
218}
219
220static int r871x_resume(struct usb_interface *pusb_intf)
221{
222 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
223
224 netdev_info(pnetdev, "Resuming...\n");
225 if (!pnetdev || !netif_running(pnetdev)) {
226 netdev_info(pnetdev, "Unable to resume\n");
227 return 0;
228 }
229 netif_device_attach(pnetdev);
230 if (pnetdev->netdev_ops->ndo_open)
231 pnetdev->netdev_ops->ndo_open(pnetdev);
232 return 0;
233}
234
235static int r871x_reset_resume(struct usb_interface *pusb_intf)
236{
237
238 return 0;
239}
240
241#endif
242
243static struct drv_priv drvpriv = {
244 .r871xu_drv.name = "r8712u",
245 .r871xu_drv.id_table = rtl871x_usb_id_tbl,
246 .r871xu_drv.probe = r871xu_drv_init,
247 .r871xu_drv.disconnect = r871xu_dev_remove,
248#ifdef CONFIG_PM
249 .r871xu_drv.suspend = r871x_suspend,
250 .r871xu_drv.resume = r871x_resume,
251 .r871xu_drv.reset_resume = r871x_reset_resume,
252#endif
253};
254
255static uint r8712_usb_dvobj_init(struct _adapter *padapter)
256{
257 uint status = _SUCCESS;
258 struct usb_device_descriptor *pdev_desc;
259 struct usb_host_config *phost_conf;
260 struct usb_config_descriptor *pconf_desc;
261 struct usb_host_interface *phost_iface;
262 struct usb_interface_descriptor *piface_desc;
263 struct dvobj_priv *pdvobjpriv = &padapter->dvobjpriv;
264 struct usb_device *pusbd = pdvobjpriv->pusbdev;
265
266 pdvobjpriv->padapter = padapter;
267 padapter->EepromAddressSize = 6;
268 pdev_desc = &pusbd->descriptor;
269 phost_conf = pusbd->actconfig;
270 pconf_desc = &phost_conf->desc;
271 phost_iface = &pintf->altsetting[0];
272 piface_desc = &phost_iface->desc;
273 pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
274 if (pusbd->speed == USB_SPEED_HIGH) {
275 pdvobjpriv->ishighspeed = true;
276 dev_info(&pusbd->dev, "r8712u: USB_SPEED_HIGH with %d endpoints\n",
277 pdvobjpriv->nr_endpoint);
278 } else {
279 pdvobjpriv->ishighspeed = false;
280 dev_info(&pusbd->dev, "r8712u: USB_SPEED_LOW with %d endpoints\n",
281 pdvobjpriv->nr_endpoint);
282 }
283 if ((r8712_alloc_io_queue(padapter)) == _FAIL)
284 status = _FAIL;
285 return status;
286}
287
288static void r8712_usb_dvobj_deinit(struct _adapter *padapter)
289{
290}
291
292void rtl871x_intf_stop(struct _adapter *padapter)
293{
294
295 if (padapter->bSurpriseRemoved == false) {
296
297
298 }
299
300
301 if (padapter->dvobjpriv.inirp_deinit != NULL)
302 padapter->dvobjpriv.inirp_deinit(padapter);
303
304 r8712_usb_write_port_cancel(padapter);
305
306}
307
308void r871x_dev_unload(struct _adapter *padapter)
309{
310 if (padapter->bup == true) {
311
312 padapter->bDriverStopped = true;
313
314
315 rtl871x_intf_stop(padapter);
316
317
318 r8712_stop_drv_threads(padapter);
319
320
321 if (padapter->bSurpriseRemoved == false) {
322 padapter->hw_init_completed = false;
323 rtl8712_hal_deinit(padapter);
324 }
325
326
327 if (padapter->dvobj_deinit)
328 padapter->dvobj_deinit(padapter);
329 padapter->bup = false;
330 }
331}
332
333static void disable_ht_for_spec_devid(const struct usb_device_id *pdid,
334 struct _adapter *padapter)
335{
336 u16 vid, pid;
337 u32 flags;
338 int i;
339 int num = sizeof(specific_device_id_tbl) /
340 sizeof(struct specific_device_id);
341
342 for (i = 0; i < num; i++) {
343 vid = specific_device_id_tbl[i].idVendor;
344 pid = specific_device_id_tbl[i].idProduct;
345 flags = specific_device_id_tbl[i].flags;
346
347 if ((pdid->idVendor == vid) && (pdid->idProduct == pid) &&
348 (flags&SPEC_DEV_ID_DISABLE_HT)) {
349 padapter->registrypriv.ht_enable = 0;
350 padapter->registrypriv.cbw40_enable = 0;
351 padapter->registrypriv.ampdu_enable = 0;
352 }
353 }
354}
355
356static const struct device_type wlan_type = {
357 .name = "wlan",
358};
359
360
361
362
363
364
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: Staging version\n");
376
377
378
379
380 udev = interface_to_usbdev(pusb_intf);
381 usb_get_dev(udev);
382 pintf = pusb_intf;
383
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 padapter->pusb_intf = pusb_intf;
393 usb_set_intfdata(pusb_intf, pnetdev);
394 SET_NETDEV_DEV(pnetdev, &pusb_intf->dev);
395 pnetdev->dev.type = &wlan_type;
396
397 padapter->dvobj_init = &r8712_usb_dvobj_init;
398 padapter->dvobj_deinit = &r8712_usb_dvobj_deinit;
399 padapter->halpriv.hal_bus_init = &r8712_usb_hal_bus_init;
400 padapter->dvobjpriv.inirp_init = &r8712_usb_inirp_init;
401 padapter->dvobjpriv.inirp_deinit = &r8712_usb_inirp_deinit;
402
403
404
405 if (padapter->dvobj_init == NULL)
406 goto error;
407 else {
408 status = padapter->dvobj_init(padapter);
409 if (status != _SUCCESS)
410 goto error;
411 }
412
413 status = r8712_init_drv_sw(padapter);
414 if (status == _FAIL)
415 goto error;
416
417 {
418 int i, offset;
419 u8 mac[6];
420 u8 tmpU1b, AutoloadFail, eeprom_CustomerID;
421 u8 *pdata = padapter->eeprompriv.efuse_eeprom_data;
422
423 tmpU1b = r8712_read8(padapter, EE_9346CR);
424
425
426 dev_info(&udev->dev, "r8712u: Boot from %s: Autoload %s\n",
427 (tmpU1b & _9356SEL) ? "EEPROM" : "EFUSE",
428 (tmpU1b & _EEPROM_EN) ? "OK" : "Failed");
429
430
431 if (tmpU1b & _EEPROM_EN) {
432 AutoloadFail = true;
433
434
435
436 tmpU1b = r8712_read8(padapter, EFUSE_TEST+3);
437 r8712_write8(padapter, EFUSE_TEST + 3, tmpU1b | 0x80);
438 msleep(20);
439 r8712_write8(padapter, EFUSE_TEST + 3,
440 (tmpU1b & (~BIT(7))));
441
442
443
444
445 tmpU1b = (u8)((r8712_read32(padapter, PMC_FSM) >> 15) &
446 0x1F);
447 if (tmpU1b == 0x3)
448 padapter->registrypriv.chip_version =
449 RTL8712_3rdCUT;
450 else
451 padapter->registrypriv.chip_version =
452 (tmpU1b >> 1) + 1;
453 switch (padapter->registrypriv.chip_version) {
454 case RTL8712_1stCUT:
455 case RTL8712_2ndCUT:
456 case RTL8712_3rdCUT:
457 break;
458 default:
459 padapter->registrypriv.chip_version =
460 RTL8712_2ndCUT;
461 break;
462 }
463
464 for (i = 0, offset = 0; i < 128; i += 8, offset++)
465 r8712_efuse_pg_packet_read(padapter, offset,
466 &pdata[i]);
467
468 if (!r8712_initmac || !mac_pton(r8712_initmac, mac)) {
469
470
471
472 memcpy(mac, &pdata[0x12], ETH_ALEN);
473 }
474 eeprom_CustomerID = pdata[0x52];
475 switch (eeprom_CustomerID) {
476 case EEPROM_CID_ALPHA:
477 padapter->eeprompriv.CustomerID =
478 RT_CID_819x_ALPHA;
479 break;
480 case EEPROM_CID_CAMEO:
481 padapter->eeprompriv.CustomerID =
482 RT_CID_819x_CAMEO;
483 break;
484 case EEPROM_CID_SITECOM:
485 padapter->eeprompriv.CustomerID =
486 RT_CID_819x_Sitecom;
487 break;
488 case EEPROM_CID_COREGA:
489 padapter->eeprompriv.CustomerID =
490 RT_CID_COREGA;
491 break;
492 case EEPROM_CID_Senao:
493 padapter->eeprompriv.CustomerID =
494 RT_CID_819x_Senao;
495 break;
496 case EEPROM_CID_EDIMAX_BELKIN:
497 padapter->eeprompriv.CustomerID =
498 RT_CID_819x_Edimax_Belkin;
499 break;
500 case EEPROM_CID_SERCOMM_BELKIN:
501 padapter->eeprompriv.CustomerID =
502 RT_CID_819x_Sercomm_Belkin;
503 break;
504 case EEPROM_CID_WNC_COREGA:
505 padapter->eeprompriv.CustomerID =
506 RT_CID_819x_WNC_COREGA;
507 break;
508 case EEPROM_CID_WHQL:
509 break;
510 case EEPROM_CID_NetCore:
511 padapter->eeprompriv.CustomerID =
512 RT_CID_819x_Netcore;
513 break;
514 case EEPROM_CID_CAMEO1:
515 padapter->eeprompriv.CustomerID =
516 RT_CID_819x_CAMEO1;
517 break;
518 case EEPROM_CID_CLEVO:
519 padapter->eeprompriv.CustomerID =
520 RT_CID_819x_CLEVO;
521 break;
522 default:
523 padapter->eeprompriv.CustomerID =
524 RT_CID_DEFAULT;
525 break;
526 }
527 dev_info(&udev->dev, "r8712u: CustomerID = 0x%.4x\n",
528 padapter->eeprompriv.CustomerID);
529
530 switch (padapter->eeprompriv.CustomerID) {
531 case RT_CID_DEFAULT:
532 case RT_CID_819x_ALPHA:
533 case RT_CID_819x_CAMEO:
534 padapter->ledpriv.LedStrategy = SW_LED_MODE1;
535 padapter->ledpriv.bRegUseLed = true;
536 break;
537 case RT_CID_819x_Sitecom:
538 padapter->ledpriv.LedStrategy = SW_LED_MODE2;
539 padapter->ledpriv.bRegUseLed = true;
540 break;
541 case RT_CID_COREGA:
542 case RT_CID_819x_Senao:
543 padapter->ledpriv.LedStrategy = SW_LED_MODE3;
544 padapter->ledpriv.bRegUseLed = true;
545 break;
546 case RT_CID_819x_Edimax_Belkin:
547 padapter->ledpriv.LedStrategy = SW_LED_MODE4;
548 padapter->ledpriv.bRegUseLed = true;
549 break;
550 case RT_CID_819x_Sercomm_Belkin:
551 padapter->ledpriv.LedStrategy = SW_LED_MODE5;
552 padapter->ledpriv.bRegUseLed = true;
553 break;
554 case RT_CID_819x_WNC_COREGA:
555 padapter->ledpriv.LedStrategy = SW_LED_MODE6;
556 padapter->ledpriv.bRegUseLed = true;
557 break;
558 default:
559 padapter->ledpriv.LedStrategy = SW_LED_MODE0;
560 padapter->ledpriv.bRegUseLed = false;
561 break;
562 }
563 } else
564 AutoloadFail = false;
565 if (((mac[0] == 0xff) && (mac[1] == 0xff) &&
566 (mac[2] == 0xff) && (mac[3] == 0xff) &&
567 (mac[4] == 0xff) && (mac[5] == 0xff)) ||
568 ((mac[0] == 0x00) && (mac[1] == 0x00) &&
569 (mac[2] == 0x00) && (mac[3] == 0x00) &&
570 (mac[4] == 0x00) && (mac[5] == 0x00)) ||
571 (AutoloadFail == false)) {
572 mac[0] = 0x00;
573 mac[1] = 0xe0;
574 mac[2] = 0x4c;
575 mac[3] = 0x87;
576 mac[4] = 0x00;
577 mac[5] = 0x00;
578 }
579 if (r8712_initmac) {
580
581
582
583 mac[0] &= 0xFE;
584 dev_info(&udev->dev, "r8712u: MAC Address from user = %pM\n", mac);
585 } else
586 dev_info(&udev->dev, "r8712u: MAC Address from efuse = %pM\n", mac);
587 memcpy(pnetdev->dev_addr, mac, ETH_ALEN);
588 }
589
590 if (rtl871x_load_fw(padapter))
591 goto error;
592 spin_lock_init(&padapter->lockRxFF0Filter);
593 mutex_init(&padapter->mutex_start);
594 return 0;
595error:
596 usb_put_dev(udev);
597 usb_set_intfdata(pusb_intf, NULL);
598 if (padapter && padapter->dvobj_deinit != NULL)
599 padapter->dvobj_deinit(padapter);
600 if (pnetdev)
601 free_netdev(pnetdev);
602 return -ENODEV;
603}
604
605
606
607static void r871xu_dev_remove(struct usb_interface *pusb_intf)
608{
609 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
610 struct _adapter *padapter = netdev_priv(pnetdev);
611 struct usb_device *udev = interface_to_usbdev(pusb_intf);
612
613 usb_set_intfdata(pusb_intf, NULL);
614 if (padapter->fw_found)
615 release_firmware(padapter->fw);
616
617 wait_for_completion(&padapter->rtl8712_fw_ready);
618 if (drvpriv.drv_registered == true)
619 padapter->bSurpriseRemoved = true;
620 if (pnetdev != NULL) {
621
622 unregister_netdev(pnetdev);
623 }
624 flush_scheduled_work();
625 udelay(1);
626
627 if (padapter->fw_found)
628 r8712_stop_drv_timers(padapter);
629 r871x_dev_unload(padapter);
630 r8712_free_drv_sw(padapter);
631 usb_set_intfdata(pusb_intf, NULL);
632
633
634 usb_put_dev(udev);
635
636
637
638 if (udev->state != USB_STATE_NOTATTACHED)
639 usb_reset_device(udev);
640 return;
641}
642
643static int __init r8712u_drv_entry(void)
644{
645 drvpriv.drv_registered = true;
646 return usb_register(&drvpriv.r871xu_drv);
647}
648
649static void __exit r8712u_drv_halt(void)
650{
651 drvpriv.drv_registered = false;
652 usb_deregister(&drvpriv.r871xu_drv);
653}
654
655module_init(r8712u_drv_entry);
656module_exit(r8712u_drv_halt);
657