Misc.c 62 KB

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