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