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