lpfc_nportdisc.c 63 KB

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