at v3.7 24 kB view raw
1#include "headers.h" 2 3static struct usb_device_id InterfaceUsbtable[] = { 4 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3) }, 5 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3B) }, 6 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3L) }, 7 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_SM250) }, 8 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_226) }, 9 { USB_DEVICE(BCM_USB_VENDOR_ID_FOXCONN, BCM_USB_PRODUCT_ID_1901) }, 10 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_ZTE_TU25) }, 11 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_ZTE_226) }, 12 { } 13}; 14MODULE_DEVICE_TABLE(usb, InterfaceUsbtable); 15 16static int debug = -1; 17module_param(debug, uint, 0600); 18MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); 19 20static const u32 default_msg = 21 NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK 22 | NETIF_MSG_TIMER | NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR 23 | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN; 24 25static int InterfaceAdapterInit(PS_INTERFACE_ADAPTER Adapter); 26 27static void InterfaceAdapterFree(PS_INTERFACE_ADAPTER psIntfAdapter) 28{ 29 int i = 0; 30 31 /* Wake up the wait_queue... */ 32 if (psIntfAdapter->psAdapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) { 33 psIntfAdapter->psAdapter->DriverState = DRIVER_HALT; 34 wake_up(&psIntfAdapter->psAdapter->LEDInfo.notify_led_event); 35 } 36 reset_card_proc(psIntfAdapter->psAdapter); 37 38 /* 39 * worst case time taken by the RDM/WRM will be 5 sec. will check after every 100 ms 40 * to accertain the device is not being accessed. After this No RDM/WRM should be made. 41 */ 42 while (psIntfAdapter->psAdapter->DeviceAccess) { 43 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 44 "Device is being accessed.\n"); 45 msleep(100); 46 } 47 /* Free interrupt URB */ 48 /* psIntfAdapter->psAdapter->device_removed = TRUE; */ 49 usb_free_urb(psIntfAdapter->psInterruptUrb); 50 51 /* Free transmit URBs */ 52 for (i = 0; i < MAXIMUM_USB_TCB; i++) { 53 if (psIntfAdapter->asUsbTcb[i].urb != NULL) { 54 usb_free_urb(psIntfAdapter->asUsbTcb[i].urb); 55 psIntfAdapter->asUsbTcb[i].urb = NULL; 56 } 57 } 58 /* Free receive URB and buffers */ 59 for (i = 0; i < MAXIMUM_USB_RCB; i++) { 60 if (psIntfAdapter->asUsbRcb[i].urb != NULL) { 61 kfree(psIntfAdapter->asUsbRcb[i].urb->transfer_buffer); 62 usb_free_urb(psIntfAdapter->asUsbRcb[i].urb); 63 psIntfAdapter->asUsbRcb[i].urb = NULL; 64 } 65 } 66 AdapterFree(psIntfAdapter->psAdapter); 67} 68 69static void ConfigureEndPointTypesThroughEEPROM(struct bcm_mini_adapter *Adapter) 70{ 71 unsigned long ulReg = 0; 72 int bytes; 73 74 /* Program EP2 MAX_PKT_SIZE */ 75 ulReg = ntohl(EP2_MPS_REG); 76 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x128, 4, TRUE); 77 ulReg = ntohl(EP2_MPS); 78 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x12C, 4, TRUE); 79 80 ulReg = ntohl(EP2_CFG_REG); 81 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x132, 4, TRUE); 82 if (((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter))->bHighSpeedDevice == TRUE) { 83 ulReg = ntohl(EP2_CFG_INT); 84 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE); 85 } else { 86 /* USE BULK EP as TX in FS mode. */ 87 ulReg = ntohl(EP2_CFG_BULK); 88 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE); 89 } 90 91 /* Program EP4 MAX_PKT_SIZE. */ 92 ulReg = ntohl(EP4_MPS_REG); 93 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x13C, 4, TRUE); 94 ulReg = ntohl(EP4_MPS); 95 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x140, 4, TRUE); 96 97 /* Program TX EP as interrupt(Alternate Setting) */ 98 bytes = rdmalt(Adapter, 0x0F0110F8, (u32 *)&ulReg, sizeof(u32)); 99 if (bytes < 0) { 100 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 101 "reading of Tx EP failed\n"); 102 return; 103 } 104 ulReg |= 0x6; 105 106 ulReg = ntohl(ulReg); 107 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1CC, 4, TRUE); 108 109 ulReg = ntohl(EP4_CFG_REG); 110 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C8, 4, TRUE); 111 /* Program ISOCHRONOUS EP size to zero. */ 112 ulReg = ntohl(ISO_MPS_REG); 113 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1D2, 4, TRUE); 114 ulReg = ntohl(ISO_MPS); 115 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1D6, 4, TRUE); 116 117 /* 118 * Update EEPROM Version. 119 * Read 4 bytes from 508 and modify 511 and 510. 120 */ 121 ReadBeceemEEPROM(Adapter, 0x1FC, (PUINT)&ulReg); 122 ulReg &= 0x0101FFFF; 123 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1FC, 4, TRUE); 124 125 /* Update length field if required. Also make the string NULL terminated. */ 126 127 ReadBeceemEEPROM(Adapter, 0xA8, (PUINT)&ulReg); 128 if ((ulReg&0x00FF0000)>>16 > 0x30) { 129 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16); 130 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0xA8, 4, TRUE); 131 } 132 ReadBeceemEEPROM(Adapter, 0x148, (PUINT)&ulReg); 133 if ((ulReg&0x00FF0000)>>16 > 0x30) { 134 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16); 135 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x148, 4, TRUE); 136 } 137 ulReg = 0; 138 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x122, 4, TRUE); 139 ulReg = 0; 140 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C2, 4, TRUE); 141} 142 143static int usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id) 144{ 145 struct usb_device *udev = interface_to_usbdev(intf); 146 int retval; 147 struct bcm_mini_adapter *psAdapter; 148 PS_INTERFACE_ADAPTER psIntfAdapter; 149 struct net_device *ndev; 150 151 /* Reserve one extra queue for the bit-bucket */ 152 ndev = alloc_etherdev_mq(sizeof(struct bcm_mini_adapter), NO_OF_QUEUES+1); 153 if (ndev == NULL) { 154 dev_err(&udev->dev, DRV_NAME ": no memory for device\n"); 155 return -ENOMEM; 156 } 157 158 SET_NETDEV_DEV(ndev, &intf->dev); 159 160 psAdapter = netdev_priv(ndev); 161 psAdapter->dev = ndev; 162 psAdapter->msg_enable = netif_msg_init(debug, default_msg); 163 164 /* Init default driver debug state */ 165 166 psAdapter->stDebugState.debug_level = DBG_LVL_CURR; 167 psAdapter->stDebugState.type = DBG_TYPE_INITEXIT; 168 169 /* 170 * Technically, one can start using BCM_DEBUG_PRINT after this point. 171 * However, realize that by default the Type/Subtype bitmaps are all zero now; 172 * so no prints will actually appear until the TestApp turns on debug paths via 173 * the ioctl(); so practically speaking, in early init, no logging happens. 174 * 175 * A solution (used below): we explicitly set the bitmaps to 1 for Type=DBG_TYPE_INITEXIT 176 * and ALL subtype's of the same. Now all bcm debug statements get logged, enabling debug 177 * during early init. 178 * Further, we turn this OFF once init_module() completes. 179 */ 180 181 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0xff; 182 BCM_SHOW_DEBUG_BITMAP(psAdapter); 183 184 retval = InitAdapter(psAdapter); 185 if (retval) { 186 dev_err(&udev->dev, DRV_NAME ": InitAdapter Failed\n"); 187 AdapterFree(psAdapter); 188 return retval; 189 } 190 191 /* Allocate interface adapter structure */ 192 psIntfAdapter = kzalloc(sizeof(S_INTERFACE_ADAPTER), GFP_KERNEL); 193 if (psIntfAdapter == NULL) { 194 dev_err(&udev->dev, DRV_NAME ": no memory for Interface adapter\n"); 195 AdapterFree(psAdapter); 196 return -ENOMEM; 197 } 198 199 psAdapter->pvInterfaceAdapter = psIntfAdapter; 200 psIntfAdapter->psAdapter = psAdapter; 201 202 /* Store usb interface in Interface Adapter */ 203 psIntfAdapter->interface = intf; 204 usb_set_intfdata(intf, psIntfAdapter); 205 206 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 207 "psIntfAdapter 0x%p\n", psIntfAdapter); 208 retval = InterfaceAdapterInit(psIntfAdapter); 209 if (retval) { 210 /* If the Firmware/Cfg File is not present 211 * then return success, let the application 212 * download the files. 213 */ 214 if (-ENOENT == retval) { 215 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 216 "File Not Found. Use app to download.\n"); 217 return STATUS_SUCCESS; 218 } 219 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 220 "InterfaceAdapterInit failed.\n"); 221 usb_set_intfdata(intf, NULL); 222 udev = interface_to_usbdev(intf); 223 usb_put_dev(udev); 224 InterfaceAdapterFree(psIntfAdapter); 225 return retval; 226 } 227 if (psAdapter->chip_id > T3) { 228 uint32_t uiNackZeroLengthInt = 4; 229 230 retval = wrmalt(psAdapter, DISABLE_USB_ZERO_LEN_INT, &uiNackZeroLengthInt, sizeof(uiNackZeroLengthInt)); 231 if (retval) 232 return retval; 233 } 234 235 /* Check whether the USB-Device Supports remote Wake-Up */ 236 if (USB_CONFIG_ATT_WAKEUP & udev->actconfig->desc.bmAttributes) { 237 /* If Suspend then only support dynamic suspend */ 238 if (psAdapter->bDoSuspend) { 239#ifdef CONFIG_PM 240 pm_runtime_set_autosuspend_delay(&udev->dev, 0); 241 intf->needs_remote_wakeup = 1; 242 usb_enable_autosuspend(udev); 243 device_init_wakeup(&intf->dev, 1); 244 INIT_WORK(&psIntfAdapter->usbSuspendWork, putUsbSuspend); 245 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 246 "Enabling USB Auto-Suspend\n"); 247#endif 248 } else { 249 intf->needs_remote_wakeup = 0; 250 usb_disable_autosuspend(udev); 251 } 252 } 253 254 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0x0; 255 return retval; 256} 257 258static void usbbcm_disconnect(struct usb_interface *intf) 259{ 260 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf); 261 struct bcm_mini_adapter *psAdapter; 262 struct usb_device *udev = interface_to_usbdev(intf); 263 264 if (psIntfAdapter == NULL) 265 return; 266 267 psAdapter = psIntfAdapter->psAdapter; 268 netif_device_detach(psAdapter->dev); 269 270 if (psAdapter->bDoSuspend) 271 intf->needs_remote_wakeup = 0; 272 273 psAdapter->device_removed = TRUE ; 274 usb_set_intfdata(intf, NULL); 275 InterfaceAdapterFree(psIntfAdapter); 276 usb_put_dev(udev); 277} 278 279static int AllocUsbCb(PS_INTERFACE_ADAPTER psIntfAdapter) 280{ 281 int i = 0; 282 283 for (i = 0; i < MAXIMUM_USB_TCB; i++) { 284 psIntfAdapter->asUsbTcb[i].urb = usb_alloc_urb(0, GFP_KERNEL); 285 286 if (psIntfAdapter->asUsbTcb[i].urb == NULL) { 287 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, 288 "Can't allocate Tx urb for index %d\n", i); 289 return -ENOMEM; 290 } 291 } 292 293 for (i = 0; i < MAXIMUM_USB_RCB; i++) { 294 psIntfAdapter->asUsbRcb[i].urb = usb_alloc_urb(0, GFP_KERNEL); 295 296 if (psIntfAdapter->asUsbRcb[i].urb == NULL) { 297 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, 298 "Can't allocate Rx urb for index %d\n", i); 299 return -ENOMEM; 300 } 301 302 psIntfAdapter->asUsbRcb[i].urb->transfer_buffer = kmalloc(MAX_DATA_BUFFER_SIZE, GFP_KERNEL); 303 304 if (psIntfAdapter->asUsbRcb[i].urb->transfer_buffer == NULL) { 305 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, 306 "Can't allocate Rx buffer for index %d\n", i); 307 return -ENOMEM; 308 } 309 psIntfAdapter->asUsbRcb[i].urb->transfer_buffer_length = MAX_DATA_BUFFER_SIZE; 310 } 311 return 0; 312} 313 314static int device_run(PS_INTERFACE_ADAPTER psIntfAdapter) 315{ 316 int value = 0; 317 UINT status = STATUS_SUCCESS; 318 319 status = InitCardAndDownloadFirmware(psIntfAdapter->psAdapter); 320 if (status != STATUS_SUCCESS) { 321 pr_err(DRV_NAME "InitCardAndDownloadFirmware failed.\n"); 322 return status; 323 } 324 if (TRUE == psIntfAdapter->psAdapter->fw_download_done) { 325 if (StartInterruptUrb(psIntfAdapter)) { 326 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 327 "Cannot send interrupt in URB\n"); 328 } 329 330 /* 331 * now register the cntrl interface. 332 * after downloading the f/w waiting for 5 sec to get the mailbox interrupt. 333 */ 334 psIntfAdapter->psAdapter->waiting_to_fw_download_done = FALSE; 335 value = wait_event_timeout(psIntfAdapter->psAdapter->ioctl_fw_dnld_wait_queue, 336 psIntfAdapter->psAdapter->waiting_to_fw_download_done, 5*HZ); 337 338 if (value == 0) 339 pr_err(DRV_NAME ": Timeout waiting for mailbox interrupt.\n"); 340 341 if (register_control_device_interface(psIntfAdapter->psAdapter) < 0) { 342 pr_err(DRV_NAME ": Register Control Device failed.\n"); 343 return -EIO; 344 } 345 } 346 return 0; 347} 348 349 350static inline int bcm_usb_endpoint_num(const struct usb_endpoint_descriptor *epd) 351{ 352 return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; 353} 354 355static inline int bcm_usb_endpoint_type(const struct usb_endpoint_descriptor *epd) 356{ 357 return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; 358} 359 360static inline int bcm_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd) 361{ 362 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN); 363} 364 365static inline int bcm_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd) 366{ 367 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT); 368} 369 370static inline int bcm_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd) 371{ 372 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 373 USB_ENDPOINT_XFER_BULK); 374} 375 376static inline int bcm_usb_endpoint_xfer_control(const struct usb_endpoint_descriptor *epd) 377{ 378 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 379 USB_ENDPOINT_XFER_CONTROL); 380} 381 382static inline int bcm_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd) 383{ 384 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 385 USB_ENDPOINT_XFER_INT); 386} 387 388static inline int bcm_usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd) 389{ 390 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 391 USB_ENDPOINT_XFER_ISOC); 392} 393 394static inline int bcm_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd) 395{ 396 return bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_in(epd); 397} 398 399static inline int bcm_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd) 400{ 401 return bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_out(epd); 402} 403 404static inline int bcm_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd) 405{ 406 return bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_in(epd); 407} 408 409static inline int bcm_usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd) 410{ 411 return bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_out(epd); 412} 413 414static inline int bcm_usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd) 415{ 416 return bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_in(epd); 417} 418 419static inline int bcm_usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd) 420{ 421 return bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_out(epd); 422} 423 424static int InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter) 425{ 426 struct usb_host_interface *iface_desc; 427 struct usb_endpoint_descriptor *endpoint; 428 size_t buffer_size; 429 unsigned long value; 430 int retval = 0; 431 int usedIntOutForBulkTransfer = 0 ; 432 BOOLEAN bBcm16 = FALSE; 433 UINT uiData = 0; 434 int bytes; 435 436 /* Store the usb dev into interface adapter */ 437 psIntfAdapter->udev = usb_get_dev(interface_to_usbdev(psIntfAdapter->interface)); 438 439 psIntfAdapter->bHighSpeedDevice = (psIntfAdapter->udev->speed == USB_SPEED_HIGH); 440 psIntfAdapter->psAdapter->interface_rdm = BcmRDM; 441 psIntfAdapter->psAdapter->interface_wrm = BcmWRM; 442 443 bytes = rdmalt(psIntfAdapter->psAdapter, CHIP_ID_REG, 444 (u32 *)&(psIntfAdapter->psAdapter->chip_id), sizeof(u32)); 445 if (bytes < 0) { 446 retval = bytes; 447 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, "CHIP ID Read Failed\n"); 448 return retval; 449 } 450 451 if (0xbece3200 == (psIntfAdapter->psAdapter->chip_id & ~(0xF0))) 452 psIntfAdapter->psAdapter->chip_id &= ~0xF0; 453 454 dev_info(&psIntfAdapter->udev->dev, "RDM Chip ID 0x%lx\n", 455 psIntfAdapter->psAdapter->chip_id); 456 457 iface_desc = psIntfAdapter->interface->cur_altsetting; 458 459 if (psIntfAdapter->psAdapter->chip_id == T3B) { 460 /* T3B device will have EEPROM, check if EEPROM is proper and BCM16 can be done or not. */ 461 BeceemEEPROMBulkRead(psIntfAdapter->psAdapter, &uiData, 0x0, 4); 462 if (uiData == BECM) 463 bBcm16 = TRUE; 464 465 dev_info(&psIntfAdapter->udev->dev, "number of alternate setting %d\n", 466 psIntfAdapter->interface->num_altsetting); 467 468 if (bBcm16 == TRUE) { 469 /* selecting alternate setting one as a default setting for High Speed modem. */ 470 if (psIntfAdapter->bHighSpeedDevice) 471 retval = usb_set_interface(psIntfAdapter->udev, DEFAULT_SETTING_0, ALTERNATE_SETTING_1); 472 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 473 "BCM16 is applicable on this dongle\n"); 474 if (retval || (psIntfAdapter->bHighSpeedDevice == FALSE)) { 475 usedIntOutForBulkTransfer = EP2 ; 476 endpoint = &iface_desc->endpoint[EP2].desc; 477 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 478 "Interface altsetting failed or modem is configured to Full Speed, hence will work on default setting 0\n"); 479 /* 480 * If Modem is high speed device EP2 should be INT OUT End point 481 * If Mode is FS then EP2 should be bulk end point 482 */ 483 if (((psIntfAdapter->bHighSpeedDevice == TRUE) && (bcm_usb_endpoint_is_int_out(endpoint) == FALSE)) 484 || ((psIntfAdapter->bHighSpeedDevice == FALSE) && (bcm_usb_endpoint_is_bulk_out(endpoint) == FALSE))) { 485 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 486 "Configuring the EEPROM\n"); 487 /* change the EP2, EP4 to INT OUT end point */ 488 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter); 489 490 /* 491 * It resets the device and if any thing gets changed 492 * in USB descriptor it will show fail and re-enumerate 493 * the device 494 */ 495 retval = usb_reset_device(psIntfAdapter->udev); 496 if (retval) { 497 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 498 "reset failed. Re-enumerating the device.\n"); 499 return retval ; 500 } 501 502 } 503 if ((psIntfAdapter->bHighSpeedDevice == FALSE) && bcm_usb_endpoint_is_bulk_out(endpoint)) { 504 /* Once BULK is selected in FS mode. Revert it back to INT. Else USB_IF will fail. */ 505 UINT _uiData = ntohl(EP2_CFG_INT); 506 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 507 "Reverting Bulk to INT as it is in Full Speed mode.\n"); 508 BeceemEEPROMBulkWrite(psIntfAdapter->psAdapter, (PUCHAR)&_uiData, 0x136, 4, TRUE); 509 } 510 } else { 511 usedIntOutForBulkTransfer = EP4 ; 512 endpoint = &iface_desc->endpoint[EP4].desc; 513 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 514 "Choosing AltSetting as a default setting.\n"); 515 if (bcm_usb_endpoint_is_int_out(endpoint) == FALSE) { 516 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 517 "Dongle does not have BCM16 Fix.\n"); 518 /* change the EP2, EP4 to INT OUT end point and use EP4 in altsetting */ 519 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter); 520 521 /* 522 * It resets the device and if any thing gets changed in 523 * USB descriptor it will show fail and re-enumerate the 524 * device 525 */ 526 retval = usb_reset_device(psIntfAdapter->udev); 527 if (retval) { 528 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 529 "reset failed. Re-enumerating the device.\n"); 530 return retval; 531 } 532 533 } 534 } 535 } 536 } 537 538 iface_desc = psIntfAdapter->interface->cur_altsetting; 539 540 for (value = 0; value < iface_desc->desc.bNumEndpoints; ++value) { 541 endpoint = &iface_desc->endpoint[value].desc; 542 543 if (!psIntfAdapter->sBulkIn.bulk_in_endpointAddr && bcm_usb_endpoint_is_bulk_in(endpoint)) { 544 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 545 psIntfAdapter->sBulkIn.bulk_in_size = buffer_size; 546 psIntfAdapter->sBulkIn.bulk_in_endpointAddr = endpoint->bEndpointAddress; 547 psIntfAdapter->sBulkIn.bulk_in_pipe = 548 usb_rcvbulkpipe(psIntfAdapter->udev, 549 psIntfAdapter->sBulkIn.bulk_in_endpointAddr); 550 } 551 552 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr && bcm_usb_endpoint_is_bulk_out(endpoint)) { 553 psIntfAdapter->sBulkOut.bulk_out_endpointAddr = endpoint->bEndpointAddress; 554 psIntfAdapter->sBulkOut.bulk_out_pipe = 555 usb_sndbulkpipe(psIntfAdapter->udev, 556 psIntfAdapter->sBulkOut.bulk_out_endpointAddr); 557 } 558 559 if (!psIntfAdapter->sIntrIn.int_in_endpointAddr && bcm_usb_endpoint_is_int_in(endpoint)) { 560 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 561 psIntfAdapter->sIntrIn.int_in_size = buffer_size; 562 psIntfAdapter->sIntrIn.int_in_endpointAddr = endpoint->bEndpointAddress; 563 psIntfAdapter->sIntrIn.int_in_interval = endpoint->bInterval; 564 psIntfAdapter->sIntrIn.int_in_buffer = 565 kmalloc(buffer_size, GFP_KERNEL); 566 if (!psIntfAdapter->sIntrIn.int_in_buffer) { 567 dev_err(&psIntfAdapter->udev->dev, 568 "could not allocate interrupt_in_buffer\n"); 569 return -EINVAL; 570 } 571 } 572 573 if (!psIntfAdapter->sIntrOut.int_out_endpointAddr && bcm_usb_endpoint_is_int_out(endpoint)) { 574 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr && 575 (psIntfAdapter->psAdapter->chip_id == T3B) && (value == usedIntOutForBulkTransfer)) { 576 /* use first intout end point as a bulk out end point */ 577 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 578 psIntfAdapter->sBulkOut.bulk_out_size = buffer_size; 579 psIntfAdapter->sBulkOut.bulk_out_endpointAddr = endpoint->bEndpointAddress; 580 psIntfAdapter->sBulkOut.bulk_out_pipe = usb_sndintpipe(psIntfAdapter->udev, 581 psIntfAdapter->sBulkOut.bulk_out_endpointAddr); 582 psIntfAdapter->sBulkOut.int_out_interval = endpoint->bInterval; 583 } else if (value == EP6) { 584 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 585 psIntfAdapter->sIntrOut.int_out_size = buffer_size; 586 psIntfAdapter->sIntrOut.int_out_endpointAddr = endpoint->bEndpointAddress; 587 psIntfAdapter->sIntrOut.int_out_interval = endpoint->bInterval; 588 psIntfAdapter->sIntrOut.int_out_buffer = kmalloc(buffer_size, GFP_KERNEL); 589 if (!psIntfAdapter->sIntrOut.int_out_buffer) { 590 dev_err(&psIntfAdapter->udev->dev, 591 "could not allocate interrupt_out_buffer\n"); 592 return -EINVAL; 593 } 594 } 595 } 596 } 597 598 usb_set_intfdata(psIntfAdapter->interface, psIntfAdapter); 599 600 psIntfAdapter->psAdapter->bcm_file_download = InterfaceFileDownload; 601 psIntfAdapter->psAdapter->bcm_file_readback_from_chip = 602 InterfaceFileReadbackFromChip; 603 psIntfAdapter->psAdapter->interface_transmit = InterfaceTransmitPacket; 604 605 retval = CreateInterruptUrb(psIntfAdapter); 606 607 if (retval) { 608 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, 609 "Cannot create interrupt urb\n"); 610 return retval; 611 } 612 613 retval = AllocUsbCb(psIntfAdapter); 614 if (retval) 615 return retval; 616 617 return device_run(psIntfAdapter); 618} 619 620static int InterfaceSuspend(struct usb_interface *intf, pm_message_t message) 621{ 622 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf); 623 624 psIntfAdapter->bSuspended = TRUE; 625 626 if (TRUE == psIntfAdapter->bPreparingForBusSuspend) { 627 psIntfAdapter->bPreparingForBusSuspend = FALSE; 628 629 if (psIntfAdapter->psAdapter->LinkStatus == LINKUP_DONE) { 630 psIntfAdapter->psAdapter->IdleMode = TRUE ; 631 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 632 "Host Entered in PMU Idle Mode.\n"); 633 } else { 634 psIntfAdapter->psAdapter->bShutStatus = TRUE; 635 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 636 "Host Entered in PMU Shutdown Mode.\n"); 637 } 638 } 639 psIntfAdapter->psAdapter->bPreparingForLowPowerMode = FALSE; 640 641 /* Signaling the control pkt path */ 642 wake_up(&psIntfAdapter->psAdapter->lowpower_mode_wait_queue); 643 644 return 0; 645} 646 647static int InterfaceResume(struct usb_interface *intf) 648{ 649 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf); 650 651 mdelay(100); 652 psIntfAdapter->bSuspended = FALSE; 653 654 StartInterruptUrb(psIntfAdapter); 655 InterfaceRx(psIntfAdapter); 656 return 0; 657} 658 659static struct usb_driver usbbcm_driver = { 660 .name = "usbbcm", 661 .probe = usbbcm_device_probe, 662 .disconnect = usbbcm_disconnect, 663 .suspend = InterfaceSuspend, 664 .resume = InterfaceResume, 665 .id_table = InterfaceUsbtable, 666 .supports_autosuspend = 1, 667}; 668 669struct class *bcm_class; 670 671static __init int bcm_init(void) 672{ 673 int retval; 674 675 pr_info("%s: %s, %s\n", DRV_NAME, DRV_DESCRIPTION, DRV_VERSION); 676 pr_info("%s\n", DRV_COPYRIGHT); 677 678 bcm_class = class_create(THIS_MODULE, DRV_NAME); 679 if (IS_ERR(bcm_class)) { 680 pr_err(DRV_NAME ": could not create class\n"); 681 return PTR_ERR(bcm_class); 682 } 683 684 retval = usb_register(&usbbcm_driver); 685 if (retval < 0) { 686 pr_err(DRV_NAME ": could not register usb driver\n"); 687 class_destroy(bcm_class); 688 return retval; 689 } 690 return 0; 691} 692 693static __exit void bcm_exit(void) 694{ 695 usb_deregister(&usbbcm_driver); 696 class_destroy(bcm_class); 697} 698 699module_init(bcm_init); 700module_exit(bcm_exit); 701 702MODULE_DESCRIPTION(DRV_DESCRIPTION); 703MODULE_VERSION(DRV_VERSION); 704MODULE_LICENSE("GPL");