3 static int BcmFileDownload(PMINI_ADAPTER Adapter, const char *path,
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);
10 static VOID default_wimax_protocol_initialize(PMINI_ADAPTER Adapter)
15 for(uiLoopIndex=0; uiLoopIndex < NO_OF_QUEUES-1; uiLoopIndex++)
17 Adapter->PackInfo[uiLoopIndex].uiThreshold=TX_PACKET_THRESHOLD;
18 Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate=MAX_ALLOWED_RATE;
19 Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize=20*1024*1024;
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;
32 InitAdapter(PMINI_ADAPTER psAdapter)
35 INT Status = STATUS_SUCCESS ;
36 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Initialising Adapter = %p", psAdapter);
40 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Adapter is NULL");
44 sema_init(&psAdapter->NVMRdmWrmLock,1);
45 // psAdapter->ulFlashCalStart = FLASH_AUTO_INIT_BASE_ADDR;
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);
55 // spin_lock_init(&psAdapter->sleeper_lock);
57 for(i=0;i<NO_OF_QUEUES; i++)
58 spin_lock_init(&psAdapter->PackInfo[i].SFQueueLock);
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;
71 default_wimax_protocol_initialize(psAdapter);
72 for (i=0;i<MAX_CNTRL_PKTS;i++)
74 psAdapter->txctlpacket[i] = kmalloc(MAX_CNTL_PKT_SIZE, GFP_KERNEL);
75 if(!psAdapter->txctlpacket[i])
77 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No More Cntl pkts got, max got is %d", i);
81 if(AllocAdapterDsxBuffer(psAdapter))
83 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to allocate DSX buffers");
87 //Initialize PHS interface
88 if(phs_init(&psAdapter->stBCMPhsContext,psAdapter)!=0)
90 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"%s:%s:%d:Error PHS Init Failed=====>\n", __FILE__, __FUNCTION__, __LINE__);
94 Status = BcmAllocFlashCSStructure(psAdapter);
97 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Memory Allocation for Flash structure failed");
101 Status = vendorextnInit(psAdapter);
103 if(STATUS_SUCCESS != Status)
105 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Vendor Init Failed");
109 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Adapter initialised");
112 return STATUS_SUCCESS;
115 VOID AdapterFree(PMINI_ADAPTER Adapter)
119 beceem_protocol_reset(Adapter);
121 vendorextnExit(Adapter);
123 if(Adapter->control_packet_handler && !IS_ERR(Adapter->control_packet_handler))
124 kthread_stop (Adapter->control_packet_handler);
126 if(Adapter->transmit_packet_thread && !IS_ERR(Adapter->transmit_packet_thread))
127 kthread_stop (Adapter->transmit_packet_thread);
129 wake_up(&Adapter->process_read_wait_queue);
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);
134 unregister_networkdev(Adapter);
136 /* FIXME: use proper wait_event and refcounting */
137 while(atomic_read(&Adapter->ApplicationRunning))
139 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Waiting for Application to close.. %d\n",atomic_read(&Adapter->ApplicationRunning));
142 unregister_control_device_interface(Adapter);
144 kfree(Adapter->pstargetparams);
146 for (count =0;count < MAX_CNTRL_PKTS;count++)
147 kfree(Adapter->txctlpacket[count]);
149 FreeAdapterDsxBuffer(Adapter);
151 kfree(Adapter->pvInterfaceAdapter);
153 //Free the PHS Interface
154 PhsCleanup(&Adapter->stBCMPhsContext);
156 BcmDeAllocFlashCSStructure(Adapter);
158 free_netdev(Adapter->dev);
161 static int create_worker_threads(PMINI_ADAPTER psAdapter)
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))
168 pr_notice(DRV_NAME ": could not create control thread\n");
169 return PTR_ERR(psAdapter->control_packet_handler);
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))
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);
184 static struct file *open_firmware_file(PMINI_ADAPTER Adapter, const char *path)
186 struct file *flp=NULL;
190 flp=filp_open(path, O_RDONLY, S_IRWXU);
194 pr_err(DRV_NAME "Unable To Open File %s, err %ld",
199 if(Adapter->device_removed)
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*/
212 struct file *flp=NULL;
214 struct timeval tv={0};
216 flp=open_firmware_file(Adapter, path);
220 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Unable to Open %s\n", path);
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);
226 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "download start %lx", ((tv.tv_sec * 1000) +
228 if(Adapter->bcm_file_download(Adapter->pvInterfaceAdapter, flp, loc))
230 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to download the firmware with error\
235 oldfs=get_fs();set_fs(get_ds());
236 vfs_llseek(flp, 0, 0);
238 if(Adapter->bcm_file_readback_from_chip(Adapter->pvInterfaceAdapter,
241 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to read back firmware!");
247 oldfs=get_fs();set_fs(get_ds());
248 if(flp && !(IS_ERR(flp)))
249 filp_close(flp, current->files);
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.
262 INT CopyBufferToControlPacket(PMINI_ADAPTER Adapter,/**<Logical Adapter*/
263 PVOID ioBuffer/**<Control Packet Buffer*/
266 PLEADER pLeader=NULL;
268 unsigned char *ctrl_buff=NULL;
270 PLINK_REQUEST pLinkReq = NULL;
271 PUCHAR pucAddIndication = NULL;
273 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "======>");
276 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Got Null Buffer\n");
280 pLinkReq = (PLINK_REQUEST)ioBuffer;
281 pLeader=(PLEADER)ioBuffer; //ioBuffer Contains sw_Status and Payload
283 if(Adapter->bShutStatus == TRUE &&
284 pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD &&
285 pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE)
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;
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
297 if(Adapter->LinkStatus > PHY_SYNC_ACHIVED)
299 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL,"LinkStatus is Greater than PHY_SYN_ACHIEVED");
300 return STATUS_FAILURE;
302 if(TRUE == Adapter->bShutStatus)
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)
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);
312 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
313 !Adapter->bShutStatus, (5 * HZ));
315 if(Status == -ERESTARTSYS)
318 if(Adapter->bShutStatus)
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;
326 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Wakeup has been tried already...\n");
331 if(TRUE == Adapter->IdleMode)
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 )
338 if((pLeader->Status == LINK_UP_CONTROL_REQ) && (pLinkReq->szData[0]==LINK_DOWN_REQ_PAYLOAD))
340 if((pLinkReq->szData[1] == LINK_SYNC_DOWN_SUBTYPE))
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
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;
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;
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);
365 if(LINK_DOWN_REQ_PAYLOAD == pLinkReq->szData[0])
367 // We should not send DREG message down while in idlemode.
368 return STATUS_SUCCESS;
371 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
372 !Adapter->IdleMode, (5 * HZ));
374 if(Status == -ERESTARTSYS)
377 if(Adapter->IdleMode)
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;
384 return STATUS_SUCCESS;
386 //The Driver has to send control messages with a particular VCID
387 pLeader->Vcid = VCID_CONTROL_PACKET;//VCID for control packet.
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];
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);
399 if((pLeader->Status == 0x80) ||
400 (pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ))
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.
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);
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;
418 //update the leader to use the new length
419 //The length of the control packet is length of message being sent + Leader length
421 pLeader->PLength = pktlen;
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");
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);
437 Adapter->PackInfo[HiPriority].bValid = TRUE;
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);
452 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "mem allocation Failed");
454 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<====");
459 /*****************************************************************
460 * Function - SendStatisticsPointerRequest()
462 * Description - This function builds and forwards the Statistics
463 * Pointer Request control Packet.
465 * Parameters - Adapter : Pointer to Adapter structure.
466 * - pstStatisticsPtrRequest : Pointer to link request.
469 *****************************************************************/
470 static VOID SendStatisticsPointerRequest(PMINI_ADAPTER Adapter,
471 PLINK_REQUEST pstStatisticsPtrRequest)
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;
478 CopyBufferToControlPacket(Adapter,pstStatisticsPtrRequest);
479 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "<=====");
485 /******************************************************************
486 * Function - LinkMessage()
488 * Description - This function builds the Sync-up and Link-up request
489 * packet messages depending on the device Link status.
491 * Parameters - Adapter: Pointer to the Adapter structure.
494 *******************************************************************/
495 VOID LinkMessage(PMINI_ADAPTER Adapter)
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)
501 pstLinkRequest=kmalloc(sizeof(LINK_REQUEST), GFP_ATOMIC);
504 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
507 memset(pstLinkRequest,0,sizeof(LINK_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;
517 else if(Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp)
519 pstLinkRequest=kmalloc(sizeof(LINK_REQUEST), GFP_ATOMIC);
522 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
525 memset(pstLinkRequest,0,sizeof(LINK_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);
535 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
536 CopyBufferToControlPacket(Adapter, pstLinkRequest);
537 kfree(pstLinkRequest);
539 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
544 /**********************************************************************
545 * Function - StatisticsResponse()
547 * Description - This function handles the Statistics response packet.
549 * Parameters - Adapter : Pointer to the Adapter structure.
550 * - pvBuffer: Starting address of Statistic response data.
553 ************************************************************************/
554 VOID StatisticsResponse(PMINI_ADAPTER Adapter,PVOID pvBuffer)
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__);
564 /**********************************************************************
565 * Function - LinkControlResponseMessage()
567 * Description - This function handles the Link response packets.
569 * Parameters - Adapter : Pointer to the Adapter structure.
570 * - pucBuffer: Starting address of Link response data.
573 ***********************************************************************/
574 VOID LinkControlResponseMessage(PMINI_ADAPTER Adapter,PUCHAR pucBuffer)
576 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
578 if(*pucBuffer==LINK_UP_ACK)
580 switch(*(pucBuffer+1))
582 case PHY_SYNC_ACHIVED: //SYNCed UP
583 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "PHY_SYNC_ACHIVED");
585 if(Adapter->LinkStatus == LINKUP_DONE)
587 beceem_protocol_reset(Adapter);
590 Adapter->usBestEffortQueueIndex=INVALID_QUEUE_INDEX ;
591 Adapter->LinkStatus=PHY_SYNC_ACHIVED;
593 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
595 Adapter->DriverState = NO_NETWORK_ENTRY;
596 wake_up(&Adapter->LEDInfo.notify_led_event);
599 LinkMessage(Adapter);
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))
611 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
613 Adapter->DriverState = NORMAL_OPERATION;
614 wake_up(&Adapter->LEDInfo.notify_led_event);
617 LinkMessage(Adapter);
622 * Driver to ignore the DREG_RECEIVED
623 * WiMAX Application should handle this Message
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);
634 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
635 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
637 HandleShutDownModeRequest(Adapter, pucBuffer);
641 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x",*(pucBuffer+1));
645 else if(SET_MAC_ADDRESS_RESPONSE==*pucBuffer)
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);
653 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====",__FUNCTION__);
657 void SendIdleModeResponse(PMINI_ADAPTER Adapter)
659 INT status = 0, NVMAccess = 0,lowPwrAbortMsg = 0;
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," ============>");
668 /*********************************
670 ** if [ semaphore is available ]
671 ** acquire semaphone and return value 0 ;
673 ** return non-zero value ;
675 ***********************************/
677 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
679 lowPwrAbortMsg= down_trylock(&Adapter->LowPowerModeSync);
682 if((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
683 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) )
686 up(&Adapter->NVMRdmWrmLock);
689 up(&Adapter->LowPowerModeSync);
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;
697 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; //2;//Idle ACK
698 Adapter->StatisticsPointer = 0;
700 /* Wait for the LED to TURN OFF before sending ACK response */
701 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
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);
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));
715 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
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!!!!!!!!");
724 if(stIdleResponse.szData[1] == TARGET_CAN_GO_TO_IDLE_MODE)
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);
731 if(Adapter->bDoSuspend == TRUE)
732 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
737 Adapter->bPreparingForLowPowerMode = FALSE;
741 up(&Adapter->NVMRdmWrmLock);
744 up(&Adapter->LowPowerModeSync);
747 status = CopyBufferToControlPacket(Adapter,&stIdleResponse);
748 if((status != STATUS_SUCCESS))
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));
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);
759 /******************************************************************
760 * Function - DumpPackInfo()
762 * Description - This function dumps the all Queue(PackInfo[]) details.
764 * Parameters - Adapter: Pointer to the Adapter structure.
767 *******************************************************************/
768 VOID DumpPackInfo(PMINI_ADAPTER Adapter)
771 UINT uiLoopIndex = 0;
773 UINT uiClsfrIndex = 0;
774 S_CLASSIFIER_RULE *pstClassifierEntry = NULL;
776 for(uiLoopIndex=0;uiLoopIndex<NO_OF_QUEUES;uiLoopIndex++)
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)
781 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"bValid is FALSE for %X index\n",uiLoopIndex);
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)
789 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Ipv6 Service Flow \n");
793 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Ipv4 Service Flow \n");
795 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL," SF Traffic Priority %X \n",Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
797 for(uiClsfrIndex=0;uiClsfrIndex<MAX_CLASSIFIERS;uiClsfrIndex++)
799 pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
800 if(!pstClassifierEntry->bUsed)
803 if(pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
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);
814 for(uiIndex=0;uiIndex<MAX_PORT_RANGE;uiIndex++)
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]);
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++)
826 if(Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
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);
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]);
839 for(uiIndex=0;uiIndex<pstClassifierEntry->ucIPDestinationAddressLength;uiIndex++)
841 if(Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
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);
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]);
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);
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);
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));
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]);
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]);
919 int reset_card_proc(PMINI_ADAPTER ps_adapter)
921 int retval = STATUS_SUCCESS;
923 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
924 PS_INTERFACE_ADAPTER psIntfAdapter = NULL;
925 unsigned int value = 0, uiResetValue = 0;
927 psIntfAdapter = ((PS_INTERFACE_ADAPTER)(ps_adapter->pvInterfaceAdapter)) ;
929 ps_adapter->bDDRInitDone = FALSE;
931 if(ps_adapter->chip_id >= T3LPB)
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));
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));
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)
949 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Reseting UMA-B \n");
950 retval = usb_reset_device(psIntfAdapter->udev);
952 psIntfAdapter->psAdapter->StopAllXaction = FALSE ;
954 if(retval != STATUS_SUCCESS)
956 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
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)
964 retval = rdmalt(ps_adapter,HPM_CONFIG_LDO145, &value, sizeof(value));
967 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"read failed with status :%d",retval);
972 retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
975 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
983 retval = rdmalt(ps_adapter,0x0f007018, &value, sizeof(value));
985 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"read failed with status :%d",retval);
989 retval= wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value)) ;
991 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
995 // Toggling the GPIO 8, 9
997 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
999 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
1003 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value)) ;
1005 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
1011 //ps_adapter->downloadDDR = false;
1013 if(ps_adapter->bFlashBoot)
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));
1020 uiResetValue |=(1<<30);
1021 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
1024 if(ps_adapter->chip_id >= T3LPB)
1028 // WA for SYSConfig Issue.
1029 // Read SYSCFG Twice to make it writable.
1031 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
1032 if(uiResetValue & (1<<4))
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));
1042 wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
1045 psIntfAdapter->psAdapter->StopAllXaction = FALSE ;
1049 int run_card_proc(PMINI_ADAPTER ps_adapter )
1051 unsigned int value=0;
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;
1059 if(ps_adapter->bFlashBoot)
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;
1074 return STATUS_SUCCESS;
1077 int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter)
1083 * Create the threads first and then download the
1084 * Firm/DDR Settings..
1087 status = create_worker_threads(ps_adapter);
1092 * For Downloading the Firm, parse the cfg file first.
1094 status = bcm_parse_target_params (ps_adapter);
1099 if(ps_adapter->chip_id >= T3LPB)
1101 rdmalt(ps_adapter, SYS_CFG, &value, sizeof (value));
1102 ps_adapter->syscfgBefFwDld = value ;
1103 if((value & 0x60)== 0)
1105 ps_adapter->bFlashBoot = TRUE;
1109 reset_card_proc(ps_adapter);
1111 //Initializing the NVM.
1112 BcmInitNVM(ps_adapter);
1113 status = ddr_init(ps_adapter);
1116 pr_err(DRV_NAME "ddr_init Failed\n");
1120 /* Download cfg file */
1121 status = buffDnldVerify(ps_adapter,
1122 (PUCHAR)ps_adapter->pstargetparams,
1123 sizeof(STARGETPARAMS),
1127 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
1131 if(register_networkdev(ps_adapter))
1133 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
1137 if(FALSE == ps_adapter->AutoFirmDld)
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)
1144 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
1148 return STATUS_SUCCESS;
1152 * Do the LED Settings here. It will be used by the Firmware Download
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.
1162 status = InitLedSettings (ps_adapter);
1166 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_PRINTK, 0, 0,"INIT LED FAILED\n");
1169 if(ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1171 ps_adapter->DriverState = DRIVER_INIT;
1172 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1175 if(ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1177 ps_adapter->DriverState = FW_DOWNLOAD;
1178 wake_up(&ps_adapter->LEDInfo.notify_led_event);
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));
1185 if(ps_adapter->eNVMType == NVM_FLASH)
1187 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
1190 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL," Propogation of Cal param failed .." );
1195 /* Download Firmare */
1196 if ((status = BcmFileDownload( ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR)))
1198 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Firmware File is present... \n");
1202 status = run_card_proc(ps_adapter);
1205 BCM_DEBUG_PRINT (ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "run_card_proc Failed\n");
1210 ps_adapter->fw_download_done = TRUE;
1214 if(ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1216 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1217 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1224 static int bcm_parse_target_params(PMINI_ADAPTER Adapter)
1226 struct file *flp=NULL;
1227 mm_segment_t oldfs={0};
1232 buff=kmalloc(BUFFER_1K, GFP_KERNEL);
1237 if((Adapter->pstargetparams =
1238 kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL)) == NULL)
1243 flp=open_firmware_file(Adapter, CFG_FILE);
1245 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE \n", CFG_FILE);
1247 kfree(Adapter->pstargetparams);
1248 Adapter->pstargetparams = NULL;
1251 oldfs=get_fs(); set_fs(get_ds());
1252 len=vfs_read(flp, (void __user __force *)buff, BUFFER_1K, &pos);
1255 if(len != sizeof(STARGETPARAMS))
1257 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Mismatch in Target Param Structure!\n");
1259 kfree(Adapter->pstargetparams);
1260 Adapter->pstargetparams = NULL;
1261 filp_close(flp, current->files);
1264 filp_close(flp, current->files);
1266 /* Check for autolink in config params */
1268 * Values in Adapter->pstargetparams are in network byte order
1270 memcpy(Adapter->pstargetparams, buff, sizeof(STARGETPARAMS));
1272 beceem_parse_target_struct(Adapter);
1273 return STATUS_SUCCESS;
1276 void beceem_parse_target_struct(PMINI_ADAPTER Adapter)
1278 UINT uiHostDrvrCfg6 =0, uiEEPROMFlag = 0;
1280 if(ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE)
1282 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
1283 Adapter->AutoSyncup = FALSE;
1287 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
1288 Adapter->AutoSyncup = TRUE;
1291 if(ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE)
1293 pr_info(DRV_NAME ": Enabling autolink up");
1294 Adapter->AutoLinkUp = TRUE;
1298 pr_info(DRV_NAME ": Disabling autolink up");
1299 Adapter->AutoLinkUp = FALSE;
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;
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)
1311 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1312 Adapter->AutoFirmDld = TRUE;
1316 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1317 Adapter->AutoFirmDld = FALSE;
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;
1325 Adapter->PmuMode= (uiHostDrvrCfg6 >> 24 ) & 0x03;
1326 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
1328 if((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT ) & (0x01))
1330 Adapter->bDoSuspend = TRUE;
1331 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
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);
1338 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
1340 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
1342 Adapter->bSectorSizeOverride =(bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
1344 if(ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) &0x01)
1345 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
1347 if(Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1348 doPowerAutoCorrection(Adapter);
1352 static VOID doPowerAutoCorrection(PMINI_ADAPTER psAdapter)
1354 UINT reporting_mode;
1356 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) &0x02 ;
1357 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1359 if(reporting_mode == TRUE)
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;
1365 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB))
1367 //If reporting mode is enable, switch PMU to PMC
1369 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
1370 psAdapter->bDoSuspend =FALSE;
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));
1380 else if (psAdapter->bIsAutoCorrectEnabled == FALSE)
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);
1391 static unsigned char *ReadMacAddrEEPROM(PMINI_ADAPTER Adapter, ulong dwAddress)
1393 int status = 0, i = 0;
1394 unsigned int temp = 0;
1395 unsigned char *pucmacaddr = kmalloc(MAC_ADDRESS_SIZE, GFP_KERNEL);
1399 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "No Buffers to Read the EEPROM Address\n");
1403 dwAddress |= 0x5b000000;
1404 status = wrmalt(Adapter, EEPROM_COMMAND_Q_REG,
1405 (PUINT)&dwAddress, sizeof(UINT));
1406 if(status != STATUS_SUCCESS)
1408 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "wrm Failed..\n");
1413 for(i=0;i<MAC_ADDRESS_SIZE;i++)
1415 status = rdmalt(Adapter, EEPROM_READ_DATA_Q_REG, &temp,sizeof(temp));
1416 if(status != STATUS_SUCCESS)
1418 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm Failed..\n");
1423 pucmacaddr[i] = temp & 0xff;
1424 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"%x \n", pucmacaddr[i]);
1432 static void convertEndian(B_UINT8 rwFlag, PUINT puiBuffer, UINT uiByteCount)
1436 if(RWM_WRITE == rwFlag) {
1437 for(uiIndex =0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++) {
1438 puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
1441 for(uiIndex =0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++) {
1442 puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
1447 #define CACHE_ADDRESS_MASK 0x80000000
1448 #define UNCACHE_ADDRESS_MASK 0xa0000000
1450 int rdm(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1454 uiRetVal = Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
1455 uiAddress, pucBuff, sSize);
1462 int wrm(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1466 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
1467 uiAddress, pucBuff, sSize);
1473 int wrmalt (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1475 convertEndian(RWM_WRITE, pucBuff, size);
1476 return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1479 int rdmalt (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1483 uiRetVal = rdm(Adapter,uiAddress,(PUCHAR)pucBuff,size);
1484 convertEndian(RWM_READ, (PUINT)pucBuff, size);
1490 int wrmWithLock(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1492 INT status = STATUS_SUCCESS ;
1493 down(&Adapter->rdmwrmsync);
1495 if((Adapter->IdleMode == TRUE) ||
1496 (Adapter->bShutStatus ==TRUE) ||
1497 (Adapter->bPreparingForLowPowerMode ==TRUE))
1503 status =wrm(Adapter, uiAddress, pucBuff, sSize);
1506 up(&Adapter->rdmwrmsync);
1510 int wrmaltWithLock (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1512 int iRetVal = STATUS_SUCCESS;
1514 down(&Adapter->rdmwrmsync);
1516 if((Adapter->IdleMode == TRUE) ||
1517 (Adapter->bShutStatus ==TRUE) ||
1518 (Adapter->bPreparingForLowPowerMode ==TRUE))
1524 iRetVal = wrmalt(Adapter,uiAddress,pucBuff,size);
1527 up(&Adapter->rdmwrmsync);
1531 int rdmaltWithLock (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1533 INT uiRetVal =STATUS_SUCCESS;
1535 down(&Adapter->rdmwrmsync);
1537 if((Adapter->IdleMode == TRUE) ||
1538 (Adapter->bShutStatus ==TRUE) ||
1539 (Adapter->bPreparingForLowPowerMode ==TRUE))
1545 uiRetVal = rdmalt(Adapter,uiAddress, pucBuff, size);
1548 up(&Adapter->rdmwrmsync);
1553 static VOID HandleShutDownModeWakeup(PMINI_ADAPTER Adapter)
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));
1562 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
1565 if(Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1568 InterfaceHandleShutdownModeWakeup(Adapter);
1571 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1573 Adapter->DriverState = NO_NETWORK_ENTRY;
1574 wake_up(&Adapter->LEDInfo.notify_led_event);
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");
1583 static VOID SendShutModeResponse(PMINI_ADAPTER Adapter)
1585 CONTROL_MESSAGE stShutdownResponse;
1586 UINT NVMAccess = 0,lowPwrAbortMsg = 0;
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;
1595 /*********************************
1597 ** if [ semaphore is available ]
1598 ** acquire semaphone and return value 0 ;
1600 ** return non-zero value ;
1602 ***********************************/
1604 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1606 lowPwrAbortMsg= down_trylock(&Adapter->LowPowerModeSync);
1609 if(NVMAccess || lowPwrAbortMsg|| atomic_read(&Adapter->TotalPacketCount))
1612 up(&Adapter->NVMRdmWrmLock);
1615 up(&Adapter->LowPowerModeSync);
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;
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
1626 /* Wait for the LED to TURN OFF before sending ACK response */
1627 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1631 /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1632 Adapter->DriverState = LOWPOWER_MODE_ENTER;
1633 wake_up(&Adapter->LEDInfo.notify_led_event);
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));
1639 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
1642 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER;//NACK- device access is going on.
1644 Adapter->DriverState = NO_NETWORK_ENTRY;
1645 wake_up(&Adapter->LEDInfo.notify_led_event);
1649 if(stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER)
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);
1656 if(Adapter->bDoSuspend == TRUE)
1657 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1661 Adapter->bPreparingForLowPowerMode = FALSE;
1665 up(&Adapter->NVMRdmWrmLock);
1668 up(&Adapter->LowPowerModeSync);
1670 Status = CopyBufferToControlPacket(Adapter,&stShutdownResponse);
1671 if((Status != STATUS_SUCCESS))
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;
1676 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1681 static void HandleShutDownModeRequest(PMINI_ADAPTER Adapter,PUCHAR pucBuffer)
1683 B_UINT32 uiResetValue = 0;
1685 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1687 if(*(pucBuffer+1) == COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW)
1689 HandleShutDownModeWakeup(Adapter);
1691 else if(*(pucBuffer+1) == LINK_SHUTDOWN_REQ_FROM_FIRMWARE)
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)
1700 rdmalt(Adapter,HPM_CONFIG_MSW, &uiResetValue, 4);
1701 uiResetValue |= (1<<17);
1702 wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
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");
1709 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1714 VOID ResetCounters(PMINI_ADAPTER Adapter)
1717 beceem_protocol_reset(Adapter);
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;
1732 S_CLASSIFIER_RULE *GetFragIPClsEntry(PMINI_ADAPTER Adapter,USHORT usIpIdentification,ULONG SrcIP)
1735 for(uiIndex=0;uiIndex<MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES;uiIndex++)
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;
1746 void AddFragIPClsEntry(PMINI_ADAPTER Adapter,PS_FRAGMENTED_PACKET_INFO psFragPktInfo)
1749 for(uiIndex=0;uiIndex<MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES;uiIndex++)
1751 if(!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed)
1753 memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex],psFragPktInfo,sizeof(S_FRAGMENTED_PACKET_INFO));
1760 void DelFragIPClsEntry(PMINI_ADAPTER Adapter,USHORT usIpIdentification,ULONG SrcIp)
1763 for(uiIndex=0;uiIndex<MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES;uiIndex++)
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));
1772 void update_per_cid_rx (PMINI_ADAPTER Adapter)
1776 if((jiffies - Adapter->liDrainCalculated) < XSECONDS)
1779 for(qindex = 0; qindex < HiPriority; qindex++)
1781 if(Adapter->PackInfo[qindex].ucDirection == 0)
1783 Adapter->PackInfo[qindex].uiCurrentRxRate =
1784 (Adapter->PackInfo[qindex].uiCurrentRxRate +
1785 Adapter->PackInfo[qindex].uiThisPeriodRxBytes)/2;
1787 Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
1791 Adapter->PackInfo[qindex].uiCurrentDrainRate =
1792 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
1793 Adapter->PackInfo[qindex].uiThisPeriodSentBytes)/2;
1795 Adapter->PackInfo[qindex].uiThisPeriodSentBytes=0;
1798 Adapter->liDrainCalculated=jiffies;
1800 void update_per_sf_desc_cnts( PMINI_ADAPTER Adapter)
1803 u32 uibuff[MAX_TARGET_DSX_BUFFERS];
1805 if(!atomic_read (&Adapter->uiMBupdate))
1808 if(rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (PUINT)uibuff, sizeof(UINT) * MAX_TARGET_DSX_BUFFERS)<0)
1810 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
1813 for(iIndex = 0;iIndex < HiPriority; iIndex++)
1815 if(Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection)
1817 if(Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
1819 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
1823 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Invalid VCID : %x \n",
1824 Adapter->PackInfo[iIndex].usVCID_Value);
1828 atomic_set (&Adapter->uiMBupdate, FALSE);
1831 void flush_queue(PMINI_ADAPTER Adapter, UINT iQIndex)
1833 struct sk_buff* PacketToDrop=NULL;
1834 struct net_device_stats* netstats = &Adapter->dev->stats;
1836 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1838 while(Adapter->PackInfo[iQIndex].FirstTxQueue &&
1839 atomic_read(&Adapter->TotalPacketCount))
1841 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
1842 if(PacketToDrop && PacketToDrop->len)
1844 netstats->tx_dropped++;
1845 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, \
1846 Adapter->PackInfo[iQIndex].LastTxQueue);
1848 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1849 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1851 //Adding dropped statistics
1852 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1853 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
1855 dev_kfree_skb(PacketToDrop);
1856 atomic_dec(&Adapter->TotalPacketCount);
1859 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1863 static void beceem_protocol_reset (PMINI_ADAPTER Adapter)
1867 if (netif_msg_link(Adapter))
1868 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
1870 netif_carrier_off(Adapter->dev);
1871 netif_stop_queue(Adapter->dev);
1873 Adapter->IdleMode = FALSE;
1874 Adapter->LinkUpStatus = FALSE;
1875 ClearTargetDSXBuffer(Adapter,0, TRUE);
1876 //Delete All Classifier Rules
1878 for(i = 0;i<HiPriority;i++)
1880 DeleteAllClassifiersForSF(Adapter,i);
1883 flush_all_queues(Adapter);
1885 if(Adapter->TimerActive == TRUE)
1886 Adapter->TimerActive = FALSE;
1888 memset(Adapter->astFragmentedPktClassifierTable, 0,
1889 sizeof(S_FRAGMENTED_PACKET_INFO) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
1891 for(i = 0;i<HiPriority;i++)
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));