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

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 <rtw_version.h>
 28 #include <linux/usb.h>
 29 #include <linux/vmalloc.h>
 30 #include <osdep_intf.h>
 31 
 32 #include <usb_vendor_req.h>
 33 #include <usb_ops.h>
 34 #include <usb_osintf.h>
 35 #include <usb_hal.h>
 36 #include <rtw_ioctl.h>
 37 
 38 int ui_pid[3] = {0, 0, 0};
 39 
 40 static int rtw_suspend(struct usb_interface *intf, pm_message_t message);
 41 static int rtw_resume(struct usb_interface *intf);
 42 
 43 
 44 static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid);
 45 static void rtw_dev_remove(struct usb_interface *pusb_intf);
 46 
 47 
 48 #define USB_VENDER_ID_REALTEK           0x0bda
 49 
 50 /* DID_USB_v916_20130116 */
 51 static struct usb_device_id rtw_usb_id_tbl[] = {
 52         /*=== Realtek demoboard ===*/
 53         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8179)}, /* 8188EUS */
 54         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0179)}, /* 8188ETV */
 55         /*=== Customer ID ===*/
 56         /****** 8188EUS ********/
 57         {USB_DEVICE(0x07b8, 0x8179)}, /* Abocom - Abocom */
 58         {USB_DEVICE(0x2001, 0x330F)}, /* DLink DWA-125 REV D1 */
 59         {USB_DEVICE(0x2001, 0x3310)}, /* Dlink DWA-123 REV D1 */
 60         {}      /* Terminating entry */
 61 };
 62 
 63 MODULE_DEVICE_TABLE(usb, rtw_usb_id_tbl);
 64 
 65 struct rtw_usb_drv {
 66         struct usb_driver usbdrv;
 67         int drv_registered;
 68         struct mutex hw_init_mutex;
 69 };
 70 
 71 static struct rtw_usb_drv rtl8188e_usb_drv = {
 72         .usbdrv.name = "r8188eu",
 73         .usbdrv.probe = rtw_drv_init,
 74         .usbdrv.disconnect = rtw_dev_remove,
 75         .usbdrv.id_table = rtw_usb_id_tbl,
 76         .usbdrv.suspend =  rtw_suspend,
 77         .usbdrv.resume = rtw_resume,
 78         .usbdrv.reset_resume   = rtw_resume,
 79 };
 80 
 81 static struct rtw_usb_drv *usb_drv = &rtl8188e_usb_drv;
 82 
 83 static u8 rtw_init_intf_priv(struct dvobj_priv *dvobj)
 84 {
 85         u8 rst = _SUCCESS;
 86 
 87         mutex_init(&dvobj->usb_vendor_req_mutex);
 88 
 89         dvobj->usb_alloc_vendor_req_buf = rtw_zmalloc(MAX_USB_IO_CTL_SIZE);
 90         if (dvobj->usb_alloc_vendor_req_buf == NULL) {
 91                 DBG_88E("alloc usb_vendor_req_buf failed...\n");
 92                 rst = _FAIL;
 93                 goto exit;
 94         }
 95         dvobj->usb_vendor_req_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(dvobj->usb_alloc_vendor_req_buf), ALIGNMENT_UNIT);
 96 exit:
 97         return rst;
 98 }
 99 
100 static u8 rtw_deinit_intf_priv(struct dvobj_priv *dvobj)
101 {
102         u8 rst = _SUCCESS;
103 
104         kfree(dvobj->usb_alloc_vendor_req_buf);
105         mutex_destroy(&dvobj->usb_vendor_req_mutex);
106         return rst;
107 }
108 
109 static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf)
110 {
111         int     i;
112         int     status = _FAIL;
113         struct dvobj_priv *pdvobjpriv;
114         struct usb_host_config          *phost_conf;
115         struct usb_config_descriptor    *pconf_desc;
116         struct usb_host_interface       *phost_iface;
117         struct usb_interface_descriptor *piface_desc;
118         struct usb_host_endpoint        *phost_endp;
119         struct usb_endpoint_descriptor  *pendp_desc;
120         struct usb_device       *pusbd;
121 
122 
123         pdvobjpriv = (struct dvobj_priv *)rtw_zmalloc(sizeof(*pdvobjpriv));
124         if (pdvobjpriv == NULL)
125                 goto exit;
126 
127         pdvobjpriv->pusbintf = usb_intf;
128         pusbd = interface_to_usbdev(usb_intf);
129         pdvobjpriv->pusbdev = pusbd;
130         usb_set_intfdata(usb_intf, pdvobjpriv);
131 
132         pdvobjpriv->RtNumInPipes = 0;
133         pdvobjpriv->RtNumOutPipes = 0;
134 
135         phost_conf = pusbd->actconfig;
136         pconf_desc = &phost_conf->desc;
137 
138         phost_iface = &usb_intf->altsetting[0];
139         piface_desc = &phost_iface->desc;
140 
141         pdvobjpriv->NumInterfaces = pconf_desc->bNumInterfaces;
142         pdvobjpriv->InterfaceNumber = piface_desc->bInterfaceNumber;
143         pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
144 
145         for (i = 0; i < pdvobjpriv->nr_endpoint; i++) {
146                 int ep_num;
147                 phost_endp = phost_iface->endpoint + i;
148 
149                 if (phost_endp) {
150                         pendp_desc = &phost_endp->desc;
151                         ep_num = usb_endpoint_num(pendp_desc);
152 
153                         if (usb_endpoint_is_bulk_in(pendp_desc)) {
154                                 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = ep_num;
155                                 pdvobjpriv->RtNumInPipes++;
156                         } else if (usb_endpoint_is_int_in(pendp_desc)) {
157                                 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = ep_num;
158                                 pdvobjpriv->RtNumInPipes++;
159                         } else if (usb_endpoint_is_bulk_out(pendp_desc)) {
160                                 pdvobjpriv->RtOutPipe[pdvobjpriv->RtNumOutPipes] = ep_num;
161                                 pdvobjpriv->RtNumOutPipes++;
162                         }
163                         pdvobjpriv->ep_num[i] = ep_num;
164                 }
165         }
166 
167         if (pusbd->speed == USB_SPEED_HIGH)
168                 pdvobjpriv->ishighspeed = true;
169         else
170                 pdvobjpriv->ishighspeed = false;
171 
172         if (rtw_init_intf_priv(pdvobjpriv) == _FAIL)
173                 goto free_dvobj;
174 
175         sema_init(&(pdvobjpriv->usb_suspend_sema), 0);
176         rtw_reset_continual_urb_error(pdvobjpriv);
177 
178         usb_get_dev(pusbd);
179 
180         status = _SUCCESS;
181 
182 free_dvobj:
183         if (status != _SUCCESS && pdvobjpriv) {
184                 usb_set_intfdata(usb_intf, NULL);
185                 kfree(pdvobjpriv);
186                 pdvobjpriv = NULL;
187         }
188 exit:
189         return pdvobjpriv;
190 }
191 
192 static void usb_dvobj_deinit(struct usb_interface *usb_intf)
193 {
194         struct dvobj_priv *dvobj = usb_get_intfdata(usb_intf);
195 
196 
197         usb_set_intfdata(usb_intf, NULL);
198         if (dvobj) {
199                 /* Modify condition for 92DU DMDP 2010.11.18, by Thomas */
200                 if ((dvobj->NumInterfaces != 2 &&
201                     dvobj->NumInterfaces != 3) ||
202                     (dvobj->InterfaceNumber == 1)) {
203                         if (interface_to_usbdev(usb_intf)->state !=
204                             USB_STATE_NOTATTACHED) {
205                                 /* If we didn't unplug usb dongle and
206                                  * remove/insert module, driver fails
207                                  * on sitesurvey for the first time when
208                                  * device is up . Reset usb port for sitesurvey
209                                  * fail issue. */
210                                 DBG_88E("usb attached..., try to reset usb device\n");
211                                 usb_reset_device(interface_to_usbdev(usb_intf));
212                         }
213                 }
214                 rtw_deinit_intf_priv(dvobj);
215                 kfree(dvobj);
216         }
217 
218         usb_put_dev(interface_to_usbdev(usb_intf));
219 
220 }
221 
222 static void usb_intf_start(struct adapter *padapter)
223 {
224         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+usb_intf_start\n"));
225 
226         rtw_hal_inirp_init(padapter);
227 
228         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-usb_intf_start\n"));
229 }
230 
231 static void usb_intf_stop(struct adapter *padapter)
232 {
233         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+usb_intf_stop\n"));
234 
235         /* disabel_hw_interrupt */
236         if (!padapter->bSurpriseRemoved) {
237                 /* device still exists, so driver can do i/o operation */
238                 /* TODO: */
239                 RT_TRACE(_module_hci_intfs_c_, _drv_err_,
240                          ("SurpriseRemoved == false\n"));
241         }
242 
243         /* cancel in irp */
244         rtw_hal_inirp_deinit(padapter);
245 
246         /* cancel out irp */
247         rtw_write_port_cancel(padapter);
248 
249         /* todo:cancel other irps */
250 
251         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-usb_intf_stop\n"));
252 }
253 
254 static void rtw_dev_unload(struct adapter *padapter)
255 {
256         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_dev_unload\n"));
257 
258         if (padapter->bup) {
259                 DBG_88E("===> rtw_dev_unload\n");
260                 padapter->bDriverStopped = true;
261                 if (padapter->xmitpriv.ack_tx)
262                         rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP);
263                 /* s3. */
264                 if (padapter->intf_stop)
265                         padapter->intf_stop(padapter);
266                 /* s4. */
267                 if (!padapter->pwrctrlpriv.bInternalAutoSuspend)
268                         rtw_stop_drv_threads(padapter);
269 
270                 /* s5. */
271                 if (!padapter->bSurpriseRemoved) {
272                         rtw_hal_deinit(padapter);
273                         padapter->bSurpriseRemoved = true;
274                 }
275 
276                 padapter->bup = false;
277         } else {
278                 RT_TRACE(_module_hci_intfs_c_, _drv_err_,
279                          ("r871x_dev_unload():padapter->bup == false\n"));
280         }
281 
282         DBG_88E("<=== rtw_dev_unload\n");
283 
284         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-rtw_dev_unload\n"));
285 }
286 
287 int rtw_hw_suspend(struct adapter *padapter)
288 {
289         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
290         struct net_device *pnetdev = padapter->pnetdev;
291 
292 
293         if ((!padapter->bup) || (padapter->bDriverStopped) ||
294             (padapter->bSurpriseRemoved)) {
295                 DBG_88E("padapter->bup=%d bDriverStopped=%d bSurpriseRemoved = %d\n",
296                         padapter->bup, padapter->bDriverStopped,
297                         padapter->bSurpriseRemoved);
298                 goto error_exit;
299         }
300 
301         /* system suspend */
302         LeaveAllPowerSaveMode(padapter);
303 
304         DBG_88E("==> rtw_hw_suspend\n");
305         _enter_pwrlock(&pwrpriv->lock);
306         pwrpriv->bips_processing = true;
307         /* s1. */
308         if (pnetdev) {
309                 netif_carrier_off(pnetdev);
310                 netif_tx_stop_all_queues(pnetdev);
311         }
312 
313         /* s2. */
314         rtw_disassoc_cmd(padapter, 500, false);
315 
316         /* s2-2.  indicate disconnect to os */
317         {
318                 struct  mlme_priv *pmlmepriv = &padapter->mlmepriv;
319 
320                 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
321                         _clr_fwstate_(pmlmepriv, _FW_LINKED);
322 
323                         rtw_led_control(padapter, LED_CTL_NO_LINK);
324 
325                         rtw_os_indicate_disconnect(padapter);
326 
327                         /* donnot enqueue cmd */
328                         rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_DISCONNECT, 0);
329                 }
330         }
331         /* s2-3. */
332         rtw_free_assoc_resources(padapter, 1);
333 
334         /* s2-4. */
335         rtw_free_network_queue(padapter, true);
336         rtw_ips_dev_unload(padapter);
337         pwrpriv->rf_pwrstate = rf_off;
338         pwrpriv->bips_processing = false;
339 
340         _exit_pwrlock(&pwrpriv->lock);
341 
342         return 0;
343 
344 error_exit:
345         DBG_88E("%s, failed\n", __func__);
346         return -1;
347 }
348 
349 int rtw_hw_resume(struct adapter *padapter)
350 {
351         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
352         struct net_device *pnetdev = padapter->pnetdev;
353 
354 
355         /* system resume */
356         DBG_88E("==> rtw_hw_resume\n");
357         _enter_pwrlock(&pwrpriv->lock);
358         pwrpriv->bips_processing = true;
359         rtw_reset_drv_sw(padapter);
360 
361         if (pm_netdev_open(pnetdev, false) != 0) {
362                 _exit_pwrlock(&pwrpriv->lock);
363                 goto error_exit;
364         }
365 
366         netif_device_attach(pnetdev);
367         netif_carrier_on(pnetdev);
368 
369         if (!netif_queue_stopped(pnetdev))
370                 netif_start_queue(pnetdev);
371         else
372                 netif_wake_queue(pnetdev);
373 
374         pwrpriv->bkeepfwalive = false;
375         pwrpriv->brfoffbyhw = false;
376 
377         pwrpriv->rf_pwrstate = rf_on;
378         pwrpriv->bips_processing = false;
379 
380         _exit_pwrlock(&pwrpriv->lock);
381 
382 
383         return 0;
384 error_exit:
385         DBG_88E("%s, Open net dev failed\n", __func__);
386         return -1;
387 }
388 
389 static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
390 {
391         struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
392         struct adapter *padapter = dvobj->if1;
393         struct net_device *pnetdev = padapter->pnetdev;
394         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
395         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
396 
397         int ret = 0;
398         u32 start_time = jiffies;
399 
400 
401         DBG_88E("==> %s (%s:%d)\n", __func__, current->comm, current->pid);
402 
403         if ((!padapter->bup) || (padapter->bDriverStopped) ||
404             (padapter->bSurpriseRemoved)) {
405                 DBG_88E("padapter->bup=%d bDriverStopped=%d bSurpriseRemoved = %d\n",
406                         padapter->bup, padapter->bDriverStopped,
407                         padapter->bSurpriseRemoved);
408                 goto exit;
409         }
410 
411         pwrpriv->bInSuspend = true;
412         rtw_cancel_all_timer(padapter);
413         LeaveAllPowerSaveMode(padapter);
414 
415         _enter_pwrlock(&pwrpriv->lock);
416         /* s1. */
417         if (pnetdev) {
418                 netif_carrier_off(pnetdev);
419                 netif_tx_stop_all_queues(pnetdev);
420         }
421 
422         /* s2. */
423         rtw_disassoc_cmd(padapter, 0, false);
424 
425         if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) &&
426             check_fwstate(pmlmepriv, _FW_LINKED)) {
427                 DBG_88E("%s:%d %s(%pM), length:%d assoc_ssid.length:%d\n",
428                         __func__, __LINE__,
429                         pmlmepriv->cur_network.network.Ssid.Ssid,
430                         pmlmepriv->cur_network.network.MacAddress,
431                         pmlmepriv->cur_network.network.Ssid.SsidLength,
432                         pmlmepriv->assoc_ssid.SsidLength);
433 
434                 pmlmepriv->to_roaming = 1;
435         }
436         /* s2-2.  indicate disconnect to os */
437         rtw_indicate_disconnect(padapter);
438         /* s2-3. */
439         rtw_free_assoc_resources(padapter, 1);
440         /* s2-4. */
441         rtw_free_network_queue(padapter, true);
442 
443         rtw_dev_unload(padapter);
444         _exit_pwrlock(&pwrpriv->lock);
445 
446         if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
447                 rtw_indicate_scan_done(padapter, 1);
448 
449         if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
450                 rtw_indicate_disconnect(padapter);
451 
452 exit:
453         DBG_88E("<===  %s return %d.............. in %dms\n", __func__
454                 , ret, rtw_get_passing_time_ms(start_time));
455 
456         return ret;
457 }
458 
459 static int rtw_resume(struct usb_interface *pusb_intf)
460 {
461         struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
462         struct adapter *padapter = dvobj->if1;
463         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
464          int ret = 0;
465 
466         if (pwrpriv->bInternalAutoSuspend)
467                 ret = rtw_resume_process(padapter);
468         else
469                 ret = rtw_resume_process(padapter);
470         return ret;
471 }
472 
473 int rtw_resume_process(struct adapter *padapter)
474 {
475         struct net_device *pnetdev;
476         struct pwrctrl_priv *pwrpriv = NULL;
477         int ret = -1;
478         u32 start_time = jiffies;
479 
480         DBG_88E("==> %s (%s:%d)\n", __func__, current->comm, current->pid);
481 
482         if (padapter) {
483                 pnetdev = padapter->pnetdev;
484                 pwrpriv = &padapter->pwrctrlpriv;
485         } else {
486                 goto exit;
487         }
488 
489         _enter_pwrlock(&pwrpriv->lock);
490         rtw_reset_drv_sw(padapter);
491         pwrpriv->bkeepfwalive = false;
492 
493         DBG_88E("bkeepfwalive(%x)\n", pwrpriv->bkeepfwalive);
494         if (pm_netdev_open(pnetdev, true) != 0)
495                 goto exit;
496 
497         netif_device_attach(pnetdev);
498         netif_carrier_on(pnetdev);
499 
500         _exit_pwrlock(&pwrpriv->lock);
501 
502         if (padapter->pid[1] != 0) {
503                 DBG_88E("pid[1]:%d\n", padapter->pid[1]);
504                 rtw_signal_process(padapter->pid[1], SIGUSR2);
505         }
506 
507         rtw_roaming(padapter, NULL);
508 
509         ret = 0;
510 exit:
511         if (pwrpriv)
512                 pwrpriv->bInSuspend = false;
513         DBG_88E("<===  %s return %d.............. in %dms\n", __func__,
514                 ret, rtw_get_passing_time_ms(start_time));
515 
516 
517         return ret;
518 }
519 
520 /*
521  * drv_init() - a device potentially for us
522  *
523  * notes: drv_init() is called when the bus driver has located
524  * a card for us to support.
525  *        We accept the new device by returning 0.
526  */
527 
528 static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
529         struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
530 {
531         struct adapter *padapter = NULL;
532         struct net_device *pnetdev = NULL;
533         int status = _FAIL;
534 
535         padapter = (struct adapter *)vzalloc(sizeof(*padapter));
536         if (padapter == NULL)
537                 goto exit;
538         padapter->dvobj = dvobj;
539         dvobj->if1 = padapter;
540 
541         padapter->bDriverStopped = true;
542         padapter->hw_init_mutex = &usb_drv->hw_init_mutex;
543         padapter->chip_type = RTL8188E;
544 
545         pnetdev = rtw_init_netdev(padapter);
546         if (pnetdev == NULL)
547                 goto free_adapter;
548         SET_NETDEV_DEV(pnetdev, dvobj_to_dev(dvobj));
549         padapter = rtw_netdev_priv(pnetdev);
550 
551         /* step 2. hook HalFunc, allocate HalData */
552         hal_set_hal_ops(padapter);
553 
554         padapter->intf_start = &usb_intf_start;
555         padapter->intf_stop = &usb_intf_stop;
556 
557         /* step init_io_priv */
558         rtw_init_io_priv(padapter, usb_set_intf_ops);
559 
560         /* step read_chip_version */
561         rtw_hal_read_chip_version(padapter);
562 
563         /* step usb endpoint mapping */
564         rtw_hal_chip_configure(padapter);
565 
566         /* step read efuse/eeprom data and get mac_addr */
567         rtw_hal_read_chip_info(padapter);
568 
569         /* step 5. */
570         if (rtw_init_drv_sw(padapter) == _FAIL) {
571                 RT_TRACE(_module_hci_intfs_c_, _drv_err_,
572                          ("Initialize driver software resource Failed!\n"));
573                 goto free_hal_data;
574         }
575 
576 #ifdef CONFIG_PM
577         if (padapter->pwrctrlpriv.bSupportRemoteWakeup) {
578                 dvobj->pusbdev->do_remote_wakeup = 1;
579                 pusb_intf->needs_remote_wakeup = 1;
580                 device_init_wakeup(&pusb_intf->dev, 1);
581                 DBG_88E("\n  padapter->pwrctrlpriv.bSupportRemoteWakeup~~~~~~\n");
582                 DBG_88E("\n  padapter->pwrctrlpriv.bSupportRemoteWakeup~~~[%d]~~~\n",
583                         device_may_wakeup(&pusb_intf->dev));
584         }
585 #endif
586 
587         /* 2012-07-11 Move here to prevent the 8723AS-VAU BT auto
588          * suspend influence */
589         if (usb_autopm_get_interface(pusb_intf) < 0)
590                         DBG_88E("can't get autopm:\n");
591 
592         /*  alloc dev name after read efuse. */
593         rtw_init_netdev_name(pnetdev, padapter->registrypriv.ifname);
594         rtw_macaddr_cfg(padapter->eeprompriv.mac_addr);
595 #ifdef CONFIG_88EU_P2P
596         rtw_init_wifidirect_addrs(padapter, padapter->eeprompriv.mac_addr,
597                                   padapter->eeprompriv.mac_addr);
598 #endif
599         memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
600         DBG_88E("MAC Address from pnetdev->dev_addr =  %pM\n",
601                 pnetdev->dev_addr);
602 
603         /* step 6. Tell the network stack we exist */
604         if (register_netdev(pnetdev) != 0) {
605                 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("register_netdev() failed\n"));
606                 goto free_hal_data;
607         }
608 
609         DBG_88E("bDriverStopped:%d, bSurpriseRemoved:%d, bup:%d, hw_init_completed:%d\n"
610                 , padapter->bDriverStopped
611                 , padapter->bSurpriseRemoved
612                 , padapter->bup
613                 , padapter->hw_init_completed
614         );
615 
616         status = _SUCCESS;
617 
618 free_hal_data:
619         if (status != _SUCCESS)
620                 kfree(padapter->HalData);
621 free_adapter:
622         if (status != _SUCCESS) {
623                 if (pnetdev)
624                         rtw_free_netdev(pnetdev);
625                 else if (padapter)
626                         vfree(padapter);
627                 padapter = NULL;
628         }
629 exit:
630         return padapter;
631 }
632 
633 static void rtw_usb_if1_deinit(struct adapter *if1)
634 {
635         struct net_device *pnetdev = if1->pnetdev;
636         struct mlme_priv *pmlmepriv = &if1->mlmepriv;
637 
638         if (check_fwstate(pmlmepriv, _FW_LINKED))
639                 rtw_disassoc_cmd(if1, 0, false);
640 
641 #ifdef CONFIG_88EU_AP_MODE
642         free_mlme_ap_info(if1);
643 #endif
644 
645         if (if1->DriverState != DRIVER_DISAPPEAR) {
646                 if (pnetdev) {
647                         /* will call netdev_close() */
648                         unregister_netdev(pnetdev);
649                         rtw_proc_remove_one(pnetdev);
650                 }
651         }
652         rtw_cancel_all_timer(if1);
653 
654         rtw_dev_unload(if1);
655         DBG_88E("+r871xu_dev_remove, hw_init_completed=%d\n",
656                 if1->hw_init_completed);
657         rtw_free_drv_sw(if1);
658         if (pnetdev)
659                 rtw_free_netdev(pnetdev);
660 }
661 
662 static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
663 {
664         struct adapter *if1 = NULL;
665         int status = _FAIL;
666         struct dvobj_priv *dvobj;
667 
668         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_drv_init\n"));
669 
670         /* Initialize dvobj_priv */
671         dvobj = usb_dvobj_init(pusb_intf);
672         if (dvobj == NULL) {
673                 RT_TRACE(_module_hci_intfs_c_, _drv_err_,
674                          ("initialize device object priv Failed!\n"));
675                 goto exit;
676         }
677 
678         if1 = rtw_usb_if1_init(dvobj, pusb_intf, pdid);
679         if (if1 == NULL) {
680                 DBG_88E("rtw_init_primarystruct adapter Failed!\n");
681                 goto free_dvobj;
682         }
683 
684         if (ui_pid[1] != 0) {
685                 DBG_88E("ui_pid[1]:%d\n", ui_pid[1]);
686                 rtw_signal_process(ui_pid[1], SIGUSR2);
687         }
688 
689         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-871x_drv - drv_init, success!\n"));
690 
691         status = _SUCCESS;
692 
693 free_dvobj:
694         if (status != _SUCCESS)
695                 usb_dvobj_deinit(pusb_intf);
696 exit:
697         return status == _SUCCESS ? 0 : -ENODEV;
698 }
699 
700 /*
701  * dev_remove() - our device is being removed
702 */
703 /* rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove() => how to recognize both */
704 static void rtw_dev_remove(struct usb_interface *pusb_intf)
705 {
706         struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
707         struct adapter *padapter = dvobj->if1;
708 
709 
710         DBG_88E("+rtw_dev_remove\n");
711         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+dev_remove()\n"));
712 
713         if (usb_drv->drv_registered)
714                 padapter->bSurpriseRemoved = true;
715 
716         rtw_pm_set_ips(padapter, IPS_NONE);
717         rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
718 
719         LeaveAllPowerSaveMode(padapter);
720 
721         rtw_usb_if1_deinit(padapter);
722 
723         usb_dvobj_deinit(pusb_intf);
724 
725         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-dev_remove()\n"));
726         DBG_88E("-r871xu_dev_remove, done\n");
727 
728         return;
729 }
730 
731 static int __init rtw_drv_entry(void)
732 {
733         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_drv_entry\n"));
734 
735         DBG_88E(DRV_NAME " driver version=%s\n", DRIVERVERSION);
736 
737         mutex_init(&usb_drv->hw_init_mutex);
738 
739         usb_drv->drv_registered = true;
740         return usb_register(&usb_drv->usbdrv);
741 }
742 
743 static void __exit rtw_drv_halt(void)
744 {
745         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_drv_halt\n"));
746         DBG_88E("+rtw_drv_halt\n");
747 
748         usb_drv->drv_registered = false;
749         usb_deregister(&usb_drv->usbdrv);
750 
751         mutex_destroy(&usb_drv->hw_init_mutex);
752         DBG_88E("-rtw_drv_halt\n");
753 }
754 
755 module_init(rtw_drv_entry);
756 module_exit(rtw_drv_halt);
757 

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