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 const 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, 0x006C)},
148 {USB_DEVICE(0x0DF6, 0x0064)},
149
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)},
159 {USB_DEVICE(0x13D3, 0x3341)},
160 {USB_DEVICE(0x13D3, 0x3310)},
161 {USB_DEVICE(0x13D3, 0x3325)},
162
163
164
165 {USB_DEVICE(0x0BDA, 0x8174)},
166
167 {USB_DEVICE(0x050D, 0x845A)},
168
169 {USB_DEVICE(0x07AA, 0x0051)},
170
171 {USB_DEVICE(0x7392, 0x7622)},
172
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 struct _adapter *padapter = netdev_priv(pnetdev);
209
210 netdev_info(pnetdev, "Suspending...\n");
211 if (!pnetdev || !netif_running(pnetdev)) {
212 netdev_info(pnetdev, "Unable to suspend\n");
213 return 0;
214 }
215 padapter->bSuspended = true;
216 rtl871x_intf_stop(padapter);
217 if (pnetdev->netdev_ops->ndo_stop)
218 pnetdev->netdev_ops->ndo_stop(pnetdev);
219 mdelay(10);
220 netif_device_detach(pnetdev);
221 return 0;
222}
223
224static void rtl871x_intf_resume(struct _adapter *padapter)
225{
226 if (padapter->dvobjpriv.inirp_init)
227 padapter->dvobjpriv.inirp_init(padapter);
228}
229
230static int r871x_resume(struct usb_interface *pusb_intf)
231{
232 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
233 struct _adapter *padapter = netdev_priv(pnetdev);
234
235 netdev_info(pnetdev, "Resuming...\n");
236 if (!pnetdev || !netif_running(pnetdev)) {
237 netdev_info(pnetdev, "Unable to resume\n");
238 return 0;
239 }
240 netif_device_attach(pnetdev);
241 if (pnetdev->netdev_ops->ndo_open)
242 pnetdev->netdev_ops->ndo_open(pnetdev);
243 padapter->bSuspended = false;
244 rtl871x_intf_resume(padapter);
245 return 0;
246}
247
248static int r871x_reset_resume(struct usb_interface *pusb_intf)
249{
250
251 return 0;
252}
253
254#endif
255
256static struct drv_priv drvpriv = {
257 .r871xu_drv.name = "r8712u",
258 .r871xu_drv.id_table = rtl871x_usb_id_tbl,
259 .r871xu_drv.probe = r871xu_drv_init,
260 .r871xu_drv.disconnect = r871xu_dev_remove,
261#ifdef CONFIG_PM
262 .r871xu_drv.suspend = r871x_suspend,
263 .r871xu_drv.resume = r871x_resume,
264 .r871xu_drv.reset_resume = r871x_reset_resume,
265#endif
266};
267
268static uint r8712_usb_dvobj_init(struct _adapter *padapter)
269{
270 uint status = _SUCCESS;
271 struct usb_host_interface *phost_iface;
272 struct usb_interface_descriptor *piface_desc;
273 struct dvobj_priv *pdvobjpriv = &padapter->dvobjpriv;
274 struct usb_device *pusbd = pdvobjpriv->pusbdev;
275
276 pdvobjpriv->padapter = padapter;
277 padapter->EepromAddressSize = 6;
278 phost_iface = &pintf->altsetting[0];
279 piface_desc = &phost_iface->desc;
280 pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
281 if (pusbd->speed == USB_SPEED_HIGH) {
282 pdvobjpriv->ishighspeed = true;
283 dev_info(&pusbd->dev, "r8712u: USB_SPEED_HIGH with %d endpoints\n",
284 pdvobjpriv->nr_endpoint);
285 } else {
286 pdvobjpriv->ishighspeed = false;
287 dev_info(&pusbd->dev, "r8712u: USB_SPEED_LOW with %d endpoints\n",
288 pdvobjpriv->nr_endpoint);
289 }
290 if ((r8712_alloc_io_queue(padapter)) == _FAIL)
291 status = _FAIL;
292 return status;
293}
294
295static void r8712_usb_dvobj_deinit(struct _adapter *padapter)
296{
297}
298
299void rtl871x_intf_stop(struct _adapter *padapter)
300{
301
302 if (!padapter->bSurpriseRemoved) {
303
304
305
306 }
307
308
309 if (padapter->dvobjpriv.inirp_deinit)
310 padapter->dvobjpriv.inirp_deinit(padapter);
311
312 r8712_usb_write_port_cancel(padapter);
313
314}
315
316void r871x_dev_unload(struct _adapter *padapter)
317{
318 if (padapter->bup) {
319
320 padapter->bDriverStopped = true;
321
322
323 rtl871x_intf_stop(padapter);
324
325
326 r8712_stop_drv_threads(padapter);
327
328
329 if (!padapter->bSurpriseRemoved) {
330 padapter->hw_init_completed = false;
331 rtl8712_hal_deinit(padapter);
332 }
333
334
335 if (padapter->dvobj_deinit)
336 padapter->dvobj_deinit(padapter);
337 padapter->bup = false;
338 }
339}
340
341static void disable_ht_for_spec_devid(const struct usb_device_id *pdid,
342 struct _adapter *padapter)
343{
344 u16 vid, pid;
345 u32 flags;
346 int i;
347 int num = ARRAY_SIZE(specific_device_id_tbl);
348
349 for (i = 0; i < num; i++) {
350 vid = specific_device_id_tbl[i].idVendor;
351 pid = specific_device_id_tbl[i].idProduct;
352 flags = specific_device_id_tbl[i].flags;
353
354 if ((pdid->idVendor == vid) && (pdid->idProduct == pid) &&
355 (flags & SPEC_DEV_ID_DISABLE_HT)) {
356 padapter->registrypriv.ht_enable = 0;
357 padapter->registrypriv.cbw40_enable = 0;
358 padapter->registrypriv.ampdu_enable = 0;
359 }
360 }
361}
362
363static const struct device_type wlan_type = {
364 .name = "wlan",
365};
366
367
368
369
370
371
372
373static int r871xu_drv_init(struct usb_interface *pusb_intf,
374 const struct usb_device_id *pdid)
375{
376 uint status;
377 struct _adapter *padapter = NULL;
378 struct dvobj_priv *pdvobjpriv;
379 struct net_device *pnetdev;
380 struct usb_device *udev;
381
382
383
384
385
386 udev = interface_to_usbdev(pusb_intf);
387 usb_get_dev(udev);
388 pintf = pusb_intf;
389
390 pnetdev = r8712_init_netdev();
391 if (!pnetdev)
392 goto error;
393 padapter = netdev_priv(pnetdev);
394 disable_ht_for_spec_devid(pdid, padapter);
395 pdvobjpriv = &padapter->dvobjpriv;
396 pdvobjpriv->padapter = padapter;
397 padapter->dvobjpriv.pusbdev = udev;
398 padapter->pusb_intf = pusb_intf;
399 usb_set_intfdata(pusb_intf, pnetdev);
400 SET_NETDEV_DEV(pnetdev, &pusb_intf->dev);
401 pnetdev->dev.type = &wlan_type;
402
403 padapter->dvobj_init = r8712_usb_dvobj_init;
404 padapter->dvobj_deinit = r8712_usb_dvobj_deinit;
405 padapter->halpriv.hal_bus_init = r8712_usb_hal_bus_init;
406 padapter->dvobjpriv.inirp_init = r8712_usb_inirp_init;
407 padapter->dvobjpriv.inirp_deinit = r8712_usb_inirp_deinit;
408
409
410
411 if (!padapter->dvobj_init) {
412 goto error;
413 } else {
414 status = padapter->dvobj_init(padapter);
415 if (status != _SUCCESS)
416 goto error;
417 }
418
419 status = r8712_init_drv_sw(padapter);
420 if (status == _FAIL)
421 goto error;
422
423 {
424 int i, offset;
425 u8 mac[6];
426 u8 tmpU1b, AutoloadFail, eeprom_CustomerID;
427 u8 *pdata = padapter->eeprompriv.efuse_eeprom_data;
428
429 tmpU1b = r8712_read8(padapter, EE_9346CR);
430
431
432 dev_info(&udev->dev, "r8712u: Boot from %s: Autoload %s\n",
433 (tmpU1b & _9356SEL) ? "EEPROM" : "EFUSE",
434 (tmpU1b & _EEPROM_EN) ? "OK" : "Failed");
435
436
437 if (tmpU1b & _EEPROM_EN) {
438 AutoloadFail = true;
439
440
441
442 tmpU1b = r8712_read8(padapter, EFUSE_TEST + 3);
443 r8712_write8(padapter, EFUSE_TEST + 3, tmpU1b | 0x80);
444 msleep(20);
445 r8712_write8(padapter, EFUSE_TEST + 3,
446 (tmpU1b & (~BIT(7))));
447
448
449
450
451 tmpU1b = (u8)((r8712_read32(padapter, PMC_FSM) >> 15) &
452 0x1F);
453 if (tmpU1b == 0x3)
454 padapter->registrypriv.chip_version =
455 RTL8712_3rdCUT;
456 else
457 padapter->registrypriv.chip_version =
458 (tmpU1b >> 1) + 1;
459 switch (padapter->registrypriv.chip_version) {
460 case RTL8712_1stCUT:
461 case RTL8712_2ndCUT:
462 case RTL8712_3rdCUT:
463 break;
464 default:
465 padapter->registrypriv.chip_version =
466 RTL8712_2ndCUT;
467 break;
468 }
469
470 for (i = 0, offset = 0; i < 128; i += 8, offset++)
471 r8712_efuse_pg_packet_read(padapter, offset,
472 &pdata[i]);
473
474 if (!r8712_initmac || !mac_pton(r8712_initmac, mac)) {
475
476
477
478 ether_addr_copy(mac, &pdata[0x12]);
479 }
480 eeprom_CustomerID = pdata[0x52];
481 switch (eeprom_CustomerID) {
482 case EEPROM_CID_ALPHA:
483 padapter->eeprompriv.CustomerID =
484 RT_CID_819x_ALPHA;
485 break;
486 case EEPROM_CID_CAMEO:
487 padapter->eeprompriv.CustomerID =
488 RT_CID_819x_CAMEO;
489 break;
490 case EEPROM_CID_SITECOM:
491 padapter->eeprompriv.CustomerID =
492 RT_CID_819x_Sitecom;
493 break;
494 case EEPROM_CID_COREGA:
495 padapter->eeprompriv.CustomerID =
496 RT_CID_COREGA;
497 break;
498 case EEPROM_CID_Senao:
499 padapter->eeprompriv.CustomerID =
500 RT_CID_819x_Senao;
501 break;
502 case EEPROM_CID_EDIMAX_BELKIN:
503 padapter->eeprompriv.CustomerID =
504 RT_CID_819x_Edimax_Belkin;
505 break;
506 case EEPROM_CID_SERCOMM_BELKIN:
507 padapter->eeprompriv.CustomerID =
508 RT_CID_819x_Sercomm_Belkin;
509 break;
510 case EEPROM_CID_WNC_COREGA:
511 padapter->eeprompriv.CustomerID =
512 RT_CID_819x_WNC_COREGA;
513 break;
514 case EEPROM_CID_WHQL:
515 break;
516 case EEPROM_CID_NetCore:
517 padapter->eeprompriv.CustomerID =
518 RT_CID_819x_Netcore;
519 break;
520 case EEPROM_CID_CAMEO1:
521 padapter->eeprompriv.CustomerID =
522 RT_CID_819x_CAMEO1;
523 break;
524 case EEPROM_CID_CLEVO:
525 padapter->eeprompriv.CustomerID =
526 RT_CID_819x_CLEVO;
527 break;
528 default:
529 padapter->eeprompriv.CustomerID =
530 RT_CID_DEFAULT;
531 break;
532 }
533 dev_info(&udev->dev, "r8712u: CustomerID = 0x%.4x\n",
534 padapter->eeprompriv.CustomerID);
535
536 switch (padapter->eeprompriv.CustomerID) {
537 case RT_CID_DEFAULT:
538 case RT_CID_819x_ALPHA:
539 case RT_CID_819x_CAMEO:
540 padapter->ledpriv.LedStrategy = SW_LED_MODE1;
541 padapter->ledpriv.bRegUseLed = true;
542 break;
543 case RT_CID_819x_Sitecom:
544 padapter->ledpriv.LedStrategy = SW_LED_MODE2;
545 padapter->ledpriv.bRegUseLed = true;
546 break;
547 case RT_CID_COREGA:
548 case RT_CID_819x_Senao:
549 padapter->ledpriv.LedStrategy = SW_LED_MODE3;
550 padapter->ledpriv.bRegUseLed = true;
551 break;
552 case RT_CID_819x_Edimax_Belkin:
553 padapter->ledpriv.LedStrategy = SW_LED_MODE4;
554 padapter->ledpriv.bRegUseLed = true;
555 break;
556 case RT_CID_819x_Sercomm_Belkin:
557 padapter->ledpriv.LedStrategy = SW_LED_MODE5;
558 padapter->ledpriv.bRegUseLed = true;
559 break;
560 case RT_CID_819x_WNC_COREGA:
561 padapter->ledpriv.LedStrategy = SW_LED_MODE6;
562 padapter->ledpriv.bRegUseLed = true;
563 break;
564 default:
565 padapter->ledpriv.LedStrategy = SW_LED_MODE0;
566 padapter->ledpriv.bRegUseLed = false;
567 break;
568 }
569 } else {
570 AutoloadFail = false;
571 }
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)) {
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
588
589
590 mac[0] &= 0xFE;
591 dev_info(&udev->dev,
592 "r8712u: MAC Address from user = %pM\n", mac);
593 } else {
594 dev_info(&udev->dev,
595 "r8712u: MAC Address from efuse = %pM\n", mac);
596 }
597 ether_addr_copy(pnetdev->dev_addr, mac);
598 }
599
600 if (rtl871x_load_fw(padapter))
601 goto error;
602 spin_lock_init(&padapter->lockRxFF0Filter);
603 mutex_init(&padapter->mutex_start);
604 return 0;
605error:
606 usb_put_dev(udev);
607 usb_set_intfdata(pusb_intf, NULL);
608 if (padapter && padapter->dvobj_deinit != NULL)
609 padapter->dvobj_deinit(padapter);
610 if (pnetdev)
611 free_netdev(pnetdev);
612 return -ENODEV;
613}
614
615
616
617
618static void r871xu_dev_remove(struct usb_interface *pusb_intf)
619{
620 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
621 struct usb_device *udev = interface_to_usbdev(pusb_intf);
622
623 if (pnetdev) {
624 struct _adapter *padapter = netdev_priv(pnetdev);
625
626 usb_set_intfdata(pusb_intf, NULL);
627 release_firmware(padapter->fw);
628
629 wait_for_completion(&padapter->rtl8712_fw_ready);
630 if (drvpriv.drv_registered)
631 padapter->bSurpriseRemoved = true;
632 unregister_netdev(pnetdev);
633 flush_scheduled_work();
634 udelay(1);
635
636 r8712_stop_drv_timers(padapter);
637 r871x_dev_unload(padapter);
638 r8712_free_drv_sw(padapter);
639
640
641
642
643 usb_put_dev(udev);
644 }
645
646
647
648
649 if (udev->state != USB_STATE_NOTATTACHED)
650 usb_reset_device(udev);
651}
652
653static int __init r8712u_drv_entry(void)
654{
655 drvpriv.drv_registered = true;
656 return usb_register(&drvpriv.r871xu_drv);
657}
658
659static void __exit r8712u_drv_halt(void)
660{
661 drvpriv.drv_registered = false;
662 usb_deregister(&drvpriv.r871xu_drv);
663}
664
665module_init(r8712u_drv_entry);
666module_exit(r8712u_drv_halt);
667