lpfc_nportdisc.c 65 KB

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