Version:  2.0.40 2.2.26 2.4.37 3.11 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

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

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