Staging: bcm: Add two products and remove an existing product.
[linux/fpc-iii.git] / drivers / staging / bcm / Misc.c
blobf13a9582a82f0007406f564a77d0ef444dbd0c91
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 UINT 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)flp->f_dentry->d_inode->i_size, loc);
189 do_gettimeofday(&tv);
191 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "download start %lx", ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)));
192 if (Adapter->bcm_file_download(Adapter->pvInterfaceAdapter, flp, loc)) {
193 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to download the firmware with error %x!!!", -EIO);
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 spinock, 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, PVOID ioBuffer)
221 struct bcm_leader *pLeader = NULL;
222 INT Status = 0;
223 unsigned char *ctrl_buff = NULL;
224 UINT 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 (TRUE == Adapter->bShutStatus) {
257 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "SYNC UP IN SHUTDOWN..Device WakeUp\n");
258 if (Adapter->bTriedToWakeUpFromlowPowerMode == FALSE) {
259 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Waking up for the First Time..\n");
260 Adapter->usIdleModePattern = ABORT_SHUTDOWN_MODE; /* change it to 1 for current support. */
261 Adapter->bWakeUpDevice = TRUE;
262 wake_up(&Adapter->process_rx_cntrlpkt);
263 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->bShutStatus, (5 * HZ));
265 if (Status == -ERESTARTSYS)
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 (TRUE == Adapter->IdleMode) {
279 /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle mode ... hence\n"); */
280 if (pLeader->Status == LINK_UP_CONTROL_REQ || pLeader->Status == 0x80 ||
281 pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ) {
283 if ((pLeader->Status == LINK_UP_CONTROL_REQ) && (pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD)) {
284 if ((pLinkReq->szData[1] == LINK_SYNC_DOWN_SUBTYPE)) {
285 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Link Down Sent in Idle Mode\n");
286 Adapter->usIdleModePattern = ABORT_IDLE_SYNCDOWN; /* LINK DOWN sent in Idle Mode */
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 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Control packet to be taken =%d and address is =%pincoming address is =%p and packet len=%x",
329 atomic_read(&Adapter->index_wr_txcntrlpkt), ctrl_buff, ioBuffer, pktlen);
330 if (ctrl_buff) {
331 if (pLeader) {
332 if ((pLeader->Status == 0x80) ||
333 (pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ)) {
335 * Restructure the DSX message to handle Multiple classifier Support
336 * Write the Service Flow param Structures directly to the target
337 * and embed the pointers in the DSX messages sent to target.
339 /* Lets store the current length of the control packet we are transmitting */
340 pucAddIndication = (PUCHAR)ioBuffer + LEADER_SIZE;
341 pktlen = pLeader->PLength;
342 Status = StoreCmControlResponseMessage(Adapter, pucAddIndication, &pktlen);
343 if (Status != 1) {
344 ClearTargetDSXBuffer(Adapter, ((stLocalSFAddIndicationAlt *)pucAddIndication)->u16TID, FALSE);
345 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, " Error Restoring The DSX Control Packet. Dsx Buffers on Target may not be Setup Properly ");
346 return STATUS_FAILURE;
349 * update the leader to use the new length
350 * The length of the control packet is length of message being sent + Leader length
352 pLeader->PLength = pktlen;
356 if (pktlen + LEADER_SIZE > MAX_CNTL_PKT_SIZE)
357 return -EINVAL;
359 memset(ctrl_buff, 0, pktlen+LEADER_SIZE);
360 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Copying the Control Packet Buffer with length=%d\n", pLeader->PLength);
361 *(struct bcm_leader *)ctrl_buff = *pLeader;
362 memcpy(ctrl_buff + LEADER_SIZE, ((PUCHAR)ioBuffer + LEADER_SIZE), pLeader->PLength);
363 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Enqueuing the Control Packet");
365 /* Update the statistics counters */
366 spin_lock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
367 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost += pLeader->PLength;
368 Adapter->PackInfo[HiPriority].uiCurrentPacketsOnHost++;
369 atomic_inc(&Adapter->TotalPacketCount);
370 spin_unlock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
371 Adapter->PackInfo[HiPriority].bValid = TRUE;
373 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "CurrBytesOnHost: %x bValid: %x",
374 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost,
375 Adapter->PackInfo[HiPriority].bValid);
376 Status = STATUS_SUCCESS;
377 /*Queue the packet for transmission */
378 atomic_inc(&Adapter->index_wr_txcntrlpkt);
379 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Calling transmit_packets");
380 atomic_set(&Adapter->TxPktAvail, 1);
381 wake_up(&Adapter->tx_packet_wait_queue);
382 } else {
383 Status = -ENOMEM;
384 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "mem allocation Failed");
386 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<====");
387 return Status;
390 /******************************************************************
391 * Function - LinkMessage()
393 * Description - This function builds the Sync-up and Link-up request
394 * packet messages depending on the device Link status.
396 * Parameters - Adapter: Pointer to the Adapter structure.
398 * Returns - None.
399 *******************************************************************/
400 VOID LinkMessage(struct bcm_mini_adapter *Adapter)
402 struct bcm_link_request *pstLinkRequest = NULL;
403 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>");
404 if (Adapter->LinkStatus == SYNC_UP_REQUEST && Adapter->AutoSyncup) {
405 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
406 if (!pstLinkRequest) {
407 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
408 return;
410 /* sync up request... */
411 Adapter->LinkStatus = WAIT_FOR_SYNC; /* current link status */
412 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For SyncUp...");
413 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
414 pstLinkRequest->szData[1] = LINK_SYNC_UP_SUBTYPE;
415 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
416 pstLinkRequest->Leader.PLength = sizeof(ULONG);
417 Adapter->bSyncUpRequestSent = TRUE;
419 } else if (Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp) {
420 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
421 if (!pstLinkRequest) {
422 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
423 return;
425 /* LINK_UP_REQUEST */
426 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For LinkUp...");
427 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
428 pstLinkRequest->szData[1] = LINK_NET_ENTRY;
429 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
430 pstLinkRequest->Leader.PLength = sizeof(ULONG);
432 if (pstLinkRequest) {
433 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
434 CopyBufferToControlPacket(Adapter, pstLinkRequest);
435 kfree(pstLinkRequest);
437 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
438 return;
441 /**********************************************************************
442 * Function - StatisticsResponse()
444 * Description - This function handles the Statistics response packet.
446 * Parameters - Adapter : Pointer to the Adapter structure.
447 * - pvBuffer: Starting address of Statistic response data.
449 * Returns - None.
450 ************************************************************************/
451 VOID StatisticsResponse(struct bcm_mini_adapter *Adapter, PVOID pvBuffer)
453 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>", __func__);
454 Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
455 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (UINT)Adapter->StatisticsPointer);
456 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====", __func__);
457 return;
460 /**********************************************************************
461 * Function - LinkControlResponseMessage()
463 * Description - This function handles the Link response packets.
465 * Parameters - Adapter : Pointer to the Adapter structure.
466 * - pucBuffer: Starting address of Link response data.
468 * Returns - None.
469 ***********************************************************************/
470 VOID LinkControlResponseMessage(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
472 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
474 if (*pucBuffer == LINK_UP_ACK) {
475 switch (*(pucBuffer+1)) {
476 case PHY_SYNC_ACHIVED: /* SYNCed UP */
477 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHY_SYNC_ACHIVED");
479 if (Adapter->LinkStatus == LINKUP_DONE)
480 beceem_protocol_reset(Adapter);
482 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
483 Adapter->LinkStatus = PHY_SYNC_ACHIVED;
485 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
486 Adapter->DriverState = NO_NETWORK_ENTRY;
487 wake_up(&Adapter->LEDInfo.notify_led_event);
490 LinkMessage(Adapter);
491 break;
493 case LINKUP_DONE:
494 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LINKUP_DONE");
495 Adapter->LinkStatus = LINKUP_DONE;
496 Adapter->bPHSEnabled = *(pucBuffer+3);
497 Adapter->bETHCSEnabled = *(pucBuffer+4) & ETH_CS_MASK;
498 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHS Support Status Received In LinkUp Ack : %x\n", Adapter->bPHSEnabled);
500 if ((FALSE == Adapter->bShutStatus) && (FALSE == Adapter->IdleMode)) {
501 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
502 Adapter->DriverState = NORMAL_OPERATION;
503 wake_up(&Adapter->LEDInfo.notify_led_event);
506 LinkMessage(Adapter);
507 break;
509 case WAIT_FOR_SYNC:
511 * Driver to ignore the DREG_RECEIVED
512 * WiMAX Application should handle this Message
514 /* Adapter->liTimeSinceLastNetEntry = 0; */
515 Adapter->LinkUpStatus = 0;
516 Adapter->LinkStatus = 0;
517 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
518 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
519 Adapter->IdleMode = FALSE;
520 beceem_protocol_reset(Adapter);
522 break;
523 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
524 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
526 HandleShutDownModeRequest(Adapter, pucBuffer);
528 break;
529 default:
530 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x", *(pucBuffer + 1));
531 break;
533 } else if (SET_MAC_ADDRESS_RESPONSE == *pucBuffer) {
534 PUCHAR puMacAddr = (pucBuffer + 1);
535 Adapter->LinkStatus = SYNC_UP_REQUEST;
536 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "MAC address response, sending SYNC_UP");
537 LinkMessage(Adapter);
538 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
540 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====", __func__);
541 return;
544 void SendIdleModeResponse(struct bcm_mini_adapter *Adapter)
546 INT status = 0, NVMAccess = 0, lowPwrAbortMsg = 0;
547 struct timeval tv;
548 struct bcm_link_request stIdleResponse = {{0} };
549 memset(&tv, 0, sizeof(tv));
550 stIdleResponse.Leader.Status = IDLE_MESSAGE;
551 stIdleResponse.Leader.PLength = IDLE_MODE_PAYLOAD_LENGTH;
552 stIdleResponse.szData[0] = GO_TO_IDLE_MODE_PAYLOAD;
553 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, " ============>");
555 /*********************************
556 *down_trylock -
557 * if [ semaphore is available ]
558 * acquire semaphone and return value 0 ;
559 * else
560 * return non-zero value ;
562 ***********************************/
564 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
565 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
568 if ((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
569 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)) {
571 if (!NVMAccess)
572 up(&Adapter->NVMRdmWrmLock);
574 if (!lowPwrAbortMsg)
575 up(&Adapter->LowPowerModeSync);
577 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
578 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "HOST IS NACKING Idle mode To F/W!!!!!!!!");
579 Adapter->bPreparingForLowPowerMode = FALSE;
580 } else {
581 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; /* 2; Idle ACK */
582 Adapter->StatisticsPointer = 0;
584 /* Wait for the LED to TURN OFF before sending ACK response */
585 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
586 INT iRetVal = 0;
588 /* Wake the LED Thread with IDLEMODE_ENTER State */
589 Adapter->DriverState = LOWPOWER_MODE_ENTER;
590 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LED Thread is Running..Hence Setting LED Event as IDLEMODE_ENTER jiffies:%ld", jiffies);
591 wake_up(&Adapter->LEDInfo.notify_led_event);
593 /* Wait for 1 SEC for LED to OFF */
594 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
596 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
597 if (iRetVal <= 0) {
598 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
599 Adapter->DriverState = NORMAL_OPERATION;
600 wake_up(&Adapter->LEDInfo.notify_led_event);
601 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "NACKING Idle mode as time out happen from LED side!!!!!!!!");
605 if (stIdleResponse.szData[1] == TARGET_CAN_GO_TO_IDLE_MODE) {
606 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "ACKING IDLE MODE !!!!!!!!!");
607 down(&Adapter->rdmwrmsync);
608 Adapter->bPreparingForLowPowerMode = TRUE;
609 up(&Adapter->rdmwrmsync);
610 /* Killing all URBS. */
611 if (Adapter->bDoSuspend == TRUE)
612 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
613 } else {
614 Adapter->bPreparingForLowPowerMode = FALSE;
617 if (!NVMAccess)
618 up(&Adapter->NVMRdmWrmLock);
620 if (!lowPwrAbortMsg)
621 up(&Adapter->LowPowerModeSync);
624 status = CopyBufferToControlPacket(Adapter, &stIdleResponse);
625 if ((status != STATUS_SUCCESS)) {
626 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "fail to send the Idle mode Request\n");
627 Adapter->bPreparingForLowPowerMode = FALSE;
628 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
630 do_gettimeofday(&tv);
631 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "IdleMode Msg submitter to Q :%ld ms", tv.tv_sec * 1000 + tv.tv_usec / 1000);
634 /******************************************************************
635 * Function - DumpPackInfo()
637 * Description - This function dumps the all Queue(PackInfo[]) details.
639 * Parameters - Adapter: Pointer to the Adapter structure.
641 * Returns - None.
642 *******************************************************************/
643 VOID DumpPackInfo(struct bcm_mini_adapter *Adapter)
645 UINT uiLoopIndex = 0;
646 UINT uiIndex = 0;
647 UINT uiClsfrIndex = 0;
648 struct bcm_classifier_rule *pstClassifierEntry = NULL;
650 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
651 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "*********** Showing Details Of Queue %d***** ******", uiLoopIndex);
652 if (FALSE == Adapter->PackInfo[uiLoopIndex].bValid) {
653 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid is FALSE for %X index\n", uiLoopIndex);
654 continue;
657 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " Dumping SF Rule Entry For SFID %lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
658 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " ucDirection %X\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
660 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
661 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv6 Service Flow\n");
662 else
663 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv4 Service Flow\n");
665 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SF Traffic Priority %X\n", Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
667 for (uiClsfrIndex = 0; uiClsfrIndex < MAX_CLASSIFIERS; uiClsfrIndex++) {
668 pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
669 if (!pstClassifierEntry->bUsed)
670 continue;
672 if (pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
673 continue;
675 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X Classifier Rule ID : %X\n", uiClsfrIndex, pstClassifierEntry->uiClassifierRuleIndex);
676 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X usVCID_Value : %X\n", uiClsfrIndex, pstClassifierEntry->usVCID_Value);
677 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bProtocolValid : %X\n", uiClsfrIndex, pstClassifierEntry->bProtocolValid);
678 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bTOSValid : %X\n", uiClsfrIndex, pstClassifierEntry->bTOSValid);
679 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bDestIpValid : %X\n", uiClsfrIndex, pstClassifierEntry->bDestIpValid);
680 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bSrcIpValid : %X\n", uiClsfrIndex, pstClassifierEntry->bSrcIpValid);
682 for (uiIndex = 0; uiIndex < MAX_PORT_RANGE; uiIndex++) {
683 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeLo:%X\n", pstClassifierEntry->usSrcPortRangeLo[uiIndex]);
684 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeHi:%X\n", pstClassifierEntry->usSrcPortRangeHi[uiIndex]);
685 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeLo:%X\n", pstClassifierEntry->usDestPortRangeLo[uiIndex]);
686 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeHi:%X\n", pstClassifierEntry->usDestPortRangeHi[uiIndex]);
689 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPSourceAddressLength : 0x%x\n", pstClassifierEntry->ucIPSourceAddressLength);
690 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPDestinationAddressLength : 0x%x\n", pstClassifierEntry->ucIPDestinationAddressLength);
691 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPSourceAddressLength; uiIndex++) {
692 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
693 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpAddr :\n");
694 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Addr);
695 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpMask :\n");
696 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Mask);
697 } else {
698 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpAddr:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Addr[uiIndex]);
699 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpMask:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Mask[uiIndex]);
703 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPDestinationAddressLength; uiIndex++) {
704 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
705 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpAddr :\n");
706 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Addr);
707 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpMask :\n");
708 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Mask);
709 } else {
710 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpAddr:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Addr[uiIndex]);
711 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpMask:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Mask[uiIndex]);
714 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucProtocol:0x%X\n", pstClassifierEntry->ucProtocol[0]);
715 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tu8ClassifierRulePriority:%X\n", pstClassifierEntry->u8ClassifierRulePriority);
717 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ulSFID:%lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
718 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "usVCID_Value:%X\n", Adapter->PackInfo[uiLoopIndex].usVCID_Value);
719 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "PhsEnabled: 0x%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
720 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThreshold:%X\n", Adapter->PackInfo[uiLoopIndex].uiThreshold);
722 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid:%X\n", Adapter->PackInfo[uiLoopIndex].bValid);
723 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bActive:%X\n", Adapter->PackInfo[uiLoopIndex].bActive);
724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActivateReqSent: %x", Adapter->PackInfo[uiLoopIndex].bActivateRequestSent);
725 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "u8QueueType:%X\n", Adapter->PackInfo[uiLoopIndex].u8QueueType);
726 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxBucketSize:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize);
727 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPerSFTxResourceCount:%X\n", atomic_read(&Adapter->PackInfo[uiLoopIndex].uiPerSFTxResourceCount));
728 /* DumpDebug(DUMP_INFO,("bCSSupport:%X\n",Adapter->PackInfo[uiLoopIndex].bCSSupport)); */
729 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CurrQueueDepthOnTarget: %x\n", Adapter->PackInfo[uiLoopIndex].uiCurrentQueueDepthOnTarget);
730 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentBytesOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentBytesOnHost);
731 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentPacketsOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentPacketsOnHost);
732 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountBytes);
733 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountPackets);
734 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentBytes);
735 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentPackets);
736 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentDrainRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentDrainRate);
737 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThisPeriodSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiThisPeriodSentBytes);
738 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liDrainCalculated:%llX\n", Adapter->PackInfo[uiLoopIndex].liDrainCalculated);
739 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentTokenCount:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentTokenCount);
740 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liLastUpdateTokenAt:%llX\n", Adapter->PackInfo[uiLoopIndex].liLastUpdateTokenAt);
741 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxAllowedRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate);
742 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPendedLast:%X\n", Adapter->PackInfo[uiLoopIndex].uiPendedLast);
743 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "NumOfPacketsSent:%X\n", Adapter->PackInfo[uiLoopIndex].NumOfPacketsSent);
744 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Direction: %x\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
745 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CID: %x\n", Adapter->PackInfo[uiLoopIndex].usCID);
746 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ProtocolValid: %x\n", Adapter->PackInfo[uiLoopIndex].bProtocolValid);
747 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "TOSValid: %x\n", Adapter->PackInfo[uiLoopIndex].bTOSValid);
748 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "DestIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bDestIpValid);
749 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SrcIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bSrcIpValid);
750 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActiveSet: %x\n", Adapter->PackInfo[uiLoopIndex].bActiveSet);
751 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AdmittedSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAdmittedSet);
752 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AuthzSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAuthorizedSet);
753 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ClassifyPrority: %x\n", Adapter->PackInfo[uiLoopIndex].bClassifierPriority);
754 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxLatency: %x\n", Adapter->PackInfo[uiLoopIndex].uiMaxLatency);
755 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO,
756 DBG_LVL_ALL, "ServiceClassName: %*ph\n",
757 4, Adapter->PackInfo[uiLoopIndex].
758 ucServiceClassName);
759 /* BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bHeaderSuppressionEnabled :%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
760 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalTxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalTxBytes);
761 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalRxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalRxBytes);
762 * DumpDebug(DUMP_INFO,(" uiRanOutOfResCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiRanOutOfResCount));
766 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
767 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aRxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aRxPktSizeHist[uiLoopIndex]);
769 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
770 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aTxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aTxPktSizeHist[uiLoopIndex]);
772 return;
775 int reset_card_proc(struct bcm_mini_adapter *ps_adapter)
777 int retval = STATUS_SUCCESS;
778 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
779 PS_INTERFACE_ADAPTER psIntfAdapter = NULL;
780 unsigned int value = 0, uiResetValue = 0;
781 int bytes;
783 psIntfAdapter = ((PS_INTERFACE_ADAPTER)(ps_adapter->pvInterfaceAdapter));
784 ps_adapter->bDDRInitDone = FALSE;
786 if (ps_adapter->chip_id >= T3LPB) {
787 /* SYS_CFG register is write protected hence for modifying this reg value, it should be read twice before */
788 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
789 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
791 /* making bit[6...5] same as was before f/w download. this setting force the h/w to */
792 /* re-populated the SP RAM area with the string descriptor. */
793 value = value | (ps_adapter->syscfgBefFwDld & 0x00000060);
794 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
797 /* killing all submitted URBs. */
798 psIntfAdapter->psAdapter->StopAllXaction = TRUE;
799 Bcm_kill_all_URBs(psIntfAdapter);
800 /* Reset the UMA-B Device */
801 if (ps_adapter->chip_id >= T3LPB) {
802 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Resetting UMA-B\n");
803 retval = usb_reset_device(psIntfAdapter->udev);
804 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
806 if (retval != STATUS_SUCCESS) {
807 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
808 goto err_exit;
811 if (ps_adapter->chip_id == BCS220_2 ||
812 ps_adapter->chip_id == BCS220_2BC ||
813 ps_adapter->chip_id == BCS250_BC ||
814 ps_adapter->chip_id == BCS220_3) {
816 bytes = rdmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
817 if (bytes < 0) {
818 retval = bytes;
819 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
820 goto err_exit;
822 /* setting 0th bit */
823 value |= (1<<0);
824 retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
825 if (retval < 0) {
826 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
827 goto err_exit;
830 } else {
831 bytes = rdmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
832 if (bytes < 0) {
833 retval = bytes;
834 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
835 goto err_exit;
837 value &= (~(1<<16));
838 retval = wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
839 if (retval < 0) {
840 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
841 goto err_exit;
844 /* Toggling the GPIO 8, 9 */
845 value = 0;
846 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
847 if (retval < 0) {
848 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
849 goto err_exit;
851 value = 0x300;
852 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value));
853 if (retval < 0) {
854 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
855 goto err_exit;
857 mdelay(50);
860 /* ps_adapter->downloadDDR = false; */
861 if (ps_adapter->bFlashBoot) {
862 /* In flash boot mode MIPS state register has reverse polarity.
863 * So just or with setting bit 30.
864 * Make the MIPS in Reset state.
866 rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
867 uiResetValue |= (1<<30);
868 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
871 if (ps_adapter->chip_id >= T3LPB) {
872 uiResetValue = 0;
874 * WA for SYSConfig Issue.
875 * Read SYSCFG Twice to make it writable.
877 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
878 if (uiResetValue & (1<<4)) {
879 uiResetValue = 0;
880 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue)); /* 2nd read to make it writable. */
881 uiResetValue &= (~(1<<4));
882 wrmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
885 uiResetValue = 0;
886 wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
888 err_exit:
889 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
890 return retval;
893 int run_card_proc(struct bcm_mini_adapter *ps_adapter)
895 int status = STATUS_SUCCESS;
896 int bytes;
898 unsigned int value = 0;
900 bytes = rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value));
901 if (bytes < 0) {
902 status = bytes;
903 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
904 return status;
907 if (ps_adapter->bFlashBoot)
908 value &= (~(1<<30));
909 else
910 value |= (1<<30);
912 if (wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
913 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
914 return STATUS_FAILURE;
917 return status;
920 int InitCardAndDownloadFirmware(struct bcm_mini_adapter *ps_adapter)
922 int status;
923 UINT value = 0;
925 * Create the threads first and then download the
926 * Firm/DDR Settings..
928 status = create_worker_threads(ps_adapter);
929 if (status < 0)
930 return status;
932 status = bcm_parse_target_params(ps_adapter);
933 if (status)
934 return status;
936 if (ps_adapter->chip_id >= T3LPB) {
937 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
938 ps_adapter->syscfgBefFwDld = value;
940 if ((value & 0x60) == 0)
941 ps_adapter->bFlashBoot = TRUE;
944 reset_card_proc(ps_adapter);
946 /* Initializing the NVM. */
947 BcmInitNVM(ps_adapter);
948 status = ddr_init(ps_adapter);
949 if (status) {
950 pr_err(DRV_NAME "ddr_init Failed\n");
951 return status;
954 /* Download cfg file */
955 status = buffDnldVerify(ps_adapter,
956 (PUCHAR)ps_adapter->pstargetparams,
957 sizeof(STARGETPARAMS),
958 CONFIG_BEGIN_ADDR);
959 if (status) {
960 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
961 goto OUT;
964 if (register_networkdev(ps_adapter)) {
965 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
966 return -EIO;
969 if (FALSE == ps_adapter->AutoFirmDld) {
970 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoFirmDld Disabled in CFG File..\n");
971 /* If Auto f/w download is disable, register the control interface, */
972 /* register the control interface after the mailbox. */
973 if (register_control_device_interface(ps_adapter) < 0) {
974 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
975 return -EIO;
977 return STATUS_SUCCESS;
981 * Do the LED Settings here. It will be used by the Firmware Download
982 * Thread.
986 * 1. If the LED Settings fails, do not stop and do the Firmware download.
987 * 2. This init would happened only if the cfg file is present, else
988 * call from the ioctl context.
991 status = InitLedSettings(ps_adapter);
992 if (status) {
993 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_PRINTK, 0, 0, "INIT LED FAILED\n");
994 return status;
997 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
998 ps_adapter->DriverState = DRIVER_INIT;
999 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1002 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1003 ps_adapter->DriverState = FW_DOWNLOAD;
1004 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1007 value = 0;
1008 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1009 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1011 if (ps_adapter->eNVMType == NVM_FLASH) {
1012 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
1013 if (status) {
1014 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Propagation of Cal param failed ..");
1015 goto OUT;
1019 /* Download Firmare */
1020 status = BcmFileDownload(ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR);
1021 if (status != 0) {
1022 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Firmware File is present...\n");
1023 goto OUT;
1026 status = run_card_proc(ps_adapter);
1027 if (status) {
1028 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "run_card_proc Failed\n");
1029 goto OUT;
1032 ps_adapter->fw_download_done = TRUE;
1033 mdelay(10);
1035 OUT:
1036 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1037 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1038 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1041 return status;
1044 static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter)
1046 struct file *flp = NULL;
1047 char *buff;
1048 int len = 0;
1050 buff = kmalloc(BUFFER_1K, GFP_KERNEL);
1051 if (!buff)
1052 return -ENOMEM;
1054 Adapter->pstargetparams = kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL);
1055 if (Adapter->pstargetparams == NULL) {
1056 kfree(buff);
1057 return -ENOMEM;
1060 flp = open_firmware_file(Adapter, CFG_FILE);
1061 if (!flp) {
1062 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE\n", CFG_FILE);
1063 kfree(buff);
1064 kfree(Adapter->pstargetparams);
1065 Adapter->pstargetparams = NULL;
1066 return -ENOENT;
1068 len = kernel_read(flp, 0, buff, BUFFER_1K);
1069 filp_close(flp, NULL);
1071 if (len != sizeof(STARGETPARAMS)) {
1072 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n");
1073 kfree(buff);
1074 kfree(Adapter->pstargetparams);
1075 Adapter->pstargetparams = NULL;
1076 return -ENOENT;
1079 /* Check for autolink in config params */
1081 * Values in Adapter->pstargetparams are in network byte order
1083 memcpy(Adapter->pstargetparams, buff, sizeof(STARGETPARAMS));
1084 kfree(buff);
1085 beceem_parse_target_struct(Adapter);
1086 return STATUS_SUCCESS;
1089 void beceem_parse_target_struct(struct bcm_mini_adapter *Adapter)
1091 UINT uiHostDrvrCfg6 = 0, uiEEPROMFlag = 0;
1093 if (ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE) {
1094 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
1095 Adapter->AutoSyncup = FALSE;
1096 } else {
1097 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
1098 Adapter->AutoSyncup = TRUE;
1101 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE) {
1102 pr_info(DRV_NAME ": Enabling autolink up");
1103 Adapter->AutoLinkUp = TRUE;
1104 } else {
1105 pr_info(DRV_NAME ": Disabling autolink up");
1106 Adapter->AutoLinkUp = FALSE;
1108 /* Setting the DDR Setting.. */
1109 Adapter->DDRSetting = (ntohl(Adapter->pstargetparams->HostDrvrConfig6) >> 8)&0x0F;
1110 Adapter->ulPowerSaveMode = (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
1111 pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1112 pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
1113 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD) {
1114 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1115 Adapter->AutoFirmDld = TRUE;
1116 } else {
1117 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1118 Adapter->AutoFirmDld = FALSE;
1120 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1121 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
1122 pr_info(DRV_NAME ": MIPSConfig : 0x%X\n", Adapter->bMipsConfig);
1123 /* used for backward compatibility. */
1124 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
1125 Adapter->PmuMode = (uiHostDrvrCfg6 >> 24) & 0x03;
1126 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
1128 if ((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT) & (0x01)) {
1129 Adapter->bDoSuspend = TRUE;
1130 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1133 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
1134 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n", uiEEPROMFlag);
1135 Adapter->eNVMType = (NVM_TYPE)((uiEEPROMFlag>>4)&0x3);
1136 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
1137 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
1138 Adapter->bSectorSizeOverride = (bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
1140 if (ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x01)
1141 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
1143 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1144 doPowerAutoCorrection(Adapter);
1147 static VOID doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter)
1149 UINT reporting_mode;
1151 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x02;
1152 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1154 if (reporting_mode == TRUE) {
1155 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "can't do suspen/resume as reporting mode is enable");
1156 psAdapter->bDoSuspend = FALSE;
1159 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB)) {
1160 /* If reporting mode is enable, switch PMU to PMC */
1162 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
1163 psAdapter->bDoSuspend = FALSE;
1166 /* clearing space bit[15..12] */
1167 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl((0xF << 12)));
1168 /* placing the power save mode option */
1169 psAdapter->pstargetparams->HostDrvrConfig6 |= htonl((psAdapter->ulPowerSaveMode << 12));
1170 } else if (psAdapter->bIsAutoCorrectEnabled == FALSE) {
1171 /* remove the autocorrect disable bit set before dumping. */
1172 psAdapter->ulPowerSaveMode &= ~(1 << 3);
1173 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl(1 << 15));
1174 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Using Forced User Choice: %lx\n", psAdapter->ulPowerSaveMode);
1178 static void convertEndian(B_UINT8 rwFlag, PUINT puiBuffer, UINT uiByteCount)
1180 UINT uiIndex = 0;
1182 if (RWM_WRITE == rwFlag) {
1183 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++)
1184 puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
1185 } else {
1186 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++)
1187 puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
1191 int rdm(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1193 return Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
1194 uiAddress, pucBuff, sSize);
1197 int wrm(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1199 int iRetVal;
1201 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
1202 uiAddress, pucBuff, sSize);
1203 return iRetVal;
1206 int wrmalt(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1208 convertEndian(RWM_WRITE, pucBuff, size);
1209 return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1212 int rdmalt(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1214 INT uiRetVal = 0;
1216 uiRetVal = rdm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1217 convertEndian(RWM_READ, (PUINT)pucBuff, size);
1219 return uiRetVal;
1222 int wrmWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1224 INT status = STATUS_SUCCESS;
1225 down(&Adapter->rdmwrmsync);
1227 if ((Adapter->IdleMode == TRUE) ||
1228 (Adapter->bShutStatus == TRUE) ||
1229 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1231 status = -EACCES;
1232 goto exit;
1235 status = wrm(Adapter, uiAddress, pucBuff, sSize);
1236 exit:
1237 up(&Adapter->rdmwrmsync);
1238 return status;
1241 int wrmaltWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1243 int iRetVal = STATUS_SUCCESS;
1245 down(&Adapter->rdmwrmsync);
1247 if ((Adapter->IdleMode == TRUE) ||
1248 (Adapter->bShutStatus == TRUE) ||
1249 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1251 iRetVal = -EACCES;
1252 goto exit;
1255 iRetVal = wrmalt(Adapter, uiAddress, pucBuff, size);
1256 exit:
1257 up(&Adapter->rdmwrmsync);
1258 return iRetVal;
1261 int rdmaltWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1263 INT uiRetVal = STATUS_SUCCESS;
1265 down(&Adapter->rdmwrmsync);
1266 if ((Adapter->IdleMode == TRUE) ||
1267 (Adapter->bShutStatus == TRUE) ||
1268 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1270 uiRetVal = -EACCES;
1271 goto exit;
1274 uiRetVal = rdmalt(Adapter, uiAddress, pucBuff, size);
1275 exit:
1276 up(&Adapter->rdmwrmsync);
1277 return uiRetVal;
1280 static VOID HandleShutDownModeWakeup(struct bcm_mini_adapter *Adapter)
1282 int clear_abort_pattern = 0, Status = 0;
1283 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1284 /* target has woken up From Shut Down */
1285 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Clearing Shut Down Software abort pattern\n");
1286 Status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC, (PUINT)&clear_abort_pattern, sizeof(clear_abort_pattern));
1287 if (Status) {
1288 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
1289 return;
1292 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) {
1293 msleep(100);
1294 InterfaceHandleShutdownModeWakeup(Adapter);
1295 msleep(100);
1298 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1299 Adapter->DriverState = NO_NETWORK_ENTRY;
1300 wake_up(&Adapter->LEDInfo.notify_led_event);
1303 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
1304 Adapter->bShutStatus = FALSE;
1305 wake_up(&Adapter->lowpower_mode_wait_queue);
1306 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1309 static VOID SendShutModeResponse(struct bcm_mini_adapter *Adapter)
1311 struct bcm_link_request stShutdownResponse;
1312 UINT NVMAccess = 0, lowPwrAbortMsg = 0;
1313 UINT Status = 0;
1315 memset(&stShutdownResponse, 0, sizeof(struct bcm_link_request));
1316 stShutdownResponse.Leader.Status = LINK_UP_CONTROL_REQ;
1317 stShutdownResponse.Leader.PLength = 8; /* 8 bytes; */
1318 stShutdownResponse.szData[0] = LINK_UP_ACK;
1319 stShutdownResponse.szData[1] = LINK_SHUTDOWN_REQ_FROM_FIRMWARE;
1321 /*********************************
1322 * down_trylock -
1323 * if [ semaphore is available ]
1324 * acquire semaphone and return value 0 ;
1325 * else
1326 * return non-zero value ;
1328 ***********************************/
1330 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1331 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
1333 if (NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) {
1334 if (!NVMAccess)
1335 up(&Adapter->NVMRdmWrmLock);
1337 if (!lowPwrAbortMsg)
1338 up(&Adapter->LowPowerModeSync);
1340 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Device Access is going on NACK the Shut Down MODE\n");
1341 stShutdownResponse.szData[2] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
1342 Adapter->bPreparingForLowPowerMode = FALSE;
1343 } else {
1344 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Sending SHUTDOWN MODE ACK\n");
1345 stShutdownResponse.szData[2] = SHUTDOWN_ACK_FROM_DRIVER; /* ShutDown ACK */
1347 /* Wait for the LED to TURN OFF before sending ACK response */
1348 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1349 INT iRetVal = 0;
1351 /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1352 Adapter->DriverState = LOWPOWER_MODE_ENTER;
1353 wake_up(&Adapter->LEDInfo.notify_led_event);
1355 /* Wait for 1 SEC for LED to OFF */
1356 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
1358 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
1359 if (iRetVal <= 0) {
1360 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
1361 Adapter->DriverState = NO_NETWORK_ENTRY;
1362 wake_up(&Adapter->LEDInfo.notify_led_event);
1366 if (stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER) {
1367 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ACKING SHUTDOWN MODE !!!!!!!!!");
1368 down(&Adapter->rdmwrmsync);
1369 Adapter->bPreparingForLowPowerMode = TRUE;
1370 up(&Adapter->rdmwrmsync);
1371 /* Killing all URBS. */
1372 if (Adapter->bDoSuspend == TRUE)
1373 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1374 } else {
1375 Adapter->bPreparingForLowPowerMode = FALSE;
1378 if (!NVMAccess)
1379 up(&Adapter->NVMRdmWrmLock);
1381 if (!lowPwrAbortMsg)
1382 up(&Adapter->LowPowerModeSync);
1385 Status = CopyBufferToControlPacket(Adapter, &stShutdownResponse);
1386 if ((Status != STATUS_SUCCESS)) {
1387 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "fail to send the Idle mode Request\n");
1388 Adapter->bPreparingForLowPowerMode = FALSE;
1389 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1393 static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
1395 B_UINT32 uiResetValue = 0;
1397 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1399 if (*(pucBuffer+1) == COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW) {
1400 HandleShutDownModeWakeup(Adapter);
1401 } else if (*(pucBuffer+1) == LINK_SHUTDOWN_REQ_FROM_FIRMWARE) {
1402 /* Target wants to go to Shut Down Mode */
1403 /* InterfacePrepareForShutdown(Adapter); */
1404 if (Adapter->chip_id == BCS220_2 ||
1405 Adapter->chip_id == BCS220_2BC ||
1406 Adapter->chip_id == BCS250_BC ||
1407 Adapter->chip_id == BCS220_3) {
1409 rdmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1410 uiResetValue |= (1<<17);
1411 wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1414 SendShutModeResponse(Adapter);
1415 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ShutDownModeResponse:Notification received: Sending the response(Ack/Nack)\n");
1418 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1419 return;
1422 VOID ResetCounters(struct bcm_mini_adapter *Adapter)
1424 beceem_protocol_reset(Adapter);
1425 Adapter->CurrNumRecvDescs = 0;
1426 Adapter->PrevNumRecvDescs = 0;
1427 Adapter->LinkUpStatus = 0;
1428 Adapter->LinkStatus = 0;
1429 atomic_set(&Adapter->cntrlpktCnt, 0);
1430 atomic_set(&Adapter->TotalPacketCount, 0);
1431 Adapter->fw_download_done = FALSE;
1432 Adapter->LinkStatus = 0;
1433 Adapter->AutoLinkUp = FALSE;
1434 Adapter->IdleMode = FALSE;
1435 Adapter->bShutStatus = FALSE;
1438 struct bcm_classifier_rule *GetFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIP)
1440 UINT uiIndex = 0;
1441 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1442 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1443 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1444 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIP) &&
1445 !Adapter->astFragmentedPktClassifierTable[uiIndex].bOutOfOrderFragment)
1447 return Adapter->astFragmentedPktClassifierTable[uiIndex].pstMatchedClassifierEntry;
1449 return NULL;
1452 void AddFragIPClsEntry(struct bcm_mini_adapter *Adapter, struct bcm_fragmented_packet_info *psFragPktInfo)
1454 UINT uiIndex = 0;
1455 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1456 if (!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) {
1457 memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex], psFragPktInfo, sizeof(struct bcm_fragmented_packet_info));
1458 break;
1463 void DelFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIp)
1465 UINT uiIndex = 0;
1466 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1467 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1468 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1469 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIp))
1471 memset(&Adapter->astFragmentedPktClassifierTable[uiIndex], 0, sizeof(struct bcm_fragmented_packet_info));
1475 void update_per_cid_rx(struct bcm_mini_adapter *Adapter)
1477 UINT qindex = 0;
1479 if ((jiffies - Adapter->liDrainCalculated) < XSECONDS)
1480 return;
1482 for (qindex = 0; qindex < HiPriority; qindex++) {
1483 if (Adapter->PackInfo[qindex].ucDirection == 0) {
1484 Adapter->PackInfo[qindex].uiCurrentRxRate =
1485 (Adapter->PackInfo[qindex].uiCurrentRxRate +
1486 Adapter->PackInfo[qindex].uiThisPeriodRxBytes) / 2;
1488 Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
1489 } else {
1490 Adapter->PackInfo[qindex].uiCurrentDrainRate =
1491 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
1492 Adapter->PackInfo[qindex].uiThisPeriodSentBytes) / 2;
1493 Adapter->PackInfo[qindex].uiThisPeriodSentBytes = 0;
1496 Adapter->liDrainCalculated = jiffies;
1499 void update_per_sf_desc_cnts(struct bcm_mini_adapter *Adapter)
1501 INT iIndex = 0;
1502 u32 uibuff[MAX_TARGET_DSX_BUFFERS];
1503 int bytes;
1505 if (!atomic_read(&Adapter->uiMBupdate))
1506 return;
1508 bytes = rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (PUINT)uibuff, sizeof(UINT) * MAX_TARGET_DSX_BUFFERS);
1509 if (bytes < 0) {
1510 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
1511 return;
1514 for (iIndex = 0; iIndex < HiPriority; iIndex++) {
1515 if (Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection) {
1516 if (Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
1517 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
1518 else
1519 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid VCID : %x\n", Adapter->PackInfo[iIndex].usVCID_Value);
1522 atomic_set(&Adapter->uiMBupdate, FALSE);
1525 void flush_queue(struct bcm_mini_adapter *Adapter, UINT iQIndex)
1527 struct sk_buff *PacketToDrop = NULL;
1528 struct net_device_stats *netstats = &Adapter->dev->stats;
1529 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1531 while (Adapter->PackInfo[iQIndex].FirstTxQueue && atomic_read(&Adapter->TotalPacketCount)) {
1532 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
1533 if (PacketToDrop && PacketToDrop->len) {
1534 netstats->tx_dropped++;
1535 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, Adapter->PackInfo[iQIndex].LastTxQueue);
1536 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1537 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1539 /* Adding dropped statistics */
1540 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1541 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
1542 dev_kfree_skb(PacketToDrop);
1543 atomic_dec(&Adapter->TotalPacketCount);
1546 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1549 static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter)
1551 int i;
1552 if (netif_msg_link(Adapter))
1553 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
1555 netif_carrier_off(Adapter->dev);
1556 netif_stop_queue(Adapter->dev);
1558 Adapter->IdleMode = FALSE;
1559 Adapter->LinkUpStatus = FALSE;
1560 ClearTargetDSXBuffer(Adapter, 0, TRUE);
1561 /* Delete All Classifier Rules */
1563 for (i = 0; i < HiPriority; i++)
1564 DeleteAllClassifiersForSF(Adapter, i);
1566 flush_all_queues(Adapter);
1568 if (Adapter->TimerActive == TRUE)
1569 Adapter->TimerActive = FALSE;
1571 memset(Adapter->astFragmentedPktClassifierTable, 0, sizeof(struct bcm_fragmented_packet_info) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
1573 for (i = 0; i < HiPriority; i++) {
1574 /* resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF. */
1575 /* It is same between MIBs and SF. */
1576 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable, 0, sizeof(S_MIBS_EXTSERVICEFLOW_PARAMETERS));