This source file includes following definitions.
- rsi_usb_card_write
- rsi_write_multiple
- rsi_find_bulk_in_and_out_endpoints
- rsi_usb_reg_read
- rsi_usb_reg_write
- rsi_rx_done_handler
- rsi_rx_urb_kill
- rsi_rx_urb_submit
- rsi_usb_read_register_multiple
- rsi_usb_write_register_multiple
- rsi_usb_host_intf_write_pkt
- rsi_usb_master_reg_read
- rsi_usb_master_reg_write
- rsi_usb_load_data_master_write
- rsi_deinit_usb_interface
- rsi_usb_init_rx
- rsi_init_usb_interface
- usb_ulp_read_write
- rsi_reset_card
- rsi_probe
- rsi_disconnect
- rsi_suspend
- rsi_resume
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <net/rsi_91x.h>
21 #include "rsi_usb.h"
22 #include "rsi_hal.h"
23 #include "rsi_coex.h"
24
25
26 static u16 dev_oper_mode = DEV_OPMODE_STA_BT_DUAL;
27 module_param(dev_oper_mode, ushort, 0444);
28 MODULE_PARM_DESC(dev_oper_mode,
29 "1[Wi-Fi], 4[BT], 8[BT LE], 5[Wi-Fi STA + BT classic]\n"
30 "9[Wi-Fi STA + BT LE], 13[Wi-Fi STA + BT classic + BT LE]\n"
31 "6[AP + BT classic], 14[AP + BT classic + BT LE]");
32
33 static int rsi_rx_urb_submit(struct rsi_hw *adapter, u8 ep_num, gfp_t flags);
34
35
36
37
38
39
40
41
42
43
44 static int rsi_usb_card_write(struct rsi_hw *adapter,
45 u8 *buf,
46 u16 len,
47 u8 endpoint)
48 {
49 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
50 int status;
51 u8 *seg = dev->tx_buffer;
52 int transfer;
53 int ep = dev->bulkout_endpoint_addr[endpoint - 1];
54
55 memset(seg, 0, len + RSI_USB_TX_HEAD_ROOM);
56 memcpy(seg + RSI_USB_TX_HEAD_ROOM, buf, len);
57 len += RSI_USB_TX_HEAD_ROOM;
58 transfer = len;
59 status = usb_bulk_msg(dev->usbdev,
60 usb_sndbulkpipe(dev->usbdev, ep),
61 (void *)seg,
62 (int)len,
63 &transfer,
64 HZ * 5);
65
66 if (status < 0) {
67 rsi_dbg(ERR_ZONE,
68 "Card write failed with error code :%10d\n", status);
69 dev->write_fail = 1;
70 }
71 return status;
72 }
73
74
75
76
77
78
79
80
81
82
83
84 static int rsi_write_multiple(struct rsi_hw *adapter,
85 u8 endpoint,
86 u8 *data,
87 u32 count)
88 {
89 struct rsi_91x_usbdev *dev;
90
91 if (!adapter)
92 return -ENODEV;
93
94 if (endpoint == 0)
95 return -EINVAL;
96
97 dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
98 if (dev->write_fail)
99 return -ENETDOWN;
100
101 return rsi_usb_card_write(adapter, data, count, endpoint);
102 }
103
104
105
106
107
108
109
110
111
112 static int rsi_find_bulk_in_and_out_endpoints(struct usb_interface *interface,
113 struct rsi_hw *adapter)
114 {
115 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
116 struct usb_host_interface *iface_desc;
117 struct usb_endpoint_descriptor *endpoint;
118 __le16 buffer_size;
119 int ii, bin_found = 0, bout_found = 0;
120
121 iface_desc = interface->cur_altsetting;
122
123 for (ii = 0; ii < iface_desc->desc.bNumEndpoints; ++ii) {
124 endpoint = &(iface_desc->endpoint[ii].desc);
125
126 if (!dev->bulkin_endpoint_addr[bin_found] &&
127 (endpoint->bEndpointAddress & USB_DIR_IN) &&
128 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
129 USB_ENDPOINT_XFER_BULK)) {
130 buffer_size = endpoint->wMaxPacketSize;
131 dev->bulkin_size[bin_found] = buffer_size;
132 dev->bulkin_endpoint_addr[bin_found] =
133 endpoint->bEndpointAddress;
134 bin_found++;
135 }
136
137 if (!dev->bulkout_endpoint_addr[bout_found] &&
138 !(endpoint->bEndpointAddress & USB_DIR_IN) &&
139 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
140 USB_ENDPOINT_XFER_BULK)) {
141 buffer_size = endpoint->wMaxPacketSize;
142 dev->bulkout_endpoint_addr[bout_found] =
143 endpoint->bEndpointAddress;
144 dev->bulkout_size[bout_found] = buffer_size;
145 bout_found++;
146 }
147
148 if (bin_found >= MAX_BULK_EP || bout_found >= MAX_BULK_EP)
149 break;
150 }
151
152 if (!(dev->bulkin_endpoint_addr[0]) &&
153 dev->bulkout_endpoint_addr[0])
154 return -EINVAL;
155
156 return 0;
157 }
158
159 #define RSI_USB_REQ_OUT (USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE)
160 #define RSI_USB_REQ_IN (USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE)
161
162
163
164
165
166
167
168
169
170 static int rsi_usb_reg_read(struct usb_device *usbdev,
171 u32 reg,
172 u16 *value,
173 u16 len)
174 {
175 u8 *buf;
176 int status = -ENOMEM;
177
178 if (len > RSI_USB_CTRL_BUF_SIZE)
179 return -EINVAL;
180
181 buf = kmalloc(RSI_USB_CTRL_BUF_SIZE, GFP_KERNEL);
182 if (!buf)
183 return status;
184
185 status = usb_control_msg(usbdev,
186 usb_rcvctrlpipe(usbdev, 0),
187 USB_VENDOR_REGISTER_READ,
188 RSI_USB_REQ_IN,
189 ((reg & 0xffff0000) >> 16), (reg & 0xffff),
190 (void *)buf,
191 len,
192 USB_CTRL_GET_TIMEOUT);
193
194 *value = (buf[0] | (buf[1] << 8));
195 if (status < 0) {
196 rsi_dbg(ERR_ZONE,
197 "%s: Reg read failed with error code :%d\n",
198 __func__, status);
199 }
200 kfree(buf);
201
202 return status;
203 }
204
205
206
207
208
209
210
211
212
213
214
215 static int rsi_usb_reg_write(struct usb_device *usbdev,
216 u32 reg,
217 u32 value,
218 u16 len)
219 {
220 u8 *usb_reg_buf;
221 int status = -ENOMEM;
222
223 if (len > RSI_USB_CTRL_BUF_SIZE)
224 return -EINVAL;
225
226 usb_reg_buf = kmalloc(RSI_USB_CTRL_BUF_SIZE, GFP_KERNEL);
227 if (!usb_reg_buf)
228 return status;
229
230 usb_reg_buf[0] = (cpu_to_le32(value) & 0x00ff);
231 usb_reg_buf[1] = (cpu_to_le32(value) & 0xff00) >> 8;
232 usb_reg_buf[2] = (cpu_to_le32(value) & 0x00ff0000) >> 16;
233 usb_reg_buf[3] = (cpu_to_le32(value) & 0xff000000) >> 24;
234
235 status = usb_control_msg(usbdev,
236 usb_sndctrlpipe(usbdev, 0),
237 USB_VENDOR_REGISTER_WRITE,
238 RSI_USB_REQ_OUT,
239 ((cpu_to_le32(reg) & 0xffff0000) >> 16),
240 (cpu_to_le32(reg) & 0xffff),
241 (void *)usb_reg_buf,
242 len,
243 USB_CTRL_SET_TIMEOUT);
244 if (status < 0) {
245 rsi_dbg(ERR_ZONE,
246 "%s: Reg write failed with error code :%d\n",
247 __func__, status);
248 }
249 kfree(usb_reg_buf);
250
251 return status;
252 }
253
254
255
256
257
258
259
260
261 static void rsi_rx_done_handler(struct urb *urb)
262 {
263 struct rx_usb_ctrl_block *rx_cb = urb->context;
264 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)rx_cb->data;
265 int status = -EINVAL;
266
267 if (urb->status) {
268 dev_kfree_skb(rx_cb->rx_skb);
269 return;
270 }
271
272 if (urb->actual_length <= 0 ||
273 urb->actual_length > rx_cb->rx_skb->len) {
274 rsi_dbg(INFO_ZONE, "%s: Invalid packet length = %d\n",
275 __func__, urb->actual_length);
276 goto out;
277 }
278 if (skb_queue_len(&dev->rx_q) >= RSI_MAX_RX_PKTS) {
279 rsi_dbg(INFO_ZONE, "Max RX packets reached\n");
280 goto out;
281 }
282 skb_trim(rx_cb->rx_skb, urb->actual_length);
283 skb_queue_tail(&dev->rx_q, rx_cb->rx_skb);
284
285 rsi_set_event(&dev->rx_thread.event);
286 status = 0;
287
288 out:
289 if (rsi_rx_urb_submit(dev->priv, rx_cb->ep_num, GFP_ATOMIC))
290 rsi_dbg(ERR_ZONE, "%s: Failed in urb submission", __func__);
291
292 if (status)
293 dev_kfree_skb(rx_cb->rx_skb);
294 }
295
296 static void rsi_rx_urb_kill(struct rsi_hw *adapter, u8 ep_num)
297 {
298 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
299 struct rx_usb_ctrl_block *rx_cb = &dev->rx_cb[ep_num - 1];
300 struct urb *urb = rx_cb->rx_urb;
301
302 usb_kill_urb(urb);
303 }
304
305
306
307
308
309
310
311 static int rsi_rx_urb_submit(struct rsi_hw *adapter, u8 ep_num, gfp_t mem_flags)
312 {
313 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
314 struct rx_usb_ctrl_block *rx_cb = &dev->rx_cb[ep_num - 1];
315 struct urb *urb = rx_cb->rx_urb;
316 int status;
317 struct sk_buff *skb;
318 u8 dword_align_bytes = 0;
319
320 #define RSI_MAX_RX_USB_PKT_SIZE 3000
321 skb = dev_alloc_skb(RSI_MAX_RX_USB_PKT_SIZE);
322 if (!skb)
323 return -ENOMEM;
324 skb_reserve(skb, MAX_DWORD_ALIGN_BYTES);
325 skb_put(skb, RSI_MAX_RX_USB_PKT_SIZE - MAX_DWORD_ALIGN_BYTES);
326 dword_align_bytes = (unsigned long)skb->data & 0x3f;
327 if (dword_align_bytes > 0)
328 skb_push(skb, dword_align_bytes);
329 urb->transfer_buffer = skb->data;
330 rx_cb->rx_skb = skb;
331
332 usb_fill_bulk_urb(urb,
333 dev->usbdev,
334 usb_rcvbulkpipe(dev->usbdev,
335 dev->bulkin_endpoint_addr[ep_num - 1]),
336 urb->transfer_buffer,
337 skb->len,
338 rsi_rx_done_handler,
339 rx_cb);
340
341 status = usb_submit_urb(urb, mem_flags);
342 if (status) {
343 rsi_dbg(ERR_ZONE, "%s: Failed in urb submission\n", __func__);
344 dev_kfree_skb(skb);
345 }
346
347 return status;
348 }
349
350 static int rsi_usb_read_register_multiple(struct rsi_hw *adapter, u32 addr,
351 u8 *data, u16 count)
352 {
353 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
354 u8 *buf;
355 u16 transfer;
356 int status;
357
358 if (!addr)
359 return -EINVAL;
360
361 buf = kzalloc(RSI_USB_BUF_SIZE, GFP_KERNEL);
362 if (!buf)
363 return -ENOMEM;
364
365 while (count) {
366 transfer = min_t(u16, count, RSI_USB_BUF_SIZE);
367 status = usb_control_msg(dev->usbdev,
368 usb_rcvctrlpipe(dev->usbdev, 0),
369 USB_VENDOR_REGISTER_READ,
370 RSI_USB_REQ_IN,
371 ((addr & 0xffff0000) >> 16),
372 (addr & 0xffff), (void *)buf,
373 transfer, USB_CTRL_GET_TIMEOUT);
374 if (status < 0) {
375 rsi_dbg(ERR_ZONE,
376 "Reg read failed with error code :%d\n",
377 status);
378 kfree(buf);
379 return status;
380 }
381 memcpy(data, buf, transfer);
382 count -= transfer;
383 data += transfer;
384 addr += transfer;
385 }
386 kfree(buf);
387 return 0;
388 }
389
390
391
392
393
394
395
396
397
398
399
400 static int rsi_usb_write_register_multiple(struct rsi_hw *adapter, u32 addr,
401 u8 *data, u16 count)
402 {
403 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
404 u8 *buf;
405 u16 transfer;
406 int status = 0;
407
408 buf = kzalloc(RSI_USB_BUF_SIZE, GFP_KERNEL);
409 if (!buf)
410 return -ENOMEM;
411
412 while (count) {
413 transfer = min_t(u16, count, RSI_USB_BUF_SIZE);
414 memcpy(buf, data, transfer);
415 status = usb_control_msg(dev->usbdev,
416 usb_sndctrlpipe(dev->usbdev, 0),
417 USB_VENDOR_REGISTER_WRITE,
418 RSI_USB_REQ_OUT,
419 ((addr & 0xffff0000) >> 16),
420 (addr & 0xffff),
421 (void *)buf,
422 transfer,
423 USB_CTRL_SET_TIMEOUT);
424 if (status < 0) {
425 rsi_dbg(ERR_ZONE,
426 "Reg write failed with error code :%d\n",
427 status);
428 kfree(buf);
429 return status;
430 }
431 count -= transfer;
432 data += transfer;
433 addr += transfer;
434 }
435
436 kfree(buf);
437 return 0;
438 }
439
440
441
442
443
444
445
446
447
448
449 static int rsi_usb_host_intf_write_pkt(struct rsi_hw *adapter,
450 u8 *pkt,
451 u32 len)
452 {
453 u32 queueno = ((pkt[1] >> 4) & 0x7);
454 u8 endpoint;
455
456 endpoint = ((queueno == RSI_WIFI_MGMT_Q || queueno == RSI_WIFI_DATA_Q ||
457 queueno == RSI_COEX_Q) ? WLAN_EP : BT_EP);
458
459 return rsi_write_multiple(adapter,
460 endpoint,
461 (u8 *)pkt,
462 len);
463 }
464
465 static int rsi_usb_master_reg_read(struct rsi_hw *adapter, u32 reg,
466 u32 *value, u16 len)
467 {
468 struct usb_device *usbdev =
469 ((struct rsi_91x_usbdev *)adapter->rsi_dev)->usbdev;
470 u16 temp;
471 int ret;
472
473 ret = rsi_usb_reg_read(usbdev, reg, &temp, len);
474 if (ret < 0)
475 return ret;
476 *value = temp;
477
478 return 0;
479 }
480
481 static int rsi_usb_master_reg_write(struct rsi_hw *adapter,
482 unsigned long reg,
483 unsigned long value, u16 len)
484 {
485 struct usb_device *usbdev =
486 ((struct rsi_91x_usbdev *)adapter->rsi_dev)->usbdev;
487
488 return rsi_usb_reg_write(usbdev, reg, value, len);
489 }
490
491 static int rsi_usb_load_data_master_write(struct rsi_hw *adapter,
492 u32 base_address,
493 u32 instructions_sz, u16 block_size,
494 u8 *ta_firmware)
495 {
496 u16 num_blocks;
497 u32 cur_indx, i;
498 u8 temp_buf[256];
499 int status;
500
501 num_blocks = instructions_sz / block_size;
502 rsi_dbg(INFO_ZONE, "num_blocks: %d\n", num_blocks);
503
504 for (cur_indx = 0, i = 0; i < num_blocks; i++, cur_indx += block_size) {
505 memcpy(temp_buf, ta_firmware + cur_indx, block_size);
506 status = rsi_usb_write_register_multiple(adapter, base_address,
507 (u8 *)(temp_buf),
508 block_size);
509 if (status < 0)
510 return status;
511
512 rsi_dbg(INFO_ZONE, "%s: loading block: %d\n", __func__, i);
513 base_address += block_size;
514 }
515
516 if (instructions_sz % block_size) {
517 memset(temp_buf, 0, block_size);
518 memcpy(temp_buf, ta_firmware + cur_indx,
519 instructions_sz % block_size);
520 status = rsi_usb_write_register_multiple
521 (adapter, base_address,
522 (u8 *)temp_buf,
523 instructions_sz % block_size);
524 if (status < 0)
525 return status;
526 rsi_dbg(INFO_ZONE,
527 "Written Last Block in Address 0x%x Successfully\n",
528 cur_indx);
529 }
530 return 0;
531 }
532
533 static struct rsi_host_intf_ops usb_host_intf_ops = {
534 .write_pkt = rsi_usb_host_intf_write_pkt,
535 .read_reg_multiple = rsi_usb_read_register_multiple,
536 .write_reg_multiple = rsi_usb_write_register_multiple,
537 .master_reg_read = rsi_usb_master_reg_read,
538 .master_reg_write = rsi_usb_master_reg_write,
539 .load_data_master_write = rsi_usb_load_data_master_write,
540 };
541
542
543
544
545
546
547
548 static void rsi_deinit_usb_interface(struct rsi_hw *adapter)
549 {
550 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
551
552 rsi_kill_thread(&dev->rx_thread);
553
554 usb_free_urb(dev->rx_cb[0].rx_urb);
555 if (adapter->priv->coex_mode > 1)
556 usb_free_urb(dev->rx_cb[1].rx_urb);
557
558 kfree(dev->tx_buffer);
559 }
560
561 static int rsi_usb_init_rx(struct rsi_hw *adapter)
562 {
563 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
564 struct rx_usb_ctrl_block *rx_cb;
565 u8 idx, num_rx_cb;
566
567 num_rx_cb = (adapter->priv->coex_mode > 1 ? 2 : 1);
568
569 for (idx = 0; idx < num_rx_cb; idx++) {
570 rx_cb = &dev->rx_cb[idx];
571
572 rx_cb->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
573 if (!rx_cb->rx_urb) {
574 rsi_dbg(ERR_ZONE, "Failed alloc rx urb[%d]\n", idx);
575 goto err;
576 }
577 rx_cb->ep_num = idx + 1;
578 rx_cb->data = (void *)dev;
579 }
580 skb_queue_head_init(&dev->rx_q);
581 rsi_init_event(&dev->rx_thread.event);
582 if (rsi_create_kthread(adapter->priv, &dev->rx_thread,
583 rsi_usb_rx_thread, "RX-Thread")) {
584 rsi_dbg(ERR_ZONE, "%s: Unable to init rx thrd\n", __func__);
585 goto err;
586 }
587
588 return 0;
589
590 err:
591 usb_free_urb(dev->rx_cb[0].rx_urb);
592 if (adapter->priv->coex_mode > 1)
593 usb_free_urb(dev->rx_cb[1].rx_urb);
594
595 return -1;
596 }
597
598
599
600
601
602
603
604
605 static int rsi_init_usb_interface(struct rsi_hw *adapter,
606 struct usb_interface *pfunction)
607 {
608 struct rsi_91x_usbdev *rsi_dev;
609 int status;
610
611 rsi_dev = kzalloc(sizeof(*rsi_dev), GFP_KERNEL);
612 if (!rsi_dev)
613 return -ENOMEM;
614
615 adapter->rsi_dev = rsi_dev;
616 rsi_dev->usbdev = interface_to_usbdev(pfunction);
617 rsi_dev->priv = (void *)adapter;
618
619 if (rsi_find_bulk_in_and_out_endpoints(pfunction, adapter)) {
620 status = -EINVAL;
621 goto fail_eps;
622 }
623
624 adapter->device = &pfunction->dev;
625 usb_set_intfdata(pfunction, adapter);
626
627 rsi_dev->tx_buffer = kmalloc(2048, GFP_KERNEL);
628 if (!rsi_dev->tx_buffer) {
629 status = -ENOMEM;
630 goto fail_eps;
631 }
632
633 if (rsi_usb_init_rx(adapter)) {
634 rsi_dbg(ERR_ZONE, "Failed to init RX handle\n");
635 status = -ENOMEM;
636 goto fail_rx;
637 }
638
639 rsi_dev->tx_blk_size = 252;
640 adapter->block_size = rsi_dev->tx_blk_size;
641
642
643 adapter->check_hw_queue_status = rsi_usb_check_queue_status;
644 adapter->determine_event_timeout = rsi_usb_event_timeout;
645 adapter->rsi_host_intf = RSI_HOST_INTF_USB;
646 adapter->host_intf_ops = &usb_host_intf_ops;
647
648 #ifdef CONFIG_RSI_DEBUGFS
649
650 adapter->num_debugfs_entries = (MAX_DEBUGFS_ENTRIES - 1);
651 #endif
652
653 rsi_dbg(INIT_ZONE, "%s: Enabled the interface\n", __func__);
654 return 0;
655
656 fail_rx:
657 kfree(rsi_dev->tx_buffer);
658
659 fail_eps:
660
661 return status;
662 }
663
664 static int usb_ulp_read_write(struct rsi_hw *adapter, u16 addr, u32 data,
665 u16 len_in_bits)
666 {
667 int ret;
668
669 ret = rsi_usb_master_reg_write
670 (adapter, RSI_GSPI_DATA_REG1,
671 ((addr << 6) | ((data >> 16) & 0xffff)), 2);
672 if (ret < 0)
673 return ret;
674
675 ret = rsi_usb_master_reg_write(adapter, RSI_GSPI_DATA_REG0,
676 (data & 0xffff), 2);
677 if (ret < 0)
678 return ret;
679
680
681 rsi_usb_master_reg_write(adapter, RSI_GSPI_CTRL_REG0,
682 RSI_GSPI_CTRL_REG0_VALUE, 2);
683
684 ret = rsi_usb_master_reg_write(adapter, RSI_GSPI_CTRL_REG1,
685 ((len_in_bits - 1) | RSI_GSPI_TRIG), 2);
686 if (ret < 0)
687 return ret;
688
689 msleep(20);
690
691 return 0;
692 }
693
694 static int rsi_reset_card(struct rsi_hw *adapter)
695 {
696 int ret;
697
698 rsi_dbg(INFO_ZONE, "Resetting Card...\n");
699 rsi_usb_master_reg_write(adapter, RSI_TA_HOLD_REG, 0xE, 4);
700
701
702
703
704 msleep(100);
705
706 ret = rsi_usb_master_reg_write(adapter, SWBL_REGOUT,
707 RSI_FW_WDT_DISABLE_REQ,
708 RSI_COMMON_REG_SIZE);
709 if (ret < 0) {
710 rsi_dbg(ERR_ZONE, "Disabling firmware watchdog timer failed\n");
711 goto fail;
712 }
713
714 if (adapter->device_model != RSI_DEV_9116) {
715 ret = usb_ulp_read_write(adapter, RSI_WATCH_DOG_TIMER_1,
716 RSI_ULP_WRITE_2, 32);
717 if (ret < 0)
718 goto fail;
719 ret = usb_ulp_read_write(adapter, RSI_WATCH_DOG_TIMER_2,
720 RSI_ULP_WRITE_0, 32);
721 if (ret < 0)
722 goto fail;
723 ret = usb_ulp_read_write(adapter, RSI_WATCH_DOG_DELAY_TIMER_1,
724 RSI_ULP_WRITE_50, 32);
725 if (ret < 0)
726 goto fail;
727 ret = usb_ulp_read_write(adapter, RSI_WATCH_DOG_DELAY_TIMER_2,
728 RSI_ULP_WRITE_0, 32);
729 if (ret < 0)
730 goto fail;
731 ret = usb_ulp_read_write(adapter, RSI_WATCH_DOG_TIMER_ENABLE,
732 RSI_ULP_TIMER_ENABLE, 32);
733 if (ret < 0)
734 goto fail;
735 } else {
736 if ((rsi_usb_master_reg_write(adapter,
737 NWP_WWD_INTERRUPT_TIMER,
738 NWP_WWD_INT_TIMER_CLKS,
739 RSI_9116_REG_SIZE)) < 0) {
740 goto fail;
741 }
742 if ((rsi_usb_master_reg_write(adapter,
743 NWP_WWD_SYSTEM_RESET_TIMER,
744 NWP_WWD_SYS_RESET_TIMER_CLKS,
745 RSI_9116_REG_SIZE)) < 0) {
746 goto fail;
747 }
748 if ((rsi_usb_master_reg_write(adapter,
749 NWP_WWD_MODE_AND_RSTART,
750 NWP_WWD_TIMER_DISABLE,
751 RSI_9116_REG_SIZE)) < 0) {
752 goto fail;
753 }
754 }
755
756 rsi_dbg(INFO_ZONE, "Reset card done\n");
757 return ret;
758
759 fail:
760 rsi_dbg(ERR_ZONE, "Reset card failed\n");
761 return ret;
762 }
763
764
765
766
767
768
769
770
771
772
773 static int rsi_probe(struct usb_interface *pfunction,
774 const struct usb_device_id *id)
775 {
776 struct rsi_hw *adapter;
777 struct rsi_91x_usbdev *dev;
778 u16 fw_status;
779 int status;
780
781 rsi_dbg(INIT_ZONE, "%s: Init function called\n", __func__);
782
783 adapter = rsi_91x_init(dev_oper_mode);
784 if (!adapter) {
785 rsi_dbg(ERR_ZONE, "%s: Failed to init os intf ops\n",
786 __func__);
787 return -ENOMEM;
788 }
789 adapter->rsi_host_intf = RSI_HOST_INTF_USB;
790
791 status = rsi_init_usb_interface(adapter, pfunction);
792 if (status) {
793 rsi_dbg(ERR_ZONE, "%s: Failed to init usb interface\n",
794 __func__);
795 goto err;
796 }
797
798 rsi_dbg(ERR_ZONE, "%s: Initialized os intf ops\n", __func__);
799
800 if (id && id->idProduct == RSI_USB_PID_9113) {
801 rsi_dbg(INIT_ZONE, "%s: 9113 module detected\n", __func__);
802 adapter->device_model = RSI_DEV_9113;
803 } else if (id && id->idProduct == RSI_USB_PID_9116) {
804 rsi_dbg(INIT_ZONE, "%s: 9116 module detected\n", __func__);
805 adapter->device_model = RSI_DEV_9116;
806 } else {
807 rsi_dbg(ERR_ZONE, "%s: Unsupported RSI device id 0x%x\n",
808 __func__, id->idProduct);
809 goto err1;
810 }
811
812 dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
813
814 status = rsi_usb_reg_read(dev->usbdev, FW_STATUS_REG, &fw_status, 2);
815 if (status < 0)
816 goto err1;
817 else
818 fw_status &= 1;
819
820 if (!fw_status) {
821 rsi_dbg(INIT_ZONE, "Loading firmware...\n");
822 status = rsi_hal_device_init(adapter);
823 if (status) {
824 rsi_dbg(ERR_ZONE, "%s: Failed in device init\n",
825 __func__);
826 goto err1;
827 }
828 rsi_dbg(INIT_ZONE, "%s: Device Init Done\n", __func__);
829 }
830
831 status = rsi_rx_urb_submit(adapter, WLAN_EP, GFP_KERNEL);
832 if (status)
833 goto err1;
834
835 if (adapter->priv->coex_mode > 1) {
836 status = rsi_rx_urb_submit(adapter, BT_EP, GFP_KERNEL);
837 if (status)
838 goto err_kill_wlan_urb;
839 }
840
841 return 0;
842
843 err_kill_wlan_urb:
844 rsi_rx_urb_kill(adapter, WLAN_EP);
845 err1:
846 rsi_deinit_usb_interface(adapter);
847 err:
848 rsi_91x_deinit(adapter);
849 rsi_dbg(ERR_ZONE, "%s: Failed in probe...Exiting\n", __func__);
850 return status;
851 }
852
853
854
855
856
857
858
859
860 static void rsi_disconnect(struct usb_interface *pfunction)
861 {
862 struct rsi_hw *adapter = usb_get_intfdata(pfunction);
863
864 if (!adapter)
865 return;
866
867 rsi_mac80211_detach(adapter);
868
869 if (IS_ENABLED(CONFIG_RSI_COEX) && adapter->priv->coex_mode > 1 &&
870 adapter->priv->bt_adapter) {
871 rsi_bt_ops.detach(adapter->priv->bt_adapter);
872 adapter->priv->bt_adapter = NULL;
873 }
874
875 if (adapter->priv->coex_mode > 1)
876 rsi_rx_urb_kill(adapter, BT_EP);
877 rsi_rx_urb_kill(adapter, WLAN_EP);
878
879 rsi_reset_card(adapter);
880 rsi_deinit_usb_interface(adapter);
881 rsi_91x_deinit(adapter);
882
883 rsi_dbg(INFO_ZONE, "%s: Deinitialization completed\n", __func__);
884 }
885
886 #ifdef CONFIG_PM
887 static int rsi_suspend(struct usb_interface *intf, pm_message_t message)
888 {
889
890 return -ENOSYS;
891 }
892
893 static int rsi_resume(struct usb_interface *intf)
894 {
895
896 return -ENOSYS;
897 }
898 #endif
899
900 static const struct usb_device_id rsi_dev_table[] = {
901 { USB_DEVICE(RSI_USB_VENDOR_ID, RSI_USB_PID_9113) },
902 { USB_DEVICE(RSI_USB_VENDOR_ID, RSI_USB_PID_9116) },
903 { },
904 };
905
906 static struct usb_driver rsi_driver = {
907 .name = "RSI-USB WLAN",
908 .probe = rsi_probe,
909 .disconnect = rsi_disconnect,
910 .id_table = rsi_dev_table,
911 #ifdef CONFIG_PM
912 .suspend = rsi_suspend,
913 .resume = rsi_resume,
914 #endif
915 };
916
917 module_usb_driver(rsi_driver);
918
919 MODULE_AUTHOR("Redpine Signals Inc");
920 MODULE_DESCRIPTION("Common USB layer for RSI drivers");
921 MODULE_SUPPORTED_DEVICE("RSI-91x");
922 MODULE_DEVICE_TABLE(usb, rsi_dev_table);
923 MODULE_FIRMWARE(FIRMWARE_RSI9113);
924 MODULE_VERSION("0.1");
925 MODULE_LICENSE("Dual BSD/GPL");