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