3 static int BcmFileDownload(struct bcm_mini_adapter *Adapter, const char *path, unsigned int loc);
4 static VOID doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter);
5 static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer);
6 static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter);
7 static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter);
9 static VOID default_wimax_protocol_initialize(struct bcm_mini_adapter *Adapter)
13 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES-1; uiLoopIndex++) {
14 Adapter->PackInfo[uiLoopIndex].uiThreshold = TX_PACKET_THRESHOLD;
15 Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate = MAX_ALLOWED_RATE;
16 Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize = 20*1024*1024;
19 Adapter->BEBucketSize = BE_BUCKET_SIZE;
20 Adapter->rtPSBucketSize = rtPS_BUCKET_SIZE;
21 Adapter->LinkStatus = SYNC_UP_REQUEST;
22 Adapter->TransferMode = IP_PACKET_ONLY_MODE;
23 Adapter->usBestEffortQueueIndex = -1;
27 INT InitAdapter(struct bcm_mini_adapter *psAdapter)
30 INT Status = STATUS_SUCCESS;
31 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Initialising Adapter = %p", psAdapter);
33 if (psAdapter == NULL) {
34 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Adapter is NULL");
38 sema_init(&psAdapter->NVMRdmWrmLock, 1);
39 sema_init(&psAdapter->rdmwrmsync, 1);
40 spin_lock_init(&psAdapter->control_queue_lock);
41 spin_lock_init(&psAdapter->txtransmitlock);
42 sema_init(&psAdapter->RxAppControlQueuelock, 1);
43 sema_init(&psAdapter->fw_download_sema, 1);
44 sema_init(&psAdapter->LowPowerModeSync, 1);
46 for (i = 0; i < NO_OF_QUEUES; i++)
47 spin_lock_init(&psAdapter->PackInfo[i].SFQueueLock);
50 init_waitqueue_head(&psAdapter->process_rx_cntrlpkt);
51 init_waitqueue_head(&psAdapter->tx_packet_wait_queue);
52 init_waitqueue_head(&psAdapter->process_read_wait_queue);
53 init_waitqueue_head(&psAdapter->ioctl_fw_dnld_wait_queue);
54 init_waitqueue_head(&psAdapter->lowpower_mode_wait_queue);
55 psAdapter->waiting_to_fw_download_done = TRUE;
56 psAdapter->fw_download_done = FALSE;
58 default_wimax_protocol_initialize(psAdapter);
59 for (i = 0; i < MAX_CNTRL_PKTS; i++) {
60 psAdapter->txctlpacket[i] = kmalloc(MAX_CNTL_PKT_SIZE, GFP_KERNEL);
61 if (!psAdapter->txctlpacket[i]) {
62 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No More Cntl pkts got, max got is %d", i);
67 if (AllocAdapterDsxBuffer(psAdapter)) {
68 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to allocate DSX buffers");
72 /* Initialize PHS interface */
73 if (phs_init(&psAdapter->stBCMPhsContext, psAdapter) != 0) {
74 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%s:%d:Error PHS Init Failed=====>\n", __FILE__, __func__, __LINE__);
78 Status = BcmAllocFlashCSStructure(psAdapter);
80 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Memory Allocation for Flash structure failed");
84 Status = vendorextnInit(psAdapter);
86 if (STATUS_SUCCESS != Status) {
87 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Vendor Init Failed");
91 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Adapter initialised");
93 return STATUS_SUCCESS;
96 VOID AdapterFree(struct bcm_mini_adapter *Adapter)
99 beceem_protocol_reset(Adapter);
100 vendorextnExit(Adapter);
102 if (Adapter->control_packet_handler && !IS_ERR(Adapter->control_packet_handler))
103 kthread_stop(Adapter->control_packet_handler);
105 if (Adapter->transmit_packet_thread && !IS_ERR(Adapter->transmit_packet_thread))
106 kthread_stop(Adapter->transmit_packet_thread);
108 wake_up(&Adapter->process_read_wait_queue);
110 if (Adapter->LEDInfo.led_thread_running & (BCM_LED_THREAD_RUNNING_ACTIVELY | BCM_LED_THREAD_RUNNING_INACTIVELY))
111 kthread_stop(Adapter->LEDInfo.led_cntrl_threadid);
113 unregister_networkdev(Adapter);
115 /* FIXME: use proper wait_event and refcounting */
116 while (atomic_read(&Adapter->ApplicationRunning)) {
117 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Waiting for Application to close.. %d\n", atomic_read(&Adapter->ApplicationRunning));
120 unregister_control_device_interface(Adapter);
121 kfree(Adapter->pstargetparams);
123 for (count = 0; count < MAX_CNTRL_PKTS; count++)
124 kfree(Adapter->txctlpacket[count]);
126 FreeAdapterDsxBuffer(Adapter);
127 kfree(Adapter->pvInterfaceAdapter);
129 /* Free the PHS Interface */
130 PhsCleanup(&Adapter->stBCMPhsContext);
132 BcmDeAllocFlashCSStructure(Adapter);
134 free_netdev(Adapter->dev);
137 static int create_worker_threads(struct bcm_mini_adapter *psAdapter)
139 /* Rx Control Packets Processing */
140 psAdapter->control_packet_handler = kthread_run((int (*)(void *))
141 control_packet_handler, psAdapter, "%s-rx", DRV_NAME);
142 if (IS_ERR(psAdapter->control_packet_handler)) {
143 pr_notice(DRV_NAME ": could not create control thread\n");
144 return PTR_ERR(psAdapter->control_packet_handler);
148 psAdapter->transmit_packet_thread = kthread_run((int (*)(void *))
149 tx_pkt_handler, psAdapter, "%s-tx", DRV_NAME);
150 if (IS_ERR(psAdapter->transmit_packet_thread)) {
151 pr_notice(DRV_NAME ": could not creat transmit thread\n");
152 kthread_stop(psAdapter->control_packet_handler);
153 return PTR_ERR(psAdapter->transmit_packet_thread);
158 static struct file *open_firmware_file(struct bcm_mini_adapter *Adapter, const char *path)
160 struct file *flp = filp_open(path, O_RDONLY, S_IRWXU);
162 pr_err(DRV_NAME "Unable To Open File %s, err %ld", path, PTR_ERR(flp));
166 if (Adapter->device_removed)
175 * Download Address on the chip
177 static int BcmFileDownload(struct bcm_mini_adapter *Adapter, const char *path, unsigned int loc)
180 struct file *flp = NULL;
181 struct timeval tv = {0};
183 flp = open_firmware_file(Adapter, path);
185 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Unable to Open %s\n", path);
188 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);
189 do_gettimeofday(&tv);
191 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "download start %lx", ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)));
192 if (Adapter->bcm_file_download(Adapter->pvInterfaceAdapter, flp, loc)) {
193 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to download the firmware with error %x!!!", -EIO);
197 vfs_llseek(flp, 0, 0);
198 if (Adapter->bcm_file_readback_from_chip(Adapter->pvInterfaceAdapter, flp, loc)) {
199 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to read back firmware!");
205 filp_close(flp, NULL);
210 * @ingroup ctrl_pkt_functions
211 * This function copies the contents of given buffer
212 * to the control packet and queues it for transmission.
213 * @note Do not acquire the spinock, as it it already acquired.
214 * @return SUCCESS/FAILURE.
217 * Control Packet Buffer
219 INT CopyBufferToControlPacket(struct bcm_mini_adapter *Adapter, PVOID ioBuffer)
221 struct bcm_leader *pLeader = NULL;
223 unsigned char *ctrl_buff = NULL;
225 struct bcm_link_request *pLinkReq = NULL;
226 PUCHAR pucAddIndication = NULL;
228 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "======>");
230 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Got Null Buffer\n");
234 pLinkReq = (struct bcm_link_request *)ioBuffer;
235 pLeader = (struct bcm_leader *)ioBuffer; /* ioBuffer Contains sw_Status and Payload */
237 if (Adapter->bShutStatus == TRUE &&
238 pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD &&
239 pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE) {
241 /* Got sync down in SHUTDOWN..we could not process this. */
242 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "SYNC DOWN Request in Shut Down Mode..\n");
243 return STATUS_FAILURE;
246 if ((pLeader->Status == LINK_UP_CONTROL_REQ) &&
247 ((pLinkReq->szData[0] == LINK_UP_REQ_PAYLOAD &&
248 (pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE)) || /* Sync Up Command */
249 pLinkReq->szData[0] == NETWORK_ENTRY_REQ_PAYLOAD)) /* Net Entry Command */ {
251 if (Adapter->LinkStatus > PHY_SYNC_ACHIVED) {
252 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "LinkStatus is Greater than PHY_SYN_ACHIEVED");
253 return STATUS_FAILURE;
256 if (TRUE == Adapter->bShutStatus) {
257 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "SYNC UP IN SHUTDOWN..Device WakeUp\n");
258 if (Adapter->bTriedToWakeUpFromlowPowerMode == FALSE) {
259 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Waking up for the First Time..\n");
260 Adapter->usIdleModePattern = ABORT_SHUTDOWN_MODE; /* change it to 1 for current support. */
261 Adapter->bWakeUpDevice = TRUE;
262 wake_up(&Adapter->process_rx_cntrlpkt);
263 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->bShutStatus, (5 * HZ));
265 if (Status == -ERESTARTSYS)
268 if (Adapter->bShutStatus) {
269 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Shutdown Mode Wake up Failed - No Wake Up Received\n");
270 return STATUS_FAILURE;
273 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Wakeup has been tried already...\n");
278 if (TRUE == Adapter->IdleMode) {
279 /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle mode ... hence\n"); */
280 if (pLeader->Status == LINK_UP_CONTROL_REQ || pLeader->Status == 0x80 ||
281 pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ) {
283 if ((pLeader->Status == LINK_UP_CONTROL_REQ) && (pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD)) {
284 if ((pLinkReq->szData[1] == LINK_SYNC_DOWN_SUBTYPE)) {
285 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Link Down Sent in Idle Mode\n");
286 Adapter->usIdleModePattern = ABORT_IDLE_SYNCDOWN; /* LINK DOWN sent in Idle Mode */
288 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "ABORT_IDLE_MODE pattern is being written\n");
289 Adapter->usIdleModePattern = ABORT_IDLE_REG;
292 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "ABORT_IDLE_MODE pattern is being written\n");
293 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
296 /*Setting bIdleMode_tx_from_host to TRUE to indicate LED control thread to represent
297 * the wake up from idlemode is from host
299 /* Adapter->LEDInfo.bIdleMode_tx_from_host = TRUE; */
300 Adapter->bWakeUpDevice = TRUE;
301 wake_up(&Adapter->process_rx_cntrlpkt);
303 /* We should not send DREG message down while in idlemode. */
304 if (LINK_DOWN_REQ_PAYLOAD == pLinkReq->szData[0])
305 return STATUS_SUCCESS;
307 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->IdleMode, (5 * HZ));
309 if (Status == -ERESTARTSYS)
312 if (Adapter->IdleMode) {
313 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Idle Mode Wake up Failed - No Wake Up Received\n");
314 return STATUS_FAILURE;
317 return STATUS_SUCCESS;
321 /* The Driver has to send control messages with a particular VCID */
322 pLeader->Vcid = VCID_CONTROL_PACKET; /* VCID for control packet. */
324 /* Allocate skb for Control Packet */
325 pktlen = pLeader->PLength;
326 ctrl_buff = (char *)Adapter->txctlpacket[atomic_read(&Adapter->index_wr_txcntrlpkt)%MAX_CNTRL_PKTS];
328 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",
329 atomic_read(&Adapter->index_wr_txcntrlpkt), ctrl_buff, ioBuffer, pktlen);
332 if ((pLeader->Status == 0x80) ||
333 (pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ)) {
335 * Restructure the DSX message to handle Multiple classifier Support
336 * Write the Service Flow param Structures directly to the target
337 * and embed the pointers in the DSX messages sent to target.
339 /* Lets store the current length of the control packet we are transmitting */
340 pucAddIndication = (PUCHAR)ioBuffer + LEADER_SIZE;
341 pktlen = pLeader->PLength;
342 Status = StoreCmControlResponseMessage(Adapter, pucAddIndication, &pktlen);
344 ClearTargetDSXBuffer(Adapter, ((stLocalSFAddIndicationAlt *)pucAddIndication)->u16TID, FALSE);
345 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 ");
346 return STATUS_FAILURE;
349 * update the leader to use the new length
350 * The length of the control packet is length of message being sent + Leader length
352 pLeader->PLength = pktlen;
356 if (pktlen + LEADER_SIZE > MAX_CNTL_PKT_SIZE)
359 memset(ctrl_buff, 0, pktlen+LEADER_SIZE);
360 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Copying the Control Packet Buffer with length=%d\n", pLeader->PLength);
361 *(struct bcm_leader *)ctrl_buff = *pLeader;
362 memcpy(ctrl_buff + LEADER_SIZE, ((PUCHAR)ioBuffer + LEADER_SIZE), pLeader->PLength);
363 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Enqueuing the Control Packet");
365 /* Update the statistics counters */
366 spin_lock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
367 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost += pLeader->PLength;
368 Adapter->PackInfo[HiPriority].uiCurrentPacketsOnHost++;
369 atomic_inc(&Adapter->TotalPacketCount);
370 spin_unlock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
371 Adapter->PackInfo[HiPriority].bValid = TRUE;
373 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "CurrBytesOnHost: %x bValid: %x",
374 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost,
375 Adapter->PackInfo[HiPriority].bValid);
376 Status = STATUS_SUCCESS;
377 /*Queue the packet for transmission */
378 atomic_inc(&Adapter->index_wr_txcntrlpkt);
379 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Calling transmit_packets");
380 atomic_set(&Adapter->TxPktAvail, 1);
381 wake_up(&Adapter->tx_packet_wait_queue);
384 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "mem allocation Failed");
386 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<====");
390 /******************************************************************
391 * Function - LinkMessage()
393 * Description - This function builds the Sync-up and Link-up request
394 * packet messages depending on the device Link status.
396 * Parameters - Adapter: Pointer to the Adapter structure.
399 *******************************************************************/
400 VOID LinkMessage(struct bcm_mini_adapter *Adapter)
402 struct bcm_link_request *pstLinkRequest = NULL;
403 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>");
404 if (Adapter->LinkStatus == SYNC_UP_REQUEST && Adapter->AutoSyncup) {
405 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
406 if (!pstLinkRequest) {
407 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
410 /* sync up request... */
411 Adapter->LinkStatus = WAIT_FOR_SYNC; /* current link status */
412 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For SyncUp...");
413 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
414 pstLinkRequest->szData[1] = LINK_SYNC_UP_SUBTYPE;
415 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
416 pstLinkRequest->Leader.PLength = sizeof(ULONG);
417 Adapter->bSyncUpRequestSent = TRUE;
419 } else if (Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp) {
420 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
421 if (!pstLinkRequest) {
422 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
425 /* LINK_UP_REQUEST */
426 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For LinkUp...");
427 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
428 pstLinkRequest->szData[1] = LINK_NET_ENTRY;
429 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
430 pstLinkRequest->Leader.PLength = sizeof(ULONG);
432 if (pstLinkRequest) {
433 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
434 CopyBufferToControlPacket(Adapter, pstLinkRequest);
435 kfree(pstLinkRequest);
437 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
441 /**********************************************************************
442 * Function - StatisticsResponse()
444 * Description - This function handles the Statistics response packet.
446 * Parameters - Adapter : Pointer to the Adapter structure.
447 * - pvBuffer: Starting address of Statistic response data.
450 ************************************************************************/
451 VOID StatisticsResponse(struct bcm_mini_adapter *Adapter, PVOID pvBuffer)
453 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>", __func__);
454 Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
455 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (UINT)Adapter->StatisticsPointer);
456 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====", __func__);
460 /**********************************************************************
461 * Function - LinkControlResponseMessage()
463 * Description - This function handles the Link response packets.
465 * Parameters - Adapter : Pointer to the Adapter structure.
466 * - pucBuffer: Starting address of Link response data.
469 ***********************************************************************/
470 VOID LinkControlResponseMessage(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
472 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
474 if (*pucBuffer == LINK_UP_ACK) {
475 switch (*(pucBuffer+1)) {
476 case PHY_SYNC_ACHIVED: /* SYNCed UP */
477 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHY_SYNC_ACHIVED");
479 if (Adapter->LinkStatus == LINKUP_DONE)
480 beceem_protocol_reset(Adapter);
482 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
483 Adapter->LinkStatus = PHY_SYNC_ACHIVED;
485 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
486 Adapter->DriverState = NO_NETWORK_ENTRY;
487 wake_up(&Adapter->LEDInfo.notify_led_event);
490 LinkMessage(Adapter);
494 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LINKUP_DONE");
495 Adapter->LinkStatus = LINKUP_DONE;
496 Adapter->bPHSEnabled = *(pucBuffer+3);
497 Adapter->bETHCSEnabled = *(pucBuffer+4) & ETH_CS_MASK;
498 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHS Support Status Received In LinkUp Ack : %x\n", Adapter->bPHSEnabled);
500 if ((FALSE == Adapter->bShutStatus) && (FALSE == Adapter->IdleMode)) {
501 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
502 Adapter->DriverState = NORMAL_OPERATION;
503 wake_up(&Adapter->LEDInfo.notify_led_event);
506 LinkMessage(Adapter);
511 * Driver to ignore the DREG_RECEIVED
512 * WiMAX Application should handle this Message
514 /* Adapter->liTimeSinceLastNetEntry = 0; */
515 Adapter->LinkUpStatus = 0;
516 Adapter->LinkStatus = 0;
517 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
518 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
519 Adapter->IdleMode = FALSE;
520 beceem_protocol_reset(Adapter);
523 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
524 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
526 HandleShutDownModeRequest(Adapter, pucBuffer);
530 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x", *(pucBuffer + 1));
533 } else if (SET_MAC_ADDRESS_RESPONSE == *pucBuffer) {
534 PUCHAR puMacAddr = (pucBuffer + 1);
535 Adapter->LinkStatus = SYNC_UP_REQUEST;
536 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "MAC address response, sending SYNC_UP");
537 LinkMessage(Adapter);
538 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
540 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====", __func__);
544 void SendIdleModeResponse(struct bcm_mini_adapter *Adapter)
546 INT status = 0, NVMAccess = 0, lowPwrAbortMsg = 0;
548 struct bcm_link_request stIdleResponse = {{0} };
549 memset(&tv, 0, sizeof(tv));
550 stIdleResponse.Leader.Status = IDLE_MESSAGE;
551 stIdleResponse.Leader.PLength = IDLE_MODE_PAYLOAD_LENGTH;
552 stIdleResponse.szData[0] = GO_TO_IDLE_MODE_PAYLOAD;
553 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, " ============>");
555 /*********************************
557 * if [ semaphore is available ]
558 * acquire semaphone and return value 0 ;
560 * return non-zero value ;
562 ***********************************/
564 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
565 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
568 if ((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
569 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)) {
572 up(&Adapter->NVMRdmWrmLock);
575 up(&Adapter->LowPowerModeSync);
577 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
578 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "HOST IS NACKING Idle mode To F/W!!!!!!!!");
579 Adapter->bPreparingForLowPowerMode = FALSE;
581 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; /* 2; Idle ACK */
582 Adapter->StatisticsPointer = 0;
584 /* Wait for the LED to TURN OFF before sending ACK response */
585 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
588 /* Wake the LED Thread with IDLEMODE_ENTER State */
589 Adapter->DriverState = LOWPOWER_MODE_ENTER;
590 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);
591 wake_up(&Adapter->LEDInfo.notify_led_event);
593 /* Wait for 1 SEC for LED to OFF */
594 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
596 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
598 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
599 Adapter->DriverState = NORMAL_OPERATION;
600 wake_up(&Adapter->LEDInfo.notify_led_event);
601 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "NACKING Idle mode as time out happen from LED side!!!!!!!!");
605 if (stIdleResponse.szData[1] == TARGET_CAN_GO_TO_IDLE_MODE) {
606 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "ACKING IDLE MODE !!!!!!!!!");
607 down(&Adapter->rdmwrmsync);
608 Adapter->bPreparingForLowPowerMode = TRUE;
609 up(&Adapter->rdmwrmsync);
610 /* Killing all URBS. */
611 if (Adapter->bDoSuspend == TRUE)
612 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
614 Adapter->bPreparingForLowPowerMode = FALSE;
618 up(&Adapter->NVMRdmWrmLock);
621 up(&Adapter->LowPowerModeSync);
624 status = CopyBufferToControlPacket(Adapter, &stIdleResponse);
625 if ((status != STATUS_SUCCESS)) {
626 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "fail to send the Idle mode Request\n");
627 Adapter->bPreparingForLowPowerMode = FALSE;
628 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
630 do_gettimeofday(&tv);
631 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);
634 /******************************************************************
635 * Function - DumpPackInfo()
637 * Description - This function dumps the all Queue(PackInfo[]) details.
639 * Parameters - Adapter: Pointer to the Adapter structure.
642 *******************************************************************/
643 VOID DumpPackInfo(struct bcm_mini_adapter *Adapter)
645 UINT uiLoopIndex = 0;
647 UINT uiClsfrIndex = 0;
648 struct bcm_classifier_rule *pstClassifierEntry = NULL;
650 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
651 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "*********** Showing Details Of Queue %d***** ******", uiLoopIndex);
652 if (FALSE == Adapter->PackInfo[uiLoopIndex].bValid) {
653 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid is FALSE for %X index\n", uiLoopIndex);
657 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " Dumping SF Rule Entry For SFID %lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
658 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " ucDirection %X\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
660 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
661 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv6 Service Flow\n");
663 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv4 Service Flow\n");
665 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SF Traffic Priority %X\n", Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
667 for (uiClsfrIndex = 0; uiClsfrIndex < MAX_CLASSIFIERS; uiClsfrIndex++) {
668 pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
669 if (!pstClassifierEntry->bUsed)
672 if (pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
675 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);
676 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);
677 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);
678 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);
679 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);
680 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);
682 for (uiIndex = 0; uiIndex < MAX_PORT_RANGE; uiIndex++) {
683 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeLo:%X\n", pstClassifierEntry->usSrcPortRangeLo[uiIndex]);
684 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeHi:%X\n", pstClassifierEntry->usSrcPortRangeHi[uiIndex]);
685 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeLo:%X\n", pstClassifierEntry->usDestPortRangeLo[uiIndex]);
686 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeHi:%X\n", pstClassifierEntry->usDestPortRangeHi[uiIndex]);
689 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPSourceAddressLength : 0x%x\n", pstClassifierEntry->ucIPSourceAddressLength);
690 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPDestinationAddressLength : 0x%x\n", pstClassifierEntry->ucIPDestinationAddressLength);
691 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPSourceAddressLength; uiIndex++) {
692 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
693 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpAddr :\n");
694 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Addr);
695 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpMask :\n");
696 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Mask);
698 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpAddr:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Addr[uiIndex]);
699 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpMask:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Mask[uiIndex]);
703 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPDestinationAddressLength; uiIndex++) {
704 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
705 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpAddr :\n");
706 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Addr);
707 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpMask :\n");
708 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Mask);
710 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpAddr:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Addr[uiIndex]);
711 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpMask:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Mask[uiIndex]);
714 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucProtocol:0x%X\n", pstClassifierEntry->ucProtocol[0]);
715 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tu8ClassifierRulePriority:%X\n", pstClassifierEntry->u8ClassifierRulePriority);
717 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ulSFID:%lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
718 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "usVCID_Value:%X\n", Adapter->PackInfo[uiLoopIndex].usVCID_Value);
719 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "PhsEnabled: 0x%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
720 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThreshold:%X\n", Adapter->PackInfo[uiLoopIndex].uiThreshold);
722 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid:%X\n", Adapter->PackInfo[uiLoopIndex].bValid);
723 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bActive:%X\n", Adapter->PackInfo[uiLoopIndex].bActive);
724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActivateReqSent: %x", Adapter->PackInfo[uiLoopIndex].bActivateRequestSent);
725 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "u8QueueType:%X\n", Adapter->PackInfo[uiLoopIndex].u8QueueType);
726 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxBucketSize:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize);
727 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPerSFTxResourceCount:%X\n", atomic_read(&Adapter->PackInfo[uiLoopIndex].uiPerSFTxResourceCount));
728 /* DumpDebug(DUMP_INFO,("bCSSupport:%X\n",Adapter->PackInfo[uiLoopIndex].bCSSupport)); */
729 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CurrQueueDepthOnTarget: %x\n", Adapter->PackInfo[uiLoopIndex].uiCurrentQueueDepthOnTarget);
730 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentBytesOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentBytesOnHost);
731 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentPacketsOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentPacketsOnHost);
732 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountBytes);
733 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountPackets);
734 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentBytes);
735 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentPackets);
736 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentDrainRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentDrainRate);
737 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThisPeriodSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiThisPeriodSentBytes);
738 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liDrainCalculated:%llX\n", Adapter->PackInfo[uiLoopIndex].liDrainCalculated);
739 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentTokenCount:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentTokenCount);
740 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liLastUpdateTokenAt:%llX\n", Adapter->PackInfo[uiLoopIndex].liLastUpdateTokenAt);
741 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxAllowedRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate);
742 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPendedLast:%X\n", Adapter->PackInfo[uiLoopIndex].uiPendedLast);
743 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "NumOfPacketsSent:%X\n", Adapter->PackInfo[uiLoopIndex].NumOfPacketsSent);
744 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Direction: %x\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
745 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CID: %x\n", Adapter->PackInfo[uiLoopIndex].usCID);
746 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ProtocolValid: %x\n", Adapter->PackInfo[uiLoopIndex].bProtocolValid);
747 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "TOSValid: %x\n", Adapter->PackInfo[uiLoopIndex].bTOSValid);
748 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "DestIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bDestIpValid);
749 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SrcIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bSrcIpValid);
750 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActiveSet: %x\n", Adapter->PackInfo[uiLoopIndex].bActiveSet);
751 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AdmittedSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAdmittedSet);
752 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AuthzSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAuthorizedSet);
753 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ClassifyPrority: %x\n", Adapter->PackInfo[uiLoopIndex].bClassifierPriority);
754 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxLatency: %x\n", Adapter->PackInfo[uiLoopIndex].uiMaxLatency);
755 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]);
756 /* BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bHeaderSuppressionEnabled :%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
757 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalTxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalTxBytes);
758 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalRxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalRxBytes);
759 * DumpDebug(DUMP_INFO,(" uiRanOutOfResCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiRanOutOfResCount));
763 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
764 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aRxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aRxPktSizeHist[uiLoopIndex]);
766 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
767 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aTxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aTxPktSizeHist[uiLoopIndex]);
772 int reset_card_proc(struct bcm_mini_adapter *ps_adapter)
774 int retval = STATUS_SUCCESS;
775 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
776 PS_INTERFACE_ADAPTER psIntfAdapter = NULL;
777 unsigned int value = 0, uiResetValue = 0;
780 psIntfAdapter = ((PS_INTERFACE_ADAPTER)(ps_adapter->pvInterfaceAdapter));
781 ps_adapter->bDDRInitDone = FALSE;
783 if (ps_adapter->chip_id >= T3LPB) {
784 /* SYS_CFG register is write protected hence for modifying this reg value, it should be read twice before */
785 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
786 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
788 /* making bit[6...5] same as was before f/w download. this setting force the h/w to */
789 /* re-populated the SP RAM area with the string descriptor. */
790 value = value | (ps_adapter->syscfgBefFwDld & 0x00000060);
791 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
794 /* killing all submitted URBs. */
795 psIntfAdapter->psAdapter->StopAllXaction = TRUE;
796 Bcm_kill_all_URBs(psIntfAdapter);
797 /* Reset the UMA-B Device */
798 if (ps_adapter->chip_id >= T3LPB) {
799 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Resetting UMA-B\n");
800 retval = usb_reset_device(psIntfAdapter->udev);
801 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
803 if (retval != STATUS_SUCCESS) {
804 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
808 if (ps_adapter->chip_id == BCS220_2 ||
809 ps_adapter->chip_id == BCS220_2BC ||
810 ps_adapter->chip_id == BCS250_BC ||
811 ps_adapter->chip_id == BCS220_3) {
813 bytes = rdmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
816 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
819 /* setting 0th bit */
821 retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
823 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
828 bytes = rdmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
831 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
835 retval = wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
837 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
841 /* Toggling the GPIO 8, 9 */
843 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
845 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
849 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value));
851 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
857 /* ps_adapter->downloadDDR = false; */
858 if (ps_adapter->bFlashBoot) {
859 /* In flash boot mode MIPS state register has reverse polarity.
860 * So just or with setting bit 30.
861 * Make the MIPS in Reset state.
863 rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
864 uiResetValue |= (1<<30);
865 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
868 if (ps_adapter->chip_id >= T3LPB) {
871 * WA for SYSConfig Issue.
872 * Read SYSCFG Twice to make it writable.
874 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
875 if (uiResetValue & (1<<4)) {
877 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue)); /* 2nd read to make it writable. */
878 uiResetValue &= (~(1<<4));
879 wrmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
883 wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
886 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
890 int run_card_proc(struct bcm_mini_adapter *ps_adapter)
892 int status = STATUS_SUCCESS;
895 unsigned int value = 0;
897 bytes = rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value));
900 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
904 if (ps_adapter->bFlashBoot)
909 if (wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
910 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
911 return STATUS_FAILURE;
917 int InitCardAndDownloadFirmware(struct bcm_mini_adapter *ps_adapter)
922 * Create the threads first and then download the
923 * Firm/DDR Settings..
925 status = create_worker_threads(ps_adapter);
929 status = bcm_parse_target_params(ps_adapter);
933 if (ps_adapter->chip_id >= T3LPB) {
934 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
935 ps_adapter->syscfgBefFwDld = value;
937 if ((value & 0x60) == 0)
938 ps_adapter->bFlashBoot = TRUE;
941 reset_card_proc(ps_adapter);
943 /* Initializing the NVM. */
944 BcmInitNVM(ps_adapter);
945 status = ddr_init(ps_adapter);
947 pr_err(DRV_NAME "ddr_init Failed\n");
951 /* Download cfg file */
952 status = buffDnldVerify(ps_adapter,
953 (PUCHAR)ps_adapter->pstargetparams,
954 sizeof(STARGETPARAMS),
957 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
961 if (register_networkdev(ps_adapter)) {
962 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
966 if (FALSE == ps_adapter->AutoFirmDld) {
967 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoFirmDld Disabled in CFG File..\n");
968 /* If Auto f/w download is disable, register the control interface, */
969 /* register the control interface after the mailbox. */
970 if (register_control_device_interface(ps_adapter) < 0) {
971 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
974 return STATUS_SUCCESS;
978 * Do the LED Settings here. It will be used by the Firmware Download
983 * 1. If the LED Settings fails, do not stop and do the Firmware download.
984 * 2. This init would happened only if the cfg file is present, else
985 * call from the ioctl context.
988 status = InitLedSettings(ps_adapter);
990 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_PRINTK, 0, 0, "INIT LED FAILED\n");
994 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
995 ps_adapter->DriverState = DRIVER_INIT;
996 wake_up(&ps_adapter->LEDInfo.notify_led_event);
999 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1000 ps_adapter->DriverState = FW_DOWNLOAD;
1001 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1005 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1006 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1008 if (ps_adapter->eNVMType == NVM_FLASH) {
1009 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
1011 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Propagation of Cal param failed ..");
1016 /* Download Firmare */
1017 status = BcmFileDownload(ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR);
1019 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Firmware File is present...\n");
1023 status = run_card_proc(ps_adapter);
1025 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "run_card_proc Failed\n");
1029 ps_adapter->fw_download_done = TRUE;
1033 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1034 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1035 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1041 static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter)
1043 struct file *flp = NULL;
1047 buff = kmalloc(BUFFER_1K, GFP_KERNEL);
1051 Adapter->pstargetparams = kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL);
1052 if (Adapter->pstargetparams == NULL) {
1057 flp = open_firmware_file(Adapter, CFG_FILE);
1059 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE\n", CFG_FILE);
1061 kfree(Adapter->pstargetparams);
1062 Adapter->pstargetparams = NULL;
1065 len = kernel_read(flp, 0, buff, BUFFER_1K);
1066 filp_close(flp, NULL);
1068 if (len != sizeof(STARGETPARAMS)) {
1069 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n");
1071 kfree(Adapter->pstargetparams);
1072 Adapter->pstargetparams = NULL;
1076 /* Check for autolink in config params */
1078 * Values in Adapter->pstargetparams are in network byte order
1080 memcpy(Adapter->pstargetparams, buff, sizeof(STARGETPARAMS));
1082 beceem_parse_target_struct(Adapter);
1083 return STATUS_SUCCESS;
1086 void beceem_parse_target_struct(struct bcm_mini_adapter *Adapter)
1088 UINT uiHostDrvrCfg6 = 0, uiEEPROMFlag = 0;
1090 if (ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE) {
1091 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
1092 Adapter->AutoSyncup = FALSE;
1094 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
1095 Adapter->AutoSyncup = TRUE;
1098 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE) {
1099 pr_info(DRV_NAME ": Enabling autolink up");
1100 Adapter->AutoLinkUp = TRUE;
1102 pr_info(DRV_NAME ": Disabling autolink up");
1103 Adapter->AutoLinkUp = FALSE;
1105 /* Setting the DDR Setting.. */
1106 Adapter->DDRSetting = (ntohl(Adapter->pstargetparams->HostDrvrConfig6) >> 8)&0x0F;
1107 Adapter->ulPowerSaveMode = (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
1108 pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1109 pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
1110 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD) {
1111 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1112 Adapter->AutoFirmDld = TRUE;
1114 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1115 Adapter->AutoFirmDld = FALSE;
1117 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1118 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
1119 pr_info(DRV_NAME ": MIPSConfig : 0x%X\n", Adapter->bMipsConfig);
1120 /* used for backward compatibility. */
1121 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
1122 Adapter->PmuMode = (uiHostDrvrCfg6 >> 24) & 0x03;
1123 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
1125 if ((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT) & (0x01)) {
1126 Adapter->bDoSuspend = TRUE;
1127 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1130 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
1131 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n", uiEEPROMFlag);
1132 Adapter->eNVMType = (NVM_TYPE)((uiEEPROMFlag>>4)&0x3);
1133 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
1134 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
1135 Adapter->bSectorSizeOverride = (bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
1137 if (ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x01)
1138 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
1140 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1141 doPowerAutoCorrection(Adapter);
1144 static VOID doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter)
1146 UINT reporting_mode;
1148 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x02;
1149 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1151 if (reporting_mode == TRUE) {
1152 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "can't do suspen/resume as reporting mode is enable");
1153 psAdapter->bDoSuspend = FALSE;
1156 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB)) {
1157 /* If reporting mode is enable, switch PMU to PMC */
1159 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
1160 psAdapter->bDoSuspend = FALSE;
1163 /* clearing space bit[15..12] */
1164 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl((0xF << 12)));
1165 /* placing the power save mode option */
1166 psAdapter->pstargetparams->HostDrvrConfig6 |= htonl((psAdapter->ulPowerSaveMode << 12));
1167 } else if (psAdapter->bIsAutoCorrectEnabled == FALSE) {
1168 /* remove the autocorrect disable bit set before dumping. */
1169 psAdapter->ulPowerSaveMode &= ~(1 << 3);
1170 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl(1 << 15));
1171 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Using Forced User Choice: %lx\n", psAdapter->ulPowerSaveMode);
1175 static void convertEndian(B_UINT8 rwFlag, PUINT puiBuffer, UINT uiByteCount)
1179 if (RWM_WRITE == rwFlag) {
1180 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++)
1181 puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
1183 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++)
1184 puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
1188 int rdm(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1190 return Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
1191 uiAddress, pucBuff, sSize);
1194 int wrm(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1198 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
1199 uiAddress, pucBuff, sSize);
1203 int wrmalt(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1205 convertEndian(RWM_WRITE, pucBuff, size);
1206 return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1209 int rdmalt(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1213 uiRetVal = rdm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1214 convertEndian(RWM_READ, (PUINT)pucBuff, size);
1219 int wrmWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1221 INT status = STATUS_SUCCESS;
1222 down(&Adapter->rdmwrmsync);
1224 if ((Adapter->IdleMode == TRUE) ||
1225 (Adapter->bShutStatus == TRUE) ||
1226 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1232 status = wrm(Adapter, uiAddress, pucBuff, sSize);
1234 up(&Adapter->rdmwrmsync);
1238 int wrmaltWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1240 int iRetVal = STATUS_SUCCESS;
1242 down(&Adapter->rdmwrmsync);
1244 if ((Adapter->IdleMode == TRUE) ||
1245 (Adapter->bShutStatus == TRUE) ||
1246 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1252 iRetVal = wrmalt(Adapter, uiAddress, pucBuff, size);
1254 up(&Adapter->rdmwrmsync);
1258 int rdmaltWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1260 INT uiRetVal = STATUS_SUCCESS;
1262 down(&Adapter->rdmwrmsync);
1263 if ((Adapter->IdleMode == TRUE) ||
1264 (Adapter->bShutStatus == TRUE) ||
1265 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1271 uiRetVal = rdmalt(Adapter, uiAddress, pucBuff, size);
1273 up(&Adapter->rdmwrmsync);
1277 static VOID HandleShutDownModeWakeup(struct bcm_mini_adapter *Adapter)
1279 int clear_abort_pattern = 0, Status = 0;
1280 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1281 /* target has woken up From Shut Down */
1282 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Clearing Shut Down Software abort pattern\n");
1283 Status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC, (PUINT)&clear_abort_pattern, sizeof(clear_abort_pattern));
1285 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
1289 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) {
1291 InterfaceHandleShutdownModeWakeup(Adapter);
1295 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1296 Adapter->DriverState = NO_NETWORK_ENTRY;
1297 wake_up(&Adapter->LEDInfo.notify_led_event);
1300 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
1301 Adapter->bShutStatus = FALSE;
1302 wake_up(&Adapter->lowpower_mode_wait_queue);
1303 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1306 static VOID SendShutModeResponse(struct bcm_mini_adapter *Adapter)
1308 struct bcm_link_request stShutdownResponse;
1309 UINT NVMAccess = 0, lowPwrAbortMsg = 0;
1312 memset(&stShutdownResponse, 0, sizeof(struct bcm_link_request));
1313 stShutdownResponse.Leader.Status = LINK_UP_CONTROL_REQ;
1314 stShutdownResponse.Leader.PLength = 8; /* 8 bytes; */
1315 stShutdownResponse.szData[0] = LINK_UP_ACK;
1316 stShutdownResponse.szData[1] = LINK_SHUTDOWN_REQ_FROM_FIRMWARE;
1318 /*********************************
1320 * if [ semaphore is available ]
1321 * acquire semaphone and return value 0 ;
1323 * return non-zero value ;
1325 ***********************************/
1327 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1328 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
1330 if (NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) {
1332 up(&Adapter->NVMRdmWrmLock);
1334 if (!lowPwrAbortMsg)
1335 up(&Adapter->LowPowerModeSync);
1337 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Device Access is going on NACK the Shut Down MODE\n");
1338 stShutdownResponse.szData[2] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
1339 Adapter->bPreparingForLowPowerMode = FALSE;
1341 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Sending SHUTDOWN MODE ACK\n");
1342 stShutdownResponse.szData[2] = SHUTDOWN_ACK_FROM_DRIVER; /* ShutDown ACK */
1344 /* Wait for the LED to TURN OFF before sending ACK response */
1345 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1348 /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1349 Adapter->DriverState = LOWPOWER_MODE_ENTER;
1350 wake_up(&Adapter->LEDInfo.notify_led_event);
1352 /* Wait for 1 SEC for LED to OFF */
1353 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
1355 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
1357 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
1358 Adapter->DriverState = NO_NETWORK_ENTRY;
1359 wake_up(&Adapter->LEDInfo.notify_led_event);
1363 if (stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER) {
1364 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ACKING SHUTDOWN MODE !!!!!!!!!");
1365 down(&Adapter->rdmwrmsync);
1366 Adapter->bPreparingForLowPowerMode = TRUE;
1367 up(&Adapter->rdmwrmsync);
1368 /* Killing all URBS. */
1369 if (Adapter->bDoSuspend == TRUE)
1370 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1372 Adapter->bPreparingForLowPowerMode = FALSE;
1376 up(&Adapter->NVMRdmWrmLock);
1378 if (!lowPwrAbortMsg)
1379 up(&Adapter->LowPowerModeSync);
1382 Status = CopyBufferToControlPacket(Adapter, &stShutdownResponse);
1383 if ((Status != STATUS_SUCCESS)) {
1384 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "fail to send the Idle mode Request\n");
1385 Adapter->bPreparingForLowPowerMode = FALSE;
1386 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1390 static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
1392 B_UINT32 uiResetValue = 0;
1394 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1396 if (*(pucBuffer+1) == COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW) {
1397 HandleShutDownModeWakeup(Adapter);
1398 } else if (*(pucBuffer+1) == LINK_SHUTDOWN_REQ_FROM_FIRMWARE) {
1399 /* Target wants to go to Shut Down Mode */
1400 /* InterfacePrepareForShutdown(Adapter); */
1401 if (Adapter->chip_id == BCS220_2 ||
1402 Adapter->chip_id == BCS220_2BC ||
1403 Adapter->chip_id == BCS250_BC ||
1404 Adapter->chip_id == BCS220_3) {
1406 rdmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1407 uiResetValue |= (1<<17);
1408 wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1411 SendShutModeResponse(Adapter);
1412 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ShutDownModeResponse:Notification received: Sending the response(Ack/Nack)\n");
1415 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1419 VOID ResetCounters(struct bcm_mini_adapter *Adapter)
1421 beceem_protocol_reset(Adapter);
1422 Adapter->CurrNumRecvDescs = 0;
1423 Adapter->PrevNumRecvDescs = 0;
1424 Adapter->LinkUpStatus = 0;
1425 Adapter->LinkStatus = 0;
1426 atomic_set(&Adapter->cntrlpktCnt, 0);
1427 atomic_set(&Adapter->TotalPacketCount, 0);
1428 Adapter->fw_download_done = FALSE;
1429 Adapter->LinkStatus = 0;
1430 Adapter->AutoLinkUp = FALSE;
1431 Adapter->IdleMode = FALSE;
1432 Adapter->bShutStatus = FALSE;
1435 struct bcm_classifier_rule *GetFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIP)
1438 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1439 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1440 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1441 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIP) &&
1442 !Adapter->astFragmentedPktClassifierTable[uiIndex].bOutOfOrderFragment)
1444 return Adapter->astFragmentedPktClassifierTable[uiIndex].pstMatchedClassifierEntry;
1449 void AddFragIPClsEntry(struct bcm_mini_adapter *Adapter, struct bcm_fragmented_packet_info *psFragPktInfo)
1452 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1453 if (!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) {
1454 memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex], psFragPktInfo, sizeof(struct bcm_fragmented_packet_info));
1460 void DelFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIp)
1463 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1464 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1465 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1466 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIp))
1468 memset(&Adapter->astFragmentedPktClassifierTable[uiIndex], 0, sizeof(struct bcm_fragmented_packet_info));
1472 void update_per_cid_rx(struct bcm_mini_adapter *Adapter)
1476 if ((jiffies - Adapter->liDrainCalculated) < XSECONDS)
1479 for (qindex = 0; qindex < HiPriority; qindex++) {
1480 if (Adapter->PackInfo[qindex].ucDirection == 0) {
1481 Adapter->PackInfo[qindex].uiCurrentRxRate =
1482 (Adapter->PackInfo[qindex].uiCurrentRxRate +
1483 Adapter->PackInfo[qindex].uiThisPeriodRxBytes) / 2;
1485 Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
1487 Adapter->PackInfo[qindex].uiCurrentDrainRate =
1488 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
1489 Adapter->PackInfo[qindex].uiThisPeriodSentBytes) / 2;
1490 Adapter->PackInfo[qindex].uiThisPeriodSentBytes = 0;
1493 Adapter->liDrainCalculated = jiffies;
1496 void update_per_sf_desc_cnts(struct bcm_mini_adapter *Adapter)
1499 u32 uibuff[MAX_TARGET_DSX_BUFFERS];
1502 if (!atomic_read(&Adapter->uiMBupdate))
1505 bytes = rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (PUINT)uibuff, sizeof(UINT) * MAX_TARGET_DSX_BUFFERS);
1507 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
1511 for (iIndex = 0; iIndex < HiPriority; iIndex++) {
1512 if (Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection) {
1513 if (Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
1514 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
1516 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid VCID : %x\n", Adapter->PackInfo[iIndex].usVCID_Value);
1519 atomic_set(&Adapter->uiMBupdate, FALSE);
1522 void flush_queue(struct bcm_mini_adapter *Adapter, UINT iQIndex)
1524 struct sk_buff *PacketToDrop = NULL;
1525 struct net_device_stats *netstats = &Adapter->dev->stats;
1526 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1528 while (Adapter->PackInfo[iQIndex].FirstTxQueue && atomic_read(&Adapter->TotalPacketCount)) {
1529 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
1530 if (PacketToDrop && PacketToDrop->len) {
1531 netstats->tx_dropped++;
1532 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, Adapter->PackInfo[iQIndex].LastTxQueue);
1533 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1534 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1536 /* Adding dropped statistics */
1537 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1538 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
1539 dev_kfree_skb(PacketToDrop);
1540 atomic_dec(&Adapter->TotalPacketCount);
1543 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1546 static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter)
1549 if (netif_msg_link(Adapter))
1550 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
1552 netif_carrier_off(Adapter->dev);
1553 netif_stop_queue(Adapter->dev);
1555 Adapter->IdleMode = FALSE;
1556 Adapter->LinkUpStatus = FALSE;
1557 ClearTargetDSXBuffer(Adapter, 0, TRUE);
1558 /* Delete All Classifier Rules */
1560 for (i = 0; i < HiPriority; i++)
1561 DeleteAllClassifiersForSF(Adapter, i);
1563 flush_all_queues(Adapter);
1565 if (Adapter->TimerActive == TRUE)
1566 Adapter->TimerActive = FALSE;
1568 memset(Adapter->astFragmentedPktClassifierTable, 0, sizeof(struct bcm_fragmented_packet_info) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
1570 for (i = 0; i < HiPriority; i++) {
1571 /* resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF. */
1572 /* It is same between MIBs and SF. */
1573 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable, 0, sizeof(S_MIBS_EXTSERVICEFLOW_PARAMETERS));