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