forked from lwfinger/rtw89
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusb.c
705 lines (582 loc) · 16.7 KB
/
usb.c
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/* Copyright(c) 2018-2019 Realtek Corporation
*/
#include <linux/module.h>
#include <linux/usb.h>
#include <linux/mutex.h>
#include "debug.h"
#include "fw.h"
#include "usb.h"
#define RTW_USB_CONTROL_MSG_TIMEOUT 30000 /* (us) */
#define RTW_USB_MSG_TIMEOUT 30000 /* (ms) */
#define RTW_USB_MAX_RXQ_LEN 128
struct rtw89_usb_txcb_t {
struct rtw89_dev *rtwdev;
struct sk_buff_head tx_ack_queue;
};
struct rtw89_usb_ctrlcb_t {
atomic_t done;
__u8 req_type;
int status;
};
/*
* usb read/write register functions
*/
static void rtw_usb_ctrl_atomic_cb(struct urb *urb)
{
struct rtw89_usb_ctrlcb_t *ctx;
if (unlikely(!urb))
return;
ctx = (struct rtw89_usb_ctrlcb_t *)urb->context;
if (likely(ctx)) {
atomic_set(&ctx->done, 1);
ctx->status = urb->status;
}
/* free dr */
kfree(urb->setup_packet);
}
static int rtw_usb_ctrl_atomic(struct rtw89_dev *rtwdev,
struct usb_device *dev, unsigned int pipe,
__u8 req_type, __u16 value, __u16 index,
void *databuf, __u16 size)
{
struct usb_ctrlrequest *dr = NULL;
struct rtw89_usb_ctrlcb_t *ctx = NULL;
struct urb *urb = NULL;
bool done;
int ret = -ENOMEM;
ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC);
if (!ctx)
goto out;
dr = kmalloc(sizeof(*dr), GFP_ATOMIC);
if (!dr)
goto err_free_ctx;
dr->bRequestType = req_type;
dr->bRequest = RTW_USB_CMD_REQ;
dr->wValue = cpu_to_le16(value);
dr->wIndex = cpu_to_le16(index);
dr->wLength = cpu_to_le16(size);
urb = usb_alloc_urb(0, GFP_ATOMIC);
if (!urb)
goto err_free_dr;
atomic_set(&ctx->done, 0);
ctx->req_type = req_type;
usb_fill_control_urb(urb, dev, pipe, (unsigned char *)dr, databuf, size,
rtw_usb_ctrl_atomic_cb, ctx);
ret = usb_submit_urb(urb, GFP_ATOMIC);
if (unlikely(ret)) {
rtw89_err(rtwdev, "failed to submit urb, ret=%d\n", ret);
goto err_free_urb;
}
done = false;
read_poll_timeout_atomic(atomic_read, done, done, 100,
RTW_USB_CONTROL_MSG_TIMEOUT, false,
&ctx->done);
if (!done) {
usb_kill_urb(urb);
rtw89_err(rtwdev, "failed to wait usb ctrl req:%u\n", req_type);
ret = (ctx->status == -ENOENT ? -ETIMEDOUT : ctx->status);
} else {
ret = 0;
}
kfree(ctx);
usb_free_urb(urb);
return ret;
err_free_urb:
usb_free_urb(urb);
err_free_dr:
kfree(dr);
err_free_ctx:
kfree(ctx);
out:
return ret;
}
static u8 rtw_usb_read8_atomic(struct rtw89_dev *rtwdev, u32 addr)
{
struct rtw89_usb *rtwusb = (struct rtw89_usb *)rtwdev->priv;
struct usb_device *udev = rtwusb->udev;
u8 *buf = NULL, data;
buf = kmalloc(sizeof(*buf), GFP_ATOMIC);
if (!buf)
return 0;
rtw_usb_ctrl_atomic(rtwdev, udev, usb_rcvctrlpipe(udev, 0),
RTW_USB_CMD_READ, addr, 0, buf, sizeof(*buf));
data = *buf;
kfree(buf);
return data;
}
static u16 rtw_usb_read16_atomic(struct rtw89_dev *rtwdev, u32 addr)
{
struct rtw89_usb *rtwusb = (struct rtw89_usb *)rtwdev->priv;
struct usb_device *udev = rtwusb->udev;
__le16 *buf = NULL;
u16 data;
buf = kmalloc(sizeof(*buf), GFP_ATOMIC);
if (!buf)
return 0;
rtw_usb_ctrl_atomic(rtwdev, udev, usb_rcvctrlpipe(udev, 0),
RTW_USB_CMD_READ, addr, 0, buf, sizeof(*buf));
data = le16_to_cpu(*buf);
kfree(buf);
return data;
}
static u32 rtw_usb_read32_atomic(struct rtw89_dev *rtwdev, u32 addr)
{
struct rtw89_usb *rtwusb = (struct rtw89_usb *)rtwdev->priv;
struct usb_device *udev = rtwusb->udev;
__le32 *buf;
u32 data;
buf = kmalloc(sizeof(*buf), GFP_ATOMIC);
if (!buf)
return 0;
rtw_usb_ctrl_atomic(rtwdev, udev, usb_rcvctrlpipe(udev, 0),
RTW_USB_CMD_READ, addr, 0, buf, sizeof(*buf));
data = le32_to_cpu(*buf);
kfree(buf);
return data;
}
static void rtw_usb_write8_atomic(struct rtw89_dev *rtwdev, u32 addr, u8 val)
{
struct rtw89_usb *rtwusb = (struct rtw89_usb *)rtwdev->priv;
struct usb_device *udev = rtwusb->udev;
u8 *buf;
buf = kmalloc(sizeof(*buf), GFP_ATOMIC);
if (!buf)
return;
*buf = val;
rtw_usb_ctrl_atomic(rtwdev, udev, usb_sndctrlpipe(udev, 0),
RTW_USB_CMD_WRITE, addr, 0, buf, sizeof(*buf));
kfree(buf);
}
static void rtw_usb_write16_atomic(struct rtw89_dev *rtwdev, u32 addr, u16 val)
{
struct rtw89_usb *rtwusb = (struct rtw89_usb *)rtwdev->priv;
struct usb_device *udev = rtwusb->udev;
__le16 *buf;
buf = kmalloc(sizeof(*buf), GFP_ATOMIC);
if (!buf)
return;
*buf = cpu_to_le16(val);
rtw_usb_ctrl_atomic(rtwdev, udev, usb_sndctrlpipe(udev, 0),
RTW_USB_CMD_WRITE, addr, 0, buf, sizeof(*buf));
kfree(buf);
}
static void rtw_usb_write32_atomic(struct rtw89_dev *rtwdev, u32 addr, u32 val)
{
struct rtw89_usb *rtwusb = (struct rtw89_usb *)rtwdev->priv;
struct usb_device *udev = rtwusb->udev;
__le32 *buf;
buf = kmalloc(sizeof(*buf), GFP_ATOMIC);
if (!buf)
return;
*buf = cpu_to_le32(val);
rtw_usb_ctrl_atomic(rtwdev, udev, usb_sndctrlpipe(udev, 0),
RTW_USB_CMD_WRITE, addr, 0, buf, sizeof(*buf));
kfree(buf);
}
static int rtw_usb_parse(struct rtw89_dev *rtwdev,
struct usb_interface *interface)
{
struct rtw89_usb *rtwusb;
struct usb_interface_descriptor *interface_desc;
struct usb_host_interface *host_interface;
struct usb_endpoint_descriptor *endpoint;
struct device *dev;
struct usb_device *usbd;
int i, endpoints;
u8 dir, xtype, num;
int ret = 0;
rtwusb = rtw_get_usb_priv(rtwdev);
dev = &rtwusb->udev->dev;
usbd = interface_to_usbdev(interface);
host_interface = &interface->altsetting[0];
interface_desc = &host_interface->desc;
endpoints = interface_desc->bNumEndpoints;
rtwusb->pipe_in = 0;
rtwusb->num_in_pipes = 0;
rtwusb->num_out_pipes = 0;
for (i = 0; i < endpoints; i++) {
endpoint = &host_interface->endpoint[i].desc;
dir = endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
num = usb_endpoint_num(endpoint);
xtype = usb_endpoint_type(endpoint);
rtw89_info(rtwdev, "\nusb endpoint descriptor (%i):\n", i);
rtw89_info(rtwdev, "bLength=%x\n", endpoint->bLength);
rtw89_info(rtwdev, "bDescriptorType=%x\n",
endpoint->bDescriptorType);
rtw89_info(rtwdev, "bEndpointAddress=%x\n",
endpoint->bEndpointAddress);
rtw89_info(rtwdev, "wMaxPacketSize=%d\n",
le16_to_cpu(endpoint->wMaxPacketSize));
rtw89_info(rtwdev, "bInterval=%x\n", endpoint->bInterval);
if (usb_endpoint_dir_in(endpoint) &&
usb_endpoint_xfer_bulk(endpoint)) {
rtw89_info(rtwdev, "USB: dir in endpoint num %i\n", num);
if (rtwusb->pipe_in) {
rtw89_err(rtwdev,
"failed to get many IN pipes\n");
ret = -EINVAL;
goto exit;
}
rtwusb->pipe_in = num;
rtwusb->num_in_pipes++;
}
if (usb_endpoint_dir_in(endpoint) &&
usb_endpoint_xfer_int(endpoint)) {
rtw89_info(rtwdev, "USB: interrupt endpoint num %i\n",
num);
if (rtwusb->pipe_interrupt) {
rtw89_err(rtwdev,
"failed to get many INTERRUPT pipes\n");
ret = -EINVAL;
goto exit;
}
rtwusb->pipe_interrupt = num;
}
if (usb_endpoint_dir_out(endpoint) &&
usb_endpoint_xfer_bulk(endpoint)) {
rtw89_info(rtwdev, "USB: out endpoint num %i\n", num);
if (rtwusb->num_out_pipes >= 8) {
rtw89_err(rtwdev,
"failed to get many OUT pipes\n");
ret = -EINVAL;
goto exit;
}
/* for out enpoint, address == number */
rtwusb->out_ep[rtwusb->num_out_pipes] = num;
rtwusb->num_out_pipes++;
}
}
switch (usbd->speed) {
case USB_SPEED_LOW:
rtw89_info(rtwdev, "USB_SPEED_LOW\n");
rtwusb->usb_speed = RTW_USB_SPEED_1_1;
break;
case USB_SPEED_FULL:
rtw89_info(rtwdev, "USB_SPEED_FULL\n");
rtwusb->usb_speed = RTW_USB_SPEED_1_1;
break;
case USB_SPEED_HIGH:
rtw89_info(rtwdev, "USB_SPEED_HIGH\n");
rtwusb->usb_speed = RTW_USB_SPEED_2;
break;
case USB_SPEED_SUPER:
rtw89_info(rtwdev, "USB_SPEED_SUPER\n");
rtwusb->usb_speed = RTW_USB_SPEED_3;
break;
default:
rtw89_err(rtwdev, "failed to get USB speed\n");
break;
}
exit:
return ret;
}
/*
* driver status relative functions
*/
#if 0
static
bool rtw_usb_is_bus_ready(struct rtw89_dev *rtwdev)
{
struct rtw89_usb *rtwusb = rtw_get_usb_priv(rtwdev);
return (atomic_read(&rtwusb->is_bus_drv_ready) == true);
}
static
void rtw_usb_set_bus_ready(struct rtw89_dev *rtwdev, bool ready)
{
struct rtw89_usb *rtwusb = rtw_get_usb_priv(rtwdev);
atomic_set(&rtwusb->is_bus_drv_ready, ready);
}
#endif
static void rtw_usb_tx_queue_init(struct rtw89_usb *rtwusb)
{
int i;
for (i = 0; i < RTW89_BULKOUT_NUM; i++)
skb_queue_head_init(&rtwusb->tx_queue[i]);
}
static void rtw_usb_tx_queue_purge(struct rtw89_usb *rtwusb)
{
int i;
for (i = 0; i < RTW89_BULKOUT_NUM; i++)
skb_queue_purge(&rtwusb->tx_queue[i]);
}
static void rtw_usb_rx_queue_purge(struct rtw89_usb *rtwusb)
{
skb_queue_purge(&rtwusb->rx_queue);
}
static int rtw89_usb_ops_mac_pre_init(struct rtw89_dev *rtwdev)
{
pr_info("%s enter\n", __func__);
return 0;
}
static struct rtw89_hci_ops rtw89_usb_ops = {
.read8 = rtw_usb_read8_atomic,
.read16 = rtw_usb_read16_atomic,
.read32 = rtw_usb_read32_atomic,
.write8 = rtw_usb_write8_atomic,
.write16 = rtw_usb_write16_atomic,
.write32 = rtw_usb_write32_atomic,
.mac_pre_init = rtw89_usb_ops_mac_pre_init,
};
static void rtw_usb_rx_handler(struct work_struct *work)
{
struct rtw89_usb_work_data *work_data = container_of(work,
struct rtw89_usb_work_data,
work);
struct rtw89_dev *rtwdev = work_data->rtwdev;
struct rtw89_usb *rtwusb = rtw_get_usb_priv(rtwdev);
//struct rtw_rx_pkt_stat pkt_stat;
struct sk_buff *skb;
//u32 pkt_desc_sz = chip->rx_pkt_desc_sz;
#if 0 //NEO : mark off first
const struct rtw89_chip_info *chip = rtwdev->chip;
struct ieee80211_rx_status rx_status;
u32 pkt_offset;
u8 *rx_desc;
#endif //NEO
while ((skb = skb_dequeue(&rtwusb->rx_queue)) != NULL) {
pr_info("%s skb=%p\n", __func__, skb);
#if 0 //NEO : mark off first
rx_desc = skb->data;
chip->ops->query_rx_desc(rtwdev, rx_desc, &pkt_stat,
&rx_status);
pkt_offset = pkt_desc_sz + pkt_stat.drv_info_sz +
pkt_stat.shift;
if (pkt_stat.is_c2h) {
skb_put(skb, pkt_stat.pkt_len + pkt_offset);
*((u32 *)skb->cb) = pkt_offset;
rtw_fw_c2h_cmd_handle(rtwdev, skb);
dev_kfree_skb(skb);
continue;
}
if (skb_queue_len(&rtwusb->rx_queue) >= RTW_USB_MAX_RXQ_LEN) {
rtw_err(rtwdev, "failed to get rx_queue, overflow\n");
dev_kfree_skb(skb);
continue;
}
skb_put(skb, pkt_stat.pkt_len);
skb_reserve(skb, pkt_offset);
memcpy(skb->cb, &rx_status, sizeof(rx_status));
ieee80211_rx_irqsafe(rtwdev->hw, skb);
#endif //NEO
}
}
static void rtw_usb_tx_handler(struct work_struct *work)
{
struct rtw89_usb_work_data *work_data = container_of(work,
struct rtw89_usb_work_data,
work);
struct rtw89_dev *rtwdev = work_data->rtwdev;
struct rtw89_usb *rtwusb = rtw_get_usb_priv(rtwdev);
struct sk_buff *skb;
bool is_empty = true;
int index;
/* should use bucket share algorithm for each queue */
index = RTW89_DMA_CH_NUM - 1;
while (index >= 0) {
skb = skb_dequeue(&rtwusb->tx_queue[index]);
if (skb) {
pr_info("%s skb:%p\n", __func__, skb);
//rtw_usb_tx_agg(rtwusb, skb);
is_empty = false;
} else {
index--;
}
if (index < 0 && !is_empty) {
index = RTW89_DMA_CH_NUM - 1;
is_empty = true;
}
}
}
static int rtw_usb_init_rx(struct rtw89_dev *rtwdev)
{
struct rtw89_usb *rtwusb = rtw_get_usb_priv(rtwdev);
rtwusb->rxwq = create_singlethread_workqueue("rtw89_usb: rx wq");
if (!rtwusb->rxwq) {
rtw89_err(rtwdev, "failed to create RX work queue\n");
return -ENOMEM;
}
skb_queue_head_init(&rtwusb->rx_queue);
rtwusb->rx_handler_data = kmalloc(sizeof(*rtwusb->rx_handler_data),
GFP_KERNEL);
if (!rtwusb->rx_handler_data)
goto err_destroy_wq;
rtwusb->rx_handler_data->rtwdev = rtwdev;
INIT_WORK(&rtwusb->rx_handler_data->work, rtw_usb_rx_handler);
return 0;
err_destroy_wq:
destroy_workqueue(rtwusb->rxwq);
return -ENOMEM;
}
static void rtw_usb_deinit_rx(struct rtw89_dev *rtwdev)
{
struct rtw89_usb *rtwusb = rtw_get_usb_priv(rtwdev);
rtw_usb_rx_queue_purge(rtwusb);
flush_workqueue(rtwusb->rxwq);
destroy_workqueue(rtwusb->rxwq);
kfree(rtwusb->rx_handler_data);
}
static int rtw_usb_init_tx(struct rtw89_dev *rtwdev)
{
struct rtw89_usb *rtwusb = rtw_get_usb_priv(rtwdev);
rtwusb->txwq = create_singlethread_workqueue("rtw89_usb: tx wq");
if (!rtwusb->txwq) {
rtw89_err(rtwdev, "failed to create TX work queue\n");
return -ENOMEM;
}
rtw_usb_tx_queue_init(rtwusb);
rtwusb->tx_handler_data = kmalloc(sizeof(*rtwusb->tx_handler_data),
GFP_KERNEL);
if (!rtwusb->tx_handler_data)
goto err_destroy_wq;
rtwusb->tx_handler_data->rtwdev = rtwdev;
INIT_WORK(&rtwusb->tx_handler_data->work, rtw_usb_tx_handler);
return 0;
err_destroy_wq:
destroy_workqueue(rtwusb->txwq);
return -ENOMEM;
}
static void rtw_usb_deinit_tx(struct rtw89_dev *rtwdev)
{
struct rtw89_usb *rtwusb = rtw_get_usb_priv(rtwdev);
rtw_usb_tx_queue_purge(rtwusb);
flush_workqueue(rtwusb->txwq);
destroy_workqueue(rtwusb->txwq);
kfree(rtwusb->tx_handler_data);
}
static void rtw_usb_interface_configure(struct rtw89_dev *rtwdev)
{
struct rtw89_usb *rtwusb = rtw_get_usb_priv(rtwdev);
if (RTW_USB_IS_SUPER_SPEED(rtwusb))
rtwusb->bulkout_size = RTW_USB_SUPER_SPEED_BULK_SIZE;
else if (RTW_USB_IS_HIGH_SPEED(rtwusb))
rtwusb->bulkout_size = RTW_USB_HIGH_SPEED_BULK_SIZE;
else
rtwusb->bulkout_size = RTW_USB_FULL_SPEED_BULK_SIZE;
rtw89_info(rtwdev, "USB: bulkout_size: %d\n", rtwusb->bulkout_size);
}
static int rtw_usb_intf_init(struct rtw89_dev *rtwdev,
struct usb_interface *intf)
{
struct rtw89_usb *rtwusb = rtw_get_usb_priv(rtwdev);
struct usb_device *udev = usb_get_dev(interface_to_usbdev(intf));
int ret;
rtwusb->udev = udev;
rtwusb->rtwdev = rtwdev;
ret = rtw_usb_parse(rtwdev, intf);
if (ret) {
rtw89_err(rtwdev, "failed to check USB configuration, ret=%d\n",
ret);
return ret;
}
usb_set_intfdata(intf, rtwdev->hw);
rtw_usb_interface_configure(rtwdev);
SET_IEEE80211_DEV(rtwdev->hw, &intf->dev);
return 0;
}
static void rtw_usb_intf_deinit(struct rtw89_dev *rtwdev,
struct usb_interface *intf)
{
struct rtw89_usb *rtwusb = rtw_get_usb_priv(rtwdev);
usb_put_dev(rtwusb->udev);
usb_set_intfdata(intf, NULL);
}
static int rtw_usb_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct ieee80211_hw *hw;
struct rtw89_dev *rtwdev;
int drv_data_size;
int ret;
drv_data_size = sizeof(struct rtw89_dev) + sizeof(struct rtw89_usb);
hw = ieee80211_alloc_hw(drv_data_size, &rtw89_ops);
if (!hw) {
dev_err(&intf->dev, "failed to allocate hw\n");
return -ENOMEM;
}
rtwdev = hw->priv;
rtwdev->hw = hw;
rtwdev->dev = &intf->dev;
rtwdev->chip = (const struct rtw89_chip_info *)id->driver_info;
rtwdev->hci.ops = &rtw89_usb_ops;
rtwdev->hci.type = RTW89_HCI_TYPE_USB;
rtwdev->fw_name = "rtw89/rtl8852a_u3_nic.bin",
ret = rtw89_core_init(rtwdev);
if (ret) {
rtw89_err(rtwdev, "failed to initialise core\n");
goto err_release_hw;
}
ret = rtw_usb_intf_init(rtwdev, intf);
if (ret) {
rtw89_err(rtwdev, "failed to init USB interface\n");
goto err_deinit_core;
}
ret = rtw_usb_init_tx(rtwdev);
if (ret) {
rtw89_err(rtwdev, "failed to init USB TX\n");
goto err_destroy_usb;
}
ret = rtw_usb_init_rx(rtwdev);
if (ret) {
rtw89_err(rtwdev, "failed to init USB RX\n");
goto err_destroy_txwq;
}
ret = rtw89_chip_info_setup(rtwdev);
if (ret) {
rtw89_err(rtwdev, "failed to setup chip information\n");
goto err_destroy_rxwq;
}
return 0;
err_destroy_rxwq:
rtw_usb_deinit_rx(rtwdev);
err_destroy_txwq:
rtw_usb_deinit_tx(rtwdev);
err_destroy_usb:
rtw_usb_intf_deinit(rtwdev, intf);
err_deinit_core:
rtw89_core_deinit(rtwdev);
err_release_hw:
ieee80211_free_hw(hw);
return ret;
}
static void rtw_usb_disconnect(struct usb_interface *intf)
{
struct ieee80211_hw *hw = usb_get_intfdata(intf);
struct rtw89_dev *rtwdev;
struct rtw89_usb *rtwusb;
if (!hw)
return;
rtwdev = hw->priv;
rtwusb = rtw_get_usb_priv(rtwdev);
rtw_usb_deinit_rx(rtwdev);
rtw_usb_deinit_tx(rtwdev);
if (rtwusb->udev->state != USB_STATE_NOTATTACHED)
usb_reset_device(rtwusb->udev);
rtw_usb_intf_deinit(rtwdev, intf);
rtw89_core_deinit(rtwdev);
ieee80211_free_hw(hw);
}
static const struct usb_device_id rtw_usb_id_table[] = {
{RTK_USB_DEVICE(VENDOR_ID_REALTEK, /* Realtek generic, e.g. Comfast CF-957AX */
0x8832, rtw8852a_chip_info)},
{RTK_USB_DEVICE(VENDOR_ID_REALTEK,
0x885a, rtw8852a_chip_info)},
{RTK_USB_DEVICE(VENDOR_ID_REALTEK, /* Realtek generic, e.g. Fenvi FU-AX1800P */
0x885c, rtw8852a_chip_info)},
{RTK_USB_DEVICE(VENDOR_ID_ASUS, /* ASUS USB-AX56 */
0x1997, rtw8852a_chip_info)},
{RTK_USB_DEVICE(VENDOR_ID_DLINK, /* D-Link DWA-X1850 */
0x3321, rtw8852a_chip_info)},
{},
};
MODULE_DEVICE_TABLE(usb, rtw_usb_id_table);
static struct usb_driver rtw_usb_driver = {
.name = "rtwifi_usb",
.id_table = rtw_usb_id_table,
.probe = rtw_usb_probe,
.disconnect = rtw_usb_disconnect,
};
module_usb_driver(rtw_usb_driver);
MODULE_AUTHOR("Realtek Corporation");
MODULE_DESCRIPTION("Realtek 802.11ax wireless USB driver");
MODULE_LICENSE("Dual BSD/GPL");