lpfc_hbadisc.c 63 KB

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