lpfc_hbadisc.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388
  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. 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. default:
  623. phba->fc_linkspeed = LA_UNKNW_LINK;
  624. break;
  625. }
  626. phba->fc_topology = la->topology;
  627. if (phba->fc_topology == TOPOLOGY_LOOP) {
  628. /* Get Loop Map information */
  629. if (la->il)
  630. phba->fc_flag |= FC_LBIT;
  631. phba->fc_myDID = la->granted_AL_PA;
  632. i = la->un.lilpBde64.tus.f.bdeSize;
  633. if (i == 0) {
  634. phba->alpa_map[0] = 0;
  635. } else {
  636. if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
  637. int numalpa, j, k;
  638. union {
  639. uint8_t pamap[16];
  640. struct {
  641. uint32_t wd1;
  642. uint32_t wd2;
  643. uint32_t wd3;
  644. uint32_t wd4;
  645. } pa;
  646. } un;
  647. numalpa = phba->alpa_map[0];
  648. j = 0;
  649. while (j < numalpa) {
  650. memset(un.pamap, 0, 16);
  651. for (k = 1; j < numalpa; k++) {
  652. un.pamap[k - 1] =
  653. phba->alpa_map[j + 1];
  654. j++;
  655. if (k == 16)
  656. break;
  657. }
  658. /* Link Up Event ALPA map */
  659. lpfc_printf_log(phba,
  660. KERN_WARNING,
  661. LOG_LINK_EVENT,
  662. "%d:1304 Link Up Event "
  663. "ALPA map Data: x%x "
  664. "x%x x%x x%x\n",
  665. phba->brd_no,
  666. un.pa.wd1, un.pa.wd2,
  667. un.pa.wd3, un.pa.wd4);
  668. }
  669. }
  670. }
  671. } else {
  672. phba->fc_myDID = phba->fc_pref_DID;
  673. phba->fc_flag |= FC_LBIT;
  674. }
  675. spin_unlock_irq(phba->host->host_lock);
  676. lpfc_linkup(phba);
  677. if (sparam_mbox) {
  678. lpfc_read_sparam(phba, sparam_mbox);
  679. sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
  680. rc = lpfc_sli_issue_mbox(phba, sparam_mbox,
  681. (MBX_NOWAIT | MBX_STOP_IOCB));
  682. if (rc == MBX_NOT_FINISHED) {
  683. mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
  684. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  685. kfree(mp);
  686. mempool_free(sparam_mbox, phba->mbox_mem_pool);
  687. if (cfglink_mbox)
  688. mempool_free(cfglink_mbox, phba->mbox_mem_pool);
  689. return;
  690. }
  691. }
  692. if (cfglink_mbox) {
  693. phba->hba_state = LPFC_LOCAL_CFG_LINK;
  694. lpfc_config_link(phba, cfglink_mbox);
  695. cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
  696. rc = lpfc_sli_issue_mbox(phba, cfglink_mbox,
  697. (MBX_NOWAIT | MBX_STOP_IOCB));
  698. if (rc == MBX_NOT_FINISHED)
  699. mempool_free(cfglink_mbox, phba->mbox_mem_pool);
  700. }
  701. }
  702. static void
  703. lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
  704. uint32_t control;
  705. struct lpfc_sli *psli = &phba->sli;
  706. lpfc_linkdown(phba);
  707. /* turn on Link Attention interrupts - no CLEAR_LA needed */
  708. spin_lock_irq(phba->host->host_lock);
  709. psli->sli_flag |= LPFC_PROCESS_LA;
  710. control = readl(phba->HCregaddr);
  711. control |= HC_LAINT_ENA;
  712. writel(control, phba->HCregaddr);
  713. readl(phba->HCregaddr); /* flush */
  714. spin_unlock_irq(phba->host->host_lock);
  715. }
  716. /*
  717. * This routine handles processing a READ_LA mailbox
  718. * command upon completion. It is setup in the LPFC_MBOXQ
  719. * as the completion routine when the command is
  720. * handed off to the SLI layer.
  721. */
  722. void
  723. lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  724. {
  725. READ_LA_VAR *la;
  726. MAILBOX_t *mb = &pmb->mb;
  727. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  728. /* Check for error */
  729. if (mb->mbxStatus) {
  730. lpfc_printf_log(phba,
  731. KERN_INFO,
  732. LOG_LINK_EVENT,
  733. "%d:1307 READ_LA mbox error x%x state x%x\n",
  734. phba->brd_no,
  735. mb->mbxStatus, phba->hba_state);
  736. lpfc_mbx_issue_link_down(phba);
  737. phba->hba_state = LPFC_HBA_ERROR;
  738. goto lpfc_mbx_cmpl_read_la_free_mbuf;
  739. }
  740. la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
  741. memcpy(&phba->alpa_map[0], mp->virt, 128);
  742. spin_lock_irq(phba->host->host_lock);
  743. if (la->pb)
  744. phba->fc_flag |= FC_BYPASSED_MODE;
  745. else
  746. phba->fc_flag &= ~FC_BYPASSED_MODE;
  747. spin_unlock_irq(phba->host->host_lock);
  748. if (((phba->fc_eventTag + 1) < la->eventTag) ||
  749. (phba->fc_eventTag == la->eventTag)) {
  750. phba->fc_stat.LinkMultiEvent++;
  751. if (la->attType == AT_LINK_UP) {
  752. if (phba->fc_eventTag != 0)
  753. lpfc_linkdown(phba);
  754. }
  755. }
  756. phba->fc_eventTag = la->eventTag;
  757. if (la->attType == AT_LINK_UP) {
  758. phba->fc_stat.LinkUp++;
  759. if (phba->fc_flag & FC_LOOPBACK_MODE) {
  760. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  761. "%d:1306 Link Up Event in loop back mode "
  762. "x%x received Data: x%x x%x x%x x%x\n",
  763. phba->brd_no, la->eventTag, phba->fc_eventTag,
  764. la->granted_AL_PA, la->UlnkSpeed,
  765. phba->alpa_map[0]);
  766. } else {
  767. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  768. "%d:1303 Link Up Event x%x received "
  769. "Data: x%x x%x x%x x%x\n",
  770. phba->brd_no, la->eventTag, phba->fc_eventTag,
  771. la->granted_AL_PA, la->UlnkSpeed,
  772. phba->alpa_map[0]);
  773. }
  774. lpfc_mbx_process_link_up(phba, la);
  775. } else {
  776. phba->fc_stat.LinkDown++;
  777. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  778. "%d:1305 Link Down Event x%x received "
  779. "Data: x%x x%x x%x\n",
  780. phba->brd_no, la->eventTag, phba->fc_eventTag,
  781. phba->hba_state, phba->fc_flag);
  782. lpfc_mbx_issue_link_down(phba);
  783. }
  784. lpfc_mbx_cmpl_read_la_free_mbuf:
  785. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  786. kfree(mp);
  787. mempool_free(pmb, phba->mbox_mem_pool);
  788. return;
  789. }
  790. /*
  791. * This routine handles processing a REG_LOGIN mailbox
  792. * command upon completion. It is setup in the LPFC_MBOXQ
  793. * as the completion routine when the command is
  794. * handed off to the SLI layer.
  795. */
  796. void
  797. lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  798. {
  799. struct lpfc_sli *psli;
  800. MAILBOX_t *mb;
  801. struct lpfc_dmabuf *mp;
  802. struct lpfc_nodelist *ndlp;
  803. psli = &phba->sli;
  804. mb = &pmb->mb;
  805. ndlp = (struct lpfc_nodelist *) pmb->context2;
  806. mp = (struct lpfc_dmabuf *) (pmb->context1);
  807. pmb->context1 = NULL;
  808. /* Good status, call state machine */
  809. lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
  810. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  811. kfree(mp);
  812. mempool_free( pmb, phba->mbox_mem_pool);
  813. lpfc_nlp_put(ndlp);
  814. return;
  815. }
  816. /*
  817. * This routine handles processing a Fabric REG_LOGIN mailbox
  818. * command upon completion. It is setup in the LPFC_MBOXQ
  819. * as the completion routine when the command is
  820. * handed off to the SLI layer.
  821. */
  822. void
  823. lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  824. {
  825. struct lpfc_sli *psli;
  826. MAILBOX_t *mb;
  827. struct lpfc_dmabuf *mp;
  828. struct lpfc_nodelist *ndlp;
  829. struct lpfc_nodelist *ndlp_fdmi;
  830. psli = &phba->sli;
  831. mb = &pmb->mb;
  832. ndlp = (struct lpfc_nodelist *) pmb->context2;
  833. mp = (struct lpfc_dmabuf *) (pmb->context1);
  834. pmb->context1 = NULL;
  835. pmb->context2 = NULL;
  836. if (mb->mbxStatus) {
  837. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  838. kfree(mp);
  839. mempool_free(pmb, phba->mbox_mem_pool);
  840. lpfc_nlp_put(ndlp);
  841. /* FLOGI failed, so just use loop map to make discovery list */
  842. lpfc_disc_list_loopmap(phba);
  843. /* Start discovery */
  844. lpfc_disc_start(phba);
  845. return;
  846. }
  847. ndlp->nlp_rpi = mb->un.varWords[0];
  848. ndlp->nlp_type |= NLP_FABRIC;
  849. lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
  850. lpfc_nlp_put(ndlp); /* Drop the reference from the mbox */
  851. if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
  852. /* This NPort has been assigned an NPort_ID by the fabric as a
  853. * result of the completed fabric login. Issue a State Change
  854. * Registration (SCR) ELS request to the fabric controller
  855. * (SCR_DID) so that this NPort gets RSCN events from the
  856. * fabric.
  857. */
  858. lpfc_issue_els_scr(phba, SCR_DID, 0);
  859. ndlp = lpfc_findnode_did(phba, NameServer_DID);
  860. if (!ndlp) {
  861. /* Allocate a new node instance. If the pool is empty,
  862. * start the discovery process and skip the Nameserver
  863. * login process. This is attempted again later on.
  864. * Otherwise, issue a Port Login (PLOGI) to NameServer.
  865. */
  866. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
  867. if (!ndlp) {
  868. lpfc_disc_start(phba);
  869. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  870. kfree(mp);
  871. mempool_free(pmb, phba->mbox_mem_pool);
  872. return;
  873. } else {
  874. lpfc_nlp_init(phba, ndlp, NameServer_DID);
  875. ndlp->nlp_type |= NLP_FABRIC;
  876. }
  877. }
  878. lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
  879. lpfc_issue_els_plogi(phba, NameServer_DID, 0);
  880. if (phba->cfg_fdmi_on) {
  881. ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
  882. GFP_KERNEL);
  883. if (ndlp_fdmi) {
  884. lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
  885. ndlp_fdmi->nlp_type |= NLP_FABRIC;
  886. ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
  887. lpfc_issue_els_plogi(phba, FDMI_DID, 0);
  888. }
  889. }
  890. }
  891. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  892. kfree(mp);
  893. mempool_free(pmb, phba->mbox_mem_pool);
  894. return;
  895. }
  896. /*
  897. * This routine handles processing a NameServer REG_LOGIN mailbox
  898. * command upon completion. It is setup in the LPFC_MBOXQ
  899. * as the completion routine when the command is
  900. * handed off to the SLI layer.
  901. */
  902. void
  903. lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  904. {
  905. struct lpfc_sli *psli;
  906. MAILBOX_t *mb;
  907. struct lpfc_dmabuf *mp;
  908. struct lpfc_nodelist *ndlp;
  909. psli = &phba->sli;
  910. mb = &pmb->mb;
  911. ndlp = (struct lpfc_nodelist *) pmb->context2;
  912. mp = (struct lpfc_dmabuf *) (pmb->context1);
  913. if (mb->mbxStatus) {
  914. lpfc_nlp_put(ndlp);
  915. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  916. kfree(mp);
  917. mempool_free(pmb, phba->mbox_mem_pool);
  918. lpfc_drop_node(phba, ndlp);
  919. /* RegLogin failed, so just use loop map to make discovery
  920. list */
  921. lpfc_disc_list_loopmap(phba);
  922. /* Start discovery */
  923. lpfc_disc_start(phba);
  924. return;
  925. }
  926. pmb->context1 = NULL;
  927. ndlp->nlp_rpi = mb->un.varWords[0];
  928. ndlp->nlp_type |= NLP_FABRIC;
  929. lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
  930. if (phba->hba_state < LPFC_HBA_READY) {
  931. /* Link up discovery requires Fabrib registration. */
  932. lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
  933. lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
  934. lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
  935. lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFF_ID);
  936. }
  937. phba->fc_ns_retry = 0;
  938. /* Good status, issue CT Request to NameServer */
  939. if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
  940. /* Cannot issue NameServer Query, so finish up discovery */
  941. lpfc_disc_start(phba);
  942. }
  943. lpfc_nlp_put(ndlp);
  944. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  945. kfree(mp);
  946. mempool_free( pmb, phba->mbox_mem_pool);
  947. return;
  948. }
  949. static void
  950. lpfc_register_remote_port(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  951. {
  952. struct fc_rport *rport;
  953. struct lpfc_rport_data *rdata;
  954. struct fc_rport_identifiers rport_ids;
  955. /* Remote port has reappeared. Re-register w/ FC transport */
  956. rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  957. rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  958. rport_ids.port_id = ndlp->nlp_DID;
  959. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  960. /*
  961. * We leave our node pointer in rport->dd_data when we unregister a
  962. * FCP target port. But fc_remote_port_add zeros the space to which
  963. * rport->dd_data points. So, if we're reusing a previously
  964. * registered port, drop the reference that we took the last time we
  965. * registered the port.
  966. */
  967. if (ndlp->rport && ndlp->rport->dd_data &&
  968. *(struct lpfc_rport_data **) ndlp->rport->dd_data) {
  969. lpfc_nlp_put(ndlp);
  970. }
  971. ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
  972. if (!rport || !get_device(&rport->dev)) {
  973. dev_printk(KERN_WARNING, &phba->pcidev->dev,
  974. "Warning: fc_remote_port_add failed\n");
  975. return;
  976. }
  977. /* initialize static port data */
  978. rport->maxframe_size = ndlp->nlp_maxframe;
  979. rport->supported_classes = ndlp->nlp_class_sup;
  980. rdata = rport->dd_data;
  981. rdata->pnode = lpfc_nlp_get(ndlp);
  982. if (ndlp->nlp_type & NLP_FCP_TARGET)
  983. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  984. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  985. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  986. if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
  987. fc_remote_port_rolechg(rport, rport_ids.roles);
  988. if ((rport->scsi_target_id != -1) &&
  989. (rport->scsi_target_id < LPFC_MAX_TARGET)) {
  990. ndlp->nlp_sid = rport->scsi_target_id;
  991. }
  992. return;
  993. }
  994. static void
  995. lpfc_unregister_remote_port(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  996. {
  997. struct fc_rport *rport = ndlp->rport;
  998. struct lpfc_rport_data *rdata = rport->dd_data;
  999. if (rport->scsi_target_id == -1) {
  1000. ndlp->rport = NULL;
  1001. rdata->pnode = NULL;
  1002. lpfc_nlp_put(ndlp);
  1003. put_device(&rport->dev);
  1004. }
  1005. fc_remote_port_delete(rport);
  1006. return;
  1007. }
  1008. static void
  1009. lpfc_nlp_counters(struct lpfc_hba *phba, int state, int count)
  1010. {
  1011. spin_lock_irq(phba->host->host_lock);
  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. spin_unlock_irq(phba->host->host_lock);
  1039. }
  1040. static void
  1041. lpfc_nlp_state_cleanup(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  1042. int old_state, int new_state)
  1043. {
  1044. if (new_state == NLP_STE_UNMAPPED_NODE) {
  1045. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  1046. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  1047. ndlp->nlp_type |= NLP_FC_NODE;
  1048. }
  1049. if (new_state == NLP_STE_MAPPED_NODE)
  1050. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  1051. if (new_state == NLP_STE_NPR_NODE)
  1052. ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
  1053. /* Transport interface */
  1054. if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
  1055. old_state == NLP_STE_UNMAPPED_NODE)) {
  1056. phba->nport_event_cnt++;
  1057. lpfc_unregister_remote_port(phba, ndlp);
  1058. }
  1059. if (new_state == NLP_STE_MAPPED_NODE ||
  1060. new_state == NLP_STE_UNMAPPED_NODE) {
  1061. phba->nport_event_cnt++;
  1062. /*
  1063. * Tell the fc transport about the port, if we haven't
  1064. * already. If we have, and it's a scsi entity, be
  1065. * sure to unblock any attached scsi devices
  1066. */
  1067. lpfc_register_remote_port(phba, ndlp);
  1068. }
  1069. /*
  1070. * if we added to Mapped list, but the remote port
  1071. * registration failed or assigned a target id outside
  1072. * our presentable range - move the node to the
  1073. * Unmapped List
  1074. */
  1075. if (new_state == NLP_STE_MAPPED_NODE &&
  1076. (!ndlp->rport ||
  1077. ndlp->rport->scsi_target_id == -1 ||
  1078. ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
  1079. spin_lock_irq(phba->host->host_lock);
  1080. ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
  1081. spin_unlock_irq(phba->host->host_lock);
  1082. lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
  1083. }
  1084. }
  1085. static char *
  1086. lpfc_nlp_state_name(char *buffer, size_t size, int state)
  1087. {
  1088. static char *states[] = {
  1089. [NLP_STE_UNUSED_NODE] = "UNUSED",
  1090. [NLP_STE_PLOGI_ISSUE] = "PLOGI",
  1091. [NLP_STE_ADISC_ISSUE] = "ADISC",
  1092. [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
  1093. [NLP_STE_PRLI_ISSUE] = "PRLI",
  1094. [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
  1095. [NLP_STE_MAPPED_NODE] = "MAPPED",
  1096. [NLP_STE_NPR_NODE] = "NPR",
  1097. };
  1098. if (state < ARRAY_SIZE(states) && states[state])
  1099. strlcpy(buffer, states[state], size);
  1100. else
  1101. snprintf(buffer, size, "unknown (%d)", state);
  1102. return buffer;
  1103. }
  1104. void
  1105. lpfc_nlp_set_state(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int state)
  1106. {
  1107. int old_state = ndlp->nlp_state;
  1108. char name1[16], name2[16];
  1109. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1110. "%d:0904 NPort state transition x%06x, %s -> %s\n",
  1111. phba->brd_no,
  1112. ndlp->nlp_DID,
  1113. lpfc_nlp_state_name(name1, sizeof(name1), old_state),
  1114. lpfc_nlp_state_name(name2, sizeof(name2), state));
  1115. if (old_state == NLP_STE_NPR_NODE &&
  1116. (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
  1117. state != NLP_STE_NPR_NODE)
  1118. lpfc_cancel_retry_delay_tmo(phba, ndlp);
  1119. if (old_state == NLP_STE_UNMAPPED_NODE) {
  1120. ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
  1121. ndlp->nlp_type &= ~NLP_FC_NODE;
  1122. }
  1123. if (list_empty(&ndlp->nlp_listp)) {
  1124. spin_lock_irq(phba->host->host_lock);
  1125. list_add_tail(&ndlp->nlp_listp, &phba->fc_nodes);
  1126. spin_unlock_irq(phba->host->host_lock);
  1127. } else if (old_state)
  1128. lpfc_nlp_counters(phba, old_state, -1);
  1129. ndlp->nlp_state = state;
  1130. lpfc_nlp_counters(phba, state, 1);
  1131. lpfc_nlp_state_cleanup(phba, ndlp, old_state, state);
  1132. }
  1133. void
  1134. lpfc_dequeue_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  1135. {
  1136. if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
  1137. lpfc_cancel_retry_delay_tmo(phba, ndlp);
  1138. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  1139. lpfc_nlp_counters(phba, ndlp->nlp_state, -1);
  1140. spin_lock_irq(phba->host->host_lock);
  1141. list_del_init(&ndlp->nlp_listp);
  1142. spin_unlock_irq(phba->host->host_lock);
  1143. lpfc_nlp_state_cleanup(phba, ndlp, ndlp->nlp_state, 0);
  1144. }
  1145. void
  1146. lpfc_drop_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  1147. {
  1148. if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
  1149. lpfc_cancel_retry_delay_tmo(phba, ndlp);
  1150. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  1151. lpfc_nlp_counters(phba, ndlp->nlp_state, -1);
  1152. spin_lock_irq(phba->host->host_lock);
  1153. list_del_init(&ndlp->nlp_listp);
  1154. spin_unlock_irq(phba->host->host_lock);
  1155. lpfc_nlp_put(ndlp);
  1156. }
  1157. /*
  1158. * Start / ReStart rescue timer for Discovery / RSCN handling
  1159. */
  1160. void
  1161. lpfc_set_disctmo(struct lpfc_hba * phba)
  1162. {
  1163. uint32_t tmo;
  1164. if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
  1165. /* For FAN, timeout should be greater then edtov */
  1166. tmo = (((phba->fc_edtov + 999) / 1000) + 1);
  1167. } else {
  1168. /* Normal discovery timeout should be > then ELS/CT timeout
  1169. * FC spec states we need 3 * ratov for CT requests
  1170. */
  1171. tmo = ((phba->fc_ratov * 3) + 3);
  1172. }
  1173. mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
  1174. spin_lock_irq(phba->host->host_lock);
  1175. phba->fc_flag |= FC_DISC_TMO;
  1176. spin_unlock_irq(phba->host->host_lock);
  1177. /* Start Discovery Timer state <hba_state> */
  1178. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1179. "%d:0247 Start Discovery Timer state x%x "
  1180. "Data: x%x x%lx x%x x%x\n",
  1181. phba->brd_no,
  1182. phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
  1183. phba->fc_plogi_cnt, phba->fc_adisc_cnt);
  1184. return;
  1185. }
  1186. /*
  1187. * Cancel rescue timer for Discovery / RSCN handling
  1188. */
  1189. int
  1190. lpfc_can_disctmo(struct lpfc_hba * phba)
  1191. {
  1192. /* Turn off discovery timer if its running */
  1193. if (phba->fc_flag & FC_DISC_TMO) {
  1194. spin_lock_irq(phba->host->host_lock);
  1195. phba->fc_flag &= ~FC_DISC_TMO;
  1196. spin_unlock_irq(phba->host->host_lock);
  1197. del_timer_sync(&phba->fc_disctmo);
  1198. phba->work_hba_events &= ~WORKER_DISC_TMO;
  1199. }
  1200. /* Cancel Discovery Timer state <hba_state> */
  1201. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1202. "%d:0248 Cancel Discovery Timer state x%x "
  1203. "Data: x%x x%x x%x\n",
  1204. phba->brd_no, phba->hba_state, phba->fc_flag,
  1205. phba->fc_plogi_cnt, phba->fc_adisc_cnt);
  1206. return 0;
  1207. }
  1208. /*
  1209. * Check specified ring for outstanding IOCB on the SLI queue
  1210. * Return true if iocb matches the specified nport
  1211. */
  1212. int
  1213. lpfc_check_sli_ndlp(struct lpfc_hba * phba,
  1214. struct lpfc_sli_ring * pring,
  1215. struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
  1216. {
  1217. struct lpfc_sli *psli;
  1218. IOCB_t *icmd;
  1219. psli = &phba->sli;
  1220. icmd = &iocb->iocb;
  1221. if (pring->ringno == LPFC_ELS_RING) {
  1222. switch (icmd->ulpCommand) {
  1223. case CMD_GEN_REQUEST64_CR:
  1224. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
  1225. return 1;
  1226. case CMD_ELS_REQUEST64_CR:
  1227. if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
  1228. return 1;
  1229. case CMD_XMIT_ELS_RSP64_CX:
  1230. if (iocb->context1 == (uint8_t *) ndlp)
  1231. return 1;
  1232. }
  1233. } else if (pring->ringno == psli->extra_ring) {
  1234. } else if (pring->ringno == psli->fcp_ring) {
  1235. /* Skip match check if waiting to relogin to FCP target */
  1236. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  1237. (ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1238. return 0;
  1239. }
  1240. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
  1241. return 1;
  1242. }
  1243. } else if (pring->ringno == psli->next_ring) {
  1244. }
  1245. return 0;
  1246. }
  1247. /*
  1248. * Free resources / clean up outstanding I/Os
  1249. * associated with nlp_rpi in the LPFC_NODELIST entry.
  1250. */
  1251. static int
  1252. lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1253. {
  1254. LIST_HEAD(completions);
  1255. struct lpfc_sli *psli;
  1256. struct lpfc_sli_ring *pring;
  1257. struct lpfc_iocbq *iocb, *next_iocb;
  1258. IOCB_t *icmd;
  1259. uint32_t rpi, i;
  1260. /*
  1261. * Everything that matches on txcmplq will be returned
  1262. * by firmware with a no rpi error.
  1263. */
  1264. psli = &phba->sli;
  1265. rpi = ndlp->nlp_rpi;
  1266. if (rpi) {
  1267. /* Now process each ring */
  1268. for (i = 0; i < psli->num_rings; i++) {
  1269. pring = &psli->ring[i];
  1270. spin_lock_irq(phba->host->host_lock);
  1271. list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
  1272. list) {
  1273. /*
  1274. * Check to see if iocb matches the nport we are
  1275. * looking for
  1276. */
  1277. if ((lpfc_check_sli_ndlp
  1278. (phba, pring, iocb, ndlp))) {
  1279. /* It matches, so deque and call compl
  1280. with an error */
  1281. list_move_tail(&iocb->list,
  1282. &completions);
  1283. pring->txq_cnt--;
  1284. }
  1285. }
  1286. spin_unlock_irq(phba->host->host_lock);
  1287. }
  1288. }
  1289. while (!list_empty(&completions)) {
  1290. iocb = list_get_first(&completions, struct lpfc_iocbq, list);
  1291. list_del(&iocb->list);
  1292. if (iocb->iocb_cmpl) {
  1293. icmd = &iocb->iocb;
  1294. icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  1295. icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  1296. (iocb->iocb_cmpl) (phba, iocb, iocb);
  1297. } else
  1298. lpfc_sli_release_iocbq(phba, iocb);
  1299. }
  1300. return 0;
  1301. }
  1302. /*
  1303. * Free rpi associated with LPFC_NODELIST entry.
  1304. * This routine is called from lpfc_freenode(), when we are removing
  1305. * a LPFC_NODELIST entry. It is also called if the driver initiates a
  1306. * LOGO that completes successfully, and we are waiting to PLOGI back
  1307. * to the remote NPort. In addition, it is called after we receive
  1308. * and unsolicated ELS cmd, send back a rsp, the rsp completes and
  1309. * we are waiting to PLOGI back to the remote NPort.
  1310. */
  1311. int
  1312. lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1313. {
  1314. LPFC_MBOXQ_t *mbox;
  1315. int rc;
  1316. if (ndlp->nlp_rpi) {
  1317. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
  1318. lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
  1319. mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
  1320. rc = lpfc_sli_issue_mbox
  1321. (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
  1322. if (rc == MBX_NOT_FINISHED)
  1323. mempool_free( mbox, phba->mbox_mem_pool);
  1324. }
  1325. lpfc_no_rpi(phba, ndlp);
  1326. ndlp->nlp_rpi = 0;
  1327. return 1;
  1328. }
  1329. return 0;
  1330. }
  1331. /*
  1332. * Free resources associated with LPFC_NODELIST entry
  1333. * so it can be freed.
  1334. */
  1335. static int
  1336. lpfc_cleanup_node(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1337. {
  1338. LPFC_MBOXQ_t *mb;
  1339. LPFC_MBOXQ_t *nextmb;
  1340. struct lpfc_dmabuf *mp;
  1341. /* Cleanup node for NPort <nlp_DID> */
  1342. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1343. "%d:0900 Cleanup node for NPort x%x "
  1344. "Data: x%x x%x x%x\n",
  1345. phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
  1346. ndlp->nlp_state, ndlp->nlp_rpi);
  1347. lpfc_dequeue_node(phba, ndlp);
  1348. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  1349. if ((mb = phba->sli.mbox_active)) {
  1350. if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
  1351. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1352. mb->context2 = NULL;
  1353. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1354. }
  1355. }
  1356. spin_lock_irq(phba->host->host_lock);
  1357. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  1358. if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
  1359. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1360. mp = (struct lpfc_dmabuf *) (mb->context1);
  1361. if (mp) {
  1362. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1363. kfree(mp);
  1364. }
  1365. list_del(&mb->list);
  1366. mempool_free(mb, phba->mbox_mem_pool);
  1367. lpfc_nlp_put(ndlp);
  1368. }
  1369. }
  1370. spin_unlock_irq(phba->host->host_lock);
  1371. lpfc_els_abort(phba,ndlp);
  1372. spin_lock_irq(phba->host->host_lock);
  1373. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  1374. spin_unlock_irq(phba->host->host_lock);
  1375. ndlp->nlp_last_elscmd = 0;
  1376. del_timer_sync(&ndlp->nlp_delayfunc);
  1377. if (!list_empty(&ndlp->els_retry_evt.evt_listp))
  1378. list_del_init(&ndlp->els_retry_evt.evt_listp);
  1379. lpfc_unreg_rpi(phba, ndlp);
  1380. return 0;
  1381. }
  1382. /*
  1383. * Check to see if we can free the nlp back to the freelist.
  1384. * If we are in the middle of using the nlp in the discovery state
  1385. * machine, defer the free till we reach the end of the state machine.
  1386. */
  1387. static void
  1388. lpfc_nlp_remove(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  1389. {
  1390. struct lpfc_rport_data *rdata;
  1391. if (ndlp->nlp_flag & NLP_DELAY_TMO) {
  1392. lpfc_cancel_retry_delay_tmo(phba, ndlp);
  1393. }
  1394. lpfc_cleanup_node(phba, ndlp);
  1395. if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
  1396. put_device(&ndlp->rport->dev);
  1397. rdata = ndlp->rport->dd_data;
  1398. rdata->pnode = NULL;
  1399. ndlp->rport = NULL;
  1400. }
  1401. }
  1402. static int
  1403. lpfc_matchdid(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, uint32_t did)
  1404. {
  1405. D_ID mydid;
  1406. D_ID ndlpdid;
  1407. D_ID matchdid;
  1408. if (did == Bcast_DID)
  1409. return 0;
  1410. if (ndlp->nlp_DID == 0) {
  1411. return 0;
  1412. }
  1413. /* First check for Direct match */
  1414. if (ndlp->nlp_DID == did)
  1415. return 1;
  1416. /* Next check for area/domain identically equals 0 match */
  1417. mydid.un.word = phba->fc_myDID;
  1418. if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
  1419. return 0;
  1420. }
  1421. matchdid.un.word = did;
  1422. ndlpdid.un.word = ndlp->nlp_DID;
  1423. if (matchdid.un.b.id == ndlpdid.un.b.id) {
  1424. if ((mydid.un.b.domain == matchdid.un.b.domain) &&
  1425. (mydid.un.b.area == matchdid.un.b.area)) {
  1426. if ((ndlpdid.un.b.domain == 0) &&
  1427. (ndlpdid.un.b.area == 0)) {
  1428. if (ndlpdid.un.b.id)
  1429. return 1;
  1430. }
  1431. return 0;
  1432. }
  1433. matchdid.un.word = ndlp->nlp_DID;
  1434. if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
  1435. (mydid.un.b.area == ndlpdid.un.b.area)) {
  1436. if ((matchdid.un.b.domain == 0) &&
  1437. (matchdid.un.b.area == 0)) {
  1438. if (matchdid.un.b.id)
  1439. return 1;
  1440. }
  1441. }
  1442. }
  1443. return 0;
  1444. }
  1445. /* Search for a nodelist entry */
  1446. struct lpfc_nodelist *
  1447. lpfc_findnode_did(struct lpfc_hba *phba, uint32_t did)
  1448. {
  1449. struct lpfc_nodelist *ndlp;
  1450. uint32_t data1;
  1451. spin_lock_irq(phba->host->host_lock);
  1452. list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) {
  1453. if (lpfc_matchdid(phba, ndlp, did)) {
  1454. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1455. ((uint32_t) ndlp->nlp_xri << 16) |
  1456. ((uint32_t) ndlp->nlp_type << 8) |
  1457. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1458. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1459. "%d:0929 FIND node DID "
  1460. " Data: x%p x%x x%x x%x\n",
  1461. phba->brd_no,
  1462. ndlp, ndlp->nlp_DID,
  1463. ndlp->nlp_flag, data1);
  1464. spin_unlock_irq(phba->host->host_lock);
  1465. return ndlp;
  1466. }
  1467. }
  1468. spin_unlock_irq(phba->host->host_lock);
  1469. /* FIND node did <did> NOT FOUND */
  1470. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1471. "%d:0932 FIND node did x%x NOT FOUND.\n",
  1472. phba->brd_no, did);
  1473. return NULL;
  1474. }
  1475. struct lpfc_nodelist *
  1476. lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
  1477. {
  1478. struct lpfc_nodelist *ndlp;
  1479. ndlp = lpfc_findnode_did(phba, did);
  1480. if (!ndlp) {
  1481. if ((phba->fc_flag & FC_RSCN_MODE) &&
  1482. ((lpfc_rscn_payload_check(phba, did) == 0)))
  1483. return NULL;
  1484. ndlp = (struct lpfc_nodelist *)
  1485. mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1486. if (!ndlp)
  1487. return NULL;
  1488. lpfc_nlp_init(phba, ndlp, did);
  1489. lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
  1490. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1491. return ndlp;
  1492. }
  1493. if (phba->fc_flag & FC_RSCN_MODE) {
  1494. if (lpfc_rscn_payload_check(phba, did)) {
  1495. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1496. /* Since this node is marked for discovery,
  1497. * delay timeout is not needed.
  1498. */
  1499. if (ndlp->nlp_flag & NLP_DELAY_TMO)
  1500. lpfc_cancel_retry_delay_tmo(phba, ndlp);
  1501. } else
  1502. ndlp = NULL;
  1503. } else {
  1504. if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
  1505. ndlp->nlp_state == NLP_STE_PLOGI_ISSUE)
  1506. return NULL;
  1507. lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
  1508. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1509. }
  1510. return ndlp;
  1511. }
  1512. /* Build a list of nodes to discover based on the loopmap */
  1513. void
  1514. lpfc_disc_list_loopmap(struct lpfc_hba * phba)
  1515. {
  1516. int j;
  1517. uint32_t alpa, index;
  1518. if (phba->hba_state <= LPFC_LINK_DOWN) {
  1519. return;
  1520. }
  1521. if (phba->fc_topology != TOPOLOGY_LOOP) {
  1522. return;
  1523. }
  1524. /* Check for loop map present or not */
  1525. if (phba->alpa_map[0]) {
  1526. for (j = 1; j <= phba->alpa_map[0]; j++) {
  1527. alpa = phba->alpa_map[j];
  1528. if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
  1529. continue;
  1530. }
  1531. lpfc_setup_disc_node(phba, alpa);
  1532. }
  1533. } else {
  1534. /* No alpamap, so try all alpa's */
  1535. for (j = 0; j < FC_MAXLOOP; j++) {
  1536. /* If cfg_scan_down is set, start from highest
  1537. * ALPA (0xef) to lowest (0x1).
  1538. */
  1539. if (phba->cfg_scan_down)
  1540. index = j;
  1541. else
  1542. index = FC_MAXLOOP - j - 1;
  1543. alpa = lpfcAlpaArray[index];
  1544. if ((phba->fc_myDID & 0xff) == alpa) {
  1545. continue;
  1546. }
  1547. lpfc_setup_disc_node(phba, alpa);
  1548. }
  1549. }
  1550. return;
  1551. }
  1552. /* Start Link up / RSCN discovery on NPR list */
  1553. void
  1554. lpfc_disc_start(struct lpfc_hba * phba)
  1555. {
  1556. struct lpfc_sli *psli;
  1557. LPFC_MBOXQ_t *mbox;
  1558. struct lpfc_nodelist *ndlp, *next_ndlp;
  1559. uint32_t num_sent;
  1560. uint32_t clear_la_pending;
  1561. int did_changed;
  1562. int rc;
  1563. psli = &phba->sli;
  1564. if (phba->hba_state <= LPFC_LINK_DOWN) {
  1565. return;
  1566. }
  1567. if (phba->hba_state == LPFC_CLEAR_LA)
  1568. clear_la_pending = 1;
  1569. else
  1570. clear_la_pending = 0;
  1571. if (phba->hba_state < LPFC_HBA_READY) {
  1572. phba->hba_state = LPFC_DISC_AUTH;
  1573. }
  1574. lpfc_set_disctmo(phba);
  1575. if (phba->fc_prevDID == phba->fc_myDID) {
  1576. did_changed = 0;
  1577. } else {
  1578. did_changed = 1;
  1579. }
  1580. phba->fc_prevDID = phba->fc_myDID;
  1581. phba->num_disc_nodes = 0;
  1582. /* Start Discovery state <hba_state> */
  1583. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1584. "%d:0202 Start Discovery hba state x%x "
  1585. "Data: x%x x%x x%x\n",
  1586. phba->brd_no, phba->hba_state, phba->fc_flag,
  1587. phba->fc_plogi_cnt, phba->fc_adisc_cnt);
  1588. /* If our did changed, we MUST do PLOGI */
  1589. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp) {
  1590. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  1591. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  1592. did_changed) {
  1593. spin_lock_irq(phba->host->host_lock);
  1594. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1595. spin_unlock_irq(phba->host->host_lock);
  1596. }
  1597. }
  1598. /* First do ADISCs - if any */
  1599. num_sent = lpfc_els_disc_adisc(phba);
  1600. if (num_sent)
  1601. return;
  1602. if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
  1603. /* If we get here, there is nothing to ADISC */
  1604. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
  1605. phba->hba_state = LPFC_CLEAR_LA;
  1606. lpfc_clear_la(phba, mbox);
  1607. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  1608. rc = lpfc_sli_issue_mbox(phba, mbox,
  1609. (MBX_NOWAIT | MBX_STOP_IOCB));
  1610. if (rc == MBX_NOT_FINISHED) {
  1611. mempool_free( mbox, phba->mbox_mem_pool);
  1612. lpfc_disc_flush_list(phba);
  1613. psli->ring[(psli->extra_ring)].flag &=
  1614. ~LPFC_STOP_IOCB_EVENT;
  1615. psli->ring[(psli->fcp_ring)].flag &=
  1616. ~LPFC_STOP_IOCB_EVENT;
  1617. psli->ring[(psli->next_ring)].flag &=
  1618. ~LPFC_STOP_IOCB_EVENT;
  1619. phba->hba_state = LPFC_HBA_READY;
  1620. }
  1621. }
  1622. } else {
  1623. /* Next do PLOGIs - if any */
  1624. num_sent = lpfc_els_disc_plogi(phba);
  1625. if (num_sent)
  1626. return;
  1627. if (phba->fc_flag & FC_RSCN_MODE) {
  1628. /* Check to see if more RSCNs came in while we
  1629. * were processing this one.
  1630. */
  1631. if ((phba->fc_rscn_id_cnt == 0) &&
  1632. (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
  1633. spin_lock_irq(phba->host->host_lock);
  1634. phba->fc_flag &= ~FC_RSCN_MODE;
  1635. spin_unlock_irq(phba->host->host_lock);
  1636. } else
  1637. lpfc_els_handle_rscn(phba);
  1638. }
  1639. }
  1640. return;
  1641. }
  1642. /*
  1643. * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
  1644. * ring the match the sppecified nodelist.
  1645. */
  1646. static void
  1647. lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1648. {
  1649. LIST_HEAD(completions);
  1650. struct lpfc_sli *psli;
  1651. IOCB_t *icmd;
  1652. struct lpfc_iocbq *iocb, *next_iocb;
  1653. struct lpfc_sli_ring *pring;
  1654. psli = &phba->sli;
  1655. pring = &psli->ring[LPFC_ELS_RING];
  1656. /* Error matching iocb on txq or txcmplq
  1657. * First check the txq.
  1658. */
  1659. spin_lock_irq(phba->host->host_lock);
  1660. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  1661. if (iocb->context1 != ndlp) {
  1662. continue;
  1663. }
  1664. icmd = &iocb->iocb;
  1665. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  1666. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  1667. list_move_tail(&iocb->list, &completions);
  1668. pring->txq_cnt--;
  1669. }
  1670. }
  1671. /* Next check the txcmplq */
  1672. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  1673. if (iocb->context1 != ndlp) {
  1674. continue;
  1675. }
  1676. icmd = &iocb->iocb;
  1677. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  1678. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  1679. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  1680. }
  1681. }
  1682. spin_unlock_irq(phba->host->host_lock);
  1683. while (!list_empty(&completions)) {
  1684. iocb = list_get_first(&completions, struct lpfc_iocbq, list);
  1685. list_del(&iocb->list);
  1686. if (iocb->iocb_cmpl) {
  1687. icmd = &iocb->iocb;
  1688. icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  1689. icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  1690. (iocb->iocb_cmpl) (phba, iocb, iocb);
  1691. } else
  1692. lpfc_sli_release_iocbq(phba, iocb);
  1693. }
  1694. return;
  1695. }
  1696. void
  1697. lpfc_disc_flush_list(struct lpfc_hba * phba)
  1698. {
  1699. struct lpfc_nodelist *ndlp, *next_ndlp;
  1700. if (phba->fc_plogi_cnt || phba->fc_adisc_cnt) {
  1701. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes,
  1702. nlp_listp) {
  1703. if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  1704. ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
  1705. lpfc_free_tx(phba, ndlp);
  1706. lpfc_nlp_put(ndlp);
  1707. }
  1708. }
  1709. }
  1710. }
  1711. /*****************************************************************************/
  1712. /*
  1713. * NAME: lpfc_disc_timeout
  1714. *
  1715. * FUNCTION: Fibre Channel driver discovery timeout routine.
  1716. *
  1717. * EXECUTION ENVIRONMENT: interrupt only
  1718. *
  1719. * CALLED FROM:
  1720. * Timer function
  1721. *
  1722. * RETURNS:
  1723. * none
  1724. */
  1725. /*****************************************************************************/
  1726. void
  1727. lpfc_disc_timeout(unsigned long ptr)
  1728. {
  1729. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  1730. unsigned long flags = 0;
  1731. if (unlikely(!phba))
  1732. return;
  1733. spin_lock_irqsave(phba->host->host_lock, flags);
  1734. if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
  1735. phba->work_hba_events |= WORKER_DISC_TMO;
  1736. if (phba->work_wait)
  1737. wake_up(phba->work_wait);
  1738. }
  1739. spin_unlock_irqrestore(phba->host->host_lock, flags);
  1740. return;
  1741. }
  1742. static void
  1743. lpfc_disc_timeout_handler(struct lpfc_hba *phba)
  1744. {
  1745. struct lpfc_sli *psli;
  1746. struct lpfc_nodelist *ndlp, *next_ndlp;
  1747. LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
  1748. int rc, clrlaerr = 0;
  1749. if (unlikely(!phba))
  1750. return;
  1751. if (!(phba->fc_flag & FC_DISC_TMO))
  1752. return;
  1753. psli = &phba->sli;
  1754. spin_lock_irq(phba->host->host_lock);
  1755. phba->fc_flag &= ~FC_DISC_TMO;
  1756. spin_unlock_irq(phba->host->host_lock);
  1757. switch (phba->hba_state) {
  1758. case LPFC_LOCAL_CFG_LINK:
  1759. /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
  1760. /* FAN timeout */
  1761. lpfc_printf_log(phba,
  1762. KERN_WARNING,
  1763. LOG_DISCOVERY,
  1764. "%d:0221 FAN timeout\n",
  1765. phba->brd_no);
  1766. /* Start discovery by sending FLOGI, clean up old rpis */
  1767. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes,
  1768. nlp_listp) {
  1769. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  1770. continue;
  1771. if (ndlp->nlp_type & NLP_FABRIC) {
  1772. /* Clean up the ndlp on Fabric connections */
  1773. lpfc_drop_node(phba, ndlp);
  1774. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  1775. /* Fail outstanding IO now since device
  1776. * is marked for PLOGI.
  1777. */
  1778. lpfc_unreg_rpi(phba, ndlp);
  1779. }
  1780. }
  1781. phba->hba_state = LPFC_FLOGI;
  1782. lpfc_set_disctmo(phba);
  1783. lpfc_initial_flogi(phba);
  1784. break;
  1785. case LPFC_FLOGI:
  1786. /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
  1787. /* Initial FLOGI timeout */
  1788. lpfc_printf_log(phba,
  1789. KERN_ERR,
  1790. LOG_DISCOVERY,
  1791. "%d:0222 Initial FLOGI timeout\n",
  1792. phba->brd_no);
  1793. /* Assume no Fabric and go on with discovery.
  1794. * Check for outstanding ELS FLOGI to abort.
  1795. */
  1796. /* FLOGI failed, so just use loop map to make discovery list */
  1797. lpfc_disc_list_loopmap(phba);
  1798. /* Start discovery */
  1799. lpfc_disc_start(phba);
  1800. break;
  1801. case LPFC_FABRIC_CFG_LINK:
  1802. /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
  1803. NameServer login */
  1804. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  1805. "%d:0223 Timeout while waiting for NameServer "
  1806. "login\n", phba->brd_no);
  1807. /* Next look for NameServer ndlp */
  1808. ndlp = lpfc_findnode_did(phba, NameServer_DID);
  1809. if (ndlp)
  1810. lpfc_nlp_put(ndlp);
  1811. /* Start discovery */
  1812. lpfc_disc_start(phba);
  1813. break;
  1814. case LPFC_NS_QRY:
  1815. /* Check for wait for NameServer Rsp timeout */
  1816. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  1817. "%d:0224 NameServer Query timeout "
  1818. "Data: x%x x%x\n",
  1819. phba->brd_no,
  1820. phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
  1821. ndlp = lpfc_findnode_did(phba, NameServer_DID);
  1822. if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  1823. if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  1824. /* Try it one more time */
  1825. rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
  1826. if (rc == 0)
  1827. break;
  1828. }
  1829. phba->fc_ns_retry = 0;
  1830. }
  1831. /* Nothing to authenticate, so CLEAR_LA right now */
  1832. clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1833. if (!clearlambox) {
  1834. clrlaerr = 1;
  1835. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  1836. "%d:0226 Device Discovery "
  1837. "completion error\n",
  1838. phba->brd_no);
  1839. phba->hba_state = LPFC_HBA_ERROR;
  1840. break;
  1841. }
  1842. phba->hba_state = LPFC_CLEAR_LA;
  1843. lpfc_clear_la(phba, clearlambox);
  1844. clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  1845. rc = lpfc_sli_issue_mbox(phba, clearlambox,
  1846. (MBX_NOWAIT | MBX_STOP_IOCB));
  1847. if (rc == MBX_NOT_FINISHED) {
  1848. mempool_free(clearlambox, phba->mbox_mem_pool);
  1849. clrlaerr = 1;
  1850. break;
  1851. }
  1852. /* Setup and issue mailbox INITIALIZE LINK command */
  1853. initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1854. if (!initlinkmbox) {
  1855. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  1856. "%d:0206 Device Discovery "
  1857. "completion error\n",
  1858. phba->brd_no);
  1859. phba->hba_state = LPFC_HBA_ERROR;
  1860. break;
  1861. }
  1862. lpfc_linkdown(phba);
  1863. lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
  1864. phba->cfg_link_speed);
  1865. initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
  1866. rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
  1867. (MBX_NOWAIT | MBX_STOP_IOCB));
  1868. lpfc_set_loopback_flag(phba);
  1869. if (rc == MBX_NOT_FINISHED)
  1870. mempool_free(initlinkmbox, phba->mbox_mem_pool);
  1871. break;
  1872. case LPFC_DISC_AUTH:
  1873. /* Node Authentication timeout */
  1874. lpfc_printf_log(phba,
  1875. KERN_ERR,
  1876. LOG_DISCOVERY,
  1877. "%d:0227 Node Authentication timeout\n",
  1878. phba->brd_no);
  1879. lpfc_disc_flush_list(phba);
  1880. clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1881. if (!clearlambox) {
  1882. clrlaerr = 1;
  1883. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  1884. "%d:0207 Device Discovery "
  1885. "completion error\n",
  1886. phba->brd_no);
  1887. phba->hba_state = LPFC_HBA_ERROR;
  1888. break;
  1889. }
  1890. phba->hba_state = LPFC_CLEAR_LA;
  1891. lpfc_clear_la(phba, clearlambox);
  1892. clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  1893. rc = lpfc_sli_issue_mbox(phba, clearlambox,
  1894. (MBX_NOWAIT | MBX_STOP_IOCB));
  1895. if (rc == MBX_NOT_FINISHED) {
  1896. mempool_free(clearlambox, phba->mbox_mem_pool);
  1897. clrlaerr = 1;
  1898. }
  1899. break;
  1900. case LPFC_CLEAR_LA:
  1901. /* CLEAR LA timeout */
  1902. lpfc_printf_log(phba,
  1903. KERN_ERR,
  1904. LOG_DISCOVERY,
  1905. "%d:0228 CLEAR LA timeout\n",
  1906. phba->brd_no);
  1907. clrlaerr = 1;
  1908. break;
  1909. case LPFC_HBA_READY:
  1910. if (phba->fc_flag & FC_RSCN_MODE) {
  1911. lpfc_printf_log(phba,
  1912. KERN_ERR,
  1913. LOG_DISCOVERY,
  1914. "%d:0231 RSCN timeout Data: x%x x%x\n",
  1915. phba->brd_no,
  1916. phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
  1917. /* Cleanup any outstanding ELS commands */
  1918. lpfc_els_flush_cmd(phba);
  1919. lpfc_els_flush_rscn(phba);
  1920. lpfc_disc_flush_list(phba);
  1921. }
  1922. break;
  1923. }
  1924. if (clrlaerr) {
  1925. lpfc_disc_flush_list(phba);
  1926. psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  1927. psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  1928. psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  1929. phba->hba_state = LPFC_HBA_READY;
  1930. }
  1931. return;
  1932. }
  1933. /*
  1934. * This routine handles processing a NameServer REG_LOGIN mailbox
  1935. * command upon completion. It is setup in the LPFC_MBOXQ
  1936. * as the completion routine when the command is
  1937. * handed off to the SLI layer.
  1938. */
  1939. void
  1940. lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  1941. {
  1942. struct lpfc_sli *psli;
  1943. MAILBOX_t *mb;
  1944. struct lpfc_dmabuf *mp;
  1945. struct lpfc_nodelist *ndlp;
  1946. psli = &phba->sli;
  1947. mb = &pmb->mb;
  1948. ndlp = (struct lpfc_nodelist *) pmb->context2;
  1949. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1950. pmb->context1 = NULL;
  1951. ndlp->nlp_rpi = mb->un.varWords[0];
  1952. ndlp->nlp_type |= NLP_FABRIC;
  1953. lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
  1954. /* Start issuing Fabric-Device Management Interface (FDMI)
  1955. * command to 0xfffffa (FDMI well known port)
  1956. */
  1957. if (phba->cfg_fdmi_on == 1) {
  1958. lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
  1959. } else {
  1960. /*
  1961. * Delay issuing FDMI command if fdmi-on=2
  1962. * (supporting RPA/hostnmae)
  1963. */
  1964. mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
  1965. }
  1966. /* Mailbox took a reference to the node */
  1967. lpfc_nlp_put(ndlp);
  1968. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1969. kfree(mp);
  1970. mempool_free(pmb, phba->mbox_mem_pool);
  1971. return;
  1972. }
  1973. static int
  1974. lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
  1975. {
  1976. uint16_t *rpi = param;
  1977. return ndlp->nlp_rpi == *rpi;
  1978. }
  1979. static int
  1980. lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
  1981. {
  1982. return memcmp(&ndlp->nlp_portname, param,
  1983. sizeof(ndlp->nlp_portname)) == 0;
  1984. }
  1985. /*
  1986. * Search node lists for a remote port matching filter criteria
  1987. * Caller needs to hold host_lock before calling this routine.
  1988. */
  1989. struct lpfc_nodelist *
  1990. __lpfc_find_node(struct lpfc_hba *phba, node_filter filter, void *param)
  1991. {
  1992. struct lpfc_nodelist *ndlp;
  1993. list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) {
  1994. if (ndlp->nlp_state != NLP_STE_UNUSED_NODE &&
  1995. filter(ndlp, param))
  1996. return ndlp;
  1997. }
  1998. return NULL;
  1999. }
  2000. /*
  2001. * Search node lists for a remote port matching filter criteria
  2002. * This routine is used when the caller does NOT have host_lock.
  2003. */
  2004. struct lpfc_nodelist *
  2005. lpfc_find_node(struct lpfc_hba *phba, node_filter filter, void *param)
  2006. {
  2007. struct lpfc_nodelist *ndlp;
  2008. spin_lock_irq(phba->host->host_lock);
  2009. ndlp = __lpfc_find_node(phba, filter, param);
  2010. spin_unlock_irq(phba->host->host_lock);
  2011. return ndlp;
  2012. }
  2013. /*
  2014. * This routine looks up the ndlp lists for the given RPI. If rpi found it
  2015. * returns the node list pointer else return NULL.
  2016. */
  2017. struct lpfc_nodelist *
  2018. __lpfc_findnode_rpi(struct lpfc_hba *phba, uint16_t rpi)
  2019. {
  2020. return __lpfc_find_node(phba, lpfc_filter_by_rpi, &rpi);
  2021. }
  2022. struct lpfc_nodelist *
  2023. lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
  2024. {
  2025. struct lpfc_nodelist *ndlp;
  2026. spin_lock_irq(phba->host->host_lock);
  2027. ndlp = __lpfc_findnode_rpi(phba, rpi);
  2028. spin_unlock_irq(phba->host->host_lock);
  2029. return ndlp;
  2030. }
  2031. /*
  2032. * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
  2033. * returns the node list pointer else return NULL.
  2034. */
  2035. struct lpfc_nodelist *
  2036. lpfc_findnode_wwpn(struct lpfc_hba *phba, struct lpfc_name *wwpn)
  2037. {
  2038. struct lpfc_nodelist *ndlp;
  2039. spin_lock_irq(phba->host->host_lock);
  2040. ndlp = __lpfc_find_node(phba, lpfc_filter_by_wwpn, wwpn);
  2041. spin_unlock_irq(phba->host->host_lock);
  2042. return NULL;
  2043. }
  2044. void
  2045. lpfc_nlp_init(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, uint32_t did)
  2046. {
  2047. memset(ndlp, 0, sizeof (struct lpfc_nodelist));
  2048. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  2049. init_timer(&ndlp->nlp_delayfunc);
  2050. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  2051. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  2052. ndlp->nlp_DID = did;
  2053. ndlp->nlp_phba = phba;
  2054. ndlp->nlp_sid = NLP_NO_SID;
  2055. INIT_LIST_HEAD(&ndlp->nlp_listp);
  2056. kref_init(&ndlp->kref);
  2057. return;
  2058. }
  2059. void
  2060. lpfc_nlp_release(struct kref *kref)
  2061. {
  2062. struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
  2063. kref);
  2064. lpfc_nlp_remove(ndlp->nlp_phba, ndlp);
  2065. mempool_free(ndlp, ndlp->nlp_phba->nlp_mem_pool);
  2066. }
  2067. struct lpfc_nodelist *
  2068. lpfc_nlp_get(struct lpfc_nodelist *ndlp)
  2069. {
  2070. if (ndlp)
  2071. kref_get(&ndlp->kref);
  2072. return ndlp;
  2073. }
  2074. int
  2075. lpfc_nlp_put(struct lpfc_nodelist *ndlp)
  2076. {
  2077. return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
  2078. }