lpfc_nportdisc.c 62 KB

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