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

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

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