blob: 883f7394dee6ff9451f6dd225bf102ceefbacdf3 [file] [log] [blame]
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001#include "headers.h"
2
Kevin McKinney29794602012-05-26 12:05:12 -04003static int BcmFileDownload(struct bcm_mini_adapter *Adapter, const char *path, unsigned int loc);
Kevin McKinney7a15b792012-10-18 22:40:08 -04004static void doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter);
Kevin McKinney29794602012-05-26 12:05:12 -04005static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer);
6static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter);
7static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter);
Stephen Hemminger9dd47ee2010-11-01 12:24:00 -04008
Kevin McKinney7a15b792012-10-18 22:40:08 -04009static void default_wimax_protocol_initialize(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070010{
Kevin McKinney9ef07602012-10-18 22:40:12 -040011 unsigned int 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;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070024}
25
Kevin McKinney7af141342012-10-18 22:40:13 -040026int InitAdapter(struct bcm_mini_adapter *psAdapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070027{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040028 int i = 0;
Kevin McKinney7af141342012-10-18 22:40:13 -040029 int Status = STATUS_SUCCESS;
Robin Schroerfe830732014-06-16 13:01:46 +020030
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -040031 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;
Lisa Nguyenf70c8a92013-10-28 01:36:19 -070056 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
Kevin McKinney7a15b792012-10-18 22:40:08 -040096void AdapterFree(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070097{
Stephen Hemmingere614e282010-11-01 09:52:14 -040098 int count;
Robin Schroerfe830732014-06-16 13:01:46 +020099
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700100 beceem_protocol_reset(Adapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700101 vendorextnExit(Adapter);
102
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400103 if (Adapter->control_packet_handler && !IS_ERR(Adapter->control_packet_handler))
104 kthread_stop(Adapter->control_packet_handler);
Stephen Hemmingere614e282010-11-01 09:52:14 -0400105
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400106 if (Adapter->transmit_packet_thread && !IS_ERR(Adapter->transmit_packet_thread))
107 kthread_stop(Adapter->transmit_packet_thread);
Stephen Hemmingere614e282010-11-01 09:52:14 -0400108
109 wake_up(&Adapter->process_read_wait_queue);
110
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400111 if (Adapter->LEDInfo.led_thread_running & (BCM_LED_THREAD_RUNNING_ACTIVELY | BCM_LED_THREAD_RUNNING_INACTIVELY))
112 kthread_stop(Adapter->LEDInfo.led_cntrl_threadid);
Stephen Hemmingere614e282010-11-01 09:52:14 -0400113
Stephen Hemminger4ea4f7a2010-11-01 14:06:24 -0400114 unregister_networkdev(Adapter);
Stephen Hemmingere614e282010-11-01 09:52:14 -0400115
116 /* FIXME: use proper wait_event and refcounting */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400117 while (atomic_read(&Adapter->ApplicationRunning)) {
118 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Waiting for Application to close.. %d\n", atomic_read(&Adapter->ApplicationRunning));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700119 msleep(100);
120 }
121 unregister_control_device_interface(Adapter);
Stephen Hemmingere614e282010-11-01 09:52:14 -0400122 kfree(Adapter->pstargetparams);
123
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400124 for (count = 0; count < MAX_CNTRL_PKTS; count++)
Stephen Hemmingere614e282010-11-01 09:52:14 -0400125 kfree(Adapter->txctlpacket[count]);
126
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700127 FreeAdapterDsxBuffer(Adapter);
Stephen Hemmingere614e282010-11-01 09:52:14 -0400128 kfree(Adapter->pvInterfaceAdapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700129
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400130 /* Free the PHS Interface */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700131 PhsCleanup(&Adapter->stBCMPhsContext);
132
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700133 BcmDeAllocFlashCSStructure(Adapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700134
Stephen Hemmingere614e282010-11-01 09:52:14 -0400135 free_netdev(Adapter->dev);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700136}
137
Kevin McKinney29794602012-05-26 12:05:12 -0400138static int create_worker_threads(struct bcm_mini_adapter *psAdapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700139{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400140 /* Rx Control Packets Processing */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700141 psAdapter->control_packet_handler = kthread_run((int (*)(void *))
Stephen Hemminger2d087482010-11-01 12:14:01 -0400142 control_packet_handler, psAdapter, "%s-rx", DRV_NAME);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400143 if (IS_ERR(psAdapter->control_packet_handler)) {
Stephen Hemminger2d087482010-11-01 12:14:01 -0400144 pr_notice(DRV_NAME ": could not create control thread\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700145 return PTR_ERR(psAdapter->control_packet_handler);
146 }
Stephen Hemminger2d087482010-11-01 12:14:01 -0400147
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400148 /* Tx Thread */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700149 psAdapter->transmit_packet_thread = kthread_run((int (*)(void *))
Stephen Hemminger2d087482010-11-01 12:14:01 -0400150 tx_pkt_handler, psAdapter, "%s-tx", DRV_NAME);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400151 if (IS_ERR(psAdapter->transmit_packet_thread)) {
Stephen Hemminger2d087482010-11-01 12:14:01 -0400152 pr_notice(DRV_NAME ": could not creat transmit thread\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700153 kthread_stop(psAdapter->control_packet_handler);
154 return PTR_ERR(psAdapter->transmit_packet_thread);
155 }
156 return 0;
157}
158
Kevin McKinney29794602012-05-26 12:05:12 -0400159static struct file *open_firmware_file(struct bcm_mini_adapter *Adapter, const char *path)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700160{
Al Viro32aecdd2012-07-22 21:02:01 +0400161 struct file *flp = filp_open(path, O_RDONLY, S_IRWXU);
Robin Schroerfe830732014-06-16 13:01:46 +0200162
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400163 if (IS_ERR(flp)) {
164 pr_err(DRV_NAME "Unable To Open File %s, err %ld", path, PTR_ERR(flp));
165 flp = NULL;
166 }
Stephen Hemminger2d087482010-11-01 12:14:01 -0400167
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400168 if (Adapter->device_removed)
169 flp = NULL;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700170
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400171 return flp;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700172}
173
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400174/* Arguments:
175 * Logical Adapter
176 * Path to image file
177 * Download Address on the chip
178 */
Kevin McKinney29794602012-05-26 12:05:12 -0400179static int BcmFileDownload(struct bcm_mini_adapter *Adapter, const char *path, unsigned int loc)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700180{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400181 int errorno = 0;
182 struct file *flp = NULL;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400183 struct timeval tv = {0};
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700184
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400185 flp = open_firmware_file(Adapter, path);
186 if (!flp) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400187 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Unable to Open %s\n", path);
Al Viro32aecdd2012-07-22 21:02:01 +0400188 return -ENOENT;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400189 }
Al Viro496ad9a2013-01-23 17:07:38 -0500190 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Opened file is = %s and length =0x%lx to be downloaded at =0x%x", path, (unsigned long)file_inode(flp)->i_size, loc);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400191 do_gettimeofday(&tv);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700192
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400193 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "download start %lx", ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)));
194 if (Adapter->bcm_file_download(Adapter->pvInterfaceAdapter, flp, loc)) {
195 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to download the firmware with error %x!!!", -EIO);
196 errorno = -EIO;
197 goto exit_download;
198 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400199 vfs_llseek(flp, 0, 0);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400200 if (Adapter->bcm_file_readback_from_chip(Adapter->pvInterfaceAdapter, flp, loc)) {
201 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to read back firmware!");
202 errorno = -EIO;
203 goto exit_download;
204 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700205
206exit_download:
Al Viro32aecdd2012-07-22 21:02:01 +0400207 filp_close(flp, NULL);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400208 return errorno;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700209}
210
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700211/**
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400212 * @ingroup ctrl_pkt_functions
213 * This function copies the contents of given buffer
214 * to the control packet and queues it for transmission.
Masanari Iida6abaf582013-08-23 22:55:31 +0900215 * @note Do not acquire the spinlock, as it it already acquired.
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400216 * @return SUCCESS/FAILURE.
217 * Arguments:
218 * Logical Adapter
219 * Control Packet Buffer
220 */
Kevin McKinney7af141342012-10-18 22:40:13 -0400221int CopyBufferToControlPacket(struct bcm_mini_adapter *Adapter, void *ioBuffer)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700222{
Kevin McKinneyff352042012-05-26 12:05:11 -0400223 struct bcm_leader *pLeader = NULL;
Kevin McKinney7af141342012-10-18 22:40:13 -0400224 int Status = 0;
Kevin McKinney895b1fb2012-10-18 22:40:14 -0400225 unsigned char *ctrl_buff;
Kevin McKinney9ef07602012-10-18 22:40:12 -0400226 unsigned int pktlen = 0;
Kevin McKinney2610c7a2012-05-26 12:05:08 -0400227 struct bcm_link_request *pLinkReq = NULL;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400228 PUCHAR pucAddIndication = NULL;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700229
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400230 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "======>");
231 if (!ioBuffer) {
232 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Got Null Buffer\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700233 return -EINVAL;
234 }
235
Kevin McKinney2610c7a2012-05-26 12:05:08 -0400236 pLinkReq = (struct bcm_link_request *)ioBuffer;
Kevin McKinneyff352042012-05-26 12:05:11 -0400237 pLeader = (struct bcm_leader *)ioBuffer; /* ioBuffer Contains sw_Status and Payload */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700238
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400239 if (Adapter->bShutStatus == TRUE &&
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700240 pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD &&
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400241 pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE) {
242
243 /* Got sync down in SHUTDOWN..we could not process this. */
244 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "SYNC DOWN Request in Shut Down Mode..\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700245 return STATUS_FAILURE;
246 }
247
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400248 if ((pLeader->Status == LINK_UP_CONTROL_REQ) &&
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700249 ((pLinkReq->szData[0] == LINK_UP_REQ_PAYLOAD &&
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400250 (pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE)) || /* Sync Up Command */
251 pLinkReq->szData[0] == NETWORK_ENTRY_REQ_PAYLOAD)) /* Net Entry Command */ {
252
253 if (Adapter->LinkStatus > PHY_SYNC_ACHIVED) {
254 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "LinkStatus is Greater than PHY_SYN_ACHIEVED");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700255 return STATUS_FAILURE;
256 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400257
Kevin McKinneyb64c8462012-10-18 22:40:15 -0400258 if (Adapter->bShutStatus == TRUE) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400259 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "SYNC UP IN SHUTDOWN..Device WakeUp\n");
Lisa Nguyenf70c8a92013-10-28 01:36:19 -0700260 if (Adapter->bTriedToWakeUpFromlowPowerMode == false) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400261 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Waking up for the First Time..\n");
262 Adapter->usIdleModePattern = ABORT_SHUTDOWN_MODE; /* change it to 1 for current support. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700263 Adapter->bWakeUpDevice = TRUE;
264 wake_up(&Adapter->process_rx_cntrlpkt);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400265 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->bShutStatus, (5 * HZ));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700266
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400267 if (Status == -ERESTARTSYS)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700268 return Status;
269
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400270 if (Adapter->bShutStatus) {
271 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Shutdown Mode Wake up Failed - No Wake Up Received\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700272 return STATUS_FAILURE;
273 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400274 } else {
275 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 -0700276 }
277 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700278 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700279
Kevin McKinneyb64c8462012-10-18 22:40:15 -0400280 if (Adapter->IdleMode == TRUE) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400281 /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle mode ... hence\n"); */
282 if (pLeader->Status == LINK_UP_CONTROL_REQ || pLeader->Status == 0x80 ||
283 pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ) {
284
285 if ((pLeader->Status == LINK_UP_CONTROL_REQ) && (pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD)) {
Robin Schroer28c520a2014-06-16 13:01:47 +0200286 if (pLinkReq->szData[1] == LINK_SYNC_DOWN_SUBTYPE) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400287 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Link Down Sent in Idle Mode\n");
288 Adapter->usIdleModePattern = ABORT_IDLE_SYNCDOWN; /* LINK DOWN sent in Idle Mode */
289 } else {
290 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "ABORT_IDLE_MODE pattern is being written\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700291 Adapter->usIdleModePattern = ABORT_IDLE_REG;
292 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400293 } else {
294 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "ABORT_IDLE_MODE pattern is being written\n");
295 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700296 }
297
298 /*Setting bIdleMode_tx_from_host to TRUE to indicate LED control thread to represent
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400299 * the wake up from idlemode is from host
300 */
301 /* Adapter->LEDInfo.bIdleMode_tx_from_host = TRUE; */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700302 Adapter->bWakeUpDevice = TRUE;
303 wake_up(&Adapter->process_rx_cntrlpkt);
304
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400305 /* We should not send DREG message down while in idlemode. */
306 if (LINK_DOWN_REQ_PAYLOAD == pLinkReq->szData[0])
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700307 return STATUS_SUCCESS;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700308
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400309 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->IdleMode, (5 * HZ));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700310
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400311 if (Status == -ERESTARTSYS)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700312 return Status;
313
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400314 if (Adapter->IdleMode) {
315 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Idle Mode Wake up Failed - No Wake Up Received\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700316 return STATUS_FAILURE;
317 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400318 } else {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700319 return STATUS_SUCCESS;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400320 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700321 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400322
323 /* The Driver has to send control messages with a particular VCID */
324 pLeader->Vcid = VCID_CONTROL_PACKET; /* VCID for control packet. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700325
326 /* Allocate skb for Control Packet */
327 pktlen = pLeader->PLength;
328 ctrl_buff = (char *)Adapter->txctlpacket[atomic_read(&Adapter->index_wr_txcntrlpkt)%MAX_CNTRL_PKTS];
329
Kevin McKinney895b1fb2012-10-18 22:40:14 -0400330 if (!ctrl_buff) {
331 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "mem allocation Failed");
332 return -ENOMEM;
333 }
334
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400335 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Control packet to be taken =%d and address is =%pincoming address is =%p and packet len=%x",
336 atomic_read(&Adapter->index_wr_txcntrlpkt), ctrl_buff, ioBuffer, pktlen);
Kevin McKinney895b1fb2012-10-18 22:40:14 -0400337
338 if (pLeader) {
339 if ((pLeader->Status == 0x80) ||
340 (pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ)) {
341 /*
342 * Restructure the DSX message to handle Multiple classifier Support
343 * Write the Service Flow param Structures directly to the target
344 * and embed the pointers in the DSX messages sent to target.
345 */
346 /* Lets store the current length of the control packet we are transmitting */
347 pucAddIndication = (PUCHAR)ioBuffer + LEADER_SIZE;
348 pktlen = pLeader->PLength;
349 Status = StoreCmControlResponseMessage(Adapter, pucAddIndication, &pktlen);
350 if (Status != 1) {
Lisa Nguyenf70c8a92013-10-28 01:36:19 -0700351 ClearTargetDSXBuffer(Adapter, ((struct bcm_add_indication_alt *)pucAddIndication)->u16TID, false);
Kevin McKinney895b1fb2012-10-18 22:40:14 -0400352 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, " Error Restoring The DSX Control Packet. Dsx Buffers on Target may not be Setup Properly ");
353 return STATUS_FAILURE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700354 }
Kevin McKinney895b1fb2012-10-18 22:40:14 -0400355 /*
356 * update the leader to use the new length
357 * The length of the control packet is length of message being sent + Leader length
358 */
359 pLeader->PLength = pktlen;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700360 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700361 }
Kevin McKinney895b1fb2012-10-18 22:40:14 -0400362
363 if (pktlen + LEADER_SIZE > MAX_CNTL_PKT_SIZE)
364 return -EINVAL;
365
366 memset(ctrl_buff, 0, pktlen+LEADER_SIZE);
367 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Copying the Control Packet Buffer with length=%d\n", pLeader->PLength);
368 *(struct bcm_leader *)ctrl_buff = *pLeader;
369 memcpy(ctrl_buff + LEADER_SIZE, ((PUCHAR)ioBuffer + LEADER_SIZE), pLeader->PLength);
370 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Enqueuing the Control Packet");
371
372 /* Update the statistics counters */
373 spin_lock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
374 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost += pLeader->PLength;
375 Adapter->PackInfo[HiPriority].uiCurrentPacketsOnHost++;
376 atomic_inc(&Adapter->TotalPacketCount);
377 spin_unlock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
378 Adapter->PackInfo[HiPriority].bValid = TRUE;
379
380 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "CurrBytesOnHost: %x bValid: %x",
381 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost,
382 Adapter->PackInfo[HiPriority].bValid);
383 Status = STATUS_SUCCESS;
384 /*Queue the packet for transmission */
385 atomic_inc(&Adapter->index_wr_txcntrlpkt);
386 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Calling transmit_packets");
387 atomic_set(&Adapter->TxPktAvail, 1);
388 wake_up(&Adapter->tx_packet_wait_queue);
389
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400390 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<====");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700391 return Status;
392}
393
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700394/******************************************************************
395* Function - LinkMessage()
396*
397* Description - This function builds the Sync-up and Link-up request
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400398* packet messages depending on the device Link status.
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700399*
400* Parameters - Adapter: Pointer to the Adapter structure.
401*
402* Returns - None.
403*******************************************************************/
Kevin McKinney7a15b792012-10-18 22:40:08 -0400404void LinkMessage(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700405{
Kevin McKinney2610c7a2012-05-26 12:05:08 -0400406 struct bcm_link_request *pstLinkRequest = NULL;
Robin Schroerfe830732014-06-16 13:01:46 +0200407
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400408 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>");
409 if (Adapter->LinkStatus == SYNC_UP_REQUEST && Adapter->AutoSyncup) {
Kevin McKinney2610c7a2012-05-26 12:05:08 -0400410 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400411 if (!pstLinkRequest) {
412 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 -0700413 return;
414 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400415 /* sync up request... */
416 Adapter->LinkStatus = WAIT_FOR_SYNC; /* current link status */
417 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For SyncUp...");
418 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
419 pstLinkRequest->szData[1] = LINK_SYNC_UP_SUBTYPE;
420 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
421 pstLinkRequest->Leader.PLength = sizeof(ULONG);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700422 Adapter->bSyncUpRequestSent = TRUE;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400423
424 } else if (Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp) {
Kevin McKinney2610c7a2012-05-26 12:05:08 -0400425 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400426 if (!pstLinkRequest) {
427 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 -0700428 return;
429 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400430 /* LINK_UP_REQUEST */
431 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For LinkUp...");
432 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
433 pstLinkRequest->szData[1] = LINK_NET_ENTRY;
434 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
435 pstLinkRequest->Leader.PLength = sizeof(ULONG);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700436 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400437 if (pstLinkRequest) {
438 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700439 CopyBufferToControlPacket(Adapter, pstLinkRequest);
Stephen Hemminger082e8892010-11-01 09:35:21 -0400440 kfree(pstLinkRequest);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700441 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400442 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700443 return;
444}
445
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700446/**********************************************************************
447* Function - StatisticsResponse()
448*
449* Description - This function handles the Statistics response packet.
450*
451* Parameters - Adapter : Pointer to the Adapter structure.
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400452* - pvBuffer: Starting address of Statistic response data.
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700453*
454* Returns - None.
455************************************************************************/
Kevin McKinney7a15b792012-10-18 22:40:08 -0400456void StatisticsResponse(struct bcm_mini_adapter *Adapter, void *pvBuffer)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700457{
Kevin McKinneya8a1cdd2011-10-07 18:50:10 -0400458 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>", __func__);
Stephen Hemmingere39e3be2010-11-01 11:14:29 -0400459 Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
Kevin McKinney9ef07602012-10-18 22:40:12 -0400460 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (unsigned int)Adapter->StatisticsPointer);
Kevin McKinneya8a1cdd2011-10-07 18:50:10 -0400461 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====", __func__);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700462}
463
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700464/**********************************************************************
465* Function - LinkControlResponseMessage()
466*
467* Description - This function handles the Link response packets.
468*
469* Parameters - Adapter : Pointer to the Adapter structure.
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400470* - pucBuffer: Starting address of Link response data.
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700471*
472* Returns - None.
473***********************************************************************/
Kevin McKinney7a15b792012-10-18 22:40:08 -0400474void LinkControlResponseMessage(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700475{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400476 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700477
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400478 if (*pucBuffer == LINK_UP_ACK) {
479 switch (*(pucBuffer+1)) {
480 case PHY_SYNC_ACHIVED: /* SYNCed UP */
481 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHY_SYNC_ACHIVED");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700482
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400483 if (Adapter->LinkStatus == LINKUP_DONE)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700484 beceem_protocol_reset(Adapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700485
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400486 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
487 Adapter->LinkStatus = PHY_SYNC_ACHIVED;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700488
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400489 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700490 Adapter->DriverState = NO_NETWORK_ENTRY;
491 wake_up(&Adapter->LEDInfo.notify_led_event);
492 }
493
494 LinkMessage(Adapter);
495 break;
496
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400497 case LINKUP_DONE:
498 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LINKUP_DONE");
499 Adapter->LinkStatus = LINKUP_DONE;
500 Adapter->bPHSEnabled = *(pucBuffer+3);
501 Adapter->bETHCSEnabled = *(pucBuffer+4) & ETH_CS_MASK;
502 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHS Support Status Received In LinkUp Ack : %x\n", Adapter->bPHSEnabled);
503
Lisa Nguyenf70c8a92013-10-28 01:36:19 -0700504 if ((false == Adapter->bShutStatus) && (false == Adapter->IdleMode)) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400505 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
506 Adapter->DriverState = NORMAL_OPERATION;
507 wake_up(&Adapter->LEDInfo.notify_led_event);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700508 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700509 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400510 LinkMessage(Adapter);
511 break;
512
513 case WAIT_FOR_SYNC:
514 /*
515 * Driver to ignore the DREG_RECEIVED
516 * WiMAX Application should handle this Message
517 */
518 /* Adapter->liTimeSinceLastNetEntry = 0; */
519 Adapter->LinkUpStatus = 0;
520 Adapter->LinkStatus = 0;
521 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
Lisa Nguyenf70c8a92013-10-28 01:36:19 -0700522 Adapter->bTriedToWakeUpFromlowPowerMode = false;
523 Adapter->IdleMode = false;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400524 beceem_protocol_reset(Adapter);
525
526 break;
527 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
528 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
529 {
530 HandleShutDownModeRequest(Adapter, pucBuffer);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700531 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400532 break;
533 default:
534 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x", *(pucBuffer + 1));
535 break;
536 }
537 } else if (SET_MAC_ADDRESS_RESPONSE == *pucBuffer) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700538 PUCHAR puMacAddr = (pucBuffer + 1);
Robin Schroerfe830732014-06-16 13:01:46 +0200539
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400540 Adapter->LinkStatus = SYNC_UP_REQUEST;
541 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 -0700542 LinkMessage(Adapter);
543 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
544 }
Kevin McKinneya8a1cdd2011-10-07 18:50:10 -0400545 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====", __func__);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700546}
547
Kevin McKinney29794602012-05-26 12:05:12 -0400548void SendIdleModeResponse(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700549{
Kevin McKinney7af141342012-10-18 22:40:13 -0400550 int status = 0, NVMAccess = 0, lowPwrAbortMsg = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700551 struct timeval tv;
Kevin McKinney2610c7a2012-05-26 12:05:08 -0400552 struct bcm_link_request stIdleResponse = {{0} };
Robin Schroerfe830732014-06-16 13:01:46 +0200553
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700554 memset(&tv, 0, sizeof(tv));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400555 stIdleResponse.Leader.Status = IDLE_MESSAGE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700556 stIdleResponse.Leader.PLength = IDLE_MODE_PAYLOAD_LENGTH;
557 stIdleResponse.szData[0] = GO_TO_IDLE_MODE_PAYLOAD;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400558 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, " ============>");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700559
560 /*********************************
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400561 *down_trylock -
562 * if [ semaphore is available ]
563 * acquire semaphone and return value 0 ;
564 * else
565 * return non-zero value ;
566 *
567 ***********************************/
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700568
569 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400570 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700571
572
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400573 if ((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
574 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)) {
575
576 if (!NVMAccess)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700577 up(&Adapter->NVMRdmWrmLock);
578
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400579 if (!lowPwrAbortMsg)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700580 up(&Adapter->LowPowerModeSync);
581
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400582 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
583 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "HOST IS NACKING Idle mode To F/W!!!!!!!!");
Lisa Nguyenf70c8a92013-10-28 01:36:19 -0700584 Adapter->bPreparingForLowPowerMode = false;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400585 } else {
586 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; /* 2; Idle ACK */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700587 Adapter->StatisticsPointer = 0;
588
589 /* Wait for the LED to TURN OFF before sending ACK response */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400590 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Kevin McKinney7af141342012-10-18 22:40:13 -0400591 int iRetVal = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700592
593 /* Wake the LED Thread with IDLEMODE_ENTER State */
594 Adapter->DriverState = LOWPOWER_MODE_ENTER;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400595 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 -0700596 wake_up(&Adapter->LEDInfo.notify_led_event);
597
598 /* Wait for 1 SEC for LED to OFF */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400599 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700600
601 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400602 if (iRetVal <= 0) {
603 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700604 Adapter->DriverState = NORMAL_OPERATION;
605 wake_up(&Adapter->LEDInfo.notify_led_event);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400606 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 -0700607 }
608 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400609
610 if (stIdleResponse.szData[1] == TARGET_CAN_GO_TO_IDLE_MODE) {
611 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "ACKING IDLE MODE !!!!!!!!!");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700612 down(&Adapter->rdmwrmsync);
613 Adapter->bPreparingForLowPowerMode = TRUE;
614 up(&Adapter->rdmwrmsync);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400615 /* Killing all URBS. */
616 if (Adapter->bDoSuspend == TRUE)
Kevin McKinneyd6861cf2012-11-01 23:42:21 -0400617 Bcm_kill_all_URBs((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400618 } else {
Lisa Nguyenf70c8a92013-10-28 01:36:19 -0700619 Adapter->bPreparingForLowPowerMode = false;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700620 }
621
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400622 if (!NVMAccess)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700623 up(&Adapter->NVMRdmWrmLock);
624
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400625 if (!lowPwrAbortMsg)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700626 up(&Adapter->LowPowerModeSync);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700627 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400628
629 status = CopyBufferToControlPacket(Adapter, &stIdleResponse);
Robin Schroer28c520a2014-06-16 13:01:47 +0200630 if (status != STATUS_SUCCESS) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400631 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "fail to send the Idle mode Request\n");
Lisa Nguyenf70c8a92013-10-28 01:36:19 -0700632 Adapter->bPreparingForLowPowerMode = false;
Kevin McKinneyd6861cf2012-11-01 23:42:21 -0400633 StartInterruptUrb((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700634 }
635 do_gettimeofday(&tv);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400636 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 -0700637}
638
639/******************************************************************
640* Function - DumpPackInfo()
641*
642* Description - This function dumps the all Queue(PackInfo[]) details.
643*
644* Parameters - Adapter: Pointer to the Adapter structure.
645*
646* Returns - None.
647*******************************************************************/
Kevin McKinney7a15b792012-10-18 22:40:08 -0400648void DumpPackInfo(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700649{
Kevin McKinney9ef07602012-10-18 22:40:12 -0400650 unsigned int uiLoopIndex = 0;
651 unsigned int uiIndex = 0;
652 unsigned int uiClsfrIndex = 0;
Kevin McKinney92562ae2012-05-26 12:05:03 -0400653 struct bcm_classifier_rule *pstClassifierEntry = NULL;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700654
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400655 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
656 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "*********** Showing Details Of Queue %d***** ******", uiLoopIndex);
Lisa Nguyenf70c8a92013-10-28 01:36:19 -0700657 if (false == Adapter->PackInfo[uiLoopIndex].bValid) {
658 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid is false for %X index\n", uiLoopIndex);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700659 continue;
660 }
661
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400662 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " Dumping SF Rule Entry For SFID %lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
663 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " ucDirection %X\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
664
665 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
666 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv6 Service Flow\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700667 else
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400668 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv4 Service Flow\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700669
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400670 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SF Traffic Priority %X\n", Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
671
672 for (uiClsfrIndex = 0; uiClsfrIndex < MAX_CLASSIFIERS; uiClsfrIndex++) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700673 pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400674 if (!pstClassifierEntry->bUsed)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700675 continue;
676
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400677 if (pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700678 continue;
679
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400680 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X Classifier Rule ID : %X\n", uiClsfrIndex, pstClassifierEntry->uiClassifierRuleIndex);
681 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X usVCID_Value : %X\n", uiClsfrIndex, pstClassifierEntry->usVCID_Value);
682 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bProtocolValid : %X\n", uiClsfrIndex, pstClassifierEntry->bProtocolValid);
683 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bTOSValid : %X\n", uiClsfrIndex, pstClassifierEntry->bTOSValid);
684 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bDestIpValid : %X\n", uiClsfrIndex, pstClassifierEntry->bDestIpValid);
685 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bSrcIpValid : %X\n", uiClsfrIndex, pstClassifierEntry->bSrcIpValid);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700686
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400687 for (uiIndex = 0; uiIndex < MAX_PORT_RANGE; uiIndex++) {
688 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeLo:%X\n", pstClassifierEntry->usSrcPortRangeLo[uiIndex]);
689 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeHi:%X\n", pstClassifierEntry->usSrcPortRangeHi[uiIndex]);
690 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeLo:%X\n", pstClassifierEntry->usDestPortRangeLo[uiIndex]);
691 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeHi:%X\n", pstClassifierEntry->usDestPortRangeHi[uiIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700692 }
693
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400694 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPSourceAddressLength : 0x%x\n", pstClassifierEntry->ucIPSourceAddressLength);
695 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPDestinationAddressLength : 0x%x\n", pstClassifierEntry->ucIPDestinationAddressLength);
696 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPSourceAddressLength; uiIndex++) {
697 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
698 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpAddr :\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700699 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Addr);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400700 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpMask :\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700701 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Mask);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400702 } else {
703 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpAddr:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Addr[uiIndex]);
704 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpMask:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Mask[uiIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700705 }
706 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400707
708 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPDestinationAddressLength; uiIndex++) {
709 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
710 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpAddr :\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700711 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Addr);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400712 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpMask :\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700713 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Mask);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400714 } else {
715 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpAddr:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Addr[uiIndex]);
716 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpMask:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Mask[uiIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700717 }
718 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400719 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucProtocol:0x%X\n", pstClassifierEntry->ucProtocol[0]);
720 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tu8ClassifierRulePriority:%X\n", pstClassifierEntry->u8ClassifierRulePriority);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700721 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400722 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ulSFID:%lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
723 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "usVCID_Value:%X\n", Adapter->PackInfo[uiLoopIndex].usVCID_Value);
724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "PhsEnabled: 0x%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
725 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThreshold:%X\n", Adapter->PackInfo[uiLoopIndex].uiThreshold);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700726
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400727 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid:%X\n", Adapter->PackInfo[uiLoopIndex].bValid);
728 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bActive:%X\n", Adapter->PackInfo[uiLoopIndex].bActive);
729 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActivateReqSent: %x", Adapter->PackInfo[uiLoopIndex].bActivateRequestSent);
730 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "u8QueueType:%X\n", Adapter->PackInfo[uiLoopIndex].u8QueueType);
731 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxBucketSize:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize);
732 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPerSFTxResourceCount:%X\n", atomic_read(&Adapter->PackInfo[uiLoopIndex].uiPerSFTxResourceCount));
733 /* DumpDebug(DUMP_INFO,("bCSSupport:%X\n",Adapter->PackInfo[uiLoopIndex].bCSSupport)); */
734 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CurrQueueDepthOnTarget: %x\n", Adapter->PackInfo[uiLoopIndex].uiCurrentQueueDepthOnTarget);
735 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentBytesOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentBytesOnHost);
736 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentPacketsOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentPacketsOnHost);
737 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountBytes);
738 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountPackets);
739 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentBytes);
740 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentPackets);
741 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentDrainRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentDrainRate);
742 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThisPeriodSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiThisPeriodSentBytes);
743 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liDrainCalculated:%llX\n", Adapter->PackInfo[uiLoopIndex].liDrainCalculated);
744 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentTokenCount:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentTokenCount);
745 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liLastUpdateTokenAt:%llX\n", Adapter->PackInfo[uiLoopIndex].liLastUpdateTokenAt);
746 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxAllowedRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate);
747 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPendedLast:%X\n", Adapter->PackInfo[uiLoopIndex].uiPendedLast);
748 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "NumOfPacketsSent:%X\n", Adapter->PackInfo[uiLoopIndex].NumOfPacketsSent);
749 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Direction: %x\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
750 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CID: %x\n", Adapter->PackInfo[uiLoopIndex].usCID);
751 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ProtocolValid: %x\n", Adapter->PackInfo[uiLoopIndex].bProtocolValid);
752 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "TOSValid: %x\n", Adapter->PackInfo[uiLoopIndex].bTOSValid);
753 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "DestIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bDestIpValid);
754 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SrcIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bSrcIpValid);
755 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActiveSet: %x\n", Adapter->PackInfo[uiLoopIndex].bActiveSet);
756 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AdmittedSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAdmittedSet);
757 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AuthzSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAuthorizedSet);
758 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ClassifyPrority: %x\n", Adapter->PackInfo[uiLoopIndex].bClassifierPriority);
759 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxLatency: %x\n", Adapter->PackInfo[uiLoopIndex].uiMaxLatency);
Andy Shevchenkobcb6ef62012-08-02 19:05:44 +0300760 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO,
761 DBG_LVL_ALL, "ServiceClassName: %*ph\n",
762 4, Adapter->PackInfo[uiLoopIndex].
763 ucServiceClassName);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400764/* BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bHeaderSuppressionEnabled :%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
765 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalTxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalTxBytes);
766 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalRxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalRxBytes);
767 * DumpDebug(DUMP_INFO,(" uiRanOutOfResCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiRanOutOfResCount));
768 */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700769 }
770
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400771 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
772 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aRxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aRxPktSizeHist[uiLoopIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700773
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400774 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
775 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aTxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aTxPktSizeHist[uiLoopIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700776}
777
Kevin McKinney29794602012-05-26 12:05:12 -0400778int reset_card_proc(struct bcm_mini_adapter *ps_adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700779{
780 int retval = STATUS_SUCCESS;
Kevin McKinney29794602012-05-26 12:05:12 -0400781 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
Kevin McKinneyd6861cf2012-11-01 23:42:21 -0400782 struct bcm_interface_adapter *psIntfAdapter = NULL;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700783 unsigned int value = 0, uiResetValue = 0;
Kevin McKinney41c7b7c2011-11-06 09:40:11 -0500784 int bytes;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700785
Kevin McKinneyd6861cf2012-11-01 23:42:21 -0400786 psIntfAdapter = ((struct bcm_interface_adapter *)(ps_adapter->pvInterfaceAdapter));
Lisa Nguyenf70c8a92013-10-28 01:36:19 -0700787 ps_adapter->bDDRInitDone = false;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700788
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400789 if (ps_adapter->chip_id >= T3LPB) {
790 /* SYS_CFG register is write protected hence for modifying this reg value, it should be read twice before */
791 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
792 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700793
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400794 /* making bit[6...5] same as was before f/w download. this setting force the h/w to */
795 /* re-populated the SP RAM area with the string descriptor. */
796 value = value | (ps_adapter->syscfgBefFwDld & 0x00000060);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700797 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
798 }
799
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400800 /* killing all submitted URBs. */
801 psIntfAdapter->psAdapter->StopAllXaction = TRUE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700802 Bcm_kill_all_URBs(psIntfAdapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700803 /* Reset the UMA-B Device */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400804 if (ps_adapter->chip_id >= T3LPB) {
Masanari Iida73e29182012-04-06 23:33:52 +0900805 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Resetting UMA-B\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700806 retval = usb_reset_device(psIntfAdapter->udev);
Lisa Nguyenf70c8a92013-10-28 01:36:19 -0700807 psIntfAdapter->psAdapter->StopAllXaction = false;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700808
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400809 if (retval != STATUS_SUCCESS) {
810 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700811 goto err_exit;
812 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400813
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700814 if (ps_adapter->chip_id == BCS220_2 ||
815 ps_adapter->chip_id == BCS220_2BC ||
816 ps_adapter->chip_id == BCS250_BC ||
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400817 ps_adapter->chip_id == BCS220_3) {
818
Kevin McKinney41c7b7c2011-11-06 09:40:11 -0500819 bytes = rdmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
820 if (bytes < 0) {
821 retval = bytes;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400822 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700823 goto err_exit;
824 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400825 /* setting 0th bit */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700826 value |= (1<<0);
827 retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400828 if (retval < 0) {
829 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700830 goto err_exit;
831 }
832 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400833 } else {
Kevin McKinney41c7b7c2011-11-06 09:40:11 -0500834 bytes = rdmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
835 if (bytes < 0) {
836 retval = bytes;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400837 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700838 goto err_exit;
839 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400840 value &= (~(1<<16));
841 retval = wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
842 if (retval < 0) {
843 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700844 goto err_exit;
845 }
846
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400847 /* Toggling the GPIO 8, 9 */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700848 value = 0;
849 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400850 if (retval < 0) {
851 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700852 goto err_exit;
853 }
854 value = 0x300;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400855 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value));
856 if (retval < 0) {
857 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700858 goto err_exit;
859 }
860 mdelay(50);
861 }
862
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400863 /* ps_adapter->downloadDDR = false; */
864 if (ps_adapter->bFlashBoot) {
865 /* In flash boot mode MIPS state register has reverse polarity.
866 * So just or with setting bit 30.
867 * Make the MIPS in Reset state.
868 */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700869 rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400870 uiResetValue |= (1<<30);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700871 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
872 }
873
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400874 if (ps_adapter->chip_id >= T3LPB) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700875 uiResetValue = 0;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400876 /*
877 * WA for SYSConfig Issue.
878 * Read SYSCFG Twice to make it writable.
879 */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700880 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400881 if (uiResetValue & (1<<4)) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700882 uiResetValue = 0;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400883 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue)); /* 2nd read to make it writable. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700884 uiResetValue &= (~(1<<4));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400885 wrmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700886 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700887 }
888 uiResetValue = 0;
889 wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
890
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400891err_exit:
Lisa Nguyenf70c8a92013-10-28 01:36:19 -0700892 psIntfAdapter->psAdapter->StopAllXaction = false;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700893 return retval;
894}
895
Kevin McKinney29794602012-05-26 12:05:12 -0400896int run_card_proc(struct bcm_mini_adapter *ps_adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700897{
Kevin McKinney41c7b7c2011-11-06 09:40:11 -0500898 int status = STATUS_SUCCESS;
899 int bytes;
900
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400901 unsigned int value = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700902 {
Kevin McKinney41c7b7c2011-11-06 09:40:11 -0500903 bytes = rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value));
904 if (bytes < 0) {
905 status = bytes;
Kevin McKinneya8a1cdd2011-10-07 18:50:10 -0400906 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 -0500907 return status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700908 }
909
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400910 if (ps_adapter->bFlashBoot)
911 value &= (~(1<<30));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700912 else
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400913 value |= (1<<30);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700914
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400915 if (wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
Kevin McKinneya8a1cdd2011-10-07 18:50:10 -0400916 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 -0700917 return STATUS_FAILURE;
918 }
919 }
Kevin McKinney41c7b7c2011-11-06 09:40:11 -0500920 return status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700921}
922
Kevin McKinney29794602012-05-26 12:05:12 -0400923int InitCardAndDownloadFirmware(struct bcm_mini_adapter *ps_adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700924{
Dan Carpenter2e316132010-11-13 11:24:22 +0300925 int status;
Kevin McKinney9ef07602012-10-18 22:40:12 -0400926 unsigned int value = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700927 /*
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400928 * Create the threads first and then download the
929 * Firm/DDR Settings..
930 */
Stephen Hemminger2d087482010-11-01 12:14:01 -0400931 status = create_worker_threads(ps_adapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400932 if (status < 0)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700933 return status;
Stephen Hemminger2d087482010-11-01 12:14:01 -0400934
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400935 status = bcm_parse_target_params(ps_adapter);
936 if (status)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700937 return status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700938
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400939 if (ps_adapter->chip_id >= T3LPB) {
940 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
941 ps_adapter->syscfgBefFwDld = value;
942
943 if ((value & 0x60) == 0)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700944 ps_adapter->bFlashBoot = TRUE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700945 }
946
947 reset_card_proc(ps_adapter);
948
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400949 /* Initializing the NVM. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700950 BcmInitNVM(ps_adapter);
951 status = ddr_init(ps_adapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400952 if (status) {
Stephen Hemminger2d087482010-11-01 12:14:01 -0400953 pr_err(DRV_NAME "ddr_init Failed\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700954 return status;
955 }
956
957 /* Download cfg file */
958 status = buffDnldVerify(ps_adapter,
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400959 (PUCHAR)ps_adapter->pstargetparams,
Kevin McKinneyc8182332012-12-17 17:35:20 -0500960 sizeof(struct bcm_target_params),
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400961 CONFIG_BEGIN_ADDR);
962 if (status) {
963 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700964 goto OUT;
965 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700966
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400967 if (register_networkdev(ps_adapter)) {
968 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700969 return -EIO;
970 }
971
Lisa Nguyenf70c8a92013-10-28 01:36:19 -0700972 if (false == ps_adapter->AutoFirmDld) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400973 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoFirmDld Disabled in CFG File..\n");
974 /* If Auto f/w download is disable, register the control interface, */
975 /* register the control interface after the mailbox. */
976 if (register_control_device_interface(ps_adapter) < 0) {
977 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700978 return -EIO;
979 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700980 return STATUS_SUCCESS;
981 }
982
983 /*
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400984 * Do the LED Settings here. It will be used by the Firmware Download
985 * Thread.
986 */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700987
988 /*
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400989 * 1. If the LED Settings fails, do not stop and do the Firmware download.
990 * 2. This init would happened only if the cfg file is present, else
991 * call from the ioctl context.
992 */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700993
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400994 status = InitLedSettings(ps_adapter);
995 if (status) {
996 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_PRINTK, 0, 0, "INIT LED FAILED\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700997 return status;
998 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -0400999
1000 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001001 ps_adapter->DriverState = DRIVER_INIT;
1002 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1003 }
1004
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001005 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001006 ps_adapter->DriverState = FW_DOWNLOAD;
1007 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1008 }
1009
1010 value = 0;
1011 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1012 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1013
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001014 if (ps_adapter->eNVMType == NVM_FLASH) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001015 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001016 if (status) {
1017 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 -07001018 goto OUT;
1019 }
1020 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001021
1022 /* Download Firmare */
Kevin McKinneyd4910612011-10-07 18:50:12 -04001023 status = BcmFileDownload(ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR);
1024 if (status != 0) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001025 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 -07001026 goto OUT;
1027 }
1028
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001029 status = run_card_proc(ps_adapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001030 if (status) {
1031 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 -07001032 goto OUT;
1033 }
1034
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001035 ps_adapter->fw_download_done = TRUE;
1036 mdelay(10);
1037
1038OUT:
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001039 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001040 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1041 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1042 }
1043
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001044 return status;
1045}
1046
Kevin McKinney29794602012-05-26 12:05:12 -04001047static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001048{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001049 struct file *flp = NULL;
Jesper Juhl3701bef2010-11-10 21:31:38 +01001050 char *buff;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001051 int len = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001052
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001053 buff = kmalloc(BUFFER_1K, GFP_KERNEL);
1054 if (!buff)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001055 return -ENOMEM;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001056
Kevin McKinneyc8182332012-12-17 17:35:20 -05001057 Adapter->pstargetparams = kmalloc(sizeof(struct bcm_target_params), GFP_KERNEL);
Kevin McKinney9d4f1d02011-10-07 18:50:11 -04001058 if (Adapter->pstargetparams == NULL) {
Stephen Hemminger082e8892010-11-01 09:35:21 -04001059 kfree(buff);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001060 return -ENOMEM;
1061 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001062
1063 flp = open_firmware_file(Adapter, CFG_FILE);
1064 if (!flp) {
1065 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE\n", CFG_FILE);
Stephen Hemminger082e8892010-11-01 09:35:21 -04001066 kfree(buff);
1067 kfree(Adapter->pstargetparams);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001068 Adapter->pstargetparams = NULL;
1069 return -ENOENT;
1070 }
Al Viro32aecdd2012-07-22 21:02:01 +04001071 len = kernel_read(flp, 0, buff, BUFFER_1K);
1072 filp_close(flp, NULL);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001073
Kevin McKinneyc8182332012-12-17 17:35:20 -05001074 if (len != sizeof(struct bcm_target_params)) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001075 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 -04001076 kfree(buff);
1077 kfree(Adapter->pstargetparams);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001078 Adapter->pstargetparams = NULL;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001079 return -ENOENT;
1080 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001081
1082 /* Check for autolink in config params */
1083 /*
1084 * Values in Adapter->pstargetparams are in network byte order
1085 */
Kevin McKinneyc8182332012-12-17 17:35:20 -05001086 memcpy(Adapter->pstargetparams, buff, sizeof(struct bcm_target_params));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001087 kfree(buff);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001088 beceem_parse_target_struct(Adapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001089 return STATUS_SUCCESS;
1090}
1091
Kevin McKinney29794602012-05-26 12:05:12 -04001092void beceem_parse_target_struct(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001093{
Kevin McKinney9ef07602012-10-18 22:40:12 -04001094 unsigned int uiHostDrvrCfg6 = 0, uiEEPROMFlag = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001095
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001096 if (ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE) {
Stephen Hemminger2d087482010-11-01 12:14:01 -04001097 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001098 Adapter->AutoSyncup = false;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001099 } else {
Stephen Hemminger2d087482010-11-01 12:14:01 -04001100 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001101 Adapter->AutoSyncup = TRUE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001102 }
Stephen Hemminger2d087482010-11-01 12:14:01 -04001103
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001104 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE) {
Stephen Hemminger2d087482010-11-01 12:14:01 -04001105 pr_info(DRV_NAME ": Enabling autolink up");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001106 Adapter->AutoLinkUp = TRUE;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001107 } else {
Stephen Hemminger2d087482010-11-01 12:14:01 -04001108 pr_info(DRV_NAME ": Disabling autolink up");
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001109 Adapter->AutoLinkUp = false;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001110 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001111 /* Setting the DDR Setting.. */
1112 Adapter->DDRSetting = (ntohl(Adapter->pstargetparams->HostDrvrConfig6) >> 8)&0x0F;
1113 Adapter->ulPowerSaveMode = (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
Stephen Hemminger2d087482010-11-01 12:14:01 -04001114 pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1115 pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001116 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD) {
1117 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1118 Adapter->AutoFirmDld = TRUE;
1119 } else {
1120 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001121 Adapter->AutoFirmDld = false;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001122 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001123 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1124 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001125 pr_info(DRV_NAME ": MIPSConfig : 0x%X\n", Adapter->bMipsConfig);
1126 /* used for backward compatibility. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001127 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001128 Adapter->PmuMode = (uiHostDrvrCfg6 >> 24) & 0x03;
Stephen Hemminger2d087482010-11-01 12:14:01 -04001129 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001130
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001131 if ((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT) & (0x01)) {
1132 Adapter->bDoSuspend = TRUE;
1133 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1134 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001135
1136 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001137 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n", uiEEPROMFlag);
Kevin McKinneyaf72c612012-12-21 15:10:36 -05001138 Adapter->eNVMType = (enum bcm_nvm_type)((uiEEPROMFlag>>4)&0x3);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001139 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001140 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001141 Adapter->bSectorSizeOverride = (bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001142
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001143 if (ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x01)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001144 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
Stephen Hemminger2d087482010-11-01 12:14:01 -04001145
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001146 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001147 doPowerAutoCorrection(Adapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001148}
1149
Kevin McKinney7a15b792012-10-18 22:40:08 -04001150static void doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001151{
Kevin McKinney9ef07602012-10-18 22:40:12 -04001152 unsigned int reporting_mode;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001153
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001154 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x02;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001155 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1156
Andrey Utkin6b866092014-07-23 13:47:33 +03001157 if (reporting_mode) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001158 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "can't do suspen/resume as reporting mode is enable");
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001159 psAdapter->bDoSuspend = false;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001160 }
1161
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001162 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB)) {
1163 /* If reporting mode is enable, switch PMU to PMC */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001164 {
1165 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001166 psAdapter->bDoSuspend = false;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001167 }
1168
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001169 /* clearing space bit[15..12] */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001170 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl((0xF << 12)));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001171 /* placing the power save mode option */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001172 psAdapter->pstargetparams->HostDrvrConfig6 |= htonl((psAdapter->ulPowerSaveMode << 12));
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001173 } else if (psAdapter->bIsAutoCorrectEnabled == false) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001174 /* remove the autocorrect disable bit set before dumping. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001175 psAdapter->ulPowerSaveMode &= ~(1 << 3);
1176 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl(1 << 15));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001177 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 -07001178 }
1179}
Arnd Bergmann44a17eff2010-09-30 10:24:12 +02001180
Kevin McKinney9ef07602012-10-18 22:40:12 -04001181static void convertEndian(unsigned char rwFlag, unsigned int *puiBuffer, unsigned int uiByteCount)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001182{
Kevin McKinney9ef07602012-10-18 22:40:12 -04001183 unsigned int uiIndex = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001184
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001185 if (RWM_WRITE == rwFlag) {
Kevin McKinney9ef07602012-10-18 22:40:12 -04001186 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(unsigned int)); uiIndex++)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001187 puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001188 } else {
Kevin McKinney9ef07602012-10-18 22:40:12 -04001189 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(unsigned int)); uiIndex++)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001190 puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001191 }
1192}
1193
Kevin McKinney9ef07602012-10-18 22:40:12 -04001194int rdm(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001195{
Greg Dietschec5274ab2011-06-13 13:11:47 -05001196 return Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001197 uiAddress, pucBuff, sSize);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001198}
Greg Dietschec5274ab2011-06-13 13:11:47 -05001199
Kevin McKinney9ef07602012-10-18 22:40:12 -04001200int wrm(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001201{
1202 int iRetVal;
1203
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001204 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001205 uiAddress, pucBuff, sSize);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001206 return iRetVal;
1207}
1208
Kevin McKinney9ef07602012-10-18 22:40:12 -04001209int wrmalt(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001210{
1211 convertEndian(RWM_WRITE, pucBuff, size);
1212 return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1213}
1214
Kevin McKinney9ef07602012-10-18 22:40:12 -04001215int rdmalt(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001216{
Kevin McKinney7af141342012-10-18 22:40:13 -04001217 int uiRetVal = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001218
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001219 uiRetVal = rdm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
Kevin McKinneyb23f7f62012-10-18 22:40:09 -04001220 convertEndian(RWM_READ, (unsigned int *)pucBuff, size);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001221
1222 return uiRetVal;
1223}
1224
Kevin McKinney9ef07602012-10-18 22:40:12 -04001225int wrmWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001226{
Kevin McKinney7af141342012-10-18 22:40:13 -04001227 int status = STATUS_SUCCESS;
Robin Schroerfe830732014-06-16 13:01:46 +02001228
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001229 down(&Adapter->rdmwrmsync);
1230
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001231 if ((Adapter->IdleMode == TRUE) ||
1232 (Adapter->bShutStatus == TRUE) ||
1233 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1234
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001235 status = -EACCES;
1236 goto exit;
1237 }
1238
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001239 status = wrm(Adapter, uiAddress, pucBuff, sSize);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001240exit:
1241 up(&Adapter->rdmwrmsync);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001242 return status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001243}
1244
Kevin McKinney9ef07602012-10-18 22:40:12 -04001245int wrmaltWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001246{
1247 int iRetVal = STATUS_SUCCESS;
1248
1249 down(&Adapter->rdmwrmsync);
1250
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001251 if ((Adapter->IdleMode == TRUE) ||
1252 (Adapter->bShutStatus == TRUE) ||
1253 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1254
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001255 iRetVal = -EACCES;
1256 goto exit;
1257 }
1258
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001259 iRetVal = wrmalt(Adapter, uiAddress, pucBuff, size);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001260exit:
1261 up(&Adapter->rdmwrmsync);
1262 return iRetVal;
1263}
1264
Kevin McKinney9ef07602012-10-18 22:40:12 -04001265int rdmaltWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001266{
Kevin McKinney7af141342012-10-18 22:40:13 -04001267 int uiRetVal = STATUS_SUCCESS;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001268
1269 down(&Adapter->rdmwrmsync);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001270 if ((Adapter->IdleMode == TRUE) ||
1271 (Adapter->bShutStatus == TRUE) ||
1272 (Adapter->bPreparingForLowPowerMode == TRUE)) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001273
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001274 uiRetVal = -EACCES;
1275 goto exit;
1276 }
1277
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001278 uiRetVal = rdmalt(Adapter, uiAddress, pucBuff, size);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001279exit:
1280 up(&Adapter->rdmwrmsync);
1281 return uiRetVal;
1282}
1283
Kevin McKinney7a15b792012-10-18 22:40:08 -04001284static void HandleShutDownModeWakeup(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001285{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001286 int clear_abort_pattern = 0, Status = 0;
Robin Schroerfe830732014-06-16 13:01:46 +02001287
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001288 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1289 /* target has woken up From Shut Down */
1290 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Clearing Shut Down Software abort pattern\n");
Kevin McKinneyb23f7f62012-10-18 22:40:09 -04001291 Status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC, (unsigned int *)&clear_abort_pattern, sizeof(clear_abort_pattern));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001292 if (Status) {
1293 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001294 return;
1295 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001296
1297 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001298 msleep(100);
1299 InterfaceHandleShutdownModeWakeup(Adapter);
1300 msleep(100);
1301 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001302
1303 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001304 Adapter->DriverState = NO_NETWORK_ENTRY;
1305 wake_up(&Adapter->LEDInfo.notify_led_event);
1306 }
1307
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001308 Adapter->bTriedToWakeUpFromlowPowerMode = false;
1309 Adapter->bShutStatus = false;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001310 wake_up(&Adapter->lowpower_mode_wait_queue);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001311 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001312}
1313
Kevin McKinney7a15b792012-10-18 22:40:08 -04001314static void SendShutModeResponse(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001315{
Kevin McKinney2610c7a2012-05-26 12:05:08 -04001316 struct bcm_link_request stShutdownResponse;
Kevin McKinney9ef07602012-10-18 22:40:12 -04001317 unsigned int NVMAccess = 0, lowPwrAbortMsg = 0;
1318 unsigned int Status = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001319
Kevin McKinney2610c7a2012-05-26 12:05:08 -04001320 memset(&stShutdownResponse, 0, sizeof(struct bcm_link_request));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001321 stShutdownResponse.Leader.Status = LINK_UP_CONTROL_REQ;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001322 stShutdownResponse.Leader.PLength = 8; /* 8 bytes; */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001323 stShutdownResponse.szData[0] = LINK_UP_ACK;
1324 stShutdownResponse.szData[1] = LINK_SHUTDOWN_REQ_FROM_FIRMWARE;
1325
1326 /*********************************
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001327 * down_trylock -
1328 * if [ semaphore is available ]
1329 * acquire semaphone and return value 0 ;
1330 * else
1331 * return non-zero value ;
1332 *
1333 ***********************************/
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001334
1335 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001336 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001337
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001338 if (NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) {
1339 if (!NVMAccess)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001340 up(&Adapter->NVMRdmWrmLock);
1341
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001342 if (!lowPwrAbortMsg)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001343 up(&Adapter->LowPowerModeSync);
1344
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001345 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Device Access is going on NACK the Shut Down MODE\n");
1346 stShutdownResponse.szData[2] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001347 Adapter->bPreparingForLowPowerMode = false;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001348 } else {
1349 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Sending SHUTDOWN MODE ACK\n");
1350 stShutdownResponse.szData[2] = SHUTDOWN_ACK_FROM_DRIVER; /* ShutDown ACK */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001351
1352 /* Wait for the LED to TURN OFF before sending ACK response */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001353 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Kevin McKinney7af141342012-10-18 22:40:13 -04001354 int iRetVal = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001355
1356 /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1357 Adapter->DriverState = LOWPOWER_MODE_ENTER;
1358 wake_up(&Adapter->LEDInfo.notify_led_event);
1359
1360 /* Wait for 1 SEC for LED to OFF */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001361 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001362
1363 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001364 if (iRetVal <= 0) {
1365 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001366 Adapter->DriverState = NO_NETWORK_ENTRY;
1367 wake_up(&Adapter->LEDInfo.notify_led_event);
1368 }
1369 }
1370
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001371 if (stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER) {
1372 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ACKING SHUTDOWN MODE !!!!!!!!!");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001373 down(&Adapter->rdmwrmsync);
1374 Adapter->bPreparingForLowPowerMode = TRUE;
1375 up(&Adapter->rdmwrmsync);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001376 /* Killing all URBS. */
1377 if (Adapter->bDoSuspend == TRUE)
Kevin McKinneyd6861cf2012-11-01 23:42:21 -04001378 Bcm_kill_all_URBs((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001379 } else {
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001380 Adapter->bPreparingForLowPowerMode = false;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001381 }
1382
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001383 if (!NVMAccess)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001384 up(&Adapter->NVMRdmWrmLock);
1385
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001386 if (!lowPwrAbortMsg)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001387 up(&Adapter->LowPowerModeSync);
1388 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001389
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001390 Status = CopyBufferToControlPacket(Adapter, &stShutdownResponse);
Robin Schroer28c520a2014-06-16 13:01:47 +02001391 if (Status != STATUS_SUCCESS) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001392 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "fail to send the Idle mode Request\n");
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001393 Adapter->bPreparingForLowPowerMode = false;
Kevin McKinneyd6861cf2012-11-01 23:42:21 -04001394 StartInterruptUrb((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001395 }
1396}
1397
Kevin McKinney29794602012-05-26 12:05:12 -04001398static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001399{
Kevin McKinney70522082012-10-18 22:40:11 -04001400 unsigned int uiResetValue = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001401
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001402 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001403
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001404 if (*(pucBuffer+1) == COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001405 HandleShutDownModeWakeup(Adapter);
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001406 } else if (*(pucBuffer+1) == LINK_SHUTDOWN_REQ_FROM_FIRMWARE) {
1407 /* Target wants to go to Shut Down Mode */
1408 /* InterfacePrepareForShutdown(Adapter); */
1409 if (Adapter->chip_id == BCS220_2 ||
1410 Adapter->chip_id == BCS220_2BC ||
1411 Adapter->chip_id == BCS250_BC ||
1412 Adapter->chip_id == BCS220_3) {
1413
1414 rdmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001415 uiResetValue |= (1<<17);
1416 wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1417 }
1418
1419 SendShutModeResponse(Adapter);
Kevin McKinney7af141342012-10-18 22:40:13 -04001420 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 -07001421 }
1422
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001423 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001424}
1425
Kevin McKinney7a15b792012-10-18 22:40:08 -04001426void ResetCounters(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001427{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001428 beceem_protocol_reset(Adapter);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001429 Adapter->CurrNumRecvDescs = 0;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001430 Adapter->PrevNumRecvDescs = 0;
1431 Adapter->LinkUpStatus = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001432 Adapter->LinkStatus = 0;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001433 atomic_set(&Adapter->cntrlpktCnt, 0);
1434 atomic_set(&Adapter->TotalPacketCount, 0);
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001435 Adapter->fw_download_done = false;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001436 Adapter->LinkStatus = 0;
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001437 Adapter->AutoLinkUp = false;
1438 Adapter->IdleMode = false;
1439 Adapter->bShutStatus = false;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001440}
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001441
Kevin McKinney29794602012-05-26 12:05:12 -04001442struct bcm_classifier_rule *GetFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIP)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001443{
Kevin McKinney9ef07602012-10-18 22:40:12 -04001444 unsigned int uiIndex = 0;
Robin Schroerfe830732014-06-16 13:01:46 +02001445
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001446 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1447 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1448 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1449 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIP) &&
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001450 !Adapter->astFragmentedPktClassifierTable[uiIndex].bOutOfOrderFragment)
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001451
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001452 return Adapter->astFragmentedPktClassifierTable[uiIndex].pstMatchedClassifierEntry;
1453 }
1454 return NULL;
1455}
1456
Kevin McKinney29794602012-05-26 12:05:12 -04001457void AddFragIPClsEntry(struct bcm_mini_adapter *Adapter, struct bcm_fragmented_packet_info *psFragPktInfo)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001458{
Kevin McKinney9ef07602012-10-18 22:40:12 -04001459 unsigned int uiIndex = 0;
Robin Schroerfe830732014-06-16 13:01:46 +02001460
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001461 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1462 if (!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) {
Kevin McKinney7f224852012-05-26 12:05:02 -04001463 memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex], psFragPktInfo, sizeof(struct bcm_fragmented_packet_info));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001464 break;
1465 }
1466 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001467}
1468
Kevin McKinney29794602012-05-26 12:05:12 -04001469void DelFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIp)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001470{
Kevin McKinney9ef07602012-10-18 22:40:12 -04001471 unsigned int uiIndex = 0;
Robin Schroerfe830732014-06-16 13:01:46 +02001472
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001473 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1474 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1475 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1476 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIp))
1477
Kevin McKinney7f224852012-05-26 12:05:02 -04001478 memset(&Adapter->astFragmentedPktClassifierTable[uiIndex], 0, sizeof(struct bcm_fragmented_packet_info));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001479 }
1480}
1481
Kevin McKinney29794602012-05-26 12:05:12 -04001482void update_per_cid_rx(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001483{
Kevin McKinney9ef07602012-10-18 22:40:12 -04001484 unsigned int qindex = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001485
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001486 if ((jiffies - Adapter->liDrainCalculated) < XSECONDS)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001487 return;
1488
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001489 for (qindex = 0; qindex < HiPriority; qindex++) {
1490 if (Adapter->PackInfo[qindex].ucDirection == 0) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001491 Adapter->PackInfo[qindex].uiCurrentRxRate =
1492 (Adapter->PackInfo[qindex].uiCurrentRxRate +
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001493 Adapter->PackInfo[qindex].uiThisPeriodRxBytes) / 2;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001494
1495 Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001496 } else {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001497 Adapter->PackInfo[qindex].uiCurrentDrainRate =
1498 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001499 Adapter->PackInfo[qindex].uiThisPeriodSentBytes) / 2;
1500 Adapter->PackInfo[qindex].uiThisPeriodSentBytes = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001501 }
1502 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001503 Adapter->liDrainCalculated = jiffies;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001504}
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001505
Kevin McKinney29794602012-05-26 12:05:12 -04001506void update_per_sf_desc_cnts(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001507{
Kevin McKinney7af141342012-10-18 22:40:13 -04001508 int iIndex = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001509 u32 uibuff[MAX_TARGET_DSX_BUFFERS];
Kevin McKinney41c7b7c2011-11-06 09:40:11 -05001510 int bytes;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001511
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001512 if (!atomic_read(&Adapter->uiMBupdate))
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001513 return;
1514
Kevin McKinney9ef07602012-10-18 22:40:12 -04001515 bytes = rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (unsigned int *)uibuff, sizeof(unsigned int) * MAX_TARGET_DSX_BUFFERS);
Kevin McKinney41c7b7c2011-11-06 09:40:11 -05001516 if (bytes < 0) {
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001517 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001518 return;
1519 }
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001520
1521 for (iIndex = 0; iIndex < HiPriority; iIndex++) {
1522 if (Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection) {
1523 if (Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001524 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001525 else
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001526 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 -07001527 }
1528 }
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001529 atomic_set(&Adapter->uiMBupdate, false);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001530}
1531
Kevin McKinney9ef07602012-10-18 22:40:12 -04001532void flush_queue(struct bcm_mini_adapter *Adapter, unsigned int iQIndex)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001533{
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001534 struct sk_buff *PacketToDrop = NULL;
1535 struct net_device_stats *netstats = &Adapter->dev->stats;
Robin Schroerfe830732014-06-16 13:01:46 +02001536
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001537 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1538
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001539 while (Adapter->PackInfo[iQIndex].FirstTxQueue && atomic_read(&Adapter->TotalPacketCount)) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001540 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001541 if (PacketToDrop && PacketToDrop->len) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001542 netstats->tx_dropped++;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001543 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, Adapter->PackInfo[iQIndex].LastTxQueue);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001544 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1545 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1546
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001547 /* Adding dropped statistics */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001548 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1549 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
Stephen Hemminger082e8892010-11-01 09:35:21 -04001550 dev_kfree_skb(PacketToDrop);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001551 atomic_dec(&Adapter->TotalPacketCount);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001552 }
1553 }
1554 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001555}
1556
Kevin McKinney29794602012-05-26 12:05:12 -04001557static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001558{
Stephen Hemminger4fd64dd2010-11-01 12:12:31 -04001559 int i;
Robin Schroerfe830732014-06-16 13:01:46 +02001560
Stephen Hemminger4fd64dd2010-11-01 12:12:31 -04001561 if (netif_msg_link(Adapter))
Stephen Hemminger9ec44752010-11-01 12:18:36 -04001562 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
Stephen Hemminger4fd64dd2010-11-01 12:12:31 -04001563
1564 netif_carrier_off(Adapter->dev);
1565 netif_stop_queue(Adapter->dev);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001566
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001567 Adapter->IdleMode = false;
1568 Adapter->LinkUpStatus = false;
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001569 ClearTargetDSXBuffer(Adapter, 0, TRUE);
1570 /* Delete All Classifier Rules */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001571
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001572 for (i = 0; i < HiPriority; i++)
1573 DeleteAllClassifiersForSF(Adapter, i);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001574
1575 flush_all_queues(Adapter);
1576
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001577 if (Adapter->TimerActive == TRUE)
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07001578 Adapter->TimerActive = false;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001579
Kevin McKinney7f224852012-05-26 12:05:02 -04001580 memset(Adapter->astFragmentedPktClassifierTable, 0, sizeof(struct bcm_fragmented_packet_info) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001581
Kevin McKinney6a4ef5f2011-10-07 18:50:09 -04001582 for (i = 0; i < HiPriority; i++) {
1583 /* resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF. */
1584 /* It is same between MIBs and SF. */
Kevin McKinney8c7d51a2012-11-25 19:28:59 -05001585 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable, 0, sizeof(struct bcm_mibs_parameters));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001586 }
1587}