lpfc_nportdisc.c 68 KB

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