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

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 void usb_intf_stop(struct adapter *padapter)
145 {
146         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+usb_intf_stop\n"));
147 
148         /* disable_hw_interrupt */
149         if (!padapter->bSurpriseRemoved) {
150                 /* device still exists, so driver can do i/o operation */
151                 /* TODO: */
152                 RT_TRACE(_module_hci_intfs_c_, _drv_err_,
153                          ("SurpriseRemoved == false\n"));
154         }
155 
156         /* cancel in irp */
157         rtw_hal_inirp_deinit(padapter);
158 
159         /* cancel out irp */
160         usb_write_port_cancel(padapter);
161 
162         /* todo:cancel other irps */
163 
164         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-usb_intf_stop\n"));
165 }
166 
167 static void rtw_dev_unload(struct adapter *padapter)
168 {
169         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_dev_unload\n"));
170 
171         if (padapter->bup) {
172                 pr_debug("===> rtw_dev_unload\n");
173                 padapter->bDriverStopped = true;
174                 if (padapter->xmitpriv.ack_tx)
175                         rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP);
176                 /* s3. */
177                 usb_intf_stop(padapter);
178                 /* s4. */
179                 if (!padapter->pwrctrlpriv.bInternalAutoSuspend)
180                         rtw_stop_drv_threads(padapter);
181 
182                 /* s5. */
183                 if (!padapter->bSurpriseRemoved) {
184                         rtw_hal_deinit(padapter);
185                         padapter->bSurpriseRemoved = true;
186                 }
187 
188                 padapter->bup = false;
189         } else {
190                 RT_TRACE(_module_hci_intfs_c_, _drv_err_,
191                          ("r871x_dev_unload():padapter->bup == false\n"));
192         }
193 
194         pr_debug("<=== rtw_dev_unload\n");
195 
196         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-rtw_dev_unload\n"));
197 }
198 
199 static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
200 {
201         struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
202         struct adapter *padapter = dvobj->if1;
203         struct net_device *pnetdev = padapter->pnetdev;
204         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
205         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
206         unsigned long start_time = jiffies;
207 
208         pr_debug("==> %s (%s:%d)\n", __func__, current->comm, current->pid);
209 
210         if ((!padapter->bup) || (padapter->bDriverStopped) ||
211             (padapter->bSurpriseRemoved)) {
212                 pr_debug("padapter->bup=%d bDriverStopped=%d bSurpriseRemoved = %d\n",
213                         padapter->bup, padapter->bDriverStopped,
214                         padapter->bSurpriseRemoved);
215                 goto exit;
216         }
217 
218         pwrpriv->bInSuspend = true;
219         rtw_cancel_all_timer(padapter);
220         LeaveAllPowerSaveMode(padapter);
221 
222         mutex_lock(&pwrpriv->mutex_lock);
223         /* s1. */
224         if (pnetdev) {
225                 netif_carrier_off(pnetdev);
226                 netif_tx_stop_all_queues(pnetdev);
227         }
228 
229         /* s2. */
230         rtw_disassoc_cmd(padapter, 0, false);
231 
232         if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) &&
233             check_fwstate(pmlmepriv, _FW_LINKED)) {
234                 pr_debug("%s:%d %s(%pM), length:%d assoc_ssid.length:%d\n",
235                         __func__, __LINE__,
236                         pmlmepriv->cur_network.network.Ssid.Ssid,
237                         pmlmepriv->cur_network.network.MacAddress,
238                         pmlmepriv->cur_network.network.Ssid.SsidLength,
239                         pmlmepriv->assoc_ssid.SsidLength);
240 
241                 pmlmepriv->to_roaming = 1;
242         }
243         /* s2-2.  indicate disconnect to os */
244         rtw_indicate_disconnect(padapter);
245         /* s2-3. */
246         rtw_free_assoc_resources(padapter);
247         /* s2-4. */
248         rtw_free_network_queue(padapter, true);
249 
250         rtw_dev_unload(padapter);
251         mutex_unlock(&pwrpriv->mutex_lock);
252 
253         if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
254                 rtw_indicate_scan_done(padapter, 1);
255 
256         if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
257                 rtw_indicate_disconnect(padapter);
258 
259 exit:
260         pr_debug("<===  %s .............. in %dms\n", __func__,
261                  jiffies_to_msecs(jiffies - start_time));
262 
263         return 0;
264 }
265 
266 static int rtw_resume_process(struct adapter *padapter)
267 {
268         struct net_device *pnetdev;
269         struct pwrctrl_priv *pwrpriv = NULL;
270         int ret = -1;
271         unsigned long start_time = jiffies;
272 
273         pr_debug("==> %s (%s:%d)\n", __func__, current->comm, current->pid);
274 
275         if (padapter) {
276                 pnetdev = padapter->pnetdev;
277                 pwrpriv = &padapter->pwrctrlpriv;
278         } else {
279                 goto exit;
280         }
281 
282         mutex_lock(&pwrpriv->mutex_lock);
283         rtw_reset_drv_sw(padapter);
284         pwrpriv->bkeepfwalive = false;
285 
286         pr_debug("bkeepfwalive(%x)\n", pwrpriv->bkeepfwalive);
287         if (netdev_open(pnetdev) != 0) {
288                 mutex_unlock(&pwrpriv->mutex_lock);
289                 goto exit;
290         }
291 
292         netif_device_attach(pnetdev);
293         netif_carrier_on(pnetdev);
294 
295         mutex_unlock(&pwrpriv->mutex_lock);
296 
297         rtw_roaming(padapter, NULL);
298 
299         ret = 0;
300 exit:
301         if (pwrpriv)
302                 pwrpriv->bInSuspend = false;
303         pr_debug("<===  %s return %d.............. in %dms\n", __func__,
304                 ret, jiffies_to_msecs(jiffies - start_time));
305 
306         return ret;
307 }
308 
309 static int rtw_resume(struct usb_interface *pusb_intf)
310 {
311         struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
312         struct adapter *padapter = dvobj->if1;
313 
314         return rtw_resume_process(padapter);
315 }
316 
317 /*
318  * drv_init() - a device potentially for us
319  *
320  * notes: drv_init() is called when the bus driver has located
321  * a card for us to support.
322  *        We accept the new device by returning 0.
323  */
324 
325 static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
326         struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
327 {
328         struct adapter *padapter = NULL;
329         struct net_device *pnetdev = NULL;
330         struct net_device *pmondev;
331         int status = _FAIL;
332 
333         padapter = (struct adapter *)vzalloc(sizeof(*padapter));
334         if (padapter == NULL)
335                 goto exit;
336         padapter->dvobj = dvobj;
337         dvobj->if1 = padapter;
338 
339         padapter->bDriverStopped = true;
340         mutex_init(&padapter->hw_init_mutex);
341 
342         pnetdev = rtw_init_netdev(padapter);
343         if (pnetdev == NULL)
344                 goto free_adapter;
345         SET_NETDEV_DEV(pnetdev, dvobj_to_dev(dvobj));
346         padapter = rtw_netdev_priv(pnetdev);
347 
348         if (padapter->registrypriv.monitor_enable) {
349                 pmondev = rtl88eu_mon_init();
350                 if (pmondev == NULL)
351                         netdev_warn(pnetdev, "Failed to initialize monitor interface");
352                 padapter->pmondev = pmondev;
353         }
354 
355         padapter->HalData = kzalloc(sizeof(struct hal_data_8188e), GFP_KERNEL);
356         if (!padapter->HalData)
357                 DBG_88E("cant not alloc memory for HAL DATA\n");
358 
359         /* step read_chip_version */
360         rtw_hal_read_chip_version(padapter);
361 
362         /* step usb endpoint mapping */
363         rtw_hal_chip_configure(padapter);
364 
365         /* step read efuse/eeprom data and get mac_addr */
366         rtw_hal_read_chip_info(padapter);
367 
368         /* step 5. */
369         if (rtw_init_drv_sw(padapter) == _FAIL) {
370                 RT_TRACE(_module_hci_intfs_c_, _drv_err_,
371                          ("Initialize driver software resource Failed!\n"));
372                 goto free_hal_data;
373         }
374 
375 #ifdef CONFIG_PM
376         if (padapter->pwrctrlpriv.bSupportRemoteWakeup) {
377                 dvobj->pusbdev->do_remote_wakeup = 1;
378                 pusb_intf->needs_remote_wakeup = 1;
379                 device_init_wakeup(&pusb_intf->dev, 1);
380                 pr_debug("\n  padapter->pwrctrlpriv.bSupportRemoteWakeup~~~~~~\n");
381                 pr_debug("\n  padapter->pwrctrlpriv.bSupportRemoteWakeup~~~[%d]~~~\n",
382                         device_may_wakeup(&pusb_intf->dev));
383         }
384 #endif
385 
386         /* 2012-07-11 Move here to prevent the 8723AS-VAU BT auto
387          * suspend influence */
388         if (usb_autopm_get_interface(pusb_intf) < 0)
389                         pr_debug("can't get autopm:\n");
390 
391         /*  alloc dev name after read efuse. */
392         rtw_init_netdev_name(pnetdev, padapter->registrypriv.ifname);
393         rtw_macaddr_cfg(padapter->eeprompriv.mac_addr);
394         memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
395         pr_debug("MAC Address from pnetdev->dev_addr =  %pM\n",
396                 pnetdev->dev_addr);
397 
398         /* step 6. Tell the network stack we exist */
399         if (register_netdev(pnetdev) != 0) {
400                 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("register_netdev() failed\n"));
401                 goto free_hal_data;
402         }
403 
404         pr_debug("bDriverStopped:%d, bSurpriseRemoved:%d, bup:%d, hw_init_completed:%d\n"
405                 , padapter->bDriverStopped
406                 , padapter->bSurpriseRemoved
407                 , padapter->bup
408                 , padapter->hw_init_completed
409         );
410 
411         status = _SUCCESS;
412 
413 free_hal_data:
414         if (status != _SUCCESS)
415                 kfree(padapter->HalData);
416 free_adapter:
417         if (status != _SUCCESS) {
418                 if (pnetdev)
419                         rtw_free_netdev(pnetdev);
420                 else
421                         vfree(padapter);
422                 padapter = NULL;
423         }
424 exit:
425         return padapter;
426 }
427 
428 static void rtw_usb_if1_deinit(struct adapter *if1)
429 {
430         struct net_device *pnetdev = if1->pnetdev;
431         struct mlme_priv *pmlmepriv = &if1->mlmepriv;
432 
433         if (check_fwstate(pmlmepriv, _FW_LINKED))
434                 rtw_disassoc_cmd(if1, 0, false);
435 
436 #ifdef CONFIG_88EU_AP_MODE
437         free_mlme_ap_info(if1);
438 #endif
439 
440         if (pnetdev)
441                 unregister_netdev(pnetdev); /* will call netdev_close() */
442 
443         rtl88eu_mon_deinit(if1->pmondev);
444         rtw_cancel_all_timer(if1);
445 
446         rtw_dev_unload(if1);
447         pr_debug("+r871xu_dev_remove, hw_init_completed=%d\n",
448                 if1->hw_init_completed);
449         rtw_free_drv_sw(if1);
450         rtw_free_netdev(pnetdev);
451 }
452 
453 static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
454 {
455         struct adapter *if1 = NULL;
456         struct dvobj_priv *dvobj;
457 
458         /* Initialize dvobj_priv */
459         dvobj = usb_dvobj_init(pusb_intf);
460         if (!dvobj) {
461                 RT_TRACE(_module_hci_intfs_c_, _drv_err_,
462                          ("initialize device object priv Failed!\n"));
463                 goto exit;
464         }
465 
466         if1 = rtw_usb_if1_init(dvobj, pusb_intf, pdid);
467         if (!if1) {
468                 pr_debug("rtw_init_primarystruct adapter Failed!\n");
469                 goto free_dvobj;
470         }
471 
472         return 0;
473 
474 free_dvobj:
475         usb_dvobj_deinit(pusb_intf);
476 exit:
477         return -ENODEV;
478 }
479 
480 /*
481  * dev_remove() - our device is being removed
482 */
483 /* rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove() => how to recognize both */
484 static void rtw_dev_remove(struct usb_interface *pusb_intf)
485 {
486         struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
487         struct adapter *padapter = dvobj->if1;
488 
489         pr_debug("+rtw_dev_remove\n");
490         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+dev_remove()\n"));
491 
492         if (!pusb_intf->unregistering)
493                 padapter->bSurpriseRemoved = true;
494 
495         rtw_pm_set_ips(padapter, IPS_NONE);
496         rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
497 
498         LeaveAllPowerSaveMode(padapter);
499 
500         rtw_usb_if1_deinit(padapter);
501 
502         usb_dvobj_deinit(pusb_intf);
503 
504         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-dev_remove()\n"));
505         pr_debug("-r871xu_dev_remove, done\n");
506 }
507 
508 static struct usb_driver rtl8188e_usb_drv = {
509         .name = "r8188eu",
510         .probe = rtw_drv_init,
511         .disconnect = rtw_dev_remove,
512         .id_table = rtw_usb_id_tbl,
513         .suspend =  rtw_suspend,
514         .resume = rtw_resume,
515         .reset_resume = rtw_resume,
516 };
517 
518 module_usb_driver(rtl8188e_usb_drv)
519 

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