]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/staging/bcm/Misc.c
Merge tag 'sh-for-linus' of git://github.com/pmundt/linux-sh
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / bcm / Misc.c
CommitLineData
f8942e07
SH
1#include "headers.h"
2
2979460d
KM
3static int BcmFileDownload(struct bcm_mini_adapter *Adapter, const char *path, unsigned int loc);
4static VOID doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter);
5static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer);
6static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter);
7static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter);
9dd47ee7 8
2979460d 9static VOID default_wimax_protocol_initialize(struct bcm_mini_adapter *Adapter)
f8942e07 10{
6a4ef5f9 11 UINT uiLoopIndex;
f8942e07 12
6a4ef5f9
KM
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;
17 }
f8942e07 18
6a4ef5f9
KM
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;
25}
f8942e07 26
2979460d 27INT InitAdapter(struct bcm_mini_adapter *psAdapter)
f8942e07 28{
6a4ef5f9
KM
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);
f8942e07 32
6a4ef5f9
KM
33 if (psAdapter == NULL) {
34 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Adapter is NULL");
f8942e07
SH
35 return -EINVAL;
36 }
37
6a4ef5f9 38 sema_init(&psAdapter->NVMRdmWrmLock, 1);
f8942e07
SH
39 sema_init(&psAdapter->rdmwrmsync, 1);
40 spin_lock_init(&psAdapter->control_queue_lock);
41 spin_lock_init(&psAdapter->txtransmitlock);
6a4ef5f9
KM
42 sema_init(&psAdapter->RxAppControlQueuelock, 1);
43 sema_init(&psAdapter->fw_download_sema, 1);
44 sema_init(&psAdapter->LowPowerModeSync, 1);
45
46 for (i = 0; i < NO_OF_QUEUES; i++)
47 spin_lock_init(&psAdapter->PackInfo[i].SFQueueLock);
48 i = 0;
49
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);
f8942e07 55 psAdapter->waiting_to_fw_download_done = TRUE;
6a4ef5f9 56 psAdapter->fw_download_done = FALSE;
f8942e07
SH
57
58 default_wimax_protocol_initialize(psAdapter);
6a4ef5f9 59 for (i = 0; i < MAX_CNTRL_PKTS; i++) {
3701befc 60 psAdapter->txctlpacket[i] = kmalloc(MAX_CNTL_PKT_SIZE, GFP_KERNEL);
6a4ef5f9
KM
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);
f8942e07
SH
63 return -ENOMEM;
64 }
65 }
6a4ef5f9
KM
66
67 if (AllocAdapterDsxBuffer(psAdapter)) {
68 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to allocate DSX buffers");
f8942e07
SH
69 return -EINVAL;
70 }
71
6a4ef5f9
KM
72 /* Initialize PHS interface */
73 if (phs_init(&psAdapter->stBCMPhsContext, psAdapter) != 0) {
a8a1cdd6 74 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%s:%d:Error PHS Init Failed=====>\n", __FILE__, __func__, __LINE__);
f8942e07
SH
75 return -ENOMEM;
76 }
77
78 Status = BcmAllocFlashCSStructure(psAdapter);
6a4ef5f9
KM
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;
f8942e07
SH
82 }
83
84 Status = vendorextnInit(psAdapter);
85
6a4ef5f9
KM
86 if (STATUS_SUCCESS != Status) {
87 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Vendor Init Failed");
88 return Status;
f8942e07
SH
89 }
90
6a4ef5f9 91 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Adapter initialised");
f8942e07
SH
92
93 return STATUS_SUCCESS;
94}
95
2979460d 96VOID AdapterFree(struct bcm_mini_adapter *Adapter)
f8942e07 97{
e614e28e 98 int count;
f8942e07 99 beceem_protocol_reset(Adapter);
f8942e07
SH
100 vendorextnExit(Adapter);
101
6a4ef5f9
KM
102 if (Adapter->control_packet_handler && !IS_ERR(Adapter->control_packet_handler))
103 kthread_stop(Adapter->control_packet_handler);
e614e28e 104
6a4ef5f9
KM
105 if (Adapter->transmit_packet_thread && !IS_ERR(Adapter->transmit_packet_thread))
106 kthread_stop(Adapter->transmit_packet_thread);
e614e28e
SH
107
108 wake_up(&Adapter->process_read_wait_queue);
109
6a4ef5f9
KM
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);
e614e28e 112
4ea4f7a0 113 unregister_networkdev(Adapter);
e614e28e
SH
114
115 /* FIXME: use proper wait_event and refcounting */
6a4ef5f9
KM
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));
f8942e07
SH
118 msleep(100);
119 }
120 unregister_control_device_interface(Adapter);
e614e28e
SH
121 kfree(Adapter->pstargetparams);
122
6a4ef5f9 123 for (count = 0; count < MAX_CNTRL_PKTS; count++)
e614e28e
SH
124 kfree(Adapter->txctlpacket[count]);
125
f8942e07 126 FreeAdapterDsxBuffer(Adapter);
e614e28e 127 kfree(Adapter->pvInterfaceAdapter);
f8942e07 128
6a4ef5f9 129 /* Free the PHS Interface */
f8942e07
SH
130 PhsCleanup(&Adapter->stBCMPhsContext);
131
f8942e07 132 BcmDeAllocFlashCSStructure(Adapter);
f8942e07 133
e614e28e 134 free_netdev(Adapter->dev);
f8942e07
SH
135}
136
2979460d 137static int create_worker_threads(struct bcm_mini_adapter *psAdapter)
f8942e07 138{
6a4ef5f9 139 /* Rx Control Packets Processing */
f8942e07 140 psAdapter->control_packet_handler = kthread_run((int (*)(void *))
2d08748a 141 control_packet_handler, psAdapter, "%s-rx", DRV_NAME);
6a4ef5f9 142 if (IS_ERR(psAdapter->control_packet_handler)) {
2d08748a 143 pr_notice(DRV_NAME ": could not create control thread\n");
f8942e07
SH
144 return PTR_ERR(psAdapter->control_packet_handler);
145 }
2d08748a 146
6a4ef5f9 147 /* Tx Thread */
f8942e07 148 psAdapter->transmit_packet_thread = kthread_run((int (*)(void *))
2d08748a 149 tx_pkt_handler, psAdapter, "%s-tx", DRV_NAME);
6a4ef5f9 150 if (IS_ERR(psAdapter->transmit_packet_thread)) {
2d08748a 151 pr_notice(DRV_NAME ": could not creat transmit thread\n");
f8942e07
SH
152 kthread_stop(psAdapter->control_packet_handler);
153 return PTR_ERR(psAdapter->transmit_packet_thread);
154 }
155 return 0;
156}
157
2979460d 158static struct file *open_firmware_file(struct bcm_mini_adapter *Adapter, const char *path)
f8942e07 159{
32aecdd3 160 struct file *flp = filp_open(path, O_RDONLY, S_IRWXU);
6a4ef5f9
KM
161 if (IS_ERR(flp)) {
162 pr_err(DRV_NAME "Unable To Open File %s, err %ld", path, PTR_ERR(flp));
163 flp = NULL;
164 }
f8942e07 165
6a4ef5f9
KM
166 if (Adapter->device_removed)
167 flp = NULL;
f8942e07 168
6a4ef5f9
KM
169 return flp;
170}
171
172/* Arguments:
173 * Logical Adapter
174 * Path to image file
175 * Download Address on the chip
176 */
2979460d 177static int BcmFileDownload(struct bcm_mini_adapter *Adapter, const char *path, unsigned int loc)
f8942e07 178{
6a4ef5f9
KM
179 int errorno = 0;
180 struct file *flp = NULL;
6a4ef5f9
KM
181 struct timeval tv = {0};
182
183 flp = open_firmware_file(Adapter, path);
184 if (!flp) {
6a4ef5f9 185 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Unable to Open %s\n", path);
32aecdd3 186 return -ENOENT;
6a4ef5f9
KM
187 }
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);
190
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;
196 }
6a4ef5f9 197 vfs_llseek(flp, 0, 0);
6a4ef5f9
KM
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;
202 }
f8942e07
SH
203
204exit_download:
32aecdd3 205 filp_close(flp, NULL);
6a4ef5f9 206 return errorno;
f8942e07
SH
207}
208
f8942e07 209/**
6a4ef5f9
KM
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
218 */
2979460d 219INT CopyBufferToControlPacket(struct bcm_mini_adapter *Adapter, PVOID ioBuffer)
f8942e07 220{
ff352042 221 struct bcm_leader *pLeader = NULL;
6a4ef5f9
KM
222 INT Status = 0;
223 unsigned char *ctrl_buff = NULL;
224 UINT pktlen = 0;
2610c7a8 225 struct bcm_link_request *pLinkReq = NULL;
6a4ef5f9
KM
226 PUCHAR pucAddIndication = NULL;
227
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");
f8942e07
SH
231 return -EINVAL;
232 }
233
2610c7a8 234 pLinkReq = (struct bcm_link_request *)ioBuffer;
ff352042 235 pLeader = (struct bcm_leader *)ioBuffer; /* ioBuffer Contains sw_Status and Payload */
f8942e07 236
6a4ef5f9 237 if (Adapter->bShutStatus == TRUE &&
f8942e07 238 pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD &&
6a4ef5f9
KM
239 pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE) {
240
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");
f8942e07
SH
243 return STATUS_FAILURE;
244 }
245
6a4ef5f9 246 if ((pLeader->Status == LINK_UP_CONTROL_REQ) &&
f8942e07 247 ((pLinkReq->szData[0] == LINK_UP_REQ_PAYLOAD &&
6a4ef5f9
KM
248 (pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE)) || /* Sync Up Command */
249 pLinkReq->szData[0] == NETWORK_ENTRY_REQ_PAYLOAD)) /* Net Entry Command */ {
250
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");
f8942e07
SH
253 return STATUS_FAILURE;
254 }
6a4ef5f9
KM
255
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. */
f8942e07
SH
261 Adapter->bWakeUpDevice = TRUE;
262 wake_up(&Adapter->process_rx_cntrlpkt);
6a4ef5f9 263 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->bShutStatus, (5 * HZ));
f8942e07 264
6a4ef5f9 265 if (Status == -ERESTARTSYS)
f8942e07
SH
266 return Status;
267
6a4ef5f9
KM
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");
f8942e07
SH
270 return STATUS_FAILURE;
271 }
6a4ef5f9
KM
272 } else {
273 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Wakeup has been tried already...\n");
f8942e07
SH
274 }
275 }
f8942e07 276 }
f8942e07 277
6a4ef5f9
KM
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) {
282
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");
f8942e07
SH
289 Adapter->usIdleModePattern = ABORT_IDLE_REG;
290 }
6a4ef5f9
KM
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;
f8942e07
SH
294 }
295
296 /*Setting bIdleMode_tx_from_host to TRUE to indicate LED control thread to represent
6a4ef5f9
KM
297 * the wake up from idlemode is from host
298 */
299 /* Adapter->LEDInfo.bIdleMode_tx_from_host = TRUE; */
f8942e07
SH
300 Adapter->bWakeUpDevice = TRUE;
301 wake_up(&Adapter->process_rx_cntrlpkt);
302
6a4ef5f9
KM
303 /* We should not send DREG message down while in idlemode. */
304 if (LINK_DOWN_REQ_PAYLOAD == pLinkReq->szData[0])
f8942e07 305 return STATUS_SUCCESS;
f8942e07 306
6a4ef5f9 307 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->IdleMode, (5 * HZ));
f8942e07 308
6a4ef5f9 309 if (Status == -ERESTARTSYS)
f8942e07
SH
310 return Status;
311
6a4ef5f9
KM
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");
f8942e07
SH
314 return STATUS_FAILURE;
315 }
6a4ef5f9 316 } else {
f8942e07 317 return STATUS_SUCCESS;
6a4ef5f9 318 }
f8942e07 319 }
6a4ef5f9
KM
320
321 /* The Driver has to send control messages with a particular VCID */
322 pLeader->Vcid = VCID_CONTROL_PACKET; /* VCID for control packet. */
f8942e07
SH
323
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];
327
6a4ef5f9
KM
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)) {
f8942e07 334 /*
6a4ef5f9
KM
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.
338 */
339 /* Lets store the current length of the control packet we are transmitting */
f8942e07
SH
340 pucAddIndication = (PUCHAR)ioBuffer + LEADER_SIZE;
341 pktlen = pLeader->PLength;
6a4ef5f9
KM
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 ");
f8942e07
SH
346 return STATUS_FAILURE;
347 }
348 /*
6a4ef5f9
KM
349 * update the leader to use the new length
350 * The length of the control packet is length of message being sent + Leader length
351 */
f8942e07
SH
352 pLeader->PLength = pktlen;
353 }
354 }
e228b742
KM
355
356 if (pktlen + LEADER_SIZE > MAX_CNTL_PKT_SIZE)
357 return -EINVAL;
358
f8942e07 359 memset(ctrl_buff, 0, pktlen+LEADER_SIZE);
6a4ef5f9 360 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Copying the Control Packet Buffer with length=%d\n", pLeader->PLength);
ff352042 361 *(struct bcm_leader *)ctrl_buff = *pLeader;
f8942e07 362 memcpy(ctrl_buff + LEADER_SIZE, ((PUCHAR)ioBuffer + LEADER_SIZE), pLeader->PLength);
6a4ef5f9 363 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Enqueuing the Control Packet");
f8942e07 364
6a4ef5f9 365 /* Update the statistics counters */
f8942e07 366 spin_lock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
6a4ef5f9 367 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost += pLeader->PLength;
f8942e07
SH
368 Adapter->PackInfo[HiPriority].uiCurrentPacketsOnHost++;
369 atomic_inc(&Adapter->TotalPacketCount);
370 spin_unlock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
f8942e07
SH
371 Adapter->PackInfo[HiPriority].bValid = TRUE;
372
6a4ef5f9
KM
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;
f8942e07
SH
377 /*Queue the packet for transmission */
378 atomic_inc(&Adapter->index_wr_txcntrlpkt);
6a4ef5f9 379 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Calling transmit_packets");
f8942e07 380 atomic_set(&Adapter->TxPktAvail, 1);
f8942e07 381 wake_up(&Adapter->tx_packet_wait_queue);
6a4ef5f9
KM
382 } else {
383 Status = -ENOMEM;
384 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "mem allocation Failed");
f8942e07 385 }
6a4ef5f9 386 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<====");
f8942e07
SH
387 return Status;
388}
389
f8942e07
SH
390/******************************************************************
391* Function - LinkMessage()
392*
393* Description - This function builds the Sync-up and Link-up request
6a4ef5f9 394* packet messages depending on the device Link status.
f8942e07
SH
395*
396* Parameters - Adapter: Pointer to the Adapter structure.
397*
398* Returns - None.
399*******************************************************************/
2979460d 400VOID LinkMessage(struct bcm_mini_adapter *Adapter)
f8942e07 401{
2610c7a8 402 struct bcm_link_request *pstLinkRequest = NULL;
6a4ef5f9
KM
403 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>");
404 if (Adapter->LinkStatus == SYNC_UP_REQUEST && Adapter->AutoSyncup) {
2610c7a8 405 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
6a4ef5f9
KM
406 if (!pstLinkRequest) {
407 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
f8942e07
SH
408 return;
409 }
6a4ef5f9
KM
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);
f8942e07 417 Adapter->bSyncUpRequestSent = TRUE;
6a4ef5f9
KM
418
419 } else if (Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp) {
2610c7a8 420 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
6a4ef5f9
KM
421 if (!pstLinkRequest) {
422 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
f8942e07
SH
423 return;
424 }
6a4ef5f9
KM
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);
431 }
432 if (pstLinkRequest) {
433 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
f8942e07 434 CopyBufferToControlPacket(Adapter, pstLinkRequest);
082e889b 435 kfree(pstLinkRequest);
f8942e07 436 }
6a4ef5f9 437 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
f8942e07
SH
438 return;
439}
440
f8942e07
SH
441/**********************************************************************
442* Function - StatisticsResponse()
443*
444* Description - This function handles the Statistics response packet.
445*
446* Parameters - Adapter : Pointer to the Adapter structure.
6a4ef5f9 447* - pvBuffer: Starting address of Statistic response data.
f8942e07
SH
448*
449* Returns - None.
450************************************************************************/
2979460d 451VOID StatisticsResponse(struct bcm_mini_adapter *Adapter, PVOID pvBuffer)
f8942e07 452{
a8a1cdd6 453 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>", __func__);
e39e3be6 454 Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
6a4ef5f9 455 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (UINT)Adapter->StatisticsPointer);
a8a1cdd6 456 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====", __func__);
f8942e07
SH
457 return;
458}
459
f8942e07
SH
460/**********************************************************************
461* Function - LinkControlResponseMessage()
462*
463* Description - This function handles the Link response packets.
464*
465* Parameters - Adapter : Pointer to the Adapter structure.
6a4ef5f9 466* - pucBuffer: Starting address of Link response data.
f8942e07
SH
467*
468* Returns - None.
469***********************************************************************/
2979460d 470VOID LinkControlResponseMessage(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
f8942e07 471{
6a4ef5f9 472 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
f8942e07 473
6a4ef5f9
KM
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");
f8942e07 478
6a4ef5f9 479 if (Adapter->LinkStatus == LINKUP_DONE)
f8942e07 480 beceem_protocol_reset(Adapter);
f8942e07 481
6a4ef5f9
KM
482 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
483 Adapter->LinkStatus = PHY_SYNC_ACHIVED;
f8942e07 484
6a4ef5f9 485 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
f8942e07
SH
486 Adapter->DriverState = NO_NETWORK_ENTRY;
487 wake_up(&Adapter->LEDInfo.notify_led_event);
488 }
489
490 LinkMessage(Adapter);
491 break;
492
6a4ef5f9
KM
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);
499
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);
f8942e07 504 }
6a4ef5f9
KM
505 }
506 LinkMessage(Adapter);
507 break;
f8942e07 508
6a4ef5f9
KM
509 case WAIT_FOR_SYNC:
510 /*
511 * Driver to ignore the DREG_RECEIVED
512 * WiMAX Application should handle this Message
513 */
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);
f8942e07 521
6a4ef5f9
KM
522 break;
523 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
524 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
525 {
526 HandleShutDownModeRequest(Adapter, pucBuffer);
f8942e07 527 }
6a4ef5f9
KM
528 break;
529 default:
530 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x", *(pucBuffer + 1));
531 break;
532 }
533 } else if (SET_MAC_ADDRESS_RESPONSE == *pucBuffer) {
f8942e07 534 PUCHAR puMacAddr = (pucBuffer + 1);
6a4ef5f9
KM
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");
f8942e07
SH
537 LinkMessage(Adapter);
538 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
539 }
a8a1cdd6 540 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====", __func__);
f8942e07
SH
541 return;
542}
543
2979460d 544void SendIdleModeResponse(struct bcm_mini_adapter *Adapter)
f8942e07 545{
6a4ef5f9 546 INT status = 0, NVMAccess = 0, lowPwrAbortMsg = 0;
f8942e07 547 struct timeval tv;
2610c7a8 548 struct bcm_link_request stIdleResponse = {{0} };
f8942e07 549 memset(&tv, 0, sizeof(tv));
6a4ef5f9 550 stIdleResponse.Leader.Status = IDLE_MESSAGE;
f8942e07
SH
551 stIdleResponse.Leader.PLength = IDLE_MODE_PAYLOAD_LENGTH;
552 stIdleResponse.szData[0] = GO_TO_IDLE_MODE_PAYLOAD;
6a4ef5f9 553 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, " ============>");
f8942e07
SH
554
555 /*********************************
6a4ef5f9
KM
556 *down_trylock -
557 * if [ semaphore is available ]
558 * acquire semaphone and return value 0 ;
559 * else
560 * return non-zero value ;
561 *
562 ***********************************/
f8942e07
SH
563
564 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
6a4ef5f9 565 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
f8942e07 566
f8942e07 567
6a4ef5f9
KM
568 if ((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
569 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)) {
f8942e07 570
6a4ef5f9 571 if (!NVMAccess)
f8942e07
SH
572 up(&Adapter->NVMRdmWrmLock);
573
6a4ef5f9 574 if (!lowPwrAbortMsg)
f8942e07
SH
575 up(&Adapter->LowPowerModeSync);
576
6a4ef5f9
KM
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!!!!!!!!");
f8942e07 579 Adapter->bPreparingForLowPowerMode = FALSE;
6a4ef5f9
KM
580 } else {
581 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; /* 2; Idle ACK */
f8942e07
SH
582 Adapter->StatisticsPointer = 0;
583
584 /* Wait for the LED to TURN OFF before sending ACK response */
6a4ef5f9 585 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
f8942e07
SH
586 INT iRetVal = 0;
587
588 /* Wake the LED Thread with IDLEMODE_ENTER State */
589 Adapter->DriverState = LOWPOWER_MODE_ENTER;
6a4ef5f9 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);
f8942e07
SH
591 wake_up(&Adapter->LEDInfo.notify_led_event);
592
593 /* Wait for 1 SEC for LED to OFF */
6a4ef5f9 594 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
f8942e07
SH
595
596 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
6a4ef5f9
KM
597 if (iRetVal <= 0) {
598 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
f8942e07
SH
599 Adapter->DriverState = NORMAL_OPERATION;
600 wake_up(&Adapter->LEDInfo.notify_led_event);
6a4ef5f9 601 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "NACKING Idle mode as time out happen from LED side!!!!!!!!");
f8942e07
SH
602 }
603 }
6a4ef5f9
KM
604
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 !!!!!!!!!");
f8942e07
SH
607 down(&Adapter->rdmwrmsync);
608 Adapter->bPreparingForLowPowerMode = TRUE;
609 up(&Adapter->rdmwrmsync);
6a4ef5f9
KM
610 /* Killing all URBS. */
611 if (Adapter->bDoSuspend == TRUE)
f8942e07 612 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
6a4ef5f9 613 } else {
f8942e07
SH
614 Adapter->bPreparingForLowPowerMode = FALSE;
615 }
616
6a4ef5f9 617 if (!NVMAccess)
f8942e07
SH
618 up(&Adapter->NVMRdmWrmLock);
619
6a4ef5f9 620 if (!lowPwrAbortMsg)
f8942e07 621 up(&Adapter->LowPowerModeSync);
f8942e07 622 }
6a4ef5f9
KM
623
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");
f8942e07 627 Adapter->bPreparingForLowPowerMode = FALSE;
f8942e07 628 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
f8942e07
SH
629 }
630 do_gettimeofday(&tv);
6a4ef5f9 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);
f8942e07
SH
632}
633
634/******************************************************************
635* Function - DumpPackInfo()
636*
637* Description - This function dumps the all Queue(PackInfo[]) details.
638*
639* Parameters - Adapter: Pointer to the Adapter structure.
640*
641* Returns - None.
642*******************************************************************/
2979460d 643VOID DumpPackInfo(struct bcm_mini_adapter *Adapter)
f8942e07 644{
6a4ef5f9 645 UINT uiLoopIndex = 0;
f8942e07
SH
646 UINT uiIndex = 0;
647 UINT uiClsfrIndex = 0;
92562aee 648 struct bcm_classifier_rule *pstClassifierEntry = NULL;
f8942e07 649
6a4ef5f9
KM
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);
f8942e07
SH
654 continue;
655 }
656
6a4ef5f9
KM
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);
659
660 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
661 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv6 Service Flow\n");
f8942e07 662 else
6a4ef5f9 663 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv4 Service Flow\n");
f8942e07 664
6a4ef5f9
KM
665 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SF Traffic Priority %X\n", Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
666
667 for (uiClsfrIndex = 0; uiClsfrIndex < MAX_CLASSIFIERS; uiClsfrIndex++) {
f8942e07 668 pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
6a4ef5f9 669 if (!pstClassifierEntry->bUsed)
f8942e07
SH
670 continue;
671
6a4ef5f9 672 if (pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
f8942e07
SH
673 continue;
674
6a4ef5f9
KM
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);
681
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]);
f8942e07
SH
687 }
688
6a4ef5f9
KM
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");
f8942e07 694 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Addr);
6a4ef5f9 695 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpMask :\n");
f8942e07 696 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Mask);
6a4ef5f9
KM
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]);
f8942e07
SH
700 }
701 }
6a4ef5f9
KM
702
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");
f8942e07 706 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Addr);
6a4ef5f9 707 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpMask :\n");
f8942e07 708 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Mask);
6a4ef5f9
KM
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]);
f8942e07
SH
712 }
713 }
6a4ef5f9
KM
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);
f8942e07 716 }
6a4ef5f9
KM
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);
721
722 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid:%X\n", Adapter->PackInfo[uiLoopIndex].bValid);
723 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bActive:%X\n", Adapter->PackInfo[uiLoopIndex].bActive);
724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActivateReqSent: %x", Adapter->PackInfo[uiLoopIndex].bActivateRequestSent);
725 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "u8QueueType:%X\n", Adapter->PackInfo[uiLoopIndex].u8QueueType);
726 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxBucketSize:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize);
727 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPerSFTxResourceCount:%X\n", atomic_read(&Adapter->PackInfo[uiLoopIndex].uiPerSFTxResourceCount));
728 /* DumpDebug(DUMP_INFO,("bCSSupport:%X\n",Adapter->PackInfo[uiLoopIndex].bCSSupport)); */
729 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CurrQueueDepthOnTarget: %x\n", Adapter->PackInfo[uiLoopIndex].uiCurrentQueueDepthOnTarget);
730 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentBytesOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentBytesOnHost);
731 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentPacketsOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentPacketsOnHost);
732 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountBytes);
733 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountPackets);
734 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentBytes);
735 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentPackets);
736 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentDrainRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentDrainRate);
737 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThisPeriodSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiThisPeriodSentBytes);
738 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liDrainCalculated:%llX\n", Adapter->PackInfo[uiLoopIndex].liDrainCalculated);
739 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentTokenCount:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentTokenCount);
740 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liLastUpdateTokenAt:%llX\n", Adapter->PackInfo[uiLoopIndex].liLastUpdateTokenAt);
741 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxAllowedRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate);
742 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPendedLast:%X\n", Adapter->PackInfo[uiLoopIndex].uiPendedLast);
743 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "NumOfPacketsSent:%X\n", Adapter->PackInfo[uiLoopIndex].NumOfPacketsSent);
744 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Direction: %x\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
745 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CID: %x\n", Adapter->PackInfo[uiLoopIndex].usCID);
746 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ProtocolValid: %x\n", Adapter->PackInfo[uiLoopIndex].bProtocolValid);
747 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "TOSValid: %x\n", Adapter->PackInfo[uiLoopIndex].bTOSValid);
748 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "DestIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bDestIpValid);
749 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SrcIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bSrcIpValid);
750 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActiveSet: %x\n", Adapter->PackInfo[uiLoopIndex].bActiveSet);
751 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AdmittedSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAdmittedSet);
752 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AuthzSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAuthorizedSet);
753 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ClassifyPrority: %x\n", Adapter->PackInfo[uiLoopIndex].bClassifierPriority);
754 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxLatency: %x\n", Adapter->PackInfo[uiLoopIndex].uiMaxLatency);
755 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ServiceClassName: %x %x %x %x\n", Adapter->PackInfo[uiLoopIndex].ucServiceClassName[0], Adapter->PackInfo[uiLoopIndex].ucServiceClassName[1], Adapter->PackInfo[uiLoopIndex].ucServiceClassName[2], Adapter->PackInfo[uiLoopIndex].ucServiceClassName[3]);
756/* BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bHeaderSuppressionEnabled :%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
757 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalTxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalTxBytes);
758 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalRxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalRxBytes);
759 * DumpDebug(DUMP_INFO,(" uiRanOutOfResCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiRanOutOfResCount));
760 */
761 }
762
763 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
764 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aRxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aRxPktSizeHist[uiLoopIndex]);
765
766 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
767 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aTxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aTxPktSizeHist[uiLoopIndex]);
f8942e07
SH
768
769 return;
f8942e07
SH
770}
771
2979460d 772int reset_card_proc(struct bcm_mini_adapter *ps_adapter)
f8942e07
SH
773{
774 int retval = STATUS_SUCCESS;
2979460d 775 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
f8942e07
SH
776 PS_INTERFACE_ADAPTER psIntfAdapter = NULL;
777 unsigned int value = 0, uiResetValue = 0;
41c7b7c0 778 int bytes;
f8942e07 779
6a4ef5f9 780 psIntfAdapter = ((PS_INTERFACE_ADAPTER)(ps_adapter->pvInterfaceAdapter));
f8942e07
SH
781 ps_adapter->bDDRInitDone = FALSE;
782
6a4ef5f9
KM
783 if (ps_adapter->chip_id >= T3LPB) {
784 /* SYS_CFG register is write protected hence for modifying this reg value, it should be read twice before */
785 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
786 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
f8942e07 787
6a4ef5f9
KM
788 /* making bit[6...5] same as was before f/w download. this setting force the h/w to */
789 /* re-populated the SP RAM area with the string descriptor. */
790 value = value | (ps_adapter->syscfgBefFwDld & 0x00000060);
f8942e07
SH
791 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
792 }
793
6a4ef5f9
KM
794 /* killing all submitted URBs. */
795 psIntfAdapter->psAdapter->StopAllXaction = TRUE;
f8942e07 796 Bcm_kill_all_URBs(psIntfAdapter);
f8942e07 797 /* Reset the UMA-B Device */
6a4ef5f9 798 if (ps_adapter->chip_id >= T3LPB) {
73e29189 799 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Resetting UMA-B\n");
f8942e07 800 retval = usb_reset_device(psIntfAdapter->udev);
6a4ef5f9 801 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
f8942e07 802
6a4ef5f9
KM
803 if (retval != STATUS_SUCCESS) {
804 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
f8942e07
SH
805 goto err_exit;
806 }
6a4ef5f9 807
f8942e07
SH
808 if (ps_adapter->chip_id == BCS220_2 ||
809 ps_adapter->chip_id == BCS220_2BC ||
810 ps_adapter->chip_id == BCS250_BC ||
6a4ef5f9
KM
811 ps_adapter->chip_id == BCS220_3) {
812
41c7b7c0
KM
813 bytes = rdmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
814 if (bytes < 0) {
815 retval = bytes;
6a4ef5f9 816 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
f8942e07
SH
817 goto err_exit;
818 }
6a4ef5f9 819 /* setting 0th bit */
f8942e07
SH
820 value |= (1<<0);
821 retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
6a4ef5f9
KM
822 if (retval < 0) {
823 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
f8942e07
SH
824 goto err_exit;
825 }
826 }
6a4ef5f9 827 } else {
41c7b7c0
KM
828 bytes = rdmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
829 if (bytes < 0) {
830 retval = bytes;
6a4ef5f9 831 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
f8942e07
SH
832 goto err_exit;
833 }
6a4ef5f9
KM
834 value &= (~(1<<16));
835 retval = wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
836 if (retval < 0) {
837 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
f8942e07
SH
838 goto err_exit;
839 }
840
6a4ef5f9 841 /* Toggling the GPIO 8, 9 */
f8942e07
SH
842 value = 0;
843 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
6a4ef5f9
KM
844 if (retval < 0) {
845 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
f8942e07
SH
846 goto err_exit;
847 }
848 value = 0x300;
6a4ef5f9
KM
849 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value));
850 if (retval < 0) {
851 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
f8942e07
SH
852 goto err_exit;
853 }
854 mdelay(50);
855 }
856
6a4ef5f9
KM
857 /* ps_adapter->downloadDDR = false; */
858 if (ps_adapter->bFlashBoot) {
859 /* In flash boot mode MIPS state register has reverse polarity.
860 * So just or with setting bit 30.
861 * Make the MIPS in Reset state.
862 */
f8942e07 863 rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
6a4ef5f9 864 uiResetValue |= (1<<30);
f8942e07
SH
865 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
866 }
867
6a4ef5f9 868 if (ps_adapter->chip_id >= T3LPB) {
f8942e07 869 uiResetValue = 0;
6a4ef5f9
KM
870 /*
871 * WA for SYSConfig Issue.
872 * Read SYSCFG Twice to make it writable.
873 */
f8942e07 874 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
6a4ef5f9 875 if (uiResetValue & (1<<4)) {
f8942e07 876 uiResetValue = 0;
6a4ef5f9 877 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue)); /* 2nd read to make it writable. */
f8942e07 878 uiResetValue &= (~(1<<4));
6a4ef5f9 879 wrmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
f8942e07 880 }
f8942e07
SH
881 }
882 uiResetValue = 0;
883 wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
884
6a4ef5f9
KM
885err_exit:
886 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
f8942e07
SH
887 return retval;
888}
889
2979460d 890int run_card_proc(struct bcm_mini_adapter *ps_adapter)
f8942e07 891{
41c7b7c0
KM
892 int status = STATUS_SUCCESS;
893 int bytes;
894
6a4ef5f9 895 unsigned int value = 0;
f8942e07 896 {
41c7b7c0
KM
897 bytes = rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value));
898 if (bytes < 0) {
899 status = bytes;
a8a1cdd6 900 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
41c7b7c0 901 return status;
f8942e07
SH
902 }
903
6a4ef5f9
KM
904 if (ps_adapter->bFlashBoot)
905 value &= (~(1<<30));
f8942e07 906 else
6a4ef5f9 907 value |= (1<<30);
f8942e07 908
6a4ef5f9 909 if (wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
a8a1cdd6 910 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
f8942e07
SH
911 return STATUS_FAILURE;
912 }
913 }
41c7b7c0 914 return status;
f8942e07
SH
915}
916
2979460d 917int InitCardAndDownloadFirmware(struct bcm_mini_adapter *ps_adapter)
f8942e07 918{
2e316139 919 int status;
f8942e07 920 UINT value = 0;
f8942e07 921 /*
6a4ef5f9
KM
922 * Create the threads first and then download the
923 * Firm/DDR Settings..
924 */
2d08748a 925 status = create_worker_threads(ps_adapter);
6a4ef5f9 926 if (status < 0)
f8942e07 927 return status;
2d08748a 928
6a4ef5f9
KM
929 status = bcm_parse_target_params(ps_adapter);
930 if (status)
f8942e07 931 return status;
f8942e07 932
6a4ef5f9
KM
933 if (ps_adapter->chip_id >= T3LPB) {
934 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
935 ps_adapter->syscfgBefFwDld = value;
936
937 if ((value & 0x60) == 0)
f8942e07 938 ps_adapter->bFlashBoot = TRUE;
f8942e07
SH
939 }
940
941 reset_card_proc(ps_adapter);
942
6a4ef5f9 943 /* Initializing the NVM. */
f8942e07
SH
944 BcmInitNVM(ps_adapter);
945 status = ddr_init(ps_adapter);
6a4ef5f9 946 if (status) {
2d08748a 947 pr_err(DRV_NAME "ddr_init Failed\n");
f8942e07
SH
948 return status;
949 }
950
951 /* Download cfg file */
952 status = buffDnldVerify(ps_adapter,
6a4ef5f9
KM
953 (PUCHAR)ps_adapter->pstargetparams,
954 sizeof(STARGETPARAMS),
955 CONFIG_BEGIN_ADDR);
956 if (status) {
957 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
f8942e07
SH
958 goto OUT;
959 }
f8942e07 960
6a4ef5f9
KM
961 if (register_networkdev(ps_adapter)) {
962 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
f8942e07
SH
963 return -EIO;
964 }
965
6a4ef5f9
KM
966 if (FALSE == ps_adapter->AutoFirmDld) {
967 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoFirmDld Disabled in CFG File..\n");
968 /* If Auto f/w download is disable, register the control interface, */
969 /* register the control interface after the mailbox. */
970 if (register_control_device_interface(ps_adapter) < 0) {
971 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
f8942e07
SH
972 return -EIO;
973 }
f8942e07
SH
974 return STATUS_SUCCESS;
975 }
976
977 /*
6a4ef5f9
KM
978 * Do the LED Settings here. It will be used by the Firmware Download
979 * Thread.
980 */
f8942e07
SH
981
982 /*
6a4ef5f9
KM
983 * 1. If the LED Settings fails, do not stop and do the Firmware download.
984 * 2. This init would happened only if the cfg file is present, else
985 * call from the ioctl context.
986 */
f8942e07 987
6a4ef5f9
KM
988 status = InitLedSettings(ps_adapter);
989 if (status) {
990 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_PRINTK, 0, 0, "INIT LED FAILED\n");
f8942e07
SH
991 return status;
992 }
6a4ef5f9
KM
993
994 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
f8942e07
SH
995 ps_adapter->DriverState = DRIVER_INIT;
996 wake_up(&ps_adapter->LEDInfo.notify_led_event);
997 }
998
6a4ef5f9 999 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
f8942e07
SH
1000 ps_adapter->DriverState = FW_DOWNLOAD;
1001 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1002 }
1003
1004 value = 0;
1005 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1006 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1007
6a4ef5f9 1008 if (ps_adapter->eNVMType == NVM_FLASH) {
f8942e07 1009 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
6a4ef5f9
KM
1010 if (status) {
1011 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Propagation of Cal param failed ..");
f8942e07
SH
1012 goto OUT;
1013 }
1014 }
f8942e07
SH
1015
1016 /* Download Firmare */
d491061b
KM
1017 status = BcmFileDownload(ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR);
1018 if (status != 0) {
6a4ef5f9 1019 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Firmware File is present...\n");
f8942e07
SH
1020 goto OUT;
1021 }
1022
f8942e07 1023 status = run_card_proc(ps_adapter);
6a4ef5f9
KM
1024 if (status) {
1025 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "run_card_proc Failed\n");
f8942e07
SH
1026 goto OUT;
1027 }
1028
f8942e07
SH
1029 ps_adapter->fw_download_done = TRUE;
1030 mdelay(10);
1031
1032OUT:
6a4ef5f9 1033 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
f8942e07
SH
1034 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1035 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1036 }
1037
f8942e07
SH
1038 return status;
1039}
1040
2979460d 1041static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter)
f8942e07 1042{
6a4ef5f9 1043 struct file *flp = NULL;
3701befc 1044 char *buff;
f8942e07 1045 int len = 0;
f8942e07 1046
6a4ef5f9
KM
1047 buff = kmalloc(BUFFER_1K, GFP_KERNEL);
1048 if (!buff)
f8942e07 1049 return -ENOMEM;
6a4ef5f9 1050
9d4f1d0c
KM
1051 Adapter->pstargetparams = kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL);
1052 if (Adapter->pstargetparams == NULL) {
082e889b 1053 kfree(buff);
f8942e07
SH
1054 return -ENOMEM;
1055 }
6a4ef5f9
KM
1056
1057 flp = open_firmware_file(Adapter, CFG_FILE);
1058 if (!flp) {
1059 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE\n", CFG_FILE);
082e889b
SH
1060 kfree(buff);
1061 kfree(Adapter->pstargetparams);
f8942e07
SH
1062 Adapter->pstargetparams = NULL;
1063 return -ENOENT;
1064 }
32aecdd3
AV
1065 len = kernel_read(flp, 0, buff, BUFFER_1K);
1066 filp_close(flp, NULL);
f8942e07 1067
6a4ef5f9
KM
1068 if (len != sizeof(STARGETPARAMS)) {
1069 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n");
082e889b
SH
1070 kfree(buff);
1071 kfree(Adapter->pstargetparams);
f8942e07 1072 Adapter->pstargetparams = NULL;
f8942e07
SH
1073 return -ENOENT;
1074 }
f8942e07
SH
1075
1076 /* Check for autolink in config params */
1077 /*
1078 * Values in Adapter->pstargetparams are in network byte order
1079 */
1080 memcpy(Adapter->pstargetparams, buff, sizeof(STARGETPARAMS));
6a4ef5f9 1081 kfree(buff);
f8942e07 1082 beceem_parse_target_struct(Adapter);
f8942e07
SH
1083 return STATUS_SUCCESS;
1084}
1085
2979460d 1086void beceem_parse_target_struct(struct bcm_mini_adapter *Adapter)
f8942e07 1087{
6a4ef5f9 1088 UINT uiHostDrvrCfg6 = 0, uiEEPROMFlag = 0;
f8942e07 1089
6a4ef5f9 1090 if (ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE) {
2d08748a 1091 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
f8942e07 1092 Adapter->AutoSyncup = FALSE;
6a4ef5f9 1093 } else {
2d08748a 1094 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
6a4ef5f9 1095 Adapter->AutoSyncup = TRUE;
f8942e07 1096 }
2d08748a 1097
6a4ef5f9 1098 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE) {
2d08748a 1099 pr_info(DRV_NAME ": Enabling autolink up");
f8942e07 1100 Adapter->AutoLinkUp = TRUE;
6a4ef5f9 1101 } else {
2d08748a 1102 pr_info(DRV_NAME ": Disabling autolink up");
f8942e07
SH
1103 Adapter->AutoLinkUp = FALSE;
1104 }
6a4ef5f9
KM
1105 /* Setting the DDR Setting.. */
1106 Adapter->DDRSetting = (ntohl(Adapter->pstargetparams->HostDrvrConfig6) >> 8)&0x0F;
1107 Adapter->ulPowerSaveMode = (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
2d08748a
SH
1108 pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1109 pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
6a4ef5f9
KM
1110 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD) {
1111 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1112 Adapter->AutoFirmDld = TRUE;
1113 } else {
1114 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1115 Adapter->AutoFirmDld = FALSE;
1116 }
f8942e07
SH
1117 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1118 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
6a4ef5f9
KM
1119 pr_info(DRV_NAME ": MIPSConfig : 0x%X\n", Adapter->bMipsConfig);
1120 /* used for backward compatibility. */
f8942e07 1121 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
6a4ef5f9 1122 Adapter->PmuMode = (uiHostDrvrCfg6 >> 24) & 0x03;
2d08748a 1123 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
f8942e07 1124
6a4ef5f9
KM
1125 if ((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT) & (0x01)) {
1126 Adapter->bDoSuspend = TRUE;
1127 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1128 }
f8942e07
SH
1129
1130 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
6a4ef5f9 1131 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n", uiEEPROMFlag);
f8942e07 1132 Adapter->eNVMType = (NVM_TYPE)((uiEEPROMFlag>>4)&0x3);
f8942e07 1133 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
f8942e07 1134 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
6a4ef5f9 1135 Adapter->bSectorSizeOverride = (bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
f8942e07 1136
6a4ef5f9 1137 if (ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x01)
f8942e07 1138 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
2d08748a 1139
6a4ef5f9 1140 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
f8942e07 1141 doPowerAutoCorrection(Adapter);
f8942e07
SH
1142}
1143
2979460d 1144static VOID doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter)
f8942e07 1145{
2d08748a 1146 UINT reporting_mode;
f8942e07 1147
6a4ef5f9 1148 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x02;
f8942e07
SH
1149 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1150
6a4ef5f9
KM
1151 if (reporting_mode == TRUE) {
1152 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "can't do suspen/resume as reporting mode is enable");
f8942e07
SH
1153 psAdapter->bDoSuspend = FALSE;
1154 }
1155
6a4ef5f9
KM
1156 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB)) {
1157 /* If reporting mode is enable, switch PMU to PMC */
f8942e07
SH
1158 {
1159 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
6a4ef5f9 1160 psAdapter->bDoSuspend = FALSE;
f8942e07
SH
1161 }
1162
6a4ef5f9 1163 /* clearing space bit[15..12] */
f8942e07 1164 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl((0xF << 12)));
6a4ef5f9 1165 /* placing the power save mode option */
f8942e07 1166 psAdapter->pstargetparams->HostDrvrConfig6 |= htonl((psAdapter->ulPowerSaveMode << 12));
6a4ef5f9
KM
1167 } else if (psAdapter->bIsAutoCorrectEnabled == FALSE) {
1168 /* remove the autocorrect disable bit set before dumping. */
f8942e07
SH
1169 psAdapter->ulPowerSaveMode &= ~(1 << 3);
1170 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl(1 << 15));
6a4ef5f9 1171 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Using Forced User Choice: %lx\n", psAdapter->ulPowerSaveMode);
f8942e07
SH
1172 }
1173}
44a17eff 1174
44a17eff 1175static void convertEndian(B_UINT8 rwFlag, PUINT puiBuffer, UINT uiByteCount)
f8942e07
SH
1176{
1177 UINT uiIndex = 0;
1178
6a4ef5f9
KM
1179 if (RWM_WRITE == rwFlag) {
1180 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++)
f8942e07 1181 puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
f8942e07 1182 } else {
6a4ef5f9 1183 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++)
f8942e07 1184 puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
f8942e07
SH
1185 }
1186}
1187
2979460d 1188int rdm(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
f8942e07 1189{
c5274ab0 1190 return Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
6a4ef5f9 1191 uiAddress, pucBuff, sSize);
f8942e07 1192}
c5274ab0 1193
2979460d 1194int wrm(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
f8942e07
SH
1195{
1196 int iRetVal;
1197
f8942e07 1198 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
6a4ef5f9 1199 uiAddress, pucBuff, sSize);
f8942e07
SH
1200 return iRetVal;
1201}
1202
2979460d 1203int wrmalt(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
f8942e07
SH
1204{
1205 convertEndian(RWM_WRITE, pucBuff, size);
1206 return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1207}
1208
2979460d 1209int rdmalt(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
f8942e07 1210{
6a4ef5f9 1211 INT uiRetVal = 0;
f8942e07 1212
6a4ef5f9 1213 uiRetVal = rdm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
f8942e07
SH
1214 convertEndian(RWM_READ, (PUINT)pucBuff, size);
1215
1216 return uiRetVal;
1217}
1218
2979460d 1219int wrmWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
f8942e07 1220{
6a4ef5f9 1221 INT status = STATUS_SUCCESS;
f8942e07
SH
1222 down(&Adapter->rdmwrmsync);
1223
6a4ef5f9
KM
1224 if ((Adapter->IdleMode == TRUE) ||
1225 (Adapter->bShutStatus == TRUE) ||
1226 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1227
f8942e07
SH
1228 status = -EACCES;
1229 goto exit;
1230 }
1231
6a4ef5f9 1232 status = wrm(Adapter, uiAddress, pucBuff, sSize);
f8942e07
SH
1233exit:
1234 up(&Adapter->rdmwrmsync);
6a4ef5f9 1235 return status;
f8942e07
SH
1236}
1237
2979460d 1238int wrmaltWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
f8942e07
SH
1239{
1240 int iRetVal = STATUS_SUCCESS;
1241
1242 down(&Adapter->rdmwrmsync);
1243
6a4ef5f9
KM
1244 if ((Adapter->IdleMode == TRUE) ||
1245 (Adapter->bShutStatus == TRUE) ||
1246 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1247
f8942e07
SH
1248 iRetVal = -EACCES;
1249 goto exit;
1250 }
1251
6a4ef5f9 1252 iRetVal = wrmalt(Adapter, uiAddress, pucBuff, size);
f8942e07
SH
1253exit:
1254 up(&Adapter->rdmwrmsync);
1255 return iRetVal;
1256}
1257
2979460d 1258int rdmaltWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
f8942e07 1259{
6a4ef5f9 1260 INT uiRetVal = STATUS_SUCCESS;
f8942e07
SH
1261
1262 down(&Adapter->rdmwrmsync);
6a4ef5f9
KM
1263 if ((Adapter->IdleMode == TRUE) ||
1264 (Adapter->bShutStatus == TRUE) ||
1265 (Adapter->bPreparingForLowPowerMode == TRUE)) {
f8942e07 1266
f8942e07
SH
1267 uiRetVal = -EACCES;
1268 goto exit;
1269 }
1270
6a4ef5f9 1271 uiRetVal = rdmalt(Adapter, uiAddress, pucBuff, size);
f8942e07
SH
1272exit:
1273 up(&Adapter->rdmwrmsync);
1274 return uiRetVal;
1275}
1276
2979460d 1277static VOID HandleShutDownModeWakeup(struct bcm_mini_adapter *Adapter)
f8942e07 1278{
6a4ef5f9
KM
1279 int clear_abort_pattern = 0, Status = 0;
1280 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1281 /* target has woken up From Shut Down */
1282 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Clearing Shut Down Software abort pattern\n");
1283 Status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC, (PUINT)&clear_abort_pattern, sizeof(clear_abort_pattern));
1284 if (Status) {
1285 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
f8942e07
SH
1286 return;
1287 }
6a4ef5f9
KM
1288
1289 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) {
f8942e07
SH
1290 msleep(100);
1291 InterfaceHandleShutdownModeWakeup(Adapter);
1292 msleep(100);
1293 }
6a4ef5f9
KM
1294
1295 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
f8942e07
SH
1296 Adapter->DriverState = NO_NETWORK_ENTRY;
1297 wake_up(&Adapter->LEDInfo.notify_led_event);
1298 }
1299
1300 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
1301 Adapter->bShutStatus = FALSE;
1302 wake_up(&Adapter->lowpower_mode_wait_queue);
6a4ef5f9 1303 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
f8942e07
SH
1304}
1305
2979460d 1306static VOID SendShutModeResponse(struct bcm_mini_adapter *Adapter)
f8942e07 1307{
2610c7a8 1308 struct bcm_link_request stShutdownResponse;
6a4ef5f9 1309 UINT NVMAccess = 0, lowPwrAbortMsg = 0;
f8942e07
SH
1310 UINT Status = 0;
1311
2610c7a8 1312 memset(&stShutdownResponse, 0, sizeof(struct bcm_link_request));
f8942e07 1313 stShutdownResponse.Leader.Status = LINK_UP_CONTROL_REQ;
6a4ef5f9 1314 stShutdownResponse.Leader.PLength = 8; /* 8 bytes; */
f8942e07
SH
1315 stShutdownResponse.szData[0] = LINK_UP_ACK;
1316 stShutdownResponse.szData[1] = LINK_SHUTDOWN_REQ_FROM_FIRMWARE;
1317
1318 /*********************************
6a4ef5f9
KM
1319 * down_trylock -
1320 * if [ semaphore is available ]
1321 * acquire semaphone and return value 0 ;
1322 * else
1323 * return non-zero value ;
1324 *
1325 ***********************************/
f8942e07
SH
1326
1327 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
6a4ef5f9 1328 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
f8942e07 1329
6a4ef5f9
KM
1330 if (NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) {
1331 if (!NVMAccess)
f8942e07
SH
1332 up(&Adapter->NVMRdmWrmLock);
1333
6a4ef5f9 1334 if (!lowPwrAbortMsg)
f8942e07
SH
1335 up(&Adapter->LowPowerModeSync);
1336
6a4ef5f9
KM
1337 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Device Access is going on NACK the Shut Down MODE\n");
1338 stShutdownResponse.szData[2] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
f8942e07 1339 Adapter->bPreparingForLowPowerMode = FALSE;
6a4ef5f9
KM
1340 } else {
1341 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Sending SHUTDOWN MODE ACK\n");
1342 stShutdownResponse.szData[2] = SHUTDOWN_ACK_FROM_DRIVER; /* ShutDown ACK */
f8942e07
SH
1343
1344 /* Wait for the LED to TURN OFF before sending ACK response */
6a4ef5f9 1345 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
f8942e07
SH
1346 INT iRetVal = 0;
1347
1348 /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1349 Adapter->DriverState = LOWPOWER_MODE_ENTER;
1350 wake_up(&Adapter->LEDInfo.notify_led_event);
1351
1352 /* Wait for 1 SEC for LED to OFF */
6a4ef5f9 1353 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
f8942e07
SH
1354
1355 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
6a4ef5f9
KM
1356 if (iRetVal <= 0) {
1357 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
f8942e07
SH
1358 Adapter->DriverState = NO_NETWORK_ENTRY;
1359 wake_up(&Adapter->LEDInfo.notify_led_event);
1360 }
1361 }
1362
6a4ef5f9
KM
1363 if (stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER) {
1364 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ACKING SHUTDOWN MODE !!!!!!!!!");
f8942e07
SH
1365 down(&Adapter->rdmwrmsync);
1366 Adapter->bPreparingForLowPowerMode = TRUE;
1367 up(&Adapter->rdmwrmsync);
6a4ef5f9
KM
1368 /* Killing all URBS. */
1369 if (Adapter->bDoSuspend == TRUE)
f8942e07 1370 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
6a4ef5f9 1371 } else {
f8942e07
SH
1372 Adapter->bPreparingForLowPowerMode = FALSE;
1373 }
1374
6a4ef5f9 1375 if (!NVMAccess)
f8942e07
SH
1376 up(&Adapter->NVMRdmWrmLock);
1377
6a4ef5f9 1378 if (!lowPwrAbortMsg)
f8942e07
SH
1379 up(&Adapter->LowPowerModeSync);
1380 }
f8942e07 1381
6a4ef5f9
KM
1382 Status = CopyBufferToControlPacket(Adapter, &stShutdownResponse);
1383 if ((Status != STATUS_SUCCESS)) {
1384 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "fail to send the Idle mode Request\n");
1385 Adapter->bPreparingForLowPowerMode = FALSE;
f8942e07 1386 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
f8942e07
SH
1387 }
1388}
1389
2979460d 1390static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
f8942e07
SH
1391{
1392 B_UINT32 uiResetValue = 0;
1393
6a4ef5f9 1394 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
f8942e07 1395
6a4ef5f9 1396 if (*(pucBuffer+1) == COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW) {
f8942e07 1397 HandleShutDownModeWakeup(Adapter);
6a4ef5f9
KM
1398 } else if (*(pucBuffer+1) == LINK_SHUTDOWN_REQ_FROM_FIRMWARE) {
1399 /* Target wants to go to Shut Down Mode */
1400 /* InterfacePrepareForShutdown(Adapter); */
1401 if (Adapter->chip_id == BCS220_2 ||
1402 Adapter->chip_id == BCS220_2BC ||
1403 Adapter->chip_id == BCS250_BC ||
1404 Adapter->chip_id == BCS220_3) {
1405
1406 rdmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
f8942e07
SH
1407 uiResetValue |= (1<<17);
1408 wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1409 }
1410
1411 SendShutModeResponse(Adapter);
6a4ef5f9 1412 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ShutDownModeResponse:Notification received: Sending the response(Ack/Nack)\n");
f8942e07
SH
1413 }
1414
6a4ef5f9 1415 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
f8942e07 1416 return;
f8942e07
SH
1417}
1418
2979460d 1419VOID ResetCounters(struct bcm_mini_adapter *Adapter)
f8942e07 1420{
6a4ef5f9 1421 beceem_protocol_reset(Adapter);
f8942e07 1422 Adapter->CurrNumRecvDescs = 0;
6a4ef5f9
KM
1423 Adapter->PrevNumRecvDescs = 0;
1424 Adapter->LinkUpStatus = 0;
f8942e07 1425 Adapter->LinkStatus = 0;
6a4ef5f9
KM
1426 atomic_set(&Adapter->cntrlpktCnt, 0);
1427 atomic_set(&Adapter->TotalPacketCount, 0);
1428 Adapter->fw_download_done = FALSE;
f8942e07 1429 Adapter->LinkStatus = 0;
6a4ef5f9 1430 Adapter->AutoLinkUp = FALSE;
f8942e07
SH
1431 Adapter->IdleMode = FALSE;
1432 Adapter->bShutStatus = FALSE;
f8942e07 1433}
6a4ef5f9 1434
2979460d 1435struct bcm_classifier_rule *GetFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIP)
f8942e07 1436{
6a4ef5f9
KM
1437 UINT uiIndex = 0;
1438 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1439 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1440 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1441 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIP) &&
f8942e07 1442 !Adapter->astFragmentedPktClassifierTable[uiIndex].bOutOfOrderFragment)
6a4ef5f9 1443
f8942e07
SH
1444 return Adapter->astFragmentedPktClassifierTable[uiIndex].pstMatchedClassifierEntry;
1445 }
1446 return NULL;
1447}
1448
2979460d 1449void AddFragIPClsEntry(struct bcm_mini_adapter *Adapter, struct bcm_fragmented_packet_info *psFragPktInfo)
f8942e07 1450{
6a4ef5f9
KM
1451 UINT uiIndex = 0;
1452 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1453 if (!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) {
7f22485d 1454 memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex], psFragPktInfo, sizeof(struct bcm_fragmented_packet_info));
f8942e07
SH
1455 break;
1456 }
1457 }
f8942e07
SH
1458}
1459
2979460d 1460void DelFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIp)
f8942e07 1461{
6a4ef5f9
KM
1462 UINT uiIndex = 0;
1463 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1464 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1465 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1466 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIp))
1467
7f22485d 1468 memset(&Adapter->astFragmentedPktClassifierTable[uiIndex], 0, sizeof(struct bcm_fragmented_packet_info));
f8942e07
SH
1469 }
1470}
1471
2979460d 1472void update_per_cid_rx(struct bcm_mini_adapter *Adapter)
f8942e07 1473{
6a4ef5f9 1474 UINT qindex = 0;
f8942e07 1475
6a4ef5f9 1476 if ((jiffies - Adapter->liDrainCalculated) < XSECONDS)
f8942e07
SH
1477 return;
1478
6a4ef5f9
KM
1479 for (qindex = 0; qindex < HiPriority; qindex++) {
1480 if (Adapter->PackInfo[qindex].ucDirection == 0) {
f8942e07
SH
1481 Adapter->PackInfo[qindex].uiCurrentRxRate =
1482 (Adapter->PackInfo[qindex].uiCurrentRxRate +
6a4ef5f9 1483 Adapter->PackInfo[qindex].uiThisPeriodRxBytes) / 2;
f8942e07
SH
1484
1485 Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
6a4ef5f9 1486 } else {
f8942e07
SH
1487 Adapter->PackInfo[qindex].uiCurrentDrainRate =
1488 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
6a4ef5f9
KM
1489 Adapter->PackInfo[qindex].uiThisPeriodSentBytes) / 2;
1490 Adapter->PackInfo[qindex].uiThisPeriodSentBytes = 0;
f8942e07
SH
1491 }
1492 }
6a4ef5f9 1493 Adapter->liDrainCalculated = jiffies;
f8942e07 1494}
6a4ef5f9 1495
2979460d 1496void update_per_sf_desc_cnts(struct bcm_mini_adapter *Adapter)
f8942e07
SH
1497{
1498 INT iIndex = 0;
1499 u32 uibuff[MAX_TARGET_DSX_BUFFERS];
41c7b7c0 1500 int bytes;
f8942e07 1501
6a4ef5f9 1502 if (!atomic_read(&Adapter->uiMBupdate))
f8942e07
SH
1503 return;
1504
41c7b7c0
KM
1505 bytes = rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (PUINT)uibuff, sizeof(UINT) * MAX_TARGET_DSX_BUFFERS);
1506 if (bytes < 0) {
6a4ef5f9 1507 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
f8942e07
SH
1508 return;
1509 }
6a4ef5f9
KM
1510
1511 for (iIndex = 0; iIndex < HiPriority; iIndex++) {
1512 if (Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection) {
1513 if (Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
f8942e07 1514 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
f8942e07 1515 else
6a4ef5f9 1516 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid VCID : %x\n", Adapter->PackInfo[iIndex].usVCID_Value);
f8942e07
SH
1517 }
1518 }
6a4ef5f9 1519 atomic_set(&Adapter->uiMBupdate, FALSE);
f8942e07
SH
1520}
1521
2979460d 1522void flush_queue(struct bcm_mini_adapter *Adapter, UINT iQIndex)
f8942e07 1523{
6a4ef5f9
KM
1524 struct sk_buff *PacketToDrop = NULL;
1525 struct net_device_stats *netstats = &Adapter->dev->stats;
f8942e07
SH
1526 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1527
6a4ef5f9 1528 while (Adapter->PackInfo[iQIndex].FirstTxQueue && atomic_read(&Adapter->TotalPacketCount)) {
f8942e07 1529 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
6a4ef5f9 1530 if (PacketToDrop && PacketToDrop->len) {
f8942e07 1531 netstats->tx_dropped++;
6a4ef5f9 1532 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, Adapter->PackInfo[iQIndex].LastTxQueue);
f8942e07
SH
1533 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1534 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1535
6a4ef5f9 1536 /* Adding dropped statistics */
f8942e07
SH
1537 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1538 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
082e889b 1539 dev_kfree_skb(PacketToDrop);
f8942e07 1540 atomic_dec(&Adapter->TotalPacketCount);
f8942e07
SH
1541 }
1542 }
1543 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
f8942e07
SH
1544}
1545
2979460d 1546static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter)
f8942e07 1547{
4fd64dd0 1548 int i;
4fd64dd0 1549 if (netif_msg_link(Adapter))
9ec4475b 1550 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
4fd64dd0
SH
1551
1552 netif_carrier_off(Adapter->dev);
1553 netif_stop_queue(Adapter->dev);
f8942e07
SH
1554
1555 Adapter->IdleMode = FALSE;
1556 Adapter->LinkUpStatus = FALSE;
6a4ef5f9
KM
1557 ClearTargetDSXBuffer(Adapter, 0, TRUE);
1558 /* Delete All Classifier Rules */
f8942e07 1559
6a4ef5f9
KM
1560 for (i = 0; i < HiPriority; i++)
1561 DeleteAllClassifiersForSF(Adapter, i);
f8942e07
SH
1562
1563 flush_all_queues(Adapter);
1564
6a4ef5f9 1565 if (Adapter->TimerActive == TRUE)
f8942e07
SH
1566 Adapter->TimerActive = FALSE;
1567
7f22485d 1568 memset(Adapter->astFragmentedPktClassifierTable, 0, sizeof(struct bcm_fragmented_packet_info) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
f8942e07 1569
6a4ef5f9
KM
1570 for (i = 0; i < HiPriority; i++) {
1571 /* resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF. */
1572 /* It is same between MIBs and SF. */
1573 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable, 0, sizeof(S_MIBS_EXTSERVICEFLOW_PARAMETERS));
f8942e07
SH
1574 }
1575}