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

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

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