lpfc_nportdisc.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001
  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/interrupt.h>
  24. #include <scsi/scsi.h>
  25. #include <scsi/scsi_device.h>
  26. #include <scsi/scsi_host.h>
  27. #include <scsi/scsi_transport_fc.h>
  28. #include "lpfc_hw.h"
  29. #include "lpfc_sli.h"
  30. #include "lpfc_disc.h"
  31. #include "lpfc_scsi.h"
  32. #include "lpfc.h"
  33. #include "lpfc_logmsg.h"
  34. #include "lpfc_crtn.h"
  35. /* Called to verify a rcv'ed ADISC was intended for us. */
  36. static int
  37. lpfc_check_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  38. struct lpfc_name * nn, struct lpfc_name * pn)
  39. {
  40. /* Compare the ADISC rsp WWNN / WWPN matches our internal node
  41. * table entry for that node.
  42. */
  43. if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)) != 0)
  44. return 0;
  45. if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)) != 0)
  46. return 0;
  47. /* we match, return success */
  48. return 1;
  49. }
  50. int
  51. lpfc_check_sparm(struct lpfc_hba * phba,
  52. struct lpfc_nodelist * ndlp, struct serv_parm * sp,
  53. uint32_t class)
  54. {
  55. volatile struct serv_parm *hsp = &phba->fc_sparam;
  56. uint16_t hsp_value, ssp_value = 0;
  57. /*
  58. * The receive data field size and buffer-to-buffer receive data field
  59. * size entries are 16 bits but are represented as two 8-bit fields in
  60. * the driver data structure to account for rsvd bits and other control
  61. * bits. Reconstruct and compare the fields as a 16-bit values before
  62. * correcting the byte values.
  63. */
  64. if (sp->cls1.classValid) {
  65. hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
  66. hsp->cls1.rcvDataSizeLsb;
  67. ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
  68. sp->cls1.rcvDataSizeLsb;
  69. if (ssp_value > hsp_value) {
  70. sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
  71. sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
  72. }
  73. } else if (class == CLASS1) {
  74. return 0;
  75. }
  76. if (sp->cls2.classValid) {
  77. hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
  78. hsp->cls2.rcvDataSizeLsb;
  79. ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
  80. sp->cls2.rcvDataSizeLsb;
  81. if (ssp_value > hsp_value) {
  82. sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
  83. sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
  84. }
  85. } else if (class == CLASS2) {
  86. return 0;
  87. }
  88. if (sp->cls3.classValid) {
  89. hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
  90. hsp->cls3.rcvDataSizeLsb;
  91. ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
  92. sp->cls3.rcvDataSizeLsb;
  93. if (ssp_value > hsp_value) {
  94. sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
  95. sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
  96. }
  97. } else if (class == CLASS3) {
  98. return 0;
  99. }
  100. /*
  101. * Preserve the upper four bits of the MSB from the PLOGI response.
  102. * These bits contain the Buffer-to-Buffer State Change Number
  103. * from the target and need to be passed to the FW.
  104. */
  105. hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
  106. ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
  107. if (ssp_value > hsp_value) {
  108. sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
  109. sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
  110. (hsp->cmn.bbRcvSizeMsb & 0x0F);
  111. }
  112. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
  113. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
  114. return 1;
  115. }
  116. static void *
  117. lpfc_check_elscmpl_iocb(struct lpfc_hba * phba,
  118. struct lpfc_iocbq *cmdiocb,
  119. struct lpfc_iocbq *rspiocb)
  120. {
  121. struct lpfc_dmabuf *pcmd, *prsp;
  122. uint32_t *lp;
  123. void *ptr = NULL;
  124. IOCB_t *irsp;
  125. irsp = &rspiocb->iocb;
  126. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  127. /* For lpfc_els_abort, context2 could be zero'ed to delay
  128. * freeing associated memory till after ABTS completes.
  129. */
  130. if (pcmd) {
  131. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
  132. list);
  133. if (prsp) {
  134. lp = (uint32_t *) prsp->virt;
  135. ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
  136. }
  137. } else {
  138. /* Force ulpStatus error since we are returning NULL ptr */
  139. if (!(irsp->ulpStatus)) {
  140. irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
  141. irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
  142. }
  143. ptr = NULL;
  144. }
  145. return ptr;
  146. }
  147. /*
  148. * Free resources / clean up outstanding I/Os
  149. * associated with a LPFC_NODELIST entry. This
  150. * routine effectively results in a "software abort".
  151. */
  152. int
  153. lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  154. int send_abts)
  155. {
  156. struct lpfc_sli *psli;
  157. struct lpfc_sli_ring *pring;
  158. struct lpfc_iocbq *iocb, *next_iocb;
  159. IOCB_t *icmd;
  160. int found = 0;
  161. /* Abort outstanding I/O on NPort <nlp_DID> */
  162. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  163. "%d:0205 Abort outstanding I/O on NPort x%x "
  164. "Data: x%x x%x x%x\n",
  165. phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
  166. ndlp->nlp_state, ndlp->nlp_rpi);
  167. psli = &phba->sli;
  168. pring = &psli->ring[LPFC_ELS_RING];
  169. /* First check the txq */
  170. do {
  171. found = 0;
  172. spin_lock_irq(phba->host->host_lock);
  173. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  174. /* Check to see if iocb matches the nport we are looking
  175. for */
  176. if ((lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))) {
  177. found = 1;
  178. /* It matches, so deque and call compl with an
  179. error */
  180. list_del(&iocb->list);
  181. pring->txq_cnt--;
  182. if (iocb->iocb_cmpl) {
  183. icmd = &iocb->iocb;
  184. icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  185. icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  186. spin_unlock_irq(phba->host->host_lock);
  187. (iocb->iocb_cmpl) (phba, iocb, iocb);
  188. spin_lock_irq(phba->host->host_lock);
  189. } else
  190. lpfc_sli_release_iocbq(phba, iocb);
  191. break;
  192. }
  193. }
  194. spin_unlock_irq(phba->host->host_lock);
  195. } while (found);
  196. /* Everything on txcmplq will be returned by firmware
  197. * with a no rpi / linkdown / abort error. For ring 0,
  198. * ELS discovery, we want to get rid of it right here.
  199. */
  200. /* Next check the txcmplq */
  201. do {
  202. found = 0;
  203. spin_lock_irq(phba->host->host_lock);
  204. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  205. list) {
  206. /* Check to see if iocb matches the nport we are looking
  207. for */
  208. if ((lpfc_check_sli_ndlp (phba, pring, iocb, ndlp))) {
  209. found = 1;
  210. /* It matches, so deque and call compl with an
  211. error */
  212. list_del(&iocb->list);
  213. pring->txcmplq_cnt--;
  214. icmd = &iocb->iocb;
  215. /* If the driver is completing an ELS
  216. * command early, flush it out of the firmware.
  217. */
  218. if (send_abts &&
  219. (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) &&
  220. (icmd->un.elsreq64.bdl.ulpIoTag32)) {
  221. lpfc_sli_issue_abort_iotag32(phba,
  222. pring, iocb);
  223. }
  224. if (iocb->iocb_cmpl) {
  225. icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  226. icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  227. spin_unlock_irq(phba->host->host_lock);
  228. (iocb->iocb_cmpl) (phba, iocb, iocb);
  229. spin_lock_irq(phba->host->host_lock);
  230. } else
  231. lpfc_sli_release_iocbq(phba, iocb);
  232. break;
  233. }
  234. }
  235. spin_unlock_irq(phba->host->host_lock);
  236. } while(found);
  237. /* If we are delaying issuing an ELS command, cancel it */
  238. if (ndlp->nlp_flag & NLP_DELAY_TMO)
  239. lpfc_cancel_retry_delay_tmo(phba, ndlp);
  240. return 0;
  241. }
  242. static int
  243. lpfc_rcv_plogi(struct lpfc_hba * phba,
  244. struct lpfc_nodelist * ndlp,
  245. struct lpfc_iocbq *cmdiocb)
  246. {
  247. struct lpfc_dmabuf *pcmd;
  248. uint32_t *lp;
  249. IOCB_t *icmd;
  250. struct serv_parm *sp;
  251. LPFC_MBOXQ_t *mbox;
  252. struct ls_rjt stat;
  253. int rc;
  254. memset(&stat, 0, sizeof (struct ls_rjt));
  255. if (phba->hba_state <= LPFC_FLOGI) {
  256. /* Before responding to PLOGI, check for pt2pt mode.
  257. * If we are pt2pt, with an outstanding FLOGI, abort
  258. * the FLOGI and resend it first.
  259. */
  260. if (phba->fc_flag & FC_PT2PT) {
  261. lpfc_els_abort_flogi(phba);
  262. if (!(phba->fc_flag & FC_PT2PT_PLOGI)) {
  263. /* If the other side is supposed to initiate
  264. * the PLOGI anyway, just ACC it now and
  265. * move on with discovery.
  266. */
  267. phba->fc_edtov = FF_DEF_EDTOV;
  268. phba->fc_ratov = FF_DEF_RATOV;
  269. /* Start discovery - this should just do
  270. CLEAR_LA */
  271. lpfc_disc_start(phba);
  272. } else {
  273. lpfc_initial_flogi(phba);
  274. }
  275. } else {
  276. stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
  277. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  278. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb,
  279. ndlp);
  280. return 0;
  281. }
  282. }
  283. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  284. lp = (uint32_t *) pcmd->virt;
  285. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  286. if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3) == 0)) {
  287. /* Reject this request because invalid parameters */
  288. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  289. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  290. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  291. return 0;
  292. }
  293. icmd = &cmdiocb->iocb;
  294. /* PLOGI chkparm OK */
  295. lpfc_printf_log(phba,
  296. KERN_INFO,
  297. LOG_ELS,
  298. "%d:0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
  299. phba->brd_no,
  300. ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
  301. ndlp->nlp_rpi);
  302. if ((phba->cfg_fcp_class == 2) &&
  303. (sp->cls2.classValid)) {
  304. ndlp->nlp_fcp_info |= CLASS2;
  305. } else {
  306. ndlp->nlp_fcp_info |= CLASS3;
  307. }
  308. ndlp->nlp_class_sup = 0;
  309. if (sp->cls1.classValid)
  310. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  311. if (sp->cls2.classValid)
  312. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  313. if (sp->cls3.classValid)
  314. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  315. if (sp->cls4.classValid)
  316. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  317. ndlp->nlp_maxframe =
  318. ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
  319. /* no need to reg_login if we are already in one of these states */
  320. switch (ndlp->nlp_state) {
  321. case NLP_STE_NPR_NODE:
  322. if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
  323. break;
  324. case NLP_STE_REG_LOGIN_ISSUE:
  325. case NLP_STE_PRLI_ISSUE:
  326. case NLP_STE_UNMAPPED_NODE:
  327. case NLP_STE_MAPPED_NODE:
  328. lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
  329. return 1;
  330. }
  331. if ((phba->fc_flag & FC_PT2PT)
  332. && !(phba->fc_flag & FC_PT2PT_PLOGI)) {
  333. /* rcv'ed PLOGI decides what our NPortId will be */
  334. phba->fc_myDID = icmd->un.rcvels.parmRo;
  335. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  336. if (mbox == NULL)
  337. goto out;
  338. lpfc_config_link(phba, mbox);
  339. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  340. rc = lpfc_sli_issue_mbox
  341. (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
  342. if (rc == MBX_NOT_FINISHED) {
  343. mempool_free( mbox, phba->mbox_mem_pool);
  344. goto out;
  345. }
  346. lpfc_can_disctmo(phba);
  347. }
  348. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  349. if (mbox == NULL)
  350. goto out;
  351. if (lpfc_reg_login(phba, icmd->un.rcvels.remoteID,
  352. (uint8_t *) sp, mbox, 0)) {
  353. mempool_free( mbox, phba->mbox_mem_pool);
  354. goto out;
  355. }
  356. /* ACC PLOGI rsp command needs to execute first,
  357. * queue this mbox command to be processed later.
  358. */
  359. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  360. mbox->context2 = ndlp;
  361. ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
  362. /*
  363. * If there is an outstanding PLOGI issued, abort it before
  364. * sending ACC rsp for received PLOGI. If pending plogi
  365. * is not canceled here, the plogi will be rejected by
  366. * remote port and will be retried. On a configuration with
  367. * single discovery thread, this will cause a huge delay in
  368. * discovery. Also this will cause multiple state machines
  369. * running in parallel for this node.
  370. */
  371. if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
  372. /* software abort outstanding PLOGI */
  373. lpfc_els_abort(phba, ndlp, 1);
  374. }
  375. lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
  376. return 1;
  377. out:
  378. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  379. stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
  380. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  381. return 0;
  382. }
  383. static int
  384. lpfc_rcv_padisc(struct lpfc_hba * phba,
  385. struct lpfc_nodelist * ndlp,
  386. struct lpfc_iocbq *cmdiocb)
  387. {
  388. struct lpfc_dmabuf *pcmd;
  389. struct serv_parm *sp;
  390. struct lpfc_name *pnn, *ppn;
  391. struct ls_rjt stat;
  392. ADISC *ap;
  393. IOCB_t *icmd;
  394. uint32_t *lp;
  395. uint32_t cmd;
  396. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  397. lp = (uint32_t *) pcmd->virt;
  398. cmd = *lp++;
  399. if (cmd == ELS_CMD_ADISC) {
  400. ap = (ADISC *) lp;
  401. pnn = (struct lpfc_name *) & ap->nodeName;
  402. ppn = (struct lpfc_name *) & ap->portName;
  403. } else {
  404. sp = (struct serv_parm *) lp;
  405. pnn = (struct lpfc_name *) & sp->nodeName;
  406. ppn = (struct lpfc_name *) & sp->portName;
  407. }
  408. icmd = &cmdiocb->iocb;
  409. if ((icmd->ulpStatus == 0) &&
  410. (lpfc_check_adisc(phba, ndlp, pnn, ppn))) {
  411. if (cmd == ELS_CMD_ADISC) {
  412. lpfc_els_rsp_adisc_acc(phba, cmdiocb, ndlp);
  413. } else {
  414. lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp,
  415. NULL, 0);
  416. }
  417. return 1;
  418. }
  419. /* Reject this request because invalid parameters */
  420. stat.un.b.lsRjtRsvd0 = 0;
  421. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  422. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  423. stat.un.b.vendorUnique = 0;
  424. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  425. /* 1 sec timeout */
  426. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  427. spin_lock_irq(phba->host->host_lock);
  428. ndlp->nlp_flag |= NLP_DELAY_TMO;
  429. spin_unlock_irq(phba->host->host_lock);
  430. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  431. ndlp->nlp_prev_state = ndlp->nlp_state;
  432. ndlp->nlp_state = NLP_STE_NPR_NODE;
  433. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  434. return 0;
  435. }
  436. static int
  437. lpfc_rcv_logo(struct lpfc_hba * phba,
  438. struct lpfc_nodelist * ndlp,
  439. struct lpfc_iocbq *cmdiocb,
  440. uint32_t els_cmd)
  441. {
  442. /* Put ndlp on NPR list with 1 sec timeout for plogi, ACC logo */
  443. /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
  444. * PLOGIs during LOGO storms from a device.
  445. */
  446. ndlp->nlp_flag |= NLP_LOGO_ACC;
  447. if (els_cmd == ELS_CMD_PRLO)
  448. lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
  449. else
  450. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  451. if (!(ndlp->nlp_type & NLP_FABRIC) ||
  452. (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
  453. /* Only try to re-login if this is NOT a Fabric Node */
  454. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  455. spin_lock_irq(phba->host->host_lock);
  456. ndlp->nlp_flag |= NLP_DELAY_TMO;
  457. spin_unlock_irq(phba->host->host_lock);
  458. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  459. ndlp->nlp_prev_state = ndlp->nlp_state;
  460. ndlp->nlp_state = NLP_STE_NPR_NODE;
  461. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  462. } else {
  463. ndlp->nlp_prev_state = ndlp->nlp_state;
  464. ndlp->nlp_state = NLP_STE_UNUSED_NODE;
  465. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  466. }
  467. spin_lock_irq(phba->host->host_lock);
  468. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  469. spin_unlock_irq(phba->host->host_lock);
  470. /* The driver has to wait until the ACC completes before it continues
  471. * processing the LOGO. The action will resume in
  472. * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
  473. * unreg_login, the driver waits so the ACC does not get aborted.
  474. */
  475. return 0;
  476. }
  477. static void
  478. lpfc_rcv_prli(struct lpfc_hba * phba,
  479. struct lpfc_nodelist * ndlp,
  480. struct lpfc_iocbq *cmdiocb)
  481. {
  482. struct lpfc_dmabuf *pcmd;
  483. uint32_t *lp;
  484. PRLI *npr;
  485. struct fc_rport *rport = ndlp->rport;
  486. u32 roles;
  487. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  488. lp = (uint32_t *) pcmd->virt;
  489. npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
  490. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  491. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  492. if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
  493. (npr->prliType == PRLI_FCP_TYPE)) {
  494. if (npr->initiatorFunc)
  495. ndlp->nlp_type |= NLP_FCP_INITIATOR;
  496. if (npr->targetFunc)
  497. ndlp->nlp_type |= NLP_FCP_TARGET;
  498. if (npr->Retry)
  499. ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
  500. }
  501. if (rport) {
  502. /* We need to update the rport role values */
  503. roles = FC_RPORT_ROLE_UNKNOWN;
  504. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  505. roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  506. if (ndlp->nlp_type & NLP_FCP_TARGET)
  507. roles |= FC_RPORT_ROLE_FCP_TARGET;
  508. fc_remote_port_rolechg(rport, roles);
  509. }
  510. }
  511. static uint32_t
  512. lpfc_disc_set_adisc(struct lpfc_hba * phba,
  513. struct lpfc_nodelist * ndlp)
  514. {
  515. /* Check config parameter use-adisc or FCP-2 */
  516. if ((phba->cfg_use_adisc == 0) &&
  517. !(phba->fc_flag & FC_RSCN_MODE)) {
  518. if (!(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
  519. return 0;
  520. }
  521. spin_lock_irq(phba->host->host_lock);
  522. ndlp->nlp_flag |= NLP_NPR_ADISC;
  523. spin_unlock_irq(phba->host->host_lock);
  524. return 1;
  525. }
  526. static uint32_t
  527. lpfc_disc_illegal(struct lpfc_hba * phba,
  528. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  529. {
  530. lpfc_printf_log(phba,
  531. KERN_ERR,
  532. LOG_DISCOVERY,
  533. "%d:0253 Illegal State Transition: node x%x event x%x, "
  534. "state x%x Data: x%x x%x\n",
  535. phba->brd_no,
  536. ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
  537. ndlp->nlp_flag);
  538. return ndlp->nlp_state;
  539. }
  540. /* Start of Discovery State Machine routines */
  541. static uint32_t
  542. lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
  543. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  544. {
  545. struct lpfc_iocbq *cmdiocb;
  546. cmdiocb = (struct lpfc_iocbq *) arg;
  547. if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
  548. ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
  549. ndlp->nlp_state = NLP_STE_UNUSED_NODE;
  550. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  551. return ndlp->nlp_state;
  552. }
  553. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  554. return NLP_STE_FREED_NODE;
  555. }
  556. static uint32_t
  557. lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
  558. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  559. {
  560. lpfc_issue_els_logo(phba, ndlp, 0);
  561. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  562. return ndlp->nlp_state;
  563. }
  564. static uint32_t
  565. lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
  566. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  567. {
  568. struct lpfc_iocbq *cmdiocb;
  569. cmdiocb = (struct lpfc_iocbq *) arg;
  570. spin_lock_irq(phba->host->host_lock);
  571. ndlp->nlp_flag |= NLP_LOGO_ACC;
  572. spin_unlock_irq(phba->host->host_lock);
  573. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  574. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  575. return ndlp->nlp_state;
  576. }
  577. static uint32_t
  578. lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
  579. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  580. {
  581. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  582. return NLP_STE_FREED_NODE;
  583. }
  584. static uint32_t
  585. lpfc_device_rm_unused_node(struct lpfc_hba * phba,
  586. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  587. {
  588. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  589. return NLP_STE_FREED_NODE;
  590. }
  591. static uint32_t
  592. lpfc_rcv_plogi_plogi_issue(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  593. void *arg, uint32_t evt)
  594. {
  595. struct lpfc_iocbq *cmdiocb = arg;
  596. struct lpfc_dmabuf *pcmd;
  597. struct serv_parm *sp;
  598. uint32_t *lp;
  599. struct ls_rjt stat;
  600. int port_cmp;
  601. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  602. lp = (uint32_t *) pcmd->virt;
  603. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  604. memset(&stat, 0, sizeof (struct ls_rjt));
  605. /* For a PLOGI, we only accept if our portname is less
  606. * than the remote portname.
  607. */
  608. phba->fc_stat.elsLogiCol++;
  609. port_cmp = memcmp(&phba->fc_portname, &sp->portName,
  610. sizeof (struct lpfc_name));
  611. if (port_cmp >= 0) {
  612. /* Reject this request because the remote node will accept
  613. ours */
  614. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  615. stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
  616. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  617. } else {
  618. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  619. } /* if our portname was less */
  620. return ndlp->nlp_state;
  621. }
  622. static uint32_t
  623. lpfc_rcv_logo_plogi_issue(struct lpfc_hba * phba,
  624. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  625. {
  626. struct lpfc_iocbq *cmdiocb;
  627. cmdiocb = (struct lpfc_iocbq *) arg;
  628. /* software abort outstanding PLOGI */
  629. lpfc_els_abort(phba, ndlp, 1);
  630. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
  631. return ndlp->nlp_state;
  632. }
  633. static uint32_t
  634. lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
  635. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  636. {
  637. struct lpfc_iocbq *cmdiocb;
  638. cmdiocb = (struct lpfc_iocbq *) arg;
  639. /* software abort outstanding PLOGI */
  640. lpfc_els_abort(phba, ndlp, 1);
  641. if (evt == NLP_EVT_RCV_LOGO) {
  642. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  643. } else {
  644. lpfc_issue_els_logo(phba, ndlp, 0);
  645. }
  646. /* Put ndlp in npr list set plogi timer for 1 sec */
  647. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  648. spin_lock_irq(phba->host->host_lock);
  649. ndlp->nlp_flag |= NLP_DELAY_TMO;
  650. spin_unlock_irq(phba->host->host_lock);
  651. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  652. ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
  653. ndlp->nlp_state = NLP_STE_NPR_NODE;
  654. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  655. return ndlp->nlp_state;
  656. }
  657. static uint32_t
  658. lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
  659. struct lpfc_nodelist * ndlp, void *arg,
  660. uint32_t evt)
  661. {
  662. struct lpfc_iocbq *cmdiocb, *rspiocb;
  663. struct lpfc_dmabuf *pcmd, *prsp;
  664. uint32_t *lp;
  665. IOCB_t *irsp;
  666. struct serv_parm *sp;
  667. LPFC_MBOXQ_t *mbox;
  668. cmdiocb = (struct lpfc_iocbq *) arg;
  669. rspiocb = cmdiocb->context_un.rsp_iocb;
  670. if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  671. /* Recovery from PLOGI collision logic */
  672. return ndlp->nlp_state;
  673. }
  674. irsp = &rspiocb->iocb;
  675. if (irsp->ulpStatus)
  676. goto out;
  677. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  678. prsp = list_get_first(&pcmd->list,
  679. struct lpfc_dmabuf,
  680. list);
  681. lp = (uint32_t *) prsp->virt;
  682. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  683. if (!lpfc_check_sparm(phba, ndlp, sp, CLASS3))
  684. goto out;
  685. /* PLOGI chkparm OK */
  686. lpfc_printf_log(phba,
  687. KERN_INFO,
  688. LOG_ELS,
  689. "%d:0121 PLOGI chkparm OK "
  690. "Data: x%x x%x x%x x%x\n",
  691. phba->brd_no,
  692. ndlp->nlp_DID, ndlp->nlp_state,
  693. ndlp->nlp_flag, ndlp->nlp_rpi);
  694. if ((phba->cfg_fcp_class == 2) &&
  695. (sp->cls2.classValid)) {
  696. ndlp->nlp_fcp_info |= CLASS2;
  697. } else {
  698. ndlp->nlp_fcp_info |= CLASS3;
  699. }
  700. ndlp->nlp_class_sup = 0;
  701. if (sp->cls1.classValid)
  702. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  703. if (sp->cls2.classValid)
  704. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  705. if (sp->cls3.classValid)
  706. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  707. if (sp->cls4.classValid)
  708. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  709. ndlp->nlp_maxframe =
  710. ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  711. sp->cmn.bbRcvSizeLsb;
  712. if (!(mbox = mempool_alloc(phba->mbox_mem_pool,
  713. GFP_KERNEL)))
  714. goto out;
  715. lpfc_unreg_rpi(phba, ndlp);
  716. if (lpfc_reg_login
  717. (phba, irsp->un.elsreq64.remoteID,
  718. (uint8_t *) sp, mbox, 0) == 0) {
  719. switch (ndlp->nlp_DID) {
  720. case NameServer_DID:
  721. mbox->mbox_cmpl =
  722. lpfc_mbx_cmpl_ns_reg_login;
  723. break;
  724. case FDMI_DID:
  725. mbox->mbox_cmpl =
  726. lpfc_mbx_cmpl_fdmi_reg_login;
  727. break;
  728. default:
  729. mbox->mbox_cmpl =
  730. lpfc_mbx_cmpl_reg_login;
  731. }
  732. mbox->context2 = ndlp;
  733. if (lpfc_sli_issue_mbox(phba, mbox,
  734. (MBX_NOWAIT | MBX_STOP_IOCB))
  735. != MBX_NOT_FINISHED) {
  736. ndlp->nlp_state =
  737. NLP_STE_REG_LOGIN_ISSUE;
  738. lpfc_nlp_list(phba, ndlp,
  739. NLP_REGLOGIN_LIST);
  740. return ndlp->nlp_state;
  741. }
  742. mempool_free(mbox, phba->mbox_mem_pool);
  743. } else {
  744. mempool_free(mbox, phba->mbox_mem_pool);
  745. }
  746. out:
  747. /* Free this node since the driver cannot login or has the wrong
  748. sparm */
  749. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  750. return NLP_STE_FREED_NODE;
  751. }
  752. static uint32_t
  753. lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
  754. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  755. {
  756. if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  757. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  758. return ndlp->nlp_state;
  759. }
  760. else {
  761. /* software abort outstanding PLOGI */
  762. lpfc_els_abort(phba, ndlp, 1);
  763. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  764. return NLP_STE_FREED_NODE;
  765. }
  766. }
  767. static uint32_t
  768. lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
  769. struct lpfc_nodelist * ndlp, void *arg,
  770. uint32_t evt)
  771. {
  772. /* software abort outstanding PLOGI */
  773. lpfc_els_abort(phba, ndlp, 1);
  774. ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
  775. ndlp->nlp_state = NLP_STE_NPR_NODE;
  776. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  777. spin_lock_irq(phba->host->host_lock);
  778. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  779. spin_unlock_irq(phba->host->host_lock);
  780. return ndlp->nlp_state;
  781. }
  782. static uint32_t
  783. lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
  784. struct lpfc_nodelist * ndlp, void *arg,
  785. uint32_t evt)
  786. {
  787. struct lpfc_iocbq *cmdiocb;
  788. /* software abort outstanding ADISC */
  789. lpfc_els_abort(phba, ndlp, 1);
  790. cmdiocb = (struct lpfc_iocbq *) arg;
  791. if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
  792. return ndlp->nlp_state;
  793. }
  794. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  795. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  796. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  797. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  798. return ndlp->nlp_state;
  799. }
  800. static uint32_t
  801. lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
  802. struct lpfc_nodelist * ndlp, void *arg,
  803. uint32_t evt)
  804. {
  805. struct lpfc_iocbq *cmdiocb;
  806. cmdiocb = (struct lpfc_iocbq *) arg;
  807. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  808. return ndlp->nlp_state;
  809. }
  810. static uint32_t
  811. lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
  812. struct lpfc_nodelist * ndlp, void *arg,
  813. uint32_t evt)
  814. {
  815. struct lpfc_iocbq *cmdiocb;
  816. cmdiocb = (struct lpfc_iocbq *) arg;
  817. /* software abort outstanding ADISC */
  818. lpfc_els_abort(phba, ndlp, 0);
  819. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
  820. return ndlp->nlp_state;
  821. }
  822. static uint32_t
  823. lpfc_rcv_padisc_adisc_issue(struct lpfc_hba * phba,
  824. struct lpfc_nodelist * ndlp, void *arg,
  825. uint32_t evt)
  826. {
  827. struct lpfc_iocbq *cmdiocb;
  828. cmdiocb = (struct lpfc_iocbq *) arg;
  829. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  830. return ndlp->nlp_state;
  831. }
  832. static uint32_t
  833. lpfc_rcv_prlo_adisc_issue(struct lpfc_hba * phba,
  834. struct lpfc_nodelist * ndlp, void *arg,
  835. uint32_t evt)
  836. {
  837. struct lpfc_iocbq *cmdiocb;
  838. cmdiocb = (struct lpfc_iocbq *) arg;
  839. /* Treat like rcv logo */
  840. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_PRLO);
  841. return ndlp->nlp_state;
  842. }
  843. static uint32_t
  844. lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
  845. struct lpfc_nodelist * ndlp, void *arg,
  846. uint32_t evt)
  847. {
  848. struct lpfc_iocbq *cmdiocb, *rspiocb;
  849. IOCB_t *irsp;
  850. ADISC *ap;
  851. cmdiocb = (struct lpfc_iocbq *) arg;
  852. rspiocb = cmdiocb->context_un.rsp_iocb;
  853. ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
  854. irsp = &rspiocb->iocb;
  855. if ((irsp->ulpStatus) ||
  856. (!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
  857. /* 1 sec timeout */
  858. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  859. spin_lock_irq(phba->host->host_lock);
  860. ndlp->nlp_flag |= NLP_DELAY_TMO;
  861. spin_unlock_irq(phba->host->host_lock);
  862. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  863. memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
  864. memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
  865. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  866. ndlp->nlp_state = NLP_STE_NPR_NODE;
  867. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  868. lpfc_unreg_rpi(phba, ndlp);
  869. return ndlp->nlp_state;
  870. }
  871. if (ndlp->nlp_type & NLP_FCP_TARGET) {
  872. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  873. ndlp->nlp_state = NLP_STE_MAPPED_NODE;
  874. lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
  875. } else {
  876. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  877. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  878. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  879. }
  880. return ndlp->nlp_state;
  881. }
  882. static uint32_t
  883. lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
  884. struct lpfc_nodelist * ndlp, void *arg,
  885. uint32_t evt)
  886. {
  887. if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  888. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  889. return ndlp->nlp_state;
  890. }
  891. else {
  892. /* software abort outstanding ADISC */
  893. lpfc_els_abort(phba, ndlp, 1);
  894. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  895. return NLP_STE_FREED_NODE;
  896. }
  897. }
  898. static uint32_t
  899. lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
  900. struct lpfc_nodelist * ndlp, void *arg,
  901. uint32_t evt)
  902. {
  903. /* software abort outstanding ADISC */
  904. lpfc_els_abort(phba, ndlp, 1);
  905. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  906. ndlp->nlp_state = NLP_STE_NPR_NODE;
  907. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  908. spin_lock_irq(phba->host->host_lock);
  909. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  910. ndlp->nlp_flag |= NLP_NPR_ADISC;
  911. spin_unlock_irq(phba->host->host_lock);
  912. return ndlp->nlp_state;
  913. }
  914. static uint32_t
  915. lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
  916. struct lpfc_nodelist * ndlp, void *arg,
  917. uint32_t evt)
  918. {
  919. struct lpfc_iocbq *cmdiocb;
  920. cmdiocb = (struct lpfc_iocbq *) arg;
  921. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  922. return ndlp->nlp_state;
  923. }
  924. static uint32_t
  925. lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
  926. struct lpfc_nodelist * ndlp, void *arg,
  927. uint32_t evt)
  928. {
  929. struct lpfc_iocbq *cmdiocb;
  930. cmdiocb = (struct lpfc_iocbq *) arg;
  931. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  932. return ndlp->nlp_state;
  933. }
  934. static uint32_t
  935. lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
  936. struct lpfc_nodelist * ndlp, void *arg,
  937. uint32_t evt)
  938. {
  939. struct lpfc_iocbq *cmdiocb;
  940. cmdiocb = (struct lpfc_iocbq *) arg;
  941. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
  942. return ndlp->nlp_state;
  943. }
  944. static uint32_t
  945. lpfc_rcv_padisc_reglogin_issue(struct lpfc_hba * phba,
  946. struct lpfc_nodelist * ndlp, void *arg,
  947. uint32_t evt)
  948. {
  949. struct lpfc_iocbq *cmdiocb;
  950. cmdiocb = (struct lpfc_iocbq *) arg;
  951. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  952. return ndlp->nlp_state;
  953. }
  954. static uint32_t
  955. lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
  956. struct lpfc_nodelist * ndlp, void *arg,
  957. uint32_t evt)
  958. {
  959. struct lpfc_iocbq *cmdiocb;
  960. cmdiocb = (struct lpfc_iocbq *) arg;
  961. lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
  962. return ndlp->nlp_state;
  963. }
  964. static uint32_t
  965. lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
  966. struct lpfc_nodelist * ndlp,
  967. void *arg, uint32_t evt)
  968. {
  969. LPFC_MBOXQ_t *pmb;
  970. MAILBOX_t *mb;
  971. uint32_t did;
  972. pmb = (LPFC_MBOXQ_t *) arg;
  973. mb = &pmb->mb;
  974. did = mb->un.varWords[1];
  975. if (mb->mbxStatus) {
  976. /* RegLogin failed */
  977. lpfc_printf_log(phba,
  978. KERN_ERR,
  979. LOG_DISCOVERY,
  980. "%d:0246 RegLogin failed Data: x%x x%x x%x\n",
  981. phba->brd_no,
  982. did, mb->mbxStatus, phba->hba_state);
  983. /*
  984. * If RegLogin failed due to lack of HBA resources do not
  985. * retry discovery.
  986. */
  987. if (mb->mbxStatus == MBXERR_RPI_FULL) {
  988. ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
  989. ndlp->nlp_state = NLP_STE_UNUSED_NODE;
  990. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  991. return ndlp->nlp_state;
  992. }
  993. /* Put ndlp in npr list set plogi timer for 1 sec */
  994. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  995. spin_lock_irq(phba->host->host_lock);
  996. ndlp->nlp_flag |= NLP_DELAY_TMO;
  997. spin_unlock_irq(phba->host->host_lock);
  998. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  999. lpfc_issue_els_logo(phba, ndlp, 0);
  1000. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1001. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1002. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1003. return ndlp->nlp_state;
  1004. }
  1005. ndlp->nlp_rpi = mb->un.varWords[0];
  1006. /* Only if we are not a fabric nport do we issue PRLI */
  1007. if (!(ndlp->nlp_type & NLP_FABRIC)) {
  1008. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1009. ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
  1010. lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
  1011. lpfc_issue_els_prli(phba, ndlp, 0);
  1012. } else {
  1013. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1014. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  1015. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  1016. }
  1017. return ndlp->nlp_state;
  1018. }
  1019. static uint32_t
  1020. lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
  1021. struct lpfc_nodelist * ndlp, void *arg,
  1022. uint32_t evt)
  1023. {
  1024. if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1025. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1026. return ndlp->nlp_state;
  1027. }
  1028. else {
  1029. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1030. return NLP_STE_FREED_NODE;
  1031. }
  1032. }
  1033. static uint32_t
  1034. lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
  1035. struct lpfc_nodelist * ndlp, void *arg,
  1036. uint32_t evt)
  1037. {
  1038. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1039. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1040. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1041. spin_lock_irq(phba->host->host_lock);
  1042. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1043. spin_unlock_irq(phba->host->host_lock);
  1044. return ndlp->nlp_state;
  1045. }
  1046. static uint32_t
  1047. lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
  1048. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1049. {
  1050. struct lpfc_iocbq *cmdiocb;
  1051. cmdiocb = (struct lpfc_iocbq *) arg;
  1052. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  1053. return ndlp->nlp_state;
  1054. }
  1055. static uint32_t
  1056. lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
  1057. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1058. {
  1059. struct lpfc_iocbq *cmdiocb;
  1060. cmdiocb = (struct lpfc_iocbq *) arg;
  1061. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  1062. return ndlp->nlp_state;
  1063. }
  1064. static uint32_t
  1065. lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
  1066. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1067. {
  1068. struct lpfc_iocbq *cmdiocb;
  1069. cmdiocb = (struct lpfc_iocbq *) arg;
  1070. /* Software abort outstanding PRLI before sending acc */
  1071. lpfc_els_abort(phba, ndlp, 1);
  1072. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
  1073. return ndlp->nlp_state;
  1074. }
  1075. static uint32_t
  1076. lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
  1077. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1078. {
  1079. struct lpfc_iocbq *cmdiocb;
  1080. cmdiocb = (struct lpfc_iocbq *) arg;
  1081. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1082. return ndlp->nlp_state;
  1083. }
  1084. /* This routine is envoked when we rcv a PRLO request from a nport
  1085. * we are logged into. We should send back a PRLO rsp setting the
  1086. * appropriate bits.
  1087. * NEXT STATE = PRLI_ISSUE
  1088. */
  1089. static uint32_t
  1090. lpfc_rcv_prlo_prli_issue(struct lpfc_hba * phba,
  1091. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1092. {
  1093. struct lpfc_iocbq *cmdiocb;
  1094. cmdiocb = (struct lpfc_iocbq *) arg;
  1095. lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
  1096. return ndlp->nlp_state;
  1097. }
  1098. static uint32_t
  1099. lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
  1100. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1101. {
  1102. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1103. IOCB_t *irsp;
  1104. PRLI *npr;
  1105. cmdiocb = (struct lpfc_iocbq *) arg;
  1106. rspiocb = cmdiocb->context_un.rsp_iocb;
  1107. npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
  1108. irsp = &rspiocb->iocb;
  1109. if (irsp->ulpStatus) {
  1110. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1111. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  1112. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  1113. return ndlp->nlp_state;
  1114. }
  1115. /* Check out PRLI rsp */
  1116. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  1117. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  1118. if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
  1119. (npr->prliType == PRLI_FCP_TYPE)) {
  1120. if (npr->initiatorFunc)
  1121. ndlp->nlp_type |= NLP_FCP_INITIATOR;
  1122. if (npr->targetFunc)
  1123. ndlp->nlp_type |= NLP_FCP_TARGET;
  1124. if (npr->Retry)
  1125. ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
  1126. }
  1127. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1128. ndlp->nlp_state = NLP_STE_MAPPED_NODE;
  1129. lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
  1130. return ndlp->nlp_state;
  1131. }
  1132. /*! lpfc_device_rm_prli_issue
  1133. *
  1134. * \pre
  1135. * \post
  1136. * \param phba
  1137. * \param ndlp
  1138. * \param arg
  1139. * \param evt
  1140. * \return uint32_t
  1141. *
  1142. * \b Description:
  1143. * This routine is envoked when we a request to remove a nport we are in the
  1144. * process of PRLIing. We should software abort outstanding prli, unreg
  1145. * login, send a logout. We will change node state to UNUSED_NODE, put it
  1146. * on plogi list so it can be freed when LOGO completes.
  1147. *
  1148. */
  1149. static uint32_t
  1150. lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
  1151. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1152. {
  1153. if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1154. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1155. return ndlp->nlp_state;
  1156. }
  1157. else {
  1158. /* software abort outstanding PLOGI */
  1159. lpfc_els_abort(phba, ndlp, 1);
  1160. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1161. return NLP_STE_FREED_NODE;
  1162. }
  1163. }
  1164. /*! lpfc_device_recov_prli_issue
  1165. *
  1166. * \pre
  1167. * \post
  1168. * \param phba
  1169. * \param ndlp
  1170. * \param arg
  1171. * \param evt
  1172. * \return uint32_t
  1173. *
  1174. * \b Description:
  1175. * The routine is envoked when the state of a device is unknown, like
  1176. * during a link down. We should remove the nodelist entry from the
  1177. * unmapped list, issue a UNREG_LOGIN, do a software abort of the
  1178. * outstanding PRLI command, then free the node entry.
  1179. */
  1180. static uint32_t
  1181. lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
  1182. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1183. {
  1184. /* software abort outstanding PRLI */
  1185. lpfc_els_abort(phba, ndlp, 1);
  1186. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1187. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1188. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1189. spin_lock_irq(phba->host->host_lock);
  1190. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1191. spin_unlock_irq(phba->host->host_lock);
  1192. return ndlp->nlp_state;
  1193. }
  1194. static uint32_t
  1195. lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
  1196. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1197. {
  1198. struct lpfc_iocbq *cmdiocb;
  1199. cmdiocb = (struct lpfc_iocbq *) arg;
  1200. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  1201. return ndlp->nlp_state;
  1202. }
  1203. static uint32_t
  1204. lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
  1205. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1206. {
  1207. struct lpfc_iocbq *cmdiocb;
  1208. cmdiocb = (struct lpfc_iocbq *) arg;
  1209. lpfc_rcv_prli(phba, ndlp, cmdiocb);
  1210. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  1211. return ndlp->nlp_state;
  1212. }
  1213. static uint32_t
  1214. lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
  1215. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1216. {
  1217. struct lpfc_iocbq *cmdiocb;
  1218. cmdiocb = (struct lpfc_iocbq *) arg;
  1219. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
  1220. return ndlp->nlp_state;
  1221. }
  1222. static uint32_t
  1223. lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
  1224. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1225. {
  1226. struct lpfc_iocbq *cmdiocb;
  1227. cmdiocb = (struct lpfc_iocbq *) arg;
  1228. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1229. return ndlp->nlp_state;
  1230. }
  1231. static uint32_t
  1232. lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
  1233. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1234. {
  1235. struct lpfc_iocbq *cmdiocb;
  1236. cmdiocb = (struct lpfc_iocbq *) arg;
  1237. lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
  1238. return ndlp->nlp_state;
  1239. }
  1240. static uint32_t
  1241. lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
  1242. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1243. {
  1244. ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
  1245. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1246. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1247. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1248. lpfc_disc_set_adisc(phba, ndlp);
  1249. return ndlp->nlp_state;
  1250. }
  1251. static uint32_t
  1252. lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
  1253. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1254. {
  1255. struct lpfc_iocbq *cmdiocb;
  1256. cmdiocb = (struct lpfc_iocbq *) arg;
  1257. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  1258. return ndlp->nlp_state;
  1259. }
  1260. static uint32_t
  1261. lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
  1262. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1263. {
  1264. struct lpfc_iocbq *cmdiocb;
  1265. cmdiocb = (struct lpfc_iocbq *) arg;
  1266. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  1267. return ndlp->nlp_state;
  1268. }
  1269. static uint32_t
  1270. lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
  1271. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1272. {
  1273. struct lpfc_iocbq *cmdiocb;
  1274. cmdiocb = (struct lpfc_iocbq *) arg;
  1275. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
  1276. return ndlp->nlp_state;
  1277. }
  1278. static uint32_t
  1279. lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
  1280. struct lpfc_nodelist * ndlp, void *arg,
  1281. uint32_t evt)
  1282. {
  1283. struct lpfc_iocbq *cmdiocb;
  1284. cmdiocb = (struct lpfc_iocbq *) arg;
  1285. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1286. return ndlp->nlp_state;
  1287. }
  1288. static uint32_t
  1289. lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
  1290. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1291. {
  1292. struct lpfc_iocbq *cmdiocb;
  1293. cmdiocb = (struct lpfc_iocbq *) arg;
  1294. /* flush the target */
  1295. spin_lock_irq(phba->host->host_lock);
  1296. lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
  1297. ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
  1298. spin_unlock_irq(phba->host->host_lock);
  1299. /* Treat like rcv logo */
  1300. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_PRLO);
  1301. return ndlp->nlp_state;
  1302. }
  1303. static uint32_t
  1304. lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
  1305. struct lpfc_nodelist * ndlp, void *arg,
  1306. uint32_t evt)
  1307. {
  1308. ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
  1309. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1310. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1311. spin_lock_irq(phba->host->host_lock);
  1312. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1313. spin_unlock_irq(phba->host->host_lock);
  1314. lpfc_disc_set_adisc(phba, ndlp);
  1315. return ndlp->nlp_state;
  1316. }
  1317. static uint32_t
  1318. lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
  1319. struct lpfc_nodelist * ndlp, void *arg,
  1320. uint32_t evt)
  1321. {
  1322. struct lpfc_iocbq *cmdiocb;
  1323. cmdiocb = (struct lpfc_iocbq *) arg;
  1324. /* Ignore PLOGI if we have an outstanding LOGO */
  1325. if (ndlp->nlp_flag & NLP_LOGO_SND) {
  1326. return ndlp->nlp_state;
  1327. }
  1328. if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
  1329. spin_lock_irq(phba->host->host_lock);
  1330. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1331. spin_unlock_irq(phba->host->host_lock);
  1332. return ndlp->nlp_state;
  1333. }
  1334. /* send PLOGI immediately, move to PLOGI issue state */
  1335. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1336. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1337. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  1338. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  1339. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  1340. }
  1341. return ndlp->nlp_state;
  1342. }
  1343. static uint32_t
  1344. lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
  1345. struct lpfc_nodelist * ndlp, void *arg,
  1346. uint32_t evt)
  1347. {
  1348. struct lpfc_iocbq *cmdiocb;
  1349. struct ls_rjt stat;
  1350. cmdiocb = (struct lpfc_iocbq *) arg;
  1351. memset(&stat, 0, sizeof (struct ls_rjt));
  1352. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1353. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1354. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  1355. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1356. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  1357. spin_lock_irq(phba->host->host_lock);
  1358. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1359. spin_unlock_irq(phba->host->host_lock);
  1360. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1361. ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
  1362. lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
  1363. lpfc_issue_els_adisc(phba, ndlp, 0);
  1364. } else {
  1365. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1366. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  1367. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  1368. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  1369. }
  1370. }
  1371. return ndlp->nlp_state;
  1372. }
  1373. static uint32_t
  1374. lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
  1375. struct lpfc_nodelist * ndlp, void *arg,
  1376. uint32_t evt)
  1377. {
  1378. struct lpfc_iocbq *cmdiocb;
  1379. cmdiocb = (struct lpfc_iocbq *) arg;
  1380. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
  1381. return ndlp->nlp_state;
  1382. }
  1383. static uint32_t
  1384. lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
  1385. struct lpfc_nodelist * ndlp, void *arg,
  1386. uint32_t evt)
  1387. {
  1388. struct lpfc_iocbq *cmdiocb;
  1389. cmdiocb = (struct lpfc_iocbq *) arg;
  1390. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1391. /*
  1392. * Do not start discovery if discovery is about to start
  1393. * or discovery in progress for this node. Starting discovery
  1394. * here will affect the counting of discovery threads.
  1395. */
  1396. if ((!(ndlp->nlp_flag & NLP_DELAY_TMO)) &&
  1397. (ndlp->nlp_flag & NLP_NPR_2B_DISC)){
  1398. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  1399. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1400. ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
  1401. lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
  1402. lpfc_issue_els_adisc(phba, ndlp, 0);
  1403. } else {
  1404. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1405. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  1406. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  1407. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  1408. }
  1409. }
  1410. return ndlp->nlp_state;
  1411. }
  1412. static uint32_t
  1413. lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
  1414. struct lpfc_nodelist * ndlp, void *arg,
  1415. uint32_t evt)
  1416. {
  1417. struct lpfc_iocbq *cmdiocb;
  1418. cmdiocb = (struct lpfc_iocbq *) arg;
  1419. spin_lock_irq(phba->host->host_lock);
  1420. ndlp->nlp_flag |= NLP_LOGO_ACC;
  1421. spin_unlock_irq(phba->host->host_lock);
  1422. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  1423. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1424. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  1425. spin_lock_irq(phba->host->host_lock);
  1426. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1427. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1428. spin_unlock_irq(phba->host->host_lock);
  1429. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  1430. } else {
  1431. spin_lock_irq(phba->host->host_lock);
  1432. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1433. spin_unlock_irq(phba->host->host_lock);
  1434. }
  1435. return ndlp->nlp_state;
  1436. }
  1437. static uint32_t
  1438. lpfc_cmpl_plogi_npr_node(struct lpfc_hba * phba,
  1439. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1440. {
  1441. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1442. IOCB_t *irsp;
  1443. cmdiocb = (struct lpfc_iocbq *) arg;
  1444. rspiocb = cmdiocb->context_un.rsp_iocb;
  1445. irsp = &rspiocb->iocb;
  1446. if (irsp->ulpStatus) {
  1447. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1448. return NLP_STE_FREED_NODE;
  1449. }
  1450. return ndlp->nlp_state;
  1451. }
  1452. static uint32_t
  1453. lpfc_cmpl_prli_npr_node(struct lpfc_hba * phba,
  1454. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1455. {
  1456. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1457. IOCB_t *irsp;
  1458. cmdiocb = (struct lpfc_iocbq *) arg;
  1459. rspiocb = cmdiocb->context_un.rsp_iocb;
  1460. irsp = &rspiocb->iocb;
  1461. if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
  1462. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1463. return NLP_STE_FREED_NODE;
  1464. }
  1465. return ndlp->nlp_state;
  1466. }
  1467. static uint32_t
  1468. lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
  1469. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1470. {
  1471. lpfc_unreg_rpi(phba, ndlp);
  1472. /* This routine does nothing, just return the current state */
  1473. return ndlp->nlp_state;
  1474. }
  1475. static uint32_t
  1476. lpfc_cmpl_adisc_npr_node(struct lpfc_hba * phba,
  1477. struct lpfc_nodelist * ndlp, void *arg,
  1478. uint32_t evt)
  1479. {
  1480. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1481. IOCB_t *irsp;
  1482. cmdiocb = (struct lpfc_iocbq *) arg;
  1483. rspiocb = cmdiocb->context_un.rsp_iocb;
  1484. irsp = &rspiocb->iocb;
  1485. if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
  1486. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1487. return NLP_STE_FREED_NODE;
  1488. }
  1489. return ndlp->nlp_state;
  1490. }
  1491. static uint32_t
  1492. lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
  1493. struct lpfc_nodelist * ndlp, void *arg,
  1494. uint32_t evt)
  1495. {
  1496. LPFC_MBOXQ_t *pmb;
  1497. MAILBOX_t *mb;
  1498. pmb = (LPFC_MBOXQ_t *) arg;
  1499. mb = &pmb->mb;
  1500. if (!mb->mbxStatus)
  1501. ndlp->nlp_rpi = mb->un.varWords[0];
  1502. else {
  1503. if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
  1504. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1505. return NLP_STE_FREED_NODE;
  1506. }
  1507. }
  1508. return ndlp->nlp_state;
  1509. }
  1510. static uint32_t
  1511. lpfc_device_rm_npr_node(struct lpfc_hba * phba,
  1512. struct lpfc_nodelist * ndlp, void *arg,
  1513. uint32_t evt)
  1514. {
  1515. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1516. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1517. return ndlp->nlp_state;
  1518. }
  1519. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1520. return NLP_STE_FREED_NODE;
  1521. }
  1522. static uint32_t
  1523. lpfc_device_recov_npr_node(struct lpfc_hba * phba,
  1524. struct lpfc_nodelist * ndlp, void *arg,
  1525. uint32_t evt)
  1526. {
  1527. spin_lock_irq(phba->host->host_lock);
  1528. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1529. spin_unlock_irq(phba->host->host_lock);
  1530. if (ndlp->nlp_flag & NLP_DELAY_TMO) {
  1531. lpfc_cancel_retry_delay_tmo(phba, ndlp);
  1532. }
  1533. return ndlp->nlp_state;
  1534. }
  1535. /* This next section defines the NPort Discovery State Machine */
  1536. /* There are 4 different double linked lists nodelist entries can reside on.
  1537. * The plogi list and adisc list are used when Link Up discovery or RSCN
  1538. * processing is needed. Each list holds the nodes that we will send PLOGI
  1539. * or ADISC on. These lists will keep track of what nodes will be effected
  1540. * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
  1541. * The unmapped_list will contain all nodes that we have successfully logged
  1542. * into at the Fibre Channel level. The mapped_list will contain all nodes
  1543. * that are mapped FCP targets.
  1544. */
  1545. /*
  1546. * The bind list is a list of undiscovered (potentially non-existent) nodes
  1547. * that we have saved binding information on. This information is used when
  1548. * nodes transition from the unmapped to the mapped list.
  1549. */
  1550. /* For UNUSED_NODE state, the node has just been allocated .
  1551. * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
  1552. * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
  1553. * and put on the unmapped list. For ADISC processing, the node is taken off
  1554. * the ADISC list and placed on either the mapped or unmapped list (depending
  1555. * on its previous state). Once on the unmapped list, a PRLI is issued and the
  1556. * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
  1557. * changed to UNMAPPED_NODE. If the completion indicates a mapped
  1558. * node, the node is taken off the unmapped list. The binding list is checked
  1559. * for a valid binding, or a binding is automatically assigned. If binding
  1560. * assignment is unsuccessful, the node is left on the unmapped list. If
  1561. * binding assignment is successful, the associated binding list entry (if
  1562. * any) is removed, and the node is placed on the mapped list.
  1563. */
  1564. /*
  1565. * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
  1566. * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
  1567. * expire, all effected nodes will receive a DEVICE_RM event.
  1568. */
  1569. /*
  1570. * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
  1571. * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
  1572. * check, additional nodes may be added or removed (via DEVICE_RM) to / from
  1573. * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
  1574. * we will first process the ADISC list. 32 entries are processed initially and
  1575. * ADISC is initited for each one. Completions / Events for each node are
  1576. * funnelled thru the state machine. As each node finishes ADISC processing, it
  1577. * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
  1578. * waiting, and the ADISC list count is identically 0, then we are done. For
  1579. * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
  1580. * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
  1581. * list. 32 entries are processed initially and PLOGI is initited for each one.
  1582. * Completions / Events for each node are funnelled thru the state machine. As
  1583. * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
  1584. * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
  1585. * indentically 0, then we are done. We have now completed discovery / RSCN
  1586. * handling. Upon completion, ALL nodes should be on either the mapped or
  1587. * unmapped lists.
  1588. */
  1589. static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
  1590. (struct lpfc_hba *, struct lpfc_nodelist *, void *, uint32_t) = {
  1591. /* Action routine Event Current State */
  1592. lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
  1593. lpfc_rcv_els_unused_node, /* RCV_PRLI */
  1594. lpfc_rcv_logo_unused_node, /* RCV_LOGO */
  1595. lpfc_rcv_els_unused_node, /* RCV_ADISC */
  1596. lpfc_rcv_els_unused_node, /* RCV_PDISC */
  1597. lpfc_rcv_els_unused_node, /* RCV_PRLO */
  1598. lpfc_disc_illegal, /* CMPL_PLOGI */
  1599. lpfc_disc_illegal, /* CMPL_PRLI */
  1600. lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
  1601. lpfc_disc_illegal, /* CMPL_ADISC */
  1602. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1603. lpfc_device_rm_unused_node, /* DEVICE_RM */
  1604. lpfc_disc_illegal, /* DEVICE_RECOVERY */
  1605. lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
  1606. lpfc_rcv_els_plogi_issue, /* RCV_PRLI */
  1607. lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
  1608. lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
  1609. lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
  1610. lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
  1611. lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
  1612. lpfc_disc_illegal, /* CMPL_PRLI */
  1613. lpfc_disc_illegal, /* CMPL_LOGO */
  1614. lpfc_disc_illegal, /* CMPL_ADISC */
  1615. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1616. lpfc_device_rm_plogi_issue, /* DEVICE_RM */
  1617. lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
  1618. lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
  1619. lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
  1620. lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
  1621. lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
  1622. lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
  1623. lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
  1624. lpfc_disc_illegal, /* CMPL_PLOGI */
  1625. lpfc_disc_illegal, /* CMPL_PRLI */
  1626. lpfc_disc_illegal, /* CMPL_LOGO */
  1627. lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
  1628. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1629. lpfc_device_rm_adisc_issue, /* DEVICE_RM */
  1630. lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
  1631. lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
  1632. lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
  1633. lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
  1634. lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
  1635. lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
  1636. lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
  1637. lpfc_disc_illegal, /* CMPL_PLOGI */
  1638. lpfc_disc_illegal, /* CMPL_PRLI */
  1639. lpfc_disc_illegal, /* CMPL_LOGO */
  1640. lpfc_disc_illegal, /* CMPL_ADISC */
  1641. lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
  1642. lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
  1643. lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
  1644. lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
  1645. lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
  1646. lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
  1647. lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
  1648. lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
  1649. lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
  1650. lpfc_disc_illegal, /* CMPL_PLOGI */
  1651. lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
  1652. lpfc_disc_illegal, /* CMPL_LOGO */
  1653. lpfc_disc_illegal, /* CMPL_ADISC */
  1654. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1655. lpfc_device_rm_prli_issue, /* DEVICE_RM */
  1656. lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
  1657. lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
  1658. lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
  1659. lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
  1660. lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
  1661. lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
  1662. lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
  1663. lpfc_disc_illegal, /* CMPL_PLOGI */
  1664. lpfc_disc_illegal, /* CMPL_PRLI */
  1665. lpfc_disc_illegal, /* CMPL_LOGO */
  1666. lpfc_disc_illegal, /* CMPL_ADISC */
  1667. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1668. lpfc_disc_illegal, /* DEVICE_RM */
  1669. lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
  1670. lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
  1671. lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
  1672. lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
  1673. lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
  1674. lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
  1675. lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
  1676. lpfc_disc_illegal, /* CMPL_PLOGI */
  1677. lpfc_disc_illegal, /* CMPL_PRLI */
  1678. lpfc_disc_illegal, /* CMPL_LOGO */
  1679. lpfc_disc_illegal, /* CMPL_ADISC */
  1680. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1681. lpfc_disc_illegal, /* DEVICE_RM */
  1682. lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
  1683. lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
  1684. lpfc_rcv_prli_npr_node, /* RCV_PRLI */
  1685. lpfc_rcv_logo_npr_node, /* RCV_LOGO */
  1686. lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
  1687. lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
  1688. lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
  1689. lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
  1690. lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
  1691. lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
  1692. lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
  1693. lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
  1694. lpfc_device_rm_npr_node, /* DEVICE_RM */
  1695. lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
  1696. };
  1697. int
  1698. lpfc_disc_state_machine(struct lpfc_hba * phba,
  1699. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1700. {
  1701. uint32_t cur_state, rc;
  1702. uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
  1703. uint32_t);
  1704. ndlp->nlp_disc_refcnt++;
  1705. cur_state = ndlp->nlp_state;
  1706. /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
  1707. lpfc_printf_log(phba,
  1708. KERN_INFO,
  1709. LOG_DISCOVERY,
  1710. "%d:0211 DSM in event x%x on NPort x%x in state %d "
  1711. "Data: x%x\n",
  1712. phba->brd_no,
  1713. evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
  1714. func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
  1715. rc = (func) (phba, ndlp, arg, evt);
  1716. /* DSM out state <rc> on NPort <nlp_DID> */
  1717. lpfc_printf_log(phba,
  1718. KERN_INFO,
  1719. LOG_DISCOVERY,
  1720. "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
  1721. phba->brd_no,
  1722. rc, ndlp->nlp_DID, ndlp->nlp_flag);
  1723. ndlp->nlp_disc_refcnt--;
  1724. /* Check to see if ndlp removal is deferred */
  1725. if ((ndlp->nlp_disc_refcnt == 0)
  1726. && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
  1727. spin_lock_irq(phba->host->host_lock);
  1728. ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
  1729. spin_unlock_irq(phba->host->host_lock);
  1730. lpfc_nlp_remove(phba, ndlp);
  1731. return NLP_STE_FREED_NODE;
  1732. }
  1733. if (rc == NLP_STE_FREED_NODE)
  1734. return NLP_STE_FREED_NODE;
  1735. return rc;
  1736. }