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)
11 unsigned int uiLoopIndex;
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;
26 int InitAdapter(struct bcm_mini_adapter *psAdapter)
29 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)
100 beceem_protocol_reset(Adapter);
101 vendorextnExit(Adapter);
103 if (Adapter->control_packet_handler && !IS_ERR(Adapter->control_packet_handler))
104 kthread_stop(Adapter->control_packet_handler);
106 if (Adapter->transmit_packet_thread && !IS_ERR(Adapter->transmit_packet_thread))
107 kthread_stop(Adapter->transmit_packet_thread);
109 wake_up(&Adapter->process_read_wait_queue);
111 if (Adapter->LEDInfo.led_thread_running & (BCM_LED_THREAD_RUNNING_ACTIVELY | BCM_LED_THREAD_RUNNING_INACTIVELY))
112 kthread_stop(Adapter->LEDInfo.led_cntrl_threadid);
114 unregister_networkdev(Adapter);
116 /* FIXME: use proper wait_event and refcounting */
117 while (atomic_read(&Adapter->ApplicationRunning)) {
118 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Waiting for Application to close.. %d\n", atomic_read(&Adapter->ApplicationRunning));
121 unregister_control_device_interface(Adapter);
122 kfree(Adapter->pstargetparams);
124 for (count = 0; count < MAX_CNTRL_PKTS; count++)
125 kfree(Adapter->txctlpacket[count]);
127 FreeAdapterDsxBuffer(Adapter);
128 kfree(Adapter->pvInterfaceAdapter);
130 /* Free the PHS Interface */
131 PhsCleanup(&Adapter->stBCMPhsContext);
133 BcmDeAllocFlashCSStructure(Adapter);
135 free_netdev(Adapter->dev);
138 static int create_worker_threads(struct bcm_mini_adapter *psAdapter)
140 /* Rx Control Packets Processing */
141 psAdapter->control_packet_handler = kthread_run((int (*)(void *))
142 control_packet_handler, psAdapter, "%s-rx", DRV_NAME);
143 if (IS_ERR(psAdapter->control_packet_handler)) {
144 pr_notice(DRV_NAME ": could not create control thread\n");
145 return PTR_ERR(psAdapter->control_packet_handler);
149 psAdapter->transmit_packet_thread = kthread_run((int (*)(void *))
150 tx_pkt_handler, psAdapter, "%s-tx", DRV_NAME);
151 if (IS_ERR(psAdapter->transmit_packet_thread)) {
152 pr_notice(DRV_NAME ": could not creat transmit thread\n");
153 kthread_stop(psAdapter->control_packet_handler);
154 return PTR_ERR(psAdapter->transmit_packet_thread);
159 static struct file *open_firmware_file(struct bcm_mini_adapter *Adapter, const char *path)
161 struct file *flp = filp_open(path, O_RDONLY, S_IRWXU);
164 pr_err(DRV_NAME "Unable To Open File %s, err %ld", path, PTR_ERR(flp));
168 if (Adapter->device_removed)
177 * Download Address on the chip
179 static int BcmFileDownload(struct bcm_mini_adapter *Adapter, const char *path, unsigned int loc)
182 struct file *flp = NULL;
183 struct timeval tv = {0};
185 flp = open_firmware_file(Adapter, path);
187 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Unable to Open %s\n", path);
190 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)file_inode(flp)->i_size, loc);
191 do_gettimeofday(&tv);
193 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "download start %lx", ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)));
194 if (Adapter->bcm_file_download(Adapter->pvInterfaceAdapter, flp, loc)) {
195 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to download the firmware with error %x!!!", -EIO);
199 vfs_llseek(flp, 0, 0);
200 if (Adapter->bcm_file_readback_from_chip(Adapter->pvInterfaceAdapter, flp, loc)) {
201 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to read back firmware!");
207 filp_close(flp, NULL);
212 * @ingroup ctrl_pkt_functions
213 * This function copies the contents of given buffer
214 * to the control packet and queues it for transmission.
215 * @note Do not acquire the spinlock, as it it already acquired.
216 * @return SUCCESS/FAILURE.
219 * Control Packet Buffer
221 int CopyBufferToControlPacket(struct bcm_mini_adapter *Adapter, void *ioBuffer)
223 struct bcm_leader *pLeader = NULL;
225 unsigned char *ctrl_buff;
226 unsigned int pktlen = 0;
227 struct bcm_link_request *pLinkReq = NULL;
228 PUCHAR pucAddIndication = NULL;
230 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "======>");
232 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Got Null Buffer\n");
236 pLinkReq = (struct bcm_link_request *)ioBuffer;
237 pLeader = (struct bcm_leader *)ioBuffer; /* ioBuffer Contains sw_Status and Payload */
239 if (Adapter->bShutStatus == TRUE &&
240 pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD &&
241 pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE) {
243 /* Got sync down in SHUTDOWN..we could not process this. */
244 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "SYNC DOWN Request in Shut Down Mode..\n");
245 return STATUS_FAILURE;
248 if ((pLeader->Status == LINK_UP_CONTROL_REQ) &&
249 ((pLinkReq->szData[0] == LINK_UP_REQ_PAYLOAD &&
250 (pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE)) || /* Sync Up Command */
251 pLinkReq->szData[0] == NETWORK_ENTRY_REQ_PAYLOAD)) /* Net Entry Command */ {
253 if (Adapter->LinkStatus > PHY_SYNC_ACHIVED) {
254 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "LinkStatus is Greater than PHY_SYN_ACHIEVED");
255 return STATUS_FAILURE;
258 if (Adapter->bShutStatus == TRUE) {
259 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "SYNC UP IN SHUTDOWN..Device WakeUp\n");
260 if (Adapter->bTriedToWakeUpFromlowPowerMode == false) {
261 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Waking up for the First Time..\n");
262 Adapter->usIdleModePattern = ABORT_SHUTDOWN_MODE; /* change it to 1 for current support. */
263 Adapter->bWakeUpDevice = TRUE;
264 wake_up(&Adapter->process_rx_cntrlpkt);
265 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->bShutStatus, (5 * HZ));
267 if (Status == -ERESTARTSYS)
270 if (Adapter->bShutStatus) {
271 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Shutdown Mode Wake up Failed - No Wake Up Received\n");
272 return STATUS_FAILURE;
275 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Wakeup has been tried already...\n");
280 if (Adapter->IdleMode == TRUE) {
281 /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle mode ... hence\n"); */
282 if (pLeader->Status == LINK_UP_CONTROL_REQ || pLeader->Status == 0x80 ||
283 pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ) {
285 if ((pLeader->Status == LINK_UP_CONTROL_REQ) && (pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD)) {
286 if (pLinkReq->szData[1] == LINK_SYNC_DOWN_SUBTYPE) {
287 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Link Down Sent in Idle Mode\n");
288 Adapter->usIdleModePattern = ABORT_IDLE_SYNCDOWN; /* LINK DOWN sent in Idle Mode */
290 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "ABORT_IDLE_MODE pattern is being written\n");
291 Adapter->usIdleModePattern = ABORT_IDLE_REG;
294 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "ABORT_IDLE_MODE pattern is being written\n");
295 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
298 /*Setting bIdleMode_tx_from_host to TRUE to indicate LED control thread to represent
299 * the wake up from idlemode is from host
301 /* Adapter->LEDInfo.bIdleMode_tx_from_host = TRUE; */
302 Adapter->bWakeUpDevice = TRUE;
303 wake_up(&Adapter->process_rx_cntrlpkt);
305 /* We should not send DREG message down while in idlemode. */
306 if (LINK_DOWN_REQ_PAYLOAD == pLinkReq->szData[0])
307 return STATUS_SUCCESS;
309 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->IdleMode, (5 * HZ));
311 if (Status == -ERESTARTSYS)
314 if (Adapter->IdleMode) {
315 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Idle Mode Wake up Failed - No Wake Up Received\n");
316 return STATUS_FAILURE;
319 return STATUS_SUCCESS;
323 /* The Driver has to send control messages with a particular VCID */
324 pLeader->Vcid = VCID_CONTROL_PACKET; /* VCID for control packet. */
326 /* Allocate skb for Control Packet */
327 pktlen = pLeader->PLength;
328 ctrl_buff = (char *)Adapter->txctlpacket[atomic_read(&Adapter->index_wr_txcntrlpkt)%MAX_CNTRL_PKTS];
331 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "mem allocation Failed");
335 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",
336 atomic_read(&Adapter->index_wr_txcntrlpkt), ctrl_buff, ioBuffer, pktlen);
339 if ((pLeader->Status == 0x80) ||
340 (pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ)) {
342 * Restructure the DSX message to handle Multiple classifier Support
343 * Write the Service Flow param Structures directly to the target
344 * and embed the pointers in the DSX messages sent to target.
346 /* Lets store the current length of the control packet we are transmitting */
347 pucAddIndication = (PUCHAR)ioBuffer + LEADER_SIZE;
348 pktlen = pLeader->PLength;
349 Status = StoreCmControlResponseMessage(Adapter, pucAddIndication, &pktlen);
351 ClearTargetDSXBuffer(Adapter, ((struct bcm_add_indication_alt *)pucAddIndication)->u16TID, false);
352 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 ");
353 return STATUS_FAILURE;
356 * update the leader to use the new length
357 * The length of the control packet is length of message being sent + Leader length
359 pLeader->PLength = pktlen;
363 if (pktlen + LEADER_SIZE > MAX_CNTL_PKT_SIZE)
366 memset(ctrl_buff, 0, pktlen+LEADER_SIZE);
367 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Copying the Control Packet Buffer with length=%d\n", pLeader->PLength);
368 *(struct bcm_leader *)ctrl_buff = *pLeader;
369 memcpy(ctrl_buff + LEADER_SIZE, ((PUCHAR)ioBuffer + LEADER_SIZE), pLeader->PLength);
370 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Enqueuing the Control Packet");
372 /* Update the statistics counters */
373 spin_lock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
374 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost += pLeader->PLength;
375 Adapter->PackInfo[HiPriority].uiCurrentPacketsOnHost++;
376 atomic_inc(&Adapter->TotalPacketCount);
377 spin_unlock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
378 Adapter->PackInfo[HiPriority].bValid = TRUE;
380 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "CurrBytesOnHost: %x bValid: %x",
381 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost,
382 Adapter->PackInfo[HiPriority].bValid);
383 Status = STATUS_SUCCESS;
384 /*Queue the packet for transmission */
385 atomic_inc(&Adapter->index_wr_txcntrlpkt);
386 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Calling transmit_packets");
387 atomic_set(&Adapter->TxPktAvail, 1);
388 wake_up(&Adapter->tx_packet_wait_queue);
390 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<====");
394 /******************************************************************
395 * Function - LinkMessage()
397 * Description - This function builds the Sync-up and Link-up request
398 * packet messages depending on the device Link status.
400 * Parameters - Adapter: Pointer to the Adapter structure.
403 *******************************************************************/
404 void LinkMessage(struct bcm_mini_adapter *Adapter)
406 struct bcm_link_request *pstLinkRequest = NULL;
408 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>");
409 if (Adapter->LinkStatus == SYNC_UP_REQUEST && Adapter->AutoSyncup) {
410 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
411 if (!pstLinkRequest) {
412 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
415 /* sync up request... */
416 Adapter->LinkStatus = WAIT_FOR_SYNC; /* current link status */
417 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For SyncUp...");
418 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
419 pstLinkRequest->szData[1] = LINK_SYNC_UP_SUBTYPE;
420 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
421 pstLinkRequest->Leader.PLength = sizeof(ULONG);
422 Adapter->bSyncUpRequestSent = TRUE;
424 } else if (Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp) {
425 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
426 if (!pstLinkRequest) {
427 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
430 /* LINK_UP_REQUEST */
431 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For LinkUp...");
432 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
433 pstLinkRequest->szData[1] = LINK_NET_ENTRY;
434 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
435 pstLinkRequest->Leader.PLength = sizeof(ULONG);
437 if (pstLinkRequest) {
438 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
439 CopyBufferToControlPacket(Adapter, pstLinkRequest);
440 kfree(pstLinkRequest);
442 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
446 /**********************************************************************
447 * Function - StatisticsResponse()
449 * Description - This function handles the Statistics response packet.
451 * Parameters - Adapter : Pointer to the Adapter structure.
452 * - pvBuffer: Starting address of Statistic response data.
455 ************************************************************************/
456 void StatisticsResponse(struct bcm_mini_adapter *Adapter, void *pvBuffer)
458 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>", __func__);
459 Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
460 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (unsigned int)Adapter->StatisticsPointer);
461 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====", __func__);
464 /**********************************************************************
465 * Function - LinkControlResponseMessage()
467 * Description - This function handles the Link response packets.
469 * Parameters - Adapter : Pointer to the Adapter structure.
470 * - pucBuffer: Starting address of Link response data.
473 ***********************************************************************/
474 void LinkControlResponseMessage(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
476 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
478 if (*pucBuffer == LINK_UP_ACK) {
479 switch (*(pucBuffer+1)) {
480 case PHY_SYNC_ACHIVED: /* SYNCed UP */
481 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHY_SYNC_ACHIVED");
483 if (Adapter->LinkStatus == LINKUP_DONE)
484 beceem_protocol_reset(Adapter);
486 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
487 Adapter->LinkStatus = PHY_SYNC_ACHIVED;
489 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
490 Adapter->DriverState = NO_NETWORK_ENTRY;
491 wake_up(&Adapter->LEDInfo.notify_led_event);
494 LinkMessage(Adapter);
498 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LINKUP_DONE");
499 Adapter->LinkStatus = LINKUP_DONE;
500 Adapter->bPHSEnabled = *(pucBuffer+3);
501 Adapter->bETHCSEnabled = *(pucBuffer+4) & ETH_CS_MASK;
502 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHS Support Status Received In LinkUp Ack : %x\n", Adapter->bPHSEnabled);
504 if ((false == Adapter->bShutStatus) && (false == Adapter->IdleMode)) {
505 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
506 Adapter->DriverState = NORMAL_OPERATION;
507 wake_up(&Adapter->LEDInfo.notify_led_event);
510 LinkMessage(Adapter);
515 * Driver to ignore the DREG_RECEIVED
516 * WiMAX Application should handle this Message
518 /* Adapter->liTimeSinceLastNetEntry = 0; */
519 Adapter->LinkUpStatus = 0;
520 Adapter->LinkStatus = 0;
521 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
522 Adapter->bTriedToWakeUpFromlowPowerMode = false;
523 Adapter->IdleMode = false;
524 beceem_protocol_reset(Adapter);
527 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
528 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
530 HandleShutDownModeRequest(Adapter, pucBuffer);
534 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x", *(pucBuffer + 1));
537 } else if (SET_MAC_ADDRESS_RESPONSE == *pucBuffer) {
538 PUCHAR puMacAddr = (pucBuffer + 1);
540 Adapter->LinkStatus = SYNC_UP_REQUEST;
541 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "MAC address response, sending SYNC_UP");
542 LinkMessage(Adapter);
543 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
545 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====", __func__);
548 void SendIdleModeResponse(struct bcm_mini_adapter *Adapter)
550 int status = 0, NVMAccess = 0, lowPwrAbortMsg = 0;
552 struct bcm_link_request stIdleResponse = {{0} };
554 memset(&tv, 0, sizeof(tv));
555 stIdleResponse.Leader.Status = IDLE_MESSAGE;
556 stIdleResponse.Leader.PLength = IDLE_MODE_PAYLOAD_LENGTH;
557 stIdleResponse.szData[0] = GO_TO_IDLE_MODE_PAYLOAD;
558 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, " ============>");
560 /*********************************
562 * if [ semaphore is available ]
563 * acquire semaphone and return value 0 ;
565 * return non-zero value ;
567 ***********************************/
569 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
570 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
573 if ((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
574 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)) {
577 up(&Adapter->NVMRdmWrmLock);
580 up(&Adapter->LowPowerModeSync);
582 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
583 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "HOST IS NACKING Idle mode To F/W!!!!!!!!");
584 Adapter->bPreparingForLowPowerMode = false;
586 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; /* 2; Idle ACK */
587 Adapter->StatisticsPointer = 0;
589 /* Wait for the LED to TURN OFF before sending ACK response */
590 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
593 /* Wake the LED Thread with IDLEMODE_ENTER State */
594 Adapter->DriverState = LOWPOWER_MODE_ENTER;
595 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);
596 wake_up(&Adapter->LEDInfo.notify_led_event);
598 /* Wait for 1 SEC for LED to OFF */
599 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
601 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
603 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
604 Adapter->DriverState = NORMAL_OPERATION;
605 wake_up(&Adapter->LEDInfo.notify_led_event);
606 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "NACKING Idle mode as time out happen from LED side!!!!!!!!");
610 if (stIdleResponse.szData[1] == TARGET_CAN_GO_TO_IDLE_MODE) {
611 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "ACKING IDLE MODE !!!!!!!!!");
612 down(&Adapter->rdmwrmsync);
613 Adapter->bPreparingForLowPowerMode = TRUE;
614 up(&Adapter->rdmwrmsync);
615 /* Killing all URBS. */
616 if (Adapter->bDoSuspend == TRUE)
617 Bcm_kill_all_URBs((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
619 Adapter->bPreparingForLowPowerMode = false;
623 up(&Adapter->NVMRdmWrmLock);
626 up(&Adapter->LowPowerModeSync);
629 status = CopyBufferToControlPacket(Adapter, &stIdleResponse);
630 if (status != STATUS_SUCCESS) {
631 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "fail to send the Idle mode Request\n");
632 Adapter->bPreparingForLowPowerMode = false;
633 StartInterruptUrb((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
635 do_gettimeofday(&tv);
636 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);
639 /******************************************************************
640 * Function - DumpPackInfo()
642 * Description - This function dumps the all Queue(PackInfo[]) details.
644 * Parameters - Adapter: Pointer to the Adapter structure.
647 *******************************************************************/
648 void DumpPackInfo(struct bcm_mini_adapter *Adapter)
650 unsigned int uiLoopIndex = 0;
651 unsigned int uiIndex = 0;
652 unsigned int uiClsfrIndex = 0;
653 struct bcm_classifier_rule *pstClassifierEntry = NULL;
655 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
656 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "*********** Showing Details Of Queue %d***** ******", uiLoopIndex);
657 if (false == Adapter->PackInfo[uiLoopIndex].bValid) {
658 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid is false for %X index\n", uiLoopIndex);
662 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " Dumping SF Rule Entry For SFID %lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
663 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " ucDirection %X\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
665 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
666 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv6 Service Flow\n");
668 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv4 Service Flow\n");
670 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SF Traffic Priority %X\n", Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
672 for (uiClsfrIndex = 0; uiClsfrIndex < MAX_CLASSIFIERS; uiClsfrIndex++) {
673 pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
674 if (!pstClassifierEntry->bUsed)
677 if (pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
680 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);
681 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);
682 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);
683 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);
684 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);
685 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);
687 for (uiIndex = 0; uiIndex < MAX_PORT_RANGE; uiIndex++) {
688 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeLo:%X\n", pstClassifierEntry->usSrcPortRangeLo[uiIndex]);
689 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeHi:%X\n", pstClassifierEntry->usSrcPortRangeHi[uiIndex]);
690 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeLo:%X\n", pstClassifierEntry->usDestPortRangeLo[uiIndex]);
691 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeHi:%X\n", pstClassifierEntry->usDestPortRangeHi[uiIndex]);
694 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPSourceAddressLength : 0x%x\n", pstClassifierEntry->ucIPSourceAddressLength);
695 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPDestinationAddressLength : 0x%x\n", pstClassifierEntry->ucIPDestinationAddressLength);
696 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPSourceAddressLength; uiIndex++) {
697 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
698 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpAddr :\n");
699 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Addr);
700 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpMask :\n");
701 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Mask);
703 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpAddr:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Addr[uiIndex]);
704 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpMask:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Mask[uiIndex]);
708 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPDestinationAddressLength; uiIndex++) {
709 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
710 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpAddr :\n");
711 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Addr);
712 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpMask :\n");
713 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Mask);
715 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpAddr:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Addr[uiIndex]);
716 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpMask:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Mask[uiIndex]);
719 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucProtocol:0x%X\n", pstClassifierEntry->ucProtocol[0]);
720 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tu8ClassifierRulePriority:%X\n", pstClassifierEntry->u8ClassifierRulePriority);
722 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ulSFID:%lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
723 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "usVCID_Value:%X\n", Adapter->PackInfo[uiLoopIndex].usVCID_Value);
724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "PhsEnabled: 0x%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
725 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThreshold:%X\n", Adapter->PackInfo[uiLoopIndex].uiThreshold);
727 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid:%X\n", Adapter->PackInfo[uiLoopIndex].bValid);
728 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bActive:%X\n", Adapter->PackInfo[uiLoopIndex].bActive);
729 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActivateReqSent: %x", Adapter->PackInfo[uiLoopIndex].bActivateRequestSent);
730 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "u8QueueType:%X\n", Adapter->PackInfo[uiLoopIndex].u8QueueType);
731 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxBucketSize:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize);
732 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPerSFTxResourceCount:%X\n", atomic_read(&Adapter->PackInfo[uiLoopIndex].uiPerSFTxResourceCount));
733 /* DumpDebug(DUMP_INFO,("bCSSupport:%X\n",Adapter->PackInfo[uiLoopIndex].bCSSupport)); */
734 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CurrQueueDepthOnTarget: %x\n", Adapter->PackInfo[uiLoopIndex].uiCurrentQueueDepthOnTarget);
735 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentBytesOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentBytesOnHost);
736 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentPacketsOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentPacketsOnHost);
737 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountBytes);
738 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountPackets);
739 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentBytes);
740 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentPackets);
741 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentDrainRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentDrainRate);
742 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThisPeriodSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiThisPeriodSentBytes);
743 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liDrainCalculated:%llX\n", Adapter->PackInfo[uiLoopIndex].liDrainCalculated);
744 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentTokenCount:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentTokenCount);
745 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liLastUpdateTokenAt:%llX\n", Adapter->PackInfo[uiLoopIndex].liLastUpdateTokenAt);
746 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxAllowedRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate);
747 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPendedLast:%X\n", Adapter->PackInfo[uiLoopIndex].uiPendedLast);
748 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "NumOfPacketsSent:%X\n", Adapter->PackInfo[uiLoopIndex].NumOfPacketsSent);
749 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Direction: %x\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
750 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CID: %x\n", Adapter->PackInfo[uiLoopIndex].usCID);
751 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ProtocolValid: %x\n", Adapter->PackInfo[uiLoopIndex].bProtocolValid);
752 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "TOSValid: %x\n", Adapter->PackInfo[uiLoopIndex].bTOSValid);
753 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "DestIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bDestIpValid);
754 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SrcIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bSrcIpValid);
755 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActiveSet: %x\n", Adapter->PackInfo[uiLoopIndex].bActiveSet);
756 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AdmittedSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAdmittedSet);
757 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AuthzSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAuthorizedSet);
758 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ClassifyPrority: %x\n", Adapter->PackInfo[uiLoopIndex].bClassifierPriority);
759 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxLatency: %x\n", Adapter->PackInfo[uiLoopIndex].uiMaxLatency);
760 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO,
761 DBG_LVL_ALL, "ServiceClassName: %*ph\n",
762 4, Adapter->PackInfo[uiLoopIndex].
764 /* BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bHeaderSuppressionEnabled :%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
765 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalTxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalTxBytes);
766 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalRxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalRxBytes);
767 * DumpDebug(DUMP_INFO,(" uiRanOutOfResCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiRanOutOfResCount));
771 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
772 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aRxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aRxPktSizeHist[uiLoopIndex]);
774 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
775 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aTxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aTxPktSizeHist[uiLoopIndex]);
778 int reset_card_proc(struct bcm_mini_adapter *ps_adapter)
780 int retval = STATUS_SUCCESS;
781 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
782 struct bcm_interface_adapter *psIntfAdapter = NULL;
783 unsigned int value = 0, uiResetValue = 0;
786 psIntfAdapter = ((struct bcm_interface_adapter *)(ps_adapter->pvInterfaceAdapter));
787 ps_adapter->bDDRInitDone = false;
789 if (ps_adapter->chip_id >= T3LPB) {
790 /* SYS_CFG register is write protected hence for modifying this reg value, it should be read twice before */
791 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
792 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
794 /* making bit[6...5] same as was before f/w download. this setting force the h/w to */
795 /* re-populated the SP RAM area with the string descriptor. */
796 value = value | (ps_adapter->syscfgBefFwDld & 0x00000060);
797 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
800 /* killing all submitted URBs. */
801 psIntfAdapter->psAdapter->StopAllXaction = TRUE;
802 Bcm_kill_all_URBs(psIntfAdapter);
803 /* Reset the UMA-B Device */
804 if (ps_adapter->chip_id >= T3LPB) {
805 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Resetting UMA-B\n");
806 retval = usb_reset_device(psIntfAdapter->udev);
807 psIntfAdapter->psAdapter->StopAllXaction = false;
809 if (retval != STATUS_SUCCESS) {
810 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
814 if (ps_adapter->chip_id == BCS220_2 ||
815 ps_adapter->chip_id == BCS220_2BC ||
816 ps_adapter->chip_id == BCS250_BC ||
817 ps_adapter->chip_id == BCS220_3) {
819 bytes = rdmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
822 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
825 /* setting 0th bit */
827 retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
829 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
834 bytes = rdmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
837 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
841 retval = wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
843 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
847 /* Toggling the GPIO 8, 9 */
849 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
851 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
855 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value));
857 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
863 /* ps_adapter->downloadDDR = false; */
864 if (ps_adapter->bFlashBoot) {
865 /* In flash boot mode MIPS state register has reverse polarity.
866 * So just or with setting bit 30.
867 * Make the MIPS in Reset state.
869 rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
870 uiResetValue |= (1<<30);
871 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
874 if (ps_adapter->chip_id >= T3LPB) {
877 * WA for SYSConfig Issue.
878 * Read SYSCFG Twice to make it writable.
880 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
881 if (uiResetValue & (1<<4)) {
883 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue)); /* 2nd read to make it writable. */
884 uiResetValue &= (~(1<<4));
885 wrmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
889 wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
892 psIntfAdapter->psAdapter->StopAllXaction = false;
896 int run_card_proc(struct bcm_mini_adapter *ps_adapter)
898 int status = STATUS_SUCCESS;
901 unsigned int value = 0;
903 bytes = rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value));
906 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
910 if (ps_adapter->bFlashBoot)
915 if (wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
916 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
917 return STATUS_FAILURE;
923 int InitCardAndDownloadFirmware(struct bcm_mini_adapter *ps_adapter)
926 unsigned int value = 0;
928 * Create the threads first and then download the
929 * Firm/DDR Settings..
931 status = create_worker_threads(ps_adapter);
935 status = bcm_parse_target_params(ps_adapter);
939 if (ps_adapter->chip_id >= T3LPB) {
940 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
941 ps_adapter->syscfgBefFwDld = value;
943 if ((value & 0x60) == 0)
944 ps_adapter->bFlashBoot = TRUE;
947 reset_card_proc(ps_adapter);
949 /* Initializing the NVM. */
950 BcmInitNVM(ps_adapter);
951 status = ddr_init(ps_adapter);
953 pr_err(DRV_NAME "ddr_init Failed\n");
957 /* Download cfg file */
958 status = buffDnldVerify(ps_adapter,
959 (PUCHAR)ps_adapter->pstargetparams,
960 sizeof(struct bcm_target_params),
963 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
967 if (register_networkdev(ps_adapter)) {
968 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
972 if (false == ps_adapter->AutoFirmDld) {
973 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoFirmDld Disabled in CFG File..\n");
974 /* If Auto f/w download is disable, register the control interface, */
975 /* register the control interface after the mailbox. */
976 if (register_control_device_interface(ps_adapter) < 0) {
977 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
980 return STATUS_SUCCESS;
984 * Do the LED Settings here. It will be used by the Firmware Download
989 * 1. If the LED Settings fails, do not stop and do the Firmware download.
990 * 2. This init would happened only if the cfg file is present, else
991 * call from the ioctl context.
994 status = InitLedSettings(ps_adapter);
996 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_PRINTK, 0, 0, "INIT LED FAILED\n");
1000 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1001 ps_adapter->DriverState = DRIVER_INIT;
1002 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1005 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1006 ps_adapter->DriverState = FW_DOWNLOAD;
1007 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1011 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1012 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1014 if (ps_adapter->eNVMType == NVM_FLASH) {
1015 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
1017 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Propagation of Cal param failed ..");
1022 /* Download Firmare */
1023 status = BcmFileDownload(ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR);
1025 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Firmware File is present...\n");
1029 status = run_card_proc(ps_adapter);
1031 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "run_card_proc Failed\n");
1035 ps_adapter->fw_download_done = TRUE;
1039 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1040 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1041 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1047 static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter)
1049 struct file *flp = NULL;
1053 buff = kmalloc(BUFFER_1K, GFP_KERNEL);
1057 Adapter->pstargetparams = kmalloc(sizeof(struct bcm_target_params), GFP_KERNEL);
1058 if (Adapter->pstargetparams == NULL) {
1063 flp = open_firmware_file(Adapter, CFG_FILE);
1065 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE\n", CFG_FILE);
1067 kfree(Adapter->pstargetparams);
1068 Adapter->pstargetparams = NULL;
1071 len = kernel_read(flp, 0, buff, BUFFER_1K);
1072 filp_close(flp, NULL);
1074 if (len != sizeof(struct bcm_target_params)) {
1075 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n");
1077 kfree(Adapter->pstargetparams);
1078 Adapter->pstargetparams = NULL;
1082 /* Check for autolink in config params */
1084 * Values in Adapter->pstargetparams are in network byte order
1086 memcpy(Adapter->pstargetparams, buff, sizeof(struct bcm_target_params));
1088 beceem_parse_target_struct(Adapter);
1089 return STATUS_SUCCESS;
1092 void beceem_parse_target_struct(struct bcm_mini_adapter *Adapter)
1094 unsigned int uiHostDrvrCfg6 = 0, uiEEPROMFlag = 0;
1096 if (ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE) {
1097 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
1098 Adapter->AutoSyncup = false;
1100 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
1101 Adapter->AutoSyncup = TRUE;
1104 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE) {
1105 pr_info(DRV_NAME ": Enabling autolink up");
1106 Adapter->AutoLinkUp = TRUE;
1108 pr_info(DRV_NAME ": Disabling autolink up");
1109 Adapter->AutoLinkUp = false;
1111 /* Setting the DDR Setting.. */
1112 Adapter->DDRSetting = (ntohl(Adapter->pstargetparams->HostDrvrConfig6) >> 8)&0x0F;
1113 Adapter->ulPowerSaveMode = (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
1114 pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1115 pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
1116 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD) {
1117 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1118 Adapter->AutoFirmDld = TRUE;
1120 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1121 Adapter->AutoFirmDld = false;
1123 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1124 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
1125 pr_info(DRV_NAME ": MIPSConfig : 0x%X\n", Adapter->bMipsConfig);
1126 /* used for backward compatibility. */
1127 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
1128 Adapter->PmuMode = (uiHostDrvrCfg6 >> 24) & 0x03;
1129 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
1131 if ((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT) & (0x01)) {
1132 Adapter->bDoSuspend = TRUE;
1133 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1136 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
1137 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n", uiEEPROMFlag);
1138 Adapter->eNVMType = (enum bcm_nvm_type)((uiEEPROMFlag>>4)&0x3);
1139 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
1140 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
1141 Adapter->bSectorSizeOverride = (bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
1143 if (ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x01)
1144 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
1146 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1147 doPowerAutoCorrection(Adapter);
1150 static void doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter)
1152 unsigned int reporting_mode;
1154 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x02;
1155 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1157 if (reporting_mode) {
1158 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "can't do suspen/resume as reporting mode is enable");
1159 psAdapter->bDoSuspend = false;
1162 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB)) {
1163 /* If reporting mode is enable, switch PMU to PMC */
1165 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
1166 psAdapter->bDoSuspend = false;
1169 /* clearing space bit[15..12] */
1170 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl((0xF << 12)));
1171 /* placing the power save mode option */
1172 psAdapter->pstargetparams->HostDrvrConfig6 |= htonl((psAdapter->ulPowerSaveMode << 12));
1173 } else if (psAdapter->bIsAutoCorrectEnabled == false) {
1174 /* remove the autocorrect disable bit set before dumping. */
1175 psAdapter->ulPowerSaveMode &= ~(1 << 3);
1176 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl(1 << 15));
1177 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Using Forced User Choice: %lx\n", psAdapter->ulPowerSaveMode);
1181 static void convertEndian(unsigned char rwFlag, unsigned int *puiBuffer, unsigned int uiByteCount)
1183 unsigned int uiIndex = 0;
1185 if (RWM_WRITE == rwFlag) {
1186 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(unsigned int)); uiIndex++)
1187 puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
1189 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(unsigned int)); uiIndex++)
1190 puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
1194 int rdm(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
1196 return Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
1197 uiAddress, pucBuff, sSize);
1200 int wrm(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
1204 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
1205 uiAddress, pucBuff, sSize);
1209 int wrmalt(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
1211 convertEndian(RWM_WRITE, pucBuff, size);
1212 return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1215 int rdmalt(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
1219 uiRetVal = rdm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1220 convertEndian(RWM_READ, (unsigned int *)pucBuff, size);
1225 int wrmWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
1227 int status = STATUS_SUCCESS;
1229 down(&Adapter->rdmwrmsync);
1231 if ((Adapter->IdleMode == TRUE) ||
1232 (Adapter->bShutStatus == TRUE) ||
1233 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1239 status = wrm(Adapter, uiAddress, pucBuff, sSize);
1241 up(&Adapter->rdmwrmsync);
1245 int wrmaltWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
1247 int iRetVal = STATUS_SUCCESS;
1249 down(&Adapter->rdmwrmsync);
1251 if ((Adapter->IdleMode == TRUE) ||
1252 (Adapter->bShutStatus == TRUE) ||
1253 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1259 iRetVal = wrmalt(Adapter, uiAddress, pucBuff, size);
1261 up(&Adapter->rdmwrmsync);
1265 int rdmaltWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
1267 int uiRetVal = STATUS_SUCCESS;
1269 down(&Adapter->rdmwrmsync);
1270 if ((Adapter->IdleMode == TRUE) ||
1271 (Adapter->bShutStatus == TRUE) ||
1272 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1278 uiRetVal = rdmalt(Adapter, uiAddress, pucBuff, size);
1280 up(&Adapter->rdmwrmsync);
1284 static void HandleShutDownModeWakeup(struct bcm_mini_adapter *Adapter)
1286 int clear_abort_pattern = 0, Status = 0;
1288 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1289 /* target has woken up From Shut Down */
1290 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Clearing Shut Down Software abort pattern\n");
1291 Status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC, (unsigned int *)&clear_abort_pattern, sizeof(clear_abort_pattern));
1293 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
1297 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) {
1299 InterfaceHandleShutdownModeWakeup(Adapter);
1303 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1304 Adapter->DriverState = NO_NETWORK_ENTRY;
1305 wake_up(&Adapter->LEDInfo.notify_led_event);
1308 Adapter->bTriedToWakeUpFromlowPowerMode = false;
1309 Adapter->bShutStatus = false;
1310 wake_up(&Adapter->lowpower_mode_wait_queue);
1311 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1314 static void SendShutModeResponse(struct bcm_mini_adapter *Adapter)
1316 struct bcm_link_request stShutdownResponse;
1317 unsigned int NVMAccess = 0, lowPwrAbortMsg = 0;
1318 unsigned int Status = 0;
1320 memset(&stShutdownResponse, 0, sizeof(struct bcm_link_request));
1321 stShutdownResponse.Leader.Status = LINK_UP_CONTROL_REQ;
1322 stShutdownResponse.Leader.PLength = 8; /* 8 bytes; */
1323 stShutdownResponse.szData[0] = LINK_UP_ACK;
1324 stShutdownResponse.szData[1] = LINK_SHUTDOWN_REQ_FROM_FIRMWARE;
1326 /*********************************
1328 * if [ semaphore is available ]
1329 * acquire semaphone and return value 0 ;
1331 * return non-zero value ;
1333 ***********************************/
1335 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1336 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
1338 if (NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) {
1340 up(&Adapter->NVMRdmWrmLock);
1342 if (!lowPwrAbortMsg)
1343 up(&Adapter->LowPowerModeSync);
1345 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Device Access is going on NACK the Shut Down MODE\n");
1346 stShutdownResponse.szData[2] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
1347 Adapter->bPreparingForLowPowerMode = false;
1349 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Sending SHUTDOWN MODE ACK\n");
1350 stShutdownResponse.szData[2] = SHUTDOWN_ACK_FROM_DRIVER; /* ShutDown ACK */
1352 /* Wait for the LED to TURN OFF before sending ACK response */
1353 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1356 /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1357 Adapter->DriverState = LOWPOWER_MODE_ENTER;
1358 wake_up(&Adapter->LEDInfo.notify_led_event);
1360 /* Wait for 1 SEC for LED to OFF */
1361 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
1363 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
1365 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
1366 Adapter->DriverState = NO_NETWORK_ENTRY;
1367 wake_up(&Adapter->LEDInfo.notify_led_event);
1371 if (stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER) {
1372 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ACKING SHUTDOWN MODE !!!!!!!!!");
1373 down(&Adapter->rdmwrmsync);
1374 Adapter->bPreparingForLowPowerMode = TRUE;
1375 up(&Adapter->rdmwrmsync);
1376 /* Killing all URBS. */
1377 if (Adapter->bDoSuspend == TRUE)
1378 Bcm_kill_all_URBs((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
1380 Adapter->bPreparingForLowPowerMode = false;
1384 up(&Adapter->NVMRdmWrmLock);
1386 if (!lowPwrAbortMsg)
1387 up(&Adapter->LowPowerModeSync);
1390 Status = CopyBufferToControlPacket(Adapter, &stShutdownResponse);
1391 if (Status != STATUS_SUCCESS) {
1392 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "fail to send the Idle mode Request\n");
1393 Adapter->bPreparingForLowPowerMode = false;
1394 StartInterruptUrb((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
1398 static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
1400 unsigned int uiResetValue = 0;
1402 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1404 if (*(pucBuffer+1) == COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW) {
1405 HandleShutDownModeWakeup(Adapter);
1406 } else if (*(pucBuffer+1) == LINK_SHUTDOWN_REQ_FROM_FIRMWARE) {
1407 /* Target wants to go to Shut Down Mode */
1408 /* InterfacePrepareForShutdown(Adapter); */
1409 if (Adapter->chip_id == BCS220_2 ||
1410 Adapter->chip_id == BCS220_2BC ||
1411 Adapter->chip_id == BCS250_BC ||
1412 Adapter->chip_id == BCS220_3) {
1414 rdmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1415 uiResetValue |= (1<<17);
1416 wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1419 SendShutModeResponse(Adapter);
1420 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ShutDownModeResponse:Notification received: Sending the response(Ack/Nack)\n");
1423 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1426 void ResetCounters(struct bcm_mini_adapter *Adapter)
1428 beceem_protocol_reset(Adapter);
1429 Adapter->CurrNumRecvDescs = 0;
1430 Adapter->PrevNumRecvDescs = 0;
1431 Adapter->LinkUpStatus = 0;
1432 Adapter->LinkStatus = 0;
1433 atomic_set(&Adapter->cntrlpktCnt, 0);
1434 atomic_set(&Adapter->TotalPacketCount, 0);
1435 Adapter->fw_download_done = false;
1436 Adapter->LinkStatus = 0;
1437 Adapter->AutoLinkUp = false;
1438 Adapter->IdleMode = false;
1439 Adapter->bShutStatus = false;
1442 struct bcm_classifier_rule *GetFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIP)
1444 unsigned int uiIndex = 0;
1446 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1447 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1448 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1449 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIP) &&
1450 !Adapter->astFragmentedPktClassifierTable[uiIndex].bOutOfOrderFragment)
1452 return Adapter->astFragmentedPktClassifierTable[uiIndex].pstMatchedClassifierEntry;
1457 void AddFragIPClsEntry(struct bcm_mini_adapter *Adapter, struct bcm_fragmented_packet_info *psFragPktInfo)
1459 unsigned int uiIndex = 0;
1461 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1462 if (!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) {
1463 memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex], psFragPktInfo, sizeof(struct bcm_fragmented_packet_info));
1469 void DelFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIp)
1471 unsigned int uiIndex = 0;
1473 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1474 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1475 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1476 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIp))
1478 memset(&Adapter->astFragmentedPktClassifierTable[uiIndex], 0, sizeof(struct bcm_fragmented_packet_info));
1482 void update_per_cid_rx(struct bcm_mini_adapter *Adapter)
1484 unsigned int qindex = 0;
1486 if ((jiffies - Adapter->liDrainCalculated) < XSECONDS)
1489 for (qindex = 0; qindex < HiPriority; qindex++) {
1490 if (Adapter->PackInfo[qindex].ucDirection == 0) {
1491 Adapter->PackInfo[qindex].uiCurrentRxRate =
1492 (Adapter->PackInfo[qindex].uiCurrentRxRate +
1493 Adapter->PackInfo[qindex].uiThisPeriodRxBytes) / 2;
1495 Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
1497 Adapter->PackInfo[qindex].uiCurrentDrainRate =
1498 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
1499 Adapter->PackInfo[qindex].uiThisPeriodSentBytes) / 2;
1500 Adapter->PackInfo[qindex].uiThisPeriodSentBytes = 0;
1503 Adapter->liDrainCalculated = jiffies;
1506 void update_per_sf_desc_cnts(struct bcm_mini_adapter *Adapter)
1509 u32 uibuff[MAX_TARGET_DSX_BUFFERS];
1512 if (!atomic_read(&Adapter->uiMBupdate))
1515 bytes = rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (unsigned int *)uibuff, sizeof(unsigned int) * MAX_TARGET_DSX_BUFFERS);
1517 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
1521 for (iIndex = 0; iIndex < HiPriority; iIndex++) {
1522 if (Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection) {
1523 if (Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
1524 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
1526 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid VCID : %x\n", Adapter->PackInfo[iIndex].usVCID_Value);
1529 atomic_set(&Adapter->uiMBupdate, false);
1532 void flush_queue(struct bcm_mini_adapter *Adapter, unsigned int iQIndex)
1534 struct sk_buff *PacketToDrop = NULL;
1535 struct net_device_stats *netstats = &Adapter->dev->stats;
1537 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1539 while (Adapter->PackInfo[iQIndex].FirstTxQueue && atomic_read(&Adapter->TotalPacketCount)) {
1540 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
1541 if (PacketToDrop && PacketToDrop->len) {
1542 netstats->tx_dropped++;
1543 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, Adapter->PackInfo[iQIndex].LastTxQueue);
1544 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1545 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1547 /* Adding dropped statistics */
1548 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1549 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
1550 dev_kfree_skb(PacketToDrop);
1551 atomic_dec(&Adapter->TotalPacketCount);
1554 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1557 static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter)
1561 if (netif_msg_link(Adapter))
1562 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
1564 netif_carrier_off(Adapter->dev);
1565 netif_stop_queue(Adapter->dev);
1567 Adapter->IdleMode = false;
1568 Adapter->LinkUpStatus = false;
1569 ClearTargetDSXBuffer(Adapter, 0, TRUE);
1570 /* Delete All Classifier Rules */
1572 for (i = 0; i < HiPriority; i++)
1573 DeleteAllClassifiersForSF(Adapter, i);
1575 flush_all_queues(Adapter);
1577 if (Adapter->TimerActive == TRUE)
1578 Adapter->TimerActive = false;
1580 memset(Adapter->astFragmentedPktClassifierTable, 0, sizeof(struct bcm_fragmented_packet_info) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
1582 for (i = 0; i < HiPriority; i++) {
1583 /* resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF. */
1584 /* It is same between MIBs and SF. */
1585 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable, 0, sizeof(struct bcm_mibs_parameters));