lpfc_hbadisc.c 62 KB

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