Misc.c 65 KB

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