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