lpfc_nportdisc.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2012 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/slab.h>
  24. #include <linux/interrupt.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_device.h>
  27. #include <scsi/scsi_host.h>
  28. #include <scsi/scsi_transport_fc.h>
  29. #include "lpfc_hw4.h"
  30. #include "lpfc_hw.h"
  31. #include "lpfc_sli.h"
  32. #include "lpfc_sli4.h"
  33. #include "lpfc_nl.h"
  34. #include "lpfc_disc.h"
  35. #include "lpfc_scsi.h"
  36. #include "lpfc.h"
  37. #include "lpfc_logmsg.h"
  38. #include "lpfc_crtn.h"
  39. #include "lpfc_vport.h"
  40. #include "lpfc_debugfs.h"
  41. /* Called to verify a rcv'ed ADISC was intended for us. */
  42. static int
  43. lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  44. struct lpfc_name *nn, struct lpfc_name *pn)
  45. {
  46. /* First, we MUST have a RPI registered */
  47. if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
  48. return 0;
  49. /* Compare the ADISC rsp WWNN / WWPN matches our internal node
  50. * table entry for that node.
  51. */
  52. if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
  53. return 0;
  54. if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
  55. return 0;
  56. /* we match, return success */
  57. return 1;
  58. }
  59. int
  60. lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  61. struct serv_parm *sp, uint32_t class, int flogi)
  62. {
  63. volatile struct serv_parm *hsp = &vport->fc_sparam;
  64. uint16_t hsp_value, ssp_value = 0;
  65. /*
  66. * The receive data field size and buffer-to-buffer receive data field
  67. * size entries are 16 bits but are represented as two 8-bit fields in
  68. * the driver data structure to account for rsvd bits and other control
  69. * bits. Reconstruct and compare the fields as a 16-bit values before
  70. * correcting the byte values.
  71. */
  72. if (sp->cls1.classValid) {
  73. if (!flogi) {
  74. hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
  75. hsp->cls1.rcvDataSizeLsb);
  76. ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
  77. sp->cls1.rcvDataSizeLsb);
  78. if (!ssp_value)
  79. goto bad_service_param;
  80. if (ssp_value > hsp_value) {
  81. sp->cls1.rcvDataSizeLsb =
  82. hsp->cls1.rcvDataSizeLsb;
  83. sp->cls1.rcvDataSizeMsb =
  84. hsp->cls1.rcvDataSizeMsb;
  85. }
  86. }
  87. } else if (class == CLASS1)
  88. goto bad_service_param;
  89. if (sp->cls2.classValid) {
  90. if (!flogi) {
  91. hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
  92. hsp->cls2.rcvDataSizeLsb);
  93. ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
  94. sp->cls2.rcvDataSizeLsb);
  95. if (!ssp_value)
  96. goto bad_service_param;
  97. if (ssp_value > hsp_value) {
  98. sp->cls2.rcvDataSizeLsb =
  99. hsp->cls2.rcvDataSizeLsb;
  100. sp->cls2.rcvDataSizeMsb =
  101. hsp->cls2.rcvDataSizeMsb;
  102. }
  103. }
  104. } else if (class == CLASS2)
  105. goto bad_service_param;
  106. if (sp->cls3.classValid) {
  107. if (!flogi) {
  108. hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
  109. hsp->cls3.rcvDataSizeLsb);
  110. ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
  111. sp->cls3.rcvDataSizeLsb);
  112. if (!ssp_value)
  113. goto bad_service_param;
  114. if (ssp_value > hsp_value) {
  115. sp->cls3.rcvDataSizeLsb =
  116. hsp->cls3.rcvDataSizeLsb;
  117. sp->cls3.rcvDataSizeMsb =
  118. hsp->cls3.rcvDataSizeMsb;
  119. }
  120. }
  121. } else if (class == CLASS3)
  122. goto bad_service_param;
  123. /*
  124. * Preserve the upper four bits of the MSB from the PLOGI response.
  125. * These bits contain the Buffer-to-Buffer State Change Number
  126. * from the target and need to be passed to the FW.
  127. */
  128. hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
  129. ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
  130. if (ssp_value > hsp_value) {
  131. sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
  132. sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
  133. (hsp->cmn.bbRcvSizeMsb & 0x0F);
  134. }
  135. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
  136. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
  137. return 1;
  138. bad_service_param:
  139. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  140. "0207 Device %x "
  141. "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
  142. "invalid service parameters. Ignoring device.\n",
  143. ndlp->nlp_DID,
  144. sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
  145. sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
  146. sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
  147. sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
  148. return 0;
  149. }
  150. static void *
  151. lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  152. struct lpfc_iocbq *rspiocb)
  153. {
  154. struct lpfc_dmabuf *pcmd, *prsp;
  155. uint32_t *lp;
  156. void *ptr = NULL;
  157. IOCB_t *irsp;
  158. irsp = &rspiocb->iocb;
  159. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  160. /* For lpfc_els_abort, context2 could be zero'ed to delay
  161. * freeing associated memory till after ABTS completes.
  162. */
  163. if (pcmd) {
  164. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
  165. list);
  166. if (prsp) {
  167. lp = (uint32_t *) prsp->virt;
  168. ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
  169. }
  170. } else {
  171. /* Force ulpStatus error since we are returning NULL ptr */
  172. if (!(irsp->ulpStatus)) {
  173. irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
  174. irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
  175. }
  176. ptr = NULL;
  177. }
  178. return ptr;
  179. }
  180. /*
  181. * Free resources / clean up outstanding I/Os
  182. * associated with a LPFC_NODELIST entry. This
  183. * routine effectively results in a "software abort".
  184. */
  185. int
  186. lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  187. {
  188. LIST_HEAD(completions);
  189. LIST_HEAD(txcmplq_completions);
  190. LIST_HEAD(abort_list);
  191. struct lpfc_sli *psli = &phba->sli;
  192. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  193. struct lpfc_iocbq *iocb, *next_iocb;
  194. /* Abort outstanding I/O on NPort <nlp_DID> */
  195. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
  196. "2819 Abort outstanding I/O on NPort x%x "
  197. "Data: x%x x%x x%x\n",
  198. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  199. ndlp->nlp_rpi);
  200. lpfc_fabric_abort_nport(ndlp);
  201. /* First check the txq */
  202. spin_lock_irq(&phba->hbalock);
  203. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  204. /* Check to see if iocb matches the nport we are looking for */
  205. if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
  206. /* It matches, so deque and call compl with anp error */
  207. list_move_tail(&iocb->list, &completions);
  208. pring->txq_cnt--;
  209. }
  210. }
  211. /* Next check the txcmplq */
  212. list_splice_init(&pring->txcmplq, &txcmplq_completions);
  213. spin_unlock_irq(&phba->hbalock);
  214. list_for_each_entry_safe(iocb, next_iocb, &txcmplq_completions, list) {
  215. /* Check to see if iocb matches the nport we are looking for */
  216. if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
  217. list_add_tail(&iocb->dlist, &abort_list);
  218. }
  219. spin_lock_irq(&phba->hbalock);
  220. list_splice(&txcmplq_completions, &pring->txcmplq);
  221. spin_unlock_irq(&phba->hbalock);
  222. list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
  223. spin_lock_irq(&phba->hbalock);
  224. list_del_init(&iocb->dlist);
  225. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  226. spin_unlock_irq(&phba->hbalock);
  227. }
  228. /* Cancel all the IOCBs from the completions list */
  229. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  230. IOERR_SLI_ABORTED);
  231. lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
  232. return 0;
  233. }
  234. static int
  235. lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  236. struct lpfc_iocbq *cmdiocb)
  237. {
  238. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  239. struct lpfc_hba *phba = vport->phba;
  240. struct lpfc_dmabuf *pcmd;
  241. uint32_t *lp;
  242. IOCB_t *icmd;
  243. struct serv_parm *sp;
  244. LPFC_MBOXQ_t *mbox;
  245. struct ls_rjt stat;
  246. int rc;
  247. memset(&stat, 0, sizeof (struct ls_rjt));
  248. if (vport->port_state <= LPFC_FDISC) {
  249. /* Before responding to PLOGI, check for pt2pt mode.
  250. * If we are pt2pt, with an outstanding FLOGI, abort
  251. * the FLOGI and resend it first.
  252. */
  253. if (vport->fc_flag & FC_PT2PT) {
  254. lpfc_els_abort_flogi(phba);
  255. if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
  256. /* If the other side is supposed to initiate
  257. * the PLOGI anyway, just ACC it now and
  258. * move on with discovery.
  259. */
  260. phba->fc_edtov = FF_DEF_EDTOV;
  261. phba->fc_ratov = FF_DEF_RATOV;
  262. /* Start discovery - this should just do
  263. CLEAR_LA */
  264. lpfc_disc_start(vport);
  265. } else
  266. lpfc_initial_flogi(vport);
  267. } else {
  268. stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
  269. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  270. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
  271. ndlp, NULL);
  272. return 0;
  273. }
  274. }
  275. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  276. lp = (uint32_t *) pcmd->virt;
  277. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  278. if (wwn_to_u64(sp->portName.u.wwn) == 0) {
  279. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  280. "0140 PLOGI Reject: invalid nname\n");
  281. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  282. stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
  283. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  284. NULL);
  285. return 0;
  286. }
  287. if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
  288. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  289. "0141 PLOGI Reject: invalid pname\n");
  290. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  291. stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
  292. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  293. NULL);
  294. return 0;
  295. }
  296. if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
  297. /* Reject this request because invalid parameters */
  298. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  299. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  300. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  301. NULL);
  302. return 0;
  303. }
  304. icmd = &cmdiocb->iocb;
  305. /* PLOGI chkparm OK */
  306. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  307. "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
  308. ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
  309. ndlp->nlp_rpi);
  310. if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
  311. ndlp->nlp_fcp_info |= CLASS2;
  312. else
  313. ndlp->nlp_fcp_info |= CLASS3;
  314. ndlp->nlp_class_sup = 0;
  315. if (sp->cls1.classValid)
  316. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  317. if (sp->cls2.classValid)
  318. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  319. if (sp->cls3.classValid)
  320. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  321. if (sp->cls4.classValid)
  322. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  323. ndlp->nlp_maxframe =
  324. ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
  325. /* no need to reg_login if we are already in one of these states */
  326. switch (ndlp->nlp_state) {
  327. case NLP_STE_NPR_NODE:
  328. if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
  329. break;
  330. case NLP_STE_REG_LOGIN_ISSUE:
  331. case NLP_STE_PRLI_ISSUE:
  332. case NLP_STE_UNMAPPED_NODE:
  333. case NLP_STE_MAPPED_NODE:
  334. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
  335. return 1;
  336. }
  337. /* Check for Nport to NPort pt2pt protocol */
  338. if ((vport->fc_flag & FC_PT2PT) &&
  339. !(vport->fc_flag & FC_PT2PT_PLOGI)) {
  340. /* rcv'ed PLOGI decides what our NPortId will be */
  341. vport->fc_myDID = icmd->un.rcvels.parmRo;
  342. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  343. if (mbox == NULL)
  344. goto out;
  345. lpfc_config_link(phba, mbox);
  346. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  347. mbox->vport = vport;
  348. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  349. if (rc == MBX_NOT_FINISHED) {
  350. mempool_free(mbox, phba->mbox_mem_pool);
  351. goto out;
  352. }
  353. /*
  354. * For SLI4, the VFI/VPI are registered AFTER the
  355. * Nport with the higher WWPN sends us a PLOGI with
  356. * our assigned NPortId.
  357. */
  358. if (phba->sli_rev == LPFC_SLI_REV4)
  359. lpfc_issue_reg_vfi(vport);
  360. lpfc_can_disctmo(vport);
  361. }
  362. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  363. if (!mbox)
  364. goto out;
  365. /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
  366. if (phba->sli_rev == LPFC_SLI_REV4)
  367. lpfc_unreg_rpi(vport, ndlp);
  368. rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
  369. (uint8_t *) sp, mbox, ndlp->nlp_rpi);
  370. if (rc) {
  371. mempool_free(mbox, phba->mbox_mem_pool);
  372. goto out;
  373. }
  374. /* ACC PLOGI rsp command needs to execute first,
  375. * queue this mbox command to be processed later.
  376. */
  377. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  378. /*
  379. * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
  380. * command issued in lpfc_cmpl_els_acc().
  381. */
  382. mbox->vport = vport;
  383. spin_lock_irq(shost->host_lock);
  384. ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
  385. spin_unlock_irq(shost->host_lock);
  386. /*
  387. * If there is an outstanding PLOGI issued, abort it before
  388. * sending ACC rsp for received PLOGI. If pending plogi
  389. * is not canceled here, the plogi will be rejected by
  390. * remote port and will be retried. On a configuration with
  391. * single discovery thread, this will cause a huge delay in
  392. * discovery. Also this will cause multiple state machines
  393. * running in parallel for this node.
  394. */
  395. if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
  396. /* software abort outstanding PLOGI */
  397. lpfc_els_abort(phba, ndlp);
  398. }
  399. if ((vport->port_type == LPFC_NPIV_PORT &&
  400. vport->cfg_restrict_login)) {
  401. /* In order to preserve RPIs, we want to cleanup
  402. * the default RPI the firmware created to rcv
  403. * this ELS request. The only way to do this is
  404. * to register, then unregister the RPI.
  405. */
  406. spin_lock_irq(shost->host_lock);
  407. ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
  408. spin_unlock_irq(shost->host_lock);
  409. stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
  410. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  411. rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
  412. ndlp, mbox);
  413. if (rc)
  414. mempool_free(mbox, phba->mbox_mem_pool);
  415. return 1;
  416. }
  417. rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
  418. if (rc)
  419. mempool_free(mbox, phba->mbox_mem_pool);
  420. return 1;
  421. out:
  422. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  423. stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
  424. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  425. return 0;
  426. }
  427. /**
  428. * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
  429. * @phba: pointer to lpfc hba data structure.
  430. * @mboxq: pointer to mailbox object
  431. *
  432. * This routine is invoked to issue a completion to a rcv'ed
  433. * ADISC or PDISC after the paused RPI has been resumed.
  434. **/
  435. static void
  436. lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  437. {
  438. struct lpfc_vport *vport;
  439. struct lpfc_iocbq *elsiocb;
  440. struct lpfc_nodelist *ndlp;
  441. uint32_t cmd;
  442. elsiocb = (struct lpfc_iocbq *)mboxq->context1;
  443. ndlp = (struct lpfc_nodelist *) mboxq->context2;
  444. vport = mboxq->vport;
  445. cmd = elsiocb->drvrTimeout;
  446. if (cmd == ELS_CMD_ADISC) {
  447. lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
  448. } else {
  449. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
  450. ndlp, NULL);
  451. }
  452. kfree(elsiocb);
  453. mempool_free(mboxq, phba->mbox_mem_pool);
  454. }
  455. static int
  456. lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  457. struct lpfc_iocbq *cmdiocb)
  458. {
  459. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  460. struct lpfc_iocbq *elsiocb;
  461. struct lpfc_dmabuf *pcmd;
  462. struct serv_parm *sp;
  463. struct lpfc_name *pnn, *ppn;
  464. struct ls_rjt stat;
  465. ADISC *ap;
  466. IOCB_t *icmd;
  467. uint32_t *lp;
  468. uint32_t cmd;
  469. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  470. lp = (uint32_t *) pcmd->virt;
  471. cmd = *lp++;
  472. if (cmd == ELS_CMD_ADISC) {
  473. ap = (ADISC *) lp;
  474. pnn = (struct lpfc_name *) & ap->nodeName;
  475. ppn = (struct lpfc_name *) & ap->portName;
  476. } else {
  477. sp = (struct serv_parm *) lp;
  478. pnn = (struct lpfc_name *) & sp->nodeName;
  479. ppn = (struct lpfc_name *) & sp->portName;
  480. }
  481. icmd = &cmdiocb->iocb;
  482. if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
  483. /*
  484. * As soon as we send ACC, the remote NPort can
  485. * start sending us data. Thus, for SLI4 we must
  486. * resume the RPI before the ACC goes out.
  487. */
  488. if (vport->phba->sli_rev == LPFC_SLI_REV4) {
  489. elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
  490. GFP_KERNEL);
  491. if (elsiocb) {
  492. /* Save info from cmd IOCB used in rsp */
  493. memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
  494. sizeof(struct lpfc_iocbq));
  495. /* Save the ELS cmd */
  496. elsiocb->drvrTimeout = cmd;
  497. lpfc_sli4_resume_rpi(ndlp,
  498. lpfc_mbx_cmpl_resume_rpi, elsiocb);
  499. goto out;
  500. }
  501. }
  502. if (cmd == ELS_CMD_ADISC) {
  503. lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
  504. } else {
  505. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
  506. ndlp, NULL);
  507. }
  508. out:
  509. /* If we are authenticated, move to the proper state */
  510. if (ndlp->nlp_type & NLP_FCP_TARGET)
  511. lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
  512. else
  513. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  514. return 1;
  515. }
  516. /* Reject this request because invalid parameters */
  517. stat.un.b.lsRjtRsvd0 = 0;
  518. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  519. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  520. stat.un.b.vendorUnique = 0;
  521. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  522. /* 1 sec timeout */
  523. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  524. spin_lock_irq(shost->host_lock);
  525. ndlp->nlp_flag |= NLP_DELAY_TMO;
  526. spin_unlock_irq(shost->host_lock);
  527. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  528. ndlp->nlp_prev_state = ndlp->nlp_state;
  529. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  530. return 0;
  531. }
  532. static int
  533. lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  534. struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
  535. {
  536. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  537. struct lpfc_hba *phba = vport->phba;
  538. struct lpfc_vport **vports;
  539. int i, active_vlink_present = 0 ;
  540. /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
  541. /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
  542. * PLOGIs during LOGO storms from a device.
  543. */
  544. spin_lock_irq(shost->host_lock);
  545. ndlp->nlp_flag |= NLP_LOGO_ACC;
  546. spin_unlock_irq(shost->host_lock);
  547. if (els_cmd == ELS_CMD_PRLO)
  548. lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
  549. else
  550. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  551. if (ndlp->nlp_DID == Fabric_DID) {
  552. if (vport->port_state <= LPFC_FDISC)
  553. goto out;
  554. lpfc_linkdown_port(vport);
  555. spin_lock_irq(shost->host_lock);
  556. vport->fc_flag |= FC_VPORT_LOGO_RCVD;
  557. spin_unlock_irq(shost->host_lock);
  558. vports = lpfc_create_vport_work_array(phba);
  559. if (vports) {
  560. for (i = 0; i <= phba->max_vports && vports[i] != NULL;
  561. i++) {
  562. if ((!(vports[i]->fc_flag &
  563. FC_VPORT_LOGO_RCVD)) &&
  564. (vports[i]->port_state > LPFC_FDISC)) {
  565. active_vlink_present = 1;
  566. break;
  567. }
  568. }
  569. lpfc_destroy_vport_work_array(phba, vports);
  570. }
  571. if (active_vlink_present) {
  572. /*
  573. * If there are other active VLinks present,
  574. * re-instantiate the Vlink using FDISC.
  575. */
  576. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  577. spin_lock_irq(shost->host_lock);
  578. ndlp->nlp_flag |= NLP_DELAY_TMO;
  579. spin_unlock_irq(shost->host_lock);
  580. ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
  581. vport->port_state = LPFC_FDISC;
  582. } else {
  583. spin_lock_irq(shost->host_lock);
  584. phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
  585. spin_unlock_irq(shost->host_lock);
  586. lpfc_retry_pport_discovery(phba);
  587. }
  588. } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
  589. ((ndlp->nlp_type & NLP_FCP_TARGET) ||
  590. !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
  591. (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
  592. /* Only try to re-login if this is NOT a Fabric Node */
  593. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  594. spin_lock_irq(shost->host_lock);
  595. ndlp->nlp_flag |= NLP_DELAY_TMO;
  596. spin_unlock_irq(shost->host_lock);
  597. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  598. }
  599. out:
  600. ndlp->nlp_prev_state = ndlp->nlp_state;
  601. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  602. spin_lock_irq(shost->host_lock);
  603. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  604. spin_unlock_irq(shost->host_lock);
  605. /* The driver has to wait until the ACC completes before it continues
  606. * processing the LOGO. The action will resume in
  607. * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
  608. * unreg_login, the driver waits so the ACC does not get aborted.
  609. */
  610. return 0;
  611. }
  612. static void
  613. lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  614. struct lpfc_iocbq *cmdiocb)
  615. {
  616. struct lpfc_dmabuf *pcmd;
  617. uint32_t *lp;
  618. PRLI *npr;
  619. struct fc_rport *rport = ndlp->rport;
  620. u32 roles;
  621. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  622. lp = (uint32_t *) pcmd->virt;
  623. npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
  624. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  625. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  626. if (npr->prliType == PRLI_FCP_TYPE) {
  627. if (npr->initiatorFunc)
  628. ndlp->nlp_type |= NLP_FCP_INITIATOR;
  629. if (npr->targetFunc)
  630. ndlp->nlp_type |= NLP_FCP_TARGET;
  631. if (npr->Retry)
  632. ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
  633. }
  634. if (rport) {
  635. /* We need to update the rport role values */
  636. roles = FC_RPORT_ROLE_UNKNOWN;
  637. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  638. roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  639. if (ndlp->nlp_type & NLP_FCP_TARGET)
  640. roles |= FC_RPORT_ROLE_FCP_TARGET;
  641. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  642. "rport rolechg: role:x%x did:x%x flg:x%x",
  643. roles, ndlp->nlp_DID, ndlp->nlp_flag);
  644. fc_remote_port_rolechg(rport, roles);
  645. }
  646. }
  647. static uint32_t
  648. lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  649. {
  650. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  651. if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
  652. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  653. return 0;
  654. }
  655. if (!(vport->fc_flag & FC_PT2PT)) {
  656. /* Check config parameter use-adisc or FCP-2 */
  657. if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
  658. ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
  659. (ndlp->nlp_type & NLP_FCP_TARGET))) {
  660. spin_lock_irq(shost->host_lock);
  661. ndlp->nlp_flag |= NLP_NPR_ADISC;
  662. spin_unlock_irq(shost->host_lock);
  663. return 1;
  664. }
  665. }
  666. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  667. lpfc_unreg_rpi(vport, ndlp);
  668. return 0;
  669. }
  670. /**
  671. * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
  672. * @phba : Pointer to lpfc_hba structure.
  673. * @vport: Pointer to lpfc_vport structure.
  674. * @rpi : rpi to be release.
  675. *
  676. * This function will send a unreg_login mailbox command to the firmware
  677. * to release a rpi.
  678. **/
  679. void
  680. lpfc_release_rpi(struct lpfc_hba *phba,
  681. struct lpfc_vport *vport,
  682. uint16_t rpi)
  683. {
  684. LPFC_MBOXQ_t *pmb;
  685. int rc;
  686. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  687. GFP_KERNEL);
  688. if (!pmb)
  689. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  690. "2796 mailbox memory allocation failed \n");
  691. else {
  692. lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
  693. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  694. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  695. if (rc == MBX_NOT_FINISHED)
  696. mempool_free(pmb, phba->mbox_mem_pool);
  697. }
  698. }
  699. static uint32_t
  700. lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  701. void *arg, uint32_t evt)
  702. {
  703. struct lpfc_hba *phba;
  704. LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
  705. MAILBOX_t *mb;
  706. uint16_t rpi;
  707. phba = vport->phba;
  708. /* Release the RPI if reglogin completing */
  709. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  710. (evt == NLP_EVT_CMPL_REG_LOGIN) &&
  711. (!pmb->u.mb.mbxStatus)) {
  712. mb = &pmb->u.mb;
  713. rpi = pmb->u.mb.un.varWords[0];
  714. lpfc_release_rpi(phba, vport, rpi);
  715. }
  716. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  717. "0271 Illegal State Transition: node x%x "
  718. "event x%x, state x%x Data: x%x x%x\n",
  719. ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
  720. ndlp->nlp_flag);
  721. return ndlp->nlp_state;
  722. }
  723. static uint32_t
  724. lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  725. void *arg, uint32_t evt)
  726. {
  727. /* This transition is only legal if we previously
  728. * rcv'ed a PLOGI. Since we don't want 2 discovery threads
  729. * working on the same NPortID, do nothing for this thread
  730. * to stop it.
  731. */
  732. if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
  733. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  734. "0272 Illegal State Transition: node x%x "
  735. "event x%x, state x%x Data: x%x x%x\n",
  736. ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
  737. ndlp->nlp_flag);
  738. }
  739. return ndlp->nlp_state;
  740. }
  741. /* Start of Discovery State Machine routines */
  742. static uint32_t
  743. lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  744. void *arg, uint32_t evt)
  745. {
  746. struct lpfc_iocbq *cmdiocb;
  747. cmdiocb = (struct lpfc_iocbq *) arg;
  748. if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
  749. return ndlp->nlp_state;
  750. }
  751. return NLP_STE_FREED_NODE;
  752. }
  753. static uint32_t
  754. lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  755. void *arg, uint32_t evt)
  756. {
  757. lpfc_issue_els_logo(vport, ndlp, 0);
  758. return ndlp->nlp_state;
  759. }
  760. static uint32_t
  761. lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  762. void *arg, uint32_t evt)
  763. {
  764. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  765. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  766. spin_lock_irq(shost->host_lock);
  767. ndlp->nlp_flag |= NLP_LOGO_ACC;
  768. spin_unlock_irq(shost->host_lock);
  769. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  770. return ndlp->nlp_state;
  771. }
  772. static uint32_t
  773. lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  774. void *arg, uint32_t evt)
  775. {
  776. return NLP_STE_FREED_NODE;
  777. }
  778. static uint32_t
  779. lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  780. void *arg, uint32_t evt)
  781. {
  782. return NLP_STE_FREED_NODE;
  783. }
  784. static uint32_t
  785. lpfc_device_recov_unused_node(struct lpfc_vport *vport,
  786. struct lpfc_nodelist *ndlp,
  787. void *arg, uint32_t evt)
  788. {
  789. return ndlp->nlp_state;
  790. }
  791. static uint32_t
  792. lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  793. void *arg, uint32_t evt)
  794. {
  795. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  796. struct lpfc_hba *phba = vport->phba;
  797. struct lpfc_iocbq *cmdiocb = arg;
  798. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  799. uint32_t *lp = (uint32_t *) pcmd->virt;
  800. struct serv_parm *sp = (struct serv_parm *) (lp + 1);
  801. struct ls_rjt stat;
  802. int port_cmp;
  803. memset(&stat, 0, sizeof (struct ls_rjt));
  804. /* For a PLOGI, we only accept if our portname is less
  805. * than the remote portname.
  806. */
  807. phba->fc_stat.elsLogiCol++;
  808. port_cmp = memcmp(&vport->fc_portname, &sp->portName,
  809. sizeof(struct lpfc_name));
  810. if (port_cmp >= 0) {
  811. /* Reject this request because the remote node will accept
  812. ours */
  813. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  814. stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
  815. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  816. NULL);
  817. } else {
  818. if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
  819. (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
  820. (vport->num_disc_nodes)) {
  821. spin_lock_irq(shost->host_lock);
  822. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  823. spin_unlock_irq(shost->host_lock);
  824. /* Check if there are more PLOGIs to be sent */
  825. lpfc_more_plogi(vport);
  826. if (vport->num_disc_nodes == 0) {
  827. spin_lock_irq(shost->host_lock);
  828. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  829. spin_unlock_irq(shost->host_lock);
  830. lpfc_can_disctmo(vport);
  831. lpfc_end_rscn(vport);
  832. }
  833. }
  834. } /* If our portname was less */
  835. return ndlp->nlp_state;
  836. }
  837. static uint32_t
  838. lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  839. void *arg, uint32_t evt)
  840. {
  841. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  842. struct ls_rjt stat;
  843. memset(&stat, 0, sizeof (struct ls_rjt));
  844. stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
  845. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  846. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  847. return ndlp->nlp_state;
  848. }
  849. static uint32_t
  850. lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  851. void *arg, uint32_t evt)
  852. {
  853. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  854. /* software abort outstanding PLOGI */
  855. lpfc_els_abort(vport->phba, ndlp);
  856. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  857. return ndlp->nlp_state;
  858. }
  859. static uint32_t
  860. lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  861. void *arg, uint32_t evt)
  862. {
  863. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  864. struct lpfc_hba *phba = vport->phba;
  865. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  866. /* software abort outstanding PLOGI */
  867. lpfc_els_abort(phba, ndlp);
  868. if (evt == NLP_EVT_RCV_LOGO) {
  869. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  870. } else {
  871. lpfc_issue_els_logo(vport, ndlp, 0);
  872. }
  873. /* Put ndlp in npr state set plogi timer for 1 sec */
  874. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  875. spin_lock_irq(shost->host_lock);
  876. ndlp->nlp_flag |= NLP_DELAY_TMO;
  877. spin_unlock_irq(shost->host_lock);
  878. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  879. ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
  880. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  881. return ndlp->nlp_state;
  882. }
  883. static uint32_t
  884. lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
  885. struct lpfc_nodelist *ndlp,
  886. void *arg,
  887. uint32_t evt)
  888. {
  889. struct lpfc_hba *phba = vport->phba;
  890. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  891. struct lpfc_iocbq *cmdiocb, *rspiocb;
  892. struct lpfc_dmabuf *pcmd, *prsp, *mp;
  893. uint32_t *lp;
  894. IOCB_t *irsp;
  895. struct serv_parm *sp;
  896. LPFC_MBOXQ_t *mbox;
  897. cmdiocb = (struct lpfc_iocbq *) arg;
  898. rspiocb = cmdiocb->context_un.rsp_iocb;
  899. if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  900. /* Recovery from PLOGI collision logic */
  901. return ndlp->nlp_state;
  902. }
  903. irsp = &rspiocb->iocb;
  904. if (irsp->ulpStatus)
  905. goto out;
  906. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  907. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  908. lp = (uint32_t *) prsp->virt;
  909. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  910. /* Some switches have FDMI servers returning 0 for WWN */
  911. if ((ndlp->nlp_DID != FDMI_DID) &&
  912. (wwn_to_u64(sp->portName.u.wwn) == 0 ||
  913. wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
  914. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  915. "0142 PLOGI RSP: Invalid WWN.\n");
  916. goto out;
  917. }
  918. if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
  919. goto out;
  920. /* PLOGI chkparm OK */
  921. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  922. "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
  923. ndlp->nlp_DID, ndlp->nlp_state,
  924. ndlp->nlp_flag, ndlp->nlp_rpi);
  925. if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
  926. ndlp->nlp_fcp_info |= CLASS2;
  927. else
  928. ndlp->nlp_fcp_info |= CLASS3;
  929. ndlp->nlp_class_sup = 0;
  930. if (sp->cls1.classValid)
  931. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  932. if (sp->cls2.classValid)
  933. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  934. if (sp->cls3.classValid)
  935. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  936. if (sp->cls4.classValid)
  937. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  938. ndlp->nlp_maxframe =
  939. ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
  940. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  941. if (!mbox) {
  942. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  943. "0133 PLOGI: no memory for reg_login "
  944. "Data: x%x x%x x%x x%x\n",
  945. ndlp->nlp_DID, ndlp->nlp_state,
  946. ndlp->nlp_flag, ndlp->nlp_rpi);
  947. goto out;
  948. }
  949. lpfc_unreg_rpi(vport, ndlp);
  950. if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
  951. (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
  952. switch (ndlp->nlp_DID) {
  953. case NameServer_DID:
  954. mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
  955. break;
  956. case FDMI_DID:
  957. mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
  958. break;
  959. default:
  960. ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
  961. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  962. }
  963. mbox->context2 = lpfc_nlp_get(ndlp);
  964. mbox->vport = vport;
  965. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  966. != MBX_NOT_FINISHED) {
  967. lpfc_nlp_set_state(vport, ndlp,
  968. NLP_STE_REG_LOGIN_ISSUE);
  969. return ndlp->nlp_state;
  970. }
  971. if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
  972. ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
  973. /* decrement node reference count to the failed mbox
  974. * command
  975. */
  976. lpfc_nlp_put(ndlp);
  977. mp = (struct lpfc_dmabuf *) mbox->context1;
  978. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  979. kfree(mp);
  980. mempool_free(mbox, phba->mbox_mem_pool);
  981. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  982. "0134 PLOGI: cannot issue reg_login "
  983. "Data: x%x x%x x%x x%x\n",
  984. ndlp->nlp_DID, ndlp->nlp_state,
  985. ndlp->nlp_flag, ndlp->nlp_rpi);
  986. } else {
  987. mempool_free(mbox, phba->mbox_mem_pool);
  988. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  989. "0135 PLOGI: cannot format reg_login "
  990. "Data: x%x x%x x%x x%x\n",
  991. ndlp->nlp_DID, ndlp->nlp_state,
  992. ndlp->nlp_flag, ndlp->nlp_rpi);
  993. }
  994. out:
  995. if (ndlp->nlp_DID == NameServer_DID) {
  996. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  997. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  998. "0261 Cannot Register NameServer login\n");
  999. }
  1000. spin_lock_irq(shost->host_lock);
  1001. ndlp->nlp_flag |= NLP_DEFER_RM;
  1002. spin_unlock_irq(shost->host_lock);
  1003. return NLP_STE_FREED_NODE;
  1004. }
  1005. static uint32_t
  1006. lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1007. void *arg, uint32_t evt)
  1008. {
  1009. return ndlp->nlp_state;
  1010. }
  1011. static uint32_t
  1012. lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
  1013. struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
  1014. {
  1015. struct lpfc_hba *phba;
  1016. LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
  1017. MAILBOX_t *mb = &pmb->u.mb;
  1018. uint16_t rpi;
  1019. phba = vport->phba;
  1020. /* Release the RPI */
  1021. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1022. !mb->mbxStatus) {
  1023. rpi = pmb->u.mb.un.varWords[0];
  1024. lpfc_release_rpi(phba, vport, rpi);
  1025. }
  1026. return ndlp->nlp_state;
  1027. }
  1028. static uint32_t
  1029. lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1030. void *arg, uint32_t evt)
  1031. {
  1032. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1033. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1034. spin_lock_irq(shost->host_lock);
  1035. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1036. spin_unlock_irq(shost->host_lock);
  1037. return ndlp->nlp_state;
  1038. } else {
  1039. /* software abort outstanding PLOGI */
  1040. lpfc_els_abort(vport->phba, ndlp);
  1041. lpfc_drop_node(vport, ndlp);
  1042. return NLP_STE_FREED_NODE;
  1043. }
  1044. }
  1045. static uint32_t
  1046. lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
  1047. struct lpfc_nodelist *ndlp,
  1048. void *arg,
  1049. uint32_t evt)
  1050. {
  1051. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1052. struct lpfc_hba *phba = vport->phba;
  1053. /* Don't do anything that will mess up processing of the
  1054. * previous RSCN.
  1055. */
  1056. if (vport->fc_flag & FC_RSCN_DEFERRED)
  1057. return ndlp->nlp_state;
  1058. /* software abort outstanding PLOGI */
  1059. lpfc_els_abort(phba, ndlp);
  1060. ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
  1061. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1062. spin_lock_irq(shost->host_lock);
  1063. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1064. spin_unlock_irq(shost->host_lock);
  1065. return ndlp->nlp_state;
  1066. }
  1067. static uint32_t
  1068. lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1069. void *arg, uint32_t evt)
  1070. {
  1071. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1072. struct lpfc_hba *phba = vport->phba;
  1073. struct lpfc_iocbq *cmdiocb;
  1074. /* software abort outstanding ADISC */
  1075. lpfc_els_abort(phba, ndlp);
  1076. cmdiocb = (struct lpfc_iocbq *) arg;
  1077. if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
  1078. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1079. spin_lock_irq(shost->host_lock);
  1080. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1081. spin_unlock_irq(shost->host_lock);
  1082. if (vport->num_disc_nodes)
  1083. lpfc_more_adisc(vport);
  1084. }
  1085. return ndlp->nlp_state;
  1086. }
  1087. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  1088. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  1089. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  1090. return ndlp->nlp_state;
  1091. }
  1092. static uint32_t
  1093. lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1094. void *arg, uint32_t evt)
  1095. {
  1096. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1097. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  1098. return ndlp->nlp_state;
  1099. }
  1100. static uint32_t
  1101. lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1102. void *arg, uint32_t evt)
  1103. {
  1104. struct lpfc_hba *phba = vport->phba;
  1105. struct lpfc_iocbq *cmdiocb;
  1106. cmdiocb = (struct lpfc_iocbq *) arg;
  1107. /* software abort outstanding ADISC */
  1108. lpfc_els_abort(phba, ndlp);
  1109. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1110. return ndlp->nlp_state;
  1111. }
  1112. static uint32_t
  1113. lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
  1114. struct lpfc_nodelist *ndlp,
  1115. void *arg, uint32_t evt)
  1116. {
  1117. struct lpfc_iocbq *cmdiocb;
  1118. cmdiocb = (struct lpfc_iocbq *) arg;
  1119. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1120. return ndlp->nlp_state;
  1121. }
  1122. static uint32_t
  1123. lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1124. void *arg, uint32_t evt)
  1125. {
  1126. struct lpfc_iocbq *cmdiocb;
  1127. cmdiocb = (struct lpfc_iocbq *) arg;
  1128. /* Treat like rcv logo */
  1129. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
  1130. return ndlp->nlp_state;
  1131. }
  1132. static uint32_t
  1133. lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
  1134. struct lpfc_nodelist *ndlp,
  1135. void *arg, uint32_t evt)
  1136. {
  1137. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1138. struct lpfc_hba *phba = vport->phba;
  1139. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1140. IOCB_t *irsp;
  1141. ADISC *ap;
  1142. int rc;
  1143. cmdiocb = (struct lpfc_iocbq *) arg;
  1144. rspiocb = cmdiocb->context_un.rsp_iocb;
  1145. ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
  1146. irsp = &rspiocb->iocb;
  1147. if ((irsp->ulpStatus) ||
  1148. (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
  1149. /* 1 sec timeout */
  1150. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  1151. spin_lock_irq(shost->host_lock);
  1152. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1153. spin_unlock_irq(shost->host_lock);
  1154. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  1155. memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
  1156. memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
  1157. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  1158. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1159. lpfc_unreg_rpi(vport, ndlp);
  1160. return ndlp->nlp_state;
  1161. }
  1162. if (phba->sli_rev == LPFC_SLI_REV4) {
  1163. rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
  1164. if (rc) {
  1165. /* Stay in state and retry. */
  1166. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  1167. return ndlp->nlp_state;
  1168. }
  1169. }
  1170. if (ndlp->nlp_type & NLP_FCP_TARGET) {
  1171. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  1172. lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
  1173. } else {
  1174. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  1175. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1176. }
  1177. return ndlp->nlp_state;
  1178. }
  1179. static uint32_t
  1180. lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1181. void *arg, uint32_t evt)
  1182. {
  1183. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1184. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1185. spin_lock_irq(shost->host_lock);
  1186. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1187. spin_unlock_irq(shost->host_lock);
  1188. return ndlp->nlp_state;
  1189. } else {
  1190. /* software abort outstanding ADISC */
  1191. lpfc_els_abort(vport->phba, ndlp);
  1192. lpfc_drop_node(vport, ndlp);
  1193. return NLP_STE_FREED_NODE;
  1194. }
  1195. }
  1196. static uint32_t
  1197. lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
  1198. struct lpfc_nodelist *ndlp,
  1199. void *arg,
  1200. uint32_t evt)
  1201. {
  1202. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1203. struct lpfc_hba *phba = vport->phba;
  1204. /* Don't do anything that will mess up processing of the
  1205. * previous RSCN.
  1206. */
  1207. if (vport->fc_flag & FC_RSCN_DEFERRED)
  1208. return ndlp->nlp_state;
  1209. /* software abort outstanding ADISC */
  1210. lpfc_els_abort(phba, ndlp);
  1211. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  1212. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1213. spin_lock_irq(shost->host_lock);
  1214. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1215. spin_unlock_irq(shost->host_lock);
  1216. lpfc_disc_set_adisc(vport, ndlp);
  1217. return ndlp->nlp_state;
  1218. }
  1219. static uint32_t
  1220. lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
  1221. struct lpfc_nodelist *ndlp,
  1222. void *arg,
  1223. uint32_t evt)
  1224. {
  1225. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1226. lpfc_rcv_plogi(vport, ndlp, cmdiocb);
  1227. return ndlp->nlp_state;
  1228. }
  1229. static uint32_t
  1230. lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
  1231. struct lpfc_nodelist *ndlp,
  1232. void *arg,
  1233. uint32_t evt)
  1234. {
  1235. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1236. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  1237. return ndlp->nlp_state;
  1238. }
  1239. static uint32_t
  1240. lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
  1241. struct lpfc_nodelist *ndlp,
  1242. void *arg,
  1243. uint32_t evt)
  1244. {
  1245. struct lpfc_hba *phba = vport->phba;
  1246. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1247. LPFC_MBOXQ_t *mb;
  1248. LPFC_MBOXQ_t *nextmb;
  1249. struct lpfc_dmabuf *mp;
  1250. cmdiocb = (struct lpfc_iocbq *) arg;
  1251. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  1252. if ((mb = phba->sli.mbox_active)) {
  1253. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  1254. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1255. lpfc_nlp_put(ndlp);
  1256. mb->context2 = NULL;
  1257. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1258. }
  1259. }
  1260. spin_lock_irq(&phba->hbalock);
  1261. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  1262. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  1263. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1264. mp = (struct lpfc_dmabuf *) (mb->context1);
  1265. if (mp) {
  1266. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1267. kfree(mp);
  1268. }
  1269. lpfc_nlp_put(ndlp);
  1270. list_del(&mb->list);
  1271. phba->sli.mboxq_cnt--;
  1272. mempool_free(mb, phba->mbox_mem_pool);
  1273. }
  1274. }
  1275. spin_unlock_irq(&phba->hbalock);
  1276. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1277. return ndlp->nlp_state;
  1278. }
  1279. static uint32_t
  1280. lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
  1281. struct lpfc_nodelist *ndlp,
  1282. void *arg,
  1283. uint32_t evt)
  1284. {
  1285. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1286. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1287. return ndlp->nlp_state;
  1288. }
  1289. static uint32_t
  1290. lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
  1291. struct lpfc_nodelist *ndlp,
  1292. void *arg,
  1293. uint32_t evt)
  1294. {
  1295. struct lpfc_iocbq *cmdiocb;
  1296. cmdiocb = (struct lpfc_iocbq *) arg;
  1297. lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
  1298. return ndlp->nlp_state;
  1299. }
  1300. static uint32_t
  1301. lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
  1302. struct lpfc_nodelist *ndlp,
  1303. void *arg,
  1304. uint32_t evt)
  1305. {
  1306. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1307. LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
  1308. MAILBOX_t *mb = &pmb->u.mb;
  1309. uint32_t did = mb->un.varWords[1];
  1310. if (mb->mbxStatus) {
  1311. /* RegLogin failed */
  1312. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1313. "0246 RegLogin failed Data: x%x x%x x%x x%x "
  1314. "x%x\n",
  1315. did, mb->mbxStatus, vport->port_state,
  1316. mb->un.varRegLogin.vpi,
  1317. mb->un.varRegLogin.rpi);
  1318. /*
  1319. * If RegLogin failed due to lack of HBA resources do not
  1320. * retry discovery.
  1321. */
  1322. if (mb->mbxStatus == MBXERR_RPI_FULL) {
  1323. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1324. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1325. return ndlp->nlp_state;
  1326. }
  1327. /* Put ndlp in npr state set plogi timer for 1 sec */
  1328. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  1329. spin_lock_irq(shost->host_lock);
  1330. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1331. spin_unlock_irq(shost->host_lock);
  1332. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  1333. lpfc_issue_els_logo(vport, ndlp, 0);
  1334. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1335. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1336. return ndlp->nlp_state;
  1337. }
  1338. /* SLI4 ports have preallocated logical rpis. */
  1339. if (vport->phba->sli_rev < LPFC_SLI_REV4)
  1340. ndlp->nlp_rpi = mb->un.varWords[0];
  1341. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  1342. /* Only if we are not a fabric nport do we issue PRLI */
  1343. if (!(ndlp->nlp_type & NLP_FABRIC)) {
  1344. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1345. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  1346. lpfc_issue_els_prli(vport, ndlp, 0);
  1347. } else {
  1348. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1349. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1350. }
  1351. return ndlp->nlp_state;
  1352. }
  1353. static uint32_t
  1354. lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
  1355. struct lpfc_nodelist *ndlp,
  1356. void *arg,
  1357. uint32_t evt)
  1358. {
  1359. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1360. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1361. spin_lock_irq(shost->host_lock);
  1362. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1363. spin_unlock_irq(shost->host_lock);
  1364. return ndlp->nlp_state;
  1365. } else {
  1366. lpfc_drop_node(vport, ndlp);
  1367. return NLP_STE_FREED_NODE;
  1368. }
  1369. }
  1370. static uint32_t
  1371. lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
  1372. struct lpfc_nodelist *ndlp,
  1373. void *arg,
  1374. uint32_t evt)
  1375. {
  1376. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1377. /* Don't do anything that will mess up processing of the
  1378. * previous RSCN.
  1379. */
  1380. if (vport->fc_flag & FC_RSCN_DEFERRED)
  1381. return ndlp->nlp_state;
  1382. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1383. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1384. spin_lock_irq(shost->host_lock);
  1385. ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
  1386. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1387. spin_unlock_irq(shost->host_lock);
  1388. lpfc_disc_set_adisc(vport, ndlp);
  1389. return ndlp->nlp_state;
  1390. }
  1391. static uint32_t
  1392. lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1393. void *arg, uint32_t evt)
  1394. {
  1395. struct lpfc_iocbq *cmdiocb;
  1396. cmdiocb = (struct lpfc_iocbq *) arg;
  1397. lpfc_rcv_plogi(vport, ndlp, cmdiocb);
  1398. return ndlp->nlp_state;
  1399. }
  1400. static uint32_t
  1401. lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1402. void *arg, uint32_t evt)
  1403. {
  1404. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1405. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  1406. return ndlp->nlp_state;
  1407. }
  1408. static uint32_t
  1409. lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1410. void *arg, uint32_t evt)
  1411. {
  1412. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1413. /* Software abort outstanding PRLI before sending acc */
  1414. lpfc_els_abort(vport->phba, ndlp);
  1415. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1416. return ndlp->nlp_state;
  1417. }
  1418. static uint32_t
  1419. lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1420. void *arg, uint32_t evt)
  1421. {
  1422. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1423. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1424. return ndlp->nlp_state;
  1425. }
  1426. /* This routine is envoked when we rcv a PRLO request from a nport
  1427. * we are logged into. We should send back a PRLO rsp setting the
  1428. * appropriate bits.
  1429. * NEXT STATE = PRLI_ISSUE
  1430. */
  1431. static uint32_t
  1432. lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1433. void *arg, uint32_t evt)
  1434. {
  1435. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1436. lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
  1437. return ndlp->nlp_state;
  1438. }
  1439. static uint32_t
  1440. lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1441. void *arg, uint32_t evt)
  1442. {
  1443. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1444. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1445. struct lpfc_hba *phba = vport->phba;
  1446. IOCB_t *irsp;
  1447. PRLI *npr;
  1448. cmdiocb = (struct lpfc_iocbq *) arg;
  1449. rspiocb = cmdiocb->context_un.rsp_iocb;
  1450. npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
  1451. irsp = &rspiocb->iocb;
  1452. if (irsp->ulpStatus) {
  1453. if ((vport->port_type == LPFC_NPIV_PORT) &&
  1454. vport->cfg_restrict_login) {
  1455. goto out;
  1456. }
  1457. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1458. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1459. return ndlp->nlp_state;
  1460. }
  1461. /* Check out PRLI rsp */
  1462. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  1463. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  1464. if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
  1465. (npr->prliType == PRLI_FCP_TYPE)) {
  1466. if (npr->initiatorFunc)
  1467. ndlp->nlp_type |= NLP_FCP_INITIATOR;
  1468. if (npr->targetFunc)
  1469. ndlp->nlp_type |= NLP_FCP_TARGET;
  1470. if (npr->Retry)
  1471. ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
  1472. }
  1473. if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
  1474. (vport->port_type == LPFC_NPIV_PORT) &&
  1475. vport->cfg_restrict_login) {
  1476. out:
  1477. spin_lock_irq(shost->host_lock);
  1478. ndlp->nlp_flag |= NLP_TARGET_REMOVE;
  1479. spin_unlock_irq(shost->host_lock);
  1480. lpfc_issue_els_logo(vport, ndlp, 0);
  1481. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1482. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1483. return ndlp->nlp_state;
  1484. }
  1485. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1486. if (ndlp->nlp_type & NLP_FCP_TARGET)
  1487. lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
  1488. else
  1489. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1490. return ndlp->nlp_state;
  1491. }
  1492. /*! lpfc_device_rm_prli_issue
  1493. *
  1494. * \pre
  1495. * \post
  1496. * \param phba
  1497. * \param ndlp
  1498. * \param arg
  1499. * \param evt
  1500. * \return uint32_t
  1501. *
  1502. * \b Description:
  1503. * This routine is envoked when we a request to remove a nport we are in the
  1504. * process of PRLIing. We should software abort outstanding prli, unreg
  1505. * login, send a logout. We will change node state to UNUSED_NODE, put it
  1506. * on plogi list so it can be freed when LOGO completes.
  1507. *
  1508. */
  1509. static uint32_t
  1510. lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1511. void *arg, uint32_t evt)
  1512. {
  1513. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1514. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1515. spin_lock_irq(shost->host_lock);
  1516. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1517. spin_unlock_irq(shost->host_lock);
  1518. return ndlp->nlp_state;
  1519. } else {
  1520. /* software abort outstanding PLOGI */
  1521. lpfc_els_abort(vport->phba, ndlp);
  1522. lpfc_drop_node(vport, ndlp);
  1523. return NLP_STE_FREED_NODE;
  1524. }
  1525. }
  1526. /*! lpfc_device_recov_prli_issue
  1527. *
  1528. * \pre
  1529. * \post
  1530. * \param phba
  1531. * \param ndlp
  1532. * \param arg
  1533. * \param evt
  1534. * \return uint32_t
  1535. *
  1536. * \b Description:
  1537. * The routine is envoked when the state of a device is unknown, like
  1538. * during a link down. We should remove the nodelist entry from the
  1539. * unmapped list, issue a UNREG_LOGIN, do a software abort of the
  1540. * outstanding PRLI command, then free the node entry.
  1541. */
  1542. static uint32_t
  1543. lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
  1544. struct lpfc_nodelist *ndlp,
  1545. void *arg,
  1546. uint32_t evt)
  1547. {
  1548. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1549. struct lpfc_hba *phba = vport->phba;
  1550. /* Don't do anything that will mess up processing of the
  1551. * previous RSCN.
  1552. */
  1553. if (vport->fc_flag & FC_RSCN_DEFERRED)
  1554. return ndlp->nlp_state;
  1555. /* software abort outstanding PRLI */
  1556. lpfc_els_abort(phba, ndlp);
  1557. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1558. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1559. spin_lock_irq(shost->host_lock);
  1560. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1561. spin_unlock_irq(shost->host_lock);
  1562. lpfc_disc_set_adisc(vport, ndlp);
  1563. return ndlp->nlp_state;
  1564. }
  1565. static uint32_t
  1566. lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1567. void *arg, uint32_t evt)
  1568. {
  1569. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1570. lpfc_rcv_plogi(vport, ndlp, cmdiocb);
  1571. return ndlp->nlp_state;
  1572. }
  1573. static uint32_t
  1574. lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1575. void *arg, uint32_t evt)
  1576. {
  1577. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1578. lpfc_rcv_prli(vport, ndlp, cmdiocb);
  1579. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  1580. return ndlp->nlp_state;
  1581. }
  1582. static uint32_t
  1583. lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1584. void *arg, uint32_t evt)
  1585. {
  1586. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1587. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1588. return ndlp->nlp_state;
  1589. }
  1590. static uint32_t
  1591. lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1592. void *arg, uint32_t evt)
  1593. {
  1594. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1595. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1596. return ndlp->nlp_state;
  1597. }
  1598. static uint32_t
  1599. lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1600. void *arg, uint32_t evt)
  1601. {
  1602. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1603. lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
  1604. return ndlp->nlp_state;
  1605. }
  1606. static uint32_t
  1607. lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
  1608. struct lpfc_nodelist *ndlp,
  1609. void *arg,
  1610. uint32_t evt)
  1611. {
  1612. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1613. ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
  1614. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1615. spin_lock_irq(shost->host_lock);
  1616. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1617. spin_unlock_irq(shost->host_lock);
  1618. lpfc_disc_set_adisc(vport, ndlp);
  1619. return ndlp->nlp_state;
  1620. }
  1621. static uint32_t
  1622. lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1623. void *arg, uint32_t evt)
  1624. {
  1625. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1626. lpfc_rcv_plogi(vport, ndlp, cmdiocb);
  1627. return ndlp->nlp_state;
  1628. }
  1629. static uint32_t
  1630. lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1631. void *arg, uint32_t evt)
  1632. {
  1633. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1634. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  1635. return ndlp->nlp_state;
  1636. }
  1637. static uint32_t
  1638. lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1639. void *arg, uint32_t evt)
  1640. {
  1641. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1642. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1643. return ndlp->nlp_state;
  1644. }
  1645. static uint32_t
  1646. lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
  1647. struct lpfc_nodelist *ndlp,
  1648. void *arg, uint32_t evt)
  1649. {
  1650. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1651. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1652. return ndlp->nlp_state;
  1653. }
  1654. static uint32_t
  1655. lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1656. void *arg, uint32_t evt)
  1657. {
  1658. struct lpfc_hba *phba = vport->phba;
  1659. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1660. /* flush the target */
  1661. lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
  1662. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  1663. /* Treat like rcv logo */
  1664. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
  1665. return ndlp->nlp_state;
  1666. }
  1667. static uint32_t
  1668. lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
  1669. struct lpfc_nodelist *ndlp,
  1670. void *arg,
  1671. uint32_t evt)
  1672. {
  1673. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1674. ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
  1675. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1676. spin_lock_irq(shost->host_lock);
  1677. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1678. spin_unlock_irq(shost->host_lock);
  1679. lpfc_disc_set_adisc(vport, ndlp);
  1680. return ndlp->nlp_state;
  1681. }
  1682. static uint32_t
  1683. lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1684. void *arg, uint32_t evt)
  1685. {
  1686. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1687. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1688. /* Ignore PLOGI if we have an outstanding LOGO */
  1689. if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
  1690. return ndlp->nlp_state;
  1691. if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
  1692. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  1693. spin_lock_irq(shost->host_lock);
  1694. ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
  1695. spin_unlock_irq(shost->host_lock);
  1696. } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
  1697. /* send PLOGI immediately, move to PLOGI issue state */
  1698. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1699. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1700. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  1701. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  1702. }
  1703. }
  1704. return ndlp->nlp_state;
  1705. }
  1706. static uint32_t
  1707. lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1708. void *arg, uint32_t evt)
  1709. {
  1710. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1711. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1712. struct ls_rjt stat;
  1713. memset(&stat, 0, sizeof (struct ls_rjt));
  1714. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1715. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1716. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  1717. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1718. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  1719. spin_lock_irq(shost->host_lock);
  1720. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1721. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1722. spin_unlock_irq(shost->host_lock);
  1723. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  1724. lpfc_issue_els_adisc(vport, ndlp, 0);
  1725. } else {
  1726. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1727. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  1728. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  1729. }
  1730. }
  1731. return ndlp->nlp_state;
  1732. }
  1733. static uint32_t
  1734. lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1735. void *arg, uint32_t evt)
  1736. {
  1737. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1738. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1739. return ndlp->nlp_state;
  1740. }
  1741. static uint32_t
  1742. lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1743. void *arg, uint32_t evt)
  1744. {
  1745. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1746. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1747. /*
  1748. * Do not start discovery if discovery is about to start
  1749. * or discovery in progress for this node. Starting discovery
  1750. * here will affect the counting of discovery threads.
  1751. */
  1752. if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
  1753. !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
  1754. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  1755. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1756. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1757. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  1758. lpfc_issue_els_adisc(vport, ndlp, 0);
  1759. } else {
  1760. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1761. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  1762. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  1763. }
  1764. }
  1765. return ndlp->nlp_state;
  1766. }
  1767. static uint32_t
  1768. lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1769. void *arg, uint32_t evt)
  1770. {
  1771. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1772. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1773. spin_lock_irq(shost->host_lock);
  1774. ndlp->nlp_flag |= NLP_LOGO_ACC;
  1775. spin_unlock_irq(shost->host_lock);
  1776. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  1777. if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
  1778. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  1779. spin_lock_irq(shost->host_lock);
  1780. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1781. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1782. spin_unlock_irq(shost->host_lock);
  1783. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  1784. } else {
  1785. spin_lock_irq(shost->host_lock);
  1786. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1787. spin_unlock_irq(shost->host_lock);
  1788. }
  1789. return ndlp->nlp_state;
  1790. }
  1791. static uint32_t
  1792. lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1793. void *arg, uint32_t evt)
  1794. {
  1795. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1796. IOCB_t *irsp;
  1797. cmdiocb = (struct lpfc_iocbq *) arg;
  1798. rspiocb = cmdiocb->context_un.rsp_iocb;
  1799. irsp = &rspiocb->iocb;
  1800. if (irsp->ulpStatus) {
  1801. ndlp->nlp_flag |= NLP_DEFER_RM;
  1802. return NLP_STE_FREED_NODE;
  1803. }
  1804. return ndlp->nlp_state;
  1805. }
  1806. static uint32_t
  1807. lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1808. void *arg, uint32_t evt)
  1809. {
  1810. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1811. IOCB_t *irsp;
  1812. cmdiocb = (struct lpfc_iocbq *) arg;
  1813. rspiocb = cmdiocb->context_un.rsp_iocb;
  1814. irsp = &rspiocb->iocb;
  1815. if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
  1816. lpfc_drop_node(vport, ndlp);
  1817. return NLP_STE_FREED_NODE;
  1818. }
  1819. return ndlp->nlp_state;
  1820. }
  1821. static uint32_t
  1822. lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1823. void *arg, uint32_t evt)
  1824. {
  1825. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1826. if (ndlp->nlp_DID == Fabric_DID) {
  1827. spin_lock_irq(shost->host_lock);
  1828. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  1829. spin_unlock_irq(shost->host_lock);
  1830. }
  1831. lpfc_unreg_rpi(vport, ndlp);
  1832. return ndlp->nlp_state;
  1833. }
  1834. static uint32_t
  1835. lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1836. void *arg, uint32_t evt)
  1837. {
  1838. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1839. IOCB_t *irsp;
  1840. cmdiocb = (struct lpfc_iocbq *) arg;
  1841. rspiocb = cmdiocb->context_un.rsp_iocb;
  1842. irsp = &rspiocb->iocb;
  1843. if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
  1844. lpfc_drop_node(vport, ndlp);
  1845. return NLP_STE_FREED_NODE;
  1846. }
  1847. return ndlp->nlp_state;
  1848. }
  1849. static uint32_t
  1850. lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
  1851. struct lpfc_nodelist *ndlp,
  1852. void *arg, uint32_t evt)
  1853. {
  1854. LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
  1855. MAILBOX_t *mb = &pmb->u.mb;
  1856. if (!mb->mbxStatus) {
  1857. /* SLI4 ports have preallocated logical rpis. */
  1858. if (vport->phba->sli_rev < LPFC_SLI_REV4)
  1859. ndlp->nlp_rpi = mb->un.varWords[0];
  1860. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  1861. } else {
  1862. if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
  1863. lpfc_drop_node(vport, ndlp);
  1864. return NLP_STE_FREED_NODE;
  1865. }
  1866. }
  1867. return ndlp->nlp_state;
  1868. }
  1869. static uint32_t
  1870. lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1871. void *arg, uint32_t evt)
  1872. {
  1873. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1874. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1875. spin_lock_irq(shost->host_lock);
  1876. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1877. spin_unlock_irq(shost->host_lock);
  1878. return ndlp->nlp_state;
  1879. }
  1880. lpfc_drop_node(vport, ndlp);
  1881. return NLP_STE_FREED_NODE;
  1882. }
  1883. static uint32_t
  1884. lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1885. void *arg, uint32_t evt)
  1886. {
  1887. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1888. /* Don't do anything that will mess up processing of the
  1889. * previous RSCN.
  1890. */
  1891. if (vport->fc_flag & FC_RSCN_DEFERRED)
  1892. return ndlp->nlp_state;
  1893. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  1894. spin_lock_irq(shost->host_lock);
  1895. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1896. spin_unlock_irq(shost->host_lock);
  1897. return ndlp->nlp_state;
  1898. }
  1899. /* This next section defines the NPort Discovery State Machine */
  1900. /* There are 4 different double linked lists nodelist entries can reside on.
  1901. * The plogi list and adisc list are used when Link Up discovery or RSCN
  1902. * processing is needed. Each list holds the nodes that we will send PLOGI
  1903. * or ADISC on. These lists will keep track of what nodes will be effected
  1904. * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
  1905. * The unmapped_list will contain all nodes that we have successfully logged
  1906. * into at the Fibre Channel level. The mapped_list will contain all nodes
  1907. * that are mapped FCP targets.
  1908. */
  1909. /*
  1910. * The bind list is a list of undiscovered (potentially non-existent) nodes
  1911. * that we have saved binding information on. This information is used when
  1912. * nodes transition from the unmapped to the mapped list.
  1913. */
  1914. /* For UNUSED_NODE state, the node has just been allocated .
  1915. * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
  1916. * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
  1917. * and put on the unmapped list. For ADISC processing, the node is taken off
  1918. * the ADISC list and placed on either the mapped or unmapped list (depending
  1919. * on its previous state). Once on the unmapped list, a PRLI is issued and the
  1920. * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
  1921. * changed to UNMAPPED_NODE. If the completion indicates a mapped
  1922. * node, the node is taken off the unmapped list. The binding list is checked
  1923. * for a valid binding, or a binding is automatically assigned. If binding
  1924. * assignment is unsuccessful, the node is left on the unmapped list. If
  1925. * binding assignment is successful, the associated binding list entry (if
  1926. * any) is removed, and the node is placed on the mapped list.
  1927. */
  1928. /*
  1929. * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
  1930. * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
  1931. * expire, all effected nodes will receive a DEVICE_RM event.
  1932. */
  1933. /*
  1934. * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
  1935. * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
  1936. * check, additional nodes may be added or removed (via DEVICE_RM) to / from
  1937. * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
  1938. * we will first process the ADISC list. 32 entries are processed initially and
  1939. * ADISC is initited for each one. Completions / Events for each node are
  1940. * funnelled thru the state machine. As each node finishes ADISC processing, it
  1941. * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
  1942. * waiting, and the ADISC list count is identically 0, then we are done. For
  1943. * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
  1944. * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
  1945. * list. 32 entries are processed initially and PLOGI is initited for each one.
  1946. * Completions / Events for each node are funnelled thru the state machine. As
  1947. * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
  1948. * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
  1949. * indentically 0, then we are done. We have now completed discovery / RSCN
  1950. * handling. Upon completion, ALL nodes should be on either the mapped or
  1951. * unmapped lists.
  1952. */
  1953. static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
  1954. (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
  1955. /* Action routine Event Current State */
  1956. lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
  1957. lpfc_rcv_els_unused_node, /* RCV_PRLI */
  1958. lpfc_rcv_logo_unused_node, /* RCV_LOGO */
  1959. lpfc_rcv_els_unused_node, /* RCV_ADISC */
  1960. lpfc_rcv_els_unused_node, /* RCV_PDISC */
  1961. lpfc_rcv_els_unused_node, /* RCV_PRLO */
  1962. lpfc_disc_illegal, /* CMPL_PLOGI */
  1963. lpfc_disc_illegal, /* CMPL_PRLI */
  1964. lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
  1965. lpfc_disc_illegal, /* CMPL_ADISC */
  1966. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1967. lpfc_device_rm_unused_node, /* DEVICE_RM */
  1968. lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
  1969. lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
  1970. lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
  1971. lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
  1972. lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
  1973. lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
  1974. lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
  1975. lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
  1976. lpfc_disc_illegal, /* CMPL_PRLI */
  1977. lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
  1978. lpfc_disc_illegal, /* CMPL_ADISC */
  1979. lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
  1980. lpfc_device_rm_plogi_issue, /* DEVICE_RM */
  1981. lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
  1982. lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
  1983. lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
  1984. lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
  1985. lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
  1986. lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
  1987. lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
  1988. lpfc_disc_illegal, /* CMPL_PLOGI */
  1989. lpfc_disc_illegal, /* CMPL_PRLI */
  1990. lpfc_disc_illegal, /* CMPL_LOGO */
  1991. lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
  1992. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1993. lpfc_device_rm_adisc_issue, /* DEVICE_RM */
  1994. lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
  1995. lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
  1996. lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
  1997. lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
  1998. lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
  1999. lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
  2000. lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
  2001. lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
  2002. lpfc_disc_illegal, /* CMPL_PRLI */
  2003. lpfc_disc_illegal, /* CMPL_LOGO */
  2004. lpfc_disc_illegal, /* CMPL_ADISC */
  2005. lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
  2006. lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
  2007. lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
  2008. lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
  2009. lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
  2010. lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
  2011. lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
  2012. lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
  2013. lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
  2014. lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
  2015. lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
  2016. lpfc_disc_illegal, /* CMPL_LOGO */
  2017. lpfc_disc_illegal, /* CMPL_ADISC */
  2018. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2019. lpfc_device_rm_prli_issue, /* DEVICE_RM */
  2020. lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
  2021. lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
  2022. lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
  2023. lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
  2024. lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
  2025. lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
  2026. lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
  2027. lpfc_disc_illegal, /* CMPL_PLOGI */
  2028. lpfc_disc_illegal, /* CMPL_PRLI */
  2029. lpfc_disc_illegal, /* CMPL_LOGO */
  2030. lpfc_disc_illegal, /* CMPL_ADISC */
  2031. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2032. lpfc_disc_illegal, /* DEVICE_RM */
  2033. lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
  2034. lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
  2035. lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
  2036. lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
  2037. lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
  2038. lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
  2039. lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
  2040. lpfc_disc_illegal, /* CMPL_PLOGI */
  2041. lpfc_disc_illegal, /* CMPL_PRLI */
  2042. lpfc_disc_illegal, /* CMPL_LOGO */
  2043. lpfc_disc_illegal, /* CMPL_ADISC */
  2044. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2045. lpfc_disc_illegal, /* DEVICE_RM */
  2046. lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
  2047. lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
  2048. lpfc_rcv_prli_npr_node, /* RCV_PRLI */
  2049. lpfc_rcv_logo_npr_node, /* RCV_LOGO */
  2050. lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
  2051. lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
  2052. lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
  2053. lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
  2054. lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
  2055. lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
  2056. lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
  2057. lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
  2058. lpfc_device_rm_npr_node, /* DEVICE_RM */
  2059. lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
  2060. };
  2061. int
  2062. lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2063. void *arg, uint32_t evt)
  2064. {
  2065. uint32_t cur_state, rc;
  2066. uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
  2067. uint32_t);
  2068. uint32_t got_ndlp = 0;
  2069. if (lpfc_nlp_get(ndlp))
  2070. got_ndlp = 1;
  2071. cur_state = ndlp->nlp_state;
  2072. /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
  2073. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2074. "0211 DSM in event x%x on NPort x%x in "
  2075. "state %d Data: x%x\n",
  2076. evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
  2077. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
  2078. "DSM in: evt:%d ste:%d did:x%x",
  2079. evt, cur_state, ndlp->nlp_DID);
  2080. func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
  2081. rc = (func) (vport, ndlp, arg, evt);
  2082. /* DSM out state <rc> on NPort <nlp_DID> */
  2083. if (got_ndlp) {
  2084. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2085. "0212 DSM out state %d on NPort x%x Data: x%x\n",
  2086. rc, ndlp->nlp_DID, ndlp->nlp_flag);
  2087. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
  2088. "DSM out: ste:%d did:x%x flg:x%x",
  2089. rc, ndlp->nlp_DID, ndlp->nlp_flag);
  2090. /* Decrement the ndlp reference count held for this function */
  2091. lpfc_nlp_put(ndlp);
  2092. } else {
  2093. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2094. "0213 DSM out state %d on NPort free\n", rc);
  2095. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
  2096. "DSM out: ste:%d did:x%x flg:x%x",
  2097. rc, 0, 0);
  2098. }
  2099. return rc;
  2100. }