blob: b2d90d1e26af75d416bb27b6f89a66f5f3085527 [file] [log] [blame]
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001#include "headers.h"
2
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04003static int BcmFileDownload(PMINI_ADAPTER Adapter, const char *path, unsigned int loc);
Stephen Hemminger9dd47ee2010-11-01 12:24:00 -04004static VOID doPowerAutoCorrection(PMINI_ADAPTER psAdapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04005static void HandleShutDownModeRequest(PMINI_ADAPTER Adapter, PUCHAR pucBuffer);
Stephen Hemminger9dd47ee2010-11-01 12:24:00 -04006static int bcm_parse_target_params(PMINI_ADAPTER Adapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04007static void beceem_protocol_reset(PMINI_ADAPTER Adapter);
Stephen Hemminger9dd47ee2010-11-01 12:24:00 -04008
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07009static VOID default_wimax_protocol_initialize(PMINI_ADAPTER Adapter)
10{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040011 UINT uiLoopIndex;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070012
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040013 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 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070018
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040019 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;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070025}
26
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040027INT InitAdapter(PMINI_ADAPTER psAdapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070028{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040029 int i = 0;
30 INT Status = STATUS_SUCCESS;
31 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Initialising Adapter = %p", psAdapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070032
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040033 if (psAdapter == NULL) {
34 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Adapter is NULL");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070035 return -EINVAL;
36 }
37
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040038 sema_init(&psAdapter->NVMRdmWrmLock, 1);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070039 sema_init(&psAdapter->rdmwrmsync, 1);
40 spin_lock_init(&psAdapter->control_queue_lock);
41 spin_lock_init(&psAdapter->txtransmitlock);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040042 sema_init(&psAdapter->RxAppControlQueuelock, 1);
43 sema_init(&psAdapter->fw_download_sema, 1);
44 sema_init(&psAdapter->LowPowerModeSync, 1);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070045
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040046 for (i = 0; i < NO_OF_QUEUES; i++)
47 spin_lock_init(&psAdapter->PackInfo[i].SFQueueLock);
48 i = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070049
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040050 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);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070055 psAdapter->waiting_to_fw_download_done = TRUE;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040056 psAdapter->fw_download_done = FALSE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070057
58 default_wimax_protocol_initialize(psAdapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040059 for (i = 0; i < MAX_CNTRL_PKTS; i++) {
Jesper Juhl3701bef2010-11-10 21:31:38 +010060 psAdapter->txctlpacket[i] = kmalloc(MAX_CNTL_PKT_SIZE, GFP_KERNEL);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040061 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);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070063 return -ENOMEM;
64 }
65 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040066
67 if (AllocAdapterDsxBuffer(psAdapter)) {
68 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to allocate DSX buffers");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070069 return -EINVAL;
70 }
71
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040072 /* Initialize PHS interface */
73 if (phs_init(&psAdapter->stBCMPhsContext, psAdapter) != 0) {
Kevin McKinneya8a1cdd2011-10-07 18:50:10 -040074 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%s:%d:Error PHS Init Failed=====>\n", __FILE__, __func__, __LINE__);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070075 return -ENOMEM;
76 }
77
78 Status = BcmAllocFlashCSStructure(psAdapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040079 if (Status) {
80 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Memory Allocation for Flash structure failed");
81 return Status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070082 }
83
84 Status = vendorextnInit(psAdapter);
85
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040086 if (STATUS_SUCCESS != Status) {
87 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Vendor Init Failed");
88 return Status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070089 }
90
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040091 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Adapter initialised");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070092
93 return STATUS_SUCCESS;
94}
95
96VOID AdapterFree(PMINI_ADAPTER Adapter)
97{
Stephen Hemmingere614e282010-11-01 09:52:14 -040098 int count;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070099 beceem_protocol_reset(Adapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700100 vendorextnExit(Adapter);
101
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400102 if (Adapter->control_packet_handler && !IS_ERR(Adapter->control_packet_handler))
103 kthread_stop(Adapter->control_packet_handler);
Stephen Hemmingere614e282010-11-01 09:52:14 -0400104
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400105 if (Adapter->transmit_packet_thread && !IS_ERR(Adapter->transmit_packet_thread))
106 kthread_stop(Adapter->transmit_packet_thread);
Stephen Hemmingere614e282010-11-01 09:52:14 -0400107
108 wake_up(&Adapter->process_read_wait_queue);
109
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400110 if (Adapter->LEDInfo.led_thread_running & (BCM_LED_THREAD_RUNNING_ACTIVELY | BCM_LED_THREAD_RUNNING_INACTIVELY))
111 kthread_stop(Adapter->LEDInfo.led_cntrl_threadid);
Stephen Hemmingere614e282010-11-01 09:52:14 -0400112
Stephen Hemminger4ea4f7a2010-11-01 14:06:24 -0400113 unregister_networkdev(Adapter);
Stephen Hemmingere614e282010-11-01 09:52:14 -0400114
115 /* FIXME: use proper wait_event and refcounting */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400116 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));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700118 msleep(100);
119 }
120 unregister_control_device_interface(Adapter);
Stephen Hemmingere614e282010-11-01 09:52:14 -0400121 kfree(Adapter->pstargetparams);
122
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400123 for (count = 0; count < MAX_CNTRL_PKTS; count++)
Stephen Hemmingere614e282010-11-01 09:52:14 -0400124 kfree(Adapter->txctlpacket[count]);
125
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700126 FreeAdapterDsxBuffer(Adapter);
Stephen Hemmingere614e282010-11-01 09:52:14 -0400127 kfree(Adapter->pvInterfaceAdapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700128
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400129 /* Free the PHS Interface */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700130 PhsCleanup(&Adapter->stBCMPhsContext);
131
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700132 BcmDeAllocFlashCSStructure(Adapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700133
Stephen Hemmingere614e282010-11-01 09:52:14 -0400134 free_netdev(Adapter->dev);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700135}
136
Stephen Hemminger2d087482010-11-01 12:14:01 -0400137static int create_worker_threads(PMINI_ADAPTER psAdapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700138{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400139 /* Rx Control Packets Processing */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700140 psAdapter->control_packet_handler = kthread_run((int (*)(void *))
Stephen Hemminger2d087482010-11-01 12:14:01 -0400141 control_packet_handler, psAdapter, "%s-rx", DRV_NAME);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400142 if (IS_ERR(psAdapter->control_packet_handler)) {
Stephen Hemminger2d087482010-11-01 12:14:01 -0400143 pr_notice(DRV_NAME ": could not create control thread\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700144 return PTR_ERR(psAdapter->control_packet_handler);
145 }
Stephen Hemminger2d087482010-11-01 12:14:01 -0400146
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400147 /* Tx Thread */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700148 psAdapter->transmit_packet_thread = kthread_run((int (*)(void *))
Stephen Hemminger2d087482010-11-01 12:14:01 -0400149 tx_pkt_handler, psAdapter, "%s-tx", DRV_NAME);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400150 if (IS_ERR(psAdapter->transmit_packet_thread)) {
Stephen Hemminger2d087482010-11-01 12:14:01 -0400151 pr_notice(DRV_NAME ": could not creat transmit thread\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700152 kthread_stop(psAdapter->control_packet_handler);
153 return PTR_ERR(psAdapter->transmit_packet_thread);
154 }
155 return 0;
156}
157
Stephen Hemminger9dd47ee2010-11-01 12:24:00 -0400158static struct file *open_firmware_file(PMINI_ADAPTER Adapter, const char *path)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700159{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400160 struct file *flp = NULL;
161 mm_segment_t oldfs;
162 oldfs = get_fs();
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700163 set_fs(get_ds());
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400164 flp = filp_open(path, O_RDONLY, S_IRWXU);
165 set_fs(oldfs);
166 if (IS_ERR(flp)) {
167 pr_err(DRV_NAME "Unable To Open File %s, err %ld", path, PTR_ERR(flp));
168 flp = NULL;
169 }
Stephen Hemminger2d087482010-11-01 12:14:01 -0400170
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400171 if (Adapter->device_removed)
172 flp = NULL;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700173
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400174 return flp;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700175}
176
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400177/* Arguments:
178 * Logical Adapter
179 * Path to image file
180 * Download Address on the chip
181 */
182static int BcmFileDownload(PMINI_ADAPTER Adapter, const char *path, unsigned int loc)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700183{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400184 int errorno = 0;
185 struct file *flp = NULL;
186 mm_segment_t oldfs;
187 struct timeval tv = {0};
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700188
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400189 flp = open_firmware_file(Adapter, path);
190 if (!flp) {
191 errorno = -ENOENT;
192 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Unable to Open %s\n", path);
193 goto exit_download;
194 }
195 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Opened file is = %s and length =0x%lx to be downloaded at =0x%x", path, (unsigned long)flp->f_dentry->d_inode->i_size, loc);
196 do_gettimeofday(&tv);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700197
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400198 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "download start %lx", ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)));
199 if (Adapter->bcm_file_download(Adapter->pvInterfaceAdapter, flp, loc)) {
200 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to download the firmware with error %x!!!", -EIO);
201 errorno = -EIO;
202 goto exit_download;
203 }
204 oldfs = get_fs();
205 set_fs(get_ds());
206 vfs_llseek(flp, 0, 0);
207 set_fs(oldfs);
208 if (Adapter->bcm_file_readback_from_chip(Adapter->pvInterfaceAdapter, flp, loc)) {
209 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to read back firmware!");
210 errorno = -EIO;
211 goto exit_download;
212 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700213
214exit_download:
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400215 oldfs = get_fs();
216 set_fs(get_ds());
217 if (flp && !(IS_ERR(flp)))
218 filp_close(flp, current->files);
219 set_fs(oldfs);
Stephen Hemminger2d087482010-11-01 12:14:01 -0400220
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400221 return errorno;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700222}
223
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700224/**
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400225 * @ingroup ctrl_pkt_functions
226 * This function copies the contents of given buffer
227 * to the control packet and queues it for transmission.
228 * @note Do not acquire the spinock, as it it already acquired.
229 * @return SUCCESS/FAILURE.
230 * Arguments:
231 * Logical Adapter
232 * Control Packet Buffer
233 */
234INT CopyBufferToControlPacket(PMINI_ADAPTER Adapter, PVOID ioBuffer)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700235{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400236 PLEADER pLeader = NULL;
237 INT Status = 0;
238 unsigned char *ctrl_buff = NULL;
239 UINT pktlen = 0;
240 PLINK_REQUEST pLinkReq = NULL;
241 PUCHAR pucAddIndication = NULL;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700242
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400243 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "======>");
244 if (!ioBuffer) {
245 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Got Null Buffer\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700246 return -EINVAL;
247 }
248
249 pLinkReq = (PLINK_REQUEST)ioBuffer;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400250 pLeader = (PLEADER)ioBuffer; /* ioBuffer Contains sw_Status and Payload */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700251
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400252 if (Adapter->bShutStatus == TRUE &&
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700253 pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD &&
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400254 pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE) {
255
256 /* Got sync down in SHUTDOWN..we could not process this. */
257 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "SYNC DOWN Request in Shut Down Mode..\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700258 return STATUS_FAILURE;
259 }
260
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400261 if ((pLeader->Status == LINK_UP_CONTROL_REQ) &&
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700262 ((pLinkReq->szData[0] == LINK_UP_REQ_PAYLOAD &&
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400263 (pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE)) || /* Sync Up Command */
264 pLinkReq->szData[0] == NETWORK_ENTRY_REQ_PAYLOAD)) /* Net Entry Command */ {
265
266 if (Adapter->LinkStatus > PHY_SYNC_ACHIVED) {
267 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "LinkStatus is Greater than PHY_SYN_ACHIEVED");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700268 return STATUS_FAILURE;
269 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400270
271 if (TRUE == Adapter->bShutStatus) {
272 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "SYNC UP IN SHUTDOWN..Device WakeUp\n");
273 if (Adapter->bTriedToWakeUpFromlowPowerMode == FALSE) {
274 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Waking up for the First Time..\n");
275 Adapter->usIdleModePattern = ABORT_SHUTDOWN_MODE; /* change it to 1 for current support. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700276 Adapter->bWakeUpDevice = TRUE;
277 wake_up(&Adapter->process_rx_cntrlpkt);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400278 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->bShutStatus, (5 * HZ));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700279
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400280 if (Status == -ERESTARTSYS)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700281 return Status;
282
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400283 if (Adapter->bShutStatus) {
284 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Shutdown Mode Wake up Failed - No Wake Up Received\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700285 return STATUS_FAILURE;
286 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400287 } else {
288 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Wakeup has been tried already...\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700289 }
290 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700291 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700292
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400293 if (TRUE == Adapter->IdleMode) {
294 /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle mode ... hence\n"); */
295 if (pLeader->Status == LINK_UP_CONTROL_REQ || pLeader->Status == 0x80 ||
296 pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ) {
297
298 if ((pLeader->Status == LINK_UP_CONTROL_REQ) && (pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD)) {
299 if ((pLinkReq->szData[1] == LINK_SYNC_DOWN_SUBTYPE)) {
300 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Link Down Sent in Idle Mode\n");
301 Adapter->usIdleModePattern = ABORT_IDLE_SYNCDOWN; /* LINK DOWN sent in Idle Mode */
302 } else {
303 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "ABORT_IDLE_MODE pattern is being written\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700304 Adapter->usIdleModePattern = ABORT_IDLE_REG;
305 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400306 } else {
307 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "ABORT_IDLE_MODE pattern is being written\n");
308 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700309 }
310
311 /*Setting bIdleMode_tx_from_host to TRUE to indicate LED control thread to represent
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400312 * the wake up from idlemode is from host
313 */
314 /* Adapter->LEDInfo.bIdleMode_tx_from_host = TRUE; */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700315 Adapter->bWakeUpDevice = TRUE;
316 wake_up(&Adapter->process_rx_cntrlpkt);
317
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400318 /* We should not send DREG message down while in idlemode. */
319 if (LINK_DOWN_REQ_PAYLOAD == pLinkReq->szData[0])
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700320 return STATUS_SUCCESS;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700321
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400322 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->IdleMode, (5 * HZ));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700323
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400324 if (Status == -ERESTARTSYS)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700325 return Status;
326
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400327 if (Adapter->IdleMode) {
328 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Idle Mode Wake up Failed - No Wake Up Received\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700329 return STATUS_FAILURE;
330 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400331 } else {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700332 return STATUS_SUCCESS;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400333 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700334 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400335
336 /* The Driver has to send control messages with a particular VCID */
337 pLeader->Vcid = VCID_CONTROL_PACKET; /* VCID for control packet. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700338
339 /* Allocate skb for Control Packet */
340 pktlen = pLeader->PLength;
341 ctrl_buff = (char *)Adapter->txctlpacket[atomic_read(&Adapter->index_wr_txcntrlpkt)%MAX_CNTRL_PKTS];
342
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400343 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",
344 atomic_read(&Adapter->index_wr_txcntrlpkt), ctrl_buff, ioBuffer, pktlen);
345 if (ctrl_buff) {
346 if (pLeader) {
347 if ((pLeader->Status == 0x80) ||
348 (pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ)) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700349 /*
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400350 * Restructure the DSX message to handle Multiple classifier Support
351 * Write the Service Flow param Structures directly to the target
352 * and embed the pointers in the DSX messages sent to target.
353 */
354 /* Lets store the current length of the control packet we are transmitting */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700355 pucAddIndication = (PUCHAR)ioBuffer + LEADER_SIZE;
356 pktlen = pLeader->PLength;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400357 Status = StoreCmControlResponseMessage(Adapter, pucAddIndication, &pktlen);
358 if (Status != 1) {
359 ClearTargetDSXBuffer(Adapter, ((stLocalSFAddIndicationAlt *)pucAddIndication)->u16TID, FALSE);
360 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 ");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700361 return STATUS_FAILURE;
362 }
363 /*
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400364 * update the leader to use the new length
365 * The length of the control packet is length of message being sent + Leader length
366 */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700367 pLeader->PLength = pktlen;
368 }
369 }
Kevin McKinneye228b742011-09-18 18:34:47 -0400370
371 if (pktlen + LEADER_SIZE > MAX_CNTL_PKT_SIZE)
372 return -EINVAL;
373
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700374 memset(ctrl_buff, 0, pktlen+LEADER_SIZE);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400375 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Copying the Control Packet Buffer with length=%d\n", pLeader->PLength);
376 *(PLEADER)ctrl_buff = *pLeader;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700377 memcpy(ctrl_buff + LEADER_SIZE, ((PUCHAR)ioBuffer + LEADER_SIZE), pLeader->PLength);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400378 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Enqueuing the Control Packet");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700379
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400380 /* Update the statistics counters */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700381 spin_lock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400382 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost += pLeader->PLength;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700383 Adapter->PackInfo[HiPriority].uiCurrentPacketsOnHost++;
384 atomic_inc(&Adapter->TotalPacketCount);
385 spin_unlock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700386 Adapter->PackInfo[HiPriority].bValid = TRUE;
387
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400388 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "CurrBytesOnHost: %x bValid: %x",
389 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost,
390 Adapter->PackInfo[HiPriority].bValid);
391 Status = STATUS_SUCCESS;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700392 /*Queue the packet for transmission */
393 atomic_inc(&Adapter->index_wr_txcntrlpkt);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400394 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Calling transmit_packets");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700395 atomic_set(&Adapter->TxPktAvail, 1);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700396 wake_up(&Adapter->tx_packet_wait_queue);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400397 } else {
398 Status = -ENOMEM;
399 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "mem allocation Failed");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700400 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400401 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<====");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700402 return Status;
403}
404
Arnd Bergmann44a17eff2010-09-30 10:24:12 +0200405#if 0
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700406/*****************************************************************
407* Function - SendStatisticsPointerRequest()
408*
409* Description - This function builds and forwards the Statistics
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400410* Pointer Request control Packet.
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700411*
412* Parameters - Adapter : Pointer to Adapter structure.
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400413* - pstStatisticsPtrRequest : Pointer to link request.
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700414*
415* Returns - None.
416*****************************************************************/
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400417static VOID SendStatisticsPointerRequest(PMINI_ADAPTER Adapter, PLINK_REQUEST pstStatisticsPtrRequest)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700418{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400419 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "======>");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700420 pstStatisticsPtrRequest->Leader.Status = STATS_POINTER_REQ_STATUS;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400421 pstStatisticsPtrRequest->Leader.PLength = sizeof(ULONG); /* minimum 4 bytes */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700422 pstStatisticsPtrRequest->szData[0] = STATISTICS_POINTER_REQ;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400423 CopyBufferToControlPacket(Adapter, pstStatisticsPtrRequest);
424 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "<=====");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700425 return;
426}
Arnd Bergmann44a17eff2010-09-30 10:24:12 +0200427#endif
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700428
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700429/******************************************************************
430* Function - LinkMessage()
431*
432* Description - This function builds the Sync-up and Link-up request
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400433* packet messages depending on the device Link status.
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700434*
435* Parameters - Adapter: Pointer to the Adapter structure.
436*
437* Returns - None.
438*******************************************************************/
Stephen Hemminger20f48652010-10-31 23:52:36 -0400439VOID LinkMessage(PMINI_ADAPTER Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700440{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400441 PLINK_REQUEST pstLinkRequest = NULL;
442 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>");
443 if (Adapter->LinkStatus == SYNC_UP_REQUEST && Adapter->AutoSyncup) {
Alexander Beregalovf4a0e6b2011-03-09 03:53:34 +0300444 pstLinkRequest = kzalloc(sizeof(LINK_REQUEST), GFP_ATOMIC);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400445 if (!pstLinkRequest) {
446 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700447 return;
448 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400449 /* sync up request... */
450 Adapter->LinkStatus = WAIT_FOR_SYNC; /* current link status */
451 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For SyncUp...");
452 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
453 pstLinkRequest->szData[1] = LINK_SYNC_UP_SUBTYPE;
454 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
455 pstLinkRequest->Leader.PLength = sizeof(ULONG);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700456 Adapter->bSyncUpRequestSent = TRUE;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400457
458 } else if (Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp) {
Alexander Beregalovf4a0e6b2011-03-09 03:53:34 +0300459 pstLinkRequest = kzalloc(sizeof(LINK_REQUEST), GFP_ATOMIC);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400460 if (!pstLinkRequest) {
461 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700462 return;
463 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400464 /* LINK_UP_REQUEST */
465 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For LinkUp...");
466 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
467 pstLinkRequest->szData[1] = LINK_NET_ENTRY;
468 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
469 pstLinkRequest->Leader.PLength = sizeof(ULONG);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700470 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400471 if (pstLinkRequest) {
472 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700473 CopyBufferToControlPacket(Adapter, pstLinkRequest);
Stephen Hemminger082e8892010-11-01 09:35:21 -0400474 kfree(pstLinkRequest);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700475 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400476 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700477 return;
478}
479
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700480/**********************************************************************
481* Function - StatisticsResponse()
482*
483* Description - This function handles the Statistics response packet.
484*
485* Parameters - Adapter : Pointer to the Adapter structure.
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400486* - pvBuffer: Starting address of Statistic response data.
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700487*
488* Returns - None.
489************************************************************************/
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400490VOID StatisticsResponse(PMINI_ADAPTER Adapter, PVOID pvBuffer)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700491{
Kevin McKinneya8a1cdd2011-10-07 18:50:10 -0400492 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>", __func__);
Stephen Hemmingere39e3be2010-11-01 11:14:29 -0400493 Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400494 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (UINT)Adapter->StatisticsPointer);
Kevin McKinneya8a1cdd2011-10-07 18:50:10 -0400495 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====", __func__);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700496 return;
497}
498
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700499/**********************************************************************
500* Function - LinkControlResponseMessage()
501*
502* Description - This function handles the Link response packets.
503*
504* Parameters - Adapter : Pointer to the Adapter structure.
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400505* - pucBuffer: Starting address of Link response data.
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700506*
507* Returns - None.
508***********************************************************************/
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400509VOID LinkControlResponseMessage(PMINI_ADAPTER Adapter, PUCHAR pucBuffer)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700510{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400511 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700512
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400513 if (*pucBuffer == LINK_UP_ACK) {
514 switch (*(pucBuffer+1)) {
515 case PHY_SYNC_ACHIVED: /* SYNCed UP */
516 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHY_SYNC_ACHIVED");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700517
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400518 if (Adapter->LinkStatus == LINKUP_DONE)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700519 beceem_protocol_reset(Adapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700520
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400521 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
522 Adapter->LinkStatus = PHY_SYNC_ACHIVED;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700523
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400524 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700525 Adapter->DriverState = NO_NETWORK_ENTRY;
526 wake_up(&Adapter->LEDInfo.notify_led_event);
527 }
528
529 LinkMessage(Adapter);
530 break;
531
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400532 case LINKUP_DONE:
533 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LINKUP_DONE");
534 Adapter->LinkStatus = LINKUP_DONE;
535 Adapter->bPHSEnabled = *(pucBuffer+3);
536 Adapter->bETHCSEnabled = *(pucBuffer+4) & ETH_CS_MASK;
537 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHS Support Status Received In LinkUp Ack : %x\n", Adapter->bPHSEnabled);
538
539 if ((FALSE == Adapter->bShutStatus) && (FALSE == Adapter->IdleMode)) {
540 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
541 Adapter->DriverState = NORMAL_OPERATION;
542 wake_up(&Adapter->LEDInfo.notify_led_event);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700543 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700544 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400545 LinkMessage(Adapter);
546 break;
547
548 case WAIT_FOR_SYNC:
549 /*
550 * Driver to ignore the DREG_RECEIVED
551 * WiMAX Application should handle this Message
552 */
553 /* Adapter->liTimeSinceLastNetEntry = 0; */
554 Adapter->LinkUpStatus = 0;
555 Adapter->LinkStatus = 0;
556 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
557 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
558 Adapter->IdleMode = FALSE;
559 beceem_protocol_reset(Adapter);
560
561 break;
562 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
563 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
564 {
565 HandleShutDownModeRequest(Adapter, pucBuffer);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700566 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400567 break;
568 default:
569 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x", *(pucBuffer + 1));
570 break;
571 }
572 } else if (SET_MAC_ADDRESS_RESPONSE == *pucBuffer) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700573 PUCHAR puMacAddr = (pucBuffer + 1);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400574 Adapter->LinkStatus = SYNC_UP_REQUEST;
575 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "MAC address response, sending SYNC_UP");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700576 LinkMessage(Adapter);
577 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
578 }
Kevin McKinneya8a1cdd2011-10-07 18:50:10 -0400579 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====", __func__);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700580 return;
581}
582
583void SendIdleModeResponse(PMINI_ADAPTER Adapter)
584{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400585 INT status = 0, NVMAccess = 0, lowPwrAbortMsg = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700586 struct timeval tv;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400587 CONTROL_MESSAGE stIdleResponse = {{0} };
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700588 memset(&tv, 0, sizeof(tv));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400589 stIdleResponse.Leader.Status = IDLE_MESSAGE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700590 stIdleResponse.Leader.PLength = IDLE_MODE_PAYLOAD_LENGTH;
591 stIdleResponse.szData[0] = GO_TO_IDLE_MODE_PAYLOAD;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400592 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, " ============>");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700593
594 /*********************************
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400595 *down_trylock -
596 * if [ semaphore is available ]
597 * acquire semaphone and return value 0 ;
598 * else
599 * return non-zero value ;
600 *
601 ***********************************/
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700602
603 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400604 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700605
606
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400607 if ((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
608 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)) {
609
610 if (!NVMAccess)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700611 up(&Adapter->NVMRdmWrmLock);
612
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400613 if (!lowPwrAbortMsg)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700614 up(&Adapter->LowPowerModeSync);
615
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400616 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
617 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "HOST IS NACKING Idle mode To F/W!!!!!!!!");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700618 Adapter->bPreparingForLowPowerMode = FALSE;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400619 } else {
620 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; /* 2; Idle ACK */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700621 Adapter->StatisticsPointer = 0;
622
623 /* Wait for the LED to TURN OFF before sending ACK response */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400624 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700625 INT iRetVal = 0;
626
627 /* Wake the LED Thread with IDLEMODE_ENTER State */
628 Adapter->DriverState = LOWPOWER_MODE_ENTER;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400629 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);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700630 wake_up(&Adapter->LEDInfo.notify_led_event);
631
632 /* Wait for 1 SEC for LED to OFF */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400633 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700634
635 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400636 if (iRetVal <= 0) {
637 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700638 Adapter->DriverState = NORMAL_OPERATION;
639 wake_up(&Adapter->LEDInfo.notify_led_event);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400640 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "NACKING Idle mode as time out happen from LED side!!!!!!!!");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700641 }
642 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400643
644 if (stIdleResponse.szData[1] == TARGET_CAN_GO_TO_IDLE_MODE) {
645 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "ACKING IDLE MODE !!!!!!!!!");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700646 down(&Adapter->rdmwrmsync);
647 Adapter->bPreparingForLowPowerMode = TRUE;
648 up(&Adapter->rdmwrmsync);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400649 /* Killing all URBS. */
650 if (Adapter->bDoSuspend == TRUE)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700651 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400652 } else {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700653 Adapter->bPreparingForLowPowerMode = FALSE;
654 }
655
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400656 if (!NVMAccess)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700657 up(&Adapter->NVMRdmWrmLock);
658
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400659 if (!lowPwrAbortMsg)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700660 up(&Adapter->LowPowerModeSync);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700661 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400662
663 status = CopyBufferToControlPacket(Adapter, &stIdleResponse);
664 if ((status != STATUS_SUCCESS)) {
665 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "fail to send the Idle mode Request\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700666 Adapter->bPreparingForLowPowerMode = FALSE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700667 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700668 }
669 do_gettimeofday(&tv);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400670 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);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700671}
672
673/******************************************************************
674* Function - DumpPackInfo()
675*
676* Description - This function dumps the all Queue(PackInfo[]) details.
677*
678* Parameters - Adapter: Pointer to the Adapter structure.
679*
680* Returns - None.
681*******************************************************************/
682VOID DumpPackInfo(PMINI_ADAPTER Adapter)
683{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400684 UINT uiLoopIndex = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700685 UINT uiIndex = 0;
686 UINT uiClsfrIndex = 0;
Kevin McKinney92562ae2012-05-26 12:05:03 -0400687 struct bcm_classifier_rule *pstClassifierEntry = NULL;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700688
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400689 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
690 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "*********** Showing Details Of Queue %d***** ******", uiLoopIndex);
691 if (FALSE == Adapter->PackInfo[uiLoopIndex].bValid) {
692 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid is FALSE for %X index\n", uiLoopIndex);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700693 continue;
694 }
695
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400696 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " Dumping SF Rule Entry For SFID %lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
697 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " ucDirection %X\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
698
699 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
700 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv6 Service Flow\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700701 else
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400702 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv4 Service Flow\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700703
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400704 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SF Traffic Priority %X\n", Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
705
706 for (uiClsfrIndex = 0; uiClsfrIndex < MAX_CLASSIFIERS; uiClsfrIndex++) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700707 pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400708 if (!pstClassifierEntry->bUsed)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700709 continue;
710
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400711 if (pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700712 continue;
713
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400714 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);
715 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);
716 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);
717 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);
718 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);
719 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);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700720
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400721 for (uiIndex = 0; uiIndex < MAX_PORT_RANGE; uiIndex++) {
722 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeLo:%X\n", pstClassifierEntry->usSrcPortRangeLo[uiIndex]);
723 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeHi:%X\n", pstClassifierEntry->usSrcPortRangeHi[uiIndex]);
724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeLo:%X\n", pstClassifierEntry->usDestPortRangeLo[uiIndex]);
725 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeHi:%X\n", pstClassifierEntry->usDestPortRangeHi[uiIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700726 }
727
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400728 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPSourceAddressLength : 0x%x\n", pstClassifierEntry->ucIPSourceAddressLength);
729 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPDestinationAddressLength : 0x%x\n", pstClassifierEntry->ucIPDestinationAddressLength);
730 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPSourceAddressLength; uiIndex++) {
731 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
732 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpAddr :\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700733 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Addr);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400734 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpMask :\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700735 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Mask);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400736 } else {
737 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpAddr:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Addr[uiIndex]);
738 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpMask:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Mask[uiIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700739 }
740 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400741
742 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPDestinationAddressLength; uiIndex++) {
743 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
744 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpAddr :\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700745 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Addr);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400746 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpMask :\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700747 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Mask);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400748 } else {
749 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpAddr:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Addr[uiIndex]);
750 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpMask:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Mask[uiIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700751 }
752 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400753 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucProtocol:0x%X\n", pstClassifierEntry->ucProtocol[0]);
754 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tu8ClassifierRulePriority:%X\n", pstClassifierEntry->u8ClassifierRulePriority);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700755 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400756 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ulSFID:%lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
757 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "usVCID_Value:%X\n", Adapter->PackInfo[uiLoopIndex].usVCID_Value);
758 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "PhsEnabled: 0x%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
759 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThreshold:%X\n", Adapter->PackInfo[uiLoopIndex].uiThreshold);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700760
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400761 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid:%X\n", Adapter->PackInfo[uiLoopIndex].bValid);
762 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bActive:%X\n", Adapter->PackInfo[uiLoopIndex].bActive);
763 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActivateReqSent: %x", Adapter->PackInfo[uiLoopIndex].bActivateRequestSent);
764 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "u8QueueType:%X\n", Adapter->PackInfo[uiLoopIndex].u8QueueType);
765 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxBucketSize:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize);
766 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPerSFTxResourceCount:%X\n", atomic_read(&Adapter->PackInfo[uiLoopIndex].uiPerSFTxResourceCount));
767 /* DumpDebug(DUMP_INFO,("bCSSupport:%X\n",Adapter->PackInfo[uiLoopIndex].bCSSupport)); */
768 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CurrQueueDepthOnTarget: %x\n", Adapter->PackInfo[uiLoopIndex].uiCurrentQueueDepthOnTarget);
769 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentBytesOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentBytesOnHost);
770 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentPacketsOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentPacketsOnHost);
771 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountBytes);
772 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountPackets);
773 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentBytes);
774 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentPackets);
775 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentDrainRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentDrainRate);
776 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThisPeriodSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiThisPeriodSentBytes);
777 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liDrainCalculated:%llX\n", Adapter->PackInfo[uiLoopIndex].liDrainCalculated);
778 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentTokenCount:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentTokenCount);
779 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liLastUpdateTokenAt:%llX\n", Adapter->PackInfo[uiLoopIndex].liLastUpdateTokenAt);
780 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxAllowedRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate);
781 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPendedLast:%X\n", Adapter->PackInfo[uiLoopIndex].uiPendedLast);
782 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "NumOfPacketsSent:%X\n", Adapter->PackInfo[uiLoopIndex].NumOfPacketsSent);
783 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Direction: %x\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
784 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CID: %x\n", Adapter->PackInfo[uiLoopIndex].usCID);
785 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ProtocolValid: %x\n", Adapter->PackInfo[uiLoopIndex].bProtocolValid);
786 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "TOSValid: %x\n", Adapter->PackInfo[uiLoopIndex].bTOSValid);
787 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "DestIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bDestIpValid);
788 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SrcIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bSrcIpValid);
789 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActiveSet: %x\n", Adapter->PackInfo[uiLoopIndex].bActiveSet);
790 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AdmittedSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAdmittedSet);
791 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AuthzSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAuthorizedSet);
792 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ClassifyPrority: %x\n", Adapter->PackInfo[uiLoopIndex].bClassifierPriority);
793 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxLatency: %x\n", Adapter->PackInfo[uiLoopIndex].uiMaxLatency);
794 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ServiceClassName: %x %x %x %x\n", Adapter->PackInfo[uiLoopIndex].ucServiceClassName[0], Adapter->PackInfo[uiLoopIndex].ucServiceClassName[1], Adapter->PackInfo[uiLoopIndex].ucServiceClassName[2], Adapter->PackInfo[uiLoopIndex].ucServiceClassName[3]);
795/* BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bHeaderSuppressionEnabled :%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
796 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalTxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalTxBytes);
797 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalRxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalRxBytes);
798 * DumpDebug(DUMP_INFO,(" uiRanOutOfResCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiRanOutOfResCount));
799 */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700800 }
801
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400802 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
803 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aRxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aRxPktSizeHist[uiLoopIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700804
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400805 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
806 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aTxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aTxPktSizeHist[uiLoopIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700807
808 return;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700809}
810
Stephen Hemminger20f48652010-10-31 23:52:36 -0400811int reset_card_proc(PMINI_ADAPTER ps_adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700812{
813 int retval = STATUS_SUCCESS;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400814 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700815 PS_INTERFACE_ADAPTER psIntfAdapter = NULL;
816 unsigned int value = 0, uiResetValue = 0;
Kevin McKinney41c7b7c2011-11-06 09:40:11 -0500817 int bytes;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700818
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400819 psIntfAdapter = ((PS_INTERFACE_ADAPTER)(ps_adapter->pvInterfaceAdapter));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700820 ps_adapter->bDDRInitDone = FALSE;
821
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400822 if (ps_adapter->chip_id >= T3LPB) {
823 /* SYS_CFG register is write protected hence for modifying this reg value, it should be read twice before */
824 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
825 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700826
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400827 /* making bit[6...5] same as was before f/w download. this setting force the h/w to */
828 /* re-populated the SP RAM area with the string descriptor. */
829 value = value | (ps_adapter->syscfgBefFwDld & 0x00000060);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700830 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
831 }
832
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400833 /* killing all submitted URBs. */
834 psIntfAdapter->psAdapter->StopAllXaction = TRUE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700835 Bcm_kill_all_URBs(psIntfAdapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700836 /* Reset the UMA-B Device */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400837 if (ps_adapter->chip_id >= T3LPB) {
Masanari Iida73e29182012-04-06 23:33:52 +0900838 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Resetting UMA-B\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700839 retval = usb_reset_device(psIntfAdapter->udev);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400840 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700841
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400842 if (retval != STATUS_SUCCESS) {
843 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700844 goto err_exit;
845 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400846
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700847 if (ps_adapter->chip_id == BCS220_2 ||
848 ps_adapter->chip_id == BCS220_2BC ||
849 ps_adapter->chip_id == BCS250_BC ||
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400850 ps_adapter->chip_id == BCS220_3) {
851
Kevin McKinney41c7b7c2011-11-06 09:40:11 -0500852 bytes = rdmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
853 if (bytes < 0) {
854 retval = bytes;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400855 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700856 goto err_exit;
857 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400858 /* setting 0th bit */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700859 value |= (1<<0);
860 retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400861 if (retval < 0) {
862 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700863 goto err_exit;
864 }
865 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400866 } else {
Kevin McKinney41c7b7c2011-11-06 09:40:11 -0500867 bytes = rdmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
868 if (bytes < 0) {
869 retval = bytes;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400870 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700871 goto err_exit;
872 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400873 value &= (~(1<<16));
874 retval = wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
875 if (retval < 0) {
876 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700877 goto err_exit;
878 }
879
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400880 /* Toggling the GPIO 8, 9 */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700881 value = 0;
882 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400883 if (retval < 0) {
884 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700885 goto err_exit;
886 }
887 value = 0x300;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400888 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value));
889 if (retval < 0) {
890 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700891 goto err_exit;
892 }
893 mdelay(50);
894 }
895
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400896 /* ps_adapter->downloadDDR = false; */
897 if (ps_adapter->bFlashBoot) {
898 /* In flash boot mode MIPS state register has reverse polarity.
899 * So just or with setting bit 30.
900 * Make the MIPS in Reset state.
901 */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700902 rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400903 uiResetValue |= (1<<30);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700904 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
905 }
906
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400907 if (ps_adapter->chip_id >= T3LPB) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700908 uiResetValue = 0;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400909 /*
910 * WA for SYSConfig Issue.
911 * Read SYSCFG Twice to make it writable.
912 */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700913 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400914 if (uiResetValue & (1<<4)) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700915 uiResetValue = 0;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400916 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue)); /* 2nd read to make it writable. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700917 uiResetValue &= (~(1<<4));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400918 wrmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700919 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700920 }
921 uiResetValue = 0;
922 wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
923
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400924err_exit:
925 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700926 return retval;
927}
928
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400929int run_card_proc(PMINI_ADAPTER ps_adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700930{
Kevin McKinney41c7b7c2011-11-06 09:40:11 -0500931 int status = STATUS_SUCCESS;
932 int bytes;
933
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400934 unsigned int value = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700935 {
Kevin McKinney41c7b7c2011-11-06 09:40:11 -0500936 bytes = rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value));
937 if (bytes < 0) {
938 status = bytes;
Kevin McKinneya8a1cdd2011-10-07 18:50:10 -0400939 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
Kevin McKinney41c7b7c2011-11-06 09:40:11 -0500940 return status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700941 }
942
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400943 if (ps_adapter->bFlashBoot)
944 value &= (~(1<<30));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700945 else
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400946 value |= (1<<30);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700947
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400948 if (wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
Kevin McKinneya8a1cdd2011-10-07 18:50:10 -0400949 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700950 return STATUS_FAILURE;
951 }
952 }
Kevin McKinney41c7b7c2011-11-06 09:40:11 -0500953 return status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700954}
955
956int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter)
957{
Dan Carpenter2e316132010-11-13 11:24:22 +0300958 int status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700959 UINT value = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700960 /*
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400961 * Create the threads first and then download the
962 * Firm/DDR Settings..
963 */
Stephen Hemminger2d087482010-11-01 12:14:01 -0400964 status = create_worker_threads(ps_adapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400965 if (status < 0)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700966 return status;
Stephen Hemminger2d087482010-11-01 12:14:01 -0400967
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400968 status = bcm_parse_target_params(ps_adapter);
969 if (status)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700970 return status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700971
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400972 if (ps_adapter->chip_id >= T3LPB) {
973 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
974 ps_adapter->syscfgBefFwDld = value;
975
976 if ((value & 0x60) == 0)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700977 ps_adapter->bFlashBoot = TRUE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700978 }
979
980 reset_card_proc(ps_adapter);
981
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400982 /* Initializing the NVM. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700983 BcmInitNVM(ps_adapter);
984 status = ddr_init(ps_adapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400985 if (status) {
Stephen Hemminger2d087482010-11-01 12:14:01 -0400986 pr_err(DRV_NAME "ddr_init Failed\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700987 return status;
988 }
989
990 /* Download cfg file */
991 status = buffDnldVerify(ps_adapter,
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400992 (PUCHAR)ps_adapter->pstargetparams,
993 sizeof(STARGETPARAMS),
994 CONFIG_BEGIN_ADDR);
995 if (status) {
996 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700997 goto OUT;
998 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700999
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001000 if (register_networkdev(ps_adapter)) {
1001 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001002 return -EIO;
1003 }
1004
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001005 if (FALSE == ps_adapter->AutoFirmDld) {
1006 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoFirmDld Disabled in CFG File..\n");
1007 /* If Auto f/w download is disable, register the control interface, */
1008 /* register the control interface after the mailbox. */
1009 if (register_control_device_interface(ps_adapter) < 0) {
1010 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001011 return -EIO;
1012 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001013 return STATUS_SUCCESS;
1014 }
1015
1016 /*
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001017 * Do the LED Settings here. It will be used by the Firmware Download
1018 * Thread.
1019 */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001020
1021 /*
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001022 * 1. If the LED Settings fails, do not stop and do the Firmware download.
1023 * 2. This init would happened only if the cfg file is present, else
1024 * call from the ioctl context.
1025 */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001026
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001027 status = InitLedSettings(ps_adapter);
1028 if (status) {
1029 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_PRINTK, 0, 0, "INIT LED FAILED\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001030 return status;
1031 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001032
1033 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001034 ps_adapter->DriverState = DRIVER_INIT;
1035 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1036 }
1037
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001038 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001039 ps_adapter->DriverState = FW_DOWNLOAD;
1040 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1041 }
1042
1043 value = 0;
1044 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1045 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1046
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001047 if (ps_adapter->eNVMType == NVM_FLASH) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001048 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001049 if (status) {
1050 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Propagation of Cal param failed ..");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001051 goto OUT;
1052 }
1053 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001054
1055 /* Download Firmare */
Kevin McKinneyd4910612011-10-07 18:50:12 -04001056 status = BcmFileDownload(ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR);
1057 if (status != 0) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001058 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Firmware File is present...\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001059 goto OUT;
1060 }
1061
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001062 status = run_card_proc(ps_adapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001063 if (status) {
1064 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "run_card_proc Failed\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001065 goto OUT;
1066 }
1067
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001068 ps_adapter->fw_download_done = TRUE;
1069 mdelay(10);
1070
1071OUT:
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001072 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001073 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1074 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1075 }
1076
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001077 return status;
1078}
1079
Stephen Hemminger9dd47ee2010-11-01 12:24:00 -04001080static int bcm_parse_target_params(PMINI_ADAPTER Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001081{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001082 struct file *flp = NULL;
1083 mm_segment_t oldfs = {0};
Jesper Juhl3701bef2010-11-10 21:31:38 +01001084 char *buff;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001085 int len = 0;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001086 loff_t pos = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001087
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001088 buff = kmalloc(BUFFER_1K, GFP_KERNEL);
1089 if (!buff)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001090 return -ENOMEM;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001091
Kevin McKinney9d4f1d02011-10-07 18:50:11 -04001092 Adapter->pstargetparams = kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL);
1093 if (Adapter->pstargetparams == NULL) {
Stephen Hemminger082e8892010-11-01 09:35:21 -04001094 kfree(buff);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001095 return -ENOMEM;
1096 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001097
1098 flp = open_firmware_file(Adapter, CFG_FILE);
1099 if (!flp) {
1100 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE\n", CFG_FILE);
Stephen Hemminger082e8892010-11-01 09:35:21 -04001101 kfree(buff);
1102 kfree(Adapter->pstargetparams);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001103 Adapter->pstargetparams = NULL;
1104 return -ENOENT;
1105 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001106 oldfs = get_fs();
1107 set_fs(get_ds());
1108 len = vfs_read(flp, (void __user __force *)buff, BUFFER_1K, &pos);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001109 set_fs(oldfs);
1110
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001111 if (len != sizeof(STARGETPARAMS)) {
1112 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n");
Stephen Hemminger082e8892010-11-01 09:35:21 -04001113 kfree(buff);
1114 kfree(Adapter->pstargetparams);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001115 Adapter->pstargetparams = NULL;
1116 filp_close(flp, current->files);
1117 return -ENOENT;
1118 }
1119 filp_close(flp, current->files);
1120
1121 /* Check for autolink in config params */
1122 /*
1123 * Values in Adapter->pstargetparams are in network byte order
1124 */
1125 memcpy(Adapter->pstargetparams, buff, sizeof(STARGETPARAMS));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001126 kfree(buff);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001127 beceem_parse_target_struct(Adapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001128 return STATUS_SUCCESS;
1129}
1130
1131void beceem_parse_target_struct(PMINI_ADAPTER Adapter)
1132{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001133 UINT uiHostDrvrCfg6 = 0, uiEEPROMFlag = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001134
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001135 if (ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE) {
Stephen Hemminger2d087482010-11-01 12:14:01 -04001136 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001137 Adapter->AutoSyncup = FALSE;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001138 } else {
Stephen Hemminger2d087482010-11-01 12:14:01 -04001139 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001140 Adapter->AutoSyncup = TRUE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001141 }
Stephen Hemminger2d087482010-11-01 12:14:01 -04001142
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001143 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE) {
Stephen Hemminger2d087482010-11-01 12:14:01 -04001144 pr_info(DRV_NAME ": Enabling autolink up");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001145 Adapter->AutoLinkUp = TRUE;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001146 } else {
Stephen Hemminger2d087482010-11-01 12:14:01 -04001147 pr_info(DRV_NAME ": Disabling autolink up");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001148 Adapter->AutoLinkUp = FALSE;
1149 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001150 /* Setting the DDR Setting.. */
1151 Adapter->DDRSetting = (ntohl(Adapter->pstargetparams->HostDrvrConfig6) >> 8)&0x0F;
1152 Adapter->ulPowerSaveMode = (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
Stephen Hemminger2d087482010-11-01 12:14:01 -04001153 pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1154 pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001155 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD) {
1156 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1157 Adapter->AutoFirmDld = TRUE;
1158 } else {
1159 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1160 Adapter->AutoFirmDld = FALSE;
1161 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001162 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1163 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001164 pr_info(DRV_NAME ": MIPSConfig : 0x%X\n", Adapter->bMipsConfig);
1165 /* used for backward compatibility. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001166 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001167 Adapter->PmuMode = (uiHostDrvrCfg6 >> 24) & 0x03;
Stephen Hemminger2d087482010-11-01 12:14:01 -04001168 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001169
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001170 if ((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT) & (0x01)) {
1171 Adapter->bDoSuspend = TRUE;
1172 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1173 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001174
1175 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001176 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n", uiEEPROMFlag);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001177 Adapter->eNVMType = (NVM_TYPE)((uiEEPROMFlag>>4)&0x3);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001178 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001179 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001180 Adapter->bSectorSizeOverride = (bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001181
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001182 if (ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x01)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001183 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
Stephen Hemminger2d087482010-11-01 12:14:01 -04001184
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001185 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001186 doPowerAutoCorrection(Adapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001187}
1188
Stephen Hemminger9dd47ee2010-11-01 12:24:00 -04001189static VOID doPowerAutoCorrection(PMINI_ADAPTER psAdapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001190{
Stephen Hemminger2d087482010-11-01 12:14:01 -04001191 UINT reporting_mode;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001192
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001193 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x02;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001194 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1195
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001196 if (reporting_mode == TRUE) {
1197 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "can't do suspen/resume as reporting mode is enable");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001198 psAdapter->bDoSuspend = FALSE;
1199 }
1200
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001201 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB)) {
1202 /* If reporting mode is enable, switch PMU to PMC */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001203 {
1204 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001205 psAdapter->bDoSuspend = FALSE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001206 }
1207
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001208 /* clearing space bit[15..12] */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001209 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl((0xF << 12)));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001210 /* placing the power save mode option */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001211 psAdapter->pstargetparams->HostDrvrConfig6 |= htonl((psAdapter->ulPowerSaveMode << 12));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001212 } else if (psAdapter->bIsAutoCorrectEnabled == FALSE) {
1213 /* remove the autocorrect disable bit set before dumping. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001214 psAdapter->ulPowerSaveMode &= ~(1 << 3);
1215 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl(1 << 15));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001216 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Using Forced User Choice: %lx\n", psAdapter->ulPowerSaveMode);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001217 }
1218}
Arnd Bergmann44a17eff2010-09-30 10:24:12 +02001219
1220#if 0
1221static unsigned char *ReadMacAddrEEPROM(PMINI_ADAPTER Adapter, ulong dwAddress)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001222{
Jesper Juhl3701bef2010-11-10 21:31:38 +01001223 int status = 0, i = 0;
1224 unsigned int temp = 0;
1225 unsigned char *pucmacaddr = kmalloc(MAC_ADDRESS_SIZE, GFP_KERNEL);
Kevin McKinney41c7b7c2011-11-06 09:40:11 -05001226 int bytes;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001227
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001228 if (!pucmacaddr) {
1229 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "No Buffers to Read the EEPROM Address\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001230 return NULL;
1231 }
1232
1233 dwAddress |= 0x5b000000;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001234 status = wrmalt(Adapter, EEPROM_COMMAND_Q_REG, (PUINT)&dwAddress, sizeof(UINT));
1235 if (status != STATUS_SUCCESS) {
1236 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "wrm Failed..\n");
Stephen Hemminger082e8892010-11-01 09:35:21 -04001237 kfree(pucmacaddr);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001238 pucmacaddr = NULL;
1239 goto OUT;
1240 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001241
1242 for (i = 0; i < MAC_ADDRESS_SIZE; i++) {
Kevin McKinney41c7b7c2011-11-06 09:40:11 -05001243 bytes = rdmalt(Adapter, EEPROM_READ_DATA_Q_REG, &temp, sizeof(temp));
1244 if (bytes < 0) {
1245 status = bytes;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001246 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "rdm Failed..\n");
Stephen Hemminger082e8892010-11-01 09:35:21 -04001247 kfree(pucmacaddr);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001248 pucmacaddr = NULL;
1249 goto OUT;
1250 }
1251 pucmacaddr[i] = temp & 0xff;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001252 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "%x\n", pucmacaddr[i]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001253 }
1254OUT:
1255 return pucmacaddr;
1256}
Arnd Bergmann44a17eff2010-09-30 10:24:12 +02001257#endif
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001258
Arnd Bergmann44a17eff2010-09-30 10:24:12 +02001259static void convertEndian(B_UINT8 rwFlag, PUINT puiBuffer, UINT uiByteCount)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001260{
1261 UINT uiIndex = 0;
1262
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001263 if (RWM_WRITE == rwFlag) {
1264 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001265 puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001266 } else {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001267 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(UINT)); uiIndex++)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001268 puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001269 }
1270}
1271
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001272#define CACHE_ADDRESS_MASK 0x80000000
1273#define UNCACHE_ADDRESS_MASK 0xa0000000
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001274
1275int rdm(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1276{
Greg Dietschec5274ab2011-06-13 13:11:47 -05001277 return Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001278 uiAddress, pucBuff, sSize);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001279}
Greg Dietschec5274ab2011-06-13 13:11:47 -05001280
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001281int wrm(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1282{
1283 int iRetVal;
1284
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001285 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001286 uiAddress, pucBuff, sSize);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001287 return iRetVal;
1288}
1289
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001290int wrmalt(PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001291{
1292 convertEndian(RWM_WRITE, pucBuff, size);
1293 return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1294}
1295
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001296int rdmalt(PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001297{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001298 INT uiRetVal = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001299
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001300 uiRetVal = rdm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001301 convertEndian(RWM_READ, (PUINT)pucBuff, size);
1302
1303 return uiRetVal;
1304}
1305
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001306int wrmWithLock(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1307{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001308 INT status = STATUS_SUCCESS;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001309 down(&Adapter->rdmwrmsync);
1310
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001311 if ((Adapter->IdleMode == TRUE) ||
1312 (Adapter->bShutStatus == TRUE) ||
1313 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1314
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001315 status = -EACCES;
1316 goto exit;
1317 }
1318
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001319 status = wrm(Adapter, uiAddress, pucBuff, sSize);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001320exit:
1321 up(&Adapter->rdmwrmsync);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001322 return status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001323}
1324
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001325int wrmaltWithLock(PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001326{
1327 int iRetVal = STATUS_SUCCESS;
1328
1329 down(&Adapter->rdmwrmsync);
1330
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001331 if ((Adapter->IdleMode == TRUE) ||
1332 (Adapter->bShutStatus == TRUE) ||
1333 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1334
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001335 iRetVal = -EACCES;
1336 goto exit;
1337 }
1338
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001339 iRetVal = wrmalt(Adapter, uiAddress, pucBuff, size);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001340exit:
1341 up(&Adapter->rdmwrmsync);
1342 return iRetVal;
1343}
1344
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001345int rdmaltWithLock(PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001346{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001347 INT uiRetVal = STATUS_SUCCESS;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001348
1349 down(&Adapter->rdmwrmsync);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001350 if ((Adapter->IdleMode == TRUE) ||
1351 (Adapter->bShutStatus == TRUE) ||
1352 (Adapter->bPreparingForLowPowerMode == TRUE)) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001353
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001354 uiRetVal = -EACCES;
1355 goto exit;
1356 }
1357
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001358 uiRetVal = rdmalt(Adapter, uiAddress, pucBuff, size);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001359exit:
1360 up(&Adapter->rdmwrmsync);
1361 return uiRetVal;
1362}
1363
Arnd Bergmann44a17eff2010-09-30 10:24:12 +02001364static VOID HandleShutDownModeWakeup(PMINI_ADAPTER Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001365{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001366 int clear_abort_pattern = 0, Status = 0;
1367 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1368 /* target has woken up From Shut Down */
1369 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Clearing Shut Down Software abort pattern\n");
1370 Status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC, (PUINT)&clear_abort_pattern, sizeof(clear_abort_pattern));
1371 if (Status) {
1372 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001373 return;
1374 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001375
1376 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001377 msleep(100);
1378 InterfaceHandleShutdownModeWakeup(Adapter);
1379 msleep(100);
1380 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001381
1382 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001383 Adapter->DriverState = NO_NETWORK_ENTRY;
1384 wake_up(&Adapter->LEDInfo.notify_led_event);
1385 }
1386
1387 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
1388 Adapter->bShutStatus = FALSE;
1389 wake_up(&Adapter->lowpower_mode_wait_queue);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001390 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001391}
1392
Arnd Bergmann44a17eff2010-09-30 10:24:12 +02001393static VOID SendShutModeResponse(PMINI_ADAPTER Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001394{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001395 CONTROL_MESSAGE stShutdownResponse;
1396 UINT NVMAccess = 0, lowPwrAbortMsg = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001397 UINT Status = 0;
1398
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001399 memset(&stShutdownResponse, 0, sizeof(CONTROL_MESSAGE));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001400 stShutdownResponse.Leader.Status = LINK_UP_CONTROL_REQ;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001401 stShutdownResponse.Leader.PLength = 8; /* 8 bytes; */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001402 stShutdownResponse.szData[0] = LINK_UP_ACK;
1403 stShutdownResponse.szData[1] = LINK_SHUTDOWN_REQ_FROM_FIRMWARE;
1404
1405 /*********************************
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001406 * down_trylock -
1407 * if [ semaphore is available ]
1408 * acquire semaphone and return value 0 ;
1409 * else
1410 * return non-zero value ;
1411 *
1412 ***********************************/
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001413
1414 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001415 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001416
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001417 if (NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) {
1418 if (!NVMAccess)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001419 up(&Adapter->NVMRdmWrmLock);
1420
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001421 if (!lowPwrAbortMsg)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001422 up(&Adapter->LowPowerModeSync);
1423
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001424 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Device Access is going on NACK the Shut Down MODE\n");
1425 stShutdownResponse.szData[2] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001426 Adapter->bPreparingForLowPowerMode = FALSE;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001427 } else {
1428 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Sending SHUTDOWN MODE ACK\n");
1429 stShutdownResponse.szData[2] = SHUTDOWN_ACK_FROM_DRIVER; /* ShutDown ACK */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001430
1431 /* Wait for the LED to TURN OFF before sending ACK response */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001432 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001433 INT iRetVal = 0;
1434
1435 /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1436 Adapter->DriverState = LOWPOWER_MODE_ENTER;
1437 wake_up(&Adapter->LEDInfo.notify_led_event);
1438
1439 /* Wait for 1 SEC for LED to OFF */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001440 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001441
1442 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001443 if (iRetVal <= 0) {
1444 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001445 Adapter->DriverState = NO_NETWORK_ENTRY;
1446 wake_up(&Adapter->LEDInfo.notify_led_event);
1447 }
1448 }
1449
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001450 if (stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER) {
1451 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ACKING SHUTDOWN MODE !!!!!!!!!");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001452 down(&Adapter->rdmwrmsync);
1453 Adapter->bPreparingForLowPowerMode = TRUE;
1454 up(&Adapter->rdmwrmsync);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001455 /* Killing all URBS. */
1456 if (Adapter->bDoSuspend == TRUE)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001457 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001458 } else {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001459 Adapter->bPreparingForLowPowerMode = FALSE;
1460 }
1461
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001462 if (!NVMAccess)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001463 up(&Adapter->NVMRdmWrmLock);
1464
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001465 if (!lowPwrAbortMsg)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001466 up(&Adapter->LowPowerModeSync);
1467 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001468
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001469 Status = CopyBufferToControlPacket(Adapter, &stShutdownResponse);
1470 if ((Status != STATUS_SUCCESS)) {
1471 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "fail to send the Idle mode Request\n");
1472 Adapter->bPreparingForLowPowerMode = FALSE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001473 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001474 }
1475}
1476
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001477static void HandleShutDownModeRequest(PMINI_ADAPTER Adapter, PUCHAR pucBuffer)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001478{
1479 B_UINT32 uiResetValue = 0;
1480
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001481 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001482
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001483 if (*(pucBuffer+1) == COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001484 HandleShutDownModeWakeup(Adapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001485 } else if (*(pucBuffer+1) == LINK_SHUTDOWN_REQ_FROM_FIRMWARE) {
1486 /* Target wants to go to Shut Down Mode */
1487 /* InterfacePrepareForShutdown(Adapter); */
1488 if (Adapter->chip_id == BCS220_2 ||
1489 Adapter->chip_id == BCS220_2BC ||
1490 Adapter->chip_id == BCS250_BC ||
1491 Adapter->chip_id == BCS220_3) {
1492
1493 rdmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001494 uiResetValue |= (1<<17);
1495 wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1496 }
1497
1498 SendShutModeResponse(Adapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001499 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ShutDownModeResponse:Notification received: Sending the response(Ack/Nack)\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001500 }
1501
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001502 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001503 return;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001504}
1505
1506VOID ResetCounters(PMINI_ADAPTER Adapter)
1507{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001508 beceem_protocol_reset(Adapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001509 Adapter->CurrNumRecvDescs = 0;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001510 Adapter->PrevNumRecvDescs = 0;
1511 Adapter->LinkUpStatus = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001512 Adapter->LinkStatus = 0;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001513 atomic_set(&Adapter->cntrlpktCnt, 0);
1514 atomic_set(&Adapter->TotalPacketCount, 0);
1515 Adapter->fw_download_done = FALSE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001516 Adapter->LinkStatus = 0;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001517 Adapter->AutoLinkUp = FALSE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001518 Adapter->IdleMode = FALSE;
1519 Adapter->bShutStatus = FALSE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001520}
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001521
Kevin McKinney92562ae2012-05-26 12:05:03 -04001522struct bcm_classifier_rule *GetFragIPClsEntry(PMINI_ADAPTER Adapter, USHORT usIpIdentification, ULONG SrcIP)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001523{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001524 UINT uiIndex = 0;
1525 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1526 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1527 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1528 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIP) &&
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001529 !Adapter->astFragmentedPktClassifierTable[uiIndex].bOutOfOrderFragment)
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001530
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001531 return Adapter->astFragmentedPktClassifierTable[uiIndex].pstMatchedClassifierEntry;
1532 }
1533 return NULL;
1534}
1535
Kevin McKinney7f224852012-05-26 12:05:02 -04001536void AddFragIPClsEntry(PMINI_ADAPTER Adapter, struct bcm_fragmented_packet_info *psFragPktInfo)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001537{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001538 UINT uiIndex = 0;
1539 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1540 if (!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) {
Kevin McKinney7f224852012-05-26 12:05:02 -04001541 memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex], psFragPktInfo, sizeof(struct bcm_fragmented_packet_info));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001542 break;
1543 }
1544 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001545}
1546
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001547void DelFragIPClsEntry(PMINI_ADAPTER Adapter, USHORT usIpIdentification, ULONG SrcIp)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001548{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001549 UINT uiIndex = 0;
1550 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1551 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1552 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1553 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIp))
1554
Kevin McKinney7f224852012-05-26 12:05:02 -04001555 memset(&Adapter->astFragmentedPktClassifierTable[uiIndex], 0, sizeof(struct bcm_fragmented_packet_info));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001556 }
1557}
1558
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001559void update_per_cid_rx(PMINI_ADAPTER Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001560{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001561 UINT qindex = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001562
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001563 if ((jiffies - Adapter->liDrainCalculated) < XSECONDS)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001564 return;
1565
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001566 for (qindex = 0; qindex < HiPriority; qindex++) {
1567 if (Adapter->PackInfo[qindex].ucDirection == 0) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001568 Adapter->PackInfo[qindex].uiCurrentRxRate =
1569 (Adapter->PackInfo[qindex].uiCurrentRxRate +
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001570 Adapter->PackInfo[qindex].uiThisPeriodRxBytes) / 2;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001571
1572 Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001573 } else {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001574 Adapter->PackInfo[qindex].uiCurrentDrainRate =
1575 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001576 Adapter->PackInfo[qindex].uiThisPeriodSentBytes) / 2;
1577 Adapter->PackInfo[qindex].uiThisPeriodSentBytes = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001578 }
1579 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001580 Adapter->liDrainCalculated = jiffies;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001581}
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001582
1583void update_per_sf_desc_cnts(PMINI_ADAPTER Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001584{
1585 INT iIndex = 0;
1586 u32 uibuff[MAX_TARGET_DSX_BUFFERS];
Kevin McKinney41c7b7c2011-11-06 09:40:11 -05001587 int bytes;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001588
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001589 if (!atomic_read(&Adapter->uiMBupdate))
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001590 return;
1591
Kevin McKinney41c7b7c2011-11-06 09:40:11 -05001592 bytes = rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (PUINT)uibuff, sizeof(UINT) * MAX_TARGET_DSX_BUFFERS);
1593 if (bytes < 0) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001594 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001595 return;
1596 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001597
1598 for (iIndex = 0; iIndex < HiPriority; iIndex++) {
1599 if (Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection) {
1600 if (Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001601 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001602 else
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001603 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid VCID : %x\n", Adapter->PackInfo[iIndex].usVCID_Value);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001604 }
1605 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001606 atomic_set(&Adapter->uiMBupdate, FALSE);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001607}
1608
1609void flush_queue(PMINI_ADAPTER Adapter, UINT iQIndex)
1610{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001611 struct sk_buff *PacketToDrop = NULL;
1612 struct net_device_stats *netstats = &Adapter->dev->stats;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001613 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1614
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001615 while (Adapter->PackInfo[iQIndex].FirstTxQueue && atomic_read(&Adapter->TotalPacketCount)) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001616 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001617 if (PacketToDrop && PacketToDrop->len) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001618 netstats->tx_dropped++;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001619 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, Adapter->PackInfo[iQIndex].LastTxQueue);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001620 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1621 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1622
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001623 /* Adding dropped statistics */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001624 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1625 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
Stephen Hemminger082e8892010-11-01 09:35:21 -04001626 dev_kfree_skb(PacketToDrop);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001627 atomic_dec(&Adapter->TotalPacketCount);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001628 }
1629 }
1630 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001631}
1632
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001633static void beceem_protocol_reset(PMINI_ADAPTER Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001634{
Stephen Hemminger4fd64dd2010-11-01 12:12:31 -04001635 int i;
Stephen Hemminger4fd64dd2010-11-01 12:12:31 -04001636 if (netif_msg_link(Adapter))
Stephen Hemminger9ec44752010-11-01 12:18:36 -04001637 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
Stephen Hemminger4fd64dd2010-11-01 12:12:31 -04001638
1639 netif_carrier_off(Adapter->dev);
1640 netif_stop_queue(Adapter->dev);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001641
1642 Adapter->IdleMode = FALSE;
1643 Adapter->LinkUpStatus = FALSE;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001644 ClearTargetDSXBuffer(Adapter, 0, TRUE);
1645 /* Delete All Classifier Rules */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001646
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001647 for (i = 0; i < HiPriority; i++)
1648 DeleteAllClassifiersForSF(Adapter, i);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001649
1650 flush_all_queues(Adapter);
1651
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001652 if (Adapter->TimerActive == TRUE)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001653 Adapter->TimerActive = FALSE;
1654
Kevin McKinney7f224852012-05-26 12:05:02 -04001655 memset(Adapter->astFragmentedPktClassifierTable, 0, sizeof(struct bcm_fragmented_packet_info) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001656
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001657 for (i = 0; i < HiPriority; i++) {
1658 /* resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF. */
1659 /* It is same between MIBs and SF. */
1660 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable, 0, sizeof(S_MIBS_EXTSERVICEFLOW_PARAMETERS));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001661 }
1662}