lpfc_nportdisc.c 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  10. * *
  11. * This program is free software; you can redistribute it and/or *
  12. * modify it under the terms of version 2 of the GNU General *
  13. * Public License as published by the Free Software Foundation. *
  14. * This program is distributed in the hope that it will be useful. *
  15. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  16. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  17. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  18. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  19. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  20. * more details, a copy of which can be found in the file COPYING *
  21. * included with this package. *
  22. *******************************************************************/
  23. #include <linux/blkdev.h>
  24. #include <linux/pci.h>
  25. #include <linux/slab.h>
  26. #include <linux/interrupt.h>
  27. #include <scsi/scsi.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/nvme-fc-driver.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc.h"
  40. #include "lpfc_scsi.h"
  41. #include "lpfc_nvme.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_crtn.h"
  44. #include "lpfc_vport.h"
  45. #include "lpfc_debugfs.h"
  46. /* Called to verify a rcv'ed ADISC was intended for us. */
  47. static int
  48. lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  49. struct lpfc_name *nn, struct lpfc_name *pn)
  50. {
  51. /* First, we MUST have a RPI registered */
  52. if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
  53. return 0;
  54. /* Compare the ADISC rsp WWNN / WWPN matches our internal node
  55. * table entry for that node.
  56. */
  57. if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
  58. return 0;
  59. if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
  60. return 0;
  61. /* we match, return success */
  62. return 1;
  63. }
  64. int
  65. lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  66. struct serv_parm *sp, uint32_t class, int flogi)
  67. {
  68. volatile struct serv_parm *hsp = &vport->fc_sparam;
  69. uint16_t hsp_value, ssp_value = 0;
  70. /*
  71. * The receive data field size and buffer-to-buffer receive data field
  72. * size entries are 16 bits but are represented as two 8-bit fields in
  73. * the driver data structure to account for rsvd bits and other control
  74. * bits. Reconstruct and compare the fields as a 16-bit values before
  75. * correcting the byte values.
  76. */
  77. if (sp->cls1.classValid) {
  78. if (!flogi) {
  79. hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
  80. hsp->cls1.rcvDataSizeLsb);
  81. ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
  82. sp->cls1.rcvDataSizeLsb);
  83. if (!ssp_value)
  84. goto bad_service_param;
  85. if (ssp_value > hsp_value) {
  86. sp->cls1.rcvDataSizeLsb =
  87. hsp->cls1.rcvDataSizeLsb;
  88. sp->cls1.rcvDataSizeMsb =
  89. hsp->cls1.rcvDataSizeMsb;
  90. }
  91. }
  92. } else if (class == CLASS1)
  93. goto bad_service_param;
  94. if (sp->cls2.classValid) {
  95. if (!flogi) {
  96. hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
  97. hsp->cls2.rcvDataSizeLsb);
  98. ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
  99. sp->cls2.rcvDataSizeLsb);
  100. if (!ssp_value)
  101. goto bad_service_param;
  102. if (ssp_value > hsp_value) {
  103. sp->cls2.rcvDataSizeLsb =
  104. hsp->cls2.rcvDataSizeLsb;
  105. sp->cls2.rcvDataSizeMsb =
  106. hsp->cls2.rcvDataSizeMsb;
  107. }
  108. }
  109. } else if (class == CLASS2)
  110. goto bad_service_param;
  111. if (sp->cls3.classValid) {
  112. if (!flogi) {
  113. hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
  114. hsp->cls3.rcvDataSizeLsb);
  115. ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
  116. sp->cls3.rcvDataSizeLsb);
  117. if (!ssp_value)
  118. goto bad_service_param;
  119. if (ssp_value > hsp_value) {
  120. sp->cls3.rcvDataSizeLsb =
  121. hsp->cls3.rcvDataSizeLsb;
  122. sp->cls3.rcvDataSizeMsb =
  123. hsp->cls3.rcvDataSizeMsb;
  124. }
  125. }
  126. } else if (class == CLASS3)
  127. goto bad_service_param;
  128. /*
  129. * Preserve the upper four bits of the MSB from the PLOGI response.
  130. * These bits contain the Buffer-to-Buffer State Change Number
  131. * from the target and need to be passed to the FW.
  132. */
  133. hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
  134. ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
  135. if (ssp_value > hsp_value) {
  136. sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
  137. sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
  138. (hsp->cmn.bbRcvSizeMsb & 0x0F);
  139. }
  140. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
  141. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
  142. return 1;
  143. bad_service_param:
  144. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  145. "0207 Device %x "
  146. "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
  147. "invalid service parameters. Ignoring device.\n",
  148. ndlp->nlp_DID,
  149. sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
  150. sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
  151. sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
  152. sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
  153. return 0;
  154. }
  155. static void *
  156. lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  157. struct lpfc_iocbq *rspiocb)
  158. {
  159. struct lpfc_dmabuf *pcmd, *prsp;
  160. uint32_t *lp;
  161. void *ptr = NULL;
  162. IOCB_t *irsp;
  163. irsp = &rspiocb->iocb;
  164. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  165. /* For lpfc_els_abort, context2 could be zero'ed to delay
  166. * freeing associated memory till after ABTS completes.
  167. */
  168. if (pcmd) {
  169. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
  170. list);
  171. if (prsp) {
  172. lp = (uint32_t *) prsp->virt;
  173. ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
  174. }
  175. } else {
  176. /* Force ulpStatus error since we are returning NULL ptr */
  177. if (!(irsp->ulpStatus)) {
  178. irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
  179. irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
  180. }
  181. ptr = NULL;
  182. }
  183. return ptr;
  184. }
  185. /*
  186. * Free resources / clean up outstanding I/Os
  187. * associated with a LPFC_NODELIST entry. This
  188. * routine effectively results in a "software abort".
  189. */
  190. void
  191. lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  192. {
  193. LIST_HEAD(abort_list);
  194. struct lpfc_sli_ring *pring;
  195. struct lpfc_iocbq *iocb, *next_iocb;
  196. pring = lpfc_phba_elsring(phba);
  197. /* In case of error recovery path, we might have a NULL pring here */
  198. if (unlikely(!pring))
  199. return;
  200. /* Abort outstanding I/O on NPort <nlp_DID> */
  201. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
  202. "2819 Abort outstanding I/O on NPort x%x "
  203. "Data: x%x x%x x%x\n",
  204. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  205. ndlp->nlp_rpi);
  206. /* Clean up all fabric IOs first.*/
  207. lpfc_fabric_abort_nport(ndlp);
  208. /*
  209. * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
  210. * of all ELS IOs that need an ABTS. The IOs need to stay on the
  211. * txcmplq so that the abort operation completes them successfully.
  212. */
  213. spin_lock_irq(&phba->hbalock);
  214. if (phba->sli_rev == LPFC_SLI_REV4)
  215. spin_lock(&pring->ring_lock);
  216. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  217. /* Add to abort_list on on NDLP match. */
  218. if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
  219. list_add_tail(&iocb->dlist, &abort_list);
  220. }
  221. if (phba->sli_rev == LPFC_SLI_REV4)
  222. spin_unlock(&pring->ring_lock);
  223. spin_unlock_irq(&phba->hbalock);
  224. /* Abort the targeted IOs and remove them from the abort list. */
  225. list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
  226. spin_lock_irq(&phba->hbalock);
  227. list_del_init(&iocb->dlist);
  228. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  229. spin_unlock_irq(&phba->hbalock);
  230. }
  231. INIT_LIST_HEAD(&abort_list);
  232. /* Now process the txq */
  233. spin_lock_irq(&phba->hbalock);
  234. if (phba->sli_rev == LPFC_SLI_REV4)
  235. spin_lock(&pring->ring_lock);
  236. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  237. /* Check to see if iocb matches the nport we are looking for */
  238. if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
  239. list_del_init(&iocb->list);
  240. list_add_tail(&iocb->list, &abort_list);
  241. }
  242. }
  243. if (phba->sli_rev == LPFC_SLI_REV4)
  244. spin_unlock(&pring->ring_lock);
  245. spin_unlock_irq(&phba->hbalock);
  246. /* Cancel all the IOCBs from the completions list */
  247. lpfc_sli_cancel_iocbs(phba, &abort_list,
  248. IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
  249. lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
  250. }
  251. static int
  252. lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  253. struct lpfc_iocbq *cmdiocb)
  254. {
  255. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  256. struct lpfc_hba *phba = vport->phba;
  257. struct lpfc_dmabuf *pcmd;
  258. uint64_t nlp_portwwn = 0;
  259. uint32_t *lp;
  260. IOCB_t *icmd;
  261. struct serv_parm *sp;
  262. uint32_t ed_tov;
  263. LPFC_MBOXQ_t *mbox;
  264. struct ls_rjt stat;
  265. uint32_t vid, flag;
  266. int rc;
  267. memset(&stat, 0, sizeof (struct ls_rjt));
  268. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  269. lp = (uint32_t *) pcmd->virt;
  270. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  271. if (wwn_to_u64(sp->portName.u.wwn) == 0) {
  272. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  273. "0140 PLOGI Reject: invalid nname\n");
  274. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  275. stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
  276. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  277. NULL);
  278. return 0;
  279. }
  280. if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
  281. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  282. "0141 PLOGI Reject: invalid pname\n");
  283. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  284. stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
  285. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  286. NULL);
  287. return 0;
  288. }
  289. nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  290. if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
  291. /* Reject this request because invalid parameters */
  292. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  293. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  294. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  295. NULL);
  296. return 0;
  297. }
  298. icmd = &cmdiocb->iocb;
  299. /* PLOGI chkparm OK */
  300. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  301. "0114 PLOGI chkparm OK Data: x%x x%x x%x "
  302. "x%x x%x x%x\n",
  303. ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
  304. ndlp->nlp_rpi, vport->port_state,
  305. vport->fc_flag);
  306. if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
  307. ndlp->nlp_fcp_info |= CLASS2;
  308. else
  309. ndlp->nlp_fcp_info |= CLASS3;
  310. ndlp->nlp_class_sup = 0;
  311. if (sp->cls1.classValid)
  312. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  313. if (sp->cls2.classValid)
  314. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  315. if (sp->cls3.classValid)
  316. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  317. if (sp->cls4.classValid)
  318. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  319. ndlp->nlp_maxframe =
  320. ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
  321. /* if already logged in, do implicit logout */
  322. switch (ndlp->nlp_state) {
  323. case NLP_STE_NPR_NODE:
  324. if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
  325. break;
  326. case NLP_STE_REG_LOGIN_ISSUE:
  327. case NLP_STE_PRLI_ISSUE:
  328. case NLP_STE_UNMAPPED_NODE:
  329. case NLP_STE_MAPPED_NODE:
  330. /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
  331. * For target mode, execute implicit logo.
  332. * Fabric nodes go into NPR.
  333. */
  334. if (!(ndlp->nlp_type & NLP_FABRIC) &&
  335. !(phba->nvmet_support)) {
  336. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
  337. ndlp, NULL);
  338. return 1;
  339. }
  340. if (nlp_portwwn != 0 &&
  341. nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
  342. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  343. "0143 PLOGI recv'd from DID: x%x "
  344. "WWPN changed: old %llx new %llx\n",
  345. ndlp->nlp_DID,
  346. (unsigned long long)nlp_portwwn,
  347. (unsigned long long)
  348. wwn_to_u64(sp->portName.u.wwn));
  349. ndlp->nlp_prev_state = ndlp->nlp_state;
  350. /* rport needs to be unregistered first */
  351. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  352. break;
  353. }
  354. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  355. ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
  356. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  357. ndlp->nlp_flag &= ~NLP_FIRSTBURST;
  358. /* Check for Nport to NPort pt2pt protocol */
  359. if ((vport->fc_flag & FC_PT2PT) &&
  360. !(vport->fc_flag & FC_PT2PT_PLOGI)) {
  361. /* rcv'ed PLOGI decides what our NPortId will be */
  362. vport->fc_myDID = icmd->un.rcvels.parmRo;
  363. ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
  364. if (sp->cmn.edtovResolution) {
  365. /* E_D_TOV ticks are in nanoseconds */
  366. ed_tov = (phba->fc_edtov + 999999) / 1000000;
  367. }
  368. /*
  369. * For pt-to-pt, use the larger EDTOV
  370. * RATOV = 2 * EDTOV
  371. */
  372. if (ed_tov > phba->fc_edtov)
  373. phba->fc_edtov = ed_tov;
  374. phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
  375. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  376. /* Issue config_link / reg_vfi to account for updated TOV's */
  377. if (phba->sli_rev == LPFC_SLI_REV4)
  378. lpfc_issue_reg_vfi(vport);
  379. else {
  380. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  381. if (mbox == NULL)
  382. goto out;
  383. lpfc_config_link(phba, mbox);
  384. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  385. mbox->vport = vport;
  386. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  387. if (rc == MBX_NOT_FINISHED) {
  388. mempool_free(mbox, phba->mbox_mem_pool);
  389. goto out;
  390. }
  391. }
  392. lpfc_can_disctmo(vport);
  393. }
  394. ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
  395. if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
  396. sp->cmn.valid_vendor_ver_level) {
  397. vid = be32_to_cpu(sp->un.vv.vid);
  398. flag = be32_to_cpu(sp->un.vv.flags);
  399. if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
  400. ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
  401. }
  402. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  403. if (!mbox)
  404. goto out;
  405. /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
  406. if (phba->sli_rev == LPFC_SLI_REV4)
  407. lpfc_unreg_rpi(vport, ndlp);
  408. rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
  409. (uint8_t *) sp, mbox, ndlp->nlp_rpi);
  410. if (rc) {
  411. mempool_free(mbox, phba->mbox_mem_pool);
  412. goto out;
  413. }
  414. /* ACC PLOGI rsp command needs to execute first,
  415. * queue this mbox command to be processed later.
  416. */
  417. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  418. /*
  419. * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
  420. * command issued in lpfc_cmpl_els_acc().
  421. */
  422. mbox->vport = vport;
  423. spin_lock_irq(shost->host_lock);
  424. ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
  425. spin_unlock_irq(shost->host_lock);
  426. /*
  427. * If there is an outstanding PLOGI issued, abort it before
  428. * sending ACC rsp for received PLOGI. If pending plogi
  429. * is not canceled here, the plogi will be rejected by
  430. * remote port and will be retried. On a configuration with
  431. * single discovery thread, this will cause a huge delay in
  432. * discovery. Also this will cause multiple state machines
  433. * running in parallel for this node.
  434. * This only applies to a fabric environment.
  435. */
  436. if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
  437. (vport->fc_flag & FC_FABRIC)) {
  438. /* software abort outstanding PLOGI */
  439. lpfc_els_abort(phba, ndlp);
  440. }
  441. if ((vport->port_type == LPFC_NPIV_PORT &&
  442. vport->cfg_restrict_login)) {
  443. /* In order to preserve RPIs, we want to cleanup
  444. * the default RPI the firmware created to rcv
  445. * this ELS request. The only way to do this is
  446. * to register, then unregister the RPI.
  447. */
  448. spin_lock_irq(shost->host_lock);
  449. ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
  450. spin_unlock_irq(shost->host_lock);
  451. stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
  452. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  453. rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
  454. ndlp, mbox);
  455. if (rc)
  456. mempool_free(mbox, phba->mbox_mem_pool);
  457. return 1;
  458. }
  459. rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
  460. if (rc)
  461. mempool_free(mbox, phba->mbox_mem_pool);
  462. return 1;
  463. out:
  464. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  465. stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
  466. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  467. return 0;
  468. }
  469. /**
  470. * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
  471. * @phba: pointer to lpfc hba data structure.
  472. * @mboxq: pointer to mailbox object
  473. *
  474. * This routine is invoked to issue a completion to a rcv'ed
  475. * ADISC or PDISC after the paused RPI has been resumed.
  476. **/
  477. static void
  478. lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  479. {
  480. struct lpfc_vport *vport;
  481. struct lpfc_iocbq *elsiocb;
  482. struct lpfc_nodelist *ndlp;
  483. uint32_t cmd;
  484. elsiocb = (struct lpfc_iocbq *)mboxq->context1;
  485. ndlp = (struct lpfc_nodelist *) mboxq->context2;
  486. vport = mboxq->vport;
  487. cmd = elsiocb->drvrTimeout;
  488. if (cmd == ELS_CMD_ADISC) {
  489. lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
  490. } else {
  491. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
  492. ndlp, NULL);
  493. }
  494. kfree(elsiocb);
  495. mempool_free(mboxq, phba->mbox_mem_pool);
  496. }
  497. static int
  498. lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  499. struct lpfc_iocbq *cmdiocb)
  500. {
  501. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  502. struct lpfc_iocbq *elsiocb;
  503. struct lpfc_dmabuf *pcmd;
  504. struct serv_parm *sp;
  505. struct lpfc_name *pnn, *ppn;
  506. struct ls_rjt stat;
  507. ADISC *ap;
  508. IOCB_t *icmd;
  509. uint32_t *lp;
  510. uint32_t cmd;
  511. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  512. lp = (uint32_t *) pcmd->virt;
  513. cmd = *lp++;
  514. if (cmd == ELS_CMD_ADISC) {
  515. ap = (ADISC *) lp;
  516. pnn = (struct lpfc_name *) & ap->nodeName;
  517. ppn = (struct lpfc_name *) & ap->portName;
  518. } else {
  519. sp = (struct serv_parm *) lp;
  520. pnn = (struct lpfc_name *) & sp->nodeName;
  521. ppn = (struct lpfc_name *) & sp->portName;
  522. }
  523. icmd = &cmdiocb->iocb;
  524. if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
  525. /*
  526. * As soon as we send ACC, the remote NPort can
  527. * start sending us data. Thus, for SLI4 we must
  528. * resume the RPI before the ACC goes out.
  529. */
  530. if (vport->phba->sli_rev == LPFC_SLI_REV4) {
  531. elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
  532. GFP_KERNEL);
  533. if (elsiocb) {
  534. /* Save info from cmd IOCB used in rsp */
  535. memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
  536. sizeof(struct lpfc_iocbq));
  537. /* Save the ELS cmd */
  538. elsiocb->drvrTimeout = cmd;
  539. lpfc_sli4_resume_rpi(ndlp,
  540. lpfc_mbx_cmpl_resume_rpi, elsiocb);
  541. goto out;
  542. }
  543. }
  544. if (cmd == ELS_CMD_ADISC) {
  545. lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
  546. } else {
  547. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
  548. ndlp, NULL);
  549. }
  550. out:
  551. /* If we are authenticated, move to the proper state */
  552. if (ndlp->nlp_type & NLP_FCP_TARGET)
  553. lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
  554. else
  555. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  556. return 1;
  557. }
  558. /* Reject this request because invalid parameters */
  559. stat.un.b.lsRjtRsvd0 = 0;
  560. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  561. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  562. stat.un.b.vendorUnique = 0;
  563. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  564. /* 1 sec timeout */
  565. mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
  566. spin_lock_irq(shost->host_lock);
  567. ndlp->nlp_flag |= NLP_DELAY_TMO;
  568. spin_unlock_irq(shost->host_lock);
  569. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  570. ndlp->nlp_prev_state = ndlp->nlp_state;
  571. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  572. return 0;
  573. }
  574. static int
  575. lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  576. struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
  577. {
  578. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  579. struct lpfc_hba *phba = vport->phba;
  580. struct lpfc_vport **vports;
  581. int i, active_vlink_present = 0 ;
  582. /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
  583. /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
  584. * PLOGIs during LOGO storms from a device.
  585. */
  586. spin_lock_irq(shost->host_lock);
  587. ndlp->nlp_flag |= NLP_LOGO_ACC;
  588. spin_unlock_irq(shost->host_lock);
  589. if (els_cmd == ELS_CMD_PRLO)
  590. lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
  591. else
  592. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  593. if (ndlp->nlp_DID == Fabric_DID) {
  594. if (vport->port_state <= LPFC_FDISC)
  595. goto out;
  596. lpfc_linkdown_port(vport);
  597. spin_lock_irq(shost->host_lock);
  598. vport->fc_flag |= FC_VPORT_LOGO_RCVD;
  599. spin_unlock_irq(shost->host_lock);
  600. vports = lpfc_create_vport_work_array(phba);
  601. if (vports) {
  602. for (i = 0; i <= phba->max_vports && vports[i] != NULL;
  603. i++) {
  604. if ((!(vports[i]->fc_flag &
  605. FC_VPORT_LOGO_RCVD)) &&
  606. (vports[i]->port_state > LPFC_FDISC)) {
  607. active_vlink_present = 1;
  608. break;
  609. }
  610. }
  611. lpfc_destroy_vport_work_array(phba, vports);
  612. }
  613. /*
  614. * Don't re-instantiate if vport is marked for deletion.
  615. * If we are here first then vport_delete is going to wait
  616. * for discovery to complete.
  617. */
  618. if (!(vport->load_flag & FC_UNLOADING) &&
  619. active_vlink_present) {
  620. /*
  621. * If there are other active VLinks present,
  622. * re-instantiate the Vlink using FDISC.
  623. */
  624. mod_timer(&ndlp->nlp_delayfunc,
  625. jiffies + msecs_to_jiffies(1000));
  626. spin_lock_irq(shost->host_lock);
  627. ndlp->nlp_flag |= NLP_DELAY_TMO;
  628. spin_unlock_irq(shost->host_lock);
  629. ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
  630. vport->port_state = LPFC_FDISC;
  631. } else {
  632. spin_lock_irq(shost->host_lock);
  633. phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
  634. spin_unlock_irq(shost->host_lock);
  635. lpfc_retry_pport_discovery(phba);
  636. }
  637. } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
  638. ((ndlp->nlp_type & NLP_FCP_TARGET) ||
  639. !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
  640. (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
  641. /* Only try to re-login if this is NOT a Fabric Node */
  642. mod_timer(&ndlp->nlp_delayfunc,
  643. jiffies + msecs_to_jiffies(1000 * 1));
  644. spin_lock_irq(shost->host_lock);
  645. ndlp->nlp_flag |= NLP_DELAY_TMO;
  646. spin_unlock_irq(shost->host_lock);
  647. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  648. }
  649. out:
  650. ndlp->nlp_prev_state = ndlp->nlp_state;
  651. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  652. spin_lock_irq(shost->host_lock);
  653. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  654. spin_unlock_irq(shost->host_lock);
  655. /* The driver has to wait until the ACC completes before it continues
  656. * processing the LOGO. The action will resume in
  657. * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
  658. * unreg_login, the driver waits so the ACC does not get aborted.
  659. */
  660. return 0;
  661. }
  662. static uint32_t
  663. lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
  664. struct lpfc_nodelist *ndlp,
  665. struct lpfc_iocbq *cmdiocb)
  666. {
  667. struct ls_rjt stat;
  668. uint32_t *payload;
  669. uint32_t cmd;
  670. payload = ((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
  671. cmd = *payload;
  672. if (vport->phba->nvmet_support) {
  673. /* Must be a NVME PRLI */
  674. if (cmd == ELS_CMD_PRLI)
  675. goto out;
  676. } else {
  677. /* Initiator mode. */
  678. if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
  679. goto out;
  680. }
  681. return 1;
  682. out:
  683. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
  684. "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
  685. "state x%x flags x%x\n",
  686. cmd, ndlp->nlp_rpi, ndlp->nlp_state,
  687. ndlp->nlp_flag);
  688. memset(&stat, 0, sizeof(struct ls_rjt));
  689. stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
  690. stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
  691. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
  692. ndlp, NULL);
  693. return 0;
  694. }
  695. static void
  696. lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  697. struct lpfc_iocbq *cmdiocb)
  698. {
  699. struct lpfc_hba *phba = vport->phba;
  700. struct lpfc_dmabuf *pcmd;
  701. uint32_t *lp;
  702. PRLI *npr;
  703. struct fc_rport *rport = ndlp->rport;
  704. u32 roles;
  705. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  706. lp = (uint32_t *) pcmd->virt;
  707. npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
  708. if ((npr->prliType == PRLI_FCP_TYPE) ||
  709. (npr->prliType == PRLI_NVME_TYPE)) {
  710. if (npr->initiatorFunc) {
  711. if (npr->prliType == PRLI_FCP_TYPE)
  712. ndlp->nlp_type |= NLP_FCP_INITIATOR;
  713. if (npr->prliType == PRLI_NVME_TYPE)
  714. ndlp->nlp_type |= NLP_NVME_INITIATOR;
  715. }
  716. if (npr->targetFunc) {
  717. if (npr->prliType == PRLI_FCP_TYPE)
  718. ndlp->nlp_type |= NLP_FCP_TARGET;
  719. if (npr->prliType == PRLI_NVME_TYPE)
  720. ndlp->nlp_type |= NLP_NVME_TARGET;
  721. if (npr->writeXferRdyDis)
  722. ndlp->nlp_flag |= NLP_FIRSTBURST;
  723. }
  724. if (npr->Retry)
  725. ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
  726. /* If this driver is in nvme target mode, set the ndlp's fc4
  727. * type to NVME provided the PRLI response claims NVME FC4
  728. * type. Target mode does not issue gft_id so doesn't get
  729. * the fc4 type set until now.
  730. */
  731. if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
  732. ndlp->nlp_fc4_type |= NLP_FC4_NVME;
  733. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  734. }
  735. if (npr->prliType == PRLI_FCP_TYPE)
  736. ndlp->nlp_fc4_type |= NLP_FC4_FCP;
  737. }
  738. if (rport) {
  739. /* We need to update the rport role values */
  740. roles = FC_RPORT_ROLE_UNKNOWN;
  741. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  742. roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  743. if (ndlp->nlp_type & NLP_FCP_TARGET)
  744. roles |= FC_RPORT_ROLE_FCP_TARGET;
  745. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  746. "rport rolechg: role:x%x did:x%x flg:x%x",
  747. roles, ndlp->nlp_DID, ndlp->nlp_flag);
  748. if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
  749. fc_remote_port_rolechg(rport, roles);
  750. }
  751. }
  752. static uint32_t
  753. lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  754. {
  755. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  756. if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
  757. spin_lock_irq(shost->host_lock);
  758. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  759. spin_unlock_irq(shost->host_lock);
  760. return 0;
  761. }
  762. if (!(vport->fc_flag & FC_PT2PT)) {
  763. /* Check config parameter use-adisc or FCP-2 */
  764. if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
  765. ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
  766. (ndlp->nlp_type & NLP_FCP_TARGET)))) {
  767. spin_lock_irq(shost->host_lock);
  768. ndlp->nlp_flag |= NLP_NPR_ADISC;
  769. spin_unlock_irq(shost->host_lock);
  770. return 1;
  771. }
  772. }
  773. spin_lock_irq(shost->host_lock);
  774. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  775. spin_unlock_irq(shost->host_lock);
  776. lpfc_unreg_rpi(vport, ndlp);
  777. return 0;
  778. }
  779. /**
  780. * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
  781. * @phba : Pointer to lpfc_hba structure.
  782. * @vport: Pointer to lpfc_vport structure.
  783. * @rpi : rpi to be release.
  784. *
  785. * This function will send a unreg_login mailbox command to the firmware
  786. * to release a rpi.
  787. **/
  788. void
  789. lpfc_release_rpi(struct lpfc_hba *phba,
  790. struct lpfc_vport *vport,
  791. uint16_t rpi)
  792. {
  793. LPFC_MBOXQ_t *pmb;
  794. int rc;
  795. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  796. GFP_KERNEL);
  797. if (!pmb)
  798. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  799. "2796 mailbox memory allocation failed \n");
  800. else {
  801. lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
  802. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  803. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  804. if (rc == MBX_NOT_FINISHED)
  805. mempool_free(pmb, phba->mbox_mem_pool);
  806. }
  807. }
  808. static uint32_t
  809. lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  810. void *arg, uint32_t evt)
  811. {
  812. struct lpfc_hba *phba;
  813. LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
  814. uint16_t rpi;
  815. phba = vport->phba;
  816. /* Release the RPI if reglogin completing */
  817. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  818. (evt == NLP_EVT_CMPL_REG_LOGIN) &&
  819. (!pmb->u.mb.mbxStatus)) {
  820. rpi = pmb->u.mb.un.varWords[0];
  821. lpfc_release_rpi(phba, vport, rpi);
  822. }
  823. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  824. "0271 Illegal State Transition: node x%x "
  825. "event x%x, state x%x Data: x%x x%x\n",
  826. ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
  827. ndlp->nlp_flag);
  828. return ndlp->nlp_state;
  829. }
  830. static uint32_t
  831. lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  832. void *arg, uint32_t evt)
  833. {
  834. /* This transition is only legal if we previously
  835. * rcv'ed a PLOGI. Since we don't want 2 discovery threads
  836. * working on the same NPortID, do nothing for this thread
  837. * to stop it.
  838. */
  839. if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
  840. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  841. "0272 Illegal State Transition: node x%x "
  842. "event x%x, state x%x Data: x%x x%x\n",
  843. ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
  844. ndlp->nlp_flag);
  845. }
  846. return ndlp->nlp_state;
  847. }
  848. /* Start of Discovery State Machine routines */
  849. static uint32_t
  850. lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  851. void *arg, uint32_t evt)
  852. {
  853. struct lpfc_iocbq *cmdiocb;
  854. cmdiocb = (struct lpfc_iocbq *) arg;
  855. if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
  856. return ndlp->nlp_state;
  857. }
  858. return NLP_STE_FREED_NODE;
  859. }
  860. static uint32_t
  861. lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  862. void *arg, uint32_t evt)
  863. {
  864. lpfc_issue_els_logo(vport, ndlp, 0);
  865. return ndlp->nlp_state;
  866. }
  867. static uint32_t
  868. lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  869. void *arg, uint32_t evt)
  870. {
  871. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  872. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  873. spin_lock_irq(shost->host_lock);
  874. ndlp->nlp_flag |= NLP_LOGO_ACC;
  875. spin_unlock_irq(shost->host_lock);
  876. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  877. return ndlp->nlp_state;
  878. }
  879. static uint32_t
  880. lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  881. void *arg, uint32_t evt)
  882. {
  883. return NLP_STE_FREED_NODE;
  884. }
  885. static uint32_t
  886. lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  887. void *arg, uint32_t evt)
  888. {
  889. return NLP_STE_FREED_NODE;
  890. }
  891. static uint32_t
  892. lpfc_device_recov_unused_node(struct lpfc_vport *vport,
  893. struct lpfc_nodelist *ndlp,
  894. void *arg, uint32_t evt)
  895. {
  896. return ndlp->nlp_state;
  897. }
  898. static uint32_t
  899. lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  900. void *arg, uint32_t evt)
  901. {
  902. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  903. struct lpfc_hba *phba = vport->phba;
  904. struct lpfc_iocbq *cmdiocb = arg;
  905. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  906. uint32_t *lp = (uint32_t *) pcmd->virt;
  907. struct serv_parm *sp = (struct serv_parm *) (lp + 1);
  908. struct ls_rjt stat;
  909. int port_cmp;
  910. memset(&stat, 0, sizeof (struct ls_rjt));
  911. /* For a PLOGI, we only accept if our portname is less
  912. * than the remote portname.
  913. */
  914. phba->fc_stat.elsLogiCol++;
  915. port_cmp = memcmp(&vport->fc_portname, &sp->portName,
  916. sizeof(struct lpfc_name));
  917. if (port_cmp >= 0) {
  918. /* Reject this request because the remote node will accept
  919. ours */
  920. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  921. stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
  922. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  923. NULL);
  924. } else {
  925. if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
  926. (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
  927. (vport->num_disc_nodes)) {
  928. spin_lock_irq(shost->host_lock);
  929. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  930. spin_unlock_irq(shost->host_lock);
  931. /* Check if there are more PLOGIs to be sent */
  932. lpfc_more_plogi(vport);
  933. if (vport->num_disc_nodes == 0) {
  934. spin_lock_irq(shost->host_lock);
  935. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  936. spin_unlock_irq(shost->host_lock);
  937. lpfc_can_disctmo(vport);
  938. lpfc_end_rscn(vport);
  939. }
  940. }
  941. } /* If our portname was less */
  942. return ndlp->nlp_state;
  943. }
  944. static uint32_t
  945. lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  946. void *arg, uint32_t evt)
  947. {
  948. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  949. struct ls_rjt stat;
  950. memset(&stat, 0, sizeof (struct ls_rjt));
  951. stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
  952. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  953. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  954. return ndlp->nlp_state;
  955. }
  956. static uint32_t
  957. lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  958. void *arg, uint32_t evt)
  959. {
  960. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  961. /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
  962. if (vport->phba->sli_rev == LPFC_SLI_REV3)
  963. ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag;
  964. /* software abort outstanding PLOGI */
  965. lpfc_els_abort(vport->phba, ndlp);
  966. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  967. return ndlp->nlp_state;
  968. }
  969. static uint32_t
  970. lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  971. void *arg, uint32_t evt)
  972. {
  973. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  974. struct lpfc_hba *phba = vport->phba;
  975. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  976. /* software abort outstanding PLOGI */
  977. lpfc_els_abort(phba, ndlp);
  978. if (evt == NLP_EVT_RCV_LOGO) {
  979. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  980. } else {
  981. lpfc_issue_els_logo(vport, ndlp, 0);
  982. }
  983. /* Put ndlp in npr state set plogi timer for 1 sec */
  984. mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
  985. spin_lock_irq(shost->host_lock);
  986. ndlp->nlp_flag |= NLP_DELAY_TMO;
  987. spin_unlock_irq(shost->host_lock);
  988. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  989. ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
  990. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  991. return ndlp->nlp_state;
  992. }
  993. static uint32_t
  994. lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
  995. struct lpfc_nodelist *ndlp,
  996. void *arg,
  997. uint32_t evt)
  998. {
  999. struct lpfc_hba *phba = vport->phba;
  1000. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1001. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1002. struct lpfc_dmabuf *pcmd, *prsp, *mp;
  1003. uint32_t *lp;
  1004. uint32_t vid, flag;
  1005. IOCB_t *irsp;
  1006. struct serv_parm *sp;
  1007. uint32_t ed_tov;
  1008. LPFC_MBOXQ_t *mbox;
  1009. int rc;
  1010. cmdiocb = (struct lpfc_iocbq *) arg;
  1011. rspiocb = cmdiocb->context_un.rsp_iocb;
  1012. if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  1013. /* Recovery from PLOGI collision logic */
  1014. return ndlp->nlp_state;
  1015. }
  1016. irsp = &rspiocb->iocb;
  1017. if (irsp->ulpStatus)
  1018. goto out;
  1019. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  1020. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  1021. if (!prsp)
  1022. goto out;
  1023. lp = (uint32_t *) prsp->virt;
  1024. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  1025. /* Some switches have FDMI servers returning 0 for WWN */
  1026. if ((ndlp->nlp_DID != FDMI_DID) &&
  1027. (wwn_to_u64(sp->portName.u.wwn) == 0 ||
  1028. wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
  1029. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1030. "0142 PLOGI RSP: Invalid WWN.\n");
  1031. goto out;
  1032. }
  1033. if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
  1034. goto out;
  1035. /* PLOGI chkparm OK */
  1036. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1037. "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
  1038. ndlp->nlp_DID, ndlp->nlp_state,
  1039. ndlp->nlp_flag, ndlp->nlp_rpi);
  1040. if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
  1041. ndlp->nlp_fcp_info |= CLASS2;
  1042. else
  1043. ndlp->nlp_fcp_info |= CLASS3;
  1044. ndlp->nlp_class_sup = 0;
  1045. if (sp->cls1.classValid)
  1046. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  1047. if (sp->cls2.classValid)
  1048. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  1049. if (sp->cls3.classValid)
  1050. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  1051. if (sp->cls4.classValid)
  1052. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  1053. ndlp->nlp_maxframe =
  1054. ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
  1055. if ((vport->fc_flag & FC_PT2PT) &&
  1056. (vport->fc_flag & FC_PT2PT_PLOGI)) {
  1057. ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
  1058. if (sp->cmn.edtovResolution) {
  1059. /* E_D_TOV ticks are in nanoseconds */
  1060. ed_tov = (phba->fc_edtov + 999999) / 1000000;
  1061. }
  1062. ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
  1063. if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
  1064. sp->cmn.valid_vendor_ver_level) {
  1065. vid = be32_to_cpu(sp->un.vv.vid);
  1066. flag = be32_to_cpu(sp->un.vv.flags);
  1067. if ((vid == LPFC_VV_EMLX_ID) &&
  1068. (flag & LPFC_VV_SUPPRESS_RSP))
  1069. ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
  1070. }
  1071. /*
  1072. * Use the larger EDTOV
  1073. * RATOV = 2 * EDTOV for pt-to-pt
  1074. */
  1075. if (ed_tov > phba->fc_edtov)
  1076. phba->fc_edtov = ed_tov;
  1077. phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
  1078. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  1079. /* Issue config_link / reg_vfi to account for updated TOV's */
  1080. if (phba->sli_rev == LPFC_SLI_REV4) {
  1081. lpfc_issue_reg_vfi(vport);
  1082. } else {
  1083. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1084. if (!mbox) {
  1085. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1086. "0133 PLOGI: no memory "
  1087. "for config_link "
  1088. "Data: x%x x%x x%x x%x\n",
  1089. ndlp->nlp_DID, ndlp->nlp_state,
  1090. ndlp->nlp_flag, ndlp->nlp_rpi);
  1091. goto out;
  1092. }
  1093. lpfc_config_link(phba, mbox);
  1094. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1095. mbox->vport = vport;
  1096. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  1097. if (rc == MBX_NOT_FINISHED) {
  1098. mempool_free(mbox, phba->mbox_mem_pool);
  1099. goto out;
  1100. }
  1101. }
  1102. }
  1103. lpfc_unreg_rpi(vport, ndlp);
  1104. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1105. if (!mbox) {
  1106. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1107. "0018 PLOGI: no memory for reg_login "
  1108. "Data: x%x x%x x%x x%x\n",
  1109. ndlp->nlp_DID, ndlp->nlp_state,
  1110. ndlp->nlp_flag, ndlp->nlp_rpi);
  1111. goto out;
  1112. }
  1113. if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
  1114. (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
  1115. switch (ndlp->nlp_DID) {
  1116. case NameServer_DID:
  1117. mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
  1118. break;
  1119. case FDMI_DID:
  1120. mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
  1121. break;
  1122. default:
  1123. ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
  1124. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  1125. }
  1126. mbox->context2 = lpfc_nlp_get(ndlp);
  1127. mbox->vport = vport;
  1128. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  1129. != MBX_NOT_FINISHED) {
  1130. lpfc_nlp_set_state(vport, ndlp,
  1131. NLP_STE_REG_LOGIN_ISSUE);
  1132. return ndlp->nlp_state;
  1133. }
  1134. if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
  1135. ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
  1136. /* decrement node reference count to the failed mbox
  1137. * command
  1138. */
  1139. lpfc_nlp_put(ndlp);
  1140. mp = (struct lpfc_dmabuf *) mbox->context1;
  1141. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1142. kfree(mp);
  1143. mempool_free(mbox, phba->mbox_mem_pool);
  1144. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1145. "0134 PLOGI: cannot issue reg_login "
  1146. "Data: x%x x%x x%x x%x\n",
  1147. ndlp->nlp_DID, ndlp->nlp_state,
  1148. ndlp->nlp_flag, ndlp->nlp_rpi);
  1149. } else {
  1150. mempool_free(mbox, phba->mbox_mem_pool);
  1151. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1152. "0135 PLOGI: cannot format reg_login "
  1153. "Data: x%x x%x x%x x%x\n",
  1154. ndlp->nlp_DID, ndlp->nlp_state,
  1155. ndlp->nlp_flag, ndlp->nlp_rpi);
  1156. }
  1157. out:
  1158. if (ndlp->nlp_DID == NameServer_DID) {
  1159. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1160. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1161. "0261 Cannot Register NameServer login\n");
  1162. }
  1163. /*
  1164. ** In case the node reference counter does not go to zero, ensure that
  1165. ** the stale state for the node is not processed.
  1166. */
  1167. ndlp->nlp_prev_state = ndlp->nlp_state;
  1168. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1169. spin_lock_irq(shost->host_lock);
  1170. ndlp->nlp_flag |= NLP_DEFER_RM;
  1171. spin_unlock_irq(shost->host_lock);
  1172. return NLP_STE_FREED_NODE;
  1173. }
  1174. static uint32_t
  1175. lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1176. void *arg, uint32_t evt)
  1177. {
  1178. return ndlp->nlp_state;
  1179. }
  1180. static uint32_t
  1181. lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
  1182. struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
  1183. {
  1184. struct lpfc_hba *phba;
  1185. LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
  1186. MAILBOX_t *mb = &pmb->u.mb;
  1187. uint16_t rpi;
  1188. phba = vport->phba;
  1189. /* Release the RPI */
  1190. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1191. !mb->mbxStatus) {
  1192. rpi = pmb->u.mb.un.varWords[0];
  1193. lpfc_release_rpi(phba, vport, rpi);
  1194. }
  1195. return ndlp->nlp_state;
  1196. }
  1197. static uint32_t
  1198. lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1199. void *arg, uint32_t evt)
  1200. {
  1201. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1202. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1203. spin_lock_irq(shost->host_lock);
  1204. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1205. spin_unlock_irq(shost->host_lock);
  1206. return ndlp->nlp_state;
  1207. } else {
  1208. /* software abort outstanding PLOGI */
  1209. lpfc_els_abort(vport->phba, ndlp);
  1210. lpfc_drop_node(vport, ndlp);
  1211. return NLP_STE_FREED_NODE;
  1212. }
  1213. }
  1214. static uint32_t
  1215. lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
  1216. struct lpfc_nodelist *ndlp,
  1217. void *arg,
  1218. uint32_t evt)
  1219. {
  1220. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1221. struct lpfc_hba *phba = vport->phba;
  1222. /* Don't do anything that will mess up processing of the
  1223. * previous RSCN.
  1224. */
  1225. if (vport->fc_flag & FC_RSCN_DEFERRED)
  1226. return ndlp->nlp_state;
  1227. /* software abort outstanding PLOGI */
  1228. lpfc_els_abort(phba, ndlp);
  1229. ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
  1230. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1231. spin_lock_irq(shost->host_lock);
  1232. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1233. spin_unlock_irq(shost->host_lock);
  1234. return ndlp->nlp_state;
  1235. }
  1236. static uint32_t
  1237. lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1238. void *arg, uint32_t evt)
  1239. {
  1240. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1241. struct lpfc_hba *phba = vport->phba;
  1242. struct lpfc_iocbq *cmdiocb;
  1243. /* software abort outstanding ADISC */
  1244. lpfc_els_abort(phba, ndlp);
  1245. cmdiocb = (struct lpfc_iocbq *) arg;
  1246. if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
  1247. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1248. spin_lock_irq(shost->host_lock);
  1249. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1250. spin_unlock_irq(shost->host_lock);
  1251. if (vport->num_disc_nodes)
  1252. lpfc_more_adisc(vport);
  1253. }
  1254. return ndlp->nlp_state;
  1255. }
  1256. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  1257. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  1258. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  1259. return ndlp->nlp_state;
  1260. }
  1261. static uint32_t
  1262. lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1263. void *arg, uint32_t evt)
  1264. {
  1265. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1266. if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
  1267. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  1268. return ndlp->nlp_state;
  1269. }
  1270. static uint32_t
  1271. lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1272. void *arg, uint32_t evt)
  1273. {
  1274. struct lpfc_hba *phba = vport->phba;
  1275. struct lpfc_iocbq *cmdiocb;
  1276. cmdiocb = (struct lpfc_iocbq *) arg;
  1277. /* software abort outstanding ADISC */
  1278. lpfc_els_abort(phba, ndlp);
  1279. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1280. return ndlp->nlp_state;
  1281. }
  1282. static uint32_t
  1283. lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
  1284. struct lpfc_nodelist *ndlp,
  1285. void *arg, uint32_t evt)
  1286. {
  1287. struct lpfc_iocbq *cmdiocb;
  1288. cmdiocb = (struct lpfc_iocbq *) arg;
  1289. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1290. return ndlp->nlp_state;
  1291. }
  1292. static uint32_t
  1293. lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1294. void *arg, uint32_t evt)
  1295. {
  1296. struct lpfc_iocbq *cmdiocb;
  1297. cmdiocb = (struct lpfc_iocbq *) arg;
  1298. /* Treat like rcv logo */
  1299. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
  1300. return ndlp->nlp_state;
  1301. }
  1302. static uint32_t
  1303. lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
  1304. struct lpfc_nodelist *ndlp,
  1305. void *arg, uint32_t evt)
  1306. {
  1307. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1308. struct lpfc_hba *phba = vport->phba;
  1309. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1310. IOCB_t *irsp;
  1311. ADISC *ap;
  1312. int rc;
  1313. cmdiocb = (struct lpfc_iocbq *) arg;
  1314. rspiocb = cmdiocb->context_un.rsp_iocb;
  1315. ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
  1316. irsp = &rspiocb->iocb;
  1317. if ((irsp->ulpStatus) ||
  1318. (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
  1319. /* 1 sec timeout */
  1320. mod_timer(&ndlp->nlp_delayfunc,
  1321. jiffies + msecs_to_jiffies(1000));
  1322. spin_lock_irq(shost->host_lock);
  1323. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1324. spin_unlock_irq(shost->host_lock);
  1325. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  1326. memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
  1327. memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
  1328. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  1329. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1330. lpfc_unreg_rpi(vport, ndlp);
  1331. return ndlp->nlp_state;
  1332. }
  1333. if (phba->sli_rev == LPFC_SLI_REV4) {
  1334. rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
  1335. if (rc) {
  1336. /* Stay in state and retry. */
  1337. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  1338. return ndlp->nlp_state;
  1339. }
  1340. }
  1341. if (ndlp->nlp_type & NLP_FCP_TARGET) {
  1342. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  1343. lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
  1344. } else {
  1345. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  1346. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1347. }
  1348. return ndlp->nlp_state;
  1349. }
  1350. static uint32_t
  1351. lpfc_device_rm_adisc_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. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1356. spin_lock_irq(shost->host_lock);
  1357. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1358. spin_unlock_irq(shost->host_lock);
  1359. return ndlp->nlp_state;
  1360. } else {
  1361. /* software abort outstanding ADISC */
  1362. lpfc_els_abort(vport->phba, ndlp);
  1363. lpfc_drop_node(vport, ndlp);
  1364. return NLP_STE_FREED_NODE;
  1365. }
  1366. }
  1367. static uint32_t
  1368. lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
  1369. struct lpfc_nodelist *ndlp,
  1370. void *arg,
  1371. uint32_t evt)
  1372. {
  1373. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1374. struct lpfc_hba *phba = vport->phba;
  1375. /* Don't do anything that will mess up processing of the
  1376. * previous RSCN.
  1377. */
  1378. if (vport->fc_flag & FC_RSCN_DEFERRED)
  1379. return ndlp->nlp_state;
  1380. /* software abort outstanding ADISC */
  1381. lpfc_els_abort(phba, ndlp);
  1382. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  1383. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1384. spin_lock_irq(shost->host_lock);
  1385. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1386. spin_unlock_irq(shost->host_lock);
  1387. lpfc_disc_set_adisc(vport, ndlp);
  1388. return ndlp->nlp_state;
  1389. }
  1390. static uint32_t
  1391. lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
  1392. struct lpfc_nodelist *ndlp,
  1393. void *arg,
  1394. uint32_t evt)
  1395. {
  1396. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1397. lpfc_rcv_plogi(vport, ndlp, cmdiocb);
  1398. return ndlp->nlp_state;
  1399. }
  1400. static uint32_t
  1401. lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
  1402. struct lpfc_nodelist *ndlp,
  1403. void *arg,
  1404. uint32_t evt)
  1405. {
  1406. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1407. struct ls_rjt stat;
  1408. if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) {
  1409. return ndlp->nlp_state;
  1410. }
  1411. if (vport->phba->nvmet_support) {
  1412. /* NVME Target mode. Handle and respond to the PRLI and
  1413. * transition to UNMAPPED provided the RPI has completed
  1414. * registration.
  1415. */
  1416. if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
  1417. lpfc_rcv_prli(vport, ndlp, cmdiocb);
  1418. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  1419. } else {
  1420. /* RPI registration has not completed. Reject the PRLI
  1421. * to prevent an illegal state transition when the
  1422. * rpi registration does complete.
  1423. */
  1424. memset(&stat, 0, sizeof(struct ls_rjt));
  1425. stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
  1426. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1427. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
  1428. ndlp, NULL);
  1429. return ndlp->nlp_state;
  1430. }
  1431. } else {
  1432. /* Initiator mode. */
  1433. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  1434. }
  1435. return ndlp->nlp_state;
  1436. }
  1437. static uint32_t
  1438. lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
  1439. struct lpfc_nodelist *ndlp,
  1440. void *arg,
  1441. uint32_t evt)
  1442. {
  1443. struct lpfc_hba *phba = vport->phba;
  1444. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1445. LPFC_MBOXQ_t *mb;
  1446. LPFC_MBOXQ_t *nextmb;
  1447. struct lpfc_dmabuf *mp;
  1448. cmdiocb = (struct lpfc_iocbq *) arg;
  1449. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  1450. if ((mb = phba->sli.mbox_active)) {
  1451. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  1452. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1453. ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
  1454. lpfc_nlp_put(ndlp);
  1455. mb->context2 = NULL;
  1456. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1457. }
  1458. }
  1459. spin_lock_irq(&phba->hbalock);
  1460. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  1461. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  1462. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1463. mp = (struct lpfc_dmabuf *) (mb->context1);
  1464. if (mp) {
  1465. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1466. kfree(mp);
  1467. }
  1468. ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
  1469. lpfc_nlp_put(ndlp);
  1470. list_del(&mb->list);
  1471. phba->sli.mboxq_cnt--;
  1472. mempool_free(mb, phba->mbox_mem_pool);
  1473. }
  1474. }
  1475. spin_unlock_irq(&phba->hbalock);
  1476. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1477. return ndlp->nlp_state;
  1478. }
  1479. static uint32_t
  1480. lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
  1481. struct lpfc_nodelist *ndlp,
  1482. void *arg,
  1483. uint32_t evt)
  1484. {
  1485. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1486. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1487. return ndlp->nlp_state;
  1488. }
  1489. static uint32_t
  1490. lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
  1491. struct lpfc_nodelist *ndlp,
  1492. void *arg,
  1493. uint32_t evt)
  1494. {
  1495. struct lpfc_iocbq *cmdiocb;
  1496. cmdiocb = (struct lpfc_iocbq *) arg;
  1497. lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
  1498. return ndlp->nlp_state;
  1499. }
  1500. static uint32_t
  1501. lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
  1502. struct lpfc_nodelist *ndlp,
  1503. void *arg,
  1504. uint32_t evt)
  1505. {
  1506. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1507. struct lpfc_hba *phba = vport->phba;
  1508. LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
  1509. MAILBOX_t *mb = &pmb->u.mb;
  1510. uint32_t did = mb->un.varWords[1];
  1511. int rc = 0;
  1512. if (mb->mbxStatus) {
  1513. /* RegLogin failed */
  1514. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1515. "0246 RegLogin failed Data: x%x x%x x%x x%x "
  1516. "x%x\n",
  1517. did, mb->mbxStatus, vport->port_state,
  1518. mb->un.varRegLogin.vpi,
  1519. mb->un.varRegLogin.rpi);
  1520. /*
  1521. * If RegLogin failed due to lack of HBA resources do not
  1522. * retry discovery.
  1523. */
  1524. if (mb->mbxStatus == MBXERR_RPI_FULL) {
  1525. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1526. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1527. return ndlp->nlp_state;
  1528. }
  1529. /* Put ndlp in npr state set plogi timer for 1 sec */
  1530. mod_timer(&ndlp->nlp_delayfunc,
  1531. jiffies + msecs_to_jiffies(1000 * 1));
  1532. spin_lock_irq(shost->host_lock);
  1533. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1534. spin_unlock_irq(shost->host_lock);
  1535. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  1536. lpfc_issue_els_logo(vport, ndlp, 0);
  1537. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1538. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1539. return ndlp->nlp_state;
  1540. }
  1541. /* SLI4 ports have preallocated logical rpis. */
  1542. if (phba->sli_rev < LPFC_SLI_REV4)
  1543. ndlp->nlp_rpi = mb->un.varWords[0];
  1544. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  1545. /* Only if we are not a fabric nport do we issue PRLI */
  1546. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1547. "3066 RegLogin Complete on x%x x%x x%x\n",
  1548. did, ndlp->nlp_type, ndlp->nlp_fc4_type);
  1549. if (!(ndlp->nlp_type & NLP_FABRIC) &&
  1550. (phba->nvmet_support == 0)) {
  1551. /* The driver supports FCP and NVME concurrently. If the
  1552. * ndlp's nlp_fc4_type is still zero, the driver doesn't
  1553. * know what PRLI to send yet. Figure that out now and
  1554. * call PRLI depending on the outcome.
  1555. */
  1556. if (vport->fc_flag & FC_PT2PT) {
  1557. /* If we are pt2pt, there is no Fabric to determine
  1558. * the FC4 type of the remote nport. So if NVME
  1559. * is configured try it.
  1560. */
  1561. ndlp->nlp_fc4_type |= NLP_FC4_FCP;
  1562. if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
  1563. (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
  1564. ndlp->nlp_fc4_type |= NLP_FC4_NVME;
  1565. /* We need to update the localport also */
  1566. lpfc_nvme_update_localport(vport);
  1567. }
  1568. } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  1569. ndlp->nlp_fc4_type |= NLP_FC4_FCP;
  1570. } else if (ndlp->nlp_fc4_type == 0) {
  1571. rc = lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID,
  1572. 0, ndlp->nlp_DID);
  1573. return ndlp->nlp_state;
  1574. }
  1575. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1576. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  1577. lpfc_issue_els_prli(vport, ndlp, 0);
  1578. } else {
  1579. if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
  1580. phba->targetport->port_id = vport->fc_myDID;
  1581. /* Only Fabric ports should transition. NVME target
  1582. * must complete PRLI.
  1583. */
  1584. if (ndlp->nlp_type & NLP_FABRIC) {
  1585. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1586. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1587. }
  1588. }
  1589. return ndlp->nlp_state;
  1590. }
  1591. static uint32_t
  1592. lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
  1593. struct lpfc_nodelist *ndlp,
  1594. void *arg,
  1595. uint32_t evt)
  1596. {
  1597. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1598. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1599. spin_lock_irq(shost->host_lock);
  1600. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1601. spin_unlock_irq(shost->host_lock);
  1602. return ndlp->nlp_state;
  1603. } else {
  1604. lpfc_drop_node(vport, ndlp);
  1605. return NLP_STE_FREED_NODE;
  1606. }
  1607. }
  1608. static uint32_t
  1609. lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
  1610. struct lpfc_nodelist *ndlp,
  1611. void *arg,
  1612. uint32_t evt)
  1613. {
  1614. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1615. /* Don't do anything that will mess up processing of the
  1616. * previous RSCN.
  1617. */
  1618. if (vport->fc_flag & FC_RSCN_DEFERRED)
  1619. return ndlp->nlp_state;
  1620. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1621. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1622. spin_lock_irq(shost->host_lock);
  1623. /* If we are a target we won't immediately transition into PRLI,
  1624. * so if REG_LOGIN already completed we don't need to ignore it.
  1625. */
  1626. if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
  1627. !vport->phba->nvmet_support)
  1628. ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
  1629. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1630. spin_unlock_irq(shost->host_lock);
  1631. lpfc_disc_set_adisc(vport, ndlp);
  1632. return ndlp->nlp_state;
  1633. }
  1634. static uint32_t
  1635. lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1636. void *arg, uint32_t evt)
  1637. {
  1638. struct lpfc_iocbq *cmdiocb;
  1639. cmdiocb = (struct lpfc_iocbq *) arg;
  1640. lpfc_rcv_plogi(vport, ndlp, cmdiocb);
  1641. return ndlp->nlp_state;
  1642. }
  1643. static uint32_t
  1644. lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1645. void *arg, uint32_t evt)
  1646. {
  1647. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1648. if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
  1649. return ndlp->nlp_state;
  1650. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  1651. return ndlp->nlp_state;
  1652. }
  1653. static uint32_t
  1654. lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1655. void *arg, uint32_t evt)
  1656. {
  1657. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1658. /* Software abort outstanding PRLI before sending acc */
  1659. lpfc_els_abort(vport->phba, ndlp);
  1660. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1661. return ndlp->nlp_state;
  1662. }
  1663. static uint32_t
  1664. lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1665. void *arg, uint32_t evt)
  1666. {
  1667. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1668. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1669. return ndlp->nlp_state;
  1670. }
  1671. /* This routine is envoked when we rcv a PRLO request from a nport
  1672. * we are logged into. We should send back a PRLO rsp setting the
  1673. * appropriate bits.
  1674. * NEXT STATE = PRLI_ISSUE
  1675. */
  1676. static uint32_t
  1677. lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1678. void *arg, uint32_t evt)
  1679. {
  1680. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1681. lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
  1682. return ndlp->nlp_state;
  1683. }
  1684. static uint32_t
  1685. lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1686. void *arg, uint32_t evt)
  1687. {
  1688. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1689. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1690. struct lpfc_hba *phba = vport->phba;
  1691. IOCB_t *irsp;
  1692. PRLI *npr;
  1693. struct lpfc_nvme_prli *nvpr;
  1694. void *temp_ptr;
  1695. cmdiocb = (struct lpfc_iocbq *) arg;
  1696. rspiocb = cmdiocb->context_un.rsp_iocb;
  1697. /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
  1698. * format is different so NULL the two PRLI types so that the
  1699. * driver correctly gets the correct context.
  1700. */
  1701. npr = NULL;
  1702. nvpr = NULL;
  1703. temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
  1704. if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
  1705. npr = (PRLI *) temp_ptr;
  1706. else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
  1707. nvpr = (struct lpfc_nvme_prli *) temp_ptr;
  1708. irsp = &rspiocb->iocb;
  1709. if (irsp->ulpStatus) {
  1710. if ((vport->port_type == LPFC_NPIV_PORT) &&
  1711. vport->cfg_restrict_login) {
  1712. goto out;
  1713. }
  1714. /* Adjust the nlp_type accordingly if the PRLI failed */
  1715. if (npr)
  1716. ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
  1717. if (nvpr)
  1718. ndlp->nlp_fc4_type &= ~NLP_FC4_NVME;
  1719. /* We can't set the DSM state till BOTH PRLIs complete */
  1720. goto out_err;
  1721. }
  1722. if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
  1723. (npr->prliType == PRLI_FCP_TYPE)) {
  1724. lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
  1725. "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
  1726. npr->initiatorFunc,
  1727. npr->targetFunc);
  1728. if (npr->initiatorFunc)
  1729. ndlp->nlp_type |= NLP_FCP_INITIATOR;
  1730. if (npr->targetFunc) {
  1731. ndlp->nlp_type |= NLP_FCP_TARGET;
  1732. if (npr->writeXferRdyDis)
  1733. ndlp->nlp_flag |= NLP_FIRSTBURST;
  1734. }
  1735. if (npr->Retry)
  1736. ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
  1737. } else if (nvpr &&
  1738. (bf_get_be32(prli_acc_rsp_code, nvpr) ==
  1739. PRLI_REQ_EXECUTED) &&
  1740. (bf_get_be32(prli_type_code, nvpr) ==
  1741. PRLI_NVME_TYPE)) {
  1742. /* Complete setting up the remote ndlp personality. */
  1743. if (bf_get_be32(prli_init, nvpr))
  1744. ndlp->nlp_type |= NLP_NVME_INITIATOR;
  1745. /* Target driver cannot solicit NVME FB. */
  1746. if (bf_get_be32(prli_tgt, nvpr)) {
  1747. /* Complete the nvme target roles. The transport
  1748. * needs to know if the rport is capable of
  1749. * discovery in addition to its role.
  1750. */
  1751. ndlp->nlp_type |= NLP_NVME_TARGET;
  1752. if (bf_get_be32(prli_disc, nvpr))
  1753. ndlp->nlp_type |= NLP_NVME_DISCOVERY;
  1754. /*
  1755. * If prli_fba is set, the Target supports FirstBurst.
  1756. * If prli_fb_sz is 0, the FirstBurst size is unlimited,
  1757. * otherwise it defines the actual size supported by
  1758. * the NVME Target.
  1759. */
  1760. if ((bf_get_be32(prli_fba, nvpr) == 1) &&
  1761. (phba->cfg_nvme_enable_fb) &&
  1762. (!phba->nvmet_support)) {
  1763. /* Both sides support FB. The target's first
  1764. * burst size is a 512 byte encoded value.
  1765. */
  1766. ndlp->nlp_flag |= NLP_FIRSTBURST;
  1767. ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
  1768. nvpr);
  1769. /* Expressed in units of 512 bytes */
  1770. if (ndlp->nvme_fb_size)
  1771. ndlp->nvme_fb_size <<=
  1772. LPFC_NVME_FB_SHIFT;
  1773. else
  1774. ndlp->nvme_fb_size = LPFC_NVME_MAX_FB;
  1775. }
  1776. }
  1777. lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
  1778. "6029 NVME PRLI Cmpl w1 x%08x "
  1779. "w4 x%08x w5 x%08x flag x%x, "
  1780. "fcp_info x%x nlp_type x%x\n",
  1781. be32_to_cpu(nvpr->word1),
  1782. be32_to_cpu(nvpr->word4),
  1783. be32_to_cpu(nvpr->word5),
  1784. ndlp->nlp_flag, ndlp->nlp_fcp_info,
  1785. ndlp->nlp_type);
  1786. }
  1787. if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
  1788. (vport->port_type == LPFC_NPIV_PORT) &&
  1789. vport->cfg_restrict_login) {
  1790. out:
  1791. spin_lock_irq(shost->host_lock);
  1792. ndlp->nlp_flag |= NLP_TARGET_REMOVE;
  1793. spin_unlock_irq(shost->host_lock);
  1794. lpfc_issue_els_logo(vport, ndlp, 0);
  1795. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1796. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1797. return ndlp->nlp_state;
  1798. }
  1799. out_err:
  1800. /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
  1801. * are complete.
  1802. */
  1803. if (ndlp->fc4_prli_sent == 0) {
  1804. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1805. if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
  1806. lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
  1807. else if (ndlp->nlp_type &
  1808. (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
  1809. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1810. } else
  1811. lpfc_printf_vlog(vport,
  1812. KERN_INFO, LOG_ELS,
  1813. "3067 PRLI's still outstanding "
  1814. "on x%06x - count %d, Pend Node Mode "
  1815. "transition...\n",
  1816. ndlp->nlp_DID, ndlp->fc4_prli_sent);
  1817. return ndlp->nlp_state;
  1818. }
  1819. /*! lpfc_device_rm_prli_issue
  1820. *
  1821. * \pre
  1822. * \post
  1823. * \param phba
  1824. * \param ndlp
  1825. * \param arg
  1826. * \param evt
  1827. * \return uint32_t
  1828. *
  1829. * \b Description:
  1830. * This routine is envoked when we a request to remove a nport we are in the
  1831. * process of PRLIing. We should software abort outstanding prli, unreg
  1832. * login, send a logout. We will change node state to UNUSED_NODE, put it
  1833. * on plogi list so it can be freed when LOGO completes.
  1834. *
  1835. */
  1836. static uint32_t
  1837. lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1838. void *arg, uint32_t evt)
  1839. {
  1840. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1841. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1842. spin_lock_irq(shost->host_lock);
  1843. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1844. spin_unlock_irq(shost->host_lock);
  1845. return ndlp->nlp_state;
  1846. } else {
  1847. /* software abort outstanding PLOGI */
  1848. lpfc_els_abort(vport->phba, ndlp);
  1849. lpfc_drop_node(vport, ndlp);
  1850. return NLP_STE_FREED_NODE;
  1851. }
  1852. }
  1853. /*! lpfc_device_recov_prli_issue
  1854. *
  1855. * \pre
  1856. * \post
  1857. * \param phba
  1858. * \param ndlp
  1859. * \param arg
  1860. * \param evt
  1861. * \return uint32_t
  1862. *
  1863. * \b Description:
  1864. * The routine is envoked when the state of a device is unknown, like
  1865. * during a link down. We should remove the nodelist entry from the
  1866. * unmapped list, issue a UNREG_LOGIN, do a software abort of the
  1867. * outstanding PRLI command, then free the node entry.
  1868. */
  1869. static uint32_t
  1870. lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
  1871. struct lpfc_nodelist *ndlp,
  1872. void *arg,
  1873. uint32_t evt)
  1874. {
  1875. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1876. struct lpfc_hba *phba = vport->phba;
  1877. /* Don't do anything that will mess up processing of the
  1878. * previous RSCN.
  1879. */
  1880. if (vport->fc_flag & FC_RSCN_DEFERRED)
  1881. return ndlp->nlp_state;
  1882. /* software abort outstanding PRLI */
  1883. lpfc_els_abort(phba, ndlp);
  1884. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1885. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1886. spin_lock_irq(shost->host_lock);
  1887. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1888. spin_unlock_irq(shost->host_lock);
  1889. lpfc_disc_set_adisc(vport, ndlp);
  1890. return ndlp->nlp_state;
  1891. }
  1892. static uint32_t
  1893. lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1894. void *arg, uint32_t evt)
  1895. {
  1896. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
  1897. struct ls_rjt stat;
  1898. memset(&stat, 0, sizeof(struct ls_rjt));
  1899. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1900. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1901. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  1902. return ndlp->nlp_state;
  1903. }
  1904. static uint32_t
  1905. lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1906. void *arg, uint32_t evt)
  1907. {
  1908. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
  1909. struct ls_rjt stat;
  1910. memset(&stat, 0, sizeof(struct ls_rjt));
  1911. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1912. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1913. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  1914. return ndlp->nlp_state;
  1915. }
  1916. static uint32_t
  1917. lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1918. void *arg, uint32_t evt)
  1919. {
  1920. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1921. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
  1922. spin_lock_irq(shost->host_lock);
  1923. ndlp->nlp_flag |= NLP_LOGO_ACC;
  1924. spin_unlock_irq(shost->host_lock);
  1925. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  1926. return ndlp->nlp_state;
  1927. }
  1928. static uint32_t
  1929. lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1930. void *arg, uint32_t evt)
  1931. {
  1932. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
  1933. struct ls_rjt stat;
  1934. memset(&stat, 0, sizeof(struct ls_rjt));
  1935. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1936. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1937. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  1938. return ndlp->nlp_state;
  1939. }
  1940. static uint32_t
  1941. lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1942. void *arg, uint32_t evt)
  1943. {
  1944. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
  1945. struct ls_rjt stat;
  1946. memset(&stat, 0, sizeof(struct ls_rjt));
  1947. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1948. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1949. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  1950. return ndlp->nlp_state;
  1951. }
  1952. static uint32_t
  1953. lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1954. void *arg, uint32_t evt)
  1955. {
  1956. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1957. ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
  1958. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1959. spin_lock_irq(shost->host_lock);
  1960. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1961. spin_unlock_irq(shost->host_lock);
  1962. lpfc_disc_set_adisc(vport, ndlp);
  1963. return ndlp->nlp_state;
  1964. }
  1965. static uint32_t
  1966. lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1967. void *arg, uint32_t evt)
  1968. {
  1969. /*
  1970. * DevLoss has timed out and is calling for Device Remove.
  1971. * In this case, abort the LOGO and cleanup the ndlp
  1972. */
  1973. lpfc_unreg_rpi(vport, ndlp);
  1974. /* software abort outstanding PLOGI */
  1975. lpfc_els_abort(vport->phba, ndlp);
  1976. lpfc_drop_node(vport, ndlp);
  1977. return NLP_STE_FREED_NODE;
  1978. }
  1979. static uint32_t
  1980. lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
  1981. struct lpfc_nodelist *ndlp,
  1982. void *arg, uint32_t evt)
  1983. {
  1984. /*
  1985. * Device Recovery events have no meaning for a node with a LOGO
  1986. * outstanding. The LOGO has to complete first and handle the
  1987. * node from that point.
  1988. */
  1989. return ndlp->nlp_state;
  1990. }
  1991. static uint32_t
  1992. lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1993. void *arg, uint32_t evt)
  1994. {
  1995. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1996. lpfc_rcv_plogi(vport, ndlp, cmdiocb);
  1997. return ndlp->nlp_state;
  1998. }
  1999. static uint32_t
  2000. lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2001. void *arg, uint32_t evt)
  2002. {
  2003. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2004. if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
  2005. return ndlp->nlp_state;
  2006. lpfc_rcv_prli(vport, ndlp, cmdiocb);
  2007. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  2008. return ndlp->nlp_state;
  2009. }
  2010. static uint32_t
  2011. lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2012. void *arg, uint32_t evt)
  2013. {
  2014. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2015. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  2016. return ndlp->nlp_state;
  2017. }
  2018. static uint32_t
  2019. lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2020. void *arg, uint32_t evt)
  2021. {
  2022. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2023. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  2024. return ndlp->nlp_state;
  2025. }
  2026. static uint32_t
  2027. lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2028. void *arg, uint32_t evt)
  2029. {
  2030. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2031. lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
  2032. return ndlp->nlp_state;
  2033. }
  2034. static uint32_t
  2035. lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
  2036. struct lpfc_nodelist *ndlp,
  2037. void *arg,
  2038. uint32_t evt)
  2039. {
  2040. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2041. ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
  2042. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  2043. spin_lock_irq(shost->host_lock);
  2044. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  2045. ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
  2046. spin_unlock_irq(shost->host_lock);
  2047. lpfc_disc_set_adisc(vport, ndlp);
  2048. return ndlp->nlp_state;
  2049. }
  2050. static uint32_t
  2051. lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2052. void *arg, uint32_t evt)
  2053. {
  2054. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2055. lpfc_rcv_plogi(vport, ndlp, cmdiocb);
  2056. return ndlp->nlp_state;
  2057. }
  2058. static uint32_t
  2059. lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2060. void *arg, uint32_t evt)
  2061. {
  2062. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2063. if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
  2064. return ndlp->nlp_state;
  2065. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  2066. return ndlp->nlp_state;
  2067. }
  2068. static uint32_t
  2069. lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2070. void *arg, uint32_t evt)
  2071. {
  2072. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2073. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  2074. return ndlp->nlp_state;
  2075. }
  2076. static uint32_t
  2077. lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
  2078. struct lpfc_nodelist *ndlp,
  2079. void *arg, uint32_t evt)
  2080. {
  2081. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2082. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  2083. return ndlp->nlp_state;
  2084. }
  2085. static uint32_t
  2086. lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2087. void *arg, uint32_t evt)
  2088. {
  2089. struct lpfc_hba *phba = vport->phba;
  2090. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2091. /* flush the target */
  2092. lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
  2093. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  2094. /* Treat like rcv logo */
  2095. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
  2096. return ndlp->nlp_state;
  2097. }
  2098. static uint32_t
  2099. lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
  2100. struct lpfc_nodelist *ndlp,
  2101. void *arg,
  2102. uint32_t evt)
  2103. {
  2104. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2105. ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
  2106. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  2107. spin_lock_irq(shost->host_lock);
  2108. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  2109. ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
  2110. spin_unlock_irq(shost->host_lock);
  2111. lpfc_disc_set_adisc(vport, ndlp);
  2112. return ndlp->nlp_state;
  2113. }
  2114. static uint32_t
  2115. lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2116. void *arg, uint32_t evt)
  2117. {
  2118. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2119. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2120. /* Ignore PLOGI if we have an outstanding LOGO */
  2121. if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
  2122. return ndlp->nlp_state;
  2123. if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
  2124. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2125. spin_lock_irq(shost->host_lock);
  2126. ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
  2127. spin_unlock_irq(shost->host_lock);
  2128. } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
  2129. /* send PLOGI immediately, move to PLOGI issue state */
  2130. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  2131. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  2132. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2133. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  2134. }
  2135. }
  2136. return ndlp->nlp_state;
  2137. }
  2138. static uint32_t
  2139. lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2140. void *arg, uint32_t evt)
  2141. {
  2142. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2143. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2144. struct ls_rjt stat;
  2145. memset(&stat, 0, sizeof (struct ls_rjt));
  2146. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2147. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  2148. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  2149. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  2150. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  2151. spin_lock_irq(shost->host_lock);
  2152. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2153. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  2154. spin_unlock_irq(shost->host_lock);
  2155. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  2156. lpfc_issue_els_adisc(vport, ndlp, 0);
  2157. } else {
  2158. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  2159. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2160. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  2161. }
  2162. }
  2163. return ndlp->nlp_state;
  2164. }
  2165. static uint32_t
  2166. lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2167. void *arg, uint32_t evt)
  2168. {
  2169. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2170. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  2171. return ndlp->nlp_state;
  2172. }
  2173. static uint32_t
  2174. lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2175. void *arg, uint32_t evt)
  2176. {
  2177. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2178. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  2179. /*
  2180. * Do not start discovery if discovery is about to start
  2181. * or discovery in progress for this node. Starting discovery
  2182. * here will affect the counting of discovery threads.
  2183. */
  2184. if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
  2185. !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
  2186. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  2187. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2188. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  2189. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  2190. lpfc_issue_els_adisc(vport, ndlp, 0);
  2191. } else {
  2192. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  2193. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2194. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  2195. }
  2196. }
  2197. return ndlp->nlp_state;
  2198. }
  2199. static uint32_t
  2200. lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2201. void *arg, uint32_t evt)
  2202. {
  2203. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2204. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  2205. spin_lock_irq(shost->host_lock);
  2206. ndlp->nlp_flag |= NLP_LOGO_ACC;
  2207. spin_unlock_irq(shost->host_lock);
  2208. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2209. if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
  2210. mod_timer(&ndlp->nlp_delayfunc,
  2211. jiffies + msecs_to_jiffies(1000 * 1));
  2212. spin_lock_irq(shost->host_lock);
  2213. ndlp->nlp_flag |= NLP_DELAY_TMO;
  2214. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2215. spin_unlock_irq(shost->host_lock);
  2216. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  2217. } else {
  2218. spin_lock_irq(shost->host_lock);
  2219. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2220. spin_unlock_irq(shost->host_lock);
  2221. }
  2222. return ndlp->nlp_state;
  2223. }
  2224. static uint32_t
  2225. lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2226. void *arg, uint32_t evt)
  2227. {
  2228. struct lpfc_iocbq *cmdiocb, *rspiocb;
  2229. IOCB_t *irsp;
  2230. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2231. cmdiocb = (struct lpfc_iocbq *) arg;
  2232. rspiocb = cmdiocb->context_un.rsp_iocb;
  2233. irsp = &rspiocb->iocb;
  2234. if (irsp->ulpStatus) {
  2235. spin_lock_irq(shost->host_lock);
  2236. ndlp->nlp_flag |= NLP_DEFER_RM;
  2237. spin_unlock_irq(shost->host_lock);
  2238. return NLP_STE_FREED_NODE;
  2239. }
  2240. return ndlp->nlp_state;
  2241. }
  2242. static uint32_t
  2243. lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2244. void *arg, uint32_t evt)
  2245. {
  2246. struct lpfc_iocbq *cmdiocb, *rspiocb;
  2247. IOCB_t *irsp;
  2248. cmdiocb = (struct lpfc_iocbq *) arg;
  2249. rspiocb = cmdiocb->context_un.rsp_iocb;
  2250. irsp = &rspiocb->iocb;
  2251. if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
  2252. lpfc_drop_node(vport, ndlp);
  2253. return NLP_STE_FREED_NODE;
  2254. }
  2255. return ndlp->nlp_state;
  2256. }
  2257. static uint32_t
  2258. lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2259. void *arg, uint32_t evt)
  2260. {
  2261. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2262. /* For the fabric port just clear the fc flags. */
  2263. if (ndlp->nlp_DID == Fabric_DID) {
  2264. spin_lock_irq(shost->host_lock);
  2265. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  2266. spin_unlock_irq(shost->host_lock);
  2267. }
  2268. lpfc_unreg_rpi(vport, ndlp);
  2269. return ndlp->nlp_state;
  2270. }
  2271. static uint32_t
  2272. lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2273. void *arg, uint32_t evt)
  2274. {
  2275. struct lpfc_iocbq *cmdiocb, *rspiocb;
  2276. IOCB_t *irsp;
  2277. cmdiocb = (struct lpfc_iocbq *) arg;
  2278. rspiocb = cmdiocb->context_un.rsp_iocb;
  2279. irsp = &rspiocb->iocb;
  2280. if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
  2281. lpfc_drop_node(vport, ndlp);
  2282. return NLP_STE_FREED_NODE;
  2283. }
  2284. return ndlp->nlp_state;
  2285. }
  2286. static uint32_t
  2287. lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
  2288. struct lpfc_nodelist *ndlp,
  2289. void *arg, uint32_t evt)
  2290. {
  2291. LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
  2292. MAILBOX_t *mb = &pmb->u.mb;
  2293. if (!mb->mbxStatus) {
  2294. /* SLI4 ports have preallocated logical rpis. */
  2295. if (vport->phba->sli_rev < LPFC_SLI_REV4)
  2296. ndlp->nlp_rpi = mb->un.varWords[0];
  2297. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  2298. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  2299. lpfc_unreg_rpi(vport, ndlp);
  2300. }
  2301. } else {
  2302. if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
  2303. lpfc_drop_node(vport, ndlp);
  2304. return NLP_STE_FREED_NODE;
  2305. }
  2306. }
  2307. return ndlp->nlp_state;
  2308. }
  2309. static uint32_t
  2310. lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2311. void *arg, uint32_t evt)
  2312. {
  2313. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2314. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  2315. spin_lock_irq(shost->host_lock);
  2316. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  2317. spin_unlock_irq(shost->host_lock);
  2318. return ndlp->nlp_state;
  2319. }
  2320. lpfc_drop_node(vport, ndlp);
  2321. return NLP_STE_FREED_NODE;
  2322. }
  2323. static uint32_t
  2324. lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2325. void *arg, uint32_t evt)
  2326. {
  2327. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2328. /* Don't do anything that will mess up processing of the
  2329. * previous RSCN.
  2330. */
  2331. if (vport->fc_flag & FC_RSCN_DEFERRED)
  2332. return ndlp->nlp_state;
  2333. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2334. spin_lock_irq(shost->host_lock);
  2335. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  2336. ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
  2337. spin_unlock_irq(shost->host_lock);
  2338. return ndlp->nlp_state;
  2339. }
  2340. /* This next section defines the NPort Discovery State Machine */
  2341. /* There are 4 different double linked lists nodelist entries can reside on.
  2342. * The plogi list and adisc list are used when Link Up discovery or RSCN
  2343. * processing is needed. Each list holds the nodes that we will send PLOGI
  2344. * or ADISC on. These lists will keep track of what nodes will be effected
  2345. * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
  2346. * The unmapped_list will contain all nodes that we have successfully logged
  2347. * into at the Fibre Channel level. The mapped_list will contain all nodes
  2348. * that are mapped FCP targets.
  2349. */
  2350. /*
  2351. * The bind list is a list of undiscovered (potentially non-existent) nodes
  2352. * that we have saved binding information on. This information is used when
  2353. * nodes transition from the unmapped to the mapped list.
  2354. */
  2355. /* For UNUSED_NODE state, the node has just been allocated .
  2356. * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
  2357. * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
  2358. * and put on the unmapped list. For ADISC processing, the node is taken off
  2359. * the ADISC list and placed on either the mapped or unmapped list (depending
  2360. * on its previous state). Once on the unmapped list, a PRLI is issued and the
  2361. * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
  2362. * changed to UNMAPPED_NODE. If the completion indicates a mapped
  2363. * node, the node is taken off the unmapped list. The binding list is checked
  2364. * for a valid binding, or a binding is automatically assigned. If binding
  2365. * assignment is unsuccessful, the node is left on the unmapped list. If
  2366. * binding assignment is successful, the associated binding list entry (if
  2367. * any) is removed, and the node is placed on the mapped list.
  2368. */
  2369. /*
  2370. * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
  2371. * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
  2372. * expire, all effected nodes will receive a DEVICE_RM event.
  2373. */
  2374. /*
  2375. * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
  2376. * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
  2377. * check, additional nodes may be added or removed (via DEVICE_RM) to / from
  2378. * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
  2379. * we will first process the ADISC list. 32 entries are processed initially and
  2380. * ADISC is initited for each one. Completions / Events for each node are
  2381. * funnelled thru the state machine. As each node finishes ADISC processing, it
  2382. * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
  2383. * waiting, and the ADISC list count is identically 0, then we are done. For
  2384. * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
  2385. * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
  2386. * list. 32 entries are processed initially and PLOGI is initited for each one.
  2387. * Completions / Events for each node are funnelled thru the state machine. As
  2388. * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
  2389. * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
  2390. * indentically 0, then we are done. We have now completed discovery / RSCN
  2391. * handling. Upon completion, ALL nodes should be on either the mapped or
  2392. * unmapped lists.
  2393. */
  2394. static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
  2395. (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
  2396. /* Action routine Event Current State */
  2397. lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
  2398. lpfc_rcv_els_unused_node, /* RCV_PRLI */
  2399. lpfc_rcv_logo_unused_node, /* RCV_LOGO */
  2400. lpfc_rcv_els_unused_node, /* RCV_ADISC */
  2401. lpfc_rcv_els_unused_node, /* RCV_PDISC */
  2402. lpfc_rcv_els_unused_node, /* RCV_PRLO */
  2403. lpfc_disc_illegal, /* CMPL_PLOGI */
  2404. lpfc_disc_illegal, /* CMPL_PRLI */
  2405. lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
  2406. lpfc_disc_illegal, /* CMPL_ADISC */
  2407. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2408. lpfc_device_rm_unused_node, /* DEVICE_RM */
  2409. lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
  2410. lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
  2411. lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
  2412. lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
  2413. lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
  2414. lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
  2415. lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
  2416. lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
  2417. lpfc_disc_illegal, /* CMPL_PRLI */
  2418. lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
  2419. lpfc_disc_illegal, /* CMPL_ADISC */
  2420. lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
  2421. lpfc_device_rm_plogi_issue, /* DEVICE_RM */
  2422. lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
  2423. lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
  2424. lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
  2425. lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
  2426. lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
  2427. lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
  2428. lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
  2429. lpfc_disc_illegal, /* CMPL_PLOGI */
  2430. lpfc_disc_illegal, /* CMPL_PRLI */
  2431. lpfc_disc_illegal, /* CMPL_LOGO */
  2432. lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
  2433. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2434. lpfc_device_rm_adisc_issue, /* DEVICE_RM */
  2435. lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
  2436. lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
  2437. lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
  2438. lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
  2439. lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
  2440. lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
  2441. lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
  2442. lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
  2443. lpfc_disc_illegal, /* CMPL_PRLI */
  2444. lpfc_disc_illegal, /* CMPL_LOGO */
  2445. lpfc_disc_illegal, /* CMPL_ADISC */
  2446. lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
  2447. lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
  2448. lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
  2449. lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
  2450. lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
  2451. lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
  2452. lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
  2453. lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
  2454. lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
  2455. lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
  2456. lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
  2457. lpfc_disc_illegal, /* CMPL_LOGO */
  2458. lpfc_disc_illegal, /* CMPL_ADISC */
  2459. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2460. lpfc_device_rm_prli_issue, /* DEVICE_RM */
  2461. lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
  2462. lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
  2463. lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
  2464. lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
  2465. lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
  2466. lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
  2467. lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
  2468. lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
  2469. lpfc_disc_illegal, /* CMPL_PRLI */
  2470. lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
  2471. lpfc_disc_illegal, /* CMPL_ADISC */
  2472. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2473. lpfc_device_rm_logo_issue, /* DEVICE_RM */
  2474. lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
  2475. lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
  2476. lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
  2477. lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
  2478. lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
  2479. lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
  2480. lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
  2481. lpfc_disc_illegal, /* CMPL_PLOGI */
  2482. lpfc_disc_illegal, /* CMPL_PRLI */
  2483. lpfc_disc_illegal, /* CMPL_LOGO */
  2484. lpfc_disc_illegal, /* CMPL_ADISC */
  2485. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2486. lpfc_disc_illegal, /* DEVICE_RM */
  2487. lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
  2488. lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
  2489. lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
  2490. lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
  2491. lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
  2492. lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
  2493. lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
  2494. lpfc_disc_illegal, /* CMPL_PLOGI */
  2495. lpfc_disc_illegal, /* CMPL_PRLI */
  2496. lpfc_disc_illegal, /* CMPL_LOGO */
  2497. lpfc_disc_illegal, /* CMPL_ADISC */
  2498. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2499. lpfc_disc_illegal, /* DEVICE_RM */
  2500. lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
  2501. lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
  2502. lpfc_rcv_prli_npr_node, /* RCV_PRLI */
  2503. lpfc_rcv_logo_npr_node, /* RCV_LOGO */
  2504. lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
  2505. lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
  2506. lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
  2507. lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
  2508. lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
  2509. lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
  2510. lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
  2511. lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
  2512. lpfc_device_rm_npr_node, /* DEVICE_RM */
  2513. lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
  2514. };
  2515. int
  2516. lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2517. void *arg, uint32_t evt)
  2518. {
  2519. uint32_t cur_state, rc;
  2520. uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
  2521. uint32_t);
  2522. uint32_t got_ndlp = 0;
  2523. if (lpfc_nlp_get(ndlp))
  2524. got_ndlp = 1;
  2525. cur_state = ndlp->nlp_state;
  2526. /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
  2527. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2528. "0211 DSM in event x%x on NPort x%x in "
  2529. "state %d Data: x%x x%x\n",
  2530. evt, ndlp->nlp_DID, cur_state,
  2531. ndlp->nlp_flag, ndlp->nlp_fc4_type);
  2532. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
  2533. "DSM in: evt:%d ste:%d did:x%x",
  2534. evt, cur_state, ndlp->nlp_DID);
  2535. func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
  2536. rc = (func) (vport, ndlp, arg, evt);
  2537. /* DSM out state <rc> on NPort <nlp_DID> */
  2538. if (got_ndlp) {
  2539. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2540. "0212 DSM out state %d on NPort x%x Data: x%x\n",
  2541. rc, ndlp->nlp_DID, ndlp->nlp_flag);
  2542. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
  2543. "DSM out: ste:%d did:x%x flg:x%x",
  2544. rc, ndlp->nlp_DID, ndlp->nlp_flag);
  2545. /* Decrement the ndlp reference count held for this function */
  2546. lpfc_nlp_put(ndlp);
  2547. } else {
  2548. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2549. "0213 DSM out state %d on NPort free\n", rc);
  2550. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
  2551. "DSM out: ste:%d did:x%x flg:x%x",
  2552. rc, 0, 0);
  2553. }
  2554. return rc;
  2555. }