lpfc_nportdisc.c 64 KB

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