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