lpfc_nportdisc.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004
  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, *mp;
  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. mp = (struct lpfc_dmabuf *)mbox->context1;
  743. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  744. kfree(mp);
  745. mempool_free(mbox, phba->mbox_mem_pool);
  746. } else {
  747. mempool_free(mbox, phba->mbox_mem_pool);
  748. }
  749. out:
  750. /* Free this node since the driver cannot login or has the wrong
  751. sparm */
  752. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  753. return NLP_STE_FREED_NODE;
  754. }
  755. static uint32_t
  756. lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
  757. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  758. {
  759. if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  760. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  761. return ndlp->nlp_state;
  762. }
  763. else {
  764. /* software abort outstanding PLOGI */
  765. lpfc_els_abort(phba, ndlp, 1);
  766. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  767. return NLP_STE_FREED_NODE;
  768. }
  769. }
  770. static uint32_t
  771. lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
  772. struct lpfc_nodelist * ndlp, void *arg,
  773. uint32_t evt)
  774. {
  775. /* software abort outstanding PLOGI */
  776. lpfc_els_abort(phba, ndlp, 1);
  777. ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
  778. ndlp->nlp_state = NLP_STE_NPR_NODE;
  779. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  780. spin_lock_irq(phba->host->host_lock);
  781. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  782. spin_unlock_irq(phba->host->host_lock);
  783. return ndlp->nlp_state;
  784. }
  785. static uint32_t
  786. lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
  787. struct lpfc_nodelist * ndlp, void *arg,
  788. uint32_t evt)
  789. {
  790. struct lpfc_iocbq *cmdiocb;
  791. /* software abort outstanding ADISC */
  792. lpfc_els_abort(phba, ndlp, 1);
  793. cmdiocb = (struct lpfc_iocbq *) arg;
  794. if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
  795. return ndlp->nlp_state;
  796. }
  797. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  798. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  799. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  800. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  801. return ndlp->nlp_state;
  802. }
  803. static uint32_t
  804. lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
  805. struct lpfc_nodelist * ndlp, void *arg,
  806. uint32_t evt)
  807. {
  808. struct lpfc_iocbq *cmdiocb;
  809. cmdiocb = (struct lpfc_iocbq *) arg;
  810. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  811. return ndlp->nlp_state;
  812. }
  813. static uint32_t
  814. lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
  815. struct lpfc_nodelist * ndlp, void *arg,
  816. uint32_t evt)
  817. {
  818. struct lpfc_iocbq *cmdiocb;
  819. cmdiocb = (struct lpfc_iocbq *) arg;
  820. /* software abort outstanding ADISC */
  821. lpfc_els_abort(phba, ndlp, 0);
  822. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
  823. return ndlp->nlp_state;
  824. }
  825. static uint32_t
  826. lpfc_rcv_padisc_adisc_issue(struct lpfc_hba * phba,
  827. struct lpfc_nodelist * ndlp, void *arg,
  828. uint32_t evt)
  829. {
  830. struct lpfc_iocbq *cmdiocb;
  831. cmdiocb = (struct lpfc_iocbq *) arg;
  832. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  833. return ndlp->nlp_state;
  834. }
  835. static uint32_t
  836. lpfc_rcv_prlo_adisc_issue(struct lpfc_hba * phba,
  837. struct lpfc_nodelist * ndlp, void *arg,
  838. uint32_t evt)
  839. {
  840. struct lpfc_iocbq *cmdiocb;
  841. cmdiocb = (struct lpfc_iocbq *) arg;
  842. /* Treat like rcv logo */
  843. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_PRLO);
  844. return ndlp->nlp_state;
  845. }
  846. static uint32_t
  847. lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
  848. struct lpfc_nodelist * ndlp, void *arg,
  849. uint32_t evt)
  850. {
  851. struct lpfc_iocbq *cmdiocb, *rspiocb;
  852. IOCB_t *irsp;
  853. ADISC *ap;
  854. cmdiocb = (struct lpfc_iocbq *) arg;
  855. rspiocb = cmdiocb->context_un.rsp_iocb;
  856. ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
  857. irsp = &rspiocb->iocb;
  858. if ((irsp->ulpStatus) ||
  859. (!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
  860. /* 1 sec timeout */
  861. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  862. spin_lock_irq(phba->host->host_lock);
  863. ndlp->nlp_flag |= NLP_DELAY_TMO;
  864. spin_unlock_irq(phba->host->host_lock);
  865. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  866. memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
  867. memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
  868. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  869. ndlp->nlp_state = NLP_STE_NPR_NODE;
  870. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  871. lpfc_unreg_rpi(phba, ndlp);
  872. return ndlp->nlp_state;
  873. }
  874. if (ndlp->nlp_type & NLP_FCP_TARGET) {
  875. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  876. ndlp->nlp_state = NLP_STE_MAPPED_NODE;
  877. lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
  878. } else {
  879. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  880. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  881. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  882. }
  883. return ndlp->nlp_state;
  884. }
  885. static uint32_t
  886. lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
  887. struct lpfc_nodelist * ndlp, void *arg,
  888. uint32_t evt)
  889. {
  890. if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  891. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  892. return ndlp->nlp_state;
  893. }
  894. else {
  895. /* software abort outstanding ADISC */
  896. lpfc_els_abort(phba, ndlp, 1);
  897. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  898. return NLP_STE_FREED_NODE;
  899. }
  900. }
  901. static uint32_t
  902. lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
  903. struct lpfc_nodelist * ndlp, void *arg,
  904. uint32_t evt)
  905. {
  906. /* software abort outstanding ADISC */
  907. lpfc_els_abort(phba, ndlp, 1);
  908. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  909. ndlp->nlp_state = NLP_STE_NPR_NODE;
  910. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  911. spin_lock_irq(phba->host->host_lock);
  912. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  913. ndlp->nlp_flag |= NLP_NPR_ADISC;
  914. spin_unlock_irq(phba->host->host_lock);
  915. return ndlp->nlp_state;
  916. }
  917. static uint32_t
  918. lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
  919. struct lpfc_nodelist * ndlp, void *arg,
  920. uint32_t evt)
  921. {
  922. struct lpfc_iocbq *cmdiocb;
  923. cmdiocb = (struct lpfc_iocbq *) arg;
  924. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  925. return ndlp->nlp_state;
  926. }
  927. static uint32_t
  928. lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
  929. struct lpfc_nodelist * ndlp, void *arg,
  930. uint32_t evt)
  931. {
  932. struct lpfc_iocbq *cmdiocb;
  933. cmdiocb = (struct lpfc_iocbq *) arg;
  934. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  935. return ndlp->nlp_state;
  936. }
  937. static uint32_t
  938. lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
  939. struct lpfc_nodelist * ndlp, void *arg,
  940. uint32_t evt)
  941. {
  942. struct lpfc_iocbq *cmdiocb;
  943. cmdiocb = (struct lpfc_iocbq *) arg;
  944. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
  945. return ndlp->nlp_state;
  946. }
  947. static uint32_t
  948. lpfc_rcv_padisc_reglogin_issue(struct lpfc_hba * phba,
  949. struct lpfc_nodelist * ndlp, void *arg,
  950. uint32_t evt)
  951. {
  952. struct lpfc_iocbq *cmdiocb;
  953. cmdiocb = (struct lpfc_iocbq *) arg;
  954. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  955. return ndlp->nlp_state;
  956. }
  957. static uint32_t
  958. lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
  959. struct lpfc_nodelist * ndlp, void *arg,
  960. uint32_t evt)
  961. {
  962. struct lpfc_iocbq *cmdiocb;
  963. cmdiocb = (struct lpfc_iocbq *) arg;
  964. lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
  965. return ndlp->nlp_state;
  966. }
  967. static uint32_t
  968. lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
  969. struct lpfc_nodelist * ndlp,
  970. void *arg, uint32_t evt)
  971. {
  972. LPFC_MBOXQ_t *pmb;
  973. MAILBOX_t *mb;
  974. uint32_t did;
  975. pmb = (LPFC_MBOXQ_t *) arg;
  976. mb = &pmb->mb;
  977. did = mb->un.varWords[1];
  978. if (mb->mbxStatus) {
  979. /* RegLogin failed */
  980. lpfc_printf_log(phba,
  981. KERN_ERR,
  982. LOG_DISCOVERY,
  983. "%d:0246 RegLogin failed Data: x%x x%x x%x\n",
  984. phba->brd_no,
  985. did, mb->mbxStatus, phba->hba_state);
  986. /*
  987. * If RegLogin failed due to lack of HBA resources do not
  988. * retry discovery.
  989. */
  990. if (mb->mbxStatus == MBXERR_RPI_FULL) {
  991. ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
  992. ndlp->nlp_state = NLP_STE_UNUSED_NODE;
  993. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  994. return ndlp->nlp_state;
  995. }
  996. /* Put ndlp in npr list set plogi timer for 1 sec */
  997. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  998. spin_lock_irq(phba->host->host_lock);
  999. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1000. spin_unlock_irq(phba->host->host_lock);
  1001. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  1002. lpfc_issue_els_logo(phba, ndlp, 0);
  1003. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1004. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1005. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1006. return ndlp->nlp_state;
  1007. }
  1008. ndlp->nlp_rpi = mb->un.varWords[0];
  1009. /* Only if we are not a fabric nport do we issue PRLI */
  1010. if (!(ndlp->nlp_type & NLP_FABRIC)) {
  1011. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1012. ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
  1013. lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
  1014. lpfc_issue_els_prli(phba, ndlp, 0);
  1015. } else {
  1016. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1017. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  1018. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  1019. }
  1020. return ndlp->nlp_state;
  1021. }
  1022. static uint32_t
  1023. lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
  1024. struct lpfc_nodelist * ndlp, void *arg,
  1025. uint32_t evt)
  1026. {
  1027. if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1028. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1029. return ndlp->nlp_state;
  1030. }
  1031. else {
  1032. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1033. return NLP_STE_FREED_NODE;
  1034. }
  1035. }
  1036. static uint32_t
  1037. lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
  1038. struct lpfc_nodelist * ndlp, void *arg,
  1039. uint32_t evt)
  1040. {
  1041. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1042. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1043. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1044. spin_lock_irq(phba->host->host_lock);
  1045. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1046. spin_unlock_irq(phba->host->host_lock);
  1047. return ndlp->nlp_state;
  1048. }
  1049. static uint32_t
  1050. lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
  1051. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1052. {
  1053. struct lpfc_iocbq *cmdiocb;
  1054. cmdiocb = (struct lpfc_iocbq *) arg;
  1055. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  1056. return ndlp->nlp_state;
  1057. }
  1058. static uint32_t
  1059. lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
  1060. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1061. {
  1062. struct lpfc_iocbq *cmdiocb;
  1063. cmdiocb = (struct lpfc_iocbq *) arg;
  1064. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  1065. return ndlp->nlp_state;
  1066. }
  1067. static uint32_t
  1068. lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
  1069. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1070. {
  1071. struct lpfc_iocbq *cmdiocb;
  1072. cmdiocb = (struct lpfc_iocbq *) arg;
  1073. /* Software abort outstanding PRLI before sending acc */
  1074. lpfc_els_abort(phba, ndlp, 1);
  1075. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
  1076. return ndlp->nlp_state;
  1077. }
  1078. static uint32_t
  1079. lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
  1080. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1081. {
  1082. struct lpfc_iocbq *cmdiocb;
  1083. cmdiocb = (struct lpfc_iocbq *) arg;
  1084. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1085. return ndlp->nlp_state;
  1086. }
  1087. /* This routine is envoked when we rcv a PRLO request from a nport
  1088. * we are logged into. We should send back a PRLO rsp setting the
  1089. * appropriate bits.
  1090. * NEXT STATE = PRLI_ISSUE
  1091. */
  1092. static uint32_t
  1093. lpfc_rcv_prlo_prli_issue(struct lpfc_hba * phba,
  1094. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1095. {
  1096. struct lpfc_iocbq *cmdiocb;
  1097. cmdiocb = (struct lpfc_iocbq *) arg;
  1098. lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
  1099. return ndlp->nlp_state;
  1100. }
  1101. static uint32_t
  1102. lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
  1103. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1104. {
  1105. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1106. IOCB_t *irsp;
  1107. PRLI *npr;
  1108. cmdiocb = (struct lpfc_iocbq *) arg;
  1109. rspiocb = cmdiocb->context_un.rsp_iocb;
  1110. npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
  1111. irsp = &rspiocb->iocb;
  1112. if (irsp->ulpStatus) {
  1113. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1114. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  1115. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  1116. return ndlp->nlp_state;
  1117. }
  1118. /* Check out PRLI rsp */
  1119. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  1120. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  1121. if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
  1122. (npr->prliType == PRLI_FCP_TYPE)) {
  1123. if (npr->initiatorFunc)
  1124. ndlp->nlp_type |= NLP_FCP_INITIATOR;
  1125. if (npr->targetFunc)
  1126. ndlp->nlp_type |= NLP_FCP_TARGET;
  1127. if (npr->Retry)
  1128. ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
  1129. }
  1130. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1131. ndlp->nlp_state = NLP_STE_MAPPED_NODE;
  1132. lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
  1133. return ndlp->nlp_state;
  1134. }
  1135. /*! lpfc_device_rm_prli_issue
  1136. *
  1137. * \pre
  1138. * \post
  1139. * \param phba
  1140. * \param ndlp
  1141. * \param arg
  1142. * \param evt
  1143. * \return uint32_t
  1144. *
  1145. * \b Description:
  1146. * This routine is envoked when we a request to remove a nport we are in the
  1147. * process of PRLIing. We should software abort outstanding prli, unreg
  1148. * login, send a logout. We will change node state to UNUSED_NODE, put it
  1149. * on plogi list so it can be freed when LOGO completes.
  1150. *
  1151. */
  1152. static uint32_t
  1153. lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
  1154. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1155. {
  1156. if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1157. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1158. return ndlp->nlp_state;
  1159. }
  1160. else {
  1161. /* software abort outstanding PLOGI */
  1162. lpfc_els_abort(phba, ndlp, 1);
  1163. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1164. return NLP_STE_FREED_NODE;
  1165. }
  1166. }
  1167. /*! lpfc_device_recov_prli_issue
  1168. *
  1169. * \pre
  1170. * \post
  1171. * \param phba
  1172. * \param ndlp
  1173. * \param arg
  1174. * \param evt
  1175. * \return uint32_t
  1176. *
  1177. * \b Description:
  1178. * The routine is envoked when the state of a device is unknown, like
  1179. * during a link down. We should remove the nodelist entry from the
  1180. * unmapped list, issue a UNREG_LOGIN, do a software abort of the
  1181. * outstanding PRLI command, then free the node entry.
  1182. */
  1183. static uint32_t
  1184. lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
  1185. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1186. {
  1187. /* software abort outstanding PRLI */
  1188. lpfc_els_abort(phba, ndlp, 1);
  1189. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1190. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1191. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1192. spin_lock_irq(phba->host->host_lock);
  1193. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1194. spin_unlock_irq(phba->host->host_lock);
  1195. return ndlp->nlp_state;
  1196. }
  1197. static uint32_t
  1198. lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
  1199. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1200. {
  1201. struct lpfc_iocbq *cmdiocb;
  1202. cmdiocb = (struct lpfc_iocbq *) arg;
  1203. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  1204. return ndlp->nlp_state;
  1205. }
  1206. static uint32_t
  1207. lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
  1208. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1209. {
  1210. struct lpfc_iocbq *cmdiocb;
  1211. cmdiocb = (struct lpfc_iocbq *) arg;
  1212. lpfc_rcv_prli(phba, ndlp, cmdiocb);
  1213. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  1214. return ndlp->nlp_state;
  1215. }
  1216. static uint32_t
  1217. lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
  1218. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1219. {
  1220. struct lpfc_iocbq *cmdiocb;
  1221. cmdiocb = (struct lpfc_iocbq *) arg;
  1222. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
  1223. return ndlp->nlp_state;
  1224. }
  1225. static uint32_t
  1226. lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
  1227. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1228. {
  1229. struct lpfc_iocbq *cmdiocb;
  1230. cmdiocb = (struct lpfc_iocbq *) arg;
  1231. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1232. return ndlp->nlp_state;
  1233. }
  1234. static uint32_t
  1235. lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
  1236. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1237. {
  1238. struct lpfc_iocbq *cmdiocb;
  1239. cmdiocb = (struct lpfc_iocbq *) arg;
  1240. lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
  1241. return ndlp->nlp_state;
  1242. }
  1243. static uint32_t
  1244. lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
  1245. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1246. {
  1247. ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
  1248. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1249. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1250. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1251. lpfc_disc_set_adisc(phba, ndlp);
  1252. return ndlp->nlp_state;
  1253. }
  1254. static uint32_t
  1255. lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
  1256. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1257. {
  1258. struct lpfc_iocbq *cmdiocb;
  1259. cmdiocb = (struct lpfc_iocbq *) arg;
  1260. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  1261. return ndlp->nlp_state;
  1262. }
  1263. static uint32_t
  1264. lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
  1265. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1266. {
  1267. struct lpfc_iocbq *cmdiocb;
  1268. cmdiocb = (struct lpfc_iocbq *) arg;
  1269. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  1270. return ndlp->nlp_state;
  1271. }
  1272. static uint32_t
  1273. lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
  1274. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1275. {
  1276. struct lpfc_iocbq *cmdiocb;
  1277. cmdiocb = (struct lpfc_iocbq *) arg;
  1278. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
  1279. return ndlp->nlp_state;
  1280. }
  1281. static uint32_t
  1282. lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
  1283. struct lpfc_nodelist * ndlp, void *arg,
  1284. uint32_t evt)
  1285. {
  1286. struct lpfc_iocbq *cmdiocb;
  1287. cmdiocb = (struct lpfc_iocbq *) arg;
  1288. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1289. return ndlp->nlp_state;
  1290. }
  1291. static uint32_t
  1292. lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
  1293. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1294. {
  1295. struct lpfc_iocbq *cmdiocb;
  1296. cmdiocb = (struct lpfc_iocbq *) arg;
  1297. /* flush the target */
  1298. spin_lock_irq(phba->host->host_lock);
  1299. lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
  1300. ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
  1301. spin_unlock_irq(phba->host->host_lock);
  1302. /* Treat like rcv logo */
  1303. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_PRLO);
  1304. return ndlp->nlp_state;
  1305. }
  1306. static uint32_t
  1307. lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
  1308. struct lpfc_nodelist * ndlp, void *arg,
  1309. uint32_t evt)
  1310. {
  1311. ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
  1312. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1313. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1314. spin_lock_irq(phba->host->host_lock);
  1315. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1316. spin_unlock_irq(phba->host->host_lock);
  1317. lpfc_disc_set_adisc(phba, ndlp);
  1318. return ndlp->nlp_state;
  1319. }
  1320. static uint32_t
  1321. lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
  1322. struct lpfc_nodelist * ndlp, void *arg,
  1323. uint32_t evt)
  1324. {
  1325. struct lpfc_iocbq *cmdiocb;
  1326. cmdiocb = (struct lpfc_iocbq *) arg;
  1327. /* Ignore PLOGI if we have an outstanding LOGO */
  1328. if (ndlp->nlp_flag & NLP_LOGO_SND) {
  1329. return ndlp->nlp_state;
  1330. }
  1331. if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
  1332. spin_lock_irq(phba->host->host_lock);
  1333. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1334. spin_unlock_irq(phba->host->host_lock);
  1335. return ndlp->nlp_state;
  1336. }
  1337. /* send PLOGI immediately, move to PLOGI issue state */
  1338. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1339. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1340. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  1341. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  1342. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  1343. }
  1344. return ndlp->nlp_state;
  1345. }
  1346. static uint32_t
  1347. lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
  1348. struct lpfc_nodelist * ndlp, void *arg,
  1349. uint32_t evt)
  1350. {
  1351. struct lpfc_iocbq *cmdiocb;
  1352. struct ls_rjt stat;
  1353. cmdiocb = (struct lpfc_iocbq *) arg;
  1354. memset(&stat, 0, sizeof (struct ls_rjt));
  1355. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1356. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1357. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  1358. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1359. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  1360. spin_lock_irq(phba->host->host_lock);
  1361. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1362. spin_unlock_irq(phba->host->host_lock);
  1363. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1364. ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
  1365. lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
  1366. lpfc_issue_els_adisc(phba, ndlp, 0);
  1367. } else {
  1368. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1369. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  1370. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  1371. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  1372. }
  1373. }
  1374. return ndlp->nlp_state;
  1375. }
  1376. static uint32_t
  1377. lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
  1378. struct lpfc_nodelist * ndlp, void *arg,
  1379. uint32_t evt)
  1380. {
  1381. struct lpfc_iocbq *cmdiocb;
  1382. cmdiocb = (struct lpfc_iocbq *) arg;
  1383. lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
  1384. return ndlp->nlp_state;
  1385. }
  1386. static uint32_t
  1387. lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
  1388. struct lpfc_nodelist * ndlp, void *arg,
  1389. uint32_t evt)
  1390. {
  1391. struct lpfc_iocbq *cmdiocb;
  1392. cmdiocb = (struct lpfc_iocbq *) arg;
  1393. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1394. /*
  1395. * Do not start discovery if discovery is about to start
  1396. * or discovery in progress for this node. Starting discovery
  1397. * here will affect the counting of discovery threads.
  1398. */
  1399. if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
  1400. !(ndlp->nlp_flag & NLP_NPR_2B_DISC)){
  1401. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  1402. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1403. ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
  1404. lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
  1405. lpfc_issue_els_adisc(phba, ndlp, 0);
  1406. } else {
  1407. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1408. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  1409. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  1410. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  1411. }
  1412. }
  1413. return ndlp->nlp_state;
  1414. }
  1415. static uint32_t
  1416. lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
  1417. struct lpfc_nodelist * ndlp, void *arg,
  1418. uint32_t evt)
  1419. {
  1420. struct lpfc_iocbq *cmdiocb;
  1421. cmdiocb = (struct lpfc_iocbq *) arg;
  1422. spin_lock_irq(phba->host->host_lock);
  1423. ndlp->nlp_flag |= NLP_LOGO_ACC;
  1424. spin_unlock_irq(phba->host->host_lock);
  1425. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  1426. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1427. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  1428. spin_lock_irq(phba->host->host_lock);
  1429. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1430. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1431. spin_unlock_irq(phba->host->host_lock);
  1432. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  1433. } else {
  1434. spin_lock_irq(phba->host->host_lock);
  1435. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1436. spin_unlock_irq(phba->host->host_lock);
  1437. }
  1438. return ndlp->nlp_state;
  1439. }
  1440. static uint32_t
  1441. lpfc_cmpl_plogi_npr_node(struct lpfc_hba * phba,
  1442. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1443. {
  1444. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1445. IOCB_t *irsp;
  1446. cmdiocb = (struct lpfc_iocbq *) arg;
  1447. rspiocb = cmdiocb->context_un.rsp_iocb;
  1448. irsp = &rspiocb->iocb;
  1449. if (irsp->ulpStatus) {
  1450. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1451. return NLP_STE_FREED_NODE;
  1452. }
  1453. return ndlp->nlp_state;
  1454. }
  1455. static uint32_t
  1456. lpfc_cmpl_prli_npr_node(struct lpfc_hba * phba,
  1457. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1458. {
  1459. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1460. IOCB_t *irsp;
  1461. cmdiocb = (struct lpfc_iocbq *) arg;
  1462. rspiocb = cmdiocb->context_un.rsp_iocb;
  1463. irsp = &rspiocb->iocb;
  1464. if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
  1465. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1466. return NLP_STE_FREED_NODE;
  1467. }
  1468. return ndlp->nlp_state;
  1469. }
  1470. static uint32_t
  1471. lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
  1472. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1473. {
  1474. lpfc_unreg_rpi(phba, ndlp);
  1475. /* This routine does nothing, just return the current state */
  1476. return ndlp->nlp_state;
  1477. }
  1478. static uint32_t
  1479. lpfc_cmpl_adisc_npr_node(struct lpfc_hba * phba,
  1480. struct lpfc_nodelist * ndlp, void *arg,
  1481. uint32_t evt)
  1482. {
  1483. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1484. IOCB_t *irsp;
  1485. cmdiocb = (struct lpfc_iocbq *) arg;
  1486. rspiocb = cmdiocb->context_un.rsp_iocb;
  1487. irsp = &rspiocb->iocb;
  1488. if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
  1489. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1490. return NLP_STE_FREED_NODE;
  1491. }
  1492. return ndlp->nlp_state;
  1493. }
  1494. static uint32_t
  1495. lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
  1496. struct lpfc_nodelist * ndlp, void *arg,
  1497. uint32_t evt)
  1498. {
  1499. LPFC_MBOXQ_t *pmb;
  1500. MAILBOX_t *mb;
  1501. pmb = (LPFC_MBOXQ_t *) arg;
  1502. mb = &pmb->mb;
  1503. if (!mb->mbxStatus)
  1504. ndlp->nlp_rpi = mb->un.varWords[0];
  1505. else {
  1506. if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
  1507. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1508. return NLP_STE_FREED_NODE;
  1509. }
  1510. }
  1511. return ndlp->nlp_state;
  1512. }
  1513. static uint32_t
  1514. lpfc_device_rm_npr_node(struct lpfc_hba * phba,
  1515. struct lpfc_nodelist * ndlp, void *arg,
  1516. uint32_t evt)
  1517. {
  1518. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1519. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1520. return ndlp->nlp_state;
  1521. }
  1522. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1523. return NLP_STE_FREED_NODE;
  1524. }
  1525. static uint32_t
  1526. lpfc_device_recov_npr_node(struct lpfc_hba * phba,
  1527. struct lpfc_nodelist * ndlp, void *arg,
  1528. uint32_t evt)
  1529. {
  1530. spin_lock_irq(phba->host->host_lock);
  1531. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1532. spin_unlock_irq(phba->host->host_lock);
  1533. if (ndlp->nlp_flag & NLP_DELAY_TMO) {
  1534. lpfc_cancel_retry_delay_tmo(phba, ndlp);
  1535. }
  1536. return ndlp->nlp_state;
  1537. }
  1538. /* This next section defines the NPort Discovery State Machine */
  1539. /* There are 4 different double linked lists nodelist entries can reside on.
  1540. * The plogi list and adisc list are used when Link Up discovery or RSCN
  1541. * processing is needed. Each list holds the nodes that we will send PLOGI
  1542. * or ADISC on. These lists will keep track of what nodes will be effected
  1543. * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
  1544. * The unmapped_list will contain all nodes that we have successfully logged
  1545. * into at the Fibre Channel level. The mapped_list will contain all nodes
  1546. * that are mapped FCP targets.
  1547. */
  1548. /*
  1549. * The bind list is a list of undiscovered (potentially non-existent) nodes
  1550. * that we have saved binding information on. This information is used when
  1551. * nodes transition from the unmapped to the mapped list.
  1552. */
  1553. /* For UNUSED_NODE state, the node has just been allocated .
  1554. * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
  1555. * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
  1556. * and put on the unmapped list. For ADISC processing, the node is taken off
  1557. * the ADISC list and placed on either the mapped or unmapped list (depending
  1558. * on its previous state). Once on the unmapped list, a PRLI is issued and the
  1559. * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
  1560. * changed to UNMAPPED_NODE. If the completion indicates a mapped
  1561. * node, the node is taken off the unmapped list. The binding list is checked
  1562. * for a valid binding, or a binding is automatically assigned. If binding
  1563. * assignment is unsuccessful, the node is left on the unmapped list. If
  1564. * binding assignment is successful, the associated binding list entry (if
  1565. * any) is removed, and the node is placed on the mapped list.
  1566. */
  1567. /*
  1568. * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
  1569. * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
  1570. * expire, all effected nodes will receive a DEVICE_RM event.
  1571. */
  1572. /*
  1573. * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
  1574. * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
  1575. * check, additional nodes may be added or removed (via DEVICE_RM) to / from
  1576. * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
  1577. * we will first process the ADISC list. 32 entries are processed initially and
  1578. * ADISC is initited for each one. Completions / Events for each node are
  1579. * funnelled thru the state machine. As each node finishes ADISC processing, it
  1580. * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
  1581. * waiting, and the ADISC list count is identically 0, then we are done. For
  1582. * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
  1583. * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
  1584. * list. 32 entries are processed initially and PLOGI is initited for each one.
  1585. * Completions / Events for each node are funnelled thru the state machine. As
  1586. * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
  1587. * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
  1588. * indentically 0, then we are done. We have now completed discovery / RSCN
  1589. * handling. Upon completion, ALL nodes should be on either the mapped or
  1590. * unmapped lists.
  1591. */
  1592. static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
  1593. (struct lpfc_hba *, struct lpfc_nodelist *, void *, uint32_t) = {
  1594. /* Action routine Event Current State */
  1595. lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
  1596. lpfc_rcv_els_unused_node, /* RCV_PRLI */
  1597. lpfc_rcv_logo_unused_node, /* RCV_LOGO */
  1598. lpfc_rcv_els_unused_node, /* RCV_ADISC */
  1599. lpfc_rcv_els_unused_node, /* RCV_PDISC */
  1600. lpfc_rcv_els_unused_node, /* RCV_PRLO */
  1601. lpfc_disc_illegal, /* CMPL_PLOGI */
  1602. lpfc_disc_illegal, /* CMPL_PRLI */
  1603. lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
  1604. lpfc_disc_illegal, /* CMPL_ADISC */
  1605. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1606. lpfc_device_rm_unused_node, /* DEVICE_RM */
  1607. lpfc_disc_illegal, /* DEVICE_RECOVERY */
  1608. lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
  1609. lpfc_rcv_els_plogi_issue, /* RCV_PRLI */
  1610. lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
  1611. lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
  1612. lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
  1613. lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
  1614. lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
  1615. lpfc_disc_illegal, /* CMPL_PRLI */
  1616. lpfc_disc_illegal, /* CMPL_LOGO */
  1617. lpfc_disc_illegal, /* CMPL_ADISC */
  1618. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1619. lpfc_device_rm_plogi_issue, /* DEVICE_RM */
  1620. lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
  1621. lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
  1622. lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
  1623. lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
  1624. lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
  1625. lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
  1626. lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
  1627. lpfc_disc_illegal, /* CMPL_PLOGI */
  1628. lpfc_disc_illegal, /* CMPL_PRLI */
  1629. lpfc_disc_illegal, /* CMPL_LOGO */
  1630. lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
  1631. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1632. lpfc_device_rm_adisc_issue, /* DEVICE_RM */
  1633. lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
  1634. lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
  1635. lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
  1636. lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
  1637. lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
  1638. lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
  1639. lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
  1640. lpfc_disc_illegal, /* CMPL_PLOGI */
  1641. lpfc_disc_illegal, /* CMPL_PRLI */
  1642. lpfc_disc_illegal, /* CMPL_LOGO */
  1643. lpfc_disc_illegal, /* CMPL_ADISC */
  1644. lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
  1645. lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
  1646. lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
  1647. lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
  1648. lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
  1649. lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
  1650. lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
  1651. lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
  1652. lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
  1653. lpfc_disc_illegal, /* CMPL_PLOGI */
  1654. lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
  1655. lpfc_disc_illegal, /* CMPL_LOGO */
  1656. lpfc_disc_illegal, /* CMPL_ADISC */
  1657. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1658. lpfc_device_rm_prli_issue, /* DEVICE_RM */
  1659. lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
  1660. lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
  1661. lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
  1662. lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
  1663. lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
  1664. lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
  1665. lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
  1666. lpfc_disc_illegal, /* CMPL_PLOGI */
  1667. lpfc_disc_illegal, /* CMPL_PRLI */
  1668. lpfc_disc_illegal, /* CMPL_LOGO */
  1669. lpfc_disc_illegal, /* CMPL_ADISC */
  1670. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1671. lpfc_disc_illegal, /* DEVICE_RM */
  1672. lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
  1673. lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
  1674. lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
  1675. lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
  1676. lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
  1677. lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
  1678. lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
  1679. lpfc_disc_illegal, /* CMPL_PLOGI */
  1680. lpfc_disc_illegal, /* CMPL_PRLI */
  1681. lpfc_disc_illegal, /* CMPL_LOGO */
  1682. lpfc_disc_illegal, /* CMPL_ADISC */
  1683. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1684. lpfc_disc_illegal, /* DEVICE_RM */
  1685. lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
  1686. lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
  1687. lpfc_rcv_prli_npr_node, /* RCV_PRLI */
  1688. lpfc_rcv_logo_npr_node, /* RCV_LOGO */
  1689. lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
  1690. lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
  1691. lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
  1692. lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
  1693. lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
  1694. lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
  1695. lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
  1696. lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
  1697. lpfc_device_rm_npr_node, /* DEVICE_RM */
  1698. lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
  1699. };
  1700. int
  1701. lpfc_disc_state_machine(struct lpfc_hba * phba,
  1702. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1703. {
  1704. uint32_t cur_state, rc;
  1705. uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
  1706. uint32_t);
  1707. ndlp->nlp_disc_refcnt++;
  1708. cur_state = ndlp->nlp_state;
  1709. /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
  1710. lpfc_printf_log(phba,
  1711. KERN_INFO,
  1712. LOG_DISCOVERY,
  1713. "%d:0211 DSM in event x%x on NPort x%x in state %d "
  1714. "Data: x%x\n",
  1715. phba->brd_no,
  1716. evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
  1717. func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
  1718. rc = (func) (phba, ndlp, arg, evt);
  1719. /* DSM out state <rc> on NPort <nlp_DID> */
  1720. lpfc_printf_log(phba,
  1721. KERN_INFO,
  1722. LOG_DISCOVERY,
  1723. "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
  1724. phba->brd_no,
  1725. rc, ndlp->nlp_DID, ndlp->nlp_flag);
  1726. ndlp->nlp_disc_refcnt--;
  1727. /* Check to see if ndlp removal is deferred */
  1728. if ((ndlp->nlp_disc_refcnt == 0)
  1729. && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
  1730. spin_lock_irq(phba->host->host_lock);
  1731. ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
  1732. spin_unlock_irq(phba->host->host_lock);
  1733. lpfc_nlp_remove(phba, ndlp);
  1734. return NLP_STE_FREED_NODE;
  1735. }
  1736. if (rc == NLP_STE_FREED_NODE)
  1737. return NLP_STE_FREED_NODE;
  1738. return rc;
  1739. }