Version:  2.0.40 2.2.26 2.4.37 3.1 3.2 3.3 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

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

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