lpfc_hbadisc.c 67 KB

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