lpfc_hbadisc.c 64 KB

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