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 = kzalloc(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!");
508 Adapter->LinkStatus = WAIT_FOR_SYNC;// current link status
509 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For SyncUp...");
510 pstLinkRequest->szData[0]=LINK_UP_REQ_PAYLOAD;
511 pstLinkRequest->szData[1]=LINK_SYNC_UP_SUBTYPE;
512 pstLinkRequest->Leader.Status=LINK_UP_CONTROL_REQ;
513 pstLinkRequest->Leader.PLength=sizeof(ULONG);
514 Adapter->bSyncUpRequestSent = TRUE;
516 else if(Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp)
518 pstLinkRequest = kzalloc(sizeof(LINK_REQUEST), GFP_ATOMIC);
521 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
525 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For LinkUp...");
526 pstLinkRequest->szData[0]=LINK_UP_REQ_PAYLOAD;
527 pstLinkRequest->szData[1]=LINK_NET_ENTRY;
528 pstLinkRequest->Leader.Status=LINK_UP_CONTROL_REQ;
529 pstLinkRequest->Leader.PLength=sizeof(ULONG);
533 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
534 CopyBufferToControlPacket(Adapter, pstLinkRequest);
535 kfree(pstLinkRequest);
537 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
542 /**********************************************************************
543 * Function - StatisticsResponse()
545 * Description - This function handles the Statistics response packet.
547 * Parameters - Adapter : Pointer to the Adapter structure.
548 * - pvBuffer: Starting address of Statistic response data.
551 ************************************************************************/
552 VOID StatisticsResponse(PMINI_ADAPTER Adapter,PVOID pvBuffer)
554 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>",__FUNCTION__);
555 Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
556 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (UINT)Adapter->StatisticsPointer);
557 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====",__FUNCTION__);
562 /**********************************************************************
563 * Function - LinkControlResponseMessage()
565 * Description - This function handles the Link response packets.
567 * Parameters - Adapter : Pointer to the Adapter structure.
568 * - pucBuffer: Starting address of Link response data.
571 ***********************************************************************/
572 VOID LinkControlResponseMessage(PMINI_ADAPTER Adapter,PUCHAR pucBuffer)
574 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
576 if(*pucBuffer==LINK_UP_ACK)
578 switch(*(pucBuffer+1))
580 case PHY_SYNC_ACHIVED: //SYNCed UP
581 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "PHY_SYNC_ACHIVED");
583 if(Adapter->LinkStatus == LINKUP_DONE)
585 beceem_protocol_reset(Adapter);
588 Adapter->usBestEffortQueueIndex=INVALID_QUEUE_INDEX ;
589 Adapter->LinkStatus=PHY_SYNC_ACHIVED;
591 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
593 Adapter->DriverState = NO_NETWORK_ENTRY;
594 wake_up(&Adapter->LEDInfo.notify_led_event);
597 LinkMessage(Adapter);
601 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LINKUP_DONE");
602 Adapter->LinkStatus=LINKUP_DONE;
603 Adapter->bPHSEnabled = *(pucBuffer+3);
604 Adapter->bETHCSEnabled = *(pucBuffer+4) & ETH_CS_MASK;
605 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "PHS Support Status Received In LinkUp Ack : %x \n",Adapter->bPHSEnabled);
606 if((FALSE == Adapter->bShutStatus)&&
607 (FALSE == Adapter->IdleMode))
609 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
611 Adapter->DriverState = NORMAL_OPERATION;
612 wake_up(&Adapter->LEDInfo.notify_led_event);
615 LinkMessage(Adapter);
620 * Driver to ignore the DREG_RECEIVED
621 * WiMAX Application should handle this Message
623 //Adapter->liTimeSinceLastNetEntry = 0;
624 Adapter->LinkUpStatus = 0;
625 Adapter->LinkStatus = 0;
626 Adapter->usBestEffortQueueIndex=INVALID_QUEUE_INDEX ;
627 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
628 Adapter->IdleMode = FALSE;
629 beceem_protocol_reset(Adapter);
632 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
633 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
635 HandleShutDownModeRequest(Adapter, pucBuffer);
639 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x",*(pucBuffer+1));
643 else if(SET_MAC_ADDRESS_RESPONSE==*pucBuffer)
645 PUCHAR puMacAddr = (pucBuffer + 1);
646 Adapter->LinkStatus=SYNC_UP_REQUEST;
647 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "MAC address response, sending SYNC_UP");
648 LinkMessage(Adapter);
649 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
651 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====",__FUNCTION__);
655 void SendIdleModeResponse(PMINI_ADAPTER Adapter)
657 INT status = 0, NVMAccess = 0,lowPwrAbortMsg = 0;
659 CONTROL_MESSAGE stIdleResponse = {{0}};
660 memset(&tv, 0, sizeof(tv));
661 stIdleResponse.Leader.Status = IDLE_MESSAGE;
662 stIdleResponse.Leader.PLength = IDLE_MODE_PAYLOAD_LENGTH;
663 stIdleResponse.szData[0] = GO_TO_IDLE_MODE_PAYLOAD;
664 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL," ============>");
666 /*********************************
668 ** if [ semaphore is available ]
669 ** acquire semaphone and return value 0 ;
671 ** return non-zero value ;
673 ***********************************/
675 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
677 lowPwrAbortMsg= down_trylock(&Adapter->LowPowerModeSync);
680 if((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
681 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) )
684 up(&Adapter->NVMRdmWrmLock);
687 up(&Adapter->LowPowerModeSync);
689 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE;//NACK- device access is going on.
690 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "HOST IS NACKING Idle mode To F/W!!!!!!!!");
691 Adapter->bPreparingForLowPowerMode = FALSE;
695 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; //2;//Idle ACK
696 Adapter->StatisticsPointer = 0;
698 /* Wait for the LED to TURN OFF before sending ACK response */
699 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
703 /* Wake the LED Thread with IDLEMODE_ENTER State */
704 Adapter->DriverState = LOWPOWER_MODE_ENTER;
705 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL,"LED Thread is Running..Hence Setting LED Event as IDLEMODE_ENTER jiffies:%ld",jiffies);
706 wake_up(&Adapter->LEDInfo.notify_led_event);
708 /* Wait for 1 SEC for LED to OFF */
709 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, \
710 Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
713 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
716 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE;//NACK- device access is going on.
717 Adapter->DriverState = NORMAL_OPERATION;
718 wake_up(&Adapter->LEDInfo.notify_led_event);
719 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "NACKING Idle mode as time out happen from LED side!!!!!!!!");
722 if(stIdleResponse.szData[1] == TARGET_CAN_GO_TO_IDLE_MODE)
724 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL,"ACKING IDLE MODE !!!!!!!!!");
725 down(&Adapter->rdmwrmsync);
726 Adapter->bPreparingForLowPowerMode = TRUE;
727 up(&Adapter->rdmwrmsync);
729 if(Adapter->bDoSuspend == TRUE)
730 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
735 Adapter->bPreparingForLowPowerMode = FALSE;
739 up(&Adapter->NVMRdmWrmLock);
742 up(&Adapter->LowPowerModeSync);
745 status = CopyBufferToControlPacket(Adapter,&stIdleResponse);
746 if((status != STATUS_SUCCESS))
748 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"fail to send the Idle mode Request \n");
749 Adapter->bPreparingForLowPowerMode = FALSE;
750 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
752 do_gettimeofday(&tv);
753 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "IdleMode Msg submitter to Q :%ld ms", tv.tv_sec *1000 + tv.tv_usec /1000);
757 /******************************************************************
758 * Function - DumpPackInfo()
760 * Description - This function dumps the all Queue(PackInfo[]) details.
762 * Parameters - Adapter: Pointer to the Adapter structure.
765 *******************************************************************/
766 VOID DumpPackInfo(PMINI_ADAPTER Adapter)
769 UINT uiLoopIndex = 0;
771 UINT uiClsfrIndex = 0;
772 S_CLASSIFIER_RULE *pstClassifierEntry = NULL;
774 for(uiLoopIndex=0;uiLoopIndex<NO_OF_QUEUES;uiLoopIndex++)
776 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"*********** Showing Details Of Queue %d***** ******",uiLoopIndex);
777 if(FALSE == Adapter->PackInfo[uiLoopIndex].bValid)
779 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"bValid is FALSE for %X index\n",uiLoopIndex);
783 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL," Dumping SF Rule Entry For SFID %lX \n",Adapter->PackInfo[uiLoopIndex].ulSFID);
784 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL," ucDirection %X \n",Adapter->PackInfo[uiLoopIndex].ucDirection);
785 if(Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
787 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Ipv6 Service Flow \n");
791 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Ipv4 Service Flow \n");
793 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL," SF Traffic Priority %X \n",Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
795 for(uiClsfrIndex=0;uiClsfrIndex<MAX_CLASSIFIERS;uiClsfrIndex++)
797 pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
798 if(!pstClassifierEntry->bUsed)
801 if(pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
804 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tDumping Classifier Rule Entry For Index: %X Classifier Rule ID : %X\n",uiClsfrIndex,pstClassifierEntry->uiClassifierRuleIndex);
805 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tDumping Classifier Rule Entry For Index: %X usVCID_Value : %X\n",uiClsfrIndex,pstClassifierEntry->usVCID_Value);
806 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tDumping Classifier Rule Entry For Index: %X bProtocolValid : %X\n",uiClsfrIndex,pstClassifierEntry->bProtocolValid);
807 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tDumping Classifier Rule Entry For Index: %X bTOSValid : %X\n",uiClsfrIndex,pstClassifierEntry->bTOSValid);
808 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tDumping Classifier Rule Entry For Index: %X bDestIpValid : %X\n",uiClsfrIndex,pstClassifierEntry->bDestIpValid);
809 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tDumping Classifier Rule Entry For Index: %X bSrcIpValid : %X\n",uiClsfrIndex,pstClassifierEntry->bSrcIpValid);
812 for(uiIndex=0;uiIndex<MAX_PORT_RANGE;uiIndex++)
814 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tusSrcPortRangeLo:%X\n",pstClassifierEntry->usSrcPortRangeLo[uiIndex]);
815 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tusSrcPortRangeHi:%X\n",pstClassifierEntry->usSrcPortRangeHi[uiIndex]);
816 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tusDestPortRangeLo:%X\n",pstClassifierEntry->usDestPortRangeLo[uiIndex]);
817 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tusDestPortRangeHi:%X\n",pstClassifierEntry->usDestPortRangeHi[uiIndex]);
820 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL," \tucIPSourceAddressLength : 0x%x\n",pstClassifierEntry->ucIPSourceAddressLength);
821 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tucIPDestinationAddressLength : 0x%x\n",pstClassifierEntry->ucIPDestinationAddressLength);
822 for(uiIndex=0;uiIndex<pstClassifierEntry->ucIPSourceAddressLength;uiIndex++)
824 if(Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
826 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tIpv6 ulSrcIpAddr :\n");
827 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Addr);
828 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tIpv6 ulSrcIpMask :\n");
829 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Mask);
833 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tulSrcIpAddr:%lX\n",pstClassifierEntry->stSrcIpAddress.ulIpv4Addr[uiIndex]);
834 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tulSrcIpMask:%lX\n",pstClassifierEntry->stSrcIpAddress.ulIpv4Mask[uiIndex]);
837 for(uiIndex=0;uiIndex<pstClassifierEntry->ucIPDestinationAddressLength;uiIndex++)
839 if(Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
841 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tIpv6 ulDestIpAddr :\n");
842 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Addr);
843 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tIpv6 ulDestIpMask :\n");
844 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Mask);
849 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tulDestIpAddr:%lX\n",pstClassifierEntry->stDestIpAddress.ulIpv4Addr[uiIndex]);
850 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tulDestIpMask:%lX\n",pstClassifierEntry->stDestIpAddress.ulIpv4Mask[uiIndex]);
853 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tucProtocol:0x%X\n",pstClassifierEntry->ucProtocol[0]);
854 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tu8ClassifierRulePriority:%X\n",pstClassifierEntry->u8ClassifierRulePriority);
858 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"ulSFID:%lX\n",Adapter->PackInfo[uiLoopIndex].ulSFID);
859 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"usVCID_Value:%X\n",Adapter->PackInfo[uiLoopIndex].usVCID_Value);
860 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"PhsEnabled: 0x%X\n",Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
861 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiThreshold:%X\n",Adapter->PackInfo[uiLoopIndex].uiThreshold);
864 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"bValid:%X\n",Adapter->PackInfo[uiLoopIndex].bValid);
865 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"bActive:%X\n",Adapter->PackInfo[uiLoopIndex].bActive);
866 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"ActivateReqSent: %x", Adapter->PackInfo[uiLoopIndex].bActivateRequestSent);
867 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"u8QueueType:%X\n",Adapter->PackInfo[uiLoopIndex].u8QueueType);
868 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiMaxBucketSize:%X\n",Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize);
869 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiPerSFTxResourceCount:%X\n",atomic_read(&Adapter->PackInfo[uiLoopIndex].uiPerSFTxResourceCount));
870 //DumpDebug(DUMP_INFO,(" bCSSupport:%X\n",Adapter->PackInfo[uiLoopIndex].bCSSupport));
871 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"CurrQueueDepthOnTarget: %x\n", Adapter->PackInfo[uiLoopIndex].uiCurrentQueueDepthOnTarget);
872 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiCurrentBytesOnHost:%X\n",Adapter->PackInfo[uiLoopIndex].uiCurrentBytesOnHost);
873 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiCurrentPacketsOnHost:%X\n",Adapter->PackInfo[uiLoopIndex].uiCurrentPacketsOnHost);
874 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiDroppedCountBytes:%X\n",Adapter->PackInfo[uiLoopIndex].uiDroppedCountBytes);
875 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiDroppedCountPackets:%X\n",Adapter->PackInfo[uiLoopIndex].uiDroppedCountPackets);
876 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiSentBytes:%X\n",Adapter->PackInfo[uiLoopIndex].uiSentBytes);
877 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiSentPackets:%X\n",Adapter->PackInfo[uiLoopIndex].uiSentPackets);
878 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiCurrentDrainRate:%X\n",Adapter->PackInfo[uiLoopIndex].uiCurrentDrainRate);
879 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiThisPeriodSentBytes:%X\n",Adapter->PackInfo[uiLoopIndex].uiThisPeriodSentBytes);
880 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"liDrainCalculated:%llX\n",Adapter->PackInfo[uiLoopIndex].liDrainCalculated);
881 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiCurrentTokenCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiCurrentTokenCount);
882 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"liLastUpdateTokenAt:%llX\n",Adapter->PackInfo[uiLoopIndex].liLastUpdateTokenAt);
883 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiMaxAllowedRate:%X\n",Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate);
884 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiPendedLast:%X\n",Adapter->PackInfo[uiLoopIndex].uiPendedLast);
885 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"NumOfPacketsSent:%X\n",Adapter->PackInfo[uiLoopIndex].NumOfPacketsSent);
886 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Direction: %x\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
887 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CID: %x\n", Adapter->PackInfo[uiLoopIndex].usCID);
888 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ProtocolValid: %x\n", Adapter->PackInfo[uiLoopIndex].bProtocolValid);
889 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "TOSValid: %x\n", Adapter->PackInfo[uiLoopIndex].bTOSValid);
890 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "DestIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bDestIpValid);
891 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SrcIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bSrcIpValid);
892 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActiveSet: %x\n", Adapter->PackInfo[uiLoopIndex].bActiveSet);
893 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AdmittedSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAdmittedSet);
894 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AuthzSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAuthorizedSet);
895 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ClassifyPrority: %x\n", Adapter->PackInfo[uiLoopIndex].bClassifierPriority);
896 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxLatency: %x\n",Adapter->PackInfo[uiLoopIndex].uiMaxLatency);
897 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ServiceClassName: %x %x %x %x\n",Adapter->PackInfo[uiLoopIndex].ucServiceClassName[0],Adapter->PackInfo[uiLoopIndex].ucServiceClassName[1],Adapter->PackInfo[uiLoopIndex].ucServiceClassName[2],Adapter->PackInfo[uiLoopIndex].ucServiceClassName[3]);
898 // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bHeaderSuppressionEnabled :%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
899 // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalTxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalTxBytes);
900 // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalRxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalRxBytes);
901 // DumpDebug(DUMP_INFO,(" uiRanOutOfResCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiRanOutOfResCount));
904 for(uiLoopIndex = 0 ; uiLoopIndex < MIBS_MAX_HIST_ENTRIES ; uiLoopIndex++)
905 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Adapter->aRxPktSizeHist[%x] = %x\n",uiLoopIndex,Adapter->aRxPktSizeHist[uiLoopIndex]);
907 for(uiLoopIndex = 0 ; uiLoopIndex < MIBS_MAX_HIST_ENTRIES ; uiLoopIndex++)
908 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Adapter->aTxPktSizeHist[%x] = %x\n",uiLoopIndex,Adapter->aTxPktSizeHist[uiLoopIndex]);
917 int reset_card_proc(PMINI_ADAPTER ps_adapter)
919 int retval = STATUS_SUCCESS;
921 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
922 PS_INTERFACE_ADAPTER psIntfAdapter = NULL;
923 unsigned int value = 0, uiResetValue = 0;
925 psIntfAdapter = ((PS_INTERFACE_ADAPTER)(ps_adapter->pvInterfaceAdapter)) ;
927 ps_adapter->bDDRInitDone = FALSE;
929 if(ps_adapter->chip_id >= T3LPB)
931 //SYS_CFG register is write protected hence for modifying this reg value, it should be read twice before
932 rdmalt(ps_adapter,SYS_CFG, &value, sizeof(value));
933 rdmalt(ps_adapter,SYS_CFG, &value, sizeof(value));
935 //making bit[6...5] same as was before f/w download. this setting force the h/w to
936 //re-populated the SP RAM area with the string descriptor .
937 value = value | (ps_adapter->syscfgBefFwDld & 0x00000060) ;
938 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
941 //killing all submitted URBs.
942 psIntfAdapter->psAdapter->StopAllXaction = TRUE ;
943 Bcm_kill_all_URBs(psIntfAdapter);
944 /* Reset the UMA-B Device */
945 if(ps_adapter->chip_id >= T3LPB)
947 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Reseting UMA-B \n");
948 retval = usb_reset_device(psIntfAdapter->udev);
950 psIntfAdapter->psAdapter->StopAllXaction = FALSE ;
952 if(retval != STATUS_SUCCESS)
954 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
957 if (ps_adapter->chip_id == BCS220_2 ||
958 ps_adapter->chip_id == BCS220_2BC ||
959 ps_adapter->chip_id == BCS250_BC ||
960 ps_adapter->chip_id == BCS220_3)
962 retval = rdmalt(ps_adapter,HPM_CONFIG_LDO145, &value, sizeof(value));
965 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"read failed with status :%d",retval);
970 retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
973 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
981 retval = rdmalt(ps_adapter,0x0f007018, &value, sizeof(value));
983 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"read failed with status :%d",retval);
987 retval= wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value)) ;
989 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
993 // Toggling the GPIO 8, 9
995 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
997 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
1001 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value)) ;
1003 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
1009 //ps_adapter->downloadDDR = false;
1011 if(ps_adapter->bFlashBoot)
1013 //In flash boot mode MIPS state register has reverse polarity.
1014 // So just or with setting bit 30.
1015 //Make the MIPS in Reset state.
1016 rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
1018 uiResetValue |=(1<<30);
1019 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
1022 if(ps_adapter->chip_id >= T3LPB)
1026 // WA for SYSConfig Issue.
1027 // Read SYSCFG Twice to make it writable.
1029 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
1030 if(uiResetValue & (1<<4))
1033 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));//2nd read to make it writable.
1034 uiResetValue &= (~(1<<4));
1035 wrmalt(ps_adapter,SYS_CFG, &uiResetValue, sizeof(uiResetValue));
1040 wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
1043 psIntfAdapter->psAdapter->StopAllXaction = FALSE ;
1047 int run_card_proc(PMINI_ADAPTER ps_adapter )
1049 unsigned int value=0;
1052 if(rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
1053 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"%s:%d\n", __FUNCTION__, __LINE__);
1054 return STATUS_FAILURE;
1057 if(ps_adapter->bFlashBoot)
1067 if(wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
1068 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"%s:%d\n", __FUNCTION__, __LINE__);
1069 return STATUS_FAILURE;
1072 return STATUS_SUCCESS;
1075 int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter)
1081 * Create the threads first and then download the
1082 * Firm/DDR Settings..
1085 status = create_worker_threads(ps_adapter);
1090 * For Downloading the Firm, parse the cfg file first.
1092 status = bcm_parse_target_params (ps_adapter);
1097 if(ps_adapter->chip_id >= T3LPB)
1099 rdmalt(ps_adapter, SYS_CFG, &value, sizeof (value));
1100 ps_adapter->syscfgBefFwDld = value ;
1101 if((value & 0x60)== 0)
1103 ps_adapter->bFlashBoot = TRUE;
1107 reset_card_proc(ps_adapter);
1109 //Initializing the NVM.
1110 BcmInitNVM(ps_adapter);
1111 status = ddr_init(ps_adapter);
1114 pr_err(DRV_NAME "ddr_init Failed\n");
1118 /* Download cfg file */
1119 status = buffDnldVerify(ps_adapter,
1120 (PUCHAR)ps_adapter->pstargetparams,
1121 sizeof(STARGETPARAMS),
1125 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
1129 if(register_networkdev(ps_adapter))
1131 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
1135 if(FALSE == ps_adapter->AutoFirmDld)
1137 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoFirmDld Disabled in CFG File..\n");
1138 //If Auto f/w download is disable, register the control interface,
1139 //register the control interface after the mailbox.
1140 if(register_control_device_interface(ps_adapter) < 0)
1142 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
1146 return STATUS_SUCCESS;
1150 * Do the LED Settings here. It will be used by the Firmware Download
1155 * 1. If the LED Settings fails, do not stop and do the Firmware download.
1156 * 2. This init would happened only if the cfg file is present, else
1157 * call from the ioctl context.
1160 status = InitLedSettings (ps_adapter);
1164 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_PRINTK, 0, 0,"INIT LED FAILED\n");
1167 if(ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1169 ps_adapter->DriverState = DRIVER_INIT;
1170 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1173 if(ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1175 ps_adapter->DriverState = FW_DOWNLOAD;
1176 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1180 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1181 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1183 if(ps_adapter->eNVMType == NVM_FLASH)
1185 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
1188 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL," Propagation of Cal param failed .." );
1193 /* Download Firmare */
1194 if ((status = BcmFileDownload( ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR)))
1196 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Firmware File is present... \n");
1200 status = run_card_proc(ps_adapter);
1203 BCM_DEBUG_PRINT (ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "run_card_proc Failed\n");
1208 ps_adapter->fw_download_done = TRUE;
1212 if(ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1214 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1215 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1222 static int bcm_parse_target_params(PMINI_ADAPTER Adapter)
1224 struct file *flp=NULL;
1225 mm_segment_t oldfs={0};
1230 buff=kmalloc(BUFFER_1K, GFP_KERNEL);
1235 if((Adapter->pstargetparams =
1236 kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL)) == NULL)
1241 flp=open_firmware_file(Adapter, CFG_FILE);
1243 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE \n", CFG_FILE);
1245 kfree(Adapter->pstargetparams);
1246 Adapter->pstargetparams = NULL;
1249 oldfs=get_fs(); set_fs(get_ds());
1250 len=vfs_read(flp, (void __user __force *)buff, BUFFER_1K, &pos);
1253 if(len != sizeof(STARGETPARAMS))
1255 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Mismatch in Target Param Structure!\n");
1257 kfree(Adapter->pstargetparams);
1258 Adapter->pstargetparams = NULL;
1259 filp_close(flp, current->files);
1262 filp_close(flp, current->files);
1264 /* Check for autolink in config params */
1266 * Values in Adapter->pstargetparams are in network byte order
1268 memcpy(Adapter->pstargetparams, buff, sizeof(STARGETPARAMS));
1270 beceem_parse_target_struct(Adapter);
1271 return STATUS_SUCCESS;
1274 void beceem_parse_target_struct(PMINI_ADAPTER Adapter)
1276 UINT uiHostDrvrCfg6 =0, uiEEPROMFlag = 0;
1278 if(ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE)
1280 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
1281 Adapter->AutoSyncup = FALSE;
1285 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
1286 Adapter->AutoSyncup = TRUE;
1289 if(ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE)
1291 pr_info(DRV_NAME ": Enabling autolink up");
1292 Adapter->AutoLinkUp = TRUE;
1296 pr_info(DRV_NAME ": Disabling autolink up");
1297 Adapter->AutoLinkUp = FALSE;
1299 // Setting the DDR Setting..
1300 Adapter->DDRSetting =
1301 (ntohl(Adapter->pstargetparams->HostDrvrConfig6) >>8)&0x0F;
1302 Adapter->ulPowerSaveMode =
1303 (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
1305 pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1306 pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
1307 if(ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD)
1309 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1310 Adapter->AutoFirmDld = TRUE;
1314 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1315 Adapter->AutoFirmDld = FALSE;
1317 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1318 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
1319 pr_info(DRV_NAME ": MIPSConfig : 0x%X\n",Adapter->bMipsConfig);
1320 //used for backward compatibility.
1321 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
1323 Adapter->PmuMode= (uiHostDrvrCfg6 >> 24 ) & 0x03;
1324 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
1326 if((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT ) & (0x01))
1328 Adapter->bDoSuspend = TRUE;
1329 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1332 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
1333 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n",uiEEPROMFlag);
1334 Adapter->eNVMType = (NVM_TYPE)((uiEEPROMFlag>>4)&0x3);
1336 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
1338 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
1340 Adapter->bSectorSizeOverride =(bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
1342 if(ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) &0x01)
1343 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
1345 if(Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1346 doPowerAutoCorrection(Adapter);
1350 static VOID doPowerAutoCorrection(PMINI_ADAPTER psAdapter)
1352 UINT reporting_mode;
1354 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) &0x02 ;
1355 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1357 if(reporting_mode == TRUE)
1359 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"can't do suspen/resume as reporting mode is enable");
1360 psAdapter->bDoSuspend = FALSE;
1363 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB))
1365 //If reporting mode is enable, switch PMU to PMC
1367 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
1368 psAdapter->bDoSuspend =FALSE;
1372 //clearing space bit[15..12]
1373 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl((0xF << 12)));
1374 //placing the power save mode option
1375 psAdapter->pstargetparams->HostDrvrConfig6 |= htonl((psAdapter->ulPowerSaveMode << 12));
1378 else if (psAdapter->bIsAutoCorrectEnabled == FALSE)
1381 // remove the autocorrect disable bit set before dumping.
1382 psAdapter->ulPowerSaveMode &= ~(1 << 3);
1383 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl(1 << 15));
1384 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Using Forced User Choice: %lx\n", psAdapter->ulPowerSaveMode);
1389 static unsigned char *ReadMacAddrEEPROM(PMINI_ADAPTER Adapter, ulong dwAddress)
1391 int status = 0, i = 0;
1392 unsigned int temp = 0;
1393 unsigned char *pucmacaddr = kmalloc(MAC_ADDRESS_SIZE, GFP_KERNEL);
1397 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "No Buffers to Read the EEPROM Address\n");
1401 dwAddress |= 0x5b000000;
1402 status = wrmalt(Adapter, EEPROM_COMMAND_Q_REG,
1403 (PUINT)&dwAddress, sizeof(UINT));
1404 if(status != STATUS_SUCCESS)
1406 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "wrm Failed..\n");
1411 for(i=0;i<MAC_ADDRESS_SIZE;i++)
1413 status = rdmalt(Adapter, EEPROM_READ_DATA_Q_REG, &temp,sizeof(temp));
1414 if(status != STATUS_SUCCESS)
1416 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm Failed..\n");
1421 pucmacaddr[i] = temp & 0xff;
1422 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"%x \n", pucmacaddr[i]);
1430 static void convertEndian(B_UINT8 rwFlag, PUINT puiBuffer, UINT uiByteCount)
1434 if(RWM_WRITE == rwFlag) {
1435 for(uiIndex =0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++) {
1436 puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
1439 for(uiIndex =0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++) {
1440 puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
1445 #define CACHE_ADDRESS_MASK 0x80000000
1446 #define UNCACHE_ADDRESS_MASK 0xa0000000
1448 int rdm(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1452 uiRetVal = Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
1453 uiAddress, pucBuff, sSize);
1460 int wrm(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1464 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
1465 uiAddress, pucBuff, sSize);
1471 int wrmalt (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1473 convertEndian(RWM_WRITE, pucBuff, size);
1474 return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1477 int rdmalt (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1481 uiRetVal = rdm(Adapter,uiAddress,(PUCHAR)pucBuff,size);
1482 convertEndian(RWM_READ, (PUINT)pucBuff, size);
1488 int wrmWithLock(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1490 INT status = STATUS_SUCCESS ;
1491 down(&Adapter->rdmwrmsync);
1493 if((Adapter->IdleMode == TRUE) ||
1494 (Adapter->bShutStatus ==TRUE) ||
1495 (Adapter->bPreparingForLowPowerMode ==TRUE))
1501 status =wrm(Adapter, uiAddress, pucBuff, sSize);
1504 up(&Adapter->rdmwrmsync);
1508 int wrmaltWithLock (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1510 int iRetVal = STATUS_SUCCESS;
1512 down(&Adapter->rdmwrmsync);
1514 if((Adapter->IdleMode == TRUE) ||
1515 (Adapter->bShutStatus ==TRUE) ||
1516 (Adapter->bPreparingForLowPowerMode ==TRUE))
1522 iRetVal = wrmalt(Adapter,uiAddress,pucBuff,size);
1525 up(&Adapter->rdmwrmsync);
1529 int rdmaltWithLock (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1531 INT uiRetVal =STATUS_SUCCESS;
1533 down(&Adapter->rdmwrmsync);
1535 if((Adapter->IdleMode == TRUE) ||
1536 (Adapter->bShutStatus ==TRUE) ||
1537 (Adapter->bPreparingForLowPowerMode ==TRUE))
1543 uiRetVal = rdmalt(Adapter,uiAddress, pucBuff, size);
1546 up(&Adapter->rdmwrmsync);
1551 static VOID HandleShutDownModeWakeup(PMINI_ADAPTER Adapter)
1553 int clear_abort_pattern = 0,Status = 0;
1554 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1555 //target has woken up From Shut Down
1556 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Clearing Shut Down Software abort pattern\n");
1557 Status = wrmalt(Adapter,SW_ABORT_IDLEMODE_LOC, (PUINT)&clear_abort_pattern, sizeof(clear_abort_pattern));
1560 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
1563 if(Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1566 InterfaceHandleShutdownModeWakeup(Adapter);
1569 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1571 Adapter->DriverState = NO_NETWORK_ENTRY;
1572 wake_up(&Adapter->LEDInfo.notify_led_event);
1575 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
1576 Adapter->bShutStatus = FALSE;
1577 wake_up(&Adapter->lowpower_mode_wait_queue);
1578 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1581 static VOID SendShutModeResponse(PMINI_ADAPTER Adapter)
1583 CONTROL_MESSAGE stShutdownResponse;
1584 UINT NVMAccess = 0,lowPwrAbortMsg = 0;
1587 memset (&stShutdownResponse, 0, sizeof(CONTROL_MESSAGE));
1588 stShutdownResponse.Leader.Status = LINK_UP_CONTROL_REQ;
1589 stShutdownResponse.Leader.PLength = 8;//8 bytes;
1590 stShutdownResponse.szData[0] = LINK_UP_ACK;
1591 stShutdownResponse.szData[1] = LINK_SHUTDOWN_REQ_FROM_FIRMWARE;
1593 /*********************************
1595 ** if [ semaphore is available ]
1596 ** acquire semaphone and return value 0 ;
1598 ** return non-zero value ;
1600 ***********************************/
1602 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1604 lowPwrAbortMsg= down_trylock(&Adapter->LowPowerModeSync);
1607 if(NVMAccess || lowPwrAbortMsg|| atomic_read(&Adapter->TotalPacketCount))
1610 up(&Adapter->NVMRdmWrmLock);
1613 up(&Adapter->LowPowerModeSync);
1615 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Device Access is going on NACK the Shut Down MODE\n");
1616 stShutdownResponse.szData[2] = SHUTDOWN_NACK_FROM_DRIVER;//NACK- device access is going on.
1617 Adapter->bPreparingForLowPowerMode = FALSE;
1621 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Sending SHUTDOWN MODE ACK\n");
1622 stShutdownResponse.szData[2] = SHUTDOWN_ACK_FROM_DRIVER;//ShutDown ACK
1624 /* Wait for the LED to TURN OFF before sending ACK response */
1625 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1629 /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1630 Adapter->DriverState = LOWPOWER_MODE_ENTER;
1631 wake_up(&Adapter->LEDInfo.notify_led_event);
1633 /* Wait for 1 SEC for LED to OFF */
1634 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent,\
1635 Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
1637 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
1640 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER;//NACK- device access is going on.
1642 Adapter->DriverState = NO_NETWORK_ENTRY;
1643 wake_up(&Adapter->LEDInfo.notify_led_event);
1647 if(stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER)
1649 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"ACKING SHUTDOWN MODE !!!!!!!!!");
1650 down(&Adapter->rdmwrmsync);
1651 Adapter->bPreparingForLowPowerMode = TRUE;
1652 up(&Adapter->rdmwrmsync);
1654 if(Adapter->bDoSuspend == TRUE)
1655 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1659 Adapter->bPreparingForLowPowerMode = FALSE;
1663 up(&Adapter->NVMRdmWrmLock);
1666 up(&Adapter->LowPowerModeSync);
1668 Status = CopyBufferToControlPacket(Adapter,&stShutdownResponse);
1669 if((Status != STATUS_SUCCESS))
1671 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"fail to send the Idle mode Request \n");
1672 Adapter->bPreparingForLowPowerMode = FALSE;
1674 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1679 static void HandleShutDownModeRequest(PMINI_ADAPTER Adapter,PUCHAR pucBuffer)
1681 B_UINT32 uiResetValue = 0;
1683 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1685 if(*(pucBuffer+1) == COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW)
1687 HandleShutDownModeWakeup(Adapter);
1689 else if(*(pucBuffer+1) == LINK_SHUTDOWN_REQ_FROM_FIRMWARE)
1691 //Target wants to go to Shut Down Mode
1692 //InterfacePrepareForShutdown(Adapter);
1693 if(Adapter->chip_id == BCS220_2 ||
1694 Adapter->chip_id == BCS220_2BC ||
1695 Adapter->chip_id == BCS250_BC ||
1696 Adapter->chip_id == BCS220_3)
1698 rdmalt(Adapter,HPM_CONFIG_MSW, &uiResetValue, 4);
1699 uiResetValue |= (1<<17);
1700 wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1703 SendShutModeResponse(Adapter);
1704 BCM_DEBUG_PRINT (Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"ShutDownModeResponse:Notification received: Sending the response(Ack/Nack)\n");
1707 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1712 VOID ResetCounters(PMINI_ADAPTER Adapter)
1715 beceem_protocol_reset(Adapter);
1717 Adapter->CurrNumRecvDescs = 0;
1718 Adapter->PrevNumRecvDescs = 0;
1719 Adapter->LinkUpStatus = 0;
1720 Adapter->LinkStatus = 0;
1721 atomic_set(&Adapter->cntrlpktCnt,0);
1722 atomic_set (&Adapter->TotalPacketCount,0);
1723 Adapter->fw_download_done=FALSE;
1724 Adapter->LinkStatus = 0;
1725 Adapter->AutoLinkUp = FALSE;
1726 Adapter->IdleMode = FALSE;
1727 Adapter->bShutStatus = FALSE;
1730 S_CLASSIFIER_RULE *GetFragIPClsEntry(PMINI_ADAPTER Adapter,USHORT usIpIdentification,ULONG SrcIP)
1733 for(uiIndex=0;uiIndex<MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES;uiIndex++)
1735 if((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed)&&
1736 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification)&&
1737 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress== SrcIP)&&
1738 !Adapter->astFragmentedPktClassifierTable[uiIndex].bOutOfOrderFragment)
1739 return Adapter->astFragmentedPktClassifierTable[uiIndex].pstMatchedClassifierEntry;
1744 void AddFragIPClsEntry(PMINI_ADAPTER Adapter,PS_FRAGMENTED_PACKET_INFO psFragPktInfo)
1747 for(uiIndex=0;uiIndex<MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES;uiIndex++)
1749 if(!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed)
1751 memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex],psFragPktInfo,sizeof(S_FRAGMENTED_PACKET_INFO));
1758 void DelFragIPClsEntry(PMINI_ADAPTER Adapter,USHORT usIpIdentification,ULONG SrcIp)
1761 for(uiIndex=0;uiIndex<MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES;uiIndex++)
1763 if((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed)&&
1764 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification)&&
1765 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress== SrcIp))
1766 memset(&Adapter->astFragmentedPktClassifierTable[uiIndex],0,sizeof(S_FRAGMENTED_PACKET_INFO));
1770 void update_per_cid_rx (PMINI_ADAPTER Adapter)
1774 if((jiffies - Adapter->liDrainCalculated) < XSECONDS)
1777 for(qindex = 0; qindex < HiPriority; qindex++)
1779 if(Adapter->PackInfo[qindex].ucDirection == 0)
1781 Adapter->PackInfo[qindex].uiCurrentRxRate =
1782 (Adapter->PackInfo[qindex].uiCurrentRxRate +
1783 Adapter->PackInfo[qindex].uiThisPeriodRxBytes)/2;
1785 Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
1789 Adapter->PackInfo[qindex].uiCurrentDrainRate =
1790 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
1791 Adapter->PackInfo[qindex].uiThisPeriodSentBytes)/2;
1793 Adapter->PackInfo[qindex].uiThisPeriodSentBytes=0;
1796 Adapter->liDrainCalculated=jiffies;
1798 void update_per_sf_desc_cnts( PMINI_ADAPTER Adapter)
1801 u32 uibuff[MAX_TARGET_DSX_BUFFERS];
1803 if(!atomic_read (&Adapter->uiMBupdate))
1806 if(rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (PUINT)uibuff, sizeof(UINT) * MAX_TARGET_DSX_BUFFERS)<0)
1808 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
1811 for(iIndex = 0;iIndex < HiPriority; iIndex++)
1813 if(Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection)
1815 if(Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
1817 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
1821 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Invalid VCID : %x \n",
1822 Adapter->PackInfo[iIndex].usVCID_Value);
1826 atomic_set (&Adapter->uiMBupdate, FALSE);
1829 void flush_queue(PMINI_ADAPTER Adapter, UINT iQIndex)
1831 struct sk_buff* PacketToDrop=NULL;
1832 struct net_device_stats* netstats = &Adapter->dev->stats;
1834 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1836 while(Adapter->PackInfo[iQIndex].FirstTxQueue &&
1837 atomic_read(&Adapter->TotalPacketCount))
1839 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
1840 if(PacketToDrop && PacketToDrop->len)
1842 netstats->tx_dropped++;
1843 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, \
1844 Adapter->PackInfo[iQIndex].LastTxQueue);
1846 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1847 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1849 //Adding dropped statistics
1850 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1851 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
1853 dev_kfree_skb(PacketToDrop);
1854 atomic_dec(&Adapter->TotalPacketCount);
1857 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1861 static void beceem_protocol_reset (PMINI_ADAPTER Adapter)
1865 if (netif_msg_link(Adapter))
1866 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
1868 netif_carrier_off(Adapter->dev);
1869 netif_stop_queue(Adapter->dev);
1871 Adapter->IdleMode = FALSE;
1872 Adapter->LinkUpStatus = FALSE;
1873 ClearTargetDSXBuffer(Adapter,0, TRUE);
1874 //Delete All Classifier Rules
1876 for(i = 0;i<HiPriority;i++)
1878 DeleteAllClassifiersForSF(Adapter,i);
1881 flush_all_queues(Adapter);
1883 if(Adapter->TimerActive == TRUE)
1884 Adapter->TimerActive = FALSE;
1886 memset(Adapter->astFragmentedPktClassifierTable, 0,
1887 sizeof(S_FRAGMENTED_PACKET_INFO) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
1889 for(i = 0;i<HiPriority;i++)
1891 //resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF.
1892 // It is same between MIBs and SF.
1893 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable,
1894 0, sizeof(S_MIBS_EXTSERVICEFLOW_PARAMETERS));