lpfc_hbadisc.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2005 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/kthread.h>
  24. #include <linux/interrupt.h>
  25. #include <scsi/scsi_device.h>
  26. #include <scsi/scsi_host.h>
  27. #include <scsi/scsi_transport_fc.h>
  28. #include "lpfc_hw.h"
  29. #include "lpfc_disc.h"
  30. #include "lpfc_sli.h"
  31. #include "lpfc_scsi.h"
  32. #include "lpfc.h"
  33. #include "lpfc_logmsg.h"
  34. #include "lpfc_crtn.h"
  35. /* AlpaArray for assignment of scsid for scan-down and bind_method */
  36. static uint8_t lpfcAlpaArray[] = {
  37. 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
  38. 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
  39. 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
  40. 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
  41. 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
  42. 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
  43. 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
  44. 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
  45. 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
  46. 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
  47. 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
  48. 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
  49. 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
  50. };
  51. static void lpfc_disc_timeout_handler(struct lpfc_hba *);
  52. static void
  53. lpfc_process_nodev_timeout(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  54. {
  55. int warn_on = 0;
  56. spin_lock_irq(phba->host->host_lock);
  57. if (!(ndlp->nlp_flag & NLP_NODEV_TMO)) {
  58. spin_unlock_irq(phba->host->host_lock);
  59. return;
  60. }
  61. ndlp->nlp_flag &= ~NLP_NODEV_TMO;
  62. if (ndlp->nlp_sid != NLP_NO_SID) {
  63. warn_on = 1;
  64. /* flush the target */
  65. lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
  66. ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
  67. }
  68. spin_unlock_irq(phba->host->host_lock);
  69. if (warn_on) {
  70. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  71. "%d:0203 Nodev timeout on NPort x%x "
  72. "Data: x%x x%x x%x\n",
  73. phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
  74. ndlp->nlp_state, ndlp->nlp_rpi);
  75. } else {
  76. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  77. "%d:0204 Nodev timeout on NPort x%x "
  78. "Data: x%x x%x x%x\n",
  79. phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
  80. ndlp->nlp_state, ndlp->nlp_rpi);
  81. }
  82. lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
  83. return;
  84. }
  85. static void
  86. lpfc_work_list_done(struct lpfc_hba * phba)
  87. {
  88. struct lpfc_work_evt *evtp = NULL;
  89. struct lpfc_nodelist *ndlp;
  90. int free_evt;
  91. spin_lock_irq(phba->host->host_lock);
  92. while(!list_empty(&phba->work_list)) {
  93. list_remove_head((&phba->work_list), evtp, typeof(*evtp),
  94. evt_listp);
  95. spin_unlock_irq(phba->host->host_lock);
  96. free_evt = 1;
  97. switch(evtp->evt) {
  98. case LPFC_EVT_NODEV_TMO:
  99. ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
  100. lpfc_process_nodev_timeout(phba, ndlp);
  101. free_evt = 0;
  102. break;
  103. case LPFC_EVT_ELS_RETRY:
  104. ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
  105. lpfc_els_retry_delay_handler(ndlp);
  106. free_evt = 0;
  107. break;
  108. case LPFC_EVT_ONLINE:
  109. *(int *)(evtp->evt_arg1) = lpfc_online(phba);
  110. complete((struct completion *)(evtp->evt_arg2));
  111. break;
  112. case LPFC_EVT_OFFLINE:
  113. *(int *)(evtp->evt_arg1) = lpfc_offline(phba);
  114. complete((struct completion *)(evtp->evt_arg2));
  115. break;
  116. }
  117. if (free_evt)
  118. kfree(evtp);
  119. spin_lock_irq(phba->host->host_lock);
  120. }
  121. spin_unlock_irq(phba->host->host_lock);
  122. }
  123. static void
  124. lpfc_work_done(struct lpfc_hba * phba)
  125. {
  126. struct lpfc_sli_ring *pring;
  127. int i;
  128. uint32_t ha_copy;
  129. uint32_t control;
  130. uint32_t work_hba_events;
  131. spin_lock_irq(phba->host->host_lock);
  132. ha_copy = phba->work_ha;
  133. phba->work_ha = 0;
  134. work_hba_events=phba->work_hba_events;
  135. spin_unlock_irq(phba->host->host_lock);
  136. if(ha_copy & HA_ERATT)
  137. lpfc_handle_eratt(phba);
  138. if(ha_copy & HA_MBATT)
  139. lpfc_sli_handle_mb_event(phba);
  140. if(ha_copy & HA_LATT)
  141. lpfc_handle_latt(phba);
  142. if (work_hba_events & WORKER_DISC_TMO)
  143. lpfc_disc_timeout_handler(phba);
  144. if (work_hba_events & WORKER_ELS_TMO)
  145. lpfc_els_timeout_handler(phba);
  146. if (work_hba_events & WORKER_MBOX_TMO)
  147. lpfc_mbox_timeout_handler(phba);
  148. if (work_hba_events & WORKER_FDMI_TMO)
  149. lpfc_fdmi_tmo_handler(phba);
  150. spin_lock_irq(phba->host->host_lock);
  151. phba->work_hba_events &= ~work_hba_events;
  152. spin_unlock_irq(phba->host->host_lock);
  153. for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
  154. pring = &phba->sli.ring[i];
  155. if ((ha_copy & HA_RXATT)
  156. || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
  157. if (pring->flag & LPFC_STOP_IOCB_MASK) {
  158. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  159. } else {
  160. lpfc_sli_handle_slow_ring_event(phba, pring,
  161. (ha_copy &
  162. HA_RXMASK));
  163. pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
  164. }
  165. /*
  166. * Turn on Ring interrupts
  167. */
  168. spin_lock_irq(phba->host->host_lock);
  169. control = readl(phba->HCregaddr);
  170. control |= (HC_R0INT_ENA << i);
  171. writel(control, phba->HCregaddr);
  172. readl(phba->HCregaddr); /* flush */
  173. spin_unlock_irq(phba->host->host_lock);
  174. }
  175. }
  176. lpfc_work_list_done (phba);
  177. }
  178. static int
  179. check_work_wait_done(struct lpfc_hba *phba) {
  180. spin_lock_irq(phba->host->host_lock);
  181. if (phba->work_ha ||
  182. phba->work_hba_events ||
  183. (!list_empty(&phba->work_list)) ||
  184. kthread_should_stop()) {
  185. spin_unlock_irq(phba->host->host_lock);
  186. return 1;
  187. } else {
  188. spin_unlock_irq(phba->host->host_lock);
  189. return 0;
  190. }
  191. }
  192. int
  193. lpfc_do_work(void *p)
  194. {
  195. struct lpfc_hba *phba = p;
  196. int rc;
  197. DECLARE_WAIT_QUEUE_HEAD(work_waitq);
  198. set_user_nice(current, -20);
  199. phba->work_wait = &work_waitq;
  200. while (1) {
  201. rc = wait_event_interruptible(work_waitq,
  202. check_work_wait_done(phba));
  203. BUG_ON(rc);
  204. if (kthread_should_stop())
  205. break;
  206. lpfc_work_done(phba);
  207. }
  208. phba->work_wait = NULL;
  209. return 0;
  210. }
  211. /*
  212. * This is only called to handle FC worker events. Since this a rare
  213. * occurance, we allocate a struct lpfc_work_evt structure here instead of
  214. * embedding it in the IOCB.
  215. */
  216. int
  217. lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
  218. uint32_t evt)
  219. {
  220. struct lpfc_work_evt *evtp;
  221. /*
  222. * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
  223. * be queued to worker thread for processing
  224. */
  225. evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
  226. if (!evtp)
  227. return 0;
  228. evtp->evt_arg1 = arg1;
  229. evtp->evt_arg2 = arg2;
  230. evtp->evt = evt;
  231. list_add_tail(&evtp->evt_listp, &phba->work_list);
  232. spin_lock_irq(phba->host->host_lock);
  233. if (phba->work_wait)
  234. wake_up(phba->work_wait);
  235. spin_unlock_irq(phba->host->host_lock);
  236. return 1;
  237. }
  238. int
  239. lpfc_linkdown(struct lpfc_hba * phba)
  240. {
  241. struct lpfc_sli *psli;
  242. struct lpfc_nodelist *ndlp, *next_ndlp;
  243. struct list_head *listp;
  244. struct list_head *node_list[7];
  245. LPFC_MBOXQ_t *mb;
  246. int rc, i;
  247. psli = &phba->sli;
  248. spin_lock_irq(phba->host->host_lock);
  249. phba->hba_state = LPFC_LINK_DOWN;
  250. spin_unlock_irq(phba->host->host_lock);
  251. /* Clean up any firmware default rpi's */
  252. if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
  253. lpfc_unreg_did(phba, 0xffffffff, mb);
  254. mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
  255. if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
  256. == MBX_NOT_FINISHED) {
  257. mempool_free( mb, phba->mbox_mem_pool);
  258. }
  259. }
  260. /* Cleanup any outstanding RSCN activity */
  261. lpfc_els_flush_rscn(phba);
  262. /* Cleanup any outstanding ELS commands */
  263. lpfc_els_flush_cmd(phba);
  264. /* Issue a LINK DOWN event to all nodes */
  265. node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
  266. node_list[1] = &phba->fc_nlpmap_list;
  267. node_list[2] = &phba->fc_nlpunmap_list;
  268. node_list[3] = &phba->fc_prli_list;
  269. node_list[4] = &phba->fc_reglogin_list;
  270. node_list[5] = &phba->fc_adisc_list;
  271. node_list[6] = &phba->fc_plogi_list;
  272. for (i = 0; i < 7; i++) {
  273. listp = node_list[i];
  274. if (list_empty(listp))
  275. continue;
  276. list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
  277. /* Fabric nodes are not handled thru state machine for
  278. link down */
  279. if (ndlp->nlp_type & NLP_FABRIC) {
  280. /* Remove ALL Fabric nodes except Fabric_DID */
  281. if (ndlp->nlp_DID != Fabric_DID) {
  282. /* Take it off current list and free */
  283. lpfc_nlp_list(phba, ndlp,
  284. NLP_NO_LIST);
  285. }
  286. }
  287. else {
  288. rc = lpfc_disc_state_machine(phba, ndlp, NULL,
  289. NLP_EVT_DEVICE_RECOVERY);
  290. /* Check config parameter use-adisc or FCP-2 */
  291. if ((rc != NLP_STE_FREED_NODE) &&
  292. (phba->cfg_use_adisc == 0) &&
  293. !(ndlp->nlp_fcp_info &
  294. NLP_FCP_2_DEVICE)) {
  295. /* We know we will have to relogin, so
  296. * unreglogin the rpi right now to fail
  297. * any outstanding I/Os quickly.
  298. */
  299. lpfc_unreg_rpi(phba, ndlp);
  300. }
  301. }
  302. }
  303. }
  304. /* free any ndlp's on unused list */
  305. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
  306. nlp_listp) {
  307. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  308. }
  309. /* Setup myDID for link up if we are in pt2pt mode */
  310. if (phba->fc_flag & FC_PT2PT) {
  311. phba->fc_myDID = 0;
  312. if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
  313. lpfc_config_link(phba, mb);
  314. mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
  315. if (lpfc_sli_issue_mbox
  316. (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
  317. == MBX_NOT_FINISHED) {
  318. mempool_free( mb, phba->mbox_mem_pool);
  319. }
  320. }
  321. spin_lock_irq(phba->host->host_lock);
  322. phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
  323. spin_unlock_irq(phba->host->host_lock);
  324. }
  325. spin_lock_irq(phba->host->host_lock);
  326. phba->fc_flag &= ~FC_LBIT;
  327. spin_unlock_irq(phba->host->host_lock);
  328. /* Turn off discovery timer if its running */
  329. lpfc_can_disctmo(phba);
  330. /* Must process IOCBs on all rings to handle ABORTed I/Os */
  331. return (0);
  332. }
  333. static int
  334. lpfc_linkup(struct lpfc_hba * phba)
  335. {
  336. struct lpfc_nodelist *ndlp, *next_ndlp;
  337. spin_lock_irq(phba->host->host_lock);
  338. phba->hba_state = LPFC_LINK_UP;
  339. phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
  340. FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
  341. phba->fc_flag |= FC_NDISC_ACTIVE;
  342. phba->fc_ns_retry = 0;
  343. spin_unlock_irq(phba->host->host_lock);
  344. /*
  345. * Clean up old Fabric NLP_FABRIC logins.
  346. */
  347. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpunmap_list,
  348. nlp_listp) {
  349. if (ndlp->nlp_DID == Fabric_DID) {
  350. /* Take it off current list and free */
  351. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  352. }
  353. }
  354. /* free any ndlp's on unused list */
  355. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
  356. nlp_listp) {
  357. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  358. }
  359. return 0;
  360. }
  361. /*
  362. * This routine handles processing a CLEAR_LA mailbox
  363. * command upon completion. It is setup in the LPFC_MBOXQ
  364. * as the completion routine when the command is
  365. * handed off to the SLI layer.
  366. */
  367. void
  368. lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  369. {
  370. struct lpfc_sli *psli;
  371. MAILBOX_t *mb;
  372. uint32_t control;
  373. psli = &phba->sli;
  374. mb = &pmb->mb;
  375. /* Since we don't do discovery right now, turn these off here */
  376. psli->ring[psli->ip_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  377. psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  378. psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  379. /* Check for error */
  380. if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
  381. /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
  382. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  383. "%d:0320 CLEAR_LA mbxStatus error x%x hba "
  384. "state x%x\n",
  385. phba->brd_no, mb->mbxStatus, phba->hba_state);
  386. phba->hba_state = LPFC_HBA_ERROR;
  387. goto out;
  388. }
  389. if (phba->fc_flag & FC_ABORT_DISCOVERY)
  390. goto out;
  391. phba->num_disc_nodes = 0;
  392. /* go thru NPR list and issue ELS PLOGIs */
  393. if (phba->fc_npr_cnt) {
  394. lpfc_els_disc_plogi(phba);
  395. }
  396. if(!phba->num_disc_nodes) {
  397. spin_lock_irq(phba->host->host_lock);
  398. phba->fc_flag &= ~FC_NDISC_ACTIVE;
  399. spin_unlock_irq(phba->host->host_lock);
  400. }
  401. phba->hba_state = LPFC_HBA_READY;
  402. out:
  403. /* Device Discovery completes */
  404. lpfc_printf_log(phba,
  405. KERN_INFO,
  406. LOG_DISCOVERY,
  407. "%d:0225 Device Discovery completes\n",
  408. phba->brd_no);
  409. mempool_free( pmb, phba->mbox_mem_pool);
  410. spin_lock_irq(phba->host->host_lock);
  411. phba->fc_flag &= ~FC_ABORT_DISCOVERY;
  412. if (phba->fc_flag & FC_ESTABLISH_LINK) {
  413. phba->fc_flag &= ~FC_ESTABLISH_LINK;
  414. }
  415. spin_unlock_irq(phba->host->host_lock);
  416. del_timer_sync(&phba->fc_estabtmo);
  417. lpfc_can_disctmo(phba);
  418. /* turn on Link Attention interrupts */
  419. spin_lock_irq(phba->host->host_lock);
  420. psli->sli_flag |= LPFC_PROCESS_LA;
  421. control = readl(phba->HCregaddr);
  422. control |= HC_LAINT_ENA;
  423. writel(control, phba->HCregaddr);
  424. readl(phba->HCregaddr); /* flush */
  425. spin_unlock_irq(phba->host->host_lock);
  426. return;
  427. }
  428. static void
  429. lpfc_mbx_cmpl_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  430. {
  431. struct lpfc_sli *psli;
  432. MAILBOX_t *mb;
  433. psli = &phba->sli;
  434. mb = &pmb->mb;
  435. /* Check for error */
  436. if (mb->mbxStatus) {
  437. /* CONFIG_LINK mbox error <mbxStatus> state <hba_state> */
  438. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  439. "%d:0306 CONFIG_LINK mbxStatus error x%x "
  440. "HBA state x%x\n",
  441. phba->brd_no, mb->mbxStatus, phba->hba_state);
  442. lpfc_linkdown(phba);
  443. phba->hba_state = LPFC_HBA_ERROR;
  444. goto out;
  445. }
  446. if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
  447. if (phba->fc_topology == TOPOLOGY_LOOP) {
  448. /* If we are public loop and L bit was set */
  449. if ((phba->fc_flag & FC_PUBLIC_LOOP) &&
  450. !(phba->fc_flag & FC_LBIT)) {
  451. /* Need to wait for FAN - use discovery timer
  452. * for timeout. hba_state is identically
  453. * LPFC_LOCAL_CFG_LINK while waiting for FAN
  454. */
  455. lpfc_set_disctmo(phba);
  456. mempool_free( pmb, phba->mbox_mem_pool);
  457. return;
  458. }
  459. }
  460. /* Start discovery by sending a FLOGI hba_state is identically
  461. * LPFC_FLOGI while waiting for FLOGI cmpl
  462. */
  463. phba->hba_state = LPFC_FLOGI;
  464. lpfc_set_disctmo(phba);
  465. lpfc_initial_flogi(phba);
  466. mempool_free( pmb, phba->mbox_mem_pool);
  467. return;
  468. }
  469. if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
  470. mempool_free( pmb, phba->mbox_mem_pool);
  471. return;
  472. }
  473. out:
  474. /* CONFIG_LINK bad hba state <hba_state> */
  475. lpfc_printf_log(phba,
  476. KERN_ERR,
  477. LOG_DISCOVERY,
  478. "%d:0200 CONFIG_LINK bad hba state x%x\n",
  479. phba->brd_no, phba->hba_state);
  480. if (phba->hba_state != LPFC_CLEAR_LA) {
  481. lpfc_clear_la(phba, pmb);
  482. pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  483. if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
  484. == MBX_NOT_FINISHED) {
  485. mempool_free( pmb, phba->mbox_mem_pool);
  486. lpfc_disc_flush_list(phba);
  487. psli->ring[(psli->ip_ring)].flag &=
  488. ~LPFC_STOP_IOCB_EVENT;
  489. psli->ring[(psli->fcp_ring)].flag &=
  490. ~LPFC_STOP_IOCB_EVENT;
  491. psli->ring[(psli->next_ring)].flag &=
  492. ~LPFC_STOP_IOCB_EVENT;
  493. phba->hba_state = LPFC_HBA_READY;
  494. }
  495. } else {
  496. mempool_free( pmb, phba->mbox_mem_pool);
  497. }
  498. return;
  499. }
  500. static void
  501. lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  502. {
  503. struct lpfc_sli *psli = &phba->sli;
  504. MAILBOX_t *mb = &pmb->mb;
  505. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
  506. /* Check for error */
  507. if (mb->mbxStatus) {
  508. /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
  509. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  510. "%d:0319 READ_SPARAM mbxStatus error x%x "
  511. "hba state x%x>\n",
  512. phba->brd_no, mb->mbxStatus, phba->hba_state);
  513. lpfc_linkdown(phba);
  514. phba->hba_state = LPFC_HBA_ERROR;
  515. goto out;
  516. }
  517. memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
  518. sizeof (struct serv_parm));
  519. memcpy((uint8_t *) & phba->fc_nodename,
  520. (uint8_t *) & phba->fc_sparam.nodeName,
  521. sizeof (struct lpfc_name));
  522. memcpy((uint8_t *) & phba->fc_portname,
  523. (uint8_t *) & phba->fc_sparam.portName,
  524. sizeof (struct lpfc_name));
  525. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  526. kfree(mp);
  527. mempool_free( pmb, phba->mbox_mem_pool);
  528. return;
  529. out:
  530. pmb->context1 = NULL;
  531. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  532. kfree(mp);
  533. if (phba->hba_state != LPFC_CLEAR_LA) {
  534. lpfc_clear_la(phba, pmb);
  535. pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  536. if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
  537. == MBX_NOT_FINISHED) {
  538. mempool_free( pmb, phba->mbox_mem_pool);
  539. lpfc_disc_flush_list(phba);
  540. psli->ring[(psli->ip_ring)].flag &=
  541. ~LPFC_STOP_IOCB_EVENT;
  542. psli->ring[(psli->fcp_ring)].flag &=
  543. ~LPFC_STOP_IOCB_EVENT;
  544. psli->ring[(psli->next_ring)].flag &=
  545. ~LPFC_STOP_IOCB_EVENT;
  546. phba->hba_state = LPFC_HBA_READY;
  547. }
  548. } else {
  549. mempool_free( pmb, phba->mbox_mem_pool);
  550. }
  551. return;
  552. }
  553. static void
  554. lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
  555. {
  556. int i;
  557. LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
  558. sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  559. cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  560. spin_lock_irq(phba->host->host_lock);
  561. switch(la->UlnkSpeed) {
  562. case LA_1GHZ_LINK:
  563. phba->fc_linkspeed = LA_1GHZ_LINK;
  564. break;
  565. case LA_2GHZ_LINK:
  566. phba->fc_linkspeed = LA_2GHZ_LINK;
  567. break;
  568. case LA_4GHZ_LINK:
  569. phba->fc_linkspeed = LA_4GHZ_LINK;
  570. break;
  571. default:
  572. phba->fc_linkspeed = LA_UNKNW_LINK;
  573. break;
  574. }
  575. phba->fc_topology = la->topology;
  576. if (phba->fc_topology == TOPOLOGY_LOOP) {
  577. /* Get Loop Map information */
  578. if (la->il)
  579. phba->fc_flag |= FC_LBIT;
  580. phba->fc_myDID = la->granted_AL_PA;
  581. i = la->un.lilpBde64.tus.f.bdeSize;
  582. if (i == 0) {
  583. phba->alpa_map[0] = 0;
  584. } else {
  585. if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
  586. int numalpa, j, k;
  587. union {
  588. uint8_t pamap[16];
  589. struct {
  590. uint32_t wd1;
  591. uint32_t wd2;
  592. uint32_t wd3;
  593. uint32_t wd4;
  594. } pa;
  595. } un;
  596. numalpa = phba->alpa_map[0];
  597. j = 0;
  598. while (j < numalpa) {
  599. memset(un.pamap, 0, 16);
  600. for (k = 1; j < numalpa; k++) {
  601. un.pamap[k - 1] =
  602. phba->alpa_map[j + 1];
  603. j++;
  604. if (k == 16)
  605. break;
  606. }
  607. /* Link Up Event ALPA map */
  608. lpfc_printf_log(phba,
  609. KERN_WARNING,
  610. LOG_LINK_EVENT,
  611. "%d:1304 Link Up Event "
  612. "ALPA map Data: x%x "
  613. "x%x x%x x%x\n",
  614. phba->brd_no,
  615. un.pa.wd1, un.pa.wd2,
  616. un.pa.wd3, un.pa.wd4);
  617. }
  618. }
  619. }
  620. } else {
  621. phba->fc_myDID = phba->fc_pref_DID;
  622. phba->fc_flag |= FC_LBIT;
  623. }
  624. spin_unlock_irq(phba->host->host_lock);
  625. lpfc_linkup(phba);
  626. if (sparam_mbox) {
  627. lpfc_read_sparam(phba, sparam_mbox);
  628. sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
  629. lpfc_sli_issue_mbox(phba, sparam_mbox,
  630. (MBX_NOWAIT | MBX_STOP_IOCB));
  631. }
  632. if (cfglink_mbox) {
  633. phba->hba_state = LPFC_LOCAL_CFG_LINK;
  634. lpfc_config_link(phba, cfglink_mbox);
  635. cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_config_link;
  636. lpfc_sli_issue_mbox(phba, cfglink_mbox,
  637. (MBX_NOWAIT | MBX_STOP_IOCB));
  638. }
  639. }
  640. static void
  641. lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
  642. uint32_t control;
  643. struct lpfc_sli *psli = &phba->sli;
  644. lpfc_linkdown(phba);
  645. /* turn on Link Attention interrupts - no CLEAR_LA needed */
  646. spin_lock_irq(phba->host->host_lock);
  647. psli->sli_flag |= LPFC_PROCESS_LA;
  648. control = readl(phba->HCregaddr);
  649. control |= HC_LAINT_ENA;
  650. writel(control, phba->HCregaddr);
  651. readl(phba->HCregaddr); /* flush */
  652. spin_unlock_irq(phba->host->host_lock);
  653. }
  654. /*
  655. * This routine handles processing a READ_LA mailbox
  656. * command upon completion. It is setup in the LPFC_MBOXQ
  657. * as the completion routine when the command is
  658. * handed off to the SLI layer.
  659. */
  660. void
  661. lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  662. {
  663. READ_LA_VAR *la;
  664. MAILBOX_t *mb = &pmb->mb;
  665. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  666. /* Check for error */
  667. if (mb->mbxStatus) {
  668. lpfc_printf_log(phba,
  669. KERN_INFO,
  670. LOG_LINK_EVENT,
  671. "%d:1307 READ_LA mbox error x%x state x%x\n",
  672. phba->brd_no,
  673. mb->mbxStatus, phba->hba_state);
  674. lpfc_mbx_issue_link_down(phba);
  675. phba->hba_state = LPFC_HBA_ERROR;
  676. goto lpfc_mbx_cmpl_read_la_free_mbuf;
  677. }
  678. la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
  679. memcpy(&phba->alpa_map[0], mp->virt, 128);
  680. if (((phba->fc_eventTag + 1) < la->eventTag) ||
  681. (phba->fc_eventTag == la->eventTag)) {
  682. phba->fc_stat.LinkMultiEvent++;
  683. if (la->attType == AT_LINK_UP) {
  684. if (phba->fc_eventTag != 0)
  685. lpfc_linkdown(phba);
  686. }
  687. }
  688. phba->fc_eventTag = la->eventTag;
  689. if (la->attType == AT_LINK_UP) {
  690. phba->fc_stat.LinkUp++;
  691. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  692. "%d:1303 Link Up Event x%x received "
  693. "Data: x%x x%x x%x x%x\n",
  694. phba->brd_no, la->eventTag, phba->fc_eventTag,
  695. la->granted_AL_PA, la->UlnkSpeed,
  696. phba->alpa_map[0]);
  697. lpfc_mbx_process_link_up(phba, la);
  698. } else {
  699. phba->fc_stat.LinkDown++;
  700. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  701. "%d:1305 Link Down Event x%x received "
  702. "Data: x%x x%x x%x\n",
  703. phba->brd_no, la->eventTag, phba->fc_eventTag,
  704. phba->hba_state, phba->fc_flag);
  705. lpfc_mbx_issue_link_down(phba);
  706. }
  707. lpfc_mbx_cmpl_read_la_free_mbuf:
  708. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  709. kfree(mp);
  710. mempool_free(pmb, phba->mbox_mem_pool);
  711. return;
  712. }
  713. /*
  714. * This routine handles processing a REG_LOGIN mailbox
  715. * command upon completion. It is setup in the LPFC_MBOXQ
  716. * as the completion routine when the command is
  717. * handed off to the SLI layer.
  718. */
  719. void
  720. lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  721. {
  722. struct lpfc_sli *psli;
  723. MAILBOX_t *mb;
  724. struct lpfc_dmabuf *mp;
  725. struct lpfc_nodelist *ndlp;
  726. psli = &phba->sli;
  727. mb = &pmb->mb;
  728. ndlp = (struct lpfc_nodelist *) pmb->context2;
  729. mp = (struct lpfc_dmabuf *) (pmb->context1);
  730. pmb->context1 = NULL;
  731. /* Good status, call state machine */
  732. lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
  733. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  734. kfree(mp);
  735. mempool_free( pmb, phba->mbox_mem_pool);
  736. return;
  737. }
  738. /*
  739. * This routine handles processing a Fabric REG_LOGIN mailbox
  740. * command upon completion. It is setup in the LPFC_MBOXQ
  741. * as the completion routine when the command is
  742. * handed off to the SLI layer.
  743. */
  744. void
  745. lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  746. {
  747. struct lpfc_sli *psli;
  748. MAILBOX_t *mb;
  749. struct lpfc_dmabuf *mp;
  750. struct lpfc_nodelist *ndlp;
  751. struct lpfc_nodelist *ndlp_fdmi;
  752. psli = &phba->sli;
  753. mb = &pmb->mb;
  754. ndlp = (struct lpfc_nodelist *) pmb->context2;
  755. mp = (struct lpfc_dmabuf *) (pmb->context1);
  756. if (mb->mbxStatus) {
  757. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  758. kfree(mp);
  759. mempool_free( pmb, phba->mbox_mem_pool);
  760. mempool_free( ndlp, phba->nlp_mem_pool);
  761. /* FLOGI failed, so just use loop map to make discovery list */
  762. lpfc_disc_list_loopmap(phba);
  763. /* Start discovery */
  764. lpfc_disc_start(phba);
  765. return;
  766. }
  767. pmb->context1 = NULL;
  768. if (ndlp->nlp_rpi != 0)
  769. lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
  770. ndlp->nlp_rpi = mb->un.varWords[0];
  771. lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
  772. ndlp->nlp_type |= NLP_FABRIC;
  773. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  774. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  775. if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
  776. /* This NPort has been assigned an NPort_ID by the fabric as a
  777. * result of the completed fabric login. Issue a State Change
  778. * Registration (SCR) ELS request to the fabric controller
  779. * (SCR_DID) so that this NPort gets RSCN events from the
  780. * fabric.
  781. */
  782. lpfc_issue_els_scr(phba, SCR_DID, 0);
  783. /* Allocate a new node instance. If the pool is empty, just
  784. * start the discovery process and skip the Nameserver login
  785. * process. This is attempted again later on. Otherwise, issue
  786. * a Port Login (PLOGI) to the NameServer
  787. */
  788. if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL))
  789. == 0) {
  790. lpfc_disc_start(phba);
  791. } else {
  792. lpfc_nlp_init(phba, ndlp, NameServer_DID);
  793. ndlp->nlp_type |= NLP_FABRIC;
  794. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  795. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  796. lpfc_issue_els_plogi(phba, ndlp, 0);
  797. if (phba->cfg_fdmi_on) {
  798. if ((ndlp_fdmi = mempool_alloc(
  799. phba->nlp_mem_pool,
  800. GFP_KERNEL))) {
  801. lpfc_nlp_init(phba, ndlp_fdmi,
  802. FDMI_DID);
  803. ndlp_fdmi->nlp_type |= NLP_FABRIC;
  804. ndlp_fdmi->nlp_state =
  805. NLP_STE_PLOGI_ISSUE;
  806. lpfc_issue_els_plogi(phba, ndlp_fdmi,
  807. 0);
  808. }
  809. }
  810. }
  811. }
  812. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  813. kfree(mp);
  814. mempool_free( pmb, phba->mbox_mem_pool);
  815. return;
  816. }
  817. /*
  818. * This routine handles processing a NameServer REG_LOGIN mailbox
  819. * command upon completion. It is setup in the LPFC_MBOXQ
  820. * as the completion routine when the command is
  821. * handed off to the SLI layer.
  822. */
  823. void
  824. lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  825. {
  826. struct lpfc_sli *psli;
  827. MAILBOX_t *mb;
  828. struct lpfc_dmabuf *mp;
  829. struct lpfc_nodelist *ndlp;
  830. psli = &phba->sli;
  831. mb = &pmb->mb;
  832. ndlp = (struct lpfc_nodelist *) pmb->context2;
  833. mp = (struct lpfc_dmabuf *) (pmb->context1);
  834. if (mb->mbxStatus) {
  835. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  836. kfree(mp);
  837. mempool_free( pmb, phba->mbox_mem_pool);
  838. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  839. /* RegLogin failed, so just use loop map to make discovery
  840. list */
  841. lpfc_disc_list_loopmap(phba);
  842. /* Start discovery */
  843. lpfc_disc_start(phba);
  844. return;
  845. }
  846. pmb->context1 = NULL;
  847. if (ndlp->nlp_rpi != 0)
  848. lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
  849. ndlp->nlp_rpi = mb->un.varWords[0];
  850. lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
  851. ndlp->nlp_type |= NLP_FABRIC;
  852. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  853. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  854. if (phba->hba_state < LPFC_HBA_READY) {
  855. /* Link up discovery requires Fabrib registration. */
  856. lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
  857. lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
  858. lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
  859. }
  860. phba->fc_ns_retry = 0;
  861. /* Good status, issue CT Request to NameServer */
  862. if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
  863. /* Cannot issue NameServer Query, so finish up discovery */
  864. lpfc_disc_start(phba);
  865. }
  866. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  867. kfree(mp);
  868. mempool_free( pmb, phba->mbox_mem_pool);
  869. return;
  870. }
  871. static void
  872. lpfc_register_remote_port(struct lpfc_hba * phba,
  873. struct lpfc_nodelist * ndlp)
  874. {
  875. struct fc_rport *rport;
  876. struct lpfc_rport_data *rdata;
  877. struct fc_rport_identifiers rport_ids;
  878. uint64_t wwn;
  879. /* Remote port has reappeared. Re-register w/ FC transport */
  880. memcpy(&wwn, &ndlp->nlp_nodename, sizeof(uint64_t));
  881. rport_ids.node_name = be64_to_cpu(wwn);
  882. memcpy(&wwn, &ndlp->nlp_portname, sizeof(uint64_t));
  883. rport_ids.port_name = be64_to_cpu(wwn);
  884. rport_ids.port_id = ndlp->nlp_DID;
  885. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  886. if (ndlp->nlp_type & NLP_FCP_TARGET)
  887. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  888. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  889. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  890. ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
  891. if (!rport) {
  892. dev_printk(KERN_WARNING, &phba->pcidev->dev,
  893. "Warning: fc_remote_port_add failed\n");
  894. return;
  895. }
  896. /* initialize static port data */
  897. rport->maxframe_size = ndlp->nlp_maxframe;
  898. rport->supported_classes = ndlp->nlp_class_sup;
  899. if ((rport->scsi_target_id != -1) &&
  900. (rport->scsi_target_id < MAX_FCP_TARGET)) {
  901. ndlp->nlp_sid = rport->scsi_target_id;
  902. }
  903. rdata = rport->dd_data;
  904. rdata->pnode = ndlp;
  905. return;
  906. }
  907. int
  908. lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
  909. {
  910. enum { none, unmapped, mapped } rport_add = none, rport_del = none;
  911. struct lpfc_sli *psli;
  912. psli = &phba->sli;
  913. /* Sanity check to ensure we are not moving to / from the same list */
  914. if ((nlp->nlp_flag & NLP_LIST_MASK) == list) {
  915. if (list != NLP_NO_LIST)
  916. return(0);
  917. }
  918. switch(nlp->nlp_flag & NLP_LIST_MASK) {
  919. case NLP_NO_LIST: /* Not on any list */
  920. break;
  921. case NLP_UNUSED_LIST:
  922. phba->fc_unused_cnt--;
  923. list_del(&nlp->nlp_listp);
  924. break;
  925. case NLP_PLOGI_LIST:
  926. phba->fc_plogi_cnt--;
  927. list_del(&nlp->nlp_listp);
  928. break;
  929. case NLP_ADISC_LIST:
  930. phba->fc_adisc_cnt--;
  931. list_del(&nlp->nlp_listp);
  932. break;
  933. case NLP_REGLOGIN_LIST:
  934. phba->fc_reglogin_cnt--;
  935. list_del(&nlp->nlp_listp);
  936. break;
  937. case NLP_PRLI_LIST:
  938. phba->fc_prli_cnt--;
  939. list_del(&nlp->nlp_listp);
  940. break;
  941. case NLP_UNMAPPED_LIST:
  942. phba->fc_unmap_cnt--;
  943. list_del(&nlp->nlp_listp);
  944. spin_lock_irq(phba->host->host_lock);
  945. nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
  946. nlp->nlp_type &= ~NLP_FC_NODE;
  947. spin_unlock_irq(phba->host->host_lock);
  948. phba->nport_event_cnt++;
  949. if (nlp->rport)
  950. rport_del = unmapped;
  951. break;
  952. case NLP_MAPPED_LIST:
  953. phba->fc_map_cnt--;
  954. list_del(&nlp->nlp_listp);
  955. phba->nport_event_cnt++;
  956. if (nlp->rport)
  957. rport_del = mapped;
  958. break;
  959. case NLP_NPR_LIST:
  960. phba->fc_npr_cnt--;
  961. list_del(&nlp->nlp_listp);
  962. /* Stop delay tmo if taking node off NPR list */
  963. if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
  964. (list != NLP_NPR_LIST)) {
  965. spin_lock_irq(phba->host->host_lock);
  966. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  967. spin_unlock_irq(phba->host->host_lock);
  968. del_timer_sync(&nlp->nlp_delayfunc);
  969. if (!list_empty(&nlp->els_retry_evt.evt_listp))
  970. list_del_init(&nlp->els_retry_evt.evt_listp);
  971. }
  972. break;
  973. }
  974. spin_lock_irq(phba->host->host_lock);
  975. nlp->nlp_flag &= ~NLP_LIST_MASK;
  976. spin_unlock_irq(phba->host->host_lock);
  977. /* Add NPort <did> to <num> list */
  978. lpfc_printf_log(phba,
  979. KERN_INFO,
  980. LOG_NODE,
  981. "%d:0904 Add NPort x%x to %d list Data: x%x\n",
  982. phba->brd_no,
  983. nlp->nlp_DID, list, nlp->nlp_flag);
  984. switch(list) {
  985. case NLP_NO_LIST: /* No list, just remove it */
  986. lpfc_nlp_remove(phba, nlp);
  987. /* as node removed - stop further transport calls */
  988. rport_del = none;
  989. break;
  990. case NLP_UNUSED_LIST:
  991. spin_lock_irq(phba->host->host_lock);
  992. nlp->nlp_flag |= list;
  993. spin_unlock_irq(phba->host->host_lock);
  994. /* Put it at the end of the unused list */
  995. list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
  996. phba->fc_unused_cnt++;
  997. break;
  998. case NLP_PLOGI_LIST:
  999. spin_lock_irq(phba->host->host_lock);
  1000. nlp->nlp_flag |= list;
  1001. spin_unlock_irq(phba->host->host_lock);
  1002. /* Put it at the end of the plogi list */
  1003. list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
  1004. phba->fc_plogi_cnt++;
  1005. break;
  1006. case NLP_ADISC_LIST:
  1007. spin_lock_irq(phba->host->host_lock);
  1008. nlp->nlp_flag |= list;
  1009. spin_unlock_irq(phba->host->host_lock);
  1010. /* Put it at the end of the adisc list */
  1011. list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
  1012. phba->fc_adisc_cnt++;
  1013. break;
  1014. case NLP_REGLOGIN_LIST:
  1015. spin_lock_irq(phba->host->host_lock);
  1016. nlp->nlp_flag |= list;
  1017. spin_unlock_irq(phba->host->host_lock);
  1018. /* Put it at the end of the reglogin list */
  1019. list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
  1020. phba->fc_reglogin_cnt++;
  1021. break;
  1022. case NLP_PRLI_LIST:
  1023. spin_lock_irq(phba->host->host_lock);
  1024. nlp->nlp_flag |= list;
  1025. spin_unlock_irq(phba->host->host_lock);
  1026. /* Put it at the end of the prli list */
  1027. list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
  1028. phba->fc_prli_cnt++;
  1029. break;
  1030. case NLP_UNMAPPED_LIST:
  1031. rport_add = unmapped;
  1032. /* ensure all vestiges of "mapped" significance are gone */
  1033. nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  1034. spin_lock_irq(phba->host->host_lock);
  1035. nlp->nlp_flag |= list;
  1036. spin_unlock_irq(phba->host->host_lock);
  1037. /* Put it at the end of the unmap list */
  1038. list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
  1039. phba->fc_unmap_cnt++;
  1040. phba->nport_event_cnt++;
  1041. /* stop nodev tmo if running */
  1042. if (nlp->nlp_flag & NLP_NODEV_TMO) {
  1043. spin_lock_irq(phba->host->host_lock);
  1044. nlp->nlp_flag &= ~NLP_NODEV_TMO;
  1045. spin_unlock_irq(phba->host->host_lock);
  1046. del_timer_sync(&nlp->nlp_tmofunc);
  1047. if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
  1048. list_del_init(&nlp->nodev_timeout_evt.
  1049. evt_listp);
  1050. }
  1051. nlp->nlp_type |= NLP_FC_NODE;
  1052. break;
  1053. case NLP_MAPPED_LIST:
  1054. rport_add = mapped;
  1055. spin_lock_irq(phba->host->host_lock);
  1056. nlp->nlp_flag |= list;
  1057. spin_unlock_irq(phba->host->host_lock);
  1058. /* Put it at the end of the map list */
  1059. list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
  1060. phba->fc_map_cnt++;
  1061. phba->nport_event_cnt++;
  1062. /* stop nodev tmo if running */
  1063. if (nlp->nlp_flag & NLP_NODEV_TMO) {
  1064. nlp->nlp_flag &= ~NLP_NODEV_TMO;
  1065. del_timer_sync(&nlp->nlp_tmofunc);
  1066. if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
  1067. list_del_init(&nlp->nodev_timeout_evt.
  1068. evt_listp);
  1069. }
  1070. break;
  1071. case NLP_NPR_LIST:
  1072. spin_lock_irq(phba->host->host_lock);
  1073. nlp->nlp_flag |= list;
  1074. spin_unlock_irq(phba->host->host_lock);
  1075. /* Put it at the end of the npr list */
  1076. list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
  1077. phba->fc_npr_cnt++;
  1078. /*
  1079. * Sanity check for Fabric entity.
  1080. * Set nodev_tmo for NPR state, for Fabric use 1 sec.
  1081. */
  1082. if (nlp->nlp_type & NLP_FABRIC) {
  1083. mod_timer(&nlp->nlp_tmofunc, jiffies + HZ);
  1084. }
  1085. else {
  1086. mod_timer(&nlp->nlp_tmofunc,
  1087. jiffies + HZ * phba->cfg_nodev_tmo);
  1088. }
  1089. spin_lock_irq(phba->host->host_lock);
  1090. nlp->nlp_flag |= NLP_NODEV_TMO;
  1091. nlp->nlp_flag &= ~NLP_RCV_PLOGI;
  1092. spin_unlock_irq(phba->host->host_lock);
  1093. break;
  1094. case NLP_JUST_DQ:
  1095. break;
  1096. }
  1097. /*
  1098. * We make all the calls into the transport after we have
  1099. * moved the node between lists. This so that we don't
  1100. * release the lock while in-between lists.
  1101. */
  1102. /* Don't upcall midlayer if we're unloading */
  1103. if (!(phba->fc_flag & FC_UNLOADING)) {
  1104. /*
  1105. * We revalidate the rport pointer as the "add" function
  1106. * may have removed the remote port.
  1107. */
  1108. if ((rport_del != none) && nlp->rport)
  1109. fc_remote_port_block(nlp->rport);
  1110. if (rport_add != none) {
  1111. /*
  1112. * Tell the fc transport about the port, if we haven't
  1113. * already. If we have, and it's a scsi entity, be
  1114. * sure to unblock any attached scsi devices
  1115. */
  1116. if (!nlp->rport)
  1117. lpfc_register_remote_port(phba, nlp);
  1118. else
  1119. fc_remote_port_unblock(nlp->rport);
  1120. /*
  1121. * if we added to Mapped list, but the remote port
  1122. * registration failed or assigned a target id outside
  1123. * our presentable range - move the node to the
  1124. * Unmapped List
  1125. */
  1126. if ((rport_add == mapped) &&
  1127. ((!nlp->rport) ||
  1128. (nlp->rport->scsi_target_id == -1) ||
  1129. (nlp->rport->scsi_target_id >= MAX_FCP_TARGET))) {
  1130. nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  1131. spin_lock_irq(phba->host->host_lock);
  1132. nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
  1133. spin_unlock_irq(phba->host->host_lock);
  1134. lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
  1135. }
  1136. }
  1137. }
  1138. return (0);
  1139. }
  1140. /*
  1141. * Start / ReStart rescue timer for Discovery / RSCN handling
  1142. */
  1143. void
  1144. lpfc_set_disctmo(struct lpfc_hba * phba)
  1145. {
  1146. uint32_t tmo;
  1147. tmo = ((phba->fc_ratov * 2) + 1);
  1148. mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
  1149. spin_lock_irq(phba->host->host_lock);
  1150. phba->fc_flag |= FC_DISC_TMO;
  1151. spin_unlock_irq(phba->host->host_lock);
  1152. /* Start Discovery Timer state <hba_state> */
  1153. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1154. "%d:0247 Start Discovery Timer state x%x "
  1155. "Data: x%x x%lx x%x x%x\n",
  1156. phba->brd_no,
  1157. phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
  1158. phba->fc_plogi_cnt, phba->fc_adisc_cnt);
  1159. return;
  1160. }
  1161. /*
  1162. * Cancel rescue timer for Discovery / RSCN handling
  1163. */
  1164. int
  1165. lpfc_can_disctmo(struct lpfc_hba * phba)
  1166. {
  1167. /* Turn off discovery timer if its running */
  1168. if (phba->fc_flag & FC_DISC_TMO) {
  1169. spin_lock_irq(phba->host->host_lock);
  1170. phba->fc_flag &= ~FC_DISC_TMO;
  1171. spin_unlock_irq(phba->host->host_lock);
  1172. del_timer_sync(&phba->fc_disctmo);
  1173. phba->work_hba_events &= ~WORKER_DISC_TMO;
  1174. }
  1175. /* Cancel Discovery Timer state <hba_state> */
  1176. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1177. "%d:0248 Cancel Discovery Timer state x%x "
  1178. "Data: x%x x%x x%x\n",
  1179. phba->brd_no, phba->hba_state, phba->fc_flag,
  1180. phba->fc_plogi_cnt, phba->fc_adisc_cnt);
  1181. return (0);
  1182. }
  1183. /*
  1184. * Check specified ring for outstanding IOCB on the SLI queue
  1185. * Return true if iocb matches the specified nport
  1186. */
  1187. int
  1188. lpfc_check_sli_ndlp(struct lpfc_hba * phba,
  1189. struct lpfc_sli_ring * pring,
  1190. struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
  1191. {
  1192. struct lpfc_sli *psli;
  1193. IOCB_t *icmd;
  1194. psli = &phba->sli;
  1195. icmd = &iocb->iocb;
  1196. if (pring->ringno == LPFC_ELS_RING) {
  1197. switch (icmd->ulpCommand) {
  1198. case CMD_GEN_REQUEST64_CR:
  1199. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
  1200. return (1);
  1201. case CMD_ELS_REQUEST64_CR:
  1202. case CMD_XMIT_ELS_RSP64_CX:
  1203. if (iocb->context1 == (uint8_t *) ndlp)
  1204. return (1);
  1205. }
  1206. } else if (pring->ringno == psli->ip_ring) {
  1207. } else if (pring->ringno == psli->fcp_ring) {
  1208. /* Skip match check if waiting to relogin to FCP target */
  1209. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  1210. (ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1211. return (0);
  1212. }
  1213. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
  1214. return (1);
  1215. }
  1216. } else if (pring->ringno == psli->next_ring) {
  1217. }
  1218. return (0);
  1219. }
  1220. /*
  1221. * Free resources / clean up outstanding I/Os
  1222. * associated with nlp_rpi in the LPFC_NODELIST entry.
  1223. */
  1224. static int
  1225. lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1226. {
  1227. struct lpfc_sli *psli;
  1228. struct lpfc_sli_ring *pring;
  1229. struct lpfc_iocbq *iocb, *next_iocb;
  1230. IOCB_t *icmd;
  1231. uint32_t rpi, i;
  1232. /*
  1233. * Everything that matches on txcmplq will be returned
  1234. * by firmware with a no rpi error.
  1235. */
  1236. psli = &phba->sli;
  1237. rpi = ndlp->nlp_rpi;
  1238. if (rpi) {
  1239. /* Now process each ring */
  1240. for (i = 0; i < psli->num_rings; i++) {
  1241. pring = &psli->ring[i];
  1242. spin_lock_irq(phba->host->host_lock);
  1243. list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
  1244. list) {
  1245. /*
  1246. * Check to see if iocb matches the nport we are
  1247. * looking for
  1248. */
  1249. if ((lpfc_check_sli_ndlp
  1250. (phba, pring, iocb, ndlp))) {
  1251. /* It matches, so deque and call compl
  1252. with an error */
  1253. list_del(&iocb->list);
  1254. pring->txq_cnt--;
  1255. if (iocb->iocb_cmpl) {
  1256. icmd = &iocb->iocb;
  1257. icmd->ulpStatus =
  1258. IOSTAT_LOCAL_REJECT;
  1259. icmd->un.ulpWord[4] =
  1260. IOERR_SLI_ABORTED;
  1261. spin_unlock_irq(phba->host->
  1262. host_lock);
  1263. (iocb->iocb_cmpl) (phba,
  1264. iocb, iocb);
  1265. spin_lock_irq(phba->host->
  1266. host_lock);
  1267. } else {
  1268. list_add_tail(&iocb->list,
  1269. &phba->lpfc_iocb_list);
  1270. }
  1271. }
  1272. }
  1273. spin_unlock_irq(phba->host->host_lock);
  1274. }
  1275. }
  1276. return (0);
  1277. }
  1278. /*
  1279. * Free rpi associated with LPFC_NODELIST entry.
  1280. * This routine is called from lpfc_freenode(), when we are removing
  1281. * a LPFC_NODELIST entry. It is also called if the driver initiates a
  1282. * LOGO that completes successfully, and we are waiting to PLOGI back
  1283. * to the remote NPort. In addition, it is called after we receive
  1284. * and unsolicated ELS cmd, send back a rsp, the rsp completes and
  1285. * we are waiting to PLOGI back to the remote NPort.
  1286. */
  1287. int
  1288. lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1289. {
  1290. LPFC_MBOXQ_t *mbox;
  1291. int rc;
  1292. if (ndlp->nlp_rpi) {
  1293. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
  1294. lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
  1295. mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
  1296. rc = lpfc_sli_issue_mbox
  1297. (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
  1298. if (rc == MBX_NOT_FINISHED)
  1299. mempool_free( mbox, phba->mbox_mem_pool);
  1300. }
  1301. lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
  1302. lpfc_no_rpi(phba, ndlp);
  1303. ndlp->nlp_rpi = 0;
  1304. return 1;
  1305. }
  1306. return 0;
  1307. }
  1308. /*
  1309. * Free resources associated with LPFC_NODELIST entry
  1310. * so it can be freed.
  1311. */
  1312. static int
  1313. lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1314. {
  1315. LPFC_MBOXQ_t *mb;
  1316. LPFC_MBOXQ_t *nextmb;
  1317. struct lpfc_dmabuf *mp;
  1318. struct fc_rport *rport;
  1319. /* Cleanup node for NPort <nlp_DID> */
  1320. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1321. "%d:0900 Cleanup node for NPort x%x "
  1322. "Data: x%x x%x x%x\n",
  1323. phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
  1324. ndlp->nlp_state, ndlp->nlp_rpi);
  1325. lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
  1326. /*
  1327. * if unloading the driver - just leave the remote port in place.
  1328. * The driver unload will force the attached devices to detach
  1329. * and flush cache's w/o generating flush errors.
  1330. */
  1331. if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
  1332. rport = ndlp->rport;
  1333. ndlp->rport = NULL;
  1334. fc_remote_port_unblock(rport);
  1335. fc_remote_port_delete(rport);
  1336. ndlp->nlp_sid = NLP_NO_SID;
  1337. }
  1338. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  1339. if ((mb = phba->sli.mbox_active)) {
  1340. if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
  1341. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1342. mb->context2 = NULL;
  1343. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1344. }
  1345. }
  1346. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  1347. if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
  1348. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1349. mp = (struct lpfc_dmabuf *) (mb->context1);
  1350. if (mp) {
  1351. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1352. kfree(mp);
  1353. }
  1354. list_del(&mb->list);
  1355. mempool_free(mb, phba->mbox_mem_pool);
  1356. }
  1357. }
  1358. lpfc_els_abort(phba,ndlp,0);
  1359. spin_lock_irq(phba->host->host_lock);
  1360. ndlp->nlp_flag &= ~(NLP_NODEV_TMO|NLP_DELAY_TMO);
  1361. spin_unlock_irq(phba->host->host_lock);
  1362. del_timer_sync(&ndlp->nlp_tmofunc);
  1363. del_timer_sync(&ndlp->nlp_delayfunc);
  1364. if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
  1365. list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
  1366. if (!list_empty(&ndlp->els_retry_evt.evt_listp))
  1367. list_del_init(&ndlp->els_retry_evt.evt_listp);
  1368. lpfc_unreg_rpi(phba, ndlp);
  1369. return (0);
  1370. }
  1371. /*
  1372. * Check to see if we can free the nlp back to the freelist.
  1373. * If we are in the middle of using the nlp in the discovery state
  1374. * machine, defer the free till we reach the end of the state machine.
  1375. */
  1376. int
  1377. lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1378. {
  1379. if (ndlp->nlp_flag & NLP_NODEV_TMO) {
  1380. spin_lock_irq(phba->host->host_lock);
  1381. ndlp->nlp_flag &= ~NLP_NODEV_TMO;
  1382. spin_unlock_irq(phba->host->host_lock);
  1383. del_timer_sync(&ndlp->nlp_tmofunc);
  1384. if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
  1385. list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
  1386. }
  1387. if (ndlp->nlp_flag & NLP_DELAY_TMO) {
  1388. spin_lock_irq(phba->host->host_lock);
  1389. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  1390. spin_unlock_irq(phba->host->host_lock);
  1391. del_timer_sync(&ndlp->nlp_delayfunc);
  1392. if (!list_empty(&ndlp->els_retry_evt.evt_listp))
  1393. list_del_init(&ndlp->els_retry_evt.evt_listp);
  1394. }
  1395. if (ndlp->nlp_disc_refcnt) {
  1396. spin_lock_irq(phba->host->host_lock);
  1397. ndlp->nlp_flag |= NLP_DELAY_REMOVE;
  1398. spin_unlock_irq(phba->host->host_lock);
  1399. }
  1400. else {
  1401. lpfc_freenode(phba, ndlp);
  1402. mempool_free( ndlp, phba->nlp_mem_pool);
  1403. }
  1404. return(0);
  1405. }
  1406. static int
  1407. lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
  1408. {
  1409. D_ID mydid;
  1410. D_ID ndlpdid;
  1411. D_ID matchdid;
  1412. if (did == Bcast_DID)
  1413. return (0);
  1414. if (ndlp->nlp_DID == 0) {
  1415. return (0);
  1416. }
  1417. /* First check for Direct match */
  1418. if (ndlp->nlp_DID == did)
  1419. return (1);
  1420. /* Next check for area/domain identically equals 0 match */
  1421. mydid.un.word = phba->fc_myDID;
  1422. if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
  1423. return (0);
  1424. }
  1425. matchdid.un.word = did;
  1426. ndlpdid.un.word = ndlp->nlp_DID;
  1427. if (matchdid.un.b.id == ndlpdid.un.b.id) {
  1428. if ((mydid.un.b.domain == matchdid.un.b.domain) &&
  1429. (mydid.un.b.area == matchdid.un.b.area)) {
  1430. if ((ndlpdid.un.b.domain == 0) &&
  1431. (ndlpdid.un.b.area == 0)) {
  1432. if (ndlpdid.un.b.id)
  1433. return (1);
  1434. }
  1435. return (0);
  1436. }
  1437. matchdid.un.word = ndlp->nlp_DID;
  1438. if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
  1439. (mydid.un.b.area == ndlpdid.un.b.area)) {
  1440. if ((matchdid.un.b.domain == 0) &&
  1441. (matchdid.un.b.area == 0)) {
  1442. if (matchdid.un.b.id)
  1443. return (1);
  1444. }
  1445. }
  1446. }
  1447. return (0);
  1448. }
  1449. /* Search for a nodelist entry on a specific list */
  1450. struct lpfc_nodelist *
  1451. lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
  1452. {
  1453. struct lpfc_nodelist *ndlp, *next_ndlp;
  1454. uint32_t data1;
  1455. if (order & NLP_SEARCH_UNMAPPED) {
  1456. list_for_each_entry_safe(ndlp, next_ndlp,
  1457. &phba->fc_nlpunmap_list, nlp_listp) {
  1458. if (lpfc_matchdid(phba, ndlp, did)) {
  1459. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1460. ((uint32_t) ndlp->nlp_xri << 16) |
  1461. ((uint32_t) ndlp->nlp_type << 8) |
  1462. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1463. /* FIND node DID unmapped */
  1464. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1465. "%d:0929 FIND node DID unmapped"
  1466. " Data: x%p x%x x%x x%x\n",
  1467. phba->brd_no,
  1468. ndlp, ndlp->nlp_DID,
  1469. ndlp->nlp_flag, data1);
  1470. return (ndlp);
  1471. }
  1472. }
  1473. }
  1474. if (order & NLP_SEARCH_MAPPED) {
  1475. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
  1476. nlp_listp) {
  1477. if (lpfc_matchdid(phba, ndlp, did)) {
  1478. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1479. ((uint32_t) ndlp->nlp_xri << 16) |
  1480. ((uint32_t) ndlp->nlp_type << 8) |
  1481. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1482. /* FIND node DID mapped */
  1483. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1484. "%d:0930 FIND node DID mapped "
  1485. "Data: x%p x%x x%x x%x\n",
  1486. phba->brd_no,
  1487. ndlp, ndlp->nlp_DID,
  1488. ndlp->nlp_flag, data1);
  1489. return (ndlp);
  1490. }
  1491. }
  1492. }
  1493. if (order & NLP_SEARCH_PLOGI) {
  1494. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
  1495. nlp_listp) {
  1496. if (lpfc_matchdid(phba, ndlp, did)) {
  1497. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1498. ((uint32_t) ndlp->nlp_xri << 16) |
  1499. ((uint32_t) ndlp->nlp_type << 8) |
  1500. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1501. /* LOG change to PLOGI */
  1502. /* FIND node DID plogi */
  1503. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1504. "%d:0908 FIND node DID plogi "
  1505. "Data: x%p x%x x%x x%x\n",
  1506. phba->brd_no,
  1507. ndlp, ndlp->nlp_DID,
  1508. ndlp->nlp_flag, data1);
  1509. return (ndlp);
  1510. }
  1511. }
  1512. }
  1513. if (order & NLP_SEARCH_ADISC) {
  1514. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
  1515. nlp_listp) {
  1516. if (lpfc_matchdid(phba, ndlp, did)) {
  1517. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1518. ((uint32_t) ndlp->nlp_xri << 16) |
  1519. ((uint32_t) ndlp->nlp_type << 8) |
  1520. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1521. /* LOG change to ADISC */
  1522. /* FIND node DID adisc */
  1523. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1524. "%d:0931 FIND node DID adisc "
  1525. "Data: x%p x%x x%x x%x\n",
  1526. phba->brd_no,
  1527. ndlp, ndlp->nlp_DID,
  1528. ndlp->nlp_flag, data1);
  1529. return (ndlp);
  1530. }
  1531. }
  1532. }
  1533. if (order & NLP_SEARCH_REGLOGIN) {
  1534. list_for_each_entry_safe(ndlp, next_ndlp,
  1535. &phba->fc_reglogin_list, nlp_listp) {
  1536. if (lpfc_matchdid(phba, ndlp, did)) {
  1537. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1538. ((uint32_t) ndlp->nlp_xri << 16) |
  1539. ((uint32_t) ndlp->nlp_type << 8) |
  1540. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1541. /* LOG change to REGLOGIN */
  1542. /* FIND node DID reglogin */
  1543. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1544. "%d:0931 FIND node DID reglogin"
  1545. " Data: x%p x%x x%x x%x\n",
  1546. phba->brd_no,
  1547. ndlp, ndlp->nlp_DID,
  1548. ndlp->nlp_flag, data1);
  1549. return (ndlp);
  1550. }
  1551. }
  1552. }
  1553. if (order & NLP_SEARCH_PRLI) {
  1554. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
  1555. nlp_listp) {
  1556. if (lpfc_matchdid(phba, ndlp, did)) {
  1557. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1558. ((uint32_t) ndlp->nlp_xri << 16) |
  1559. ((uint32_t) ndlp->nlp_type << 8) |
  1560. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1561. /* LOG change to PRLI */
  1562. /* FIND node DID prli */
  1563. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1564. "%d:0931 FIND node DID prli "
  1565. "Data: x%p x%x x%x x%x\n",
  1566. phba->brd_no,
  1567. ndlp, ndlp->nlp_DID,
  1568. ndlp->nlp_flag, data1);
  1569. return (ndlp);
  1570. }
  1571. }
  1572. }
  1573. if (order & NLP_SEARCH_NPR) {
  1574. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
  1575. nlp_listp) {
  1576. if (lpfc_matchdid(phba, ndlp, did)) {
  1577. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1578. ((uint32_t) ndlp->nlp_xri << 16) |
  1579. ((uint32_t) ndlp->nlp_type << 8) |
  1580. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1581. /* LOG change to NPR */
  1582. /* FIND node DID npr */
  1583. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1584. "%d:0931 FIND node DID npr "
  1585. "Data: x%p x%x x%x x%x\n",
  1586. phba->brd_no,
  1587. ndlp, ndlp->nlp_DID,
  1588. ndlp->nlp_flag, data1);
  1589. return (ndlp);
  1590. }
  1591. }
  1592. }
  1593. if (order & NLP_SEARCH_UNUSED) {
  1594. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
  1595. nlp_listp) {
  1596. if (lpfc_matchdid(phba, ndlp, did)) {
  1597. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1598. ((uint32_t) ndlp->nlp_xri << 16) |
  1599. ((uint32_t) ndlp->nlp_type << 8) |
  1600. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1601. /* LOG change to UNUSED */
  1602. /* FIND node DID unused */
  1603. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1604. "%d:0931 FIND node DID unused "
  1605. "Data: x%p x%x x%x x%x\n",
  1606. phba->brd_no,
  1607. ndlp, ndlp->nlp_DID,
  1608. ndlp->nlp_flag, data1);
  1609. return (ndlp);
  1610. }
  1611. }
  1612. }
  1613. /* FIND node did <did> NOT FOUND */
  1614. lpfc_printf_log(phba,
  1615. KERN_INFO,
  1616. LOG_NODE,
  1617. "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
  1618. phba->brd_no, did, order);
  1619. /* no match found */
  1620. return NULL;
  1621. }
  1622. struct lpfc_nodelist *
  1623. lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
  1624. {
  1625. struct lpfc_nodelist *ndlp;
  1626. uint32_t flg;
  1627. if ((ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did)) == 0) {
  1628. if ((phba->hba_state == LPFC_HBA_READY) &&
  1629. ((lpfc_rscn_payload_check(phba, did) == 0)))
  1630. return NULL;
  1631. ndlp = (struct lpfc_nodelist *)
  1632. mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1633. if (!ndlp)
  1634. return NULL;
  1635. lpfc_nlp_init(phba, ndlp, did);
  1636. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1637. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1638. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1639. return ndlp;
  1640. }
  1641. if ((phba->hba_state == LPFC_HBA_READY) &&
  1642. (phba->fc_flag & FC_RSCN_MODE)) {
  1643. if (lpfc_rscn_payload_check(phba, did)) {
  1644. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1645. }
  1646. else {
  1647. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1648. ndlp = NULL;
  1649. }
  1650. }
  1651. else {
  1652. flg = ndlp->nlp_flag & NLP_LIST_MASK;
  1653. if ((flg == NLP_ADISC_LIST) ||
  1654. (flg == NLP_PLOGI_LIST)) {
  1655. return NULL;
  1656. }
  1657. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1658. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1659. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1660. }
  1661. return ndlp;
  1662. }
  1663. /* Build a list of nodes to discover based on the loopmap */
  1664. void
  1665. lpfc_disc_list_loopmap(struct lpfc_hba * phba)
  1666. {
  1667. int j;
  1668. uint32_t alpa, index;
  1669. if (phba->hba_state <= LPFC_LINK_DOWN) {
  1670. return;
  1671. }
  1672. if (phba->fc_topology != TOPOLOGY_LOOP) {
  1673. return;
  1674. }
  1675. /* Check for loop map present or not */
  1676. if (phba->alpa_map[0]) {
  1677. for (j = 1; j <= phba->alpa_map[0]; j++) {
  1678. alpa = phba->alpa_map[j];
  1679. if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
  1680. continue;
  1681. }
  1682. lpfc_setup_disc_node(phba, alpa);
  1683. }
  1684. } else {
  1685. /* No alpamap, so try all alpa's */
  1686. for (j = 0; j < FC_MAXLOOP; j++) {
  1687. /* If cfg_scan_down is set, start from highest
  1688. * ALPA (0xef) to lowest (0x1).
  1689. */
  1690. if (phba->cfg_scan_down)
  1691. index = j;
  1692. else
  1693. index = FC_MAXLOOP - j - 1;
  1694. alpa = lpfcAlpaArray[index];
  1695. if ((phba->fc_myDID & 0xff) == alpa) {
  1696. continue;
  1697. }
  1698. lpfc_setup_disc_node(phba, alpa);
  1699. }
  1700. }
  1701. return;
  1702. }
  1703. /* Start Link up / RSCN discovery on NPR list */
  1704. void
  1705. lpfc_disc_start(struct lpfc_hba * phba)
  1706. {
  1707. struct lpfc_sli *psli;
  1708. LPFC_MBOXQ_t *mbox;
  1709. struct lpfc_nodelist *ndlp, *next_ndlp;
  1710. uint32_t did_changed, num_sent;
  1711. uint32_t clear_la_pending;
  1712. int rc;
  1713. psli = &phba->sli;
  1714. if (phba->hba_state <= LPFC_LINK_DOWN) {
  1715. return;
  1716. }
  1717. if (phba->hba_state == LPFC_CLEAR_LA)
  1718. clear_la_pending = 1;
  1719. else
  1720. clear_la_pending = 0;
  1721. if (phba->hba_state < LPFC_HBA_READY) {
  1722. phba->hba_state = LPFC_DISC_AUTH;
  1723. }
  1724. lpfc_set_disctmo(phba);
  1725. if (phba->fc_prevDID == phba->fc_myDID) {
  1726. did_changed = 0;
  1727. } else {
  1728. did_changed = 1;
  1729. }
  1730. phba->fc_prevDID = phba->fc_myDID;
  1731. phba->num_disc_nodes = 0;
  1732. /* Start Discovery state <hba_state> */
  1733. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1734. "%d:0202 Start Discovery hba state x%x "
  1735. "Data: x%x x%x x%x\n",
  1736. phba->brd_no, phba->hba_state, phba->fc_flag,
  1737. phba->fc_plogi_cnt, phba->fc_adisc_cnt);
  1738. /* If our did changed, we MUST do PLOGI */
  1739. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
  1740. nlp_listp) {
  1741. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1742. if (did_changed) {
  1743. spin_lock_irq(phba->host->host_lock);
  1744. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1745. spin_unlock_irq(phba->host->host_lock);
  1746. }
  1747. }
  1748. }
  1749. /* First do ADISCs - if any */
  1750. num_sent = lpfc_els_disc_adisc(phba);
  1751. if (num_sent)
  1752. return;
  1753. if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
  1754. /* If we get here, there is nothing to ADISC */
  1755. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
  1756. phba->hba_state = LPFC_CLEAR_LA;
  1757. lpfc_clear_la(phba, mbox);
  1758. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  1759. rc = lpfc_sli_issue_mbox(phba, mbox,
  1760. (MBX_NOWAIT | MBX_STOP_IOCB));
  1761. if (rc == MBX_NOT_FINISHED) {
  1762. mempool_free( mbox, phba->mbox_mem_pool);
  1763. lpfc_disc_flush_list(phba);
  1764. psli->ring[(psli->ip_ring)].flag &=
  1765. ~LPFC_STOP_IOCB_EVENT;
  1766. psli->ring[(psli->fcp_ring)].flag &=
  1767. ~LPFC_STOP_IOCB_EVENT;
  1768. psli->ring[(psli->next_ring)].flag &=
  1769. ~LPFC_STOP_IOCB_EVENT;
  1770. phba->hba_state = LPFC_HBA_READY;
  1771. }
  1772. }
  1773. } else {
  1774. /* Next do PLOGIs - if any */
  1775. num_sent = lpfc_els_disc_plogi(phba);
  1776. if (num_sent)
  1777. return;
  1778. if (phba->fc_flag & FC_RSCN_MODE) {
  1779. /* Check to see if more RSCNs came in while we
  1780. * were processing this one.
  1781. */
  1782. if ((phba->fc_rscn_id_cnt == 0) &&
  1783. (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
  1784. spin_lock_irq(phba->host->host_lock);
  1785. phba->fc_flag &= ~FC_RSCN_MODE;
  1786. spin_unlock_irq(phba->host->host_lock);
  1787. }
  1788. else
  1789. lpfc_els_handle_rscn(phba);
  1790. }
  1791. }
  1792. return;
  1793. }
  1794. /*
  1795. * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
  1796. * ring the match the sppecified nodelist.
  1797. */
  1798. static void
  1799. lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1800. {
  1801. struct lpfc_sli *psli;
  1802. IOCB_t *icmd;
  1803. struct lpfc_iocbq *iocb, *next_iocb;
  1804. struct lpfc_sli_ring *pring;
  1805. struct lpfc_dmabuf *mp;
  1806. psli = &phba->sli;
  1807. pring = &psli->ring[LPFC_ELS_RING];
  1808. /* Error matching iocb on txq or txcmplq
  1809. * First check the txq.
  1810. */
  1811. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  1812. if (iocb->context1 != ndlp) {
  1813. continue;
  1814. }
  1815. icmd = &iocb->iocb;
  1816. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  1817. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  1818. list_del(&iocb->list);
  1819. pring->txq_cnt--;
  1820. lpfc_els_free_iocb(phba, iocb);
  1821. }
  1822. }
  1823. /* Next check the txcmplq */
  1824. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  1825. if (iocb->context1 != ndlp) {
  1826. continue;
  1827. }
  1828. icmd = &iocb->iocb;
  1829. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  1830. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  1831. iocb->iocb_cmpl = NULL;
  1832. /* context2 = cmd, context2->next = rsp, context3 =
  1833. bpl */
  1834. if (iocb->context2) {
  1835. /* Free the response IOCB before handling the
  1836. command. */
  1837. mp = (struct lpfc_dmabuf *) (iocb->context2);
  1838. mp = list_get_first(&mp->list,
  1839. struct lpfc_dmabuf,
  1840. list);
  1841. if (mp) {
  1842. /* Delay before releasing rsp buffer to
  1843. * give UNREG mbox a chance to take
  1844. * effect.
  1845. */
  1846. list_add(&mp->list,
  1847. &phba->freebufList);
  1848. }
  1849. lpfc_mbuf_free(phba,
  1850. ((struct lpfc_dmabuf *)
  1851. iocb->context2)->virt,
  1852. ((struct lpfc_dmabuf *)
  1853. iocb->context2)->phys);
  1854. kfree(iocb->context2);
  1855. }
  1856. if (iocb->context3) {
  1857. lpfc_mbuf_free(phba,
  1858. ((struct lpfc_dmabuf *)
  1859. iocb->context3)->virt,
  1860. ((struct lpfc_dmabuf *)
  1861. iocb->context3)->phys);
  1862. kfree(iocb->context3);
  1863. }
  1864. }
  1865. }
  1866. return;
  1867. }
  1868. void
  1869. lpfc_disc_flush_list(struct lpfc_hba * phba)
  1870. {
  1871. struct lpfc_nodelist *ndlp, *next_ndlp;
  1872. if (phba->fc_plogi_cnt) {
  1873. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
  1874. nlp_listp) {
  1875. lpfc_free_tx(phba, ndlp);
  1876. lpfc_nlp_remove(phba, ndlp);
  1877. }
  1878. }
  1879. if (phba->fc_adisc_cnt) {
  1880. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
  1881. nlp_listp) {
  1882. lpfc_free_tx(phba, ndlp);
  1883. lpfc_nlp_remove(phba, ndlp);
  1884. }
  1885. }
  1886. return;
  1887. }
  1888. /*****************************************************************************/
  1889. /*
  1890. * NAME: lpfc_disc_timeout
  1891. *
  1892. * FUNCTION: Fibre Channel driver discovery timeout routine.
  1893. *
  1894. * EXECUTION ENVIRONMENT: interrupt only
  1895. *
  1896. * CALLED FROM:
  1897. * Timer function
  1898. *
  1899. * RETURNS:
  1900. * none
  1901. */
  1902. /*****************************************************************************/
  1903. void
  1904. lpfc_disc_timeout(unsigned long ptr)
  1905. {
  1906. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  1907. unsigned long flags = 0;
  1908. if (unlikely(!phba))
  1909. return;
  1910. spin_lock_irqsave(phba->host->host_lock, flags);
  1911. if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
  1912. phba->work_hba_events |= WORKER_DISC_TMO;
  1913. if (phba->work_wait)
  1914. wake_up(phba->work_wait);
  1915. }
  1916. spin_unlock_irqrestore(phba->host->host_lock, flags);
  1917. return;
  1918. }
  1919. static void
  1920. lpfc_disc_timeout_handler(struct lpfc_hba *phba)
  1921. {
  1922. struct lpfc_sli *psli;
  1923. struct lpfc_nodelist *ndlp;
  1924. LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
  1925. int rc, clrlaerr = 0;
  1926. if (unlikely(!phba))
  1927. return;
  1928. if (!(phba->fc_flag & FC_DISC_TMO))
  1929. return;
  1930. psli = &phba->sli;
  1931. spin_lock_irq(phba->host->host_lock);
  1932. phba->fc_flag &= ~FC_DISC_TMO;
  1933. spin_unlock_irq(phba->host->host_lock);
  1934. switch (phba->hba_state) {
  1935. case LPFC_LOCAL_CFG_LINK:
  1936. /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
  1937. /* FAN timeout */
  1938. lpfc_printf_log(phba,
  1939. KERN_WARNING,
  1940. LOG_DISCOVERY,
  1941. "%d:0221 FAN timeout\n",
  1942. phba->brd_no);
  1943. /* Forget about FAN, Start discovery by sending a FLOGI
  1944. * hba_state is identically LPFC_FLOGI while waiting for FLOGI
  1945. * cmpl
  1946. */
  1947. phba->hba_state = LPFC_FLOGI;
  1948. lpfc_set_disctmo(phba);
  1949. lpfc_initial_flogi(phba);
  1950. break;
  1951. case LPFC_FLOGI:
  1952. /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
  1953. /* Initial FLOGI timeout */
  1954. lpfc_printf_log(phba,
  1955. KERN_ERR,
  1956. LOG_DISCOVERY,
  1957. "%d:0222 Initial FLOGI timeout\n",
  1958. phba->brd_no);
  1959. /* Assume no Fabric and go on with discovery.
  1960. * Check for outstanding ELS FLOGI to abort.
  1961. */
  1962. /* FLOGI failed, so just use loop map to make discovery list */
  1963. lpfc_disc_list_loopmap(phba);
  1964. /* Start discovery */
  1965. lpfc_disc_start(phba);
  1966. break;
  1967. case LPFC_FABRIC_CFG_LINK:
  1968. /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
  1969. NameServer login */
  1970. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  1971. "%d:0223 Timeout while waiting for NameServer "
  1972. "login\n", phba->brd_no);
  1973. /* Next look for NameServer ndlp */
  1974. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
  1975. if (ndlp)
  1976. lpfc_nlp_remove(phba, ndlp);
  1977. /* Start discovery */
  1978. lpfc_disc_start(phba);
  1979. break;
  1980. case LPFC_NS_QRY:
  1981. /* Check for wait for NameServer Rsp timeout */
  1982. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  1983. "%d:0224 NameServer Query timeout "
  1984. "Data: x%x x%x\n",
  1985. phba->brd_no,
  1986. phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
  1987. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
  1988. NameServer_DID);
  1989. if (ndlp) {
  1990. if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  1991. /* Try it one more time */
  1992. rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
  1993. if (rc == 0)
  1994. break;
  1995. }
  1996. phba->fc_ns_retry = 0;
  1997. }
  1998. /* Nothing to authenticate, so CLEAR_LA right now */
  1999. clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2000. if (!clearlambox) {
  2001. clrlaerr = 1;
  2002. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2003. "%d:0226 Device Discovery "
  2004. "completion error\n",
  2005. phba->brd_no);
  2006. phba->hba_state = LPFC_HBA_ERROR;
  2007. break;
  2008. }
  2009. phba->hba_state = LPFC_CLEAR_LA;
  2010. lpfc_clear_la(phba, clearlambox);
  2011. clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  2012. rc = lpfc_sli_issue_mbox(phba, clearlambox,
  2013. (MBX_NOWAIT | MBX_STOP_IOCB));
  2014. if (rc == MBX_NOT_FINISHED) {
  2015. mempool_free(clearlambox, phba->mbox_mem_pool);
  2016. clrlaerr = 1;
  2017. break;
  2018. }
  2019. /* Setup and issue mailbox INITIALIZE LINK command */
  2020. initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2021. if (!initlinkmbox) {
  2022. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2023. "%d:0226 Device Discovery "
  2024. "completion error\n",
  2025. phba->brd_no);
  2026. phba->hba_state = LPFC_HBA_ERROR;
  2027. break;
  2028. }
  2029. lpfc_linkdown(phba);
  2030. lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
  2031. phba->cfg_link_speed);
  2032. initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
  2033. rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
  2034. (MBX_NOWAIT | MBX_STOP_IOCB));
  2035. if (rc == MBX_NOT_FINISHED)
  2036. mempool_free(initlinkmbox, phba->mbox_mem_pool);
  2037. break;
  2038. case LPFC_DISC_AUTH:
  2039. /* Node Authentication timeout */
  2040. lpfc_printf_log(phba,
  2041. KERN_ERR,
  2042. LOG_DISCOVERY,
  2043. "%d:0227 Node Authentication timeout\n",
  2044. phba->brd_no);
  2045. lpfc_disc_flush_list(phba);
  2046. clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2047. if (!clearlambox) {
  2048. clrlaerr = 1;
  2049. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2050. "%d:0226 Device Discovery "
  2051. "completion error\n",
  2052. phba->brd_no);
  2053. phba->hba_state = LPFC_HBA_ERROR;
  2054. break;
  2055. }
  2056. phba->hba_state = LPFC_CLEAR_LA;
  2057. lpfc_clear_la(phba, clearlambox);
  2058. clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  2059. rc = lpfc_sli_issue_mbox(phba, clearlambox,
  2060. (MBX_NOWAIT | MBX_STOP_IOCB));
  2061. if (rc == MBX_NOT_FINISHED) {
  2062. mempool_free(clearlambox, phba->mbox_mem_pool);
  2063. clrlaerr = 1;
  2064. }
  2065. break;
  2066. case LPFC_CLEAR_LA:
  2067. /* CLEAR LA timeout */
  2068. lpfc_printf_log(phba,
  2069. KERN_ERR,
  2070. LOG_DISCOVERY,
  2071. "%d:0228 CLEAR LA timeout\n",
  2072. phba->brd_no);
  2073. clrlaerr = 1;
  2074. break;
  2075. case LPFC_HBA_READY:
  2076. if (phba->fc_flag & FC_RSCN_MODE) {
  2077. lpfc_printf_log(phba,
  2078. KERN_ERR,
  2079. LOG_DISCOVERY,
  2080. "%d:0231 RSCN timeout Data: x%x x%x\n",
  2081. phba->brd_no,
  2082. phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
  2083. /* Cleanup any outstanding ELS commands */
  2084. lpfc_els_flush_cmd(phba);
  2085. lpfc_els_flush_rscn(phba);
  2086. lpfc_disc_flush_list(phba);
  2087. }
  2088. break;
  2089. }
  2090. if (clrlaerr) {
  2091. lpfc_disc_flush_list(phba);
  2092. psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2093. psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2094. psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2095. phba->hba_state = LPFC_HBA_READY;
  2096. }
  2097. return;
  2098. }
  2099. static void
  2100. lpfc_nodev_timeout(unsigned long ptr)
  2101. {
  2102. struct lpfc_hba *phba;
  2103. struct lpfc_nodelist *ndlp;
  2104. unsigned long iflag;
  2105. struct lpfc_work_evt *evtp;
  2106. ndlp = (struct lpfc_nodelist *)ptr;
  2107. phba = ndlp->nlp_phba;
  2108. evtp = &ndlp->nodev_timeout_evt;
  2109. spin_lock_irqsave(phba->host->host_lock, iflag);
  2110. if (!list_empty(&evtp->evt_listp)) {
  2111. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  2112. return;
  2113. }
  2114. evtp->evt_arg1 = ndlp;
  2115. evtp->evt = LPFC_EVT_NODEV_TMO;
  2116. list_add_tail(&evtp->evt_listp, &phba->work_list);
  2117. if (phba->work_wait)
  2118. wake_up(phba->work_wait);
  2119. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  2120. return;
  2121. }
  2122. /*
  2123. * This routine handles processing a NameServer REG_LOGIN mailbox
  2124. * command upon completion. It is setup in the LPFC_MBOXQ
  2125. * as the completion routine when the command is
  2126. * handed off to the SLI layer.
  2127. */
  2128. void
  2129. lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  2130. {
  2131. struct lpfc_sli *psli;
  2132. MAILBOX_t *mb;
  2133. struct lpfc_dmabuf *mp;
  2134. struct lpfc_nodelist *ndlp;
  2135. psli = &phba->sli;
  2136. mb = &pmb->mb;
  2137. ndlp = (struct lpfc_nodelist *) pmb->context2;
  2138. mp = (struct lpfc_dmabuf *) (pmb->context1);
  2139. pmb->context1 = NULL;
  2140. if (ndlp->nlp_rpi != 0)
  2141. lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
  2142. ndlp->nlp_rpi = mb->un.varWords[0];
  2143. lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
  2144. ndlp->nlp_type |= NLP_FABRIC;
  2145. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  2146. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  2147. /* Start issuing Fabric-Device Management Interface (FDMI)
  2148. * command to 0xfffffa (FDMI well known port)
  2149. */
  2150. if (phba->cfg_fdmi_on == 1) {
  2151. lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
  2152. } else {
  2153. /*
  2154. * Delay issuing FDMI command if fdmi-on=2
  2155. * (supporting RPA/hostnmae)
  2156. */
  2157. mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
  2158. }
  2159. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2160. kfree(mp);
  2161. mempool_free( pmb, phba->mbox_mem_pool);
  2162. return;
  2163. }
  2164. /*
  2165. * This routine looks up the ndlp hash
  2166. * table for the given RPI. If rpi found
  2167. * it return the node list pointer
  2168. * else return 0.
  2169. */
  2170. struct lpfc_nodelist *
  2171. lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
  2172. {
  2173. struct lpfc_nodelist *ret;
  2174. ret = phba->fc_nlplookup[LPFC_RPI_HASH_FUNC(rpi)];
  2175. while ((ret != 0) && (ret->nlp_rpi != rpi)) {
  2176. ret = ret->nlp_rpi_hash_next;
  2177. }
  2178. return ret;
  2179. }
  2180. /*
  2181. * This routine looks up the ndlp hash table for the
  2182. * given RPI. If rpi found it return the node list
  2183. * pointer else return 0 after deleting the entry
  2184. * from hash table.
  2185. */
  2186. struct lpfc_nodelist *
  2187. lpfc_findnode_remove_rpi(struct lpfc_hba * phba, uint16_t rpi)
  2188. {
  2189. struct lpfc_nodelist *ret, *temp;;
  2190. ret = phba->fc_nlplookup[LPFC_RPI_HASH_FUNC(rpi)];
  2191. if (ret == 0)
  2192. return NULL;
  2193. if (ret->nlp_rpi == rpi) {
  2194. phba->fc_nlplookup[LPFC_RPI_HASH_FUNC(rpi)] =
  2195. ret->nlp_rpi_hash_next;
  2196. ret->nlp_rpi_hash_next = NULL;
  2197. return ret;
  2198. }
  2199. while ((ret->nlp_rpi_hash_next != 0) &&
  2200. (ret->nlp_rpi_hash_next->nlp_rpi != rpi)) {
  2201. ret = ret->nlp_rpi_hash_next;
  2202. }
  2203. if (ret->nlp_rpi_hash_next != 0) {
  2204. temp = ret->nlp_rpi_hash_next;
  2205. ret->nlp_rpi_hash_next = temp->nlp_rpi_hash_next;
  2206. temp->nlp_rpi_hash_next = NULL;
  2207. return temp;
  2208. } else {
  2209. return NULL;
  2210. }
  2211. }
  2212. /*
  2213. * This routine adds the node list entry to the
  2214. * ndlp hash table.
  2215. */
  2216. void
  2217. lpfc_addnode_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  2218. uint16_t rpi)
  2219. {
  2220. uint32_t index;
  2221. index = LPFC_RPI_HASH_FUNC(rpi);
  2222. ndlp->nlp_rpi_hash_next = phba->fc_nlplookup[index];
  2223. phba->fc_nlplookup[index] = ndlp;
  2224. return;
  2225. }
  2226. void
  2227. lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  2228. uint32_t did)
  2229. {
  2230. memset(ndlp, 0, sizeof (struct lpfc_nodelist));
  2231. INIT_LIST_HEAD(&ndlp->nodev_timeout_evt.evt_listp);
  2232. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  2233. init_timer(&ndlp->nlp_tmofunc);
  2234. ndlp->nlp_tmofunc.function = lpfc_nodev_timeout;
  2235. ndlp->nlp_tmofunc.data = (unsigned long)ndlp;
  2236. init_timer(&ndlp->nlp_delayfunc);
  2237. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  2238. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  2239. ndlp->nlp_DID = did;
  2240. ndlp->nlp_phba = phba;
  2241. ndlp->nlp_sid = NLP_NO_SID;
  2242. return;
  2243. }