lpfc_hbadisc.c 62 KB

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