Version:  2.0.40 2.2.26 2.4.37 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1 4.2

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

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