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