Version:  2.0.40 2.2.26 2.4.37 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9

Linux/drivers/staging/rtl8188eu/os_dep/usb_intf.c

  1 /******************************************************************************
  2  *
  3  * Copyright(c) 2007 - 2011 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  ******************************************************************************/
 15 
 16 #define pr_fmt(fmt) "R8188EU: " fmt
 17 #include <osdep_service.h>
 18 #include <drv_types.h>
 19 #include <recv_osdep.h>
 20 #include <xmit_osdep.h>
 21 #include <hal_intf.h>
 22 #include <linux/usb.h>
 23 #include <linux/vmalloc.h>
 24 #include <mon.h>
 25 #include <osdep_intf.h>
 26 
 27 #include <usb_ops_linux.h>
 28 #include <rtw_ioctl.h>
 29 
 30 #include "rtl8188e_hal.h"
 31 
 32 #define USB_VENDER_ID_REALTEK           0x0bda
 33 
 34 /* DID_USB_v916_20130116 */
 35 static struct usb_device_id rtw_usb_id_tbl[] = {
 36         /*=== Realtek demoboard ===*/
 37         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8179)}, /* 8188EUS */
 38         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0179)}, /* 8188ETV */
 39         /*=== Customer ID ===*/
 40         /****** 8188EUS ********/
 41         {USB_DEVICE(0x056e, 0x4008)}, /* Elecom WDC-150SU2M */
 42         {USB_DEVICE(0x07b8, 0x8179)}, /* Abocom - Abocom */
 43         {USB_DEVICE(0x2001, 0x330F)}, /* DLink DWA-125 REV D1 */
 44         {USB_DEVICE(0x2001, 0x3310)}, /* Dlink DWA-123 REV D1 */
 45         {USB_DEVICE(0x2001, 0x3311)}, /* DLink GO-USB-N150 REV B1 */
 46         {USB_DEVICE(0x0df6, 0x0076)}, /* Sitecom N150 v2 */
 47         {}      /* Terminating entry */
 48 };
 49 
 50 MODULE_DEVICE_TABLE(usb, rtw_usb_id_tbl);
 51 
 52 static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf)
 53 {
 54         int     i;
 55         struct dvobj_priv *pdvobjpriv;
 56         struct usb_host_config          *phost_conf;
 57         struct usb_config_descriptor    *pconf_desc;
 58         struct usb_host_interface       *phost_iface;
 59         struct usb_interface_descriptor *piface_desc;
 60         struct usb_endpoint_descriptor  *pendp_desc;
 61         struct usb_device       *pusbd;
 62 
 63         pdvobjpriv = kzalloc(sizeof(*pdvobjpriv), GFP_KERNEL);
 64         if (!pdvobjpriv)
 65                 return NULL;
 66 
 67         pdvobjpriv->pusbintf = usb_intf;
 68         pusbd = interface_to_usbdev(usb_intf);
 69         pdvobjpriv->pusbdev = pusbd;
 70         usb_set_intfdata(usb_intf, pdvobjpriv);
 71 
 72         pdvobjpriv->RtNumInPipes = 0;
 73         pdvobjpriv->RtNumOutPipes = 0;
 74 
 75         phost_conf = pusbd->actconfig;
 76         pconf_desc = &phost_conf->desc;
 77 
 78         phost_iface = &usb_intf->altsetting[0];
 79         piface_desc = &phost_iface->desc;
 80 
 81         pdvobjpriv->NumInterfaces = pconf_desc->bNumInterfaces;
 82         pdvobjpriv->InterfaceNumber = piface_desc->bInterfaceNumber;
 83 
 84         for (i = 0; i < piface_desc->bNumEndpoints; i++) {
 85                 int ep_num;
 86                 pendp_desc = &phost_iface->endpoint[i].desc;
 87 
 88                 ep_num = usb_endpoint_num(pendp_desc);
 89 
 90                 if (usb_endpoint_is_bulk_in(pendp_desc)) {
 91                         pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = ep_num;
 92                         pdvobjpriv->RtNumInPipes++;
 93                 } else if (usb_endpoint_is_int_in(pendp_desc)) {
 94                         pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = ep_num;
 95                         pdvobjpriv->RtNumInPipes++;
 96                 } else if (usb_endpoint_is_bulk_out(pendp_desc)) {
 97                         pdvobjpriv->RtOutPipe[pdvobjpriv->RtNumOutPipes] =
 98                                 ep_num;
 99                         pdvobjpriv->RtNumOutPipes++;
100                 }
101         }
102 
103         if (pusbd->speed == USB_SPEED_HIGH)
104                 pdvobjpriv->ishighspeed = true;
105         else
106                 pdvobjpriv->ishighspeed = false;
107 
108         mutex_init(&pdvobjpriv->usb_vendor_req_mutex);
109         usb_get_dev(pusbd);
110 
111         return pdvobjpriv;
112 }
113 
114 static void usb_dvobj_deinit(struct usb_interface *usb_intf)
115 {
116         struct dvobj_priv *dvobj = usb_get_intfdata(usb_intf);
117 
118         usb_set_intfdata(usb_intf, NULL);
119         if (dvobj) {
120                 /* Modify condition for 92DU DMDP 2010.11.18, by Thomas */
121                 if ((dvobj->NumInterfaces != 2 &&
122                     dvobj->NumInterfaces != 3) ||
123                     (dvobj->InterfaceNumber == 1)) {
124                         if (interface_to_usbdev(usb_intf)->state !=
125                             USB_STATE_NOTATTACHED) {
126                                 /* If we didn't unplug usb dongle and
127                                  * remove/insert module, driver fails
128                                  * on sitesurvey for the first time when
129                                  * device is up . Reset usb port for sitesurvey
130                                  * fail issue. */
131                                 pr_debug("usb attached..., try to reset usb device\n");
132                                 usb_reset_device(interface_to_usbdev(usb_intf));
133                         }
134                 }
135 
136                 mutex_destroy(&dvobj->usb_vendor_req_mutex);
137                 kfree(dvobj);
138         }
139 
140         usb_put_dev(interface_to_usbdev(usb_intf));
141 
142 }
143 
144 static void usb_intf_start(struct adapter *padapter)
145 {
146         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+usb_intf_start\n"));
147 
148         rtw_hal_inirp_init(padapter);
149 
150         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-usb_intf_start\n"));
151 }
152 
153 static void usb_intf_stop(struct adapter *padapter)
154 {
155         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+usb_intf_stop\n"));
156 
157         /* disable_hw_interrupt */
158         if (!padapter->bSurpriseRemoved) {
159                 /* device still exists, so driver can do i/o operation */
160                 /* TODO: */
161                 RT_TRACE(_module_hci_intfs_c_, _drv_err_,
162                          ("SurpriseRemoved == false\n"));
163         }
164 
165         /* cancel in irp */
166         rtw_hal_inirp_deinit(padapter);
167 
168         /* cancel out irp */
169         usb_write_port_cancel(padapter);
170 
171         /* todo:cancel other irps */
172 
173         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-usb_intf_stop\n"));
174 }
175 
176 static void rtw_dev_unload(struct adapter *padapter)
177 {
178         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_dev_unload\n"));
179 
180         if (padapter->bup) {
181                 pr_debug("===> rtw_dev_unload\n");
182                 padapter->bDriverStopped = true;
183                 if (padapter->xmitpriv.ack_tx)
184                         rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP);
185                 /* s3. */
186                 if (padapter->intf_stop)
187                         padapter->intf_stop(padapter);
188                 /* s4. */
189                 if (!padapter->pwrctrlpriv.bInternalAutoSuspend)
190                         rtw_stop_drv_threads(padapter);
191 
192                 /* s5. */
193                 if (!padapter->bSurpriseRemoved) {
194                         rtw_hal_deinit(padapter);
195                         padapter->bSurpriseRemoved = true;
196                 }
197 
198                 padapter->bup = false;
199         } else {
200                 RT_TRACE(_module_hci_intfs_c_, _drv_err_,
201                          ("r871x_dev_unload():padapter->bup == false\n"));
202         }
203 
204         pr_debug("<=== rtw_dev_unload\n");
205 
206         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-rtw_dev_unload\n"));
207 }
208 
209 static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
210 {
211         struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
212         struct adapter *padapter = dvobj->if1;
213         struct net_device *pnetdev = padapter->pnetdev;
214         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
215         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
216         unsigned long start_time = jiffies;
217 
218         pr_debug("==> %s (%s:%d)\n", __func__, current->comm, current->pid);
219 
220         if ((!padapter->bup) || (padapter->bDriverStopped) ||
221             (padapter->bSurpriseRemoved)) {
222                 pr_debug("padapter->bup=%d bDriverStopped=%d bSurpriseRemoved = %d\n",
223                         padapter->bup, padapter->bDriverStopped,
224                         padapter->bSurpriseRemoved);
225                 goto exit;
226         }
227 
228         pwrpriv->bInSuspend = true;
229         rtw_cancel_all_timer(padapter);
230         LeaveAllPowerSaveMode(padapter);
231 
232         mutex_lock(&pwrpriv->mutex_lock);
233         /* s1. */
234         if (pnetdev) {
235                 netif_carrier_off(pnetdev);
236                 netif_tx_stop_all_queues(pnetdev);
237         }
238 
239         /* s2. */
240         rtw_disassoc_cmd(padapter, 0, false);
241 
242         if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) &&
243             check_fwstate(pmlmepriv, _FW_LINKED)) {
244                 pr_debug("%s:%d %s(%pM), length:%d assoc_ssid.length:%d\n",
245                         __func__, __LINE__,
246                         pmlmepriv->cur_network.network.Ssid.Ssid,
247                         pmlmepriv->cur_network.network.MacAddress,
248                         pmlmepriv->cur_network.network.Ssid.SsidLength,
249                         pmlmepriv->assoc_ssid.SsidLength);
250 
251                 pmlmepriv->to_roaming = 1;
252         }
253         /* s2-2.  indicate disconnect to os */
254         rtw_indicate_disconnect(padapter);
255         /* s2-3. */
256         rtw_free_assoc_resources(padapter);
257         /* s2-4. */
258         rtw_free_network_queue(padapter, true);
259 
260         rtw_dev_unload(padapter);
261         mutex_unlock(&pwrpriv->mutex_lock);
262 
263         if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
264                 rtw_indicate_scan_done(padapter, 1);
265 
266         if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
267                 rtw_indicate_disconnect(padapter);
268 
269 exit:
270         pr_debug("<===  %s .............. in %dms\n", __func__,
271                  jiffies_to_msecs(jiffies - start_time));
272 
273         return 0;
274 }
275 
276 static int rtw_resume_process(struct adapter *padapter)
277 {
278         struct net_device *pnetdev;
279         struct pwrctrl_priv *pwrpriv = NULL;
280         int ret = -1;
281         unsigned long start_time = jiffies;
282 
283         pr_debug("==> %s (%s:%d)\n", __func__, current->comm, current->pid);
284 
285         if (padapter) {
286                 pnetdev = padapter->pnetdev;
287                 pwrpriv = &padapter->pwrctrlpriv;
288         } else {
289                 goto exit;
290         }
291 
292         mutex_lock(&pwrpriv->mutex_lock);
293         rtw_reset_drv_sw(padapter);
294         pwrpriv->bkeepfwalive = false;
295 
296         pr_debug("bkeepfwalive(%x)\n", pwrpriv->bkeepfwalive);
297         if (pm_netdev_open(pnetdev, true) != 0) {
298                 mutex_unlock(&pwrpriv->mutex_lock);
299                 goto exit;
300         }
301 
302         netif_device_attach(pnetdev);
303         netif_carrier_on(pnetdev);
304 
305         mutex_unlock(&pwrpriv->mutex_lock);
306 
307         rtw_roaming(padapter, NULL);
308 
309         ret = 0;
310 exit:
311         if (pwrpriv)
312                 pwrpriv->bInSuspend = false;
313         pr_debug("<===  %s return %d.............. in %dms\n", __func__,
314                 ret, jiffies_to_msecs(jiffies - start_time));
315 
316         return ret;
317 }
318 
319 static int rtw_resume(struct usb_interface *pusb_intf)
320 {
321         struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
322         struct adapter *padapter = dvobj->if1;
323 
324         return rtw_resume_process(padapter);
325 }
326 
327 /*
328  * drv_init() - a device potentially for us
329  *
330  * notes: drv_init() is called when the bus driver has located
331  * a card for us to support.
332  *        We accept the new device by returning 0.
333  */
334 
335 static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
336         struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
337 {
338         struct adapter *padapter = NULL;
339         struct net_device *pnetdev = NULL;
340         struct net_device *pmondev;
341         int status = _FAIL;
342 
343         padapter = (struct adapter *)vzalloc(sizeof(*padapter));
344         if (padapter == NULL)
345                 goto exit;
346         padapter->dvobj = dvobj;
347         dvobj->if1 = padapter;
348 
349         padapter->bDriverStopped = true;
350         mutex_init(&padapter->hw_init_mutex);
351 
352         pnetdev = rtw_init_netdev(padapter);
353         if (pnetdev == NULL)
354                 goto free_adapter;
355         SET_NETDEV_DEV(pnetdev, dvobj_to_dev(dvobj));
356         padapter = rtw_netdev_priv(pnetdev);
357 
358         if (padapter->registrypriv.monitor_enable) {
359                 pmondev = rtl88eu_mon_init();
360                 if (pmondev == NULL)
361                         netdev_warn(pnetdev, "Failed to initialize monitor interface");
362                 padapter->pmondev = pmondev;
363         }
364 
365         padapter->HalData = kzalloc(sizeof(struct hal_data_8188e), GFP_KERNEL);
366         if (!padapter->HalData)
367                 DBG_88E("cant not alloc memory for HAL DATA\n");
368 
369         padapter->intf_start = &usb_intf_start;
370         padapter->intf_stop = &usb_intf_stop;
371 
372         /* step read_chip_version */
373         rtw_hal_read_chip_version(padapter);
374 
375         /* step usb endpoint mapping */
376         rtw_hal_chip_configure(padapter);
377 
378         /* step read efuse/eeprom data and get mac_addr */
379         rtw_hal_read_chip_info(padapter);
380 
381         /* step 5. */
382         if (rtw_init_drv_sw(padapter) == _FAIL) {
383                 RT_TRACE(_module_hci_intfs_c_, _drv_err_,
384                          ("Initialize driver software resource Failed!\n"));
385                 goto free_hal_data;
386         }
387 
388 #ifdef CONFIG_PM
389         if (padapter->pwrctrlpriv.bSupportRemoteWakeup) {
390                 dvobj->pusbdev->do_remote_wakeup = 1;
391                 pusb_intf->needs_remote_wakeup = 1;
392                 device_init_wakeup(&pusb_intf->dev, 1);
393                 pr_debug("\n  padapter->pwrctrlpriv.bSupportRemoteWakeup~~~~~~\n");
394                 pr_debug("\n  padapter->pwrctrlpriv.bSupportRemoteWakeup~~~[%d]~~~\n",
395                         device_may_wakeup(&pusb_intf->dev));
396         }
397 #endif
398 
399         /* 2012-07-11 Move here to prevent the 8723AS-VAU BT auto
400          * suspend influence */
401         if (usb_autopm_get_interface(pusb_intf) < 0)
402                         pr_debug("can't get autopm:\n");
403 
404         /*  alloc dev name after read efuse. */
405         rtw_init_netdev_name(pnetdev, padapter->registrypriv.ifname);
406         rtw_macaddr_cfg(padapter->eeprompriv.mac_addr);
407         memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
408         pr_debug("MAC Address from pnetdev->dev_addr =  %pM\n",
409                 pnetdev->dev_addr);
410 
411         /* step 6. Tell the network stack we exist */
412         if (register_netdev(pnetdev) != 0) {
413                 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("register_netdev() failed\n"));
414                 goto free_hal_data;
415         }
416 
417         pr_debug("bDriverStopped:%d, bSurpriseRemoved:%d, bup:%d, hw_init_completed:%d\n"
418                 , padapter->bDriverStopped
419                 , padapter->bSurpriseRemoved
420                 , padapter->bup
421                 , padapter->hw_init_completed
422         );
423 
424         status = _SUCCESS;
425 
426 free_hal_data:
427         if (status != _SUCCESS)
428                 kfree(padapter->HalData);
429 free_adapter:
430         if (status != _SUCCESS) {
431                 if (pnetdev)
432                         rtw_free_netdev(pnetdev);
433                 else
434                         vfree(padapter);
435                 padapter = NULL;
436         }
437 exit:
438         return padapter;
439 }
440 
441 static void rtw_usb_if1_deinit(struct adapter *if1)
442 {
443         struct net_device *pnetdev = if1->pnetdev;
444         struct mlme_priv *pmlmepriv = &if1->mlmepriv;
445 
446         if (check_fwstate(pmlmepriv, _FW_LINKED))
447                 rtw_disassoc_cmd(if1, 0, false);
448 
449 #ifdef CONFIG_88EU_AP_MODE
450         free_mlme_ap_info(if1);
451 #endif
452 
453         if (pnetdev)
454                 unregister_netdev(pnetdev); /* will call netdev_close() */
455 
456         rtl88eu_mon_deinit(if1->pmondev);
457         rtw_cancel_all_timer(if1);
458 
459         rtw_dev_unload(if1);
460         pr_debug("+r871xu_dev_remove, hw_init_completed=%d\n",
461                 if1->hw_init_completed);
462         rtw_free_drv_sw(if1);
463         rtw_free_netdev(pnetdev);
464 }
465 
466 static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
467 {
468         struct adapter *if1 = NULL;
469         struct dvobj_priv *dvobj;
470 
471         /* Initialize dvobj_priv */
472         dvobj = usb_dvobj_init(pusb_intf);
473         if (!dvobj) {
474                 RT_TRACE(_module_hci_intfs_c_, _drv_err_,
475                          ("initialize device object priv Failed!\n"));
476                 goto exit;
477         }
478 
479         if1 = rtw_usb_if1_init(dvobj, pusb_intf, pdid);
480         if (!if1) {
481                 pr_debug("rtw_init_primarystruct adapter Failed!\n");
482                 goto free_dvobj;
483         }
484 
485         return 0;
486 
487 free_dvobj:
488         usb_dvobj_deinit(pusb_intf);
489 exit:
490         return -ENODEV;
491 }
492 
493 /*
494  * dev_remove() - our device is being removed
495 */
496 /* rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove() => how to recognize both */
497 static void rtw_dev_remove(struct usb_interface *pusb_intf)
498 {
499         struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
500         struct adapter *padapter = dvobj->if1;
501 
502         pr_debug("+rtw_dev_remove\n");
503         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+dev_remove()\n"));
504 
505         if (!pusb_intf->unregistering)
506                 padapter->bSurpriseRemoved = true;
507 
508         rtw_pm_set_ips(padapter, IPS_NONE);
509         rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
510 
511         LeaveAllPowerSaveMode(padapter);
512 
513         rtw_usb_if1_deinit(padapter);
514 
515         usb_dvobj_deinit(pusb_intf);
516 
517         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-dev_remove()\n"));
518         pr_debug("-r871xu_dev_remove, done\n");
519 }
520 
521 static struct usb_driver rtl8188e_usb_drv = {
522         .name = "r8188eu",
523         .probe = rtw_drv_init,
524         .disconnect = rtw_dev_remove,
525         .id_table = rtw_usb_id_tbl,
526         .suspend =  rtw_suspend,
527         .resume = rtw_resume,
528         .reset_resume = rtw_resume,
529 };
530 
531 module_usb_driver(rtl8188e_usb_drv)
532 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us