HID: rmi: Support the Lenovo Thinkpad X1 Tablet dock using hid-rmi
[platform/kernel/linux-exynos.git] / drivers / net / wireless / realtek / rtlwifi / usb.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2009-2012  Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * The full GNU General Public License is included in this distribution in the
15  * file called LICENSE.
16  *
17  * Contact Information:
18  * wlanfae <wlanfae@realtek.com>
19  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20  * Hsinchu 300, Taiwan.
21  *
22  *****************************************************************************/
23
24 #include "wifi.h"
25 #include "core.h"
26 #include "usb.h"
27 #include "base.h"
28 #include "ps.h"
29 #include "rtl8192c/fw_common.h"
30 #include <linux/export.h>
31 #include <linux/module.h>
32
33 MODULE_AUTHOR("lizhaoming       <chaoming_li@realsil.com.cn>");
34 MODULE_AUTHOR("Realtek WlanFAE  <wlanfae@realtek.com>");
35 MODULE_AUTHOR("Larry Finger     <Larry.FInger@lwfinger.net>");
36 MODULE_LICENSE("GPL");
37 MODULE_DESCRIPTION("USB basic driver for rtlwifi");
38
39 #define REALTEK_USB_VENQT_READ                  0xC0
40 #define REALTEK_USB_VENQT_WRITE                 0x40
41 #define REALTEK_USB_VENQT_CMD_REQ               0x05
42 #define REALTEK_USB_VENQT_CMD_IDX               0x00
43
44 #define MAX_USBCTRL_VENDORREQ_TIMES             10
45
46 static void usbctrl_async_callback(struct urb *urb)
47 {
48         if (urb) {
49                 /* free dr */
50                 kfree(urb->setup_packet);
51                 /* free databuf */
52                 kfree(urb->transfer_buffer);
53         }
54 }
55
56 static int _usbctrl_vendorreq_async_write(struct usb_device *udev, u8 request,
57                                           u16 value, u16 index, void *pdata,
58                                           u16 len)
59 {
60         int rc;
61         unsigned int pipe;
62         u8 reqtype;
63         struct usb_ctrlrequest *dr;
64         struct urb *urb;
65         const u16 databuf_maxlen = REALTEK_USB_VENQT_MAX_BUF_SIZE;
66         u8 *databuf;
67
68         if (WARN_ON_ONCE(len > databuf_maxlen))
69                 len = databuf_maxlen;
70
71         pipe = usb_sndctrlpipe(udev, 0); /* write_out */
72         reqtype =  REALTEK_USB_VENQT_WRITE;
73
74         dr = kzalloc(sizeof(*dr), GFP_ATOMIC);
75         if (!dr)
76                 return -ENOMEM;
77
78         databuf = kzalloc(databuf_maxlen, GFP_ATOMIC);
79         if (!databuf) {
80                 kfree(dr);
81                 return -ENOMEM;
82         }
83
84         urb = usb_alloc_urb(0, GFP_ATOMIC);
85         if (!urb) {
86                 kfree(databuf);
87                 kfree(dr);
88                 return -ENOMEM;
89         }
90
91         dr->bRequestType = reqtype;
92         dr->bRequest = request;
93         dr->wValue = cpu_to_le16(value);
94         dr->wIndex = cpu_to_le16(index);
95         dr->wLength = cpu_to_le16(len);
96         /* data are already in little-endian order */
97         memcpy(databuf, pdata, len);
98         usb_fill_control_urb(urb, udev, pipe,
99                              (unsigned char *)dr, databuf, len,
100                              usbctrl_async_callback, NULL);
101         rc = usb_submit_urb(urb, GFP_ATOMIC);
102         if (rc < 0) {
103                 kfree(databuf);
104                 kfree(dr);
105         }
106         usb_free_urb(urb);
107         return rc;
108 }
109
110 static int _usbctrl_vendorreq_sync_read(struct usb_device *udev, u8 request,
111                                         u16 value, u16 index, void *pdata,
112                                         u16 len)
113 {
114         unsigned int pipe;
115         int status;
116         u8 reqtype;
117         int vendorreq_times = 0;
118         static int count;
119
120         pipe = usb_rcvctrlpipe(udev, 0); /* read_in */
121         reqtype =  REALTEK_USB_VENQT_READ;
122
123         do {
124                 status = usb_control_msg(udev, pipe, request, reqtype, value,
125                                          index, pdata, len, 1000);
126                 if (status < 0) {
127                         /* firmware download is checksumed, don't retry */
128                         if ((value >= FW_8192C_START_ADDRESS &&
129                             value <= FW_8192C_END_ADDRESS))
130                                 break;
131                 } else {
132                         break;
133                 }
134         } while (++vendorreq_times < MAX_USBCTRL_VENDORREQ_TIMES);
135
136         if (status < 0 && count++ < 4)
137                 pr_err("reg 0x%x, usbctrl_vendorreq TimeOut! status:0x%x value=0x%x\n",
138                        value, status, *(u32 *)pdata);
139         return status;
140 }
141
142 static u32 _usb_read_sync(struct rtl_priv *rtlpriv, u32 addr, u16 len)
143 {
144         struct device *dev = rtlpriv->io.dev;
145         struct usb_device *udev = to_usb_device(dev);
146         u8 request;
147         u16 wvalue;
148         u16 index;
149         __le32 *data;
150         unsigned long flags;
151
152         spin_lock_irqsave(&rtlpriv->locks.usb_lock, flags);
153         if (++rtlpriv->usb_data_index >= RTL_USB_MAX_RX_COUNT)
154                 rtlpriv->usb_data_index = 0;
155         data = &rtlpriv->usb_data[rtlpriv->usb_data_index];
156         spin_unlock_irqrestore(&rtlpriv->locks.usb_lock, flags);
157         request = REALTEK_USB_VENQT_CMD_REQ;
158         index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */
159
160         wvalue = (u16)addr;
161         _usbctrl_vendorreq_sync_read(udev, request, wvalue, index, data, len);
162         return le32_to_cpu(*data);
163 }
164
165 static u8 _usb_read8_sync(struct rtl_priv *rtlpriv, u32 addr)
166 {
167         return (u8)_usb_read_sync(rtlpriv, addr, 1);
168 }
169
170 static u16 _usb_read16_sync(struct rtl_priv *rtlpriv, u32 addr)
171 {
172         return (u16)_usb_read_sync(rtlpriv, addr, 2);
173 }
174
175 static u32 _usb_read32_sync(struct rtl_priv *rtlpriv, u32 addr)
176 {
177         return _usb_read_sync(rtlpriv, addr, 4);
178 }
179
180 static void _usb_write_async(struct usb_device *udev, u32 addr, u32 val,
181                              u16 len)
182 {
183         u8 request;
184         u16 wvalue;
185         u16 index;
186         __le32 data;
187
188         request = REALTEK_USB_VENQT_CMD_REQ;
189         index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */
190         wvalue = (u16)(addr&0x0000ffff);
191         data = cpu_to_le32(val);
192         _usbctrl_vendorreq_async_write(udev, request, wvalue, index, &data,
193                                        len);
194 }
195
196 static void _usb_write8_async(struct rtl_priv *rtlpriv, u32 addr, u8 val)
197 {
198         struct device *dev = rtlpriv->io.dev;
199
200         _usb_write_async(to_usb_device(dev), addr, val, 1);
201 }
202
203 static void _usb_write16_async(struct rtl_priv *rtlpriv, u32 addr, u16 val)
204 {
205         struct device *dev = rtlpriv->io.dev;
206
207         _usb_write_async(to_usb_device(dev), addr, val, 2);
208 }
209
210 static void _usb_write32_async(struct rtl_priv *rtlpriv, u32 addr, u32 val)
211 {
212         struct device *dev = rtlpriv->io.dev;
213
214         _usb_write_async(to_usb_device(dev), addr, val, 4);
215 }
216
217 static void _usb_writeN_sync(struct rtl_priv *rtlpriv, u32 addr, void *data,
218                              u16 len)
219 {
220         struct device *dev = rtlpriv->io.dev;
221         struct usb_device *udev = to_usb_device(dev);
222         u8 request = REALTEK_USB_VENQT_CMD_REQ;
223         u8 reqtype =  REALTEK_USB_VENQT_WRITE;
224         u16 wvalue;
225         u16 index = REALTEK_USB_VENQT_CMD_IDX;
226         int pipe = usb_sndctrlpipe(udev, 0); /* write_out */
227         u8 *buffer;
228
229         wvalue = (u16)(addr & 0x0000ffff);
230         buffer = kmemdup(data, len, GFP_ATOMIC);
231         if (!buffer)
232                 return;
233         usb_control_msg(udev, pipe, request, reqtype, wvalue,
234                         index, buffer, len, 50);
235
236         kfree(buffer);
237 }
238
239 static void _rtl_usb_io_handler_init(struct device *dev,
240                                      struct ieee80211_hw *hw)
241 {
242         struct rtl_priv *rtlpriv = rtl_priv(hw);
243
244         rtlpriv->io.dev = dev;
245         mutex_init(&rtlpriv->io.bb_mutex);
246         rtlpriv->io.write8_async        = _usb_write8_async;
247         rtlpriv->io.write16_async       = _usb_write16_async;
248         rtlpriv->io.write32_async       = _usb_write32_async;
249         rtlpriv->io.read8_sync          = _usb_read8_sync;
250         rtlpriv->io.read16_sync         = _usb_read16_sync;
251         rtlpriv->io.read32_sync         = _usb_read32_sync;
252         rtlpriv->io.writeN_sync         = _usb_writeN_sync;
253 }
254
255 static void _rtl_usb_io_handler_release(struct ieee80211_hw *hw)
256 {
257         struct rtl_priv __maybe_unused *rtlpriv = rtl_priv(hw);
258
259         mutex_destroy(&rtlpriv->io.bb_mutex);
260 }
261
262 /**
263  *
264  *      Default aggregation handler. Do nothing and just return the oldest skb.
265  */
266 static struct sk_buff *_none_usb_tx_aggregate_hdl(struct ieee80211_hw *hw,
267                                                   struct sk_buff_head *list)
268 {
269         return skb_dequeue(list);
270 }
271
272 #define IS_HIGH_SPEED_USB(udev) \
273                 ((USB_SPEED_HIGH == (udev)->speed) ? true : false)
274
275 static int _rtl_usb_init_tx(struct ieee80211_hw *hw)
276 {
277         u32 i;
278         struct rtl_priv *rtlpriv = rtl_priv(hw);
279         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
280
281         rtlusb->max_bulk_out_size = IS_HIGH_SPEED_USB(rtlusb->udev)
282                                                     ? USB_HIGH_SPEED_BULK_SIZE
283                                                     : USB_FULL_SPEED_BULK_SIZE;
284
285         RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "USB Max Bulk-out Size=%d\n",
286                  rtlusb->max_bulk_out_size);
287
288         for (i = 0; i < __RTL_TXQ_NUM; i++) {
289                 u32 ep_num = rtlusb->ep_map.ep_mapping[i];
290                 if (!ep_num) {
291                         RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
292                                  "Invalid endpoint map setting!\n");
293                         return -EINVAL;
294                 }
295         }
296
297         rtlusb->usb_tx_post_hdl =
298                  rtlpriv->cfg->usb_interface_cfg->usb_tx_post_hdl;
299         rtlusb->usb_tx_cleanup  =
300                  rtlpriv->cfg->usb_interface_cfg->usb_tx_cleanup;
301         rtlusb->usb_tx_aggregate_hdl =
302                  (rtlpriv->cfg->usb_interface_cfg->usb_tx_aggregate_hdl)
303                  ? rtlpriv->cfg->usb_interface_cfg->usb_tx_aggregate_hdl
304                  : &_none_usb_tx_aggregate_hdl;
305
306         init_usb_anchor(&rtlusb->tx_submitted);
307         for (i = 0; i < RTL_USB_MAX_EP_NUM; i++) {
308                 skb_queue_head_init(&rtlusb->tx_skb_queue[i]);
309                 init_usb_anchor(&rtlusb->tx_pending[i]);
310         }
311         return 0;
312 }
313
314 static void _rtl_rx_work(unsigned long param);
315
316 static int _rtl_usb_init_rx(struct ieee80211_hw *hw)
317 {
318         struct rtl_priv *rtlpriv = rtl_priv(hw);
319         struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw);
320         struct rtl_usb *rtlusb = rtl_usbdev(usb_priv);
321
322         rtlusb->rx_max_size = rtlpriv->cfg->usb_interface_cfg->rx_max_size;
323         rtlusb->rx_urb_num = rtlpriv->cfg->usb_interface_cfg->rx_urb_num;
324         rtlusb->in_ep = rtlpriv->cfg->usb_interface_cfg->in_ep_num;
325         rtlusb->usb_rx_hdl = rtlpriv->cfg->usb_interface_cfg->usb_rx_hdl;
326         rtlusb->usb_rx_segregate_hdl =
327                 rtlpriv->cfg->usb_interface_cfg->usb_rx_segregate_hdl;
328
329         pr_info("rx_max_size %d, rx_urb_num %d, in_ep %d\n",
330                 rtlusb->rx_max_size, rtlusb->rx_urb_num, rtlusb->in_ep);
331         init_usb_anchor(&rtlusb->rx_submitted);
332         init_usb_anchor(&rtlusb->rx_cleanup_urbs);
333
334         skb_queue_head_init(&rtlusb->rx_queue);
335         rtlusb->rx_work_tasklet.func = _rtl_rx_work;
336         rtlusb->rx_work_tasklet.data = (unsigned long)rtlusb;
337
338         return 0;
339 }
340
341 static int _rtl_usb_init(struct ieee80211_hw *hw)
342 {
343         struct rtl_priv *rtlpriv = rtl_priv(hw);
344         struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw);
345         struct rtl_usb *rtlusb = rtl_usbdev(usb_priv);
346         int err;
347         u8 epidx;
348         struct usb_interface    *usb_intf = rtlusb->intf;
349         u8 epnums = usb_intf->cur_altsetting->desc.bNumEndpoints;
350
351         rtlusb->out_ep_nums = rtlusb->in_ep_nums = 0;
352         for (epidx = 0; epidx < epnums; epidx++) {
353                 struct usb_endpoint_descriptor *pep_desc;
354                 pep_desc = &usb_intf->cur_altsetting->endpoint[epidx].desc;
355
356                 if (usb_endpoint_dir_in(pep_desc))
357                         rtlusb->in_ep_nums++;
358                 else if (usb_endpoint_dir_out(pep_desc))
359                         rtlusb->out_ep_nums++;
360
361                 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
362                          "USB EP(0x%02x), MaxPacketSize=%d, Interval=%d\n",
363                          pep_desc->bEndpointAddress, pep_desc->wMaxPacketSize,
364                          pep_desc->bInterval);
365         }
366         if (rtlusb->in_ep_nums <  rtlpriv->cfg->usb_interface_cfg->in_ep_num) {
367                 pr_err("Too few input end points found\n");
368                 return -EINVAL;
369         }
370         if (rtlusb->out_ep_nums == 0) {
371                 pr_err("No output end points found\n");
372                 return -EINVAL;
373         }
374         /* usb endpoint mapping */
375         err = rtlpriv->cfg->usb_interface_cfg->usb_endpoint_mapping(hw);
376         rtlusb->usb_mq_to_hwq =  rtlpriv->cfg->usb_interface_cfg->usb_mq_to_hwq;
377         _rtl_usb_init_tx(hw);
378         _rtl_usb_init_rx(hw);
379         return err;
380 }
381
382 static void rtl_usb_init_sw(struct ieee80211_hw *hw)
383 {
384         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
385         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
386         struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
387         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
388
389         rtlhal->hw = hw;
390         ppsc->inactiveps = false;
391         ppsc->leisure_ps = false;
392         ppsc->fwctrl_lps = false;
393         ppsc->reg_fwctrl_lps = 3;
394         ppsc->reg_max_lps_awakeintvl = 5;
395         ppsc->fwctrl_psmode = FW_PS_DTIM_MODE;
396
397          /* IBSS */
398         mac->beacon_interval = 100;
399
400          /* AMPDU */
401         mac->min_space_cfg = 0;
402         mac->max_mss_density = 0;
403
404         /* set sane AMPDU defaults */
405         mac->current_ampdu_density = 7;
406         mac->current_ampdu_factor = 3;
407
408         /* QOS */
409         rtlusb->acm_method = EACMWAY2_SW;
410
411         /* IRQ */
412         /* HIMR - turn all on */
413         rtlusb->irq_mask[0] = 0xFFFFFFFF;
414         /* HIMR_EX - turn all on */
415         rtlusb->irq_mask[1] = 0xFFFFFFFF;
416         rtlusb->disableHWSM =  true;
417 }
418
419 static void _rtl_rx_completed(struct urb *urb);
420
421 static int _rtl_prep_rx_urb(struct ieee80211_hw *hw, struct rtl_usb *rtlusb,
422                               struct urb *urb, gfp_t gfp_mask)
423 {
424         struct rtl_priv *rtlpriv = rtl_priv(hw);
425         void *buf;
426
427         buf = usb_alloc_coherent(rtlusb->udev, rtlusb->rx_max_size, gfp_mask,
428                                  &urb->transfer_dma);
429         if (!buf) {
430                 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
431                          "Failed to usb_alloc_coherent!!\n");
432                 return -ENOMEM;
433         }
434
435         usb_fill_bulk_urb(urb, rtlusb->udev,
436                           usb_rcvbulkpipe(rtlusb->udev, rtlusb->in_ep),
437                           buf, rtlusb->rx_max_size, _rtl_rx_completed, rtlusb);
438         urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
439
440         return 0;
441 }
442
443 static void _rtl_usb_rx_process_agg(struct ieee80211_hw *hw,
444                                     struct sk_buff *skb)
445 {
446         struct rtl_priv *rtlpriv = rtl_priv(hw);
447         u8 *rxdesc = skb->data;
448         struct ieee80211_hdr *hdr;
449         bool unicast = false;
450         __le16 fc;
451         struct ieee80211_rx_status rx_status = {0};
452         struct rtl_stats stats = {
453                 .signal = 0,
454                 .rate = 0,
455         };
456
457         skb_pull(skb, RTL_RX_DESC_SIZE);
458         rtlpriv->cfg->ops->query_rx_desc(hw, &stats, &rx_status, rxdesc, skb);
459         skb_pull(skb, (stats.rx_drvinfo_size + stats.rx_bufshift));
460         hdr = (struct ieee80211_hdr *)(skb->data);
461         fc = hdr->frame_control;
462         if (!stats.crc) {
463                 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
464
465                 if (is_broadcast_ether_addr(hdr->addr1)) {
466                         /*TODO*/;
467                 } else if (is_multicast_ether_addr(hdr->addr1)) {
468                         /*TODO*/
469                 } else {
470                         unicast = true;
471                         rtlpriv->stats.rxbytesunicast +=  skb->len;
472                 }
473
474                 if (ieee80211_is_data(fc)) {
475                         rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX);
476
477                         if (unicast)
478                                 rtlpriv->link_info.num_rx_inperiod++;
479                 }
480                 /* static bcn for roaming */
481                 rtl_beacon_statistic(hw, skb);
482         }
483 }
484
485 static void _rtl_usb_rx_process_noagg(struct ieee80211_hw *hw,
486                                       struct sk_buff *skb)
487 {
488         struct rtl_priv *rtlpriv = rtl_priv(hw);
489         u8 *rxdesc = skb->data;
490         struct ieee80211_hdr *hdr;
491         bool unicast = false;
492         __le16 fc;
493         struct ieee80211_rx_status rx_status = {0};
494         struct rtl_stats stats = {
495                 .signal = 0,
496                 .rate = 0,
497         };
498
499         skb_pull(skb, RTL_RX_DESC_SIZE);
500         rtlpriv->cfg->ops->query_rx_desc(hw, &stats, &rx_status, rxdesc, skb);
501         skb_pull(skb, (stats.rx_drvinfo_size + stats.rx_bufshift));
502         hdr = (struct ieee80211_hdr *)(skb->data);
503         fc = hdr->frame_control;
504         if (!stats.crc) {
505                 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
506
507                 if (is_broadcast_ether_addr(hdr->addr1)) {
508                         /*TODO*/;
509                 } else if (is_multicast_ether_addr(hdr->addr1)) {
510                         /*TODO*/
511                 } else {
512                         unicast = true;
513                         rtlpriv->stats.rxbytesunicast +=  skb->len;
514                 }
515
516                 if (ieee80211_is_data(fc)) {
517                         rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX);
518
519                         if (unicast)
520                                 rtlpriv->link_info.num_rx_inperiod++;
521                 }
522
523                 /* static bcn for roaming */
524                 rtl_beacon_statistic(hw, skb);
525
526                 if (likely(rtl_action_proc(hw, skb, false)))
527                         ieee80211_rx(hw, skb);
528                 else
529                         dev_kfree_skb_any(skb);
530         } else {
531                 dev_kfree_skb_any(skb);
532         }
533 }
534
535 static void _rtl_rx_pre_process(struct ieee80211_hw *hw, struct sk_buff *skb)
536 {
537         struct sk_buff *_skb;
538         struct sk_buff_head rx_queue;
539         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
540
541         skb_queue_head_init(&rx_queue);
542         if (rtlusb->usb_rx_segregate_hdl)
543                 rtlusb->usb_rx_segregate_hdl(hw, skb, &rx_queue);
544         WARN_ON(skb_queue_empty(&rx_queue));
545         while (!skb_queue_empty(&rx_queue)) {
546                 _skb = skb_dequeue(&rx_queue);
547                 _rtl_usb_rx_process_agg(hw, _skb);
548                 ieee80211_rx(hw, _skb);
549         }
550 }
551
552 #define __RX_SKB_MAX_QUEUED     64
553
554 static void _rtl_rx_work(unsigned long param)
555 {
556         struct rtl_usb *rtlusb = (struct rtl_usb *)param;
557         struct ieee80211_hw *hw = usb_get_intfdata(rtlusb->intf);
558         struct sk_buff *skb;
559
560         while ((skb = skb_dequeue(&rtlusb->rx_queue))) {
561                 if (unlikely(IS_USB_STOP(rtlusb))) {
562                         dev_kfree_skb_any(skb);
563                         continue;
564                 }
565
566                 if (likely(!rtlusb->usb_rx_segregate_hdl)) {
567                         _rtl_usb_rx_process_noagg(hw, skb);
568                 } else {
569                         /* TO DO */
570                         _rtl_rx_pre_process(hw, skb);
571                         pr_err("rx agg not supported\n");
572                 }
573         }
574 }
575
576 static unsigned int _rtl_rx_get_padding(struct ieee80211_hdr *hdr,
577                                         unsigned int len)
578 {
579 #if NET_IP_ALIGN != 0
580         unsigned int padding = 0;
581 #endif
582
583         /* make function no-op when possible */
584         if (NET_IP_ALIGN == 0 || len < sizeof(*hdr))
585                 return 0;
586
587 #if NET_IP_ALIGN != 0
588         /* alignment calculation as in lbtf_rx() / carl9170_rx_copy_data() */
589         /* TODO: deduplicate common code, define helper function instead? */
590
591         if (ieee80211_is_data_qos(hdr->frame_control)) {
592                 u8 *qc = ieee80211_get_qos_ctl(hdr);
593
594                 padding ^= NET_IP_ALIGN;
595
596                 /* Input might be invalid, avoid accessing memory outside
597                  * the buffer.
598                  */
599                 if ((unsigned long)qc - (unsigned long)hdr < len &&
600                     *qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
601                         padding ^= NET_IP_ALIGN;
602         }
603
604         if (ieee80211_has_a4(hdr->frame_control))
605                 padding ^= NET_IP_ALIGN;
606
607         return padding;
608 #endif
609 }
610
611 #define __RADIO_TAP_SIZE_RSV    32
612
613 static void _rtl_rx_completed(struct urb *_urb)
614 {
615         struct rtl_usb *rtlusb = (struct rtl_usb *)_urb->context;
616         struct ieee80211_hw *hw = usb_get_intfdata(rtlusb->intf);
617         struct rtl_priv *rtlpriv = rtl_priv(hw);
618         int err = 0;
619
620         if (unlikely(IS_USB_STOP(rtlusb)))
621                 goto free;
622
623         if (likely(0 == _urb->status)) {
624                 unsigned int padding;
625                 struct sk_buff *skb;
626                 unsigned int qlen;
627                 unsigned int size = _urb->actual_length;
628                 struct ieee80211_hdr *hdr;
629
630                 if (size < RTL_RX_DESC_SIZE + sizeof(struct ieee80211_hdr)) {
631                         RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
632                                  "Too short packet from bulk IN! (len: %d)\n",
633                                  size);
634                         goto resubmit;
635                 }
636
637                 qlen = skb_queue_len(&rtlusb->rx_queue);
638                 if (qlen >= __RX_SKB_MAX_QUEUED) {
639                         RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
640                                  "Pending RX skbuff queue full! (qlen: %d)\n",
641                                  qlen);
642                         goto resubmit;
643                 }
644
645                 hdr = (void *)(_urb->transfer_buffer + RTL_RX_DESC_SIZE);
646                 padding = _rtl_rx_get_padding(hdr, size - RTL_RX_DESC_SIZE);
647
648                 skb = dev_alloc_skb(size + __RADIO_TAP_SIZE_RSV + padding);
649                 if (!skb) {
650                         RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
651                                  "Can't allocate skb for bulk IN!\n");
652                         goto resubmit;
653                 }
654
655                 _rtl_install_trx_info(rtlusb, skb, rtlusb->in_ep);
656
657                 /* Make sure the payload data is 4 byte aligned. */
658                 skb_reserve(skb, padding);
659
660                 /* reserve some space for mac80211's radiotap */
661                 skb_reserve(skb, __RADIO_TAP_SIZE_RSV);
662
663                 memcpy(skb_put(skb, size), _urb->transfer_buffer, size);
664
665                 skb_queue_tail(&rtlusb->rx_queue, skb);
666                 tasklet_schedule(&rtlusb->rx_work_tasklet);
667
668                 goto resubmit;
669         }
670
671         switch (_urb->status) {
672         /* disconnect */
673         case -ENOENT:
674         case -ECONNRESET:
675         case -ENODEV:
676         case -ESHUTDOWN:
677                 goto free;
678         default:
679                 break;
680         }
681
682 resubmit:
683         usb_anchor_urb(_urb, &rtlusb->rx_submitted);
684         err = usb_submit_urb(_urb, GFP_ATOMIC);
685         if (unlikely(err)) {
686                 usb_unanchor_urb(_urb);
687                 goto free;
688         }
689         return;
690
691 free:
692         /* On some architectures, usb_free_coherent must not be called from
693          * hardirq context. Queue urb to cleanup list.
694          */
695         usb_anchor_urb(_urb, &rtlusb->rx_cleanup_urbs);
696 }
697
698 #undef __RADIO_TAP_SIZE_RSV
699
700 static void _rtl_usb_cleanup_rx(struct ieee80211_hw *hw)
701 {
702         struct rtl_priv *rtlpriv = rtl_priv(hw);
703         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
704         struct urb *urb;
705
706         usb_kill_anchored_urbs(&rtlusb->rx_submitted);
707
708         tasklet_kill(&rtlusb->rx_work_tasklet);
709         cancel_work_sync(&rtlpriv->works.lps_change_work);
710
711         flush_workqueue(rtlpriv->works.rtl_wq);
712         destroy_workqueue(rtlpriv->works.rtl_wq);
713
714         skb_queue_purge(&rtlusb->rx_queue);
715
716         while ((urb = usb_get_from_anchor(&rtlusb->rx_cleanup_urbs))) {
717                 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
718                                 urb->transfer_buffer, urb->transfer_dma);
719                 usb_free_urb(urb);
720         }
721 }
722
723 static int _rtl_usb_receive(struct ieee80211_hw *hw)
724 {
725         struct urb *urb;
726         int err;
727         int i;
728         struct rtl_priv *rtlpriv = rtl_priv(hw);
729         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
730
731         WARN_ON(0 == rtlusb->rx_urb_num);
732         /* 1600 == 1514 + max WLAN header + rtk info */
733         WARN_ON(rtlusb->rx_max_size < 1600);
734
735         for (i = 0; i < rtlusb->rx_urb_num; i++) {
736                 err = -ENOMEM;
737                 urb = usb_alloc_urb(0, GFP_KERNEL);
738                 if (!urb)
739                         goto err_out;
740
741                 err = _rtl_prep_rx_urb(hw, rtlusb, urb, GFP_KERNEL);
742                 if (err < 0) {
743                         RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
744                                  "Failed to prep_rx_urb!!\n");
745                         usb_free_urb(urb);
746                         goto err_out;
747                 }
748
749                 usb_anchor_urb(urb, &rtlusb->rx_submitted);
750                 err = usb_submit_urb(urb, GFP_KERNEL);
751                 if (err)
752                         goto err_out;
753                 usb_free_urb(urb);
754         }
755         return 0;
756
757 err_out:
758         usb_kill_anchored_urbs(&rtlusb->rx_submitted);
759         _rtl_usb_cleanup_rx(hw);
760         return err;
761 }
762
763 static int rtl_usb_start(struct ieee80211_hw *hw)
764 {
765         int err;
766         struct rtl_priv *rtlpriv = rtl_priv(hw);
767         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
768         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
769
770         err = rtlpriv->cfg->ops->hw_init(hw);
771         if (!err) {
772                 rtl_init_rx_config(hw);
773
774                 /* Enable software */
775                 SET_USB_START(rtlusb);
776                 /* should after adapter start and interrupt enable. */
777                 set_hal_start(rtlhal);
778
779                 /* Start bulk IN */
780                 err = _rtl_usb_receive(hw);
781         }
782
783         return err;
784 }
785 /**
786  *
787  *
788  */
789
790 /*=======================  tx =========================================*/
791 static void rtl_usb_cleanup(struct ieee80211_hw *hw)
792 {
793         u32 i;
794         struct sk_buff *_skb;
795         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
796         struct ieee80211_tx_info *txinfo;
797
798         /* clean up rx stuff. */
799         _rtl_usb_cleanup_rx(hw);
800
801         /* clean up tx stuff */
802         for (i = 0; i < RTL_USB_MAX_EP_NUM; i++) {
803                 while ((_skb = skb_dequeue(&rtlusb->tx_skb_queue[i]))) {
804                         rtlusb->usb_tx_cleanup(hw, _skb);
805                         txinfo = IEEE80211_SKB_CB(_skb);
806                         ieee80211_tx_info_clear_status(txinfo);
807                         txinfo->flags |= IEEE80211_TX_STAT_ACK;
808                         ieee80211_tx_status_irqsafe(hw, _skb);
809                 }
810                 usb_kill_anchored_urbs(&rtlusb->tx_pending[i]);
811         }
812         usb_kill_anchored_urbs(&rtlusb->tx_submitted);
813 }
814
815 /**
816  *
817  * We may add some struct into struct rtl_usb later. Do deinit here.
818  *
819  */
820 static void rtl_usb_deinit(struct ieee80211_hw *hw)
821 {
822         rtl_usb_cleanup(hw);
823 }
824
825 static void rtl_usb_stop(struct ieee80211_hw *hw)
826 {
827         struct rtl_priv *rtlpriv = rtl_priv(hw);
828         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
829         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
830
831         /* should after adapter start and interrupt enable. */
832         set_hal_stop(rtlhal);
833         cancel_work_sync(&rtlpriv->works.fill_h2c_cmd);
834         /* Enable software */
835         SET_USB_STOP(rtlusb);
836         rtlpriv->cfg->ops->hw_disable(hw);
837 }
838
839 static void _rtl_submit_tx_urb(struct ieee80211_hw *hw, struct urb *_urb)
840 {
841         int err;
842         struct rtl_priv *rtlpriv = rtl_priv(hw);
843         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
844
845         usb_anchor_urb(_urb, &rtlusb->tx_submitted);
846         err = usb_submit_urb(_urb, GFP_ATOMIC);
847         if (err < 0) {
848                 struct sk_buff *skb;
849
850                 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
851                          "Failed to submit urb\n");
852                 usb_unanchor_urb(_urb);
853                 skb = (struct sk_buff *)_urb->context;
854                 kfree_skb(skb);
855         }
856         usb_free_urb(_urb);
857 }
858
859 static int _usb_tx_post(struct ieee80211_hw *hw, struct urb *urb,
860                         struct sk_buff *skb)
861 {
862         struct rtl_priv *rtlpriv = rtl_priv(hw);
863         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
864         struct ieee80211_tx_info *txinfo;
865
866         rtlusb->usb_tx_post_hdl(hw, urb, skb);
867         skb_pull(skb, RTL_TX_HEADER_SIZE);
868         txinfo = IEEE80211_SKB_CB(skb);
869         ieee80211_tx_info_clear_status(txinfo);
870         txinfo->flags |= IEEE80211_TX_STAT_ACK;
871
872         if (urb->status) {
873                 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
874                          "Urb has error status 0x%X\n", urb->status);
875                 goto out;
876         }
877         /*  TODO:       statistics */
878 out:
879         ieee80211_tx_status_irqsafe(hw, skb);
880         return urb->status;
881 }
882
883 static void _rtl_tx_complete(struct urb *urb)
884 {
885         struct sk_buff *skb = (struct sk_buff *)urb->context;
886         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
887         struct rtl_usb *rtlusb = (struct rtl_usb *)info->rate_driver_data[0];
888         struct ieee80211_hw *hw = usb_get_intfdata(rtlusb->intf);
889         int err;
890
891         if (unlikely(IS_USB_STOP(rtlusb)))
892                 return;
893         err = _usb_tx_post(hw, urb, skb);
894         if (err) {
895                 /* Ignore error and keep issuiing other urbs */
896                 return;
897         }
898 }
899
900 static struct urb *_rtl_usb_tx_urb_setup(struct ieee80211_hw *hw,
901                                 struct sk_buff *skb, u32 ep_num)
902 {
903         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
904         struct urb *_urb;
905
906         WARN_ON(NULL == skb);
907         _urb = usb_alloc_urb(0, GFP_ATOMIC);
908         if (!_urb) {
909                 kfree_skb(skb);
910                 return NULL;
911         }
912         _rtl_install_trx_info(rtlusb, skb, ep_num);
913         usb_fill_bulk_urb(_urb, rtlusb->udev, usb_sndbulkpipe(rtlusb->udev,
914                           ep_num), skb->data, skb->len, _rtl_tx_complete, skb);
915         _urb->transfer_flags |= URB_ZERO_PACKET;
916         return _urb;
917 }
918
919 static void _rtl_usb_transmit(struct ieee80211_hw *hw, struct sk_buff *skb,
920                        enum rtl_txq qnum)
921 {
922         struct rtl_priv *rtlpriv = rtl_priv(hw);
923         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
924         u32 ep_num;
925         struct urb *_urb = NULL;
926         struct sk_buff *_skb = NULL;
927
928         WARN_ON(NULL == rtlusb->usb_tx_aggregate_hdl);
929         if (unlikely(IS_USB_STOP(rtlusb))) {
930                 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
931                          "USB device is stopping...\n");
932                 kfree_skb(skb);
933                 return;
934         }
935         ep_num = rtlusb->ep_map.ep_mapping[qnum];
936         _skb = skb;
937         _urb = _rtl_usb_tx_urb_setup(hw, _skb, ep_num);
938         if (unlikely(!_urb)) {
939                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
940                          "Can't allocate urb. Drop skb!\n");
941                 kfree_skb(skb);
942                 return;
943         }
944         _rtl_submit_tx_urb(hw, _urb);
945 }
946
947 static void _rtl_usb_tx_preprocess(struct ieee80211_hw *hw,
948                                    struct ieee80211_sta *sta,
949                                    struct sk_buff *skb,
950                                    u16 hw_queue)
951 {
952         struct rtl_priv *rtlpriv = rtl_priv(hw);
953         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
954         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
955         struct rtl_tx_desc *pdesc = NULL;
956         struct rtl_tcb_desc tcb_desc;
957         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
958         __le16 fc = hdr->frame_control;
959         u8 *pda_addr = hdr->addr1;
960         /* ssn */
961         u8 *qc = NULL;
962         u8 tid = 0;
963         u16 seq_number = 0;
964
965         memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
966         if (ieee80211_is_auth(fc)) {
967                 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
968                 rtl_ips_nic_on(hw);
969         }
970
971         if (rtlpriv->psc.sw_ps_enabled) {
972                 if (ieee80211_is_data(fc) && !ieee80211_is_nullfunc(fc) &&
973                     !ieee80211_has_pm(fc))
974                         hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
975         }
976
977         rtl_action_proc(hw, skb, true);
978         if (is_multicast_ether_addr(pda_addr))
979                 rtlpriv->stats.txbytesmulticast += skb->len;
980         else if (is_broadcast_ether_addr(pda_addr))
981                 rtlpriv->stats.txbytesbroadcast += skb->len;
982         else
983                 rtlpriv->stats.txbytesunicast += skb->len;
984         if (ieee80211_is_data_qos(fc)) {
985                 qc = ieee80211_get_qos_ctl(hdr);
986                 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
987                 seq_number = (le16_to_cpu(hdr->seq_ctrl) &
988                              IEEE80211_SCTL_SEQ) >> 4;
989                 seq_number += 1;
990                 seq_number <<= 4;
991         }
992         rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc, NULL, info, sta, skb,
993                                         hw_queue, &tcb_desc);
994         if (!ieee80211_has_morefrags(hdr->frame_control)) {
995                 if (qc)
996                         mac->tids[tid].seq_number = seq_number;
997         }
998         if (ieee80211_is_data(fc))
999                 rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX);
1000 }
1001
1002 static int rtl_usb_tx(struct ieee80211_hw *hw,
1003                       struct ieee80211_sta *sta,
1004                       struct sk_buff *skb,
1005                       struct rtl_tcb_desc *dummy)
1006 {
1007         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
1008         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1009         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
1010         __le16 fc = hdr->frame_control;
1011         u16 hw_queue;
1012
1013         if (unlikely(is_hal_stop(rtlhal)))
1014                 goto err_free;
1015         hw_queue = rtlusb->usb_mq_to_hwq(fc, skb_get_queue_mapping(skb));
1016         _rtl_usb_tx_preprocess(hw, sta, skb, hw_queue);
1017         _rtl_usb_transmit(hw, skb, hw_queue);
1018         return NETDEV_TX_OK;
1019
1020 err_free:
1021         dev_kfree_skb_any(skb);
1022         return NETDEV_TX_OK;
1023 }
1024
1025 static bool rtl_usb_tx_chk_waitq_insert(struct ieee80211_hw *hw,
1026                                         struct ieee80211_sta *sta,
1027                                         struct sk_buff *skb)
1028 {
1029         return false;
1030 }
1031
1032 static void rtl_fill_h2c_cmd_work_callback(struct work_struct *work)
1033 {
1034         struct rtl_works *rtlworks =
1035             container_of(work, struct rtl_works, fill_h2c_cmd);
1036         struct ieee80211_hw *hw = rtlworks->hw;
1037         struct rtl_priv *rtlpriv = rtl_priv(hw);
1038
1039         rtlpriv->cfg->ops->fill_h2c_cmd(hw, H2C_RA_MASK, 5, rtlpriv->rate_mask);
1040 }
1041
1042 static const struct rtl_intf_ops rtl_usb_ops = {
1043         .adapter_start = rtl_usb_start,
1044         .adapter_stop = rtl_usb_stop,
1045         .adapter_tx = rtl_usb_tx,
1046         .waitq_insert = rtl_usb_tx_chk_waitq_insert,
1047 };
1048
1049 int rtl_usb_probe(struct usb_interface *intf,
1050                   const struct usb_device_id *id,
1051                   struct rtl_hal_cfg *rtl_hal_cfg)
1052 {
1053         int err;
1054         struct ieee80211_hw *hw = NULL;
1055         struct rtl_priv *rtlpriv = NULL;
1056         struct usb_device       *udev;
1057         struct rtl_usb_priv *usb_priv;
1058
1059         hw = ieee80211_alloc_hw(sizeof(struct rtl_priv) +
1060                                 sizeof(struct rtl_usb_priv), &rtl_ops);
1061         if (!hw) {
1062                 RT_ASSERT(false, "ieee80211 alloc failed\n");
1063                 return -ENOMEM;
1064         }
1065         rtlpriv = hw->priv;
1066         rtlpriv->usb_data = kzalloc(RTL_USB_MAX_RX_COUNT * sizeof(u32),
1067                                     GFP_KERNEL);
1068         if (!rtlpriv->usb_data)
1069                 return -ENOMEM;
1070
1071         /* this spin lock must be initialized early */
1072         spin_lock_init(&rtlpriv->locks.usb_lock);
1073         INIT_WORK(&rtlpriv->works.fill_h2c_cmd,
1074                   rtl_fill_h2c_cmd_work_callback);
1075         INIT_WORK(&rtlpriv->works.lps_change_work,
1076                   rtl_lps_change_work_callback);
1077
1078         rtlpriv->usb_data_index = 0;
1079         init_completion(&rtlpriv->firmware_loading_complete);
1080         SET_IEEE80211_DEV(hw, &intf->dev);
1081         udev = interface_to_usbdev(intf);
1082         usb_get_dev(udev);
1083         usb_priv = rtl_usbpriv(hw);
1084         memset(usb_priv, 0, sizeof(*usb_priv));
1085         usb_priv->dev.intf = intf;
1086         usb_priv->dev.udev = udev;
1087         usb_set_intfdata(intf, hw);
1088         /* init cfg & intf_ops */
1089         rtlpriv->rtlhal.interface = INTF_USB;
1090         rtlpriv->cfg = rtl_hal_cfg;
1091         rtlpriv->intf_ops = &rtl_usb_ops;
1092         rtl_dbgp_flag_init(hw);
1093         /* Init IO handler */
1094         _rtl_usb_io_handler_init(&udev->dev, hw);
1095         rtlpriv->cfg->ops->read_chip_version(hw);
1096         /*like read eeprom and so on */
1097         rtlpriv->cfg->ops->read_eeprom_info(hw);
1098         err = _rtl_usb_init(hw);
1099         if (err)
1100                 goto error_out;
1101         rtl_usb_init_sw(hw);
1102         /* Init mac80211 sw */
1103         err = rtl_init_core(hw);
1104         if (err) {
1105                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1106                          "Can't allocate sw for mac80211\n");
1107                 goto error_out;
1108         }
1109         if (rtlpriv->cfg->ops->init_sw_vars(hw)) {
1110                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Can't init_sw_vars\n");
1111                 goto error_out;
1112         }
1113         rtlpriv->cfg->ops->init_sw_leds(hw);
1114
1115         err = ieee80211_register_hw(hw);
1116         if (err) {
1117                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1118                          "Can't register mac80211 hw.\n");
1119                 err = -ENODEV;
1120                 goto error_out;
1121         }
1122         rtlpriv->mac80211.mac80211_registered = 1;
1123
1124         set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
1125         return 0;
1126
1127 error_out:
1128         rtl_deinit_core(hw);
1129         _rtl_usb_io_handler_release(hw);
1130         usb_put_dev(udev);
1131         complete(&rtlpriv->firmware_loading_complete);
1132         return -ENODEV;
1133 }
1134 EXPORT_SYMBOL(rtl_usb_probe);
1135
1136 void rtl_usb_disconnect(struct usb_interface *intf)
1137 {
1138         struct ieee80211_hw *hw = usb_get_intfdata(intf);
1139         struct rtl_priv *rtlpriv = rtl_priv(hw);
1140         struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
1141         struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
1142
1143         if (unlikely(!rtlpriv))
1144                 return;
1145         /* just in case driver is removed before firmware callback */
1146         wait_for_completion(&rtlpriv->firmware_loading_complete);
1147         clear_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
1148         /*ieee80211_unregister_hw will call ops_stop */
1149         if (rtlmac->mac80211_registered == 1) {
1150                 ieee80211_unregister_hw(hw);
1151                 rtlmac->mac80211_registered = 0;
1152         } else {
1153                 rtl_deinit_deferred_work(hw);
1154                 rtlpriv->intf_ops->adapter_stop(hw);
1155         }
1156         /*deinit rfkill */
1157         /* rtl_deinit_rfkill(hw); */
1158         rtl_usb_deinit(hw);
1159         rtl_deinit_core(hw);
1160         kfree(rtlpriv->usb_data);
1161         rtlpriv->cfg->ops->deinit_sw_leds(hw);
1162         rtlpriv->cfg->ops->deinit_sw_vars(hw);
1163         _rtl_usb_io_handler_release(hw);
1164         usb_put_dev(rtlusb->udev);
1165         usb_set_intfdata(intf, NULL);
1166         ieee80211_free_hw(hw);
1167 }
1168 EXPORT_SYMBOL(rtl_usb_disconnect);
1169
1170 int rtl_usb_suspend(struct usb_interface *pusb_intf, pm_message_t message)
1171 {
1172         return 0;
1173 }
1174 EXPORT_SYMBOL(rtl_usb_suspend);
1175
1176 int rtl_usb_resume(struct usb_interface *pusb_intf)
1177 {
1178         return 0;
1179 }
1180 EXPORT_SYMBOL(rtl_usb_resume);