x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / staging / bcm / Misc.c
blob4cfc2c33c6966a1e2b3d560205aac87548c422bc
1 #include "headers.h"
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;
24 return;
27 int InitAdapter(struct bcm_mini_adapter *psAdapter)
29 int i = 0;
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");
35 return -EINVAL;
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);
48 i = 0;
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);
63 return -ENOMEM;
67 if (AllocAdapterDsxBuffer(psAdapter)) {
68 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to allocate DSX buffers");
69 return -EINVAL;
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__);
75 return -ENOMEM;
78 Status = BcmAllocFlashCSStructure(psAdapter);
79 if (Status) {
80 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Memory Allocation for Flash structure failed");
81 return Status;
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");
88 return Status;
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)
98 int count;
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));
118 msleep(100);
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);
147 /* Tx Thread */
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);
155 return 0;
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);
161 if (IS_ERR(flp)) {
162 pr_err(DRV_NAME "Unable To Open File %s, err %ld", path, PTR_ERR(flp));
163 flp = NULL;
166 if (Adapter->device_removed)
167 flp = NULL;
169 return flp;
172 /* Arguments:
173 * Logical Adapter
174 * Path to image file
175 * Download Address on the chip
177 static int BcmFileDownload(struct bcm_mini_adapter *Adapter, const char *path, unsigned int loc)
179 int errorno = 0;
180 struct file *flp = NULL;
181 struct timeval tv = {0};
183 flp = open_firmware_file(Adapter, path);
184 if (!flp) {
185 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Unable to Open %s\n", path);
186 return -ENOENT;
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)file_inode(flp)->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);
194 errorno = -EIO;
195 goto exit_download;
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!");
200 errorno = -EIO;
201 goto exit_download;
204 exit_download:
205 filp_close(flp, NULL);
206 return errorno;
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 spinlock, as it it already acquired.
214 * @return SUCCESS/FAILURE.
215 * Arguments:
216 * Logical Adapter
217 * Control Packet Buffer
219 int CopyBufferToControlPacket(struct bcm_mini_adapter *Adapter, void *ioBuffer)
221 struct bcm_leader *pLeader = NULL;
222 int Status = 0;
223 unsigned char *ctrl_buff;
224 unsigned int pktlen = 0;
225 struct bcm_link_request *pLinkReq = NULL;
226 PUCHAR pucAddIndication = NULL;
228 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "======>");
229 if (!ioBuffer) {
230 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Got Null Buffer\n");
231 return -EINVAL;
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 (Adapter->bShutStatus == TRUE) {
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)
266 return Status;
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;
272 } else {
273 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Wakeup has been tried already...\n");
278 if (Adapter->IdleMode == TRUE) {
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 */
287 } else {
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;
291 } else {
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)
310 return Status;
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;
316 } else {
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 if (!ctrl_buff) {
329 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "mem allocation Failed");
330 return -ENOMEM;
333 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",
334 atomic_read(&Adapter->index_wr_txcntrlpkt), ctrl_buff, ioBuffer, pktlen);
336 if (pLeader) {
337 if ((pLeader->Status == 0x80) ||
338 (pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ)) {
340 * Restructure the DSX message to handle Multiple classifier Support
341 * Write the Service Flow param Structures directly to the target
342 * and embed the pointers in the DSX messages sent to target.
344 /* Lets store the current length of the control packet we are transmitting */
345 pucAddIndication = (PUCHAR)ioBuffer + LEADER_SIZE;
346 pktlen = pLeader->PLength;
347 Status = StoreCmControlResponseMessage(Adapter, pucAddIndication, &pktlen);
348 if (Status != 1) {
349 ClearTargetDSXBuffer(Adapter, ((struct bcm_add_indication_alt *)pucAddIndication)->u16TID, FALSE);
350 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 ");
351 return STATUS_FAILURE;
354 * update the leader to use the new length
355 * The length of the control packet is length of message being sent + Leader length
357 pLeader->PLength = pktlen;
361 if (pktlen + LEADER_SIZE > MAX_CNTL_PKT_SIZE)
362 return -EINVAL;
364 memset(ctrl_buff, 0, pktlen+LEADER_SIZE);
365 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Copying the Control Packet Buffer with length=%d\n", pLeader->PLength);
366 *(struct bcm_leader *)ctrl_buff = *pLeader;
367 memcpy(ctrl_buff + LEADER_SIZE, ((PUCHAR)ioBuffer + LEADER_SIZE), pLeader->PLength);
368 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Enqueuing the Control Packet");
370 /* Update the statistics counters */
371 spin_lock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
372 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost += pLeader->PLength;
373 Adapter->PackInfo[HiPriority].uiCurrentPacketsOnHost++;
374 atomic_inc(&Adapter->TotalPacketCount);
375 spin_unlock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
376 Adapter->PackInfo[HiPriority].bValid = TRUE;
378 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "CurrBytesOnHost: %x bValid: %x",
379 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost,
380 Adapter->PackInfo[HiPriority].bValid);
381 Status = STATUS_SUCCESS;
382 /*Queue the packet for transmission */
383 atomic_inc(&Adapter->index_wr_txcntrlpkt);
384 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Calling transmit_packets");
385 atomic_set(&Adapter->TxPktAvail, 1);
386 wake_up(&Adapter->tx_packet_wait_queue);
388 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<====");
389 return Status;
392 /******************************************************************
393 * Function - LinkMessage()
395 * Description - This function builds the Sync-up and Link-up request
396 * packet messages depending on the device Link status.
398 * Parameters - Adapter: Pointer to the Adapter structure.
400 * Returns - None.
401 *******************************************************************/
402 void LinkMessage(struct bcm_mini_adapter *Adapter)
404 struct bcm_link_request *pstLinkRequest = NULL;
405 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>");
406 if (Adapter->LinkStatus == SYNC_UP_REQUEST && Adapter->AutoSyncup) {
407 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
408 if (!pstLinkRequest) {
409 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
410 return;
412 /* sync up request... */
413 Adapter->LinkStatus = WAIT_FOR_SYNC; /* current link status */
414 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For SyncUp...");
415 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
416 pstLinkRequest->szData[1] = LINK_SYNC_UP_SUBTYPE;
417 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
418 pstLinkRequest->Leader.PLength = sizeof(ULONG);
419 Adapter->bSyncUpRequestSent = TRUE;
421 } else if (Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp) {
422 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
423 if (!pstLinkRequest) {
424 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
425 return;
427 /* LINK_UP_REQUEST */
428 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For LinkUp...");
429 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
430 pstLinkRequest->szData[1] = LINK_NET_ENTRY;
431 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
432 pstLinkRequest->Leader.PLength = sizeof(ULONG);
434 if (pstLinkRequest) {
435 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
436 CopyBufferToControlPacket(Adapter, pstLinkRequest);
437 kfree(pstLinkRequest);
439 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
440 return;
443 /**********************************************************************
444 * Function - StatisticsResponse()
446 * Description - This function handles the Statistics response packet.
448 * Parameters - Adapter : Pointer to the Adapter structure.
449 * - pvBuffer: Starting address of Statistic response data.
451 * Returns - None.
452 ************************************************************************/
453 void StatisticsResponse(struct bcm_mini_adapter *Adapter, void *pvBuffer)
455 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>", __func__);
456 Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
457 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (unsigned int)Adapter->StatisticsPointer);
458 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====", __func__);
459 return;
462 /**********************************************************************
463 * Function - LinkControlResponseMessage()
465 * Description - This function handles the Link response packets.
467 * Parameters - Adapter : Pointer to the Adapter structure.
468 * - pucBuffer: Starting address of Link response data.
470 * Returns - None.
471 ***********************************************************************/
472 void LinkControlResponseMessage(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
474 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
476 if (*pucBuffer == LINK_UP_ACK) {
477 switch (*(pucBuffer+1)) {
478 case PHY_SYNC_ACHIVED: /* SYNCed UP */
479 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHY_SYNC_ACHIVED");
481 if (Adapter->LinkStatus == LINKUP_DONE)
482 beceem_protocol_reset(Adapter);
484 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
485 Adapter->LinkStatus = PHY_SYNC_ACHIVED;
487 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
488 Adapter->DriverState = NO_NETWORK_ENTRY;
489 wake_up(&Adapter->LEDInfo.notify_led_event);
492 LinkMessage(Adapter);
493 break;
495 case LINKUP_DONE:
496 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LINKUP_DONE");
497 Adapter->LinkStatus = LINKUP_DONE;
498 Adapter->bPHSEnabled = *(pucBuffer+3);
499 Adapter->bETHCSEnabled = *(pucBuffer+4) & ETH_CS_MASK;
500 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHS Support Status Received In LinkUp Ack : %x\n", Adapter->bPHSEnabled);
502 if ((FALSE == Adapter->bShutStatus) && (FALSE == Adapter->IdleMode)) {
503 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
504 Adapter->DriverState = NORMAL_OPERATION;
505 wake_up(&Adapter->LEDInfo.notify_led_event);
508 LinkMessage(Adapter);
509 break;
511 case WAIT_FOR_SYNC:
513 * Driver to ignore the DREG_RECEIVED
514 * WiMAX Application should handle this Message
516 /* Adapter->liTimeSinceLastNetEntry = 0; */
517 Adapter->LinkUpStatus = 0;
518 Adapter->LinkStatus = 0;
519 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
520 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
521 Adapter->IdleMode = FALSE;
522 beceem_protocol_reset(Adapter);
524 break;
525 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
526 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
528 HandleShutDownModeRequest(Adapter, pucBuffer);
530 break;
531 default:
532 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x", *(pucBuffer + 1));
533 break;
535 } else if (SET_MAC_ADDRESS_RESPONSE == *pucBuffer) {
536 PUCHAR puMacAddr = (pucBuffer + 1);
537 Adapter->LinkStatus = SYNC_UP_REQUEST;
538 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "MAC address response, sending SYNC_UP");
539 LinkMessage(Adapter);
540 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
542 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====", __func__);
543 return;
546 void SendIdleModeResponse(struct bcm_mini_adapter *Adapter)
548 int status = 0, NVMAccess = 0, lowPwrAbortMsg = 0;
549 struct timeval tv;
550 struct bcm_link_request stIdleResponse = {{0} };
551 memset(&tv, 0, sizeof(tv));
552 stIdleResponse.Leader.Status = IDLE_MESSAGE;
553 stIdleResponse.Leader.PLength = IDLE_MODE_PAYLOAD_LENGTH;
554 stIdleResponse.szData[0] = GO_TO_IDLE_MODE_PAYLOAD;
555 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, " ============>");
557 /*********************************
558 *down_trylock -
559 * if [ semaphore is available ]
560 * acquire semaphone and return value 0 ;
561 * else
562 * return non-zero value ;
564 ***********************************/
566 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
567 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
570 if ((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
571 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)) {
573 if (!NVMAccess)
574 up(&Adapter->NVMRdmWrmLock);
576 if (!lowPwrAbortMsg)
577 up(&Adapter->LowPowerModeSync);
579 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
580 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "HOST IS NACKING Idle mode To F/W!!!!!!!!");
581 Adapter->bPreparingForLowPowerMode = FALSE;
582 } else {
583 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; /* 2; Idle ACK */
584 Adapter->StatisticsPointer = 0;
586 /* Wait for the LED to TURN OFF before sending ACK response */
587 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
588 int iRetVal = 0;
590 /* Wake the LED Thread with IDLEMODE_ENTER State */
591 Adapter->DriverState = LOWPOWER_MODE_ENTER;
592 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);
593 wake_up(&Adapter->LEDInfo.notify_led_event);
595 /* Wait for 1 SEC for LED to OFF */
596 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
598 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
599 if (iRetVal <= 0) {
600 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
601 Adapter->DriverState = NORMAL_OPERATION;
602 wake_up(&Adapter->LEDInfo.notify_led_event);
603 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "NACKING Idle mode as time out happen from LED side!!!!!!!!");
607 if (stIdleResponse.szData[1] == TARGET_CAN_GO_TO_IDLE_MODE) {
608 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "ACKING IDLE MODE !!!!!!!!!");
609 down(&Adapter->rdmwrmsync);
610 Adapter->bPreparingForLowPowerMode = TRUE;
611 up(&Adapter->rdmwrmsync);
612 /* Killing all URBS. */
613 if (Adapter->bDoSuspend == TRUE)
614 Bcm_kill_all_URBs((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
615 } else {
616 Adapter->bPreparingForLowPowerMode = FALSE;
619 if (!NVMAccess)
620 up(&Adapter->NVMRdmWrmLock);
622 if (!lowPwrAbortMsg)
623 up(&Adapter->LowPowerModeSync);
626 status = CopyBufferToControlPacket(Adapter, &stIdleResponse);
627 if ((status != STATUS_SUCCESS)) {
628 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "fail to send the Idle mode Request\n");
629 Adapter->bPreparingForLowPowerMode = FALSE;
630 StartInterruptUrb((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
632 do_gettimeofday(&tv);
633 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);
636 /******************************************************************
637 * Function - DumpPackInfo()
639 * Description - This function dumps the all Queue(PackInfo[]) details.
641 * Parameters - Adapter: Pointer to the Adapter structure.
643 * Returns - None.
644 *******************************************************************/
645 void DumpPackInfo(struct bcm_mini_adapter *Adapter)
647 unsigned int uiLoopIndex = 0;
648 unsigned int uiIndex = 0;
649 unsigned int uiClsfrIndex = 0;
650 struct bcm_classifier_rule *pstClassifierEntry = NULL;
652 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
653 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "*********** Showing Details Of Queue %d***** ******", uiLoopIndex);
654 if (FALSE == Adapter->PackInfo[uiLoopIndex].bValid) {
655 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid is FALSE for %X index\n", uiLoopIndex);
656 continue;
659 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " Dumping SF Rule Entry For SFID %lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
660 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " ucDirection %X\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
662 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
663 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv6 Service Flow\n");
664 else
665 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv4 Service Flow\n");
667 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SF Traffic Priority %X\n", Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
669 for (uiClsfrIndex = 0; uiClsfrIndex < MAX_CLASSIFIERS; uiClsfrIndex++) {
670 pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
671 if (!pstClassifierEntry->bUsed)
672 continue;
674 if (pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
675 continue;
677 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);
678 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);
679 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);
680 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);
681 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);
682 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);
684 for (uiIndex = 0; uiIndex < MAX_PORT_RANGE; uiIndex++) {
685 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeLo:%X\n", pstClassifierEntry->usSrcPortRangeLo[uiIndex]);
686 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeHi:%X\n", pstClassifierEntry->usSrcPortRangeHi[uiIndex]);
687 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeLo:%X\n", pstClassifierEntry->usDestPortRangeLo[uiIndex]);
688 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeHi:%X\n", pstClassifierEntry->usDestPortRangeHi[uiIndex]);
691 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPSourceAddressLength : 0x%x\n", pstClassifierEntry->ucIPSourceAddressLength);
692 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPDestinationAddressLength : 0x%x\n", pstClassifierEntry->ucIPDestinationAddressLength);
693 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPSourceAddressLength; uiIndex++) {
694 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
695 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpAddr :\n");
696 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Addr);
697 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpMask :\n");
698 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Mask);
699 } else {
700 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpAddr:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Addr[uiIndex]);
701 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpMask:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Mask[uiIndex]);
705 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPDestinationAddressLength; uiIndex++) {
706 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
707 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpAddr :\n");
708 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Addr);
709 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpMask :\n");
710 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Mask);
711 } else {
712 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpAddr:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Addr[uiIndex]);
713 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpMask:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Mask[uiIndex]);
716 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucProtocol:0x%X\n", pstClassifierEntry->ucProtocol[0]);
717 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tu8ClassifierRulePriority:%X\n", pstClassifierEntry->u8ClassifierRulePriority);
719 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ulSFID:%lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
720 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "usVCID_Value:%X\n", Adapter->PackInfo[uiLoopIndex].usVCID_Value);
721 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "PhsEnabled: 0x%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
722 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThreshold:%X\n", Adapter->PackInfo[uiLoopIndex].uiThreshold);
724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid:%X\n", Adapter->PackInfo[uiLoopIndex].bValid);
725 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bActive:%X\n", Adapter->PackInfo[uiLoopIndex].bActive);
726 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActivateReqSent: %x", Adapter->PackInfo[uiLoopIndex].bActivateRequestSent);
727 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "u8QueueType:%X\n", Adapter->PackInfo[uiLoopIndex].u8QueueType);
728 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxBucketSize:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize);
729 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPerSFTxResourceCount:%X\n", atomic_read(&Adapter->PackInfo[uiLoopIndex].uiPerSFTxResourceCount));
730 /* DumpDebug(DUMP_INFO,("bCSSupport:%X\n",Adapter->PackInfo[uiLoopIndex].bCSSupport)); */
731 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CurrQueueDepthOnTarget: %x\n", Adapter->PackInfo[uiLoopIndex].uiCurrentQueueDepthOnTarget);
732 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentBytesOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentBytesOnHost);
733 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentPacketsOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentPacketsOnHost);
734 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountBytes);
735 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountPackets);
736 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentBytes);
737 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentPackets);
738 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentDrainRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentDrainRate);
739 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThisPeriodSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiThisPeriodSentBytes);
740 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liDrainCalculated:%llX\n", Adapter->PackInfo[uiLoopIndex].liDrainCalculated);
741 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentTokenCount:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentTokenCount);
742 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liLastUpdateTokenAt:%llX\n", Adapter->PackInfo[uiLoopIndex].liLastUpdateTokenAt);
743 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxAllowedRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate);
744 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPendedLast:%X\n", Adapter->PackInfo[uiLoopIndex].uiPendedLast);
745 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "NumOfPacketsSent:%X\n", Adapter->PackInfo[uiLoopIndex].NumOfPacketsSent);
746 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Direction: %x\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
747 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CID: %x\n", Adapter->PackInfo[uiLoopIndex].usCID);
748 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ProtocolValid: %x\n", Adapter->PackInfo[uiLoopIndex].bProtocolValid);
749 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "TOSValid: %x\n", Adapter->PackInfo[uiLoopIndex].bTOSValid);
750 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "DestIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bDestIpValid);
751 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SrcIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bSrcIpValid);
752 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActiveSet: %x\n", Adapter->PackInfo[uiLoopIndex].bActiveSet);
753 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AdmittedSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAdmittedSet);
754 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AuthzSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAuthorizedSet);
755 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ClassifyPrority: %x\n", Adapter->PackInfo[uiLoopIndex].bClassifierPriority);
756 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxLatency: %x\n", Adapter->PackInfo[uiLoopIndex].uiMaxLatency);
757 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO,
758 DBG_LVL_ALL, "ServiceClassName: %*ph\n",
759 4, Adapter->PackInfo[uiLoopIndex].
760 ucServiceClassName);
761 /* BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bHeaderSuppressionEnabled :%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
762 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalTxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalTxBytes);
763 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalRxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalRxBytes);
764 * DumpDebug(DUMP_INFO,(" uiRanOutOfResCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiRanOutOfResCount));
768 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
769 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aRxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aRxPktSizeHist[uiLoopIndex]);
771 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
772 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aTxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aTxPktSizeHist[uiLoopIndex]);
774 return;
777 int reset_card_proc(struct bcm_mini_adapter *ps_adapter)
779 int retval = STATUS_SUCCESS;
780 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
781 struct bcm_interface_adapter *psIntfAdapter = NULL;
782 unsigned int value = 0, uiResetValue = 0;
783 int bytes;
785 psIntfAdapter = ((struct bcm_interface_adapter *)(ps_adapter->pvInterfaceAdapter));
786 ps_adapter->bDDRInitDone = FALSE;
788 if (ps_adapter->chip_id >= T3LPB) {
789 /* SYS_CFG register is write protected hence for modifying this reg value, it should be read twice before */
790 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
791 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
793 /* making bit[6...5] same as was before f/w download. this setting force the h/w to */
794 /* re-populated the SP RAM area with the string descriptor. */
795 value = value | (ps_adapter->syscfgBefFwDld & 0x00000060);
796 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
799 /* killing all submitted URBs. */
800 psIntfAdapter->psAdapter->StopAllXaction = TRUE;
801 Bcm_kill_all_URBs(psIntfAdapter);
802 /* Reset the UMA-B Device */
803 if (ps_adapter->chip_id >= T3LPB) {
804 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Resetting UMA-B\n");
805 retval = usb_reset_device(psIntfAdapter->udev);
806 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
808 if (retval != STATUS_SUCCESS) {
809 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
810 goto err_exit;
813 if (ps_adapter->chip_id == BCS220_2 ||
814 ps_adapter->chip_id == BCS220_2BC ||
815 ps_adapter->chip_id == BCS250_BC ||
816 ps_adapter->chip_id == BCS220_3) {
818 bytes = rdmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
819 if (bytes < 0) {
820 retval = bytes;
821 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
822 goto err_exit;
824 /* setting 0th bit */
825 value |= (1<<0);
826 retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
827 if (retval < 0) {
828 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
829 goto err_exit;
832 } else {
833 bytes = rdmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
834 if (bytes < 0) {
835 retval = bytes;
836 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
837 goto err_exit;
839 value &= (~(1<<16));
840 retval = wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
841 if (retval < 0) {
842 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
843 goto err_exit;
846 /* Toggling the GPIO 8, 9 */
847 value = 0;
848 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
849 if (retval < 0) {
850 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
851 goto err_exit;
853 value = 0x300;
854 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value));
855 if (retval < 0) {
856 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
857 goto err_exit;
859 mdelay(50);
862 /* ps_adapter->downloadDDR = false; */
863 if (ps_adapter->bFlashBoot) {
864 /* In flash boot mode MIPS state register has reverse polarity.
865 * So just or with setting bit 30.
866 * Make the MIPS in Reset state.
868 rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
869 uiResetValue |= (1<<30);
870 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
873 if (ps_adapter->chip_id >= T3LPB) {
874 uiResetValue = 0;
876 * WA for SYSConfig Issue.
877 * Read SYSCFG Twice to make it writable.
879 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
880 if (uiResetValue & (1<<4)) {
881 uiResetValue = 0;
882 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue)); /* 2nd read to make it writable. */
883 uiResetValue &= (~(1<<4));
884 wrmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
887 uiResetValue = 0;
888 wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
890 err_exit:
891 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
892 return retval;
895 int run_card_proc(struct bcm_mini_adapter *ps_adapter)
897 int status = STATUS_SUCCESS;
898 int bytes;
900 unsigned int value = 0;
902 bytes = rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value));
903 if (bytes < 0) {
904 status = bytes;
905 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
906 return status;
909 if (ps_adapter->bFlashBoot)
910 value &= (~(1<<30));
911 else
912 value |= (1<<30);
914 if (wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
915 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
916 return STATUS_FAILURE;
919 return status;
922 int InitCardAndDownloadFirmware(struct bcm_mini_adapter *ps_adapter)
924 int status;
925 unsigned int value = 0;
927 * Create the threads first and then download the
928 * Firm/DDR Settings..
930 status = create_worker_threads(ps_adapter);
931 if (status < 0)
932 return status;
934 status = bcm_parse_target_params(ps_adapter);
935 if (status)
936 return status;
938 if (ps_adapter->chip_id >= T3LPB) {
939 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
940 ps_adapter->syscfgBefFwDld = value;
942 if ((value & 0x60) == 0)
943 ps_adapter->bFlashBoot = TRUE;
946 reset_card_proc(ps_adapter);
948 /* Initializing the NVM. */
949 BcmInitNVM(ps_adapter);
950 status = ddr_init(ps_adapter);
951 if (status) {
952 pr_err(DRV_NAME "ddr_init Failed\n");
953 return status;
956 /* Download cfg file */
957 status = buffDnldVerify(ps_adapter,
958 (PUCHAR)ps_adapter->pstargetparams,
959 sizeof(struct bcm_target_params),
960 CONFIG_BEGIN_ADDR);
961 if (status) {
962 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
963 goto OUT;
966 if (register_networkdev(ps_adapter)) {
967 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
968 return -EIO;
971 if (FALSE == ps_adapter->AutoFirmDld) {
972 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoFirmDld Disabled in CFG File..\n");
973 /* If Auto f/w download is disable, register the control interface, */
974 /* register the control interface after the mailbox. */
975 if (register_control_device_interface(ps_adapter) < 0) {
976 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
977 return -EIO;
979 return STATUS_SUCCESS;
983 * Do the LED Settings here. It will be used by the Firmware Download
984 * Thread.
988 * 1. If the LED Settings fails, do not stop and do the Firmware download.
989 * 2. This init would happened only if the cfg file is present, else
990 * call from the ioctl context.
993 status = InitLedSettings(ps_adapter);
994 if (status) {
995 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_PRINTK, 0, 0, "INIT LED FAILED\n");
996 return status;
999 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1000 ps_adapter->DriverState = DRIVER_INIT;
1001 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1004 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1005 ps_adapter->DriverState = FW_DOWNLOAD;
1006 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1009 value = 0;
1010 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1011 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1013 if (ps_adapter->eNVMType == NVM_FLASH) {
1014 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
1015 if (status) {
1016 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Propagation of Cal param failed ..");
1017 goto OUT;
1021 /* Download Firmare */
1022 status = BcmFileDownload(ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR);
1023 if (status != 0) {
1024 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Firmware File is present...\n");
1025 goto OUT;
1028 status = run_card_proc(ps_adapter);
1029 if (status) {
1030 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "run_card_proc Failed\n");
1031 goto OUT;
1034 ps_adapter->fw_download_done = TRUE;
1035 mdelay(10);
1037 OUT:
1038 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1039 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1040 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1043 return status;
1046 static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter)
1048 struct file *flp = NULL;
1049 char *buff;
1050 int len = 0;
1052 buff = kmalloc(BUFFER_1K, GFP_KERNEL);
1053 if (!buff)
1054 return -ENOMEM;
1056 Adapter->pstargetparams = kmalloc(sizeof(struct bcm_target_params), GFP_KERNEL);
1057 if (Adapter->pstargetparams == NULL) {
1058 kfree(buff);
1059 return -ENOMEM;
1062 flp = open_firmware_file(Adapter, CFG_FILE);
1063 if (!flp) {
1064 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE\n", CFG_FILE);
1065 kfree(buff);
1066 kfree(Adapter->pstargetparams);
1067 Adapter->pstargetparams = NULL;
1068 return -ENOENT;
1070 len = kernel_read(flp, 0, buff, BUFFER_1K);
1071 filp_close(flp, NULL);
1073 if (len != sizeof(struct bcm_target_params)) {
1074 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n");
1075 kfree(buff);
1076 kfree(Adapter->pstargetparams);
1077 Adapter->pstargetparams = NULL;
1078 return -ENOENT;
1081 /* Check for autolink in config params */
1083 * Values in Adapter->pstargetparams are in network byte order
1085 memcpy(Adapter->pstargetparams, buff, sizeof(struct bcm_target_params));
1086 kfree(buff);
1087 beceem_parse_target_struct(Adapter);
1088 return STATUS_SUCCESS;
1091 void beceem_parse_target_struct(struct bcm_mini_adapter *Adapter)
1093 unsigned int uiHostDrvrCfg6 = 0, uiEEPROMFlag = 0;
1095 if (ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE) {
1096 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
1097 Adapter->AutoSyncup = FALSE;
1098 } else {
1099 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
1100 Adapter->AutoSyncup = TRUE;
1103 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE) {
1104 pr_info(DRV_NAME ": Enabling autolink up");
1105 Adapter->AutoLinkUp = TRUE;
1106 } else {
1107 pr_info(DRV_NAME ": Disabling autolink up");
1108 Adapter->AutoLinkUp = FALSE;
1110 /* Setting the DDR Setting.. */
1111 Adapter->DDRSetting = (ntohl(Adapter->pstargetparams->HostDrvrConfig6) >> 8)&0x0F;
1112 Adapter->ulPowerSaveMode = (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
1113 pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1114 pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
1115 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD) {
1116 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1117 Adapter->AutoFirmDld = TRUE;
1118 } else {
1119 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1120 Adapter->AutoFirmDld = FALSE;
1122 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1123 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
1124 pr_info(DRV_NAME ": MIPSConfig : 0x%X\n", Adapter->bMipsConfig);
1125 /* used for backward compatibility. */
1126 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
1127 Adapter->PmuMode = (uiHostDrvrCfg6 >> 24) & 0x03;
1128 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
1130 if ((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT) & (0x01)) {
1131 Adapter->bDoSuspend = TRUE;
1132 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1135 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
1136 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n", uiEEPROMFlag);
1137 Adapter->eNVMType = (enum bcm_nvm_type)((uiEEPROMFlag>>4)&0x3);
1138 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
1139 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
1140 Adapter->bSectorSizeOverride = (bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
1142 if (ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x01)
1143 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
1145 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1146 doPowerAutoCorrection(Adapter);
1149 static void doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter)
1151 unsigned int reporting_mode;
1153 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x02;
1154 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1156 if (reporting_mode == TRUE) {
1157 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "can't do suspen/resume as reporting mode is enable");
1158 psAdapter->bDoSuspend = FALSE;
1161 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB)) {
1162 /* If reporting mode is enable, switch PMU to PMC */
1164 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
1165 psAdapter->bDoSuspend = FALSE;
1168 /* clearing space bit[15..12] */
1169 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl((0xF << 12)));
1170 /* placing the power save mode option */
1171 psAdapter->pstargetparams->HostDrvrConfig6 |= htonl((psAdapter->ulPowerSaveMode << 12));
1172 } else if (psAdapter->bIsAutoCorrectEnabled == FALSE) {
1173 /* remove the autocorrect disable bit set before dumping. */
1174 psAdapter->ulPowerSaveMode &= ~(1 << 3);
1175 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl(1 << 15));
1176 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Using Forced User Choice: %lx\n", psAdapter->ulPowerSaveMode);
1180 static void convertEndian(unsigned char rwFlag, unsigned int *puiBuffer, unsigned int uiByteCount)
1182 unsigned int uiIndex = 0;
1184 if (RWM_WRITE == rwFlag) {
1185 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(unsigned int)); uiIndex++)
1186 puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
1187 } else {
1188 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(unsigned int)); uiIndex++)
1189 puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
1193 int rdm(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
1195 return Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
1196 uiAddress, pucBuff, sSize);
1199 int wrm(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
1201 int iRetVal;
1203 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
1204 uiAddress, pucBuff, sSize);
1205 return iRetVal;
1208 int wrmalt(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
1210 convertEndian(RWM_WRITE, pucBuff, size);
1211 return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1214 int rdmalt(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
1216 int uiRetVal = 0;
1218 uiRetVal = rdm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1219 convertEndian(RWM_READ, (unsigned int *)pucBuff, size);
1221 return uiRetVal;
1224 int wrmWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
1226 int status = STATUS_SUCCESS;
1227 down(&Adapter->rdmwrmsync);
1229 if ((Adapter->IdleMode == TRUE) ||
1230 (Adapter->bShutStatus == TRUE) ||
1231 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1233 status = -EACCES;
1234 goto exit;
1237 status = wrm(Adapter, uiAddress, pucBuff, sSize);
1238 exit:
1239 up(&Adapter->rdmwrmsync);
1240 return status;
1243 int wrmaltWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
1245 int iRetVal = STATUS_SUCCESS;
1247 down(&Adapter->rdmwrmsync);
1249 if ((Adapter->IdleMode == TRUE) ||
1250 (Adapter->bShutStatus == TRUE) ||
1251 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1253 iRetVal = -EACCES;
1254 goto exit;
1257 iRetVal = wrmalt(Adapter, uiAddress, pucBuff, size);
1258 exit:
1259 up(&Adapter->rdmwrmsync);
1260 return iRetVal;
1263 int rdmaltWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
1265 int uiRetVal = STATUS_SUCCESS;
1267 down(&Adapter->rdmwrmsync);
1268 if ((Adapter->IdleMode == TRUE) ||
1269 (Adapter->bShutStatus == TRUE) ||
1270 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1272 uiRetVal = -EACCES;
1273 goto exit;
1276 uiRetVal = rdmalt(Adapter, uiAddress, pucBuff, size);
1277 exit:
1278 up(&Adapter->rdmwrmsync);
1279 return uiRetVal;
1282 static void HandleShutDownModeWakeup(struct bcm_mini_adapter *Adapter)
1284 int clear_abort_pattern = 0, Status = 0;
1285 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1286 /* target has woken up From Shut Down */
1287 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Clearing Shut Down Software abort pattern\n");
1288 Status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC, (unsigned int *)&clear_abort_pattern, sizeof(clear_abort_pattern));
1289 if (Status) {
1290 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
1291 return;
1294 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) {
1295 msleep(100);
1296 InterfaceHandleShutdownModeWakeup(Adapter);
1297 msleep(100);
1300 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1301 Adapter->DriverState = NO_NETWORK_ENTRY;
1302 wake_up(&Adapter->LEDInfo.notify_led_event);
1305 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
1306 Adapter->bShutStatus = FALSE;
1307 wake_up(&Adapter->lowpower_mode_wait_queue);
1308 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1311 static void SendShutModeResponse(struct bcm_mini_adapter *Adapter)
1313 struct bcm_link_request stShutdownResponse;
1314 unsigned int NVMAccess = 0, lowPwrAbortMsg = 0;
1315 unsigned int Status = 0;
1317 memset(&stShutdownResponse, 0, sizeof(struct bcm_link_request));
1318 stShutdownResponse.Leader.Status = LINK_UP_CONTROL_REQ;
1319 stShutdownResponse.Leader.PLength = 8; /* 8 bytes; */
1320 stShutdownResponse.szData[0] = LINK_UP_ACK;
1321 stShutdownResponse.szData[1] = LINK_SHUTDOWN_REQ_FROM_FIRMWARE;
1323 /*********************************
1324 * down_trylock -
1325 * if [ semaphore is available ]
1326 * acquire semaphone and return value 0 ;
1327 * else
1328 * return non-zero value ;
1330 ***********************************/
1332 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1333 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
1335 if (NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) {
1336 if (!NVMAccess)
1337 up(&Adapter->NVMRdmWrmLock);
1339 if (!lowPwrAbortMsg)
1340 up(&Adapter->LowPowerModeSync);
1342 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Device Access is going on NACK the Shut Down MODE\n");
1343 stShutdownResponse.szData[2] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
1344 Adapter->bPreparingForLowPowerMode = FALSE;
1345 } else {
1346 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Sending SHUTDOWN MODE ACK\n");
1347 stShutdownResponse.szData[2] = SHUTDOWN_ACK_FROM_DRIVER; /* ShutDown ACK */
1349 /* Wait for the LED to TURN OFF before sending ACK response */
1350 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1351 int iRetVal = 0;
1353 /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1354 Adapter->DriverState = LOWPOWER_MODE_ENTER;
1355 wake_up(&Adapter->LEDInfo.notify_led_event);
1357 /* Wait for 1 SEC for LED to OFF */
1358 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
1360 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
1361 if (iRetVal <= 0) {
1362 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
1363 Adapter->DriverState = NO_NETWORK_ENTRY;
1364 wake_up(&Adapter->LEDInfo.notify_led_event);
1368 if (stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER) {
1369 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ACKING SHUTDOWN MODE !!!!!!!!!");
1370 down(&Adapter->rdmwrmsync);
1371 Adapter->bPreparingForLowPowerMode = TRUE;
1372 up(&Adapter->rdmwrmsync);
1373 /* Killing all URBS. */
1374 if (Adapter->bDoSuspend == TRUE)
1375 Bcm_kill_all_URBs((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
1376 } else {
1377 Adapter->bPreparingForLowPowerMode = FALSE;
1380 if (!NVMAccess)
1381 up(&Adapter->NVMRdmWrmLock);
1383 if (!lowPwrAbortMsg)
1384 up(&Adapter->LowPowerModeSync);
1387 Status = CopyBufferToControlPacket(Adapter, &stShutdownResponse);
1388 if ((Status != STATUS_SUCCESS)) {
1389 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "fail to send the Idle mode Request\n");
1390 Adapter->bPreparingForLowPowerMode = FALSE;
1391 StartInterruptUrb((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
1395 static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
1397 unsigned int uiResetValue = 0;
1399 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1401 if (*(pucBuffer+1) == COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW) {
1402 HandleShutDownModeWakeup(Adapter);
1403 } else if (*(pucBuffer+1) == LINK_SHUTDOWN_REQ_FROM_FIRMWARE) {
1404 /* Target wants to go to Shut Down Mode */
1405 /* InterfacePrepareForShutdown(Adapter); */
1406 if (Adapter->chip_id == BCS220_2 ||
1407 Adapter->chip_id == BCS220_2BC ||
1408 Adapter->chip_id == BCS250_BC ||
1409 Adapter->chip_id == BCS220_3) {
1411 rdmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1412 uiResetValue |= (1<<17);
1413 wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1416 SendShutModeResponse(Adapter);
1417 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ShutDownModeResponse:Notification received: Sending the response(Ack/Nack)\n");
1420 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1421 return;
1424 void ResetCounters(struct bcm_mini_adapter *Adapter)
1426 beceem_protocol_reset(Adapter);
1427 Adapter->CurrNumRecvDescs = 0;
1428 Adapter->PrevNumRecvDescs = 0;
1429 Adapter->LinkUpStatus = 0;
1430 Adapter->LinkStatus = 0;
1431 atomic_set(&Adapter->cntrlpktCnt, 0);
1432 atomic_set(&Adapter->TotalPacketCount, 0);
1433 Adapter->fw_download_done = FALSE;
1434 Adapter->LinkStatus = 0;
1435 Adapter->AutoLinkUp = FALSE;
1436 Adapter->IdleMode = FALSE;
1437 Adapter->bShutStatus = FALSE;
1440 struct bcm_classifier_rule *GetFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIP)
1442 unsigned int uiIndex = 0;
1443 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1444 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1445 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1446 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIP) &&
1447 !Adapter->astFragmentedPktClassifierTable[uiIndex].bOutOfOrderFragment)
1449 return Adapter->astFragmentedPktClassifierTable[uiIndex].pstMatchedClassifierEntry;
1451 return NULL;
1454 void AddFragIPClsEntry(struct bcm_mini_adapter *Adapter, struct bcm_fragmented_packet_info *psFragPktInfo)
1456 unsigned int uiIndex = 0;
1457 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1458 if (!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) {
1459 memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex], psFragPktInfo, sizeof(struct bcm_fragmented_packet_info));
1460 break;
1465 void DelFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIp)
1467 unsigned int uiIndex = 0;
1468 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1469 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1470 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1471 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIp))
1473 memset(&Adapter->astFragmentedPktClassifierTable[uiIndex], 0, sizeof(struct bcm_fragmented_packet_info));
1477 void update_per_cid_rx(struct bcm_mini_adapter *Adapter)
1479 unsigned int qindex = 0;
1481 if ((jiffies - Adapter->liDrainCalculated) < XSECONDS)
1482 return;
1484 for (qindex = 0; qindex < HiPriority; qindex++) {
1485 if (Adapter->PackInfo[qindex].ucDirection == 0) {
1486 Adapter->PackInfo[qindex].uiCurrentRxRate =
1487 (Adapter->PackInfo[qindex].uiCurrentRxRate +
1488 Adapter->PackInfo[qindex].uiThisPeriodRxBytes) / 2;
1490 Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
1491 } else {
1492 Adapter->PackInfo[qindex].uiCurrentDrainRate =
1493 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
1494 Adapter->PackInfo[qindex].uiThisPeriodSentBytes) / 2;
1495 Adapter->PackInfo[qindex].uiThisPeriodSentBytes = 0;
1498 Adapter->liDrainCalculated = jiffies;
1501 void update_per_sf_desc_cnts(struct bcm_mini_adapter *Adapter)
1503 int iIndex = 0;
1504 u32 uibuff[MAX_TARGET_DSX_BUFFERS];
1505 int bytes;
1507 if (!atomic_read(&Adapter->uiMBupdate))
1508 return;
1510 bytes = rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (unsigned int *)uibuff, sizeof(unsigned int) * MAX_TARGET_DSX_BUFFERS);
1511 if (bytes < 0) {
1512 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
1513 return;
1516 for (iIndex = 0; iIndex < HiPriority; iIndex++) {
1517 if (Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection) {
1518 if (Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
1519 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
1520 else
1521 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid VCID : %x\n", Adapter->PackInfo[iIndex].usVCID_Value);
1524 atomic_set(&Adapter->uiMBupdate, FALSE);
1527 void flush_queue(struct bcm_mini_adapter *Adapter, unsigned int iQIndex)
1529 struct sk_buff *PacketToDrop = NULL;
1530 struct net_device_stats *netstats = &Adapter->dev->stats;
1531 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1533 while (Adapter->PackInfo[iQIndex].FirstTxQueue && atomic_read(&Adapter->TotalPacketCount)) {
1534 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
1535 if (PacketToDrop && PacketToDrop->len) {
1536 netstats->tx_dropped++;
1537 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, Adapter->PackInfo[iQIndex].LastTxQueue);
1538 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1539 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1541 /* Adding dropped statistics */
1542 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1543 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
1544 dev_kfree_skb(PacketToDrop);
1545 atomic_dec(&Adapter->TotalPacketCount);
1548 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1551 static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter)
1553 int i;
1554 if (netif_msg_link(Adapter))
1555 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
1557 netif_carrier_off(Adapter->dev);
1558 netif_stop_queue(Adapter->dev);
1560 Adapter->IdleMode = FALSE;
1561 Adapter->LinkUpStatus = FALSE;
1562 ClearTargetDSXBuffer(Adapter, 0, TRUE);
1563 /* Delete All Classifier Rules */
1565 for (i = 0; i < HiPriority; i++)
1566 DeleteAllClassifiersForSF(Adapter, i);
1568 flush_all_queues(Adapter);
1570 if (Adapter->TimerActive == TRUE)
1571 Adapter->TimerActive = FALSE;
1573 memset(Adapter->astFragmentedPktClassifierTable, 0, sizeof(struct bcm_fragmented_packet_info) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
1575 for (i = 0; i < HiPriority; i++) {
1576 /* resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF. */
1577 /* It is same between MIBs and SF. */
1578 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable, 0, sizeof(struct bcm_mibs_parameters));