lpfc_nportdisc.c 78 KB

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