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] = (char *)kmalloc(MAX_CNTL_PKT_SIZE,
76 if(!psAdapter->txctlpacket[i])
78 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No More Cntl pkts got, max got is %d", i);
82 if(AllocAdapterDsxBuffer(psAdapter))
84 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to allocate DSX buffers");
88 //Initialize PHS interface
89 if(phs_init(&psAdapter->stBCMPhsContext,psAdapter)!=0)
91 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"%s:%s:%d:Error PHS Init Failed=====>\n", __FILE__, __FUNCTION__, __LINE__);
95 Status = BcmAllocFlashCSStructure(psAdapter);
98 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Memory Allocation for Flash structure failed");
102 Status = vendorextnInit(psAdapter);
104 if(STATUS_SUCCESS != Status)
106 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Vendor Init Failed");
110 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Adapter initialised");
113 return STATUS_SUCCESS;
116 VOID AdapterFree(PMINI_ADAPTER Adapter)
120 beceem_protocol_reset(Adapter);
122 vendorextnExit(Adapter);
124 if(Adapter->control_packet_handler && !IS_ERR(Adapter->control_packet_handler))
125 kthread_stop (Adapter->control_packet_handler);
127 if(Adapter->transmit_packet_thread && !IS_ERR(Adapter->transmit_packet_thread))
128 kthread_stop (Adapter->transmit_packet_thread);
130 wake_up(&Adapter->process_read_wait_queue);
132 if(Adapter->LEDInfo.led_thread_running & (BCM_LED_THREAD_RUNNING_ACTIVELY | BCM_LED_THREAD_RUNNING_INACTIVELY))
133 kthread_stop (Adapter->LEDInfo.led_cntrl_threadid);
135 unregister_netdev(Adapter->dev);
137 /* FIXME: use proper wait_event and refcounting */
138 while(atomic_read(&Adapter->ApplicationRunning))
140 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Waiting for Application to close.. %d\n",atomic_read(&Adapter->ApplicationRunning));
143 unregister_control_device_interface(Adapter);
145 kfree(Adapter->pstargetparams);
147 for (count =0;count < MAX_CNTRL_PKTS;count++)
148 kfree(Adapter->txctlpacket[count]);
150 FreeAdapterDsxBuffer(Adapter);
152 kfree(Adapter->pvInterfaceAdapter);
154 //Free the PHS Interface
155 PhsCleanup(&Adapter->stBCMPhsContext);
157 BcmDeAllocFlashCSStructure(Adapter);
159 free_netdev(Adapter->dev);
162 static int create_worker_threads(PMINI_ADAPTER psAdapter)
164 // Rx Control Packets Processing
165 psAdapter->control_packet_handler = kthread_run((int (*)(void *))
166 control_packet_handler, psAdapter, "%s-rx", DRV_NAME);
167 if(IS_ERR(psAdapter->control_packet_handler))
169 pr_notice(DRV_NAME ": could not create control thread\n");
170 return PTR_ERR(psAdapter->control_packet_handler);
174 psAdapter->transmit_packet_thread = kthread_run((int (*)(void *))
175 tx_pkt_handler, psAdapter, "%s-tx", DRV_NAME);
176 if(IS_ERR (psAdapter->transmit_packet_thread))
178 pr_notice(DRV_NAME ": could not creat transmit thread\n");
179 kthread_stop(psAdapter->control_packet_handler);
180 return PTR_ERR(psAdapter->transmit_packet_thread);
185 static struct file *open_firmware_file(PMINI_ADAPTER Adapter, const char *path)
187 struct file *flp=NULL;
191 flp=filp_open(path, O_RDONLY, S_IRWXU);
195 pr_err(DRV_NAME "Unable To Open File %s, err %ld",
200 if(Adapter->device_removed)
207 static int BcmFileDownload(PMINI_ADAPTER Adapter,/**< Logical Adapter */
208 const char *path, /**< path to image file */
209 unsigned int loc /**< Download Address on the chip*/
213 struct file *flp=NULL;
215 struct timeval tv={0};
217 flp=open_firmware_file(Adapter, path);
221 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Unable to Open %s\n", path);
224 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Opened file is = %s and length =0x%lx to be downloaded at =0x%x", path,(unsigned long)flp->f_dentry->d_inode->i_size, loc);
225 do_gettimeofday(&tv);
227 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "download start %lx", ((tv.tv_sec * 1000) +
229 if(Adapter->bcm_file_download(Adapter->pvInterfaceAdapter, flp, loc))
231 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to download the firmware with error\
236 oldfs=get_fs();set_fs(get_ds());
237 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
238 vfs_llseek(flp, 0, 0);
241 if(Adapter->bcm_file_readback_from_chip(Adapter->pvInterfaceAdapter,
244 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to read back firmware!");
250 oldfs=get_fs();set_fs(get_ds());
251 if(flp && !(IS_ERR(flp)))
252 filp_close(flp, current->files);
259 @ingroup ctrl_pkt_functions
260 This function copies the contents of given buffer
261 to the control packet and queues it for transmission.
262 @note Do not acquire the spinock, as it it already acquired.
263 @return SUCCESS/FAILURE.
265 INT CopyBufferToControlPacket(PMINI_ADAPTER Adapter,/**<Logical Adapter*/
266 PVOID ioBuffer/**<Control Packet Buffer*/
269 PLEADER pLeader=NULL;
271 unsigned char *ctrl_buff=NULL;
273 PLINK_REQUEST pLinkReq = NULL;
274 PUCHAR pucAddIndication = NULL;
276 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "======>");
279 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Got Null Buffer\n");
283 pLinkReq = (PLINK_REQUEST)ioBuffer;
284 pLeader=(PLEADER)ioBuffer; //ioBuffer Contains sw_Status and Payload
286 if(Adapter->bShutStatus == TRUE &&
287 pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD &&
288 pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE)
290 //Got sync down in SHUTDOWN..we could not process this.
291 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "SYNC DOWN Request in Shut Down Mode..\n");
292 return STATUS_FAILURE;
295 if((pLeader->Status == LINK_UP_CONTROL_REQ) &&
296 ((pLinkReq->szData[0] == LINK_UP_REQ_PAYLOAD &&
297 (pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE)) ||//Sync Up Command
298 pLinkReq->szData[0] == NETWORK_ENTRY_REQ_PAYLOAD)) //Net Entry Command
300 if(Adapter->LinkStatus > PHY_SYNC_ACHIVED)
302 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL,"LinkStatus is Greater than PHY_SYN_ACHIEVED");
303 return STATUS_FAILURE;
305 if(TRUE == Adapter->bShutStatus)
307 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "SYNC UP IN SHUTDOWN..Device WakeUp\n");
308 if(Adapter->bTriedToWakeUpFromlowPowerMode == FALSE)
310 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Waking up for the First Time..\n");
311 Adapter->usIdleModePattern = ABORT_SHUTDOWN_MODE; // change it to 1 for current support.
312 Adapter->bWakeUpDevice = TRUE;
313 wake_up(&Adapter->process_rx_cntrlpkt);
315 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
316 !Adapter->bShutStatus, (5 * HZ));
318 if(Status == -ERESTARTSYS)
321 if(Adapter->bShutStatus)
323 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Shutdown Mode Wake up Failed - No Wake Up Received\n");
324 return STATUS_FAILURE;
329 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Wakeup has been tried already...\n");
334 if(TRUE == Adapter->IdleMode)
336 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle mode ... hence \n");
337 if(pLeader->Status == LINK_UP_CONTROL_REQ || pLeader->Status == 0x80 ||
338 pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ )
341 if((pLeader->Status == LINK_UP_CONTROL_REQ) && (pLinkReq->szData[0]==LINK_DOWN_REQ_PAYLOAD))
343 if((pLinkReq->szData[1] == LINK_SYNC_DOWN_SUBTYPE))
345 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Link Down Sent in Idle Mode\n");
346 Adapter->usIdleModePattern = ABORT_IDLE_SYNCDOWN;//LINK DOWN sent in Idle Mode
350 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL,"ABORT_IDLE_MODE pattern is being written\n");
351 Adapter->usIdleModePattern = ABORT_IDLE_REG;
356 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL,"ABORT_IDLE_MODE pattern is being written\n");
357 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
360 /*Setting bIdleMode_tx_from_host to TRUE to indicate LED control thread to represent
361 the wake up from idlemode is from host*/
362 //Adapter->LEDInfo.bIdleMode_tx_from_host = TRUE;
363 Adapter->bWakeUpDevice = TRUE;
364 wake_up(&Adapter->process_rx_cntrlpkt);
368 if(LINK_DOWN_REQ_PAYLOAD == pLinkReq->szData[0])
370 // We should not send DREG message down while in idlemode.
371 return STATUS_SUCCESS;
374 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
375 !Adapter->IdleMode, (5 * HZ));
377 if(Status == -ERESTARTSYS)
380 if(Adapter->IdleMode)
382 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Idle Mode Wake up Failed - No Wake Up Received\n");
383 return STATUS_FAILURE;
387 return STATUS_SUCCESS;
389 //The Driver has to send control messages with a particular VCID
390 pLeader->Vcid = VCID_CONTROL_PACKET;//VCID for control packet.
392 /* Allocate skb for Control Packet */
393 pktlen = pLeader->PLength;
394 ctrl_buff = (char *)Adapter->txctlpacket[atomic_read(&Adapter->index_wr_txcntrlpkt)%MAX_CNTRL_PKTS];
396 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Control packet to be taken =%d and address is =%pincoming address is =%p and packet len=%x",
397 atomic_read(&Adapter->index_wr_txcntrlpkt), ctrl_buff, ioBuffer, pktlen);
402 if((pLeader->Status == 0x80) ||
403 (pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ))
406 //Restructure the DSX message to handle Multiple classifier Support
407 // Write the Service Flow param Structures directly to the target
408 //and embed the pointers in the DSX messages sent to target.
410 //Lets store the current length of the control packet we are transmitting
411 pucAddIndication = (PUCHAR)ioBuffer + LEADER_SIZE;
412 pktlen = pLeader->PLength;
413 Status = StoreCmControlResponseMessage(Adapter,pucAddIndication, &pktlen);
416 ClearTargetDSXBuffer(Adapter,((stLocalSFAddIndicationAlt *)pucAddIndication)->u16TID, FALSE);
417 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, " Error Restoring The DSX Control Packet. Dsx Buffers on Target may not be Setup Properly ");
418 return STATUS_FAILURE;
421 //update the leader to use the new length
422 //The length of the control packet is length of message being sent + Leader length
424 pLeader->PLength = pktlen;
427 memset(ctrl_buff, 0, pktlen+LEADER_SIZE);
428 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Copying the Control Packet Buffer with length=%d\n", pLeader->PLength);
429 *(PLEADER)ctrl_buff=*pLeader;
430 memcpy(ctrl_buff + LEADER_SIZE, ((PUCHAR)ioBuffer + LEADER_SIZE), pLeader->PLength);
431 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Enqueuing the Control Packet");
433 /*Update the statistics counters */
434 spin_lock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
435 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost+=pLeader->PLength;
436 Adapter->PackInfo[HiPriority].uiCurrentPacketsOnHost++;
437 atomic_inc(&Adapter->TotalPacketCount);
438 spin_unlock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
440 Adapter->PackInfo[HiPriority].bValid = TRUE;
442 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "CurrBytesOnHost: %x bValid: %x",
443 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost,
444 Adapter->PackInfo[HiPriority].bValid);
445 Status=STATUS_SUCCESS;
446 /*Queue the packet for transmission */
447 atomic_inc(&Adapter->index_wr_txcntrlpkt);
448 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Calling transmit_packets");
449 atomic_set(&Adapter->TxPktAvail, 1);
450 wake_up(&Adapter->tx_packet_wait_queue);
455 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "mem allocation Failed");
457 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<====");
462 /*****************************************************************
463 * Function - SendStatisticsPointerRequest()
465 * Description - This function builds and forwards the Statistics
466 * Pointer Request control Packet.
468 * Parameters - Adapter : Pointer to Adapter structure.
469 * - pstStatisticsPtrRequest : Pointer to link request.
472 *****************************************************************/
473 static VOID SendStatisticsPointerRequest(PMINI_ADAPTER Adapter,
474 PLINK_REQUEST pstStatisticsPtrRequest)
476 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "======>");
477 pstStatisticsPtrRequest->Leader.Status = STATS_POINTER_REQ_STATUS;
478 pstStatisticsPtrRequest->Leader.PLength = sizeof(ULONG);//minimum 4 bytes
479 pstStatisticsPtrRequest->szData[0] = STATISTICS_POINTER_REQ;
481 CopyBufferToControlPacket(Adapter,pstStatisticsPtrRequest);
482 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "<=====");
488 /******************************************************************
489 * Function - LinkMessage()
491 * Description - This function builds the Sync-up and Link-up request
492 * packet messages depending on the device Link status.
494 * Parameters - Adapter: Pointer to the Adapter structure.
497 *******************************************************************/
498 VOID LinkMessage(PMINI_ADAPTER Adapter)
500 PLINK_REQUEST pstLinkRequest=NULL;
501 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>");
502 if(Adapter->LinkStatus == SYNC_UP_REQUEST && Adapter->AutoSyncup)
504 pstLinkRequest=kmalloc(sizeof(LINK_REQUEST), GFP_ATOMIC);
507 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
510 memset(pstLinkRequest,0,sizeof(LINK_REQUEST));
512 Adapter->LinkStatus = WAIT_FOR_SYNC;// current link status
513 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For SyncUp...");
514 pstLinkRequest->szData[0]=LINK_UP_REQ_PAYLOAD;
515 pstLinkRequest->szData[1]=LINK_SYNC_UP_SUBTYPE;
516 pstLinkRequest->Leader.Status=LINK_UP_CONTROL_REQ;
517 pstLinkRequest->Leader.PLength=sizeof(ULONG);
518 Adapter->bSyncUpRequestSent = TRUE;
520 else if(Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp)
522 pstLinkRequest=kmalloc(sizeof(LINK_REQUEST), GFP_ATOMIC);
525 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
528 memset(pstLinkRequest,0,sizeof(LINK_REQUEST));
530 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For LinkUp...");
531 pstLinkRequest->szData[0]=LINK_UP_REQ_PAYLOAD;
532 pstLinkRequest->szData[1]=LINK_NET_ENTRY;
533 pstLinkRequest->Leader.Status=LINK_UP_CONTROL_REQ;
534 pstLinkRequest->Leader.PLength=sizeof(ULONG);
538 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
539 CopyBufferToControlPacket(Adapter, pstLinkRequest);
540 kfree(pstLinkRequest);
542 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
547 /**********************************************************************
548 * Function - StatisticsResponse()
550 * Description - This function handles the Statistics response packet.
552 * Parameters - Adapter : Pointer to the Adapter structure.
553 * - pvBuffer: Starting address of Statistic response data.
556 ************************************************************************/
557 VOID StatisticsResponse(PMINI_ADAPTER Adapter,PVOID pvBuffer)
559 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>",__FUNCTION__);
560 Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
561 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (UINT)Adapter->StatisticsPointer);
562 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====",__FUNCTION__);
567 /**********************************************************************
568 * Function - LinkControlResponseMessage()
570 * Description - This function handles the Link response packets.
572 * Parameters - Adapter : Pointer to the Adapter structure.
573 * - pucBuffer: Starting address of Link response data.
576 ***********************************************************************/
577 VOID LinkControlResponseMessage(PMINI_ADAPTER Adapter,PUCHAR pucBuffer)
579 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
581 if(*pucBuffer==LINK_UP_ACK)
583 switch(*(pucBuffer+1))
585 case PHY_SYNC_ACHIVED: //SYNCed UP
586 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "PHY_SYNC_ACHIVED");
588 if(Adapter->LinkStatus == LINKUP_DONE)
590 beceem_protocol_reset(Adapter);
593 Adapter->usBestEffortQueueIndex=INVALID_QUEUE_INDEX ;
594 Adapter->LinkStatus=PHY_SYNC_ACHIVED;
596 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
598 Adapter->DriverState = NO_NETWORK_ENTRY;
599 wake_up(&Adapter->LEDInfo.notify_led_event);
602 LinkMessage(Adapter);
606 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LINKUP_DONE");
607 Adapter->LinkStatus=LINKUP_DONE;
608 Adapter->bPHSEnabled = *(pucBuffer+3);
609 Adapter->bETHCSEnabled = *(pucBuffer+4) & ETH_CS_MASK;
610 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "PHS Support Status Recieved In LinkUp Ack : %x \n",Adapter->bPHSEnabled);
611 if((FALSE == Adapter->bShutStatus)&&
612 (FALSE == Adapter->IdleMode))
614 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
616 Adapter->DriverState = NORMAL_OPERATION;
617 wake_up(&Adapter->LEDInfo.notify_led_event);
620 LinkMessage(Adapter);
625 * Driver to ignore the DREG_RECEIVED
626 * WiMAX Application should handle this Message
628 //Adapter->liTimeSinceLastNetEntry = 0;
629 Adapter->LinkUpStatus = 0;
630 Adapter->LinkStatus = 0;
631 Adapter->usBestEffortQueueIndex=INVALID_QUEUE_INDEX ;
632 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
633 Adapter->IdleMode = FALSE;
634 beceem_protocol_reset(Adapter);
637 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
638 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
640 HandleShutDownModeRequest(Adapter, pucBuffer);
644 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x",*(pucBuffer+1));
648 else if(SET_MAC_ADDRESS_RESPONSE==*pucBuffer)
650 PUCHAR puMacAddr = (pucBuffer + 1);
651 Adapter->LinkStatus=SYNC_UP_REQUEST;
652 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "MAC address response, sending SYNC_UP");
653 LinkMessage(Adapter);
654 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
656 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====",__FUNCTION__);
660 void SendIdleModeResponse(PMINI_ADAPTER Adapter)
662 INT status = 0, NVMAccess = 0,lowPwrAbortMsg = 0;
664 CONTROL_MESSAGE stIdleResponse = {{0}};
665 memset(&tv, 0, sizeof(tv));
666 stIdleResponse.Leader.Status = IDLE_MESSAGE;
667 stIdleResponse.Leader.PLength = IDLE_MODE_PAYLOAD_LENGTH;
668 stIdleResponse.szData[0] = GO_TO_IDLE_MODE_PAYLOAD;
669 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL," ============>");
671 /*********************************
673 ** if [ semaphore is available ]
674 ** acquire semaphone and return value 0 ;
676 ** return non-zero value ;
678 ***********************************/
680 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
682 lowPwrAbortMsg= down_trylock(&Adapter->LowPowerModeSync);
685 if((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
686 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) )
689 up(&Adapter->NVMRdmWrmLock);
692 up(&Adapter->LowPowerModeSync);
694 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE;//NACK- device access is going on.
695 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "HOST IS NACKING Idle mode To F/W!!!!!!!!");
696 Adapter->bPreparingForLowPowerMode = FALSE;
700 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; //2;//Idle ACK
701 Adapter->StatisticsPointer = 0;
703 /* Wait for the LED to TURN OFF before sending ACK response */
704 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
708 /* Wake the LED Thread with IDLEMODE_ENTER State */
709 Adapter->DriverState = LOWPOWER_MODE_ENTER;
710 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL,"LED Thread is Running..Hence Setting LED Event as IDLEMODE_ENTER jiffies:%ld",jiffies);;
711 wake_up(&Adapter->LEDInfo.notify_led_event);
713 /* Wait for 1 SEC for LED to OFF */
714 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, \
715 Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
718 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
721 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE;//NACK- device access is going on.
722 Adapter->DriverState = NORMAL_OPERATION;
723 wake_up(&Adapter->LEDInfo.notify_led_event);
724 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "NACKING Idle mode as time out happen from LED side!!!!!!!!");
727 if(stIdleResponse.szData[1] == TARGET_CAN_GO_TO_IDLE_MODE)
729 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL,"ACKING IDLE MODE !!!!!!!!!");
730 down(&Adapter->rdmwrmsync);
731 Adapter->bPreparingForLowPowerMode = TRUE;
732 up(&Adapter->rdmwrmsync);
734 if(Adapter->bDoSuspend == TRUE)
735 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
740 Adapter->bPreparingForLowPowerMode = FALSE;
744 up(&Adapter->NVMRdmWrmLock);
747 up(&Adapter->LowPowerModeSync);
750 status = CopyBufferToControlPacket(Adapter,&stIdleResponse);
751 if((status != STATUS_SUCCESS))
753 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"fail to send the Idle mode Request \n");
754 Adapter->bPreparingForLowPowerMode = FALSE;
755 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
757 do_gettimeofday(&tv);
758 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "IdleMode Msg submitter to Q :%ld ms", tv.tv_sec *1000 + tv.tv_usec /1000);
762 /******************************************************************
763 * Function - DumpPackInfo()
765 * Description - This function dumps the all Queue(PackInfo[]) details.
767 * Parameters - Adapter: Pointer to the Adapter structure.
770 *******************************************************************/
771 VOID DumpPackInfo(PMINI_ADAPTER Adapter)
774 UINT uiLoopIndex = 0;
776 UINT uiClsfrIndex = 0;
777 S_CLASSIFIER_RULE *pstClassifierEntry = NULL;
779 for(uiLoopIndex=0;uiLoopIndex<NO_OF_QUEUES;uiLoopIndex++)
781 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"*********** Showing Details Of Queue %d***** ******",uiLoopIndex);
782 if(FALSE == Adapter->PackInfo[uiLoopIndex].bValid)
784 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"bValid is FALSE for %X index\n",uiLoopIndex);
788 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL," Dumping SF Rule Entry For SFID %lX \n",Adapter->PackInfo[uiLoopIndex].ulSFID);
789 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL," ucDirection %X \n",Adapter->PackInfo[uiLoopIndex].ucDirection);
790 if(Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
792 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Ipv6 Service Flow \n");
796 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Ipv4 Service Flow \n");
798 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL," SF Traffic Priority %X \n",Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
800 for(uiClsfrIndex=0;uiClsfrIndex<MAX_CLASSIFIERS;uiClsfrIndex++)
802 pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
803 if(!pstClassifierEntry->bUsed)
806 if(pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
809 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tDumping Classifier Rule Entry For Index: %X Classifier Rule ID : %X\n",uiClsfrIndex,pstClassifierEntry->uiClassifierRuleIndex);
810 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tDumping Classifier Rule Entry For Index: %X usVCID_Value : %X\n",uiClsfrIndex,pstClassifierEntry->usVCID_Value);
811 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tDumping Classifier Rule Entry For Index: %X bProtocolValid : %X\n",uiClsfrIndex,pstClassifierEntry->bProtocolValid);
812 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tDumping Classifier Rule Entry For Index: %X bTOSValid : %X\n",uiClsfrIndex,pstClassifierEntry->bTOSValid);
813 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tDumping Classifier Rule Entry For Index: %X bDestIpValid : %X\n",uiClsfrIndex,pstClassifierEntry->bDestIpValid);
814 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tDumping Classifier Rule Entry For Index: %X bSrcIpValid : %X\n",uiClsfrIndex,pstClassifierEntry->bSrcIpValid);
817 for(uiIndex=0;uiIndex<MAX_PORT_RANGE;uiIndex++)
819 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tusSrcPortRangeLo:%X\n",pstClassifierEntry->usSrcPortRangeLo[uiIndex]);
820 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tusSrcPortRangeHi:%X\n",pstClassifierEntry->usSrcPortRangeHi[uiIndex]);
821 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tusDestPortRangeLo:%X\n",pstClassifierEntry->usDestPortRangeLo[uiIndex]);
822 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tusDestPortRangeHi:%X\n",pstClassifierEntry->usDestPortRangeHi[uiIndex]);
825 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL," \tucIPSourceAddressLength : 0x%x\n",pstClassifierEntry->ucIPSourceAddressLength);
826 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tucIPDestinationAddressLength : 0x%x\n",pstClassifierEntry->ucIPDestinationAddressLength);
827 for(uiIndex=0;uiIndex<pstClassifierEntry->ucIPSourceAddressLength;uiIndex++)
829 if(Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
831 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tIpv6 ulSrcIpAddr :\n");
832 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Addr);
833 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tIpv6 ulSrcIpMask :\n");
834 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Mask);
838 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tulSrcIpAddr:%lX\n",pstClassifierEntry->stSrcIpAddress.ulIpv4Addr[uiIndex]);
839 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tulSrcIpMask:%lX\n",pstClassifierEntry->stSrcIpAddress.ulIpv4Mask[uiIndex]);
842 for(uiIndex=0;uiIndex<pstClassifierEntry->ucIPDestinationAddressLength;uiIndex++)
844 if(Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
846 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tIpv6 ulDestIpAddr :\n");
847 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Addr);
848 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tIpv6 ulDestIpMask :\n");
849 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Mask);
854 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tulDestIpAddr:%lX\n",pstClassifierEntry->stDestIpAddress.ulIpv4Addr[uiIndex]);
855 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tulDestIpMask:%lX\n",pstClassifierEntry->stDestIpAddress.ulIpv4Mask[uiIndex]);
858 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tucProtocol:0x%X\n",pstClassifierEntry->ucProtocol[0]);
859 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tu8ClassifierRulePriority:%X\n",pstClassifierEntry->u8ClassifierRulePriority);
863 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"ulSFID:%lX\n",Adapter->PackInfo[uiLoopIndex].ulSFID);
864 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"usVCID_Value:%X\n",Adapter->PackInfo[uiLoopIndex].usVCID_Value);
865 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"PhsEnabled: 0x%X\n",Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
866 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiThreshold:%X\n",Adapter->PackInfo[uiLoopIndex].uiThreshold);
869 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"bValid:%X\n",Adapter->PackInfo[uiLoopIndex].bValid);
870 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"bActive:%X\n",Adapter->PackInfo[uiLoopIndex].bActive);
871 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"ActivateReqSent: %x", Adapter->PackInfo[uiLoopIndex].bActivateRequestSent);
872 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"u8QueueType:%X\n",Adapter->PackInfo[uiLoopIndex].u8QueueType);
873 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiMaxBucketSize:%X\n",Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize);
874 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiPerSFTxResourceCount:%X\n",atomic_read(&Adapter->PackInfo[uiLoopIndex].uiPerSFTxResourceCount));
875 //DumpDebug(DUMP_INFO,(" bCSSupport:%X\n",Adapter->PackInfo[uiLoopIndex].bCSSupport));
876 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"CurrQueueDepthOnTarget: %x\n", Adapter->PackInfo[uiLoopIndex].uiCurrentQueueDepthOnTarget);
877 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiCurrentBytesOnHost:%X\n",Adapter->PackInfo[uiLoopIndex].uiCurrentBytesOnHost);
878 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiCurrentPacketsOnHost:%X\n",Adapter->PackInfo[uiLoopIndex].uiCurrentPacketsOnHost);
879 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiDroppedCountBytes:%X\n",Adapter->PackInfo[uiLoopIndex].uiDroppedCountBytes);
880 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiDroppedCountPackets:%X\n",Adapter->PackInfo[uiLoopIndex].uiDroppedCountPackets);
881 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiSentBytes:%X\n",Adapter->PackInfo[uiLoopIndex].uiSentBytes);
882 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiSentPackets:%X\n",Adapter->PackInfo[uiLoopIndex].uiSentPackets);
883 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiCurrentDrainRate:%X\n",Adapter->PackInfo[uiLoopIndex].uiCurrentDrainRate);
884 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiThisPeriodSentBytes:%X\n",Adapter->PackInfo[uiLoopIndex].uiThisPeriodSentBytes);
885 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"liDrainCalculated:%llX\n",Adapter->PackInfo[uiLoopIndex].liDrainCalculated);
886 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiCurrentTokenCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiCurrentTokenCount);
887 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"liLastUpdateTokenAt:%llX\n",Adapter->PackInfo[uiLoopIndex].liLastUpdateTokenAt);
888 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiMaxAllowedRate:%X\n",Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate);
889 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiPendedLast:%X\n",Adapter->PackInfo[uiLoopIndex].uiPendedLast);
890 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"NumOfPacketsSent:%X\n",Adapter->PackInfo[uiLoopIndex].NumOfPacketsSent);
891 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Direction: %x\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
892 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CID: %x\n", Adapter->PackInfo[uiLoopIndex].usCID);
893 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ProtocolValid: %x\n", Adapter->PackInfo[uiLoopIndex].bProtocolValid);
894 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "TOSValid: %x\n", Adapter->PackInfo[uiLoopIndex].bTOSValid);
895 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "DestIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bDestIpValid);
896 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SrcIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bSrcIpValid);
897 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActiveSet: %x\n", Adapter->PackInfo[uiLoopIndex].bActiveSet);
898 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AdmittedSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAdmittedSet);
899 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AuthzSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAuthorizedSet);
900 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ClassifyPrority: %x\n", Adapter->PackInfo[uiLoopIndex].bClassifierPriority);
901 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxLatency: %x\n",Adapter->PackInfo[uiLoopIndex].uiMaxLatency);
902 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ServiceClassName: %x %x %x %x\n",Adapter->PackInfo[uiLoopIndex].ucServiceClassName[0],Adapter->PackInfo[uiLoopIndex].ucServiceClassName[1],Adapter->PackInfo[uiLoopIndex].ucServiceClassName[2],Adapter->PackInfo[uiLoopIndex].ucServiceClassName[3]);
903 // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bHeaderSuppressionEnabled :%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
904 // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalTxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalTxBytes);
905 // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalRxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalRxBytes);
906 // DumpDebug(DUMP_INFO,(" uiRanOutOfResCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiRanOutOfResCount));
909 for(uiLoopIndex = 0 ; uiLoopIndex < MIBS_MAX_HIST_ENTRIES ; uiLoopIndex++)
910 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Adapter->aRxPktSizeHist[%x] = %x\n",uiLoopIndex,Adapter->aRxPktSizeHist[uiLoopIndex]);
912 for(uiLoopIndex = 0 ; uiLoopIndex < MIBS_MAX_HIST_ENTRIES ; uiLoopIndex++)
913 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Adapter->aTxPktSizeHist[%x] = %x\n",uiLoopIndex,Adapter->aTxPktSizeHist[uiLoopIndex]);
922 int reset_card_proc(PMINI_ADAPTER ps_adapter)
924 int retval = STATUS_SUCCESS;
926 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
927 PS_INTERFACE_ADAPTER psIntfAdapter = NULL;
928 unsigned int value = 0, uiResetValue = 0;
930 psIntfAdapter = ((PS_INTERFACE_ADAPTER)(ps_adapter->pvInterfaceAdapter)) ;
932 ps_adapter->bDDRInitDone = FALSE;
934 if(ps_adapter->chip_id >= T3LPB)
936 //SYS_CFG register is write protected hence for modifying this reg value, it should be read twice before
937 rdmalt(ps_adapter,SYS_CFG, &value, sizeof(value));
938 rdmalt(ps_adapter,SYS_CFG, &value, sizeof(value));
940 //making bit[6...5] same as was before f/w download. this setting force the h/w to
941 //re-populated the SP RAM area with the string descriptor .
942 value = value | (ps_adapter->syscfgBefFwDld & 0x00000060) ;
943 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
946 //killing all submitted URBs.
947 psIntfAdapter->psAdapter->StopAllXaction = TRUE ;
948 Bcm_kill_all_URBs(psIntfAdapter);
949 /* Reset the UMA-B Device */
950 if(ps_adapter->chip_id >= T3LPB)
952 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Reseting UMA-B \n");
953 retval = usb_reset_device(psIntfAdapter->udev);
955 psIntfAdapter->psAdapter->StopAllXaction = FALSE ;
957 if(retval != STATUS_SUCCESS)
959 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
962 if (ps_adapter->chip_id == BCS220_2 ||
963 ps_adapter->chip_id == BCS220_2BC ||
964 ps_adapter->chip_id == BCS250_BC ||
965 ps_adapter->chip_id == BCS220_3)
967 retval = rdmalt(ps_adapter,HPM_CONFIG_LDO145, &value, sizeof(value));
970 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"read failed with status :%d",retval);
975 retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
978 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
986 retval = rdmalt(ps_adapter,0x0f007018, &value, sizeof(value));
988 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"read failed with status :%d",retval);
992 retval= wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value)) ;
994 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
998 // Toggling the GPIO 8, 9
1000 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
1002 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
1006 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value)) ;
1008 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
1014 //ps_adapter->downloadDDR = false;
1016 if(ps_adapter->bFlashBoot)
1018 //In flash boot mode MIPS state register has reverse polarity.
1019 // So just or with setting bit 30.
1020 //Make the MIPS in Reset state.
1021 rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
1023 uiResetValue |=(1<<30);
1024 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
1027 if(ps_adapter->chip_id >= T3LPB)
1031 // WA for SYSConfig Issue.
1032 // Read SYSCFG Twice to make it writable.
1034 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
1035 if(uiResetValue & (1<<4))
1038 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));//2nd read to make it writable.
1039 uiResetValue &= (~(1<<4));
1040 wrmalt(ps_adapter,SYS_CFG, &uiResetValue, sizeof(uiResetValue));
1045 wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
1048 psIntfAdapter->psAdapter->StopAllXaction = FALSE ;
1052 int run_card_proc(PMINI_ADAPTER ps_adapter )
1054 unsigned int value=0;
1057 if(rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
1058 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"%s:%d\n", __FUNCTION__, __LINE__);
1059 return STATUS_FAILURE;
1062 if(ps_adapter->bFlashBoot)
1072 if(wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
1073 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"%s:%d\n", __FUNCTION__, __LINE__);
1074 return STATUS_FAILURE;
1077 return STATUS_SUCCESS;
1080 int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter)
1083 UINT status = STATUS_SUCCESS;
1086 * Create the threads first and then download the
1087 * Firm/DDR Settings..
1090 status = create_worker_threads(ps_adapter);
1095 * For Downloading the Firm, parse the cfg file first.
1097 status = bcm_parse_target_params (ps_adapter);
1102 if(ps_adapter->chip_id >= T3LPB)
1104 rdmalt(ps_adapter, SYS_CFG, &value, sizeof (value));
1105 ps_adapter->syscfgBefFwDld = value ;
1106 if((value & 0x60)== 0)
1108 ps_adapter->bFlashBoot = TRUE;
1112 reset_card_proc(ps_adapter);
1114 //Initializing the NVM.
1115 BcmInitNVM(ps_adapter);
1116 status = ddr_init(ps_adapter);
1119 pr_err(DRV_NAME "ddr_init Failed\n");
1123 /* Download cfg file */
1124 status = buffDnldVerify(ps_adapter,
1125 (PUCHAR)ps_adapter->pstargetparams,
1126 sizeof(STARGETPARAMS),
1130 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
1134 if(register_networkdev(ps_adapter))
1136 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
1140 if(FALSE == ps_adapter->AutoFirmDld)
1142 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoFirmDld Disabled in CFG File..\n");
1143 //If Auto f/w download is disable, register the control interface,
1144 //register the control interface after the mailbox.
1145 if(register_control_device_interface(ps_adapter) < 0)
1147 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
1151 return STATUS_SUCCESS;
1155 * Do the LED Settings here. It will be used by the Firmware Download
1160 * 1. If the LED Settings fails, do not stop and do the Firmware download.
1161 * 2. This init would happend only if the cfg file is present, else
1162 * call from the ioctl context.
1165 status = InitLedSettings (ps_adapter);
1169 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_PRINTK, 0, 0,"INIT LED FAILED\n");
1172 if(ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1174 ps_adapter->DriverState = DRIVER_INIT;
1175 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1178 if(ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1180 ps_adapter->DriverState = FW_DOWNLOAD;
1181 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1185 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1186 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1188 if(ps_adapter->eNVMType == NVM_FLASH)
1190 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
1193 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL," Propogation of Cal param failed .." );
1198 /* Download Firmare */
1199 if ((status = BcmFileDownload( ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR)))
1201 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Firmware File is present... \n");
1205 status = run_card_proc(ps_adapter);
1208 BCM_DEBUG_PRINT (ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "run_card_proc Failed\n");
1213 ps_adapter->fw_download_done = TRUE;
1217 if(ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1219 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1220 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1227 static int bcm_parse_target_params(PMINI_ADAPTER Adapter)
1229 struct file *flp=NULL;
1230 mm_segment_t oldfs={0};
1235 buff=(PCHAR)kmalloc(BUFFER_1K, GFP_KERNEL);
1240 if((Adapter->pstargetparams =
1241 kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL)) == NULL)
1246 flp=open_firmware_file(Adapter, CFG_FILE);
1248 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE \n", CFG_FILE);
1250 kfree(Adapter->pstargetparams);
1251 Adapter->pstargetparams = NULL;
1254 oldfs=get_fs(); set_fs(get_ds());
1255 len=vfs_read(flp, (void __user __force *)buff, BUFFER_1K, &pos);
1258 if(len != sizeof(STARGETPARAMS))
1260 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Mismatch in Target Param Structure!\n");
1262 kfree(Adapter->pstargetparams);
1263 Adapter->pstargetparams = NULL;
1264 filp_close(flp, current->files);
1267 filp_close(flp, current->files);
1269 /* Check for autolink in config params */
1271 * Values in Adapter->pstargetparams are in network byte order
1273 memcpy(Adapter->pstargetparams, buff, sizeof(STARGETPARAMS));
1275 beceem_parse_target_struct(Adapter);
1276 return STATUS_SUCCESS;
1279 void beceem_parse_target_struct(PMINI_ADAPTER Adapter)
1281 UINT uiHostDrvrCfg6 =0, uiEEPROMFlag = 0;;
1283 if(ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE)
1285 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
1286 Adapter->AutoSyncup = FALSE;
1290 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
1291 Adapter->AutoSyncup = TRUE;
1294 if(ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE)
1296 pr_info(DRV_NAME ": Enabling autolink up");
1297 Adapter->AutoLinkUp = TRUE;
1301 pr_info(DRV_NAME ": Disabling autolink up");
1302 Adapter->AutoLinkUp = FALSE;
1304 // Setting the DDR Setting..
1305 Adapter->DDRSetting =
1306 (ntohl(Adapter->pstargetparams->HostDrvrConfig6) >>8)&0x0F;
1307 Adapter->ulPowerSaveMode =
1308 (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
1310 pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1311 pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
1312 if(ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD)
1314 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1315 Adapter->AutoFirmDld = TRUE;
1319 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1320 Adapter->AutoFirmDld = FALSE;
1322 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1323 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
1324 pr_info(DRV_NAME ": MIPSConfig : 0x%X\n",Adapter->bMipsConfig);
1325 //used for backward compatibility.
1326 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
1328 Adapter->PmuMode= (uiHostDrvrCfg6 >> 24 ) & 0x03;
1329 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
1331 if((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT ) & (0x01))
1333 Adapter->bDoSuspend = TRUE;
1334 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1337 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
1338 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n",uiEEPROMFlag);
1339 Adapter->eNVMType = (NVM_TYPE)((uiEEPROMFlag>>4)&0x3);
1341 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
1343 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
1345 Adapter->bSectorSizeOverride =(bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
1347 if(ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) &0x01)
1348 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
1350 if(Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1351 doPowerAutoCorrection(Adapter);
1355 static VOID doPowerAutoCorrection(PMINI_ADAPTER psAdapter)
1357 UINT reporting_mode;
1359 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) &0x02 ;
1360 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1362 if(reporting_mode == TRUE)
1364 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"can't do suspen/resume as reporting mode is enable");
1365 psAdapter->bDoSuspend = FALSE;
1368 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB))
1370 //If reporting mode is enable, switch PMU to PMC
1372 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
1373 psAdapter->bDoSuspend =FALSE;
1377 //clearing space bit[15..12]
1378 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl((0xF << 12)));
1379 //placing the power save mode option
1380 psAdapter->pstargetparams->HostDrvrConfig6 |= htonl((psAdapter->ulPowerSaveMode << 12));
1383 else if (psAdapter->bIsAutoCorrectEnabled == FALSE)
1386 // remove the autocorrect disable bit set before dumping.
1387 psAdapter->ulPowerSaveMode &= ~(1 << 3);
1388 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl(1 << 15));
1389 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Using Forced User Choice: %lx\n", psAdapter->ulPowerSaveMode);
1394 static unsigned char *ReadMacAddrEEPROM(PMINI_ADAPTER Adapter, ulong dwAddress)
1396 unsigned char *pucmacaddr = NULL;
1397 int status = 0, i=0;
1398 unsigned int temp =0;
1401 pucmacaddr = (unsigned char *)kmalloc(MAC_ADDRESS_SIZE, GFP_KERNEL);
1404 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "No Buffers to Read the EEPROM Address\n");
1408 dwAddress |= 0x5b000000;
1409 status = wrmalt(Adapter, EEPROM_COMMAND_Q_REG,
1410 (PUINT)&dwAddress, sizeof(UINT));
1411 if(status != STATUS_SUCCESS)
1413 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "wrm Failed..\n");
1418 for(i=0;i<MAC_ADDRESS_SIZE;i++)
1420 status = rdmalt(Adapter, EEPROM_READ_DATA_Q_REG, &temp,sizeof(temp));
1421 if(status != STATUS_SUCCESS)
1423 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm Failed..\n");
1428 pucmacaddr[i] = temp & 0xff;
1429 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"%x \n", pucmacaddr[i]);
1437 static void convertEndian(B_UINT8 rwFlag, PUINT puiBuffer, UINT uiByteCount)
1441 if(RWM_WRITE == rwFlag) {
1442 for(uiIndex =0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++) {
1443 puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
1446 for(uiIndex =0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++) {
1447 puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
1452 #define CACHE_ADDRESS_MASK 0x80000000
1453 #define UNCACHE_ADDRESS_MASK 0xa0000000
1455 int rdm(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1459 uiRetVal = Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
1460 uiAddress, pucBuff, sSize);
1467 int wrm(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1471 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
1472 uiAddress, pucBuff, sSize);
1478 int wrmalt (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1480 convertEndian(RWM_WRITE, pucBuff, size);
1481 return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1484 int rdmalt (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1488 uiRetVal = rdm(Adapter,uiAddress,(PUCHAR)pucBuff,size);
1489 convertEndian(RWM_READ, (PUINT)pucBuff, size);
1495 int wrmWithLock(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1497 INT status = STATUS_SUCCESS ;
1498 down(&Adapter->rdmwrmsync);
1500 if((Adapter->IdleMode == TRUE) ||
1501 (Adapter->bShutStatus ==TRUE) ||
1502 (Adapter->bPreparingForLowPowerMode ==TRUE))
1508 status =wrm(Adapter, uiAddress, pucBuff, sSize);
1511 up(&Adapter->rdmwrmsync);
1515 int wrmaltWithLock (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1517 int iRetVal = STATUS_SUCCESS;
1519 down(&Adapter->rdmwrmsync);
1521 if((Adapter->IdleMode == TRUE) ||
1522 (Adapter->bShutStatus ==TRUE) ||
1523 (Adapter->bPreparingForLowPowerMode ==TRUE))
1529 iRetVal = wrmalt(Adapter,uiAddress,pucBuff,size);
1532 up(&Adapter->rdmwrmsync);
1536 int rdmaltWithLock (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1538 INT uiRetVal =STATUS_SUCCESS;
1540 down(&Adapter->rdmwrmsync);
1542 if((Adapter->IdleMode == TRUE) ||
1543 (Adapter->bShutStatus ==TRUE) ||
1544 (Adapter->bPreparingForLowPowerMode ==TRUE))
1550 uiRetVal = rdmalt(Adapter,uiAddress, pucBuff, size);
1553 up(&Adapter->rdmwrmsync);
1558 static VOID HandleShutDownModeWakeup(PMINI_ADAPTER Adapter)
1560 int clear_abort_pattern = 0,Status = 0;
1561 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1562 //target has woken up From Shut Down
1563 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Clearing Shut Down Software abort pattern\n");
1564 Status = wrmalt(Adapter,SW_ABORT_IDLEMODE_LOC, (PUINT)&clear_abort_pattern, sizeof(clear_abort_pattern));
1567 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
1570 if(Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1573 InterfaceHandleShutdownModeWakeup(Adapter);
1576 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1578 Adapter->DriverState = NO_NETWORK_ENTRY;
1579 wake_up(&Adapter->LEDInfo.notify_led_event);
1582 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
1583 Adapter->bShutStatus = FALSE;
1584 wake_up(&Adapter->lowpower_mode_wait_queue);
1585 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1588 static VOID SendShutModeResponse(PMINI_ADAPTER Adapter)
1590 CONTROL_MESSAGE stShutdownResponse;
1591 UINT NVMAccess = 0,lowPwrAbortMsg = 0;
1594 memset (&stShutdownResponse, 0, sizeof(CONTROL_MESSAGE));
1595 stShutdownResponse.Leader.Status = LINK_UP_CONTROL_REQ;
1596 stShutdownResponse.Leader.PLength = 8;//8 bytes;
1597 stShutdownResponse.szData[0] = LINK_UP_ACK;
1598 stShutdownResponse.szData[1] = LINK_SHUTDOWN_REQ_FROM_FIRMWARE;
1600 /*********************************
1602 ** if [ semaphore is available ]
1603 ** acquire semaphone and return value 0 ;
1605 ** return non-zero value ;
1607 ***********************************/
1609 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1611 lowPwrAbortMsg= down_trylock(&Adapter->LowPowerModeSync);
1614 if(NVMAccess || lowPwrAbortMsg|| atomic_read(&Adapter->TotalPacketCount))
1617 up(&Adapter->NVMRdmWrmLock);
1620 up(&Adapter->LowPowerModeSync);
1622 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Device Access is going on NACK the Shut Down MODE\n");
1623 stShutdownResponse.szData[2] = SHUTDOWN_NACK_FROM_DRIVER;//NACK- device access is going on.
1624 Adapter->bPreparingForLowPowerMode = FALSE;
1628 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Sending SHUTDOWN MODE ACK\n");
1629 stShutdownResponse.szData[2] = SHUTDOWN_ACK_FROM_DRIVER;//ShutDown ACK
1631 /* Wait for the LED to TURN OFF before sending ACK response */
1632 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1636 /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1637 Adapter->DriverState = LOWPOWER_MODE_ENTER;
1638 wake_up(&Adapter->LEDInfo.notify_led_event);
1640 /* Wait for 1 SEC for LED to OFF */
1641 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent,\
1642 Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
1644 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
1647 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER;//NACK- device access is going on.
1649 Adapter->DriverState = NO_NETWORK_ENTRY;
1650 wake_up(&Adapter->LEDInfo.notify_led_event);
1654 if(stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER)
1656 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"ACKING SHUTDOWN MODE !!!!!!!!!");
1657 down(&Adapter->rdmwrmsync);
1658 Adapter->bPreparingForLowPowerMode = TRUE;
1659 up(&Adapter->rdmwrmsync);
1661 if(Adapter->bDoSuspend == TRUE)
1662 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1666 Adapter->bPreparingForLowPowerMode = FALSE;
1670 up(&Adapter->NVMRdmWrmLock);
1673 up(&Adapter->LowPowerModeSync);
1675 Status = CopyBufferToControlPacket(Adapter,&stShutdownResponse);
1676 if((Status != STATUS_SUCCESS))
1678 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"fail to send the Idle mode Request \n");
1679 Adapter->bPreparingForLowPowerMode = FALSE;
1681 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1686 static void HandleShutDownModeRequest(PMINI_ADAPTER Adapter,PUCHAR pucBuffer)
1688 B_UINT32 uiResetValue = 0;
1690 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1692 if(*(pucBuffer+1) == COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW)
1694 HandleShutDownModeWakeup(Adapter);
1696 else if(*(pucBuffer+1) == LINK_SHUTDOWN_REQ_FROM_FIRMWARE)
1698 //Target wants to go to Shut Down Mode
1699 //InterfacePrepareForShutdown(Adapter);
1700 if(Adapter->chip_id == BCS220_2 ||
1701 Adapter->chip_id == BCS220_2BC ||
1702 Adapter->chip_id == BCS250_BC ||
1703 Adapter->chip_id == BCS220_3)
1705 rdmalt(Adapter,HPM_CONFIG_MSW, &uiResetValue, 4);
1706 uiResetValue |= (1<<17);
1707 wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1710 SendShutModeResponse(Adapter);
1711 BCM_DEBUG_PRINT (Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"ShutDownModeResponse:Notification received: Sending the response(Ack/Nack)\n");
1714 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1719 VOID ResetCounters(PMINI_ADAPTER Adapter)
1722 beceem_protocol_reset(Adapter);
1724 Adapter->CurrNumRecvDescs = 0;
1725 Adapter->PrevNumRecvDescs = 0;
1726 Adapter->LinkUpStatus = 0;
1727 Adapter->LinkStatus = 0;
1728 atomic_set(&Adapter->cntrlpktCnt,0);
1729 atomic_set (&Adapter->TotalPacketCount,0);
1730 Adapter->fw_download_done=FALSE;
1731 Adapter->LinkStatus = 0;
1732 Adapter->AutoLinkUp = FALSE;
1733 Adapter->IdleMode = FALSE;
1734 Adapter->bShutStatus = FALSE;
1737 S_CLASSIFIER_RULE *GetFragIPClsEntry(PMINI_ADAPTER Adapter,USHORT usIpIdentification,ULONG SrcIP)
1740 for(uiIndex=0;uiIndex<MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES;uiIndex++)
1742 if((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed)&&
1743 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification)&&
1744 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress== SrcIP)&&
1745 !Adapter->astFragmentedPktClassifierTable[uiIndex].bOutOfOrderFragment)
1746 return Adapter->astFragmentedPktClassifierTable[uiIndex].pstMatchedClassifierEntry;
1751 void AddFragIPClsEntry(PMINI_ADAPTER Adapter,PS_FRAGMENTED_PACKET_INFO psFragPktInfo)
1754 for(uiIndex=0;uiIndex<MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES;uiIndex++)
1756 if(!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed)
1758 memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex],psFragPktInfo,sizeof(S_FRAGMENTED_PACKET_INFO));
1765 void DelFragIPClsEntry(PMINI_ADAPTER Adapter,USHORT usIpIdentification,ULONG SrcIp)
1768 for(uiIndex=0;uiIndex<MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES;uiIndex++)
1770 if((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed)&&
1771 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification)&&
1772 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress== SrcIp))
1773 memset(&Adapter->astFragmentedPktClassifierTable[uiIndex],0,sizeof(S_FRAGMENTED_PACKET_INFO));
1777 void update_per_cid_rx (PMINI_ADAPTER Adapter)
1781 if((jiffies - Adapter->liDrainCalculated) < XSECONDS)
1784 for(qindex = 0; qindex < HiPriority; qindex++)
1786 if(Adapter->PackInfo[qindex].ucDirection == 0)
1788 Adapter->PackInfo[qindex].uiCurrentRxRate =
1789 (Adapter->PackInfo[qindex].uiCurrentRxRate +
1790 Adapter->PackInfo[qindex].uiThisPeriodRxBytes)/2;
1792 Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
1796 Adapter->PackInfo[qindex].uiCurrentDrainRate =
1797 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
1798 Adapter->PackInfo[qindex].uiThisPeriodSentBytes)/2;
1800 Adapter->PackInfo[qindex].uiThisPeriodSentBytes=0;
1803 Adapter->liDrainCalculated=jiffies;
1805 void update_per_sf_desc_cnts( PMINI_ADAPTER Adapter)
1808 u32 uibuff[MAX_TARGET_DSX_BUFFERS];
1810 if(!atomic_read (&Adapter->uiMBupdate))
1813 if(rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (PUINT)uibuff, sizeof(UINT) * MAX_TARGET_DSX_BUFFERS)<0)
1815 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
1818 for(iIndex = 0;iIndex < HiPriority; iIndex++)
1820 if(Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection)
1822 if(Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
1824 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
1828 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Invalid VCID : %x \n",
1829 Adapter->PackInfo[iIndex].usVCID_Value);
1833 atomic_set (&Adapter->uiMBupdate, FALSE);
1836 void flush_queue(PMINI_ADAPTER Adapter, UINT iQIndex)
1838 struct sk_buff* PacketToDrop=NULL;
1839 struct net_device_stats* netstats = &Adapter->dev->stats;
1841 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1843 while(Adapter->PackInfo[iQIndex].FirstTxQueue &&
1844 atomic_read(&Adapter->TotalPacketCount))
1846 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
1847 if(PacketToDrop && PacketToDrop->len)
1849 netstats->tx_dropped++;
1850 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, \
1851 Adapter->PackInfo[iQIndex].LastTxQueue);
1853 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1854 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1856 //Adding dropped statistics
1857 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1858 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
1860 dev_kfree_skb(PacketToDrop);
1861 atomic_dec(&Adapter->TotalPacketCount);
1864 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1868 static void beceem_protocol_reset (PMINI_ADAPTER Adapter)
1872 if (netif_msg_link(Adapter))
1873 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
1875 netif_carrier_off(Adapter->dev);
1876 netif_stop_queue(Adapter->dev);
1878 Adapter->IdleMode = FALSE;
1879 Adapter->LinkUpStatus = FALSE;
1880 ClearTargetDSXBuffer(Adapter,0, TRUE);
1881 //Delete All Classifier Rules
1883 for(i = 0;i<HiPriority;i++)
1885 DeleteAllClassifiersForSF(Adapter,i);
1888 flush_all_queues(Adapter);
1890 if(Adapter->TimerActive == TRUE)
1891 Adapter->TimerActive = FALSE;
1893 memset(Adapter->astFragmentedPktClassifierTable, 0,
1894 sizeof(S_FRAGMENTED_PACKET_INFO) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
1896 for(i = 0;i<HiPriority;i++)
1898 //resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF.
1899 // It is same between MIBs and SF.
1900 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable,
1901 0, sizeof(S_MIBS_EXTSERVICEFLOW_PARAMETERS));