lpfc_nportdisc.c 71 KB

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