lpfc_nportdisc.c 65 KB

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