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 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
237 vfs_llseek(flp, 0, 0);
240 if(Adapter->bcm_file_readback_from_chip(Adapter->pvInterfaceAdapter,
243 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to read back firmware!");
249 oldfs=get_fs();set_fs(get_ds());
250 if(flp && !(IS_ERR(flp)))
251 filp_close(flp, current->files);
258 @ingroup ctrl_pkt_functions
259 This function copies the contents of given buffer
260 to the control packet and queues it for transmission.
261 @note Do not acquire the spinock, as it it already acquired.
262 @return SUCCESS/FAILURE.
264 INT CopyBufferToControlPacket(PMINI_ADAPTER Adapter,/**<Logical Adapter*/
265 PVOID ioBuffer/**<Control Packet Buffer*/
268 PLEADER pLeader=NULL;
270 unsigned char *ctrl_buff=NULL;
272 PLINK_REQUEST pLinkReq = NULL;
273 PUCHAR pucAddIndication = NULL;
275 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "======>");
278 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Got Null Buffer\n");
282 pLinkReq = (PLINK_REQUEST)ioBuffer;
283 pLeader=(PLEADER)ioBuffer; //ioBuffer Contains sw_Status and Payload
285 if(Adapter->bShutStatus == TRUE &&
286 pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD &&
287 pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE)
289 //Got sync down in SHUTDOWN..we could not process this.
290 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "SYNC DOWN Request in Shut Down Mode..\n");
291 return STATUS_FAILURE;
294 if((pLeader->Status == LINK_UP_CONTROL_REQ) &&
295 ((pLinkReq->szData[0] == LINK_UP_REQ_PAYLOAD &&
296 (pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE)) ||//Sync Up Command
297 pLinkReq->szData[0] == NETWORK_ENTRY_REQ_PAYLOAD)) //Net Entry Command
299 if(Adapter->LinkStatus > PHY_SYNC_ACHIVED)
301 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL,"LinkStatus is Greater than PHY_SYN_ACHIEVED");
302 return STATUS_FAILURE;
304 if(TRUE == Adapter->bShutStatus)
306 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "SYNC UP IN SHUTDOWN..Device WakeUp\n");
307 if(Adapter->bTriedToWakeUpFromlowPowerMode == FALSE)
309 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Waking up for the First Time..\n");
310 Adapter->usIdleModePattern = ABORT_SHUTDOWN_MODE; // change it to 1 for current support.
311 Adapter->bWakeUpDevice = TRUE;
312 wake_up(&Adapter->process_rx_cntrlpkt);
314 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
315 !Adapter->bShutStatus, (5 * HZ));
317 if(Status == -ERESTARTSYS)
320 if(Adapter->bShutStatus)
322 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Shutdown Mode Wake up Failed - No Wake Up Received\n");
323 return STATUS_FAILURE;
328 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Wakeup has been tried already...\n");
333 if(TRUE == Adapter->IdleMode)
335 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle mode ... hence \n");
336 if(pLeader->Status == LINK_UP_CONTROL_REQ || pLeader->Status == 0x80 ||
337 pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ )
340 if((pLeader->Status == LINK_UP_CONTROL_REQ) && (pLinkReq->szData[0]==LINK_DOWN_REQ_PAYLOAD))
342 if((pLinkReq->szData[1] == LINK_SYNC_DOWN_SUBTYPE))
344 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Link Down Sent in Idle Mode\n");
345 Adapter->usIdleModePattern = ABORT_IDLE_SYNCDOWN;//LINK DOWN sent in Idle Mode
349 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL,"ABORT_IDLE_MODE pattern is being written\n");
350 Adapter->usIdleModePattern = ABORT_IDLE_REG;
355 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL,"ABORT_IDLE_MODE pattern is being written\n");
356 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
359 /*Setting bIdleMode_tx_from_host to TRUE to indicate LED control thread to represent
360 the wake up from idlemode is from host*/
361 //Adapter->LEDInfo.bIdleMode_tx_from_host = TRUE;
362 Adapter->bWakeUpDevice = TRUE;
363 wake_up(&Adapter->process_rx_cntrlpkt);
367 if(LINK_DOWN_REQ_PAYLOAD == pLinkReq->szData[0])
369 // We should not send DREG message down while in idlemode.
370 return STATUS_SUCCESS;
373 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
374 !Adapter->IdleMode, (5 * HZ));
376 if(Status == -ERESTARTSYS)
379 if(Adapter->IdleMode)
381 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Idle Mode Wake up Failed - No Wake Up Received\n");
382 return STATUS_FAILURE;
386 return STATUS_SUCCESS;
388 //The Driver has to send control messages with a particular VCID
389 pLeader->Vcid = VCID_CONTROL_PACKET;//VCID for control packet.
391 /* Allocate skb for Control Packet */
392 pktlen = pLeader->PLength;
393 ctrl_buff = (char *)Adapter->txctlpacket[atomic_read(&Adapter->index_wr_txcntrlpkt)%MAX_CNTRL_PKTS];
395 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",
396 atomic_read(&Adapter->index_wr_txcntrlpkt), ctrl_buff, ioBuffer, pktlen);
401 if((pLeader->Status == 0x80) ||
402 (pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ))
405 //Restructure the DSX message to handle Multiple classifier Support
406 // Write the Service Flow param Structures directly to the target
407 //and embed the pointers in the DSX messages sent to target.
409 //Lets store the current length of the control packet we are transmitting
410 pucAddIndication = (PUCHAR)ioBuffer + LEADER_SIZE;
411 pktlen = pLeader->PLength;
412 Status = StoreCmControlResponseMessage(Adapter,pucAddIndication, &pktlen);
415 ClearTargetDSXBuffer(Adapter,((stLocalSFAddIndicationAlt *)pucAddIndication)->u16TID, FALSE);
416 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 ");
417 return STATUS_FAILURE;
420 //update the leader to use the new length
421 //The length of the control packet is length of message being sent + Leader length
423 pLeader->PLength = pktlen;
426 memset(ctrl_buff, 0, pktlen+LEADER_SIZE);
427 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Copying the Control Packet Buffer with length=%d\n", pLeader->PLength);
428 *(PLEADER)ctrl_buff=*pLeader;
429 memcpy(ctrl_buff + LEADER_SIZE, ((PUCHAR)ioBuffer + LEADER_SIZE), pLeader->PLength);
430 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Enqueuing the Control Packet");
432 /*Update the statistics counters */
433 spin_lock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
434 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost+=pLeader->PLength;
435 Adapter->PackInfo[HiPriority].uiCurrentPacketsOnHost++;
436 atomic_inc(&Adapter->TotalPacketCount);
437 spin_unlock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
439 Adapter->PackInfo[HiPriority].bValid = TRUE;
441 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "CurrBytesOnHost: %x bValid: %x",
442 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost,
443 Adapter->PackInfo[HiPriority].bValid);
444 Status=STATUS_SUCCESS;
445 /*Queue the packet for transmission */
446 atomic_inc(&Adapter->index_wr_txcntrlpkt);
447 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Calling transmit_packets");
448 atomic_set(&Adapter->TxPktAvail, 1);
449 wake_up(&Adapter->tx_packet_wait_queue);
454 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "mem allocation Failed");
456 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<====");
461 /*****************************************************************
462 * Function - SendStatisticsPointerRequest()
464 * Description - This function builds and forwards the Statistics
465 * Pointer Request control Packet.
467 * Parameters - Adapter : Pointer to Adapter structure.
468 * - pstStatisticsPtrRequest : Pointer to link request.
471 *****************************************************************/
472 static VOID SendStatisticsPointerRequest(PMINI_ADAPTER Adapter,
473 PLINK_REQUEST pstStatisticsPtrRequest)
475 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "======>");
476 pstStatisticsPtrRequest->Leader.Status = STATS_POINTER_REQ_STATUS;
477 pstStatisticsPtrRequest->Leader.PLength = sizeof(ULONG);//minimum 4 bytes
478 pstStatisticsPtrRequest->szData[0] = STATISTICS_POINTER_REQ;
480 CopyBufferToControlPacket(Adapter,pstStatisticsPtrRequest);
481 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "<=====");
487 /******************************************************************
488 * Function - LinkMessage()
490 * Description - This function builds the Sync-up and Link-up request
491 * packet messages depending on the device Link status.
493 * Parameters - Adapter: Pointer to the Adapter structure.
496 *******************************************************************/
497 VOID LinkMessage(PMINI_ADAPTER Adapter)
499 PLINK_REQUEST pstLinkRequest=NULL;
500 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>");
501 if(Adapter->LinkStatus == SYNC_UP_REQUEST && Adapter->AutoSyncup)
503 pstLinkRequest=kmalloc(sizeof(LINK_REQUEST), GFP_ATOMIC);
506 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
509 memset(pstLinkRequest,0,sizeof(LINK_REQUEST));
511 Adapter->LinkStatus = WAIT_FOR_SYNC;// current link status
512 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For SyncUp...");
513 pstLinkRequest->szData[0]=LINK_UP_REQ_PAYLOAD;
514 pstLinkRequest->szData[1]=LINK_SYNC_UP_SUBTYPE;
515 pstLinkRequest->Leader.Status=LINK_UP_CONTROL_REQ;
516 pstLinkRequest->Leader.PLength=sizeof(ULONG);
517 Adapter->bSyncUpRequestSent = TRUE;
519 else if(Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp)
521 pstLinkRequest=kmalloc(sizeof(LINK_REQUEST), GFP_ATOMIC);
524 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
527 memset(pstLinkRequest,0,sizeof(LINK_REQUEST));
529 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For LinkUp...");
530 pstLinkRequest->szData[0]=LINK_UP_REQ_PAYLOAD;
531 pstLinkRequest->szData[1]=LINK_NET_ENTRY;
532 pstLinkRequest->Leader.Status=LINK_UP_CONTROL_REQ;
533 pstLinkRequest->Leader.PLength=sizeof(ULONG);
537 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
538 CopyBufferToControlPacket(Adapter, pstLinkRequest);
539 kfree(pstLinkRequest);
541 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
546 /**********************************************************************
547 * Function - StatisticsResponse()
549 * Description - This function handles the Statistics response packet.
551 * Parameters - Adapter : Pointer to the Adapter structure.
552 * - pvBuffer: Starting address of Statistic response data.
555 ************************************************************************/
556 VOID StatisticsResponse(PMINI_ADAPTER Adapter,PVOID pvBuffer)
558 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>",__FUNCTION__);
559 Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
560 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (UINT)Adapter->StatisticsPointer);
561 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====",__FUNCTION__);
566 /**********************************************************************
567 * Function - LinkControlResponseMessage()
569 * Description - This function handles the Link response packets.
571 * Parameters - Adapter : Pointer to the Adapter structure.
572 * - pucBuffer: Starting address of Link response data.
575 ***********************************************************************/
576 VOID LinkControlResponseMessage(PMINI_ADAPTER Adapter,PUCHAR pucBuffer)
578 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
580 if(*pucBuffer==LINK_UP_ACK)
582 switch(*(pucBuffer+1))
584 case PHY_SYNC_ACHIVED: //SYNCed UP
585 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "PHY_SYNC_ACHIVED");
587 if(Adapter->LinkStatus == LINKUP_DONE)
589 beceem_protocol_reset(Adapter);
592 Adapter->usBestEffortQueueIndex=INVALID_QUEUE_INDEX ;
593 Adapter->LinkStatus=PHY_SYNC_ACHIVED;
595 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
597 Adapter->DriverState = NO_NETWORK_ENTRY;
598 wake_up(&Adapter->LEDInfo.notify_led_event);
601 LinkMessage(Adapter);
605 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LINKUP_DONE");
606 Adapter->LinkStatus=LINKUP_DONE;
607 Adapter->bPHSEnabled = *(pucBuffer+3);
608 Adapter->bETHCSEnabled = *(pucBuffer+4) & ETH_CS_MASK;
609 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "PHS Support Status Recieved In LinkUp Ack : %x \n",Adapter->bPHSEnabled);
610 if((FALSE == Adapter->bShutStatus)&&
611 (FALSE == Adapter->IdleMode))
613 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
615 Adapter->DriverState = NORMAL_OPERATION;
616 wake_up(&Adapter->LEDInfo.notify_led_event);
619 LinkMessage(Adapter);
624 * Driver to ignore the DREG_RECEIVED
625 * WiMAX Application should handle this Message
627 //Adapter->liTimeSinceLastNetEntry = 0;
628 Adapter->LinkUpStatus = 0;
629 Adapter->LinkStatus = 0;
630 Adapter->usBestEffortQueueIndex=INVALID_QUEUE_INDEX ;
631 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
632 Adapter->IdleMode = FALSE;
633 beceem_protocol_reset(Adapter);
636 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
637 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
639 HandleShutDownModeRequest(Adapter, pucBuffer);
643 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x",*(pucBuffer+1));
647 else if(SET_MAC_ADDRESS_RESPONSE==*pucBuffer)
649 PUCHAR puMacAddr = (pucBuffer + 1);
650 Adapter->LinkStatus=SYNC_UP_REQUEST;
651 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "MAC address response, sending SYNC_UP");
652 LinkMessage(Adapter);
653 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
655 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====",__FUNCTION__);
659 void SendIdleModeResponse(PMINI_ADAPTER Adapter)
661 INT status = 0, NVMAccess = 0,lowPwrAbortMsg = 0;
663 CONTROL_MESSAGE stIdleResponse = {{0}};
664 memset(&tv, 0, sizeof(tv));
665 stIdleResponse.Leader.Status = IDLE_MESSAGE;
666 stIdleResponse.Leader.PLength = IDLE_MODE_PAYLOAD_LENGTH;
667 stIdleResponse.szData[0] = GO_TO_IDLE_MODE_PAYLOAD;
668 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL," ============>");
670 /*********************************
672 ** if [ semaphore is available ]
673 ** acquire semaphone and return value 0 ;
675 ** return non-zero value ;
677 ***********************************/
679 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
681 lowPwrAbortMsg= down_trylock(&Adapter->LowPowerModeSync);
684 if((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
685 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) )
688 up(&Adapter->NVMRdmWrmLock);
691 up(&Adapter->LowPowerModeSync);
693 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE;//NACK- device access is going on.
694 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "HOST IS NACKING Idle mode To F/W!!!!!!!!");
695 Adapter->bPreparingForLowPowerMode = FALSE;
699 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; //2;//Idle ACK
700 Adapter->StatisticsPointer = 0;
702 /* Wait for the LED to TURN OFF before sending ACK response */
703 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
707 /* Wake the LED Thread with IDLEMODE_ENTER State */
708 Adapter->DriverState = LOWPOWER_MODE_ENTER;
709 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);
710 wake_up(&Adapter->LEDInfo.notify_led_event);
712 /* Wait for 1 SEC for LED to OFF */
713 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, \
714 Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
717 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
720 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE;//NACK- device access is going on.
721 Adapter->DriverState = NORMAL_OPERATION;
722 wake_up(&Adapter->LEDInfo.notify_led_event);
723 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "NACKING Idle mode as time out happen from LED side!!!!!!!!");
726 if(stIdleResponse.szData[1] == TARGET_CAN_GO_TO_IDLE_MODE)
728 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL,"ACKING IDLE MODE !!!!!!!!!");
729 down(&Adapter->rdmwrmsync);
730 Adapter->bPreparingForLowPowerMode = TRUE;
731 up(&Adapter->rdmwrmsync);
733 if(Adapter->bDoSuspend == TRUE)
734 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
739 Adapter->bPreparingForLowPowerMode = FALSE;
743 up(&Adapter->NVMRdmWrmLock);
746 up(&Adapter->LowPowerModeSync);
749 status = CopyBufferToControlPacket(Adapter,&stIdleResponse);
750 if((status != STATUS_SUCCESS))
752 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"fail to send the Idle mode Request \n");
753 Adapter->bPreparingForLowPowerMode = FALSE;
754 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
756 do_gettimeofday(&tv);
757 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);
761 /******************************************************************
762 * Function - DumpPackInfo()
764 * Description - This function dumps the all Queue(PackInfo[]) details.
766 * Parameters - Adapter: Pointer to the Adapter structure.
769 *******************************************************************/
770 VOID DumpPackInfo(PMINI_ADAPTER Adapter)
773 UINT uiLoopIndex = 0;
775 UINT uiClsfrIndex = 0;
776 S_CLASSIFIER_RULE *pstClassifierEntry = NULL;
778 for(uiLoopIndex=0;uiLoopIndex<NO_OF_QUEUES;uiLoopIndex++)
780 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"*********** Showing Details Of Queue %d***** ******",uiLoopIndex);
781 if(FALSE == Adapter->PackInfo[uiLoopIndex].bValid)
783 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"bValid is FALSE for %X index\n",uiLoopIndex);
787 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL," Dumping SF Rule Entry For SFID %lX \n",Adapter->PackInfo[uiLoopIndex].ulSFID);
788 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL," ucDirection %X \n",Adapter->PackInfo[uiLoopIndex].ucDirection);
789 if(Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
791 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Ipv6 Service Flow \n");
795 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Ipv4 Service Flow \n");
797 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL," SF Traffic Priority %X \n",Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
799 for(uiClsfrIndex=0;uiClsfrIndex<MAX_CLASSIFIERS;uiClsfrIndex++)
801 pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
802 if(!pstClassifierEntry->bUsed)
805 if(pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
808 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);
809 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);
810 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);
811 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);
812 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);
813 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);
816 for(uiIndex=0;uiIndex<MAX_PORT_RANGE;uiIndex++)
818 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tusSrcPortRangeLo:%X\n",pstClassifierEntry->usSrcPortRangeLo[uiIndex]);
819 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tusSrcPortRangeHi:%X\n",pstClassifierEntry->usSrcPortRangeHi[uiIndex]);
820 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tusDestPortRangeLo:%X\n",pstClassifierEntry->usDestPortRangeLo[uiIndex]);
821 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tusDestPortRangeHi:%X\n",pstClassifierEntry->usDestPortRangeHi[uiIndex]);
824 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL," \tucIPSourceAddressLength : 0x%x\n",pstClassifierEntry->ucIPSourceAddressLength);
825 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tucIPDestinationAddressLength : 0x%x\n",pstClassifierEntry->ucIPDestinationAddressLength);
826 for(uiIndex=0;uiIndex<pstClassifierEntry->ucIPSourceAddressLength;uiIndex++)
828 if(Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
830 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tIpv6 ulSrcIpAddr :\n");
831 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Addr);
832 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tIpv6 ulSrcIpMask :\n");
833 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Mask);
837 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tulSrcIpAddr:%lX\n",pstClassifierEntry->stSrcIpAddress.ulIpv4Addr[uiIndex]);
838 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tulSrcIpMask:%lX\n",pstClassifierEntry->stSrcIpAddress.ulIpv4Mask[uiIndex]);
841 for(uiIndex=0;uiIndex<pstClassifierEntry->ucIPDestinationAddressLength;uiIndex++)
843 if(Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
845 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tIpv6 ulDestIpAddr :\n");
846 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Addr);
847 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tIpv6 ulDestIpMask :\n");
848 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Mask);
853 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tulDestIpAddr:%lX\n",pstClassifierEntry->stDestIpAddress.ulIpv4Addr[uiIndex]);
854 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tulDestIpMask:%lX\n",pstClassifierEntry->stDestIpAddress.ulIpv4Mask[uiIndex]);
857 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tucProtocol:0x%X\n",pstClassifierEntry->ucProtocol[0]);
858 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"\tu8ClassifierRulePriority:%X\n",pstClassifierEntry->u8ClassifierRulePriority);
862 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"ulSFID:%lX\n",Adapter->PackInfo[uiLoopIndex].ulSFID);
863 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"usVCID_Value:%X\n",Adapter->PackInfo[uiLoopIndex].usVCID_Value);
864 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"PhsEnabled: 0x%X\n",Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
865 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiThreshold:%X\n",Adapter->PackInfo[uiLoopIndex].uiThreshold);
868 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"bValid:%X\n",Adapter->PackInfo[uiLoopIndex].bValid);
869 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"bActive:%X\n",Adapter->PackInfo[uiLoopIndex].bActive);
870 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"ActivateReqSent: %x", Adapter->PackInfo[uiLoopIndex].bActivateRequestSent);
871 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"u8QueueType:%X\n",Adapter->PackInfo[uiLoopIndex].u8QueueType);
872 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiMaxBucketSize:%X\n",Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize);
873 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiPerSFTxResourceCount:%X\n",atomic_read(&Adapter->PackInfo[uiLoopIndex].uiPerSFTxResourceCount));
874 //DumpDebug(DUMP_INFO,(" bCSSupport:%X\n",Adapter->PackInfo[uiLoopIndex].bCSSupport));
875 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"CurrQueueDepthOnTarget: %x\n", Adapter->PackInfo[uiLoopIndex].uiCurrentQueueDepthOnTarget);
876 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiCurrentBytesOnHost:%X\n",Adapter->PackInfo[uiLoopIndex].uiCurrentBytesOnHost);
877 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiCurrentPacketsOnHost:%X\n",Adapter->PackInfo[uiLoopIndex].uiCurrentPacketsOnHost);
878 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiDroppedCountBytes:%X\n",Adapter->PackInfo[uiLoopIndex].uiDroppedCountBytes);
879 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiDroppedCountPackets:%X\n",Adapter->PackInfo[uiLoopIndex].uiDroppedCountPackets);
880 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiSentBytes:%X\n",Adapter->PackInfo[uiLoopIndex].uiSentBytes);
881 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiSentPackets:%X\n",Adapter->PackInfo[uiLoopIndex].uiSentPackets);
882 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiCurrentDrainRate:%X\n",Adapter->PackInfo[uiLoopIndex].uiCurrentDrainRate);
883 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiThisPeriodSentBytes:%X\n",Adapter->PackInfo[uiLoopIndex].uiThisPeriodSentBytes);
884 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"liDrainCalculated:%llX\n",Adapter->PackInfo[uiLoopIndex].liDrainCalculated);
885 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiCurrentTokenCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiCurrentTokenCount);
886 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"liLastUpdateTokenAt:%llX\n",Adapter->PackInfo[uiLoopIndex].liLastUpdateTokenAt);
887 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiMaxAllowedRate:%X\n",Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate);
888 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"uiPendedLast:%X\n",Adapter->PackInfo[uiLoopIndex].uiPendedLast);
889 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"NumOfPacketsSent:%X\n",Adapter->PackInfo[uiLoopIndex].NumOfPacketsSent);
890 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Direction: %x\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
891 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CID: %x\n", Adapter->PackInfo[uiLoopIndex].usCID);
892 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ProtocolValid: %x\n", Adapter->PackInfo[uiLoopIndex].bProtocolValid);
893 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "TOSValid: %x\n", Adapter->PackInfo[uiLoopIndex].bTOSValid);
894 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "DestIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bDestIpValid);
895 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SrcIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bSrcIpValid);
896 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActiveSet: %x\n", Adapter->PackInfo[uiLoopIndex].bActiveSet);
897 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AdmittedSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAdmittedSet);
898 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AuthzSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAuthorizedSet);
899 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ClassifyPrority: %x\n", Adapter->PackInfo[uiLoopIndex].bClassifierPriority);
900 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxLatency: %x\n",Adapter->PackInfo[uiLoopIndex].uiMaxLatency);
901 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]);
902 // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bHeaderSuppressionEnabled :%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
903 // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalTxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalTxBytes);
904 // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalRxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalRxBytes);
905 // DumpDebug(DUMP_INFO,(" uiRanOutOfResCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiRanOutOfResCount));
908 for(uiLoopIndex = 0 ; uiLoopIndex < MIBS_MAX_HIST_ENTRIES ; uiLoopIndex++)
909 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Adapter->aRxPktSizeHist[%x] = %x\n",uiLoopIndex,Adapter->aRxPktSizeHist[uiLoopIndex]);
911 for(uiLoopIndex = 0 ; uiLoopIndex < MIBS_MAX_HIST_ENTRIES ; uiLoopIndex++)
912 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,"Adapter->aTxPktSizeHist[%x] = %x\n",uiLoopIndex,Adapter->aTxPktSizeHist[uiLoopIndex]);
921 int reset_card_proc(PMINI_ADAPTER ps_adapter)
923 int retval = STATUS_SUCCESS;
925 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
926 PS_INTERFACE_ADAPTER psIntfAdapter = NULL;
927 unsigned int value = 0, uiResetValue = 0;
929 psIntfAdapter = ((PS_INTERFACE_ADAPTER)(ps_adapter->pvInterfaceAdapter)) ;
931 ps_adapter->bDDRInitDone = FALSE;
933 if(ps_adapter->chip_id >= T3LPB)
935 //SYS_CFG register is write protected hence for modifying this reg value, it should be read twice before
936 rdmalt(ps_adapter,SYS_CFG, &value, sizeof(value));
937 rdmalt(ps_adapter,SYS_CFG, &value, sizeof(value));
939 //making bit[6...5] same as was before f/w download. this setting force the h/w to
940 //re-populated the SP RAM area with the string descriptor .
941 value = value | (ps_adapter->syscfgBefFwDld & 0x00000060) ;
942 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
945 //killing all submitted URBs.
946 psIntfAdapter->psAdapter->StopAllXaction = TRUE ;
947 Bcm_kill_all_URBs(psIntfAdapter);
948 /* Reset the UMA-B Device */
949 if(ps_adapter->chip_id >= T3LPB)
951 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Reseting UMA-B \n");
952 retval = usb_reset_device(psIntfAdapter->udev);
954 psIntfAdapter->psAdapter->StopAllXaction = FALSE ;
956 if(retval != STATUS_SUCCESS)
958 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
961 if (ps_adapter->chip_id == BCS220_2 ||
962 ps_adapter->chip_id == BCS220_2BC ||
963 ps_adapter->chip_id == BCS250_BC ||
964 ps_adapter->chip_id == BCS220_3)
966 retval = rdmalt(ps_adapter,HPM_CONFIG_LDO145, &value, sizeof(value));
969 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"read failed with status :%d",retval);
974 retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
977 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
985 retval = rdmalt(ps_adapter,0x0f007018, &value, sizeof(value));
987 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"read failed with status :%d",retval);
991 retval= wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value)) ;
993 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
997 // Toggling the GPIO 8, 9
999 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
1001 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
1005 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value)) ;
1007 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"write failed with status :%d",retval);
1013 //ps_adapter->downloadDDR = false;
1015 if(ps_adapter->bFlashBoot)
1017 //In flash boot mode MIPS state register has reverse polarity.
1018 // So just or with setting bit 30.
1019 //Make the MIPS in Reset state.
1020 rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
1022 uiResetValue |=(1<<30);
1023 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
1026 if(ps_adapter->chip_id >= T3LPB)
1030 // WA for SYSConfig Issue.
1031 // Read SYSCFG Twice to make it writable.
1033 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
1034 if(uiResetValue & (1<<4))
1037 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));//2nd read to make it writable.
1038 uiResetValue &= (~(1<<4));
1039 wrmalt(ps_adapter,SYS_CFG, &uiResetValue, sizeof(uiResetValue));
1044 wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
1047 psIntfAdapter->psAdapter->StopAllXaction = FALSE ;
1051 int run_card_proc(PMINI_ADAPTER ps_adapter )
1053 unsigned int value=0;
1056 if(rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
1057 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"%s:%d\n", __FUNCTION__, __LINE__);
1058 return STATUS_FAILURE;
1061 if(ps_adapter->bFlashBoot)
1071 if(wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
1072 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"%s:%d\n", __FUNCTION__, __LINE__);
1073 return STATUS_FAILURE;
1076 return STATUS_SUCCESS;
1079 int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter)
1085 * Create the threads first and then download the
1086 * Firm/DDR Settings..
1089 status = create_worker_threads(ps_adapter);
1094 * For Downloading the Firm, parse the cfg file first.
1096 status = bcm_parse_target_params (ps_adapter);
1101 if(ps_adapter->chip_id >= T3LPB)
1103 rdmalt(ps_adapter, SYS_CFG, &value, sizeof (value));
1104 ps_adapter->syscfgBefFwDld = value ;
1105 if((value & 0x60)== 0)
1107 ps_adapter->bFlashBoot = TRUE;
1111 reset_card_proc(ps_adapter);
1113 //Initializing the NVM.
1114 BcmInitNVM(ps_adapter);
1115 status = ddr_init(ps_adapter);
1118 pr_err(DRV_NAME "ddr_init Failed\n");
1122 /* Download cfg file */
1123 status = buffDnldVerify(ps_adapter,
1124 (PUCHAR)ps_adapter->pstargetparams,
1125 sizeof(STARGETPARAMS),
1129 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
1133 if(register_networkdev(ps_adapter))
1135 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
1139 if(FALSE == ps_adapter->AutoFirmDld)
1141 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoFirmDld Disabled in CFG File..\n");
1142 //If Auto f/w download is disable, register the control interface,
1143 //register the control interface after the mailbox.
1144 if(register_control_device_interface(ps_adapter) < 0)
1146 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
1150 return STATUS_SUCCESS;
1154 * Do the LED Settings here. It will be used by the Firmware Download
1159 * 1. If the LED Settings fails, do not stop and do the Firmware download.
1160 * 2. This init would happend only if the cfg file is present, else
1161 * call from the ioctl context.
1164 status = InitLedSettings (ps_adapter);
1168 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_PRINTK, 0, 0,"INIT LED FAILED\n");
1171 if(ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1173 ps_adapter->DriverState = DRIVER_INIT;
1174 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1177 if(ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1179 ps_adapter->DriverState = FW_DOWNLOAD;
1180 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1184 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1185 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1187 if(ps_adapter->eNVMType == NVM_FLASH)
1189 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
1192 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL," Propogation of Cal param failed .." );
1197 /* Download Firmare */
1198 if ((status = BcmFileDownload( ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR)))
1200 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Firmware File is present... \n");
1204 status = run_card_proc(ps_adapter);
1207 BCM_DEBUG_PRINT (ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "run_card_proc Failed\n");
1212 ps_adapter->fw_download_done = TRUE;
1216 if(ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1218 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1219 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1226 static int bcm_parse_target_params(PMINI_ADAPTER Adapter)
1228 struct file *flp=NULL;
1229 mm_segment_t oldfs={0};
1234 buff=kmalloc(BUFFER_1K, GFP_KERNEL);
1239 if((Adapter->pstargetparams =
1240 kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL)) == NULL)
1245 flp=open_firmware_file(Adapter, CFG_FILE);
1247 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE \n", CFG_FILE);
1249 kfree(Adapter->pstargetparams);
1250 Adapter->pstargetparams = NULL;
1253 oldfs=get_fs(); set_fs(get_ds());
1254 len=vfs_read(flp, (void __user __force *)buff, BUFFER_1K, &pos);
1257 if(len != sizeof(STARGETPARAMS))
1259 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Mismatch in Target Param Structure!\n");
1261 kfree(Adapter->pstargetparams);
1262 Adapter->pstargetparams = NULL;
1263 filp_close(flp, current->files);
1266 filp_close(flp, current->files);
1268 /* Check for autolink in config params */
1270 * Values in Adapter->pstargetparams are in network byte order
1272 memcpy(Adapter->pstargetparams, buff, sizeof(STARGETPARAMS));
1274 beceem_parse_target_struct(Adapter);
1275 return STATUS_SUCCESS;
1278 void beceem_parse_target_struct(PMINI_ADAPTER Adapter)
1280 UINT uiHostDrvrCfg6 =0, uiEEPROMFlag = 0;
1282 if(ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE)
1284 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
1285 Adapter->AutoSyncup = FALSE;
1289 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
1290 Adapter->AutoSyncup = TRUE;
1293 if(ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE)
1295 pr_info(DRV_NAME ": Enabling autolink up");
1296 Adapter->AutoLinkUp = TRUE;
1300 pr_info(DRV_NAME ": Disabling autolink up");
1301 Adapter->AutoLinkUp = FALSE;
1303 // Setting the DDR Setting..
1304 Adapter->DDRSetting =
1305 (ntohl(Adapter->pstargetparams->HostDrvrConfig6) >>8)&0x0F;
1306 Adapter->ulPowerSaveMode =
1307 (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
1309 pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1310 pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
1311 if(ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD)
1313 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1314 Adapter->AutoFirmDld = TRUE;
1318 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1319 Adapter->AutoFirmDld = FALSE;
1321 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1322 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
1323 pr_info(DRV_NAME ": MIPSConfig : 0x%X\n",Adapter->bMipsConfig);
1324 //used for backward compatibility.
1325 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
1327 Adapter->PmuMode= (uiHostDrvrCfg6 >> 24 ) & 0x03;
1328 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
1330 if((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT ) & (0x01))
1332 Adapter->bDoSuspend = TRUE;
1333 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1336 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
1337 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n",uiEEPROMFlag);
1338 Adapter->eNVMType = (NVM_TYPE)((uiEEPROMFlag>>4)&0x3);
1340 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
1342 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
1344 Adapter->bSectorSizeOverride =(bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
1346 if(ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) &0x01)
1347 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
1349 if(Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1350 doPowerAutoCorrection(Adapter);
1354 static VOID doPowerAutoCorrection(PMINI_ADAPTER psAdapter)
1356 UINT reporting_mode;
1358 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) &0x02 ;
1359 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1361 if(reporting_mode == TRUE)
1363 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"can't do suspen/resume as reporting mode is enable");
1364 psAdapter->bDoSuspend = FALSE;
1367 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB))
1369 //If reporting mode is enable, switch PMU to PMC
1371 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
1372 psAdapter->bDoSuspend =FALSE;
1376 //clearing space bit[15..12]
1377 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl((0xF << 12)));
1378 //placing the power save mode option
1379 psAdapter->pstargetparams->HostDrvrConfig6 |= htonl((psAdapter->ulPowerSaveMode << 12));
1382 else if (psAdapter->bIsAutoCorrectEnabled == FALSE)
1385 // remove the autocorrect disable bit set before dumping.
1386 psAdapter->ulPowerSaveMode &= ~(1 << 3);
1387 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl(1 << 15));
1388 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Using Forced User Choice: %lx\n", psAdapter->ulPowerSaveMode);
1393 static unsigned char *ReadMacAddrEEPROM(PMINI_ADAPTER Adapter, ulong dwAddress)
1395 int status = 0, i = 0;
1396 unsigned int temp = 0;
1397 unsigned char *pucmacaddr = kmalloc(MAC_ADDRESS_SIZE, GFP_KERNEL);
1401 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "No Buffers to Read the EEPROM Address\n");
1405 dwAddress |= 0x5b000000;
1406 status = wrmalt(Adapter, EEPROM_COMMAND_Q_REG,
1407 (PUINT)&dwAddress, sizeof(UINT));
1408 if(status != STATUS_SUCCESS)
1410 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "wrm Failed..\n");
1415 for(i=0;i<MAC_ADDRESS_SIZE;i++)
1417 status = rdmalt(Adapter, EEPROM_READ_DATA_Q_REG, &temp,sizeof(temp));
1418 if(status != STATUS_SUCCESS)
1420 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm Failed..\n");
1425 pucmacaddr[i] = temp & 0xff;
1426 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"%x \n", pucmacaddr[i]);
1434 static void convertEndian(B_UINT8 rwFlag, PUINT puiBuffer, UINT uiByteCount)
1438 if(RWM_WRITE == rwFlag) {
1439 for(uiIndex =0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++) {
1440 puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
1443 for(uiIndex =0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++) {
1444 puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
1449 #define CACHE_ADDRESS_MASK 0x80000000
1450 #define UNCACHE_ADDRESS_MASK 0xa0000000
1452 int rdm(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1456 uiRetVal = Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
1457 uiAddress, pucBuff, sSize);
1464 int wrm(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1468 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
1469 uiAddress, pucBuff, sSize);
1475 int wrmalt (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1477 convertEndian(RWM_WRITE, pucBuff, size);
1478 return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1481 int rdmalt (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1485 uiRetVal = rdm(Adapter,uiAddress,(PUCHAR)pucBuff,size);
1486 convertEndian(RWM_READ, (PUINT)pucBuff, size);
1492 int wrmWithLock(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1494 INT status = STATUS_SUCCESS ;
1495 down(&Adapter->rdmwrmsync);
1497 if((Adapter->IdleMode == TRUE) ||
1498 (Adapter->bShutStatus ==TRUE) ||
1499 (Adapter->bPreparingForLowPowerMode ==TRUE))
1505 status =wrm(Adapter, uiAddress, pucBuff, sSize);
1508 up(&Adapter->rdmwrmsync);
1512 int wrmaltWithLock (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1514 int iRetVal = STATUS_SUCCESS;
1516 down(&Adapter->rdmwrmsync);
1518 if((Adapter->IdleMode == TRUE) ||
1519 (Adapter->bShutStatus ==TRUE) ||
1520 (Adapter->bPreparingForLowPowerMode ==TRUE))
1526 iRetVal = wrmalt(Adapter,uiAddress,pucBuff,size);
1529 up(&Adapter->rdmwrmsync);
1533 int rdmaltWithLock (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1535 INT uiRetVal =STATUS_SUCCESS;
1537 down(&Adapter->rdmwrmsync);
1539 if((Adapter->IdleMode == TRUE) ||
1540 (Adapter->bShutStatus ==TRUE) ||
1541 (Adapter->bPreparingForLowPowerMode ==TRUE))
1547 uiRetVal = rdmalt(Adapter,uiAddress, pucBuff, size);
1550 up(&Adapter->rdmwrmsync);
1555 static VOID HandleShutDownModeWakeup(PMINI_ADAPTER Adapter)
1557 int clear_abort_pattern = 0,Status = 0;
1558 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1559 //target has woken up From Shut Down
1560 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Clearing Shut Down Software abort pattern\n");
1561 Status = wrmalt(Adapter,SW_ABORT_IDLEMODE_LOC, (PUINT)&clear_abort_pattern, sizeof(clear_abort_pattern));
1564 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
1567 if(Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1570 InterfaceHandleShutdownModeWakeup(Adapter);
1573 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1575 Adapter->DriverState = NO_NETWORK_ENTRY;
1576 wake_up(&Adapter->LEDInfo.notify_led_event);
1579 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
1580 Adapter->bShutStatus = FALSE;
1581 wake_up(&Adapter->lowpower_mode_wait_queue);
1582 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1585 static VOID SendShutModeResponse(PMINI_ADAPTER Adapter)
1587 CONTROL_MESSAGE stShutdownResponse;
1588 UINT NVMAccess = 0,lowPwrAbortMsg = 0;
1591 memset (&stShutdownResponse, 0, sizeof(CONTROL_MESSAGE));
1592 stShutdownResponse.Leader.Status = LINK_UP_CONTROL_REQ;
1593 stShutdownResponse.Leader.PLength = 8;//8 bytes;
1594 stShutdownResponse.szData[0] = LINK_UP_ACK;
1595 stShutdownResponse.szData[1] = LINK_SHUTDOWN_REQ_FROM_FIRMWARE;
1597 /*********************************
1599 ** if [ semaphore is available ]
1600 ** acquire semaphone and return value 0 ;
1602 ** return non-zero value ;
1604 ***********************************/
1606 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1608 lowPwrAbortMsg= down_trylock(&Adapter->LowPowerModeSync);
1611 if(NVMAccess || lowPwrAbortMsg|| atomic_read(&Adapter->TotalPacketCount))
1614 up(&Adapter->NVMRdmWrmLock);
1617 up(&Adapter->LowPowerModeSync);
1619 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Device Access is going on NACK the Shut Down MODE\n");
1620 stShutdownResponse.szData[2] = SHUTDOWN_NACK_FROM_DRIVER;//NACK- device access is going on.
1621 Adapter->bPreparingForLowPowerMode = FALSE;
1625 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Sending SHUTDOWN MODE ACK\n");
1626 stShutdownResponse.szData[2] = SHUTDOWN_ACK_FROM_DRIVER;//ShutDown ACK
1628 /* Wait for the LED to TURN OFF before sending ACK response */
1629 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
1633 /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1634 Adapter->DriverState = LOWPOWER_MODE_ENTER;
1635 wake_up(&Adapter->LEDInfo.notify_led_event);
1637 /* Wait for 1 SEC for LED to OFF */
1638 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent,\
1639 Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
1641 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
1644 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER;//NACK- device access is going on.
1646 Adapter->DriverState = NO_NETWORK_ENTRY;
1647 wake_up(&Adapter->LEDInfo.notify_led_event);
1651 if(stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER)
1653 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"ACKING SHUTDOWN MODE !!!!!!!!!");
1654 down(&Adapter->rdmwrmsync);
1655 Adapter->bPreparingForLowPowerMode = TRUE;
1656 up(&Adapter->rdmwrmsync);
1658 if(Adapter->bDoSuspend == TRUE)
1659 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1663 Adapter->bPreparingForLowPowerMode = FALSE;
1667 up(&Adapter->NVMRdmWrmLock);
1670 up(&Adapter->LowPowerModeSync);
1672 Status = CopyBufferToControlPacket(Adapter,&stShutdownResponse);
1673 if((Status != STATUS_SUCCESS))
1675 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"fail to send the Idle mode Request \n");
1676 Adapter->bPreparingForLowPowerMode = FALSE;
1678 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1683 static void HandleShutDownModeRequest(PMINI_ADAPTER Adapter,PUCHAR pucBuffer)
1685 B_UINT32 uiResetValue = 0;
1687 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1689 if(*(pucBuffer+1) == COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW)
1691 HandleShutDownModeWakeup(Adapter);
1693 else if(*(pucBuffer+1) == LINK_SHUTDOWN_REQ_FROM_FIRMWARE)
1695 //Target wants to go to Shut Down Mode
1696 //InterfacePrepareForShutdown(Adapter);
1697 if(Adapter->chip_id == BCS220_2 ||
1698 Adapter->chip_id == BCS220_2BC ||
1699 Adapter->chip_id == BCS250_BC ||
1700 Adapter->chip_id == BCS220_3)
1702 rdmalt(Adapter,HPM_CONFIG_MSW, &uiResetValue, 4);
1703 uiResetValue |= (1<<17);
1704 wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1707 SendShutModeResponse(Adapter);
1708 BCM_DEBUG_PRINT (Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"ShutDownModeResponse:Notification received: Sending the response(Ack/Nack)\n");
1711 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1716 VOID ResetCounters(PMINI_ADAPTER Adapter)
1719 beceem_protocol_reset(Adapter);
1721 Adapter->CurrNumRecvDescs = 0;
1722 Adapter->PrevNumRecvDescs = 0;
1723 Adapter->LinkUpStatus = 0;
1724 Adapter->LinkStatus = 0;
1725 atomic_set(&Adapter->cntrlpktCnt,0);
1726 atomic_set (&Adapter->TotalPacketCount,0);
1727 Adapter->fw_download_done=FALSE;
1728 Adapter->LinkStatus = 0;
1729 Adapter->AutoLinkUp = FALSE;
1730 Adapter->IdleMode = FALSE;
1731 Adapter->bShutStatus = FALSE;
1734 S_CLASSIFIER_RULE *GetFragIPClsEntry(PMINI_ADAPTER Adapter,USHORT usIpIdentification,ULONG SrcIP)
1737 for(uiIndex=0;uiIndex<MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES;uiIndex++)
1739 if((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed)&&
1740 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification)&&
1741 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress== SrcIP)&&
1742 !Adapter->astFragmentedPktClassifierTable[uiIndex].bOutOfOrderFragment)
1743 return Adapter->astFragmentedPktClassifierTable[uiIndex].pstMatchedClassifierEntry;
1748 void AddFragIPClsEntry(PMINI_ADAPTER Adapter,PS_FRAGMENTED_PACKET_INFO psFragPktInfo)
1751 for(uiIndex=0;uiIndex<MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES;uiIndex++)
1753 if(!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed)
1755 memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex],psFragPktInfo,sizeof(S_FRAGMENTED_PACKET_INFO));
1762 void DelFragIPClsEntry(PMINI_ADAPTER Adapter,USHORT usIpIdentification,ULONG SrcIp)
1765 for(uiIndex=0;uiIndex<MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES;uiIndex++)
1767 if((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed)&&
1768 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification)&&
1769 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress== SrcIp))
1770 memset(&Adapter->astFragmentedPktClassifierTable[uiIndex],0,sizeof(S_FRAGMENTED_PACKET_INFO));
1774 void update_per_cid_rx (PMINI_ADAPTER Adapter)
1778 if((jiffies - Adapter->liDrainCalculated) < XSECONDS)
1781 for(qindex = 0; qindex < HiPriority; qindex++)
1783 if(Adapter->PackInfo[qindex].ucDirection == 0)
1785 Adapter->PackInfo[qindex].uiCurrentRxRate =
1786 (Adapter->PackInfo[qindex].uiCurrentRxRate +
1787 Adapter->PackInfo[qindex].uiThisPeriodRxBytes)/2;
1789 Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
1793 Adapter->PackInfo[qindex].uiCurrentDrainRate =
1794 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
1795 Adapter->PackInfo[qindex].uiThisPeriodSentBytes)/2;
1797 Adapter->PackInfo[qindex].uiThisPeriodSentBytes=0;
1800 Adapter->liDrainCalculated=jiffies;
1802 void update_per_sf_desc_cnts( PMINI_ADAPTER Adapter)
1805 u32 uibuff[MAX_TARGET_DSX_BUFFERS];
1807 if(!atomic_read (&Adapter->uiMBupdate))
1810 if(rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (PUINT)uibuff, sizeof(UINT) * MAX_TARGET_DSX_BUFFERS)<0)
1812 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
1815 for(iIndex = 0;iIndex < HiPriority; iIndex++)
1817 if(Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection)
1819 if(Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
1821 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
1825 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Invalid VCID : %x \n",
1826 Adapter->PackInfo[iIndex].usVCID_Value);
1830 atomic_set (&Adapter->uiMBupdate, FALSE);
1833 void flush_queue(PMINI_ADAPTER Adapter, UINT iQIndex)
1835 struct sk_buff* PacketToDrop=NULL;
1836 struct net_device_stats* netstats = &Adapter->dev->stats;
1838 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1840 while(Adapter->PackInfo[iQIndex].FirstTxQueue &&
1841 atomic_read(&Adapter->TotalPacketCount))
1843 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
1844 if(PacketToDrop && PacketToDrop->len)
1846 netstats->tx_dropped++;
1847 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, \
1848 Adapter->PackInfo[iQIndex].LastTxQueue);
1850 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1851 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1853 //Adding dropped statistics
1854 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1855 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
1857 dev_kfree_skb(PacketToDrop);
1858 atomic_dec(&Adapter->TotalPacketCount);
1861 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1865 static void beceem_protocol_reset (PMINI_ADAPTER Adapter)
1869 if (netif_msg_link(Adapter))
1870 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
1872 netif_carrier_off(Adapter->dev);
1873 netif_stop_queue(Adapter->dev);
1875 Adapter->IdleMode = FALSE;
1876 Adapter->LinkUpStatus = FALSE;
1877 ClearTargetDSXBuffer(Adapter,0, TRUE);
1878 //Delete All Classifier Rules
1880 for(i = 0;i<HiPriority;i++)
1882 DeleteAllClassifiersForSF(Adapter,i);
1885 flush_all_queues(Adapter);
1887 if(Adapter->TimerActive == TRUE)
1888 Adapter->TimerActive = FALSE;
1890 memset(Adapter->astFragmentedPktClassifierTable, 0,
1891 sizeof(S_FRAGMENTED_PACKET_INFO) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
1893 for(i = 0;i<HiPriority;i++)
1895 //resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF.
1896 // It is same between MIBs and SF.
1897 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable,
1898 0, sizeof(S_MIBS_EXTSERVICEFLOW_PARAMETERS));