]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/bcm/Misc.c
Merge tag 'sound-3.6' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
[karo-tx-linux.git] / drivers / staging / bcm / Misc.c
1 #include "headers.h"
2
3 static int BcmFileDownload(struct bcm_mini_adapter *Adapter, const char *path, unsigned int loc);
4 static VOID doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter);
5 static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer);
6 static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter);
7 static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter);
8
9 static VOID default_wimax_protocol_initialize(struct bcm_mini_adapter *Adapter)
10 {
11         UINT uiLoopIndex;
12
13         for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES-1; uiLoopIndex++) {
14                 Adapter->PackInfo[uiLoopIndex].uiThreshold = TX_PACKET_THRESHOLD;
15                 Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate = MAX_ALLOWED_RATE;
16                 Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize = 20*1024*1024;
17         }
18
19         Adapter->BEBucketSize = BE_BUCKET_SIZE;
20         Adapter->rtPSBucketSize = rtPS_BUCKET_SIZE;
21         Adapter->LinkStatus = SYNC_UP_REQUEST;
22         Adapter->TransferMode = IP_PACKET_ONLY_MODE;
23         Adapter->usBestEffortQueueIndex = -1;
24         return;
25 }
26
27 INT InitAdapter(struct bcm_mini_adapter *psAdapter)
28 {
29         int i = 0;
30         INT Status = STATUS_SUCCESS;
31         BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Initialising Adapter = %p", psAdapter);
32
33         if (psAdapter == NULL) {
34                 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Adapter is NULL");
35                 return -EINVAL;
36         }
37
38         sema_init(&psAdapter->NVMRdmWrmLock, 1);
39         sema_init(&psAdapter->rdmwrmsync, 1);
40         spin_lock_init(&psAdapter->control_queue_lock);
41         spin_lock_init(&psAdapter->txtransmitlock);
42         sema_init(&psAdapter->RxAppControlQueuelock, 1);
43         sema_init(&psAdapter->fw_download_sema, 1);
44         sema_init(&psAdapter->LowPowerModeSync, 1);
45
46         for (i = 0; i < NO_OF_QUEUES; i++)
47                 spin_lock_init(&psAdapter->PackInfo[i].SFQueueLock);
48         i = 0;
49
50         init_waitqueue_head(&psAdapter->process_rx_cntrlpkt);
51         init_waitqueue_head(&psAdapter->tx_packet_wait_queue);
52         init_waitqueue_head(&psAdapter->process_read_wait_queue);
53         init_waitqueue_head(&psAdapter->ioctl_fw_dnld_wait_queue);
54         init_waitqueue_head(&psAdapter->lowpower_mode_wait_queue);
55         psAdapter->waiting_to_fw_download_done = TRUE;
56         psAdapter->fw_download_done = FALSE;
57
58         default_wimax_protocol_initialize(psAdapter);
59         for (i = 0; i < MAX_CNTRL_PKTS; i++) {
60                 psAdapter->txctlpacket[i] = kmalloc(MAX_CNTL_PKT_SIZE, GFP_KERNEL);
61                 if (!psAdapter->txctlpacket[i]) {
62                         BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No More Cntl pkts got, max got is %d", i);
63                         return -ENOMEM;
64                 }
65         }
66
67         if (AllocAdapterDsxBuffer(psAdapter)) {
68                 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to allocate DSX buffers");
69                 return -EINVAL;
70         }
71
72         /* Initialize PHS interface */
73         if (phs_init(&psAdapter->stBCMPhsContext, psAdapter) != 0) {
74                 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%s:%d:Error PHS Init Failed=====>\n", __FILE__, __func__, __LINE__);
75                 return -ENOMEM;
76         }
77
78         Status = BcmAllocFlashCSStructure(psAdapter);
79         if (Status) {
80                 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Memory Allocation for Flash structure failed");
81                 return Status;
82         }
83
84         Status = vendorextnInit(psAdapter);
85
86         if (STATUS_SUCCESS != Status) {
87                 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Vendor Init Failed");
88                 return Status;
89         }
90
91         BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Adapter initialised");
92
93         return STATUS_SUCCESS;
94 }
95
96 VOID AdapterFree(struct bcm_mini_adapter *Adapter)
97 {
98         int count;
99         beceem_protocol_reset(Adapter);
100         vendorextnExit(Adapter);
101
102         if (Adapter->control_packet_handler && !IS_ERR(Adapter->control_packet_handler))
103                 kthread_stop(Adapter->control_packet_handler);
104
105         if (Adapter->transmit_packet_thread && !IS_ERR(Adapter->transmit_packet_thread))
106                 kthread_stop(Adapter->transmit_packet_thread);
107
108         wake_up(&Adapter->process_read_wait_queue);
109
110         if (Adapter->LEDInfo.led_thread_running & (BCM_LED_THREAD_RUNNING_ACTIVELY | BCM_LED_THREAD_RUNNING_INACTIVELY))
111                 kthread_stop(Adapter->LEDInfo.led_cntrl_threadid);
112
113         unregister_networkdev(Adapter);
114
115         /* FIXME: use proper wait_event and refcounting */
116         while (atomic_read(&Adapter->ApplicationRunning)) {
117                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Waiting for Application to close.. %d\n", atomic_read(&Adapter->ApplicationRunning));
118                 msleep(100);
119         }
120         unregister_control_device_interface(Adapter);
121         kfree(Adapter->pstargetparams);
122
123         for (count = 0; count < MAX_CNTRL_PKTS; count++)
124                 kfree(Adapter->txctlpacket[count]);
125
126         FreeAdapterDsxBuffer(Adapter);
127         kfree(Adapter->pvInterfaceAdapter);
128
129         /* Free the PHS Interface */
130         PhsCleanup(&Adapter->stBCMPhsContext);
131
132         BcmDeAllocFlashCSStructure(Adapter);
133
134         free_netdev(Adapter->dev);
135 }
136
137 static int create_worker_threads(struct bcm_mini_adapter *psAdapter)
138 {
139         /* Rx Control Packets Processing */
140         psAdapter->control_packet_handler = kthread_run((int (*)(void *))
141                                                         control_packet_handler, psAdapter, "%s-rx", DRV_NAME);
142         if (IS_ERR(psAdapter->control_packet_handler)) {
143                 pr_notice(DRV_NAME ": could not create control thread\n");
144                 return PTR_ERR(psAdapter->control_packet_handler);
145         }
146
147         /* Tx Thread */
148         psAdapter->transmit_packet_thread = kthread_run((int (*)(void *))
149                                                         tx_pkt_handler, psAdapter, "%s-tx", DRV_NAME);
150         if (IS_ERR(psAdapter->transmit_packet_thread)) {
151                 pr_notice(DRV_NAME ": could not creat transmit thread\n");
152                 kthread_stop(psAdapter->control_packet_handler);
153                 return PTR_ERR(psAdapter->transmit_packet_thread);
154         }
155         return 0;
156 }
157
158 static struct file *open_firmware_file(struct bcm_mini_adapter *Adapter, const char *path)
159 {
160         struct file *flp = filp_open(path, O_RDONLY, S_IRWXU);
161         if (IS_ERR(flp)) {
162                 pr_err(DRV_NAME "Unable To Open File %s, err %ld", path, PTR_ERR(flp));
163                 flp = NULL;
164         }
165
166         if (Adapter->device_removed)
167                 flp = NULL;
168
169         return flp;
170 }
171
172 /* Arguments:
173  * Logical Adapter
174  * Path to image file
175  * Download Address on the chip
176  */
177 static int BcmFileDownload(struct bcm_mini_adapter *Adapter, const char *path, unsigned int loc)
178 {
179         int errorno = 0;
180         struct file *flp = NULL;
181         struct timeval tv = {0};
182
183         flp = open_firmware_file(Adapter, path);
184         if (!flp) {
185                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Unable to Open %s\n", path);
186                 return -ENOENT;
187         }
188         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Opened file is = %s and length =0x%lx to be downloaded at =0x%x", path, (unsigned long)flp->f_dentry->d_inode->i_size, loc);
189         do_gettimeofday(&tv);
190
191         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "download start %lx", ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)));
192         if (Adapter->bcm_file_download(Adapter->pvInterfaceAdapter, flp, loc)) {
193                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to download the firmware with error %x!!!", -EIO);
194                 errorno = -EIO;
195                 goto exit_download;
196         }
197         vfs_llseek(flp, 0, 0);
198         if (Adapter->bcm_file_readback_from_chip(Adapter->pvInterfaceAdapter, flp, loc)) {
199                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to read back firmware!");
200                 errorno = -EIO;
201                 goto exit_download;
202         }
203
204 exit_download:
205         filp_close(flp, NULL);
206         return errorno;
207 }
208
209 /**
210  * @ingroup ctrl_pkt_functions
211  * This function copies the contents of given buffer
212  * to the control packet and queues it for transmission.
213  * @note Do not acquire the spinock, as it it already acquired.
214  * @return  SUCCESS/FAILURE.
215  * Arguments:
216  * Logical Adapter
217  * Control Packet Buffer
218  */
219 INT CopyBufferToControlPacket(struct bcm_mini_adapter *Adapter, PVOID ioBuffer)
220 {
221         struct bcm_leader *pLeader = NULL;
222         INT Status = 0;
223         unsigned char *ctrl_buff = NULL;
224         UINT pktlen = 0;
225         struct bcm_link_request *pLinkReq = NULL;
226         PUCHAR pucAddIndication = NULL;
227
228         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "======>");
229         if (!ioBuffer) {
230                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Got Null Buffer\n");
231                 return -EINVAL;
232         }
233
234         pLinkReq = (struct bcm_link_request *)ioBuffer;
235         pLeader = (struct bcm_leader *)ioBuffer; /* ioBuffer Contains sw_Status and Payload */
236
237         if (Adapter->bShutStatus == TRUE &&
238                 pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD &&
239                 pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE) {
240
241                 /* Got sync down in SHUTDOWN..we could not process this. */
242                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "SYNC DOWN Request in Shut Down Mode..\n");
243                 return STATUS_FAILURE;
244         }
245
246         if ((pLeader->Status == LINK_UP_CONTROL_REQ) &&
247                 ((pLinkReq->szData[0] == LINK_UP_REQ_PAYLOAD &&
248                         (pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE)) || /* Sync Up Command */
249                         pLinkReq->szData[0] == NETWORK_ENTRY_REQ_PAYLOAD)) /* Net Entry Command */ {
250
251                 if (Adapter->LinkStatus > PHY_SYNC_ACHIVED) {
252                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "LinkStatus is Greater than PHY_SYN_ACHIEVED");
253                         return STATUS_FAILURE;
254                 }
255
256                 if (TRUE == Adapter->bShutStatus) {
257                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "SYNC UP IN SHUTDOWN..Device WakeUp\n");
258                         if (Adapter->bTriedToWakeUpFromlowPowerMode == FALSE) {
259                                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Waking up for the First Time..\n");
260                                 Adapter->usIdleModePattern = ABORT_SHUTDOWN_MODE; /* change it to 1 for current support. */
261                                 Adapter->bWakeUpDevice = TRUE;
262                                 wake_up(&Adapter->process_rx_cntrlpkt);
263                                 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->bShutStatus, (5 * HZ));
264
265                                 if (Status == -ERESTARTSYS)
266                                         return Status;
267
268                                 if (Adapter->bShutStatus) {
269                                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Shutdown Mode Wake up Failed - No Wake Up Received\n");
270                                         return STATUS_FAILURE;
271                                 }
272                         } else {
273                                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Wakeup has been tried already...\n");
274                         }
275                 }
276         }
277
278         if (TRUE == Adapter->IdleMode) {
279                 /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle mode ... hence\n"); */
280                 if (pLeader->Status == LINK_UP_CONTROL_REQ || pLeader->Status == 0x80 ||
281                         pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ) {
282
283                         if ((pLeader->Status == LINK_UP_CONTROL_REQ) && (pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD)) {
284                                 if ((pLinkReq->szData[1] == LINK_SYNC_DOWN_SUBTYPE)) {
285                                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Link Down Sent in Idle Mode\n");
286                                         Adapter->usIdleModePattern = ABORT_IDLE_SYNCDOWN; /* LINK DOWN sent in Idle Mode */
287                                 } else {
288                                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "ABORT_IDLE_MODE pattern is being written\n");
289                                         Adapter->usIdleModePattern = ABORT_IDLE_REG;
290                                 }
291                         } else {
292                                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "ABORT_IDLE_MODE pattern is being written\n");
293                                 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
294                         }
295
296                         /*Setting bIdleMode_tx_from_host to TRUE to indicate LED control thread to represent
297                          *  the wake up from idlemode is from host
298                          */
299                         /* Adapter->LEDInfo.bIdleMode_tx_from_host = TRUE; */
300                         Adapter->bWakeUpDevice = TRUE;
301                         wake_up(&Adapter->process_rx_cntrlpkt);
302
303                         /* We should not send DREG message down while in idlemode. */
304                         if (LINK_DOWN_REQ_PAYLOAD == pLinkReq->szData[0])
305                                 return STATUS_SUCCESS;
306
307                         Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->IdleMode, (5 * HZ));
308
309                         if (Status == -ERESTARTSYS)
310                                 return Status;
311
312                         if (Adapter->IdleMode) {
313                                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Idle Mode Wake up Failed - No Wake Up Received\n");
314                                 return STATUS_FAILURE;
315                         }
316                 } else {
317                         return STATUS_SUCCESS;
318                 }
319         }
320
321         /* The Driver has to send control messages with a particular VCID */
322         pLeader->Vcid = VCID_CONTROL_PACKET; /* VCID for control packet. */
323
324         /* Allocate skb for Control Packet */
325         pktlen = pLeader->PLength;
326         ctrl_buff = (char *)Adapter->txctlpacket[atomic_read(&Adapter->index_wr_txcntrlpkt)%MAX_CNTRL_PKTS];
327
328         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Control packet to be taken =%d and address is =%pincoming address is =%p and packet len=%x",
329                         atomic_read(&Adapter->index_wr_txcntrlpkt), ctrl_buff, ioBuffer, pktlen);
330         if (ctrl_buff) {
331                 if (pLeader) {
332                         if ((pLeader->Status == 0x80) ||
333                                 (pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ)) {
334                                 /*
335                                  * Restructure the DSX message to handle Multiple classifier Support
336                                  * Write the Service Flow param Structures directly to the target
337                                  * and embed the pointers in the DSX messages sent to target.
338                                  */
339                                 /* Lets store the current length of the control packet we are transmitting */
340                                 pucAddIndication = (PUCHAR)ioBuffer + LEADER_SIZE;
341                                 pktlen = pLeader->PLength;
342                                 Status = StoreCmControlResponseMessage(Adapter, pucAddIndication, &pktlen);
343                                 if (Status != 1) {
344                                         ClearTargetDSXBuffer(Adapter, ((stLocalSFAddIndicationAlt *)pucAddIndication)->u16TID, FALSE);
345                                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, " Error Restoring The DSX Control Packet. Dsx Buffers on Target may not be Setup Properly ");
346                                         return STATUS_FAILURE;
347                                 }
348                                 /*
349                                  * update the leader to use the new length
350                                  * The length of the control packet is length of message being sent + Leader length
351                                  */
352                                 pLeader->PLength = pktlen;
353                         }
354                 }
355
356                 if (pktlen + LEADER_SIZE > MAX_CNTL_PKT_SIZE)
357                         return -EINVAL;
358
359                 memset(ctrl_buff, 0, pktlen+LEADER_SIZE);
360                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Copying the Control Packet Buffer with length=%d\n", pLeader->PLength);
361                 *(struct bcm_leader *)ctrl_buff = *pLeader;
362                 memcpy(ctrl_buff + LEADER_SIZE, ((PUCHAR)ioBuffer + LEADER_SIZE), pLeader->PLength);
363                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Enqueuing the Control Packet");
364
365                 /* Update the statistics counters */
366                 spin_lock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
367                 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost += pLeader->PLength;
368                 Adapter->PackInfo[HiPriority].uiCurrentPacketsOnHost++;
369                 atomic_inc(&Adapter->TotalPacketCount);
370                 spin_unlock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
371                 Adapter->PackInfo[HiPriority].bValid = TRUE;
372
373                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "CurrBytesOnHost: %x bValid: %x",
374                                 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost,
375                                 Adapter->PackInfo[HiPriority].bValid);
376                 Status = STATUS_SUCCESS;
377                 /*Queue the packet for transmission */
378                 atomic_inc(&Adapter->index_wr_txcntrlpkt);
379                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Calling transmit_packets");
380                 atomic_set(&Adapter->TxPktAvail, 1);
381                 wake_up(&Adapter->tx_packet_wait_queue);
382         } else {
383                 Status = -ENOMEM;
384                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "mem allocation Failed");
385         }
386         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<====");
387         return Status;
388 }
389
390 /******************************************************************
391 * Function    - LinkMessage()
392 *
393 * Description - This function builds the Sync-up and Link-up request
394 * packet messages depending on the device Link status.
395 *
396 * Parameters  - Adapter:        Pointer to the Adapter structure.
397 *
398 * Returns     - None.
399 *******************************************************************/
400 VOID LinkMessage(struct bcm_mini_adapter *Adapter)
401 {
402         struct bcm_link_request *pstLinkRequest = NULL;
403         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>");
404         if (Adapter->LinkStatus == SYNC_UP_REQUEST && Adapter->AutoSyncup) {
405                 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
406                 if (!pstLinkRequest) {
407                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
408                         return;
409                 }
410                 /* sync up request... */
411                 Adapter->LinkStatus = WAIT_FOR_SYNC; /* current link status */
412                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For SyncUp...");
413                 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
414                 pstLinkRequest->szData[1] = LINK_SYNC_UP_SUBTYPE;
415                 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
416                 pstLinkRequest->Leader.PLength = sizeof(ULONG);
417                 Adapter->bSyncUpRequestSent = TRUE;
418
419         } else if (Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp) {
420                 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
421                 if (!pstLinkRequest) {
422                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
423                         return;
424                 }
425                 /* LINK_UP_REQUEST */
426                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For LinkUp...");
427                 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
428                 pstLinkRequest->szData[1] = LINK_NET_ENTRY;
429                 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
430                 pstLinkRequest->Leader.PLength = sizeof(ULONG);
431         }
432         if (pstLinkRequest) {
433                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
434                 CopyBufferToControlPacket(Adapter, pstLinkRequest);
435                 kfree(pstLinkRequest);
436         }
437         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
438         return;
439 }
440
441 /**********************************************************************
442 * Function    - StatisticsResponse()
443 *
444 * Description - This function handles the Statistics response packet.
445 *
446 * Parameters  - Adapter : Pointer to the Adapter structure.
447 * - pvBuffer: Starting address of Statistic response data.
448 *
449 * Returns     - None.
450 ************************************************************************/
451 VOID StatisticsResponse(struct bcm_mini_adapter *Adapter, PVOID pvBuffer)
452 {
453         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>", __func__);
454         Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
455         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (UINT)Adapter->StatisticsPointer);
456         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====", __func__);
457         return;
458 }
459
460 /**********************************************************************
461 * Function    - LinkControlResponseMessage()
462 *
463 * Description - This function handles the Link response packets.
464 *
465 * Parameters  - Adapter  : Pointer to the Adapter structure.
466 * - pucBuffer: Starting address of Link response data.
467 *
468 * Returns     - None.
469 ***********************************************************************/
470 VOID LinkControlResponseMessage(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
471 {
472         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
473
474         if (*pucBuffer == LINK_UP_ACK) {
475                 switch (*(pucBuffer+1)) {
476                 case PHY_SYNC_ACHIVED: /* SYNCed UP */
477                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHY_SYNC_ACHIVED");
478
479                                 if (Adapter->LinkStatus == LINKUP_DONE)
480                                         beceem_protocol_reset(Adapter);
481
482                                 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
483                                 Adapter->LinkStatus = PHY_SYNC_ACHIVED;
484
485                                 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
486                                         Adapter->DriverState = NO_NETWORK_ENTRY;
487                                         wake_up(&Adapter->LEDInfo.notify_led_event);
488                                 }
489
490                                 LinkMessage(Adapter);
491                                 break;
492
493                 case LINKUP_DONE:
494                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LINKUP_DONE");
495                         Adapter->LinkStatus = LINKUP_DONE;
496                         Adapter->bPHSEnabled = *(pucBuffer+3);
497                         Adapter->bETHCSEnabled = *(pucBuffer+4) & ETH_CS_MASK;
498                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHS Support Status Received In LinkUp Ack : %x\n", Adapter->bPHSEnabled);
499
500                         if ((FALSE == Adapter->bShutStatus) && (FALSE == Adapter->IdleMode)) {
501                                 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
502                                         Adapter->DriverState = NORMAL_OPERATION;
503                                         wake_up(&Adapter->LEDInfo.notify_led_event);
504                                 }
505                         }
506                         LinkMessage(Adapter);
507                         break;
508
509                 case WAIT_FOR_SYNC:
510                         /*
511                          * Driver to ignore the DREG_RECEIVED
512                          * WiMAX Application should handle this Message
513                          */
514                         /* Adapter->liTimeSinceLastNetEntry = 0; */
515                         Adapter->LinkUpStatus = 0;
516                         Adapter->LinkStatus = 0;
517                         Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
518                         Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
519                         Adapter->IdleMode = FALSE;
520                         beceem_protocol_reset(Adapter);
521
522                         break;
523                 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
524                 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
525                 {
526                         HandleShutDownModeRequest(Adapter, pucBuffer);
527                 }
528                 break;
529                 default:
530                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x", *(pucBuffer + 1));
531                         break;
532                 }
533         } else if (SET_MAC_ADDRESS_RESPONSE == *pucBuffer) {
534                 PUCHAR puMacAddr = (pucBuffer + 1);
535                 Adapter->LinkStatus = SYNC_UP_REQUEST;
536                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "MAC address response, sending SYNC_UP");
537                 LinkMessage(Adapter);
538                 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
539         }
540         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====", __func__);
541         return;
542 }
543
544 void SendIdleModeResponse(struct bcm_mini_adapter *Adapter)
545 {
546         INT status = 0, NVMAccess = 0, lowPwrAbortMsg = 0;
547         struct timeval tv;
548         struct bcm_link_request stIdleResponse = {{0} };
549         memset(&tv, 0, sizeof(tv));
550         stIdleResponse.Leader.Status = IDLE_MESSAGE;
551         stIdleResponse.Leader.PLength = IDLE_MODE_PAYLOAD_LENGTH;
552         stIdleResponse.szData[0] = GO_TO_IDLE_MODE_PAYLOAD;
553         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, " ============>");
554
555         /*********************************
556          *down_trylock -
557          * if [ semaphore is available ]
558          *               acquire semaphone and return value 0 ;
559          *   else
560          *               return non-zero value ;
561          *
562          ***********************************/
563
564         NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
565         lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
566
567
568         if ((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
569                 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)) {
570
571                 if (!NVMAccess)
572                         up(&Adapter->NVMRdmWrmLock);
573
574                 if (!lowPwrAbortMsg)
575                         up(&Adapter->LowPowerModeSync);
576
577                 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
578                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "HOST IS NACKING Idle mode To F/W!!!!!!!!");
579                 Adapter->bPreparingForLowPowerMode = FALSE;
580         } else {
581                 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; /* 2; Idle ACK */
582                 Adapter->StatisticsPointer = 0;
583
584                 /* Wait for the LED to TURN OFF before sending ACK response */
585                 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
586                         INT iRetVal = 0;
587
588                         /* Wake the LED Thread with IDLEMODE_ENTER State */
589                         Adapter->DriverState = LOWPOWER_MODE_ENTER;
590                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LED Thread is Running..Hence Setting LED Event as IDLEMODE_ENTER jiffies:%ld", jiffies);
591                         wake_up(&Adapter->LEDInfo.notify_led_event);
592
593                         /* Wait for 1 SEC for LED to OFF */
594                         iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
595
596                         /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
597                         if (iRetVal <= 0) {
598                                 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
599                                 Adapter->DriverState = NORMAL_OPERATION;
600                                 wake_up(&Adapter->LEDInfo.notify_led_event);
601                                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "NACKING Idle mode as time out happen from LED side!!!!!!!!");
602                         }
603                 }
604
605                 if (stIdleResponse.szData[1] == TARGET_CAN_GO_TO_IDLE_MODE) {
606                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "ACKING IDLE MODE !!!!!!!!!");
607                         down(&Adapter->rdmwrmsync);
608                         Adapter->bPreparingForLowPowerMode = TRUE;
609                         up(&Adapter->rdmwrmsync);
610                         /* Killing all URBS. */
611                         if (Adapter->bDoSuspend == TRUE)
612                                 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
613                 } else {
614                         Adapter->bPreparingForLowPowerMode = FALSE;
615                 }
616
617                 if (!NVMAccess)
618                         up(&Adapter->NVMRdmWrmLock);
619
620                 if (!lowPwrAbortMsg)
621                         up(&Adapter->LowPowerModeSync);
622         }
623
624         status = CopyBufferToControlPacket(Adapter, &stIdleResponse);
625         if ((status != STATUS_SUCCESS)) {
626                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "fail to send the Idle mode Request\n");
627                 Adapter->bPreparingForLowPowerMode = FALSE;
628                 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
629         }
630         do_gettimeofday(&tv);
631         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "IdleMode Msg submitter to Q :%ld ms", tv.tv_sec * 1000 + tv.tv_usec / 1000);
632 }
633
634 /******************************************************************
635 * Function    - DumpPackInfo()
636 *
637 * Description - This function dumps the all Queue(PackInfo[]) details.
638 *
639 * Parameters  - Adapter: Pointer to the Adapter structure.
640 *
641 * Returns     - None.
642 *******************************************************************/
643 VOID DumpPackInfo(struct bcm_mini_adapter *Adapter)
644 {
645         UINT uiLoopIndex = 0;
646         UINT uiIndex = 0;
647         UINT uiClsfrIndex = 0;
648         struct bcm_classifier_rule *pstClassifierEntry = NULL;
649
650         for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
651                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "*********** Showing Details Of Queue %d***** ******", uiLoopIndex);
652                 if (FALSE == Adapter->PackInfo[uiLoopIndex].bValid) {
653                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid is FALSE for %X index\n", uiLoopIndex);
654                         continue;
655                 }
656
657                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " Dumping     SF Rule Entry For SFID %lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
658                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " ucDirection %X\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
659
660                 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
661                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv6 Service Flow\n");
662                 else
663                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv4 Service Flow\n");
664
665                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SF Traffic Priority %X\n", Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
666
667                 for (uiClsfrIndex = 0; uiClsfrIndex < MAX_CLASSIFIERS; uiClsfrIndex++) {
668                         pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
669                         if (!pstClassifierEntry->bUsed)
670                                 continue;
671
672                         if (pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
673                                 continue;
674
675                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X Classifier Rule ID : %X\n", uiClsfrIndex, pstClassifierEntry->uiClassifierRuleIndex);
676                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X usVCID_Value : %X\n", uiClsfrIndex, pstClassifierEntry->usVCID_Value);
677                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bProtocolValid : %X\n", uiClsfrIndex, pstClassifierEntry->bProtocolValid);
678                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bTOSValid : %X\n", uiClsfrIndex, pstClassifierEntry->bTOSValid);
679                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bDestIpValid : %X\n", uiClsfrIndex, pstClassifierEntry->bDestIpValid);
680                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bSrcIpValid : %X\n", uiClsfrIndex, pstClassifierEntry->bSrcIpValid);
681
682                         for (uiIndex = 0; uiIndex < MAX_PORT_RANGE; uiIndex++) {
683                                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeLo:%X\n", pstClassifierEntry->usSrcPortRangeLo[uiIndex]);
684                                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeHi:%X\n", pstClassifierEntry->usSrcPortRangeHi[uiIndex]);
685                                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeLo:%X\n", pstClassifierEntry->usDestPortRangeLo[uiIndex]);
686                                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeHi:%X\n", pstClassifierEntry->usDestPortRangeHi[uiIndex]);
687                         }
688
689                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPSourceAddressLength : 0x%x\n", pstClassifierEntry->ucIPSourceAddressLength);
690                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPDestinationAddressLength : 0x%x\n", pstClassifierEntry->ucIPDestinationAddressLength);
691                         for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPSourceAddressLength; uiIndex++) {
692                                 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
693                                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpAddr :\n");
694                                         DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Addr);
695                                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpMask :\n");
696                                         DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Mask);
697                                 } else {
698                                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpAddr:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Addr[uiIndex]);
699                                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpMask:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Mask[uiIndex]);
700                                 }
701                         }
702
703                         for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPDestinationAddressLength; uiIndex++) {
704                                 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
705                                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpAddr :\n");
706                                         DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Addr);
707                                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpMask :\n");
708                                         DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Mask);
709                                 } else {
710                                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpAddr:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Addr[uiIndex]);
711                                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpMask:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Mask[uiIndex]);
712                                 }
713                         }
714                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucProtocol:0x%X\n", pstClassifierEntry->ucProtocol[0]);
715                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tu8ClassifierRulePriority:%X\n", pstClassifierEntry->u8ClassifierRulePriority);
716                 }
717                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ulSFID:%lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
718                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "usVCID_Value:%X\n", Adapter->PackInfo[uiLoopIndex].usVCID_Value);
719                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "PhsEnabled: 0x%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
720                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThreshold:%X\n", Adapter->PackInfo[uiLoopIndex].uiThreshold);
721
722                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid:%X\n", Adapter->PackInfo[uiLoopIndex].bValid);
723                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bActive:%X\n", Adapter->PackInfo[uiLoopIndex].bActive);
724                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActivateReqSent: %x", Adapter->PackInfo[uiLoopIndex].bActivateRequestSent);
725                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "u8QueueType:%X\n", Adapter->PackInfo[uiLoopIndex].u8QueueType);
726                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxBucketSize:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize);
727                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPerSFTxResourceCount:%X\n", atomic_read(&Adapter->PackInfo[uiLoopIndex].uiPerSFTxResourceCount));
728                 /* DumpDebug(DUMP_INFO,("bCSSupport:%X\n",Adapter->PackInfo[uiLoopIndex].bCSSupport)); */
729                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CurrQueueDepthOnTarget: %x\n", Adapter->PackInfo[uiLoopIndex].uiCurrentQueueDepthOnTarget);
730                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentBytesOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentBytesOnHost);
731                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentPacketsOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentPacketsOnHost);
732                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountBytes);
733                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountPackets);
734                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentBytes);
735                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentPackets);
736                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentDrainRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentDrainRate);
737                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThisPeriodSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiThisPeriodSentBytes);
738                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liDrainCalculated:%llX\n", Adapter->PackInfo[uiLoopIndex].liDrainCalculated);
739                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentTokenCount:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentTokenCount);
740                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liLastUpdateTokenAt:%llX\n", Adapter->PackInfo[uiLoopIndex].liLastUpdateTokenAt);
741                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxAllowedRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate);
742                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPendedLast:%X\n", Adapter->PackInfo[uiLoopIndex].uiPendedLast);
743                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "NumOfPacketsSent:%X\n", Adapter->PackInfo[uiLoopIndex].NumOfPacketsSent);
744                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Direction: %x\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
745                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CID: %x\n", Adapter->PackInfo[uiLoopIndex].usCID);
746                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ProtocolValid: %x\n", Adapter->PackInfo[uiLoopIndex].bProtocolValid);
747                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "TOSValid: %x\n", Adapter->PackInfo[uiLoopIndex].bTOSValid);
748                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "DestIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bDestIpValid);
749                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SrcIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bSrcIpValid);
750                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActiveSet: %x\n", Adapter->PackInfo[uiLoopIndex].bActiveSet);
751                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AdmittedSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAdmittedSet);
752                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AuthzSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAuthorizedSet);
753                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ClassifyPrority: %x\n", Adapter->PackInfo[uiLoopIndex].bClassifierPriority);
754                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxLatency: %x\n", Adapter->PackInfo[uiLoopIndex].uiMaxLatency);
755                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ServiceClassName: %x %x %x %x\n", Adapter->PackInfo[uiLoopIndex].ucServiceClassName[0], Adapter->PackInfo[uiLoopIndex].ucServiceClassName[1], Adapter->PackInfo[uiLoopIndex].ucServiceClassName[2], Adapter->PackInfo[uiLoopIndex].ucServiceClassName[3]);
756 /* BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bHeaderSuppressionEnabled :%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
757  * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalTxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalTxBytes);
758  * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalRxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalRxBytes);
759  *              DumpDebug(DUMP_INFO,("                          uiRanOutOfResCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiRanOutOfResCount));
760  */
761         }
762
763         for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
764                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aRxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aRxPktSizeHist[uiLoopIndex]);
765
766         for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
767                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aTxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aTxPktSizeHist[uiLoopIndex]);
768
769         return;
770 }
771
772 int reset_card_proc(struct bcm_mini_adapter *ps_adapter)
773 {
774         int retval = STATUS_SUCCESS;
775         struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
776         PS_INTERFACE_ADAPTER psIntfAdapter = NULL;
777         unsigned int value = 0, uiResetValue = 0;
778         int bytes;
779
780         psIntfAdapter = ((PS_INTERFACE_ADAPTER)(ps_adapter->pvInterfaceAdapter));
781         ps_adapter->bDDRInitDone = FALSE;
782
783         if (ps_adapter->chip_id >= T3LPB) {
784                 /* SYS_CFG register is write protected hence for modifying this reg value, it should be read twice before */
785                 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
786                 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
787
788                 /* making bit[6...5] same as was before f/w download. this setting force the h/w to */
789                 /* re-populated the SP RAM area with the string descriptor. */
790                 value = value | (ps_adapter->syscfgBefFwDld & 0x00000060);
791                 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
792         }
793
794         /* killing all submitted URBs. */
795         psIntfAdapter->psAdapter->StopAllXaction = TRUE;
796         Bcm_kill_all_URBs(psIntfAdapter);
797         /* Reset the UMA-B Device */
798         if (ps_adapter->chip_id >= T3LPB) {
799                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Resetting UMA-B\n");
800                 retval = usb_reset_device(psIntfAdapter->udev);
801                 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
802
803                 if (retval != STATUS_SUCCESS) {
804                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
805                         goto err_exit;
806                 }
807
808                 if (ps_adapter->chip_id == BCS220_2 ||
809                         ps_adapter->chip_id == BCS220_2BC ||
810                         ps_adapter->chip_id == BCS250_BC ||
811                         ps_adapter->chip_id == BCS220_3) {
812
813                         bytes = rdmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
814                         if (bytes < 0) {
815                                 retval = bytes;
816                                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
817                                 goto err_exit;
818                         }
819                         /* setting 0th bit */
820                         value |= (1<<0);
821                         retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
822                         if (retval < 0) {
823                                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
824                                 goto err_exit;
825                         }
826                 }
827         } else {
828                 bytes = rdmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
829                 if (bytes < 0) {
830                         retval = bytes;
831                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
832                         goto err_exit;
833                 }
834                 value &= (~(1<<16));
835                 retval = wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
836                 if (retval < 0) {
837                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
838                         goto err_exit;
839                 }
840
841                 /* Toggling the GPIO 8, 9 */
842                 value = 0;
843                 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
844                 if (retval < 0) {
845                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
846                         goto err_exit;
847                 }
848                 value = 0x300;
849                 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value));
850                 if (retval < 0) {
851                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
852                         goto err_exit;
853                 }
854                 mdelay(50);
855         }
856
857         /* ps_adapter->downloadDDR = false; */
858         if (ps_adapter->bFlashBoot) {
859                 /* In flash boot mode MIPS state register has reverse polarity.
860                  * So just or with setting bit 30.
861                  * Make the MIPS in Reset state.
862                  */
863                 rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
864                 uiResetValue |= (1<<30);
865                 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
866         }
867
868         if (ps_adapter->chip_id >= T3LPB) {
869                 uiResetValue = 0;
870                 /*
871                  * WA for SYSConfig Issue.
872                  * Read SYSCFG Twice to make it writable.
873                  */
874                 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
875                 if (uiResetValue & (1<<4)) {
876                         uiResetValue = 0;
877                         rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue)); /* 2nd read to make it writable. */
878                         uiResetValue &= (~(1<<4));
879                         wrmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
880                 }
881         }
882         uiResetValue = 0;
883         wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
884
885 err_exit:
886         psIntfAdapter->psAdapter->StopAllXaction = FALSE;
887         return retval;
888 }
889
890 int run_card_proc(struct bcm_mini_adapter *ps_adapter)
891 {
892         int status = STATUS_SUCCESS;
893         int bytes;
894
895         unsigned int value = 0;
896         {
897                 bytes = rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value));
898                 if (bytes < 0) {
899                         status = bytes;
900                         BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
901                         return status;
902                 }
903
904                 if (ps_adapter->bFlashBoot)
905                         value &= (~(1<<30));
906                 else
907                         value |= (1<<30);
908
909                 if (wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
910                         BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
911                         return STATUS_FAILURE;
912                 }
913         }
914         return status;
915 }
916
917 int InitCardAndDownloadFirmware(struct bcm_mini_adapter *ps_adapter)
918 {
919         int status;
920         UINT value = 0;
921         /*
922          * Create the threads first and then download the
923          * Firm/DDR Settings..
924          */
925         status = create_worker_threads(ps_adapter);
926         if (status < 0)
927                 return status;
928
929         status = bcm_parse_target_params(ps_adapter);
930         if (status)
931                 return status;
932
933         if (ps_adapter->chip_id >= T3LPB) {
934                 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
935                 ps_adapter->syscfgBefFwDld = value;
936
937                 if ((value & 0x60) == 0)
938                         ps_adapter->bFlashBoot = TRUE;
939         }
940
941         reset_card_proc(ps_adapter);
942
943         /* Initializing the NVM. */
944         BcmInitNVM(ps_adapter);
945         status = ddr_init(ps_adapter);
946         if (status) {
947                 pr_err(DRV_NAME "ddr_init Failed\n");
948                 return status;
949         }
950
951         /* Download cfg file */
952         status = buffDnldVerify(ps_adapter,
953                                 (PUCHAR)ps_adapter->pstargetparams,
954                                 sizeof(STARGETPARAMS),
955                                 CONFIG_BEGIN_ADDR);
956         if (status) {
957                 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
958                 goto OUT;
959         }
960
961         if (register_networkdev(ps_adapter)) {
962                 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
963                 return -EIO;
964         }
965
966         if (FALSE == ps_adapter->AutoFirmDld) {
967                 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoFirmDld Disabled in CFG File..\n");
968                 /* If Auto f/w download is disable, register the control interface, */
969                 /* register the control interface after the mailbox. */
970                 if (register_control_device_interface(ps_adapter) < 0) {
971                         BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
972                         return -EIO;
973                 }
974                 return STATUS_SUCCESS;
975         }
976
977         /*
978          * Do the LED Settings here. It will be used by the Firmware Download
979          * Thread.
980          */
981
982         /*
983          * 1. If the LED Settings fails, do not stop and do the Firmware download.
984          * 2. This init would happened only if the cfg file is present, else
985          *    call from the ioctl context.
986          */
987
988         status = InitLedSettings(ps_adapter);
989         if (status) {
990                 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_PRINTK, 0, 0, "INIT LED FAILED\n");
991                 return status;
992         }
993
994         if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
995                 ps_adapter->DriverState = DRIVER_INIT;
996                 wake_up(&ps_adapter->LEDInfo.notify_led_event);
997         }
998
999         if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1000                 ps_adapter->DriverState = FW_DOWNLOAD;
1001                 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1002         }
1003
1004         value = 0;
1005         wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1006         wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1007
1008         if (ps_adapter->eNVMType == NVM_FLASH) {
1009                 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
1010                 if (status) {
1011                         BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Propagation of Cal param failed ..");
1012                         goto OUT;
1013                 }
1014         }
1015
1016         /* Download Firmare */
1017         status = BcmFileDownload(ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR);
1018         if (status != 0) {
1019                 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Firmware File is present...\n");
1020                 goto OUT;
1021         }
1022
1023         status = run_card_proc(ps_adapter);
1024         if (status) {
1025                 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "run_card_proc Failed\n");
1026                 goto OUT;
1027         }
1028
1029         ps_adapter->fw_download_done = TRUE;
1030         mdelay(10);
1031
1032 OUT:
1033         if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1034                 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1035                 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1036         }
1037
1038         return status;
1039 }
1040
1041 static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter)
1042 {
1043         struct file *flp = NULL;
1044         char *buff;
1045         int len = 0;
1046
1047         buff = kmalloc(BUFFER_1K, GFP_KERNEL);
1048         if (!buff)
1049                 return -ENOMEM;
1050
1051         Adapter->pstargetparams = kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL);
1052         if (Adapter->pstargetparams == NULL) {
1053                 kfree(buff);
1054                 return -ENOMEM;
1055         }
1056
1057         flp = open_firmware_file(Adapter, CFG_FILE);
1058         if (!flp) {
1059                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE\n", CFG_FILE);
1060                 kfree(buff);
1061                 kfree(Adapter->pstargetparams);
1062                 Adapter->pstargetparams = NULL;
1063                 return -ENOENT;
1064         }
1065         len = kernel_read(flp, 0, buff, BUFFER_1K);
1066         filp_close(flp, NULL);
1067
1068         if (len != sizeof(STARGETPARAMS)) {
1069                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n");
1070                 kfree(buff);
1071                 kfree(Adapter->pstargetparams);
1072                 Adapter->pstargetparams = NULL;
1073                 return -ENOENT;
1074         }
1075
1076         /* Check for autolink in config params */
1077         /*
1078          * Values in Adapter->pstargetparams are in network byte order
1079          */
1080         memcpy(Adapter->pstargetparams, buff, sizeof(STARGETPARAMS));
1081         kfree(buff);
1082         beceem_parse_target_struct(Adapter);
1083         return STATUS_SUCCESS;
1084 }
1085
1086 void beceem_parse_target_struct(struct bcm_mini_adapter *Adapter)
1087 {
1088         UINT uiHostDrvrCfg6 = 0, uiEEPROMFlag = 0;
1089
1090         if (ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE) {
1091                 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
1092                 Adapter->AutoSyncup = FALSE;
1093         } else {
1094                 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
1095                 Adapter->AutoSyncup = TRUE;
1096         }
1097
1098         if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE) {
1099                 pr_info(DRV_NAME ": Enabling autolink up");
1100                 Adapter->AutoLinkUp = TRUE;
1101         } else {
1102                 pr_info(DRV_NAME ": Disabling autolink up");
1103                 Adapter->AutoLinkUp = FALSE;
1104         }
1105         /* Setting the DDR Setting.. */
1106         Adapter->DDRSetting = (ntohl(Adapter->pstargetparams->HostDrvrConfig6) >> 8)&0x0F;
1107         Adapter->ulPowerSaveMode = (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
1108         pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1109         pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
1110         if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD) {
1111                 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1112                 Adapter->AutoFirmDld = TRUE;
1113         } else {
1114                 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1115                 Adapter->AutoFirmDld = FALSE;
1116         }
1117         uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1118         Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
1119         pr_info(DRV_NAME ": MIPSConfig   : 0x%X\n", Adapter->bMipsConfig);
1120         /* used for backward compatibility. */
1121         Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
1122         Adapter->PmuMode = (uiHostDrvrCfg6 >> 24) & 0x03;
1123         pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
1124
1125         if ((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT) & (0x01)) {
1126                 Adapter->bDoSuspend = TRUE;
1127                 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1128         }
1129
1130         uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
1131         pr_info(DRV_NAME ": uiEEPROMFlag  : 0x%X\n", uiEEPROMFlag);
1132         Adapter->eNVMType = (NVM_TYPE)((uiEEPROMFlag>>4)&0x3);
1133         Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
1134         Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
1135         Adapter->bSectorSizeOverride = (bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
1136
1137         if (ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x01)
1138                 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
1139
1140         if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1141                 doPowerAutoCorrection(Adapter);
1142 }
1143
1144 static VOID doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter)
1145 {
1146         UINT reporting_mode;
1147
1148         reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x02;
1149         psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1150
1151         if (reporting_mode == TRUE) {
1152                 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "can't do suspen/resume as reporting mode is enable");
1153                 psAdapter->bDoSuspend = FALSE;
1154         }
1155
1156         if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB)) {
1157                 /* If reporting mode is enable, switch PMU to PMC */
1158                 {
1159                         psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
1160                         psAdapter->bDoSuspend = FALSE;
1161                 }
1162
1163                 /* clearing space bit[15..12] */
1164                 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl((0xF << 12)));
1165                 /* placing the power save mode option */
1166                 psAdapter->pstargetparams->HostDrvrConfig6 |= htonl((psAdapter->ulPowerSaveMode << 12));
1167         } else if (psAdapter->bIsAutoCorrectEnabled == FALSE) {
1168                 /* remove the autocorrect disable bit set before dumping. */
1169                 psAdapter->ulPowerSaveMode &= ~(1 << 3);
1170                 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl(1 << 15));
1171                 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Using Forced User Choice: %lx\n", psAdapter->ulPowerSaveMode);
1172         }
1173 }
1174
1175 static void convertEndian(B_UINT8 rwFlag, PUINT puiBuffer, UINT uiByteCount)
1176 {
1177         UINT uiIndex = 0;
1178
1179         if (RWM_WRITE == rwFlag) {
1180                 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++)
1181                         puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
1182         } else {
1183                 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++)
1184                         puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
1185         }
1186 }
1187
1188 int rdm(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1189 {
1190         return Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
1191                                 uiAddress, pucBuff, sSize);
1192 }
1193
1194 int wrm(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1195 {
1196         int iRetVal;
1197
1198         iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
1199                                         uiAddress, pucBuff, sSize);
1200         return iRetVal;
1201 }
1202
1203 int wrmalt(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1204 {
1205         convertEndian(RWM_WRITE, pucBuff, size);
1206         return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1207 }
1208
1209 int rdmalt(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1210 {
1211         INT uiRetVal = 0;
1212
1213         uiRetVal = rdm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1214         convertEndian(RWM_READ, (PUINT)pucBuff, size);
1215
1216         return uiRetVal;
1217 }
1218
1219 int wrmWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1220 {
1221         INT status = STATUS_SUCCESS;
1222         down(&Adapter->rdmwrmsync);
1223
1224         if ((Adapter->IdleMode == TRUE) ||
1225                 (Adapter->bShutStatus == TRUE) ||
1226                 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1227
1228                 status = -EACCES;
1229                 goto exit;
1230         }
1231
1232         status = wrm(Adapter, uiAddress, pucBuff, sSize);
1233 exit:
1234         up(&Adapter->rdmwrmsync);
1235         return status;
1236 }
1237
1238 int wrmaltWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1239 {
1240         int iRetVal = STATUS_SUCCESS;
1241
1242         down(&Adapter->rdmwrmsync);
1243
1244         if ((Adapter->IdleMode == TRUE) ||
1245                 (Adapter->bShutStatus == TRUE) ||
1246                 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1247
1248                 iRetVal = -EACCES;
1249                 goto exit;
1250         }
1251
1252         iRetVal = wrmalt(Adapter, uiAddress, pucBuff, size);
1253 exit:
1254         up(&Adapter->rdmwrmsync);
1255         return iRetVal;
1256 }
1257
1258 int rdmaltWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1259 {
1260         INT uiRetVal = STATUS_SUCCESS;
1261
1262         down(&Adapter->rdmwrmsync);
1263         if ((Adapter->IdleMode == TRUE) ||
1264                 (Adapter->bShutStatus == TRUE) ||
1265                 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1266
1267                 uiRetVal = -EACCES;
1268                 goto exit;
1269         }
1270
1271         uiRetVal = rdmalt(Adapter, uiAddress, pucBuff, size);
1272 exit:
1273         up(&Adapter->rdmwrmsync);
1274         return uiRetVal;
1275 }
1276
1277 static VOID HandleShutDownModeWakeup(struct bcm_mini_adapter *Adapter)
1278 {
1279         int clear_abort_pattern = 0, Status = 0;
1280         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1281         /* target has woken up From Shut Down */
1282         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Clearing Shut Down Software abort pattern\n");
1283         Status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC, (PUINT)&clear_abort_pattern, sizeof(clear_abort_pattern));
1284         if (Status) {
1285                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
1286                 return;
1287         }
1288
1289         if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) {
1290                 msleep(100);
1291                 InterfaceHandleShutdownModeWakeup(Adapter);
1292                 msleep(100);
1293         }
1294
1295         if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1296                 Adapter->DriverState = NO_NETWORK_ENTRY;
1297                 wake_up(&Adapter->LEDInfo.notify_led_event);
1298         }
1299
1300         Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
1301         Adapter->bShutStatus = FALSE;
1302         wake_up(&Adapter->lowpower_mode_wait_queue);
1303         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1304 }
1305
1306 static VOID SendShutModeResponse(struct bcm_mini_adapter *Adapter)
1307 {
1308         struct bcm_link_request stShutdownResponse;
1309         UINT NVMAccess = 0, lowPwrAbortMsg = 0;
1310         UINT Status = 0;
1311
1312         memset(&stShutdownResponse, 0, sizeof(struct bcm_link_request));
1313         stShutdownResponse.Leader.Status  = LINK_UP_CONTROL_REQ;
1314         stShutdownResponse.Leader.PLength = 8; /* 8 bytes; */
1315         stShutdownResponse.szData[0] = LINK_UP_ACK;
1316         stShutdownResponse.szData[1] = LINK_SHUTDOWN_REQ_FROM_FIRMWARE;
1317
1318         /*********************************
1319          * down_trylock -
1320          * if [ semaphore is available ]
1321          *               acquire semaphone and return value 0 ;
1322          *   else
1323          *               return non-zero value ;
1324          *
1325          ***********************************/
1326
1327         NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1328         lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
1329
1330         if (NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) {
1331                 if (!NVMAccess)
1332                         up(&Adapter->NVMRdmWrmLock);
1333
1334                 if (!lowPwrAbortMsg)
1335                         up(&Adapter->LowPowerModeSync);
1336
1337                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Device Access is going on NACK the Shut Down MODE\n");
1338                 stShutdownResponse.szData[2] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
1339                 Adapter->bPreparingForLowPowerMode = FALSE;
1340         } else {
1341                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Sending SHUTDOWN MODE ACK\n");
1342                 stShutdownResponse.szData[2] = SHUTDOWN_ACK_FROM_DRIVER; /* ShutDown ACK */
1343
1344                 /* Wait for the LED to TURN OFF before sending ACK response */
1345                 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1346                         INT iRetVal = 0;
1347
1348                         /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1349                         Adapter->DriverState = LOWPOWER_MODE_ENTER;
1350                         wake_up(&Adapter->LEDInfo.notify_led_event);
1351
1352                         /* Wait for 1 SEC for LED to OFF */
1353                         iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
1354
1355                         /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
1356                         if (iRetVal <= 0) {
1357                                 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
1358                                 Adapter->DriverState = NO_NETWORK_ENTRY;
1359                                 wake_up(&Adapter->LEDInfo.notify_led_event);
1360                         }
1361                 }
1362
1363                 if (stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER) {
1364                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ACKING SHUTDOWN MODE !!!!!!!!!");
1365                         down(&Adapter->rdmwrmsync);
1366                         Adapter->bPreparingForLowPowerMode = TRUE;
1367                         up(&Adapter->rdmwrmsync);
1368                         /* Killing all URBS. */
1369                         if (Adapter->bDoSuspend == TRUE)
1370                                 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1371                 } else {
1372                         Adapter->bPreparingForLowPowerMode = FALSE;
1373                 }
1374
1375                 if (!NVMAccess)
1376                         up(&Adapter->NVMRdmWrmLock);
1377
1378                 if (!lowPwrAbortMsg)
1379                         up(&Adapter->LowPowerModeSync);
1380         }
1381
1382         Status = CopyBufferToControlPacket(Adapter, &stShutdownResponse);
1383         if ((Status != STATUS_SUCCESS)) {
1384                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "fail to send the Idle mode Request\n");
1385                 Adapter->bPreparingForLowPowerMode = FALSE;
1386                 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1387         }
1388 }
1389
1390 static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
1391 {
1392         B_UINT32 uiResetValue = 0;
1393
1394         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1395
1396         if (*(pucBuffer+1) ==  COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW) {
1397                 HandleShutDownModeWakeup(Adapter);
1398         } else if (*(pucBuffer+1) ==  LINK_SHUTDOWN_REQ_FROM_FIRMWARE) {
1399                 /* Target wants to go to Shut Down Mode */
1400                 /* InterfacePrepareForShutdown(Adapter); */
1401                 if (Adapter->chip_id == BCS220_2 ||
1402                         Adapter->chip_id == BCS220_2BC ||
1403                         Adapter->chip_id == BCS250_BC ||
1404                         Adapter->chip_id == BCS220_3) {
1405
1406                         rdmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1407                         uiResetValue |= (1<<17);
1408                         wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1409                 }
1410
1411                 SendShutModeResponse(Adapter);
1412                 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ShutDownModeResponse:Notification received: Sending the response(Ack/Nack)\n");
1413         }
1414
1415         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1416         return;
1417 }
1418
1419 VOID ResetCounters(struct bcm_mini_adapter *Adapter)
1420 {
1421         beceem_protocol_reset(Adapter);
1422         Adapter->CurrNumRecvDescs = 0;
1423         Adapter->PrevNumRecvDescs = 0;
1424         Adapter->LinkUpStatus = 0;
1425         Adapter->LinkStatus = 0;
1426         atomic_set(&Adapter->cntrlpktCnt, 0);
1427         atomic_set(&Adapter->TotalPacketCount, 0);
1428         Adapter->fw_download_done = FALSE;
1429         Adapter->LinkStatus = 0;
1430         Adapter->AutoLinkUp = FALSE;
1431         Adapter->IdleMode = FALSE;
1432         Adapter->bShutStatus = FALSE;
1433 }
1434
1435 struct bcm_classifier_rule *GetFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIP)
1436 {
1437         UINT uiIndex = 0;
1438         for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1439                 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1440                         (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1441                         (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIP) &&
1442                         !Adapter->astFragmentedPktClassifierTable[uiIndex].bOutOfOrderFragment)
1443
1444                         return Adapter->astFragmentedPktClassifierTable[uiIndex].pstMatchedClassifierEntry;
1445         }
1446         return NULL;
1447 }
1448
1449 void AddFragIPClsEntry(struct bcm_mini_adapter *Adapter, struct bcm_fragmented_packet_info *psFragPktInfo)
1450 {
1451         UINT uiIndex = 0;
1452         for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1453                 if (!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) {
1454                         memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex], psFragPktInfo, sizeof(struct bcm_fragmented_packet_info));
1455                         break;
1456                 }
1457         }
1458 }
1459
1460 void DelFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIp)
1461 {
1462         UINT uiIndex = 0;
1463         for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1464                 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1465                         (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1466                         (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIp))
1467
1468                         memset(&Adapter->astFragmentedPktClassifierTable[uiIndex], 0, sizeof(struct bcm_fragmented_packet_info));
1469         }
1470 }
1471
1472 void update_per_cid_rx(struct bcm_mini_adapter *Adapter)
1473 {
1474         UINT qindex = 0;
1475
1476         if ((jiffies - Adapter->liDrainCalculated) < XSECONDS)
1477                 return;
1478
1479         for (qindex = 0; qindex < HiPriority; qindex++) {
1480                 if (Adapter->PackInfo[qindex].ucDirection == 0) {
1481                         Adapter->PackInfo[qindex].uiCurrentRxRate =
1482                                 (Adapter->PackInfo[qindex].uiCurrentRxRate +
1483                                         Adapter->PackInfo[qindex].uiThisPeriodRxBytes) / 2;
1484
1485                         Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
1486                 } else {
1487                         Adapter->PackInfo[qindex].uiCurrentDrainRate =
1488                                 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
1489                                         Adapter->PackInfo[qindex].uiThisPeriodSentBytes) / 2;
1490                         Adapter->PackInfo[qindex].uiThisPeriodSentBytes = 0;
1491                 }
1492         }
1493         Adapter->liDrainCalculated = jiffies;
1494 }
1495
1496 void update_per_sf_desc_cnts(struct bcm_mini_adapter *Adapter)
1497 {
1498         INT iIndex = 0;
1499         u32 uibuff[MAX_TARGET_DSX_BUFFERS];
1500         int bytes;
1501
1502         if (!atomic_read(&Adapter->uiMBupdate))
1503                 return;
1504
1505         bytes = rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (PUINT)uibuff, sizeof(UINT) * MAX_TARGET_DSX_BUFFERS);
1506         if (bytes < 0) {
1507                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
1508                 return;
1509         }
1510
1511         for (iIndex = 0; iIndex < HiPriority; iIndex++) {
1512                 if (Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection) {
1513                         if (Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
1514                                 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
1515                         else
1516                                 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid VCID : %x\n", Adapter->PackInfo[iIndex].usVCID_Value);
1517                 }
1518         }
1519         atomic_set(&Adapter->uiMBupdate, FALSE);
1520 }
1521
1522 void flush_queue(struct bcm_mini_adapter *Adapter, UINT iQIndex)
1523 {
1524         struct sk_buff *PacketToDrop = NULL;
1525         struct net_device_stats *netstats = &Adapter->dev->stats;
1526         spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1527
1528         while (Adapter->PackInfo[iQIndex].FirstTxQueue && atomic_read(&Adapter->TotalPacketCount)) {
1529                 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
1530                 if (PacketToDrop && PacketToDrop->len) {
1531                         netstats->tx_dropped++;
1532                         DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, Adapter->PackInfo[iQIndex].LastTxQueue);
1533                         Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1534                         Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1535
1536                         /* Adding dropped statistics */
1537                         Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1538                         Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
1539                         dev_kfree_skb(PacketToDrop);
1540                         atomic_dec(&Adapter->TotalPacketCount);
1541                 }
1542         }
1543         spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1544 }
1545
1546 static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter)
1547 {
1548         int i;
1549         if (netif_msg_link(Adapter))
1550                 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
1551
1552         netif_carrier_off(Adapter->dev);
1553         netif_stop_queue(Adapter->dev);
1554
1555         Adapter->IdleMode = FALSE;
1556         Adapter->LinkUpStatus = FALSE;
1557         ClearTargetDSXBuffer(Adapter, 0, TRUE);
1558         /* Delete All Classifier Rules */
1559
1560         for (i = 0; i < HiPriority; i++)
1561                 DeleteAllClassifiersForSF(Adapter, i);
1562
1563         flush_all_queues(Adapter);
1564
1565         if (Adapter->TimerActive == TRUE)
1566                 Adapter->TimerActive = FALSE;
1567
1568         memset(Adapter->astFragmentedPktClassifierTable, 0, sizeof(struct bcm_fragmented_packet_info) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
1569
1570         for (i = 0; i < HiPriority; i++) {
1571                 /* resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF. */
1572                 /* It is same between MIBs and SF. */
1573                 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable, 0, sizeof(S_MIBS_EXTSERVICEFLOW_PARAMETERS));
1574         }
1575 }