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