lpfc_nportdisc.c 64 KB

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