Merge branch 'fixes' of git://git.linaro.org/people/rmk/linux-arm
[deliverable/linux.git] / drivers / staging / bcm / Misc.c
CommitLineData
f8942e07
SH
1#include "headers.h"
2
2979460d 3static int BcmFileDownload(struct bcm_mini_adapter *Adapter, const char *path, unsigned int loc);
7a15b79b 4static void doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter);
2979460d
KM
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
7a15b79b 9static void default_wimax_protocol_initialize(struct bcm_mini_adapter *Adapter)
f8942e07 10{
9ef0760f 11 unsigned int 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
7af14134 27int InitAdapter(struct bcm_mini_adapter *psAdapter)
f8942e07 28{
6a4ef5f9 29 int i = 0;
7af14134 30 int Status = STATUS_SUCCESS;
6a4ef5f9 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
7a15b79b 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 187 }
496ad9aa 188 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Opened file is = %s and length =0x%lx to be downloaded at =0x%x", path, (unsigned long)file_inode(flp)->i_size, loc);
6a4ef5f9
KM
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 */
7af14134 219int CopyBufferToControlPacket(struct bcm_mini_adapter *Adapter, void *ioBuffer)
f8942e07 220{
ff352042 221 struct bcm_leader *pLeader = NULL;
7af14134 222 int Status = 0;
895b1fb8 223 unsigned char *ctrl_buff;
9ef0760f 224 unsigned int 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 255
b64c8462 256 if (Adapter->bShutStatus == TRUE) {
6a4ef5f9
KM
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
b64c8462 278 if (Adapter->IdleMode == TRUE) {
6a4ef5f9
KM
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
895b1fb8
KM
328 if (!ctrl_buff) {
329 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "mem allocation Failed");
330 return -ENOMEM;
331 }
332
6a4ef5f9
KM
333 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Control packet to be taken =%d and address is =%pincoming address is =%p and packet len=%x",
334 atomic_read(&Adapter->index_wr_txcntrlpkt), ctrl_buff, ioBuffer, pktlen);
895b1fb8
KM
335
336 if (pLeader) {
337 if ((pLeader->Status == 0x80) ||
338 (pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ)) {
339 /*
340 * Restructure the DSX message to handle Multiple classifier Support
341 * Write the Service Flow param Structures directly to the target
342 * and embed the pointers in the DSX messages sent to target.
343 */
344 /* Lets store the current length of the control packet we are transmitting */
345 pucAddIndication = (PUCHAR)ioBuffer + LEADER_SIZE;
346 pktlen = pLeader->PLength;
347 Status = StoreCmControlResponseMessage(Adapter, pucAddIndication, &pktlen);
348 if (Status != 1) {
7fac0c47 349 ClearTargetDSXBuffer(Adapter, ((struct bcm_add_indication_alt *)pucAddIndication)->u16TID, FALSE);
895b1fb8
KM
350 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, " Error Restoring The DSX Control Packet. Dsx Buffers on Target may not be Setup Properly ");
351 return STATUS_FAILURE;
f8942e07 352 }
895b1fb8
KM
353 /*
354 * update the leader to use the new length
355 * The length of the control packet is length of message being sent + Leader length
356 */
357 pLeader->PLength = pktlen;
f8942e07 358 }
f8942e07 359 }
895b1fb8
KM
360
361 if (pktlen + LEADER_SIZE > MAX_CNTL_PKT_SIZE)
362 return -EINVAL;
363
364 memset(ctrl_buff, 0, pktlen+LEADER_SIZE);
365 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Copying the Control Packet Buffer with length=%d\n", pLeader->PLength);
366 *(struct bcm_leader *)ctrl_buff = *pLeader;
367 memcpy(ctrl_buff + LEADER_SIZE, ((PUCHAR)ioBuffer + LEADER_SIZE), pLeader->PLength);
368 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Enqueuing the Control Packet");
369
370 /* Update the statistics counters */
371 spin_lock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
372 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost += pLeader->PLength;
373 Adapter->PackInfo[HiPriority].uiCurrentPacketsOnHost++;
374 atomic_inc(&Adapter->TotalPacketCount);
375 spin_unlock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
376 Adapter->PackInfo[HiPriority].bValid = TRUE;
377
378 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "CurrBytesOnHost: %x bValid: %x",
379 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost,
380 Adapter->PackInfo[HiPriority].bValid);
381 Status = STATUS_SUCCESS;
382 /*Queue the packet for transmission */
383 atomic_inc(&Adapter->index_wr_txcntrlpkt);
384 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Calling transmit_packets");
385 atomic_set(&Adapter->TxPktAvail, 1);
386 wake_up(&Adapter->tx_packet_wait_queue);
387
6a4ef5f9 388 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<====");
f8942e07
SH
389 return Status;
390}
391
f8942e07
SH
392/******************************************************************
393* Function - LinkMessage()
394*
395* Description - This function builds the Sync-up and Link-up request
6a4ef5f9 396* packet messages depending on the device Link status.
f8942e07
SH
397*
398* Parameters - Adapter: Pointer to the Adapter structure.
399*
400* Returns - None.
401*******************************************************************/
7a15b79b 402void LinkMessage(struct bcm_mini_adapter *Adapter)
f8942e07 403{
2610c7a8 404 struct bcm_link_request *pstLinkRequest = NULL;
6a4ef5f9
KM
405 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>");
406 if (Adapter->LinkStatus == SYNC_UP_REQUEST && Adapter->AutoSyncup) {
2610c7a8 407 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
6a4ef5f9
KM
408 if (!pstLinkRequest) {
409 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
f8942e07
SH
410 return;
411 }
6a4ef5f9
KM
412 /* sync up request... */
413 Adapter->LinkStatus = WAIT_FOR_SYNC; /* current link status */
414 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For SyncUp...");
415 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
416 pstLinkRequest->szData[1] = LINK_SYNC_UP_SUBTYPE;
417 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
418 pstLinkRequest->Leader.PLength = sizeof(ULONG);
f8942e07 419 Adapter->bSyncUpRequestSent = TRUE;
6a4ef5f9
KM
420
421 } else if (Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp) {
2610c7a8 422 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
6a4ef5f9
KM
423 if (!pstLinkRequest) {
424 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
f8942e07
SH
425 return;
426 }
6a4ef5f9
KM
427 /* LINK_UP_REQUEST */
428 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For LinkUp...");
429 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
430 pstLinkRequest->szData[1] = LINK_NET_ENTRY;
431 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
432 pstLinkRequest->Leader.PLength = sizeof(ULONG);
433 }
434 if (pstLinkRequest) {
435 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
f8942e07 436 CopyBufferToControlPacket(Adapter, pstLinkRequest);
082e889b 437 kfree(pstLinkRequest);
f8942e07 438 }
6a4ef5f9 439 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
f8942e07
SH
440 return;
441}
442
f8942e07
SH
443/**********************************************************************
444* Function - StatisticsResponse()
445*
446* Description - This function handles the Statistics response packet.
447*
448* Parameters - Adapter : Pointer to the Adapter structure.
6a4ef5f9 449* - pvBuffer: Starting address of Statistic response data.
f8942e07
SH
450*
451* Returns - None.
452************************************************************************/
7a15b79b 453void StatisticsResponse(struct bcm_mini_adapter *Adapter, void *pvBuffer)
f8942e07 454{
a8a1cdd6 455 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>", __func__);
e39e3be6 456 Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
9ef0760f 457 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (unsigned int)Adapter->StatisticsPointer);
a8a1cdd6 458 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====", __func__);
f8942e07
SH
459 return;
460}
461
f8942e07
SH
462/**********************************************************************
463* Function - LinkControlResponseMessage()
464*
465* Description - This function handles the Link response packets.
466*
467* Parameters - Adapter : Pointer to the Adapter structure.
6a4ef5f9 468* - pucBuffer: Starting address of Link response data.
f8942e07
SH
469*
470* Returns - None.
471***********************************************************************/
7a15b79b 472void LinkControlResponseMessage(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
f8942e07 473{
6a4ef5f9 474 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
f8942e07 475
6a4ef5f9
KM
476 if (*pucBuffer == LINK_UP_ACK) {
477 switch (*(pucBuffer+1)) {
478 case PHY_SYNC_ACHIVED: /* SYNCed UP */
479 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHY_SYNC_ACHIVED");
f8942e07 480
6a4ef5f9 481 if (Adapter->LinkStatus == LINKUP_DONE)
f8942e07 482 beceem_protocol_reset(Adapter);
f8942e07 483
6a4ef5f9
KM
484 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
485 Adapter->LinkStatus = PHY_SYNC_ACHIVED;
f8942e07 486
6a4ef5f9 487 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
f8942e07
SH
488 Adapter->DriverState = NO_NETWORK_ENTRY;
489 wake_up(&Adapter->LEDInfo.notify_led_event);
490 }
491
492 LinkMessage(Adapter);
493 break;
494
6a4ef5f9
KM
495 case LINKUP_DONE:
496 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LINKUP_DONE");
497 Adapter->LinkStatus = LINKUP_DONE;
498 Adapter->bPHSEnabled = *(pucBuffer+3);
499 Adapter->bETHCSEnabled = *(pucBuffer+4) & ETH_CS_MASK;
500 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHS Support Status Received In LinkUp Ack : %x\n", Adapter->bPHSEnabled);
501
502 if ((FALSE == Adapter->bShutStatus) && (FALSE == Adapter->IdleMode)) {
503 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
504 Adapter->DriverState = NORMAL_OPERATION;
505 wake_up(&Adapter->LEDInfo.notify_led_event);
f8942e07 506 }
6a4ef5f9
KM
507 }
508 LinkMessage(Adapter);
509 break;
f8942e07 510
6a4ef5f9
KM
511 case WAIT_FOR_SYNC:
512 /*
513 * Driver to ignore the DREG_RECEIVED
514 * WiMAX Application should handle this Message
515 */
516 /* Adapter->liTimeSinceLastNetEntry = 0; */
517 Adapter->LinkUpStatus = 0;
518 Adapter->LinkStatus = 0;
519 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
520 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
521 Adapter->IdleMode = FALSE;
522 beceem_protocol_reset(Adapter);
f8942e07 523
6a4ef5f9
KM
524 break;
525 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
526 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
527 {
528 HandleShutDownModeRequest(Adapter, pucBuffer);
f8942e07 529 }
6a4ef5f9
KM
530 break;
531 default:
532 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x", *(pucBuffer + 1));
533 break;
534 }
535 } else if (SET_MAC_ADDRESS_RESPONSE == *pucBuffer) {
f8942e07 536 PUCHAR puMacAddr = (pucBuffer + 1);
6a4ef5f9
KM
537 Adapter->LinkStatus = SYNC_UP_REQUEST;
538 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "MAC address response, sending SYNC_UP");
f8942e07
SH
539 LinkMessage(Adapter);
540 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
541 }
a8a1cdd6 542 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====", __func__);
f8942e07
SH
543 return;
544}
545
2979460d 546void SendIdleModeResponse(struct bcm_mini_adapter *Adapter)
f8942e07 547{
7af14134 548 int status = 0, NVMAccess = 0, lowPwrAbortMsg = 0;
f8942e07 549 struct timeval tv;
2610c7a8 550 struct bcm_link_request stIdleResponse = {{0} };
f8942e07 551 memset(&tv, 0, sizeof(tv));
6a4ef5f9 552 stIdleResponse.Leader.Status = IDLE_MESSAGE;
f8942e07
SH
553 stIdleResponse.Leader.PLength = IDLE_MODE_PAYLOAD_LENGTH;
554 stIdleResponse.szData[0] = GO_TO_IDLE_MODE_PAYLOAD;
6a4ef5f9 555 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, " ============>");
f8942e07
SH
556
557 /*********************************
6a4ef5f9
KM
558 *down_trylock -
559 * if [ semaphore is available ]
560 * acquire semaphone and return value 0 ;
561 * else
562 * return non-zero value ;
563 *
564 ***********************************/
f8942e07
SH
565
566 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
6a4ef5f9 567 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
f8942e07 568
f8942e07 569
6a4ef5f9
KM
570 if ((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
571 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)) {
f8942e07 572
6a4ef5f9 573 if (!NVMAccess)
f8942e07
SH
574 up(&Adapter->NVMRdmWrmLock);
575
6a4ef5f9 576 if (!lowPwrAbortMsg)
f8942e07
SH
577 up(&Adapter->LowPowerModeSync);
578
6a4ef5f9
KM
579 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
580 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "HOST IS NACKING Idle mode To F/W!!!!!!!!");
f8942e07 581 Adapter->bPreparingForLowPowerMode = FALSE;
6a4ef5f9
KM
582 } else {
583 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; /* 2; Idle ACK */
f8942e07
SH
584 Adapter->StatisticsPointer = 0;
585
586 /* Wait for the LED to TURN OFF before sending ACK response */
6a4ef5f9 587 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
7af14134 588 int iRetVal = 0;
f8942e07
SH
589
590 /* Wake the LED Thread with IDLEMODE_ENTER State */
591 Adapter->DriverState = LOWPOWER_MODE_ENTER;
6a4ef5f9 592 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LED Thread is Running..Hence Setting LED Event as IDLEMODE_ENTER jiffies:%ld", jiffies);
f8942e07
SH
593 wake_up(&Adapter->LEDInfo.notify_led_event);
594
595 /* Wait for 1 SEC for LED to OFF */
6a4ef5f9 596 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
f8942e07
SH
597
598 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
6a4ef5f9
KM
599 if (iRetVal <= 0) {
600 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
f8942e07
SH
601 Adapter->DriverState = NORMAL_OPERATION;
602 wake_up(&Adapter->LEDInfo.notify_led_event);
6a4ef5f9 603 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "NACKING Idle mode as time out happen from LED side!!!!!!!!");
f8942e07
SH
604 }
605 }
6a4ef5f9
KM
606
607 if (stIdleResponse.szData[1] == TARGET_CAN_GO_TO_IDLE_MODE) {
608 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "ACKING IDLE MODE !!!!!!!!!");
f8942e07
SH
609 down(&Adapter->rdmwrmsync);
610 Adapter->bPreparingForLowPowerMode = TRUE;
611 up(&Adapter->rdmwrmsync);
6a4ef5f9
KM
612 /* Killing all URBS. */
613 if (Adapter->bDoSuspend == TRUE)
d6861cfe 614 Bcm_kill_all_URBs((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
6a4ef5f9 615 } else {
f8942e07
SH
616 Adapter->bPreparingForLowPowerMode = FALSE;
617 }
618
6a4ef5f9 619 if (!NVMAccess)
f8942e07
SH
620 up(&Adapter->NVMRdmWrmLock);
621
6a4ef5f9 622 if (!lowPwrAbortMsg)
f8942e07 623 up(&Adapter->LowPowerModeSync);
f8942e07 624 }
6a4ef5f9
KM
625
626 status = CopyBufferToControlPacket(Adapter, &stIdleResponse);
627 if ((status != STATUS_SUCCESS)) {
628 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "fail to send the Idle mode Request\n");
f8942e07 629 Adapter->bPreparingForLowPowerMode = FALSE;
d6861cfe 630 StartInterruptUrb((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
f8942e07
SH
631 }
632 do_gettimeofday(&tv);
6a4ef5f9 633 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "IdleMode Msg submitter to Q :%ld ms", tv.tv_sec * 1000 + tv.tv_usec / 1000);
f8942e07
SH
634}
635
636/******************************************************************
637* Function - DumpPackInfo()
638*
639* Description - This function dumps the all Queue(PackInfo[]) details.
640*
641* Parameters - Adapter: Pointer to the Adapter structure.
642*
643* Returns - None.
644*******************************************************************/
7a15b79b 645void DumpPackInfo(struct bcm_mini_adapter *Adapter)
f8942e07 646{
9ef0760f
KM
647 unsigned int uiLoopIndex = 0;
648 unsigned int uiIndex = 0;
649 unsigned int uiClsfrIndex = 0;
92562aee 650 struct bcm_classifier_rule *pstClassifierEntry = NULL;
f8942e07 651
6a4ef5f9
KM
652 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
653 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "*********** Showing Details Of Queue %d***** ******", uiLoopIndex);
654 if (FALSE == Adapter->PackInfo[uiLoopIndex].bValid) {
655 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid is FALSE for %X index\n", uiLoopIndex);
f8942e07
SH
656 continue;
657 }
658
6a4ef5f9
KM
659 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " Dumping SF Rule Entry For SFID %lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
660 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " ucDirection %X\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
661
662 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
663 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv6 Service Flow\n");
f8942e07 664 else
6a4ef5f9 665 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv4 Service Flow\n");
f8942e07 666
6a4ef5f9
KM
667 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SF Traffic Priority %X\n", Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
668
669 for (uiClsfrIndex = 0; uiClsfrIndex < MAX_CLASSIFIERS; uiClsfrIndex++) {
f8942e07 670 pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
6a4ef5f9 671 if (!pstClassifierEntry->bUsed)
f8942e07
SH
672 continue;
673
6a4ef5f9 674 if (pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
f8942e07
SH
675 continue;
676
6a4ef5f9
KM
677 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X Classifier Rule ID : %X\n", uiClsfrIndex, pstClassifierEntry->uiClassifierRuleIndex);
678 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X usVCID_Value : %X\n", uiClsfrIndex, pstClassifierEntry->usVCID_Value);
679 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bProtocolValid : %X\n", uiClsfrIndex, pstClassifierEntry->bProtocolValid);
680 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bTOSValid : %X\n", uiClsfrIndex, pstClassifierEntry->bTOSValid);
681 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bDestIpValid : %X\n", uiClsfrIndex, pstClassifierEntry->bDestIpValid);
682 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bSrcIpValid : %X\n", uiClsfrIndex, pstClassifierEntry->bSrcIpValid);
683
684 for (uiIndex = 0; uiIndex < MAX_PORT_RANGE; uiIndex++) {
685 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeLo:%X\n", pstClassifierEntry->usSrcPortRangeLo[uiIndex]);
686 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeHi:%X\n", pstClassifierEntry->usSrcPortRangeHi[uiIndex]);
687 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeLo:%X\n", pstClassifierEntry->usDestPortRangeLo[uiIndex]);
688 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeHi:%X\n", pstClassifierEntry->usDestPortRangeHi[uiIndex]);
f8942e07
SH
689 }
690
6a4ef5f9
KM
691 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPSourceAddressLength : 0x%x\n", pstClassifierEntry->ucIPSourceAddressLength);
692 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPDestinationAddressLength : 0x%x\n", pstClassifierEntry->ucIPDestinationAddressLength);
693 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPSourceAddressLength; uiIndex++) {
694 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
695 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpAddr :\n");
f8942e07 696 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Addr);
6a4ef5f9 697 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpMask :\n");
f8942e07 698 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Mask);
6a4ef5f9
KM
699 } else {
700 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpAddr:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Addr[uiIndex]);
701 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpMask:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Mask[uiIndex]);
f8942e07
SH
702 }
703 }
6a4ef5f9
KM
704
705 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPDestinationAddressLength; uiIndex++) {
706 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
707 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpAddr :\n");
f8942e07 708 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Addr);
6a4ef5f9 709 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpMask :\n");
f8942e07 710 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Mask);
6a4ef5f9
KM
711 } else {
712 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpAddr:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Addr[uiIndex]);
713 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpMask:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Mask[uiIndex]);
f8942e07
SH
714 }
715 }
6a4ef5f9
KM
716 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucProtocol:0x%X\n", pstClassifierEntry->ucProtocol[0]);
717 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tu8ClassifierRulePriority:%X\n", pstClassifierEntry->u8ClassifierRulePriority);
f8942e07 718 }
6a4ef5f9
KM
719 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ulSFID:%lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
720 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "usVCID_Value:%X\n", Adapter->PackInfo[uiLoopIndex].usVCID_Value);
721 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "PhsEnabled: 0x%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
722 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThreshold:%X\n", Adapter->PackInfo[uiLoopIndex].uiThreshold);
723
724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid:%X\n", Adapter->PackInfo[uiLoopIndex].bValid);
725 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bActive:%X\n", Adapter->PackInfo[uiLoopIndex].bActive);
726 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActivateReqSent: %x", Adapter->PackInfo[uiLoopIndex].bActivateRequestSent);
727 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "u8QueueType:%X\n", Adapter->PackInfo[uiLoopIndex].u8QueueType);
728 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxBucketSize:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize);
729 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPerSFTxResourceCount:%X\n", atomic_read(&Adapter->PackInfo[uiLoopIndex].uiPerSFTxResourceCount));
730 /* DumpDebug(DUMP_INFO,("bCSSupport:%X\n",Adapter->PackInfo[uiLoopIndex].bCSSupport)); */
731 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CurrQueueDepthOnTarget: %x\n", Adapter->PackInfo[uiLoopIndex].uiCurrentQueueDepthOnTarget);
732 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentBytesOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentBytesOnHost);
733 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentPacketsOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentPacketsOnHost);
734 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountBytes);
735 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountPackets);
736 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentBytes);
737 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentPackets);
738 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentDrainRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentDrainRate);
739 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThisPeriodSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiThisPeriodSentBytes);
740 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liDrainCalculated:%llX\n", Adapter->PackInfo[uiLoopIndex].liDrainCalculated);
741 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentTokenCount:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentTokenCount);
742 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liLastUpdateTokenAt:%llX\n", Adapter->PackInfo[uiLoopIndex].liLastUpdateTokenAt);
743 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxAllowedRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate);
744 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPendedLast:%X\n", Adapter->PackInfo[uiLoopIndex].uiPendedLast);
745 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "NumOfPacketsSent:%X\n", Adapter->PackInfo[uiLoopIndex].NumOfPacketsSent);
746 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Direction: %x\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
747 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CID: %x\n", Adapter->PackInfo[uiLoopIndex].usCID);
748 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ProtocolValid: %x\n", Adapter->PackInfo[uiLoopIndex].bProtocolValid);
749 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "TOSValid: %x\n", Adapter->PackInfo[uiLoopIndex].bTOSValid);
750 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "DestIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bDestIpValid);
751 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SrcIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bSrcIpValid);
752 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActiveSet: %x\n", Adapter->PackInfo[uiLoopIndex].bActiveSet);
753 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AdmittedSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAdmittedSet);
754 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AuthzSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAuthorizedSet);
755 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ClassifyPrority: %x\n", Adapter->PackInfo[uiLoopIndex].bClassifierPriority);
756 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxLatency: %x\n", Adapter->PackInfo[uiLoopIndex].uiMaxLatency);
bcb6ef66
AS
757 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO,
758 DBG_LVL_ALL, "ServiceClassName: %*ph\n",
759 4, Adapter->PackInfo[uiLoopIndex].
760 ucServiceClassName);
6a4ef5f9
KM
761/* BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bHeaderSuppressionEnabled :%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
762 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalTxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalTxBytes);
763 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalRxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalRxBytes);
764 * DumpDebug(DUMP_INFO,(" uiRanOutOfResCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiRanOutOfResCount));
765 */
766 }
767
768 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
769 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aRxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aRxPktSizeHist[uiLoopIndex]);
770
771 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
772 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aTxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aTxPktSizeHist[uiLoopIndex]);
f8942e07
SH
773
774 return;
f8942e07
SH
775}
776
2979460d 777int reset_card_proc(struct bcm_mini_adapter *ps_adapter)
f8942e07
SH
778{
779 int retval = STATUS_SUCCESS;
2979460d 780 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
d6861cfe 781 struct bcm_interface_adapter *psIntfAdapter = NULL;
f8942e07 782 unsigned int value = 0, uiResetValue = 0;
41c7b7c0 783 int bytes;
f8942e07 784
d6861cfe 785 psIntfAdapter = ((struct bcm_interface_adapter *)(ps_adapter->pvInterfaceAdapter));
f8942e07
SH
786 ps_adapter->bDDRInitDone = FALSE;
787
6a4ef5f9
KM
788 if (ps_adapter->chip_id >= T3LPB) {
789 /* SYS_CFG register is write protected hence for modifying this reg value, it should be read twice before */
790 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
791 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
f8942e07 792
6a4ef5f9
KM
793 /* making bit[6...5] same as was before f/w download. this setting force the h/w to */
794 /* re-populated the SP RAM area with the string descriptor. */
795 value = value | (ps_adapter->syscfgBefFwDld & 0x00000060);
f8942e07
SH
796 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
797 }
798
6a4ef5f9
KM
799 /* killing all submitted URBs. */
800 psIntfAdapter->psAdapter->StopAllXaction = TRUE;
f8942e07 801 Bcm_kill_all_URBs(psIntfAdapter);
f8942e07 802 /* Reset the UMA-B Device */
6a4ef5f9 803 if (ps_adapter->chip_id >= T3LPB) {
73e29189 804 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Resetting UMA-B\n");
f8942e07 805 retval = usb_reset_device(psIntfAdapter->udev);
6a4ef5f9 806 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
f8942e07 807
6a4ef5f9
KM
808 if (retval != STATUS_SUCCESS) {
809 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
f8942e07
SH
810 goto err_exit;
811 }
6a4ef5f9 812
f8942e07
SH
813 if (ps_adapter->chip_id == BCS220_2 ||
814 ps_adapter->chip_id == BCS220_2BC ||
815 ps_adapter->chip_id == BCS250_BC ||
6a4ef5f9
KM
816 ps_adapter->chip_id == BCS220_3) {
817
41c7b7c0
KM
818 bytes = rdmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
819 if (bytes < 0) {
820 retval = bytes;
6a4ef5f9 821 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
f8942e07
SH
822 goto err_exit;
823 }
6a4ef5f9 824 /* setting 0th bit */
f8942e07
SH
825 value |= (1<<0);
826 retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
6a4ef5f9
KM
827 if (retval < 0) {
828 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
f8942e07
SH
829 goto err_exit;
830 }
831 }
6a4ef5f9 832 } else {
41c7b7c0
KM
833 bytes = rdmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
834 if (bytes < 0) {
835 retval = bytes;
6a4ef5f9 836 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
f8942e07
SH
837 goto err_exit;
838 }
6a4ef5f9
KM
839 value &= (~(1<<16));
840 retval = wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
841 if (retval < 0) {
842 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
f8942e07
SH
843 goto err_exit;
844 }
845
6a4ef5f9 846 /* Toggling the GPIO 8, 9 */
f8942e07
SH
847 value = 0;
848 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
6a4ef5f9
KM
849 if (retval < 0) {
850 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
f8942e07
SH
851 goto err_exit;
852 }
853 value = 0x300;
6a4ef5f9
KM
854 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value));
855 if (retval < 0) {
856 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
f8942e07
SH
857 goto err_exit;
858 }
859 mdelay(50);
860 }
861
6a4ef5f9
KM
862 /* ps_adapter->downloadDDR = false; */
863 if (ps_adapter->bFlashBoot) {
864 /* In flash boot mode MIPS state register has reverse polarity.
865 * So just or with setting bit 30.
866 * Make the MIPS in Reset state.
867 */
f8942e07 868 rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
6a4ef5f9 869 uiResetValue |= (1<<30);
f8942e07
SH
870 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
871 }
872
6a4ef5f9 873 if (ps_adapter->chip_id >= T3LPB) {
f8942e07 874 uiResetValue = 0;
6a4ef5f9
KM
875 /*
876 * WA for SYSConfig Issue.
877 * Read SYSCFG Twice to make it writable.
878 */
f8942e07 879 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
6a4ef5f9 880 if (uiResetValue & (1<<4)) {
f8942e07 881 uiResetValue = 0;
6a4ef5f9 882 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue)); /* 2nd read to make it writable. */
f8942e07 883 uiResetValue &= (~(1<<4));
6a4ef5f9 884 wrmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
f8942e07 885 }
f8942e07
SH
886 }
887 uiResetValue = 0;
888 wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
889
6a4ef5f9
KM
890err_exit:
891 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
f8942e07
SH
892 return retval;
893}
894
2979460d 895int run_card_proc(struct bcm_mini_adapter *ps_adapter)
f8942e07 896{
41c7b7c0
KM
897 int status = STATUS_SUCCESS;
898 int bytes;
899
6a4ef5f9 900 unsigned int value = 0;
f8942e07 901 {
41c7b7c0
KM
902 bytes = rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value));
903 if (bytes < 0) {
904 status = bytes;
a8a1cdd6 905 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
41c7b7c0 906 return status;
f8942e07
SH
907 }
908
6a4ef5f9
KM
909 if (ps_adapter->bFlashBoot)
910 value &= (~(1<<30));
f8942e07 911 else
6a4ef5f9 912 value |= (1<<30);
f8942e07 913
6a4ef5f9 914 if (wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
a8a1cdd6 915 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
f8942e07
SH
916 return STATUS_FAILURE;
917 }
918 }
41c7b7c0 919 return status;
f8942e07
SH
920}
921
2979460d 922int InitCardAndDownloadFirmware(struct bcm_mini_adapter *ps_adapter)
f8942e07 923{
2e316139 924 int status;
9ef0760f 925 unsigned int value = 0;
f8942e07 926 /*
6a4ef5f9
KM
927 * Create the threads first and then download the
928 * Firm/DDR Settings..
929 */
2d08748a 930 status = create_worker_threads(ps_adapter);
6a4ef5f9 931 if (status < 0)
f8942e07 932 return status;
2d08748a 933
6a4ef5f9
KM
934 status = bcm_parse_target_params(ps_adapter);
935 if (status)
f8942e07 936 return status;
f8942e07 937
6a4ef5f9
KM
938 if (ps_adapter->chip_id >= T3LPB) {
939 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
940 ps_adapter->syscfgBefFwDld = value;
941
942 if ((value & 0x60) == 0)
f8942e07 943 ps_adapter->bFlashBoot = TRUE;
f8942e07
SH
944 }
945
946 reset_card_proc(ps_adapter);
947
6a4ef5f9 948 /* Initializing the NVM. */
f8942e07
SH
949 BcmInitNVM(ps_adapter);
950 status = ddr_init(ps_adapter);
6a4ef5f9 951 if (status) {
2d08748a 952 pr_err(DRV_NAME "ddr_init Failed\n");
f8942e07
SH
953 return status;
954 }
955
956 /* Download cfg file */
957 status = buffDnldVerify(ps_adapter,
6a4ef5f9 958 (PUCHAR)ps_adapter->pstargetparams,
c8182334 959 sizeof(struct bcm_target_params),
6a4ef5f9
KM
960 CONFIG_BEGIN_ADDR);
961 if (status) {
962 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
f8942e07
SH
963 goto OUT;
964 }
f8942e07 965
6a4ef5f9
KM
966 if (register_networkdev(ps_adapter)) {
967 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
f8942e07
SH
968 return -EIO;
969 }
970
6a4ef5f9
KM
971 if (FALSE == ps_adapter->AutoFirmDld) {
972 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoFirmDld Disabled in CFG File..\n");
973 /* If Auto f/w download is disable, register the control interface, */
974 /* register the control interface after the mailbox. */
975 if (register_control_device_interface(ps_adapter) < 0) {
976 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
f8942e07
SH
977 return -EIO;
978 }
f8942e07
SH
979 return STATUS_SUCCESS;
980 }
981
982 /*
6a4ef5f9
KM
983 * Do the LED Settings here. It will be used by the Firmware Download
984 * Thread.
985 */
f8942e07
SH
986
987 /*
6a4ef5f9
KM
988 * 1. If the LED Settings fails, do not stop and do the Firmware download.
989 * 2. This init would happened only if the cfg file is present, else
990 * call from the ioctl context.
991 */
f8942e07 992
6a4ef5f9
KM
993 status = InitLedSettings(ps_adapter);
994 if (status) {
995 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_PRINTK, 0, 0, "INIT LED FAILED\n");
f8942e07
SH
996 return status;
997 }
6a4ef5f9
KM
998
999 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
f8942e07
SH
1000 ps_adapter->DriverState = DRIVER_INIT;
1001 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1002 }
1003
6a4ef5f9 1004 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
f8942e07
SH
1005 ps_adapter->DriverState = FW_DOWNLOAD;
1006 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1007 }
1008
1009 value = 0;
1010 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1011 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1012
6a4ef5f9 1013 if (ps_adapter->eNVMType == NVM_FLASH) {
f8942e07 1014 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
6a4ef5f9
KM
1015 if (status) {
1016 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Propagation of Cal param failed ..");
f8942e07
SH
1017 goto OUT;
1018 }
1019 }
f8942e07
SH
1020
1021 /* Download Firmare */
d491061b
KM
1022 status = BcmFileDownload(ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR);
1023 if (status != 0) {
6a4ef5f9 1024 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Firmware File is present...\n");
f8942e07
SH
1025 goto OUT;
1026 }
1027
f8942e07 1028 status = run_card_proc(ps_adapter);
6a4ef5f9
KM
1029 if (status) {
1030 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "run_card_proc Failed\n");
f8942e07
SH
1031 goto OUT;
1032 }
1033
f8942e07
SH
1034 ps_adapter->fw_download_done = TRUE;
1035 mdelay(10);
1036
1037OUT:
6a4ef5f9 1038 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
f8942e07
SH
1039 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1040 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1041 }
1042
f8942e07
SH
1043 return status;
1044}
1045
2979460d 1046static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter)
f8942e07 1047{
6a4ef5f9 1048 struct file *flp = NULL;
3701befc 1049 char *buff;
f8942e07 1050 int len = 0;
f8942e07 1051
6a4ef5f9
KM
1052 buff = kmalloc(BUFFER_1K, GFP_KERNEL);
1053 if (!buff)
f8942e07 1054 return -ENOMEM;
6a4ef5f9 1055
c8182334 1056 Adapter->pstargetparams = kmalloc(sizeof(struct bcm_target_params), GFP_KERNEL);
9d4f1d0c 1057 if (Adapter->pstargetparams == NULL) {
082e889b 1058 kfree(buff);
f8942e07
SH
1059 return -ENOMEM;
1060 }
6a4ef5f9
KM
1061
1062 flp = open_firmware_file(Adapter, CFG_FILE);
1063 if (!flp) {
1064 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE\n", CFG_FILE);
082e889b
SH
1065 kfree(buff);
1066 kfree(Adapter->pstargetparams);
f8942e07
SH
1067 Adapter->pstargetparams = NULL;
1068 return -ENOENT;
1069 }
32aecdd3
AV
1070 len = kernel_read(flp, 0, buff, BUFFER_1K);
1071 filp_close(flp, NULL);
f8942e07 1072
c8182334 1073 if (len != sizeof(struct bcm_target_params)) {
6a4ef5f9 1074 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n");
082e889b
SH
1075 kfree(buff);
1076 kfree(Adapter->pstargetparams);
f8942e07 1077 Adapter->pstargetparams = NULL;
f8942e07
SH
1078 return -ENOENT;
1079 }
f8942e07
SH
1080
1081 /* Check for autolink in config params */
1082 /*
1083 * Values in Adapter->pstargetparams are in network byte order
1084 */
c8182334 1085 memcpy(Adapter->pstargetparams, buff, sizeof(struct bcm_target_params));
6a4ef5f9 1086 kfree(buff);
f8942e07 1087 beceem_parse_target_struct(Adapter);
f8942e07
SH
1088 return STATUS_SUCCESS;
1089}
1090
2979460d 1091void beceem_parse_target_struct(struct bcm_mini_adapter *Adapter)
f8942e07 1092{
9ef0760f 1093 unsigned int uiHostDrvrCfg6 = 0, uiEEPROMFlag = 0;
f8942e07 1094
6a4ef5f9 1095 if (ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE) {
2d08748a 1096 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
f8942e07 1097 Adapter->AutoSyncup = FALSE;
6a4ef5f9 1098 } else {
2d08748a 1099 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
6a4ef5f9 1100 Adapter->AutoSyncup = TRUE;
f8942e07 1101 }
2d08748a 1102
6a4ef5f9 1103 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE) {
2d08748a 1104 pr_info(DRV_NAME ": Enabling autolink up");
f8942e07 1105 Adapter->AutoLinkUp = TRUE;
6a4ef5f9 1106 } else {
2d08748a 1107 pr_info(DRV_NAME ": Disabling autolink up");
f8942e07
SH
1108 Adapter->AutoLinkUp = FALSE;
1109 }
6a4ef5f9
KM
1110 /* Setting the DDR Setting.. */
1111 Adapter->DDRSetting = (ntohl(Adapter->pstargetparams->HostDrvrConfig6) >> 8)&0x0F;
1112 Adapter->ulPowerSaveMode = (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
2d08748a
SH
1113 pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1114 pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
6a4ef5f9
KM
1115 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD) {
1116 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1117 Adapter->AutoFirmDld = TRUE;
1118 } else {
1119 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1120 Adapter->AutoFirmDld = FALSE;
1121 }
f8942e07
SH
1122 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1123 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
6a4ef5f9
KM
1124 pr_info(DRV_NAME ": MIPSConfig : 0x%X\n", Adapter->bMipsConfig);
1125 /* used for backward compatibility. */
f8942e07 1126 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
6a4ef5f9 1127 Adapter->PmuMode = (uiHostDrvrCfg6 >> 24) & 0x03;
2d08748a 1128 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
f8942e07 1129
6a4ef5f9
KM
1130 if ((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT) & (0x01)) {
1131 Adapter->bDoSuspend = TRUE;
1132 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1133 }
f8942e07
SH
1134
1135 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
6a4ef5f9 1136 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n", uiEEPROMFlag);
af72c617 1137 Adapter->eNVMType = (enum bcm_nvm_type)((uiEEPROMFlag>>4)&0x3);
f8942e07 1138 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
f8942e07 1139 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
6a4ef5f9 1140 Adapter->bSectorSizeOverride = (bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
f8942e07 1141
6a4ef5f9 1142 if (ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x01)
f8942e07 1143 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
2d08748a 1144
6a4ef5f9 1145 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
f8942e07 1146 doPowerAutoCorrection(Adapter);
f8942e07
SH
1147}
1148
7a15b79b 1149static void doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter)
f8942e07 1150{
9ef0760f 1151 unsigned int reporting_mode;
f8942e07 1152
6a4ef5f9 1153 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x02;
f8942e07
SH
1154 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1155
6a4ef5f9
KM
1156 if (reporting_mode == TRUE) {
1157 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "can't do suspen/resume as reporting mode is enable");
f8942e07
SH
1158 psAdapter->bDoSuspend = FALSE;
1159 }
1160
6a4ef5f9
KM
1161 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB)) {
1162 /* If reporting mode is enable, switch PMU to PMC */
f8942e07
SH
1163 {
1164 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
6a4ef5f9 1165 psAdapter->bDoSuspend = FALSE;
f8942e07
SH
1166 }
1167
6a4ef5f9 1168 /* clearing space bit[15..12] */
f8942e07 1169 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl((0xF << 12)));
6a4ef5f9 1170 /* placing the power save mode option */
f8942e07 1171 psAdapter->pstargetparams->HostDrvrConfig6 |= htonl((psAdapter->ulPowerSaveMode << 12));
6a4ef5f9
KM
1172 } else if (psAdapter->bIsAutoCorrectEnabled == FALSE) {
1173 /* remove the autocorrect disable bit set before dumping. */
f8942e07
SH
1174 psAdapter->ulPowerSaveMode &= ~(1 << 3);
1175 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl(1 << 15));
6a4ef5f9 1176 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Using Forced User Choice: %lx\n", psAdapter->ulPowerSaveMode);
f8942e07
SH
1177 }
1178}
44a17eff 1179
9ef0760f 1180static void convertEndian(unsigned char rwFlag, unsigned int *puiBuffer, unsigned int uiByteCount)
f8942e07 1181{
9ef0760f 1182 unsigned int uiIndex = 0;
f8942e07 1183
6a4ef5f9 1184 if (RWM_WRITE == rwFlag) {
9ef0760f 1185 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(unsigned int)); uiIndex++)
f8942e07 1186 puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
f8942e07 1187 } else {
9ef0760f 1188 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(unsigned int)); uiIndex++)
f8942e07 1189 puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
f8942e07
SH
1190 }
1191}
1192
9ef0760f 1193int rdm(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
f8942e07 1194{
c5274ab0 1195 return Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
6a4ef5f9 1196 uiAddress, pucBuff, sSize);
f8942e07 1197}
c5274ab0 1198
9ef0760f 1199int wrm(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
f8942e07
SH
1200{
1201 int iRetVal;
1202
f8942e07 1203 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
6a4ef5f9 1204 uiAddress, pucBuff, sSize);
f8942e07
SH
1205 return iRetVal;
1206}
1207
9ef0760f 1208int wrmalt(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
f8942e07
SH
1209{
1210 convertEndian(RWM_WRITE, pucBuff, size);
1211 return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1212}
1213
9ef0760f 1214int rdmalt(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
f8942e07 1215{
7af14134 1216 int uiRetVal = 0;
f8942e07 1217
6a4ef5f9 1218 uiRetVal = rdm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
b23f7f6f 1219 convertEndian(RWM_READ, (unsigned int *)pucBuff, size);
f8942e07
SH
1220
1221 return uiRetVal;
1222}
1223
9ef0760f 1224int wrmWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
f8942e07 1225{
7af14134 1226 int status = STATUS_SUCCESS;
f8942e07
SH
1227 down(&Adapter->rdmwrmsync);
1228
6a4ef5f9
KM
1229 if ((Adapter->IdleMode == TRUE) ||
1230 (Adapter->bShutStatus == TRUE) ||
1231 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1232
f8942e07
SH
1233 status = -EACCES;
1234 goto exit;
1235 }
1236
6a4ef5f9 1237 status = wrm(Adapter, uiAddress, pucBuff, sSize);
f8942e07
SH
1238exit:
1239 up(&Adapter->rdmwrmsync);
6a4ef5f9 1240 return status;
f8942e07
SH
1241}
1242
9ef0760f 1243int wrmaltWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
f8942e07
SH
1244{
1245 int iRetVal = STATUS_SUCCESS;
1246
1247 down(&Adapter->rdmwrmsync);
1248
6a4ef5f9
KM
1249 if ((Adapter->IdleMode == TRUE) ||
1250 (Adapter->bShutStatus == TRUE) ||
1251 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1252
f8942e07
SH
1253 iRetVal = -EACCES;
1254 goto exit;
1255 }
1256
6a4ef5f9 1257 iRetVal = wrmalt(Adapter, uiAddress, pucBuff, size);
f8942e07
SH
1258exit:
1259 up(&Adapter->rdmwrmsync);
1260 return iRetVal;
1261}
1262
9ef0760f 1263int rdmaltWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
f8942e07 1264{
7af14134 1265 int uiRetVal = STATUS_SUCCESS;
f8942e07
SH
1266
1267 down(&Adapter->rdmwrmsync);
6a4ef5f9
KM
1268 if ((Adapter->IdleMode == TRUE) ||
1269 (Adapter->bShutStatus == TRUE) ||
1270 (Adapter->bPreparingForLowPowerMode == TRUE)) {
f8942e07 1271
f8942e07
SH
1272 uiRetVal = -EACCES;
1273 goto exit;
1274 }
1275
6a4ef5f9 1276 uiRetVal = rdmalt(Adapter, uiAddress, pucBuff, size);
f8942e07
SH
1277exit:
1278 up(&Adapter->rdmwrmsync);
1279 return uiRetVal;
1280}
1281
7a15b79b 1282static void HandleShutDownModeWakeup(struct bcm_mini_adapter *Adapter)
f8942e07 1283{
6a4ef5f9
KM
1284 int clear_abort_pattern = 0, Status = 0;
1285 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1286 /* target has woken up From Shut Down */
1287 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Clearing Shut Down Software abort pattern\n");
b23f7f6f 1288 Status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC, (unsigned int *)&clear_abort_pattern, sizeof(clear_abort_pattern));
6a4ef5f9
KM
1289 if (Status) {
1290 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
f8942e07
SH
1291 return;
1292 }
6a4ef5f9
KM
1293
1294 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) {
f8942e07
SH
1295 msleep(100);
1296 InterfaceHandleShutdownModeWakeup(Adapter);
1297 msleep(100);
1298 }
6a4ef5f9
KM
1299
1300 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
f8942e07
SH
1301 Adapter->DriverState = NO_NETWORK_ENTRY;
1302 wake_up(&Adapter->LEDInfo.notify_led_event);
1303 }
1304
1305 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
1306 Adapter->bShutStatus = FALSE;
1307 wake_up(&Adapter->lowpower_mode_wait_queue);
6a4ef5f9 1308 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
f8942e07
SH
1309}
1310
7a15b79b 1311static void SendShutModeResponse(struct bcm_mini_adapter *Adapter)
f8942e07 1312{
2610c7a8 1313 struct bcm_link_request stShutdownResponse;
9ef0760f
KM
1314 unsigned int NVMAccess = 0, lowPwrAbortMsg = 0;
1315 unsigned int Status = 0;
f8942e07 1316
2610c7a8 1317 memset(&stShutdownResponse, 0, sizeof(struct bcm_link_request));
f8942e07 1318 stShutdownResponse.Leader.Status = LINK_UP_CONTROL_REQ;
6a4ef5f9 1319 stShutdownResponse.Leader.PLength = 8; /* 8 bytes; */
f8942e07
SH
1320 stShutdownResponse.szData[0] = LINK_UP_ACK;
1321 stShutdownResponse.szData[1] = LINK_SHUTDOWN_REQ_FROM_FIRMWARE;
1322
1323 /*********************************
6a4ef5f9
KM
1324 * down_trylock -
1325 * if [ semaphore is available ]
1326 * acquire semaphone and return value 0 ;
1327 * else
1328 * return non-zero value ;
1329 *
1330 ***********************************/
f8942e07
SH
1331
1332 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
6a4ef5f9 1333 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
f8942e07 1334
6a4ef5f9
KM
1335 if (NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) {
1336 if (!NVMAccess)
f8942e07
SH
1337 up(&Adapter->NVMRdmWrmLock);
1338
6a4ef5f9 1339 if (!lowPwrAbortMsg)
f8942e07
SH
1340 up(&Adapter->LowPowerModeSync);
1341
6a4ef5f9
KM
1342 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Device Access is going on NACK the Shut Down MODE\n");
1343 stShutdownResponse.szData[2] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
f8942e07 1344 Adapter->bPreparingForLowPowerMode = FALSE;
6a4ef5f9
KM
1345 } else {
1346 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Sending SHUTDOWN MODE ACK\n");
1347 stShutdownResponse.szData[2] = SHUTDOWN_ACK_FROM_DRIVER; /* ShutDown ACK */
f8942e07
SH
1348
1349 /* Wait for the LED to TURN OFF before sending ACK response */
6a4ef5f9 1350 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
7af14134 1351 int iRetVal = 0;
f8942e07
SH
1352
1353 /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1354 Adapter->DriverState = LOWPOWER_MODE_ENTER;
1355 wake_up(&Adapter->LEDInfo.notify_led_event);
1356
1357 /* Wait for 1 SEC for LED to OFF */
6a4ef5f9 1358 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
f8942e07
SH
1359
1360 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
6a4ef5f9
KM
1361 if (iRetVal <= 0) {
1362 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
f8942e07
SH
1363 Adapter->DriverState = NO_NETWORK_ENTRY;
1364 wake_up(&Adapter->LEDInfo.notify_led_event);
1365 }
1366 }
1367
6a4ef5f9
KM
1368 if (stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER) {
1369 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ACKING SHUTDOWN MODE !!!!!!!!!");
f8942e07
SH
1370 down(&Adapter->rdmwrmsync);
1371 Adapter->bPreparingForLowPowerMode = TRUE;
1372 up(&Adapter->rdmwrmsync);
6a4ef5f9
KM
1373 /* Killing all URBS. */
1374 if (Adapter->bDoSuspend == TRUE)
d6861cfe 1375 Bcm_kill_all_URBs((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
6a4ef5f9 1376 } else {
f8942e07
SH
1377 Adapter->bPreparingForLowPowerMode = FALSE;
1378 }
1379
6a4ef5f9 1380 if (!NVMAccess)
f8942e07
SH
1381 up(&Adapter->NVMRdmWrmLock);
1382
6a4ef5f9 1383 if (!lowPwrAbortMsg)
f8942e07
SH
1384 up(&Adapter->LowPowerModeSync);
1385 }
f8942e07 1386
6a4ef5f9
KM
1387 Status = CopyBufferToControlPacket(Adapter, &stShutdownResponse);
1388 if ((Status != STATUS_SUCCESS)) {
1389 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "fail to send the Idle mode Request\n");
1390 Adapter->bPreparingForLowPowerMode = FALSE;
d6861cfe 1391 StartInterruptUrb((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
f8942e07
SH
1392 }
1393}
1394
2979460d 1395static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
f8942e07 1396{
7052208b 1397 unsigned int uiResetValue = 0;
f8942e07 1398
6a4ef5f9 1399 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
f8942e07 1400
6a4ef5f9 1401 if (*(pucBuffer+1) == COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW) {
f8942e07 1402 HandleShutDownModeWakeup(Adapter);
6a4ef5f9
KM
1403 } else if (*(pucBuffer+1) == LINK_SHUTDOWN_REQ_FROM_FIRMWARE) {
1404 /* Target wants to go to Shut Down Mode */
1405 /* InterfacePrepareForShutdown(Adapter); */
1406 if (Adapter->chip_id == BCS220_2 ||
1407 Adapter->chip_id == BCS220_2BC ||
1408 Adapter->chip_id == BCS250_BC ||
1409 Adapter->chip_id == BCS220_3) {
1410
1411 rdmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
f8942e07
SH
1412 uiResetValue |= (1<<17);
1413 wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1414 }
1415
1416 SendShutModeResponse(Adapter);
7af14134 1417 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ShutDownModeResponse:Notification received: Sending the response(Ack/Nack)\n");
f8942e07
SH
1418 }
1419
6a4ef5f9 1420 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
f8942e07 1421 return;
f8942e07
SH
1422}
1423
7a15b79b 1424void ResetCounters(struct bcm_mini_adapter *Adapter)
f8942e07 1425{
6a4ef5f9 1426 beceem_protocol_reset(Adapter);
f8942e07 1427 Adapter->CurrNumRecvDescs = 0;
6a4ef5f9
KM
1428 Adapter->PrevNumRecvDescs = 0;
1429 Adapter->LinkUpStatus = 0;
f8942e07 1430 Adapter->LinkStatus = 0;
6a4ef5f9
KM
1431 atomic_set(&Adapter->cntrlpktCnt, 0);
1432 atomic_set(&Adapter->TotalPacketCount, 0);
1433 Adapter->fw_download_done = FALSE;
f8942e07 1434 Adapter->LinkStatus = 0;
6a4ef5f9 1435 Adapter->AutoLinkUp = FALSE;
f8942e07
SH
1436 Adapter->IdleMode = FALSE;
1437 Adapter->bShutStatus = FALSE;
f8942e07 1438}
6a4ef5f9 1439
2979460d 1440struct bcm_classifier_rule *GetFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIP)
f8942e07 1441{
9ef0760f 1442 unsigned int uiIndex = 0;
6a4ef5f9
KM
1443 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1444 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1445 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1446 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIP) &&
f8942e07 1447 !Adapter->astFragmentedPktClassifierTable[uiIndex].bOutOfOrderFragment)
6a4ef5f9 1448
f8942e07
SH
1449 return Adapter->astFragmentedPktClassifierTable[uiIndex].pstMatchedClassifierEntry;
1450 }
1451 return NULL;
1452}
1453
2979460d 1454void AddFragIPClsEntry(struct bcm_mini_adapter *Adapter, struct bcm_fragmented_packet_info *psFragPktInfo)
f8942e07 1455{
9ef0760f 1456 unsigned int uiIndex = 0;
6a4ef5f9
KM
1457 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1458 if (!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) {
7f22485d 1459 memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex], psFragPktInfo, sizeof(struct bcm_fragmented_packet_info));
f8942e07
SH
1460 break;
1461 }
1462 }
f8942e07
SH
1463}
1464
2979460d 1465void DelFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIp)
f8942e07 1466{
9ef0760f 1467 unsigned int uiIndex = 0;
6a4ef5f9
KM
1468 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1469 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1470 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1471 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIp))
1472
7f22485d 1473 memset(&Adapter->astFragmentedPktClassifierTable[uiIndex], 0, sizeof(struct bcm_fragmented_packet_info));
f8942e07
SH
1474 }
1475}
1476
2979460d 1477void update_per_cid_rx(struct bcm_mini_adapter *Adapter)
f8942e07 1478{
9ef0760f 1479 unsigned int qindex = 0;
f8942e07 1480
6a4ef5f9 1481 if ((jiffies - Adapter->liDrainCalculated) < XSECONDS)
f8942e07
SH
1482 return;
1483
6a4ef5f9
KM
1484 for (qindex = 0; qindex < HiPriority; qindex++) {
1485 if (Adapter->PackInfo[qindex].ucDirection == 0) {
f8942e07
SH
1486 Adapter->PackInfo[qindex].uiCurrentRxRate =
1487 (Adapter->PackInfo[qindex].uiCurrentRxRate +
6a4ef5f9 1488 Adapter->PackInfo[qindex].uiThisPeriodRxBytes) / 2;
f8942e07
SH
1489
1490 Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
6a4ef5f9 1491 } else {
f8942e07
SH
1492 Adapter->PackInfo[qindex].uiCurrentDrainRate =
1493 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
6a4ef5f9
KM
1494 Adapter->PackInfo[qindex].uiThisPeriodSentBytes) / 2;
1495 Adapter->PackInfo[qindex].uiThisPeriodSentBytes = 0;
f8942e07
SH
1496 }
1497 }
6a4ef5f9 1498 Adapter->liDrainCalculated = jiffies;
f8942e07 1499}
6a4ef5f9 1500
2979460d 1501void update_per_sf_desc_cnts(struct bcm_mini_adapter *Adapter)
f8942e07 1502{
7af14134 1503 int iIndex = 0;
f8942e07 1504 u32 uibuff[MAX_TARGET_DSX_BUFFERS];
41c7b7c0 1505 int bytes;
f8942e07 1506
6a4ef5f9 1507 if (!atomic_read(&Adapter->uiMBupdate))
f8942e07
SH
1508 return;
1509
9ef0760f 1510 bytes = rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (unsigned int *)uibuff, sizeof(unsigned int) * MAX_TARGET_DSX_BUFFERS);
41c7b7c0 1511 if (bytes < 0) {
6a4ef5f9 1512 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
f8942e07
SH
1513 return;
1514 }
6a4ef5f9
KM
1515
1516 for (iIndex = 0; iIndex < HiPriority; iIndex++) {
1517 if (Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection) {
1518 if (Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
f8942e07 1519 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
f8942e07 1520 else
6a4ef5f9 1521 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid VCID : %x\n", Adapter->PackInfo[iIndex].usVCID_Value);
f8942e07
SH
1522 }
1523 }
6a4ef5f9 1524 atomic_set(&Adapter->uiMBupdate, FALSE);
f8942e07
SH
1525}
1526
9ef0760f 1527void flush_queue(struct bcm_mini_adapter *Adapter, unsigned int iQIndex)
f8942e07 1528{
6a4ef5f9
KM
1529 struct sk_buff *PacketToDrop = NULL;
1530 struct net_device_stats *netstats = &Adapter->dev->stats;
f8942e07
SH
1531 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1532
6a4ef5f9 1533 while (Adapter->PackInfo[iQIndex].FirstTxQueue && atomic_read(&Adapter->TotalPacketCount)) {
f8942e07 1534 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
6a4ef5f9 1535 if (PacketToDrop && PacketToDrop->len) {
f8942e07 1536 netstats->tx_dropped++;
6a4ef5f9 1537 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, Adapter->PackInfo[iQIndex].LastTxQueue);
f8942e07
SH
1538 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1539 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1540
6a4ef5f9 1541 /* Adding dropped statistics */
f8942e07
SH
1542 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1543 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
082e889b 1544 dev_kfree_skb(PacketToDrop);
f8942e07 1545 atomic_dec(&Adapter->TotalPacketCount);
f8942e07
SH
1546 }
1547 }
1548 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
f8942e07
SH
1549}
1550
2979460d 1551static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter)
f8942e07 1552{
4fd64dd0 1553 int i;
4fd64dd0 1554 if (netif_msg_link(Adapter))
9ec4475b 1555 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
4fd64dd0
SH
1556
1557 netif_carrier_off(Adapter->dev);
1558 netif_stop_queue(Adapter->dev);
f8942e07
SH
1559
1560 Adapter->IdleMode = FALSE;
1561 Adapter->LinkUpStatus = FALSE;
6a4ef5f9
KM
1562 ClearTargetDSXBuffer(Adapter, 0, TRUE);
1563 /* Delete All Classifier Rules */
f8942e07 1564
6a4ef5f9
KM
1565 for (i = 0; i < HiPriority; i++)
1566 DeleteAllClassifiersForSF(Adapter, i);
f8942e07
SH
1567
1568 flush_all_queues(Adapter);
1569
6a4ef5f9 1570 if (Adapter->TimerActive == TRUE)
f8942e07
SH
1571 Adapter->TimerActive = FALSE;
1572
7f22485d 1573 memset(Adapter->astFragmentedPktClassifierTable, 0, sizeof(struct bcm_fragmented_packet_info) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
f8942e07 1574
6a4ef5f9
KM
1575 for (i = 0; i < HiPriority; i++) {
1576 /* resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF. */
1577 /* It is same between MIBs and SF. */
8c7d51a3 1578 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable, 0, sizeof(struct bcm_mibs_parameters));
f8942e07
SH
1579 }
1580}
This page took 0.388073 seconds and 5 git commands to generate.