lpfc_nportdisc.c 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2015 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. lpfc_nlp_put(ndlp);
  1332. mb->context2 = NULL;
  1333. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1334. }
  1335. }
  1336. spin_lock_irq(&phba->hbalock);
  1337. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  1338. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  1339. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1340. mp = (struct lpfc_dmabuf *) (mb->context1);
  1341. if (mp) {
  1342. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1343. kfree(mp);
  1344. }
  1345. lpfc_nlp_put(ndlp);
  1346. list_del(&mb->list);
  1347. phba->sli.mboxq_cnt--;
  1348. mempool_free(mb, phba->mbox_mem_pool);
  1349. }
  1350. }
  1351. spin_unlock_irq(&phba->hbalock);
  1352. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1353. return ndlp->nlp_state;
  1354. }
  1355. static uint32_t
  1356. lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
  1357. struct lpfc_nodelist *ndlp,
  1358. void *arg,
  1359. uint32_t evt)
  1360. {
  1361. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1362. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1363. return ndlp->nlp_state;
  1364. }
  1365. static uint32_t
  1366. lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
  1367. struct lpfc_nodelist *ndlp,
  1368. void *arg,
  1369. uint32_t evt)
  1370. {
  1371. struct lpfc_iocbq *cmdiocb;
  1372. cmdiocb = (struct lpfc_iocbq *) arg;
  1373. lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
  1374. return ndlp->nlp_state;
  1375. }
  1376. static uint32_t
  1377. lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
  1378. struct lpfc_nodelist *ndlp,
  1379. void *arg,
  1380. uint32_t evt)
  1381. {
  1382. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1383. LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
  1384. MAILBOX_t *mb = &pmb->u.mb;
  1385. uint32_t did = mb->un.varWords[1];
  1386. if (mb->mbxStatus) {
  1387. /* RegLogin failed */
  1388. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1389. "0246 RegLogin failed Data: x%x x%x x%x x%x "
  1390. "x%x\n",
  1391. did, mb->mbxStatus, vport->port_state,
  1392. mb->un.varRegLogin.vpi,
  1393. mb->un.varRegLogin.rpi);
  1394. /*
  1395. * If RegLogin failed due to lack of HBA resources do not
  1396. * retry discovery.
  1397. */
  1398. if (mb->mbxStatus == MBXERR_RPI_FULL) {
  1399. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1400. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1401. return ndlp->nlp_state;
  1402. }
  1403. /* Put ndlp in npr state set plogi timer for 1 sec */
  1404. mod_timer(&ndlp->nlp_delayfunc,
  1405. jiffies + msecs_to_jiffies(1000 * 1));
  1406. spin_lock_irq(shost->host_lock);
  1407. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1408. spin_unlock_irq(shost->host_lock);
  1409. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  1410. lpfc_issue_els_logo(vport, ndlp, 0);
  1411. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1412. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1413. return ndlp->nlp_state;
  1414. }
  1415. /* SLI4 ports have preallocated logical rpis. */
  1416. if (vport->phba->sli_rev < LPFC_SLI_REV4)
  1417. ndlp->nlp_rpi = mb->un.varWords[0];
  1418. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  1419. /* Only if we are not a fabric nport do we issue PRLI */
  1420. if (!(ndlp->nlp_type & NLP_FABRIC)) {
  1421. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1422. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  1423. lpfc_issue_els_prli(vport, ndlp, 0);
  1424. } else {
  1425. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1426. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1427. }
  1428. return ndlp->nlp_state;
  1429. }
  1430. static uint32_t
  1431. lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
  1432. struct lpfc_nodelist *ndlp,
  1433. void *arg,
  1434. uint32_t evt)
  1435. {
  1436. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1437. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1438. spin_lock_irq(shost->host_lock);
  1439. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1440. spin_unlock_irq(shost->host_lock);
  1441. return ndlp->nlp_state;
  1442. } else {
  1443. lpfc_drop_node(vport, ndlp);
  1444. return NLP_STE_FREED_NODE;
  1445. }
  1446. }
  1447. static uint32_t
  1448. lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
  1449. struct lpfc_nodelist *ndlp,
  1450. void *arg,
  1451. uint32_t evt)
  1452. {
  1453. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1454. /* Don't do anything that will mess up processing of the
  1455. * previous RSCN.
  1456. */
  1457. if (vport->fc_flag & FC_RSCN_DEFERRED)
  1458. return ndlp->nlp_state;
  1459. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1460. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1461. spin_lock_irq(shost->host_lock);
  1462. ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
  1463. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1464. spin_unlock_irq(shost->host_lock);
  1465. lpfc_disc_set_adisc(vport, ndlp);
  1466. return ndlp->nlp_state;
  1467. }
  1468. static uint32_t
  1469. lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1470. void *arg, uint32_t evt)
  1471. {
  1472. struct lpfc_iocbq *cmdiocb;
  1473. cmdiocb = (struct lpfc_iocbq *) arg;
  1474. lpfc_rcv_plogi(vport, ndlp, cmdiocb);
  1475. return ndlp->nlp_state;
  1476. }
  1477. static uint32_t
  1478. lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1479. void *arg, uint32_t evt)
  1480. {
  1481. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1482. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  1483. return ndlp->nlp_state;
  1484. }
  1485. static uint32_t
  1486. lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1487. void *arg, uint32_t evt)
  1488. {
  1489. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1490. /* Software abort outstanding PRLI before sending acc */
  1491. lpfc_els_abort(vport->phba, ndlp);
  1492. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1493. return ndlp->nlp_state;
  1494. }
  1495. static uint32_t
  1496. lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1497. void *arg, uint32_t evt)
  1498. {
  1499. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1500. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1501. return ndlp->nlp_state;
  1502. }
  1503. /* This routine is envoked when we rcv a PRLO request from a nport
  1504. * we are logged into. We should send back a PRLO rsp setting the
  1505. * appropriate bits.
  1506. * NEXT STATE = PRLI_ISSUE
  1507. */
  1508. static uint32_t
  1509. lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1510. void *arg, uint32_t evt)
  1511. {
  1512. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1513. lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
  1514. return ndlp->nlp_state;
  1515. }
  1516. static uint32_t
  1517. lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1518. void *arg, uint32_t evt)
  1519. {
  1520. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1521. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1522. struct lpfc_hba *phba = vport->phba;
  1523. IOCB_t *irsp;
  1524. PRLI *npr;
  1525. cmdiocb = (struct lpfc_iocbq *) arg;
  1526. rspiocb = cmdiocb->context_un.rsp_iocb;
  1527. npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
  1528. irsp = &rspiocb->iocb;
  1529. if (irsp->ulpStatus) {
  1530. if ((vport->port_type == LPFC_NPIV_PORT) &&
  1531. vport->cfg_restrict_login) {
  1532. goto out;
  1533. }
  1534. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1535. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1536. return ndlp->nlp_state;
  1537. }
  1538. /* Check out PRLI rsp */
  1539. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  1540. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  1541. ndlp->nlp_flag &= ~NLP_FIRSTBURST;
  1542. if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
  1543. (npr->prliType == PRLI_FCP_TYPE)) {
  1544. if (npr->initiatorFunc)
  1545. ndlp->nlp_type |= NLP_FCP_INITIATOR;
  1546. if (npr->targetFunc) {
  1547. ndlp->nlp_type |= NLP_FCP_TARGET;
  1548. if (npr->writeXferRdyDis)
  1549. ndlp->nlp_flag |= NLP_FIRSTBURST;
  1550. }
  1551. if (npr->Retry)
  1552. ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
  1553. }
  1554. if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
  1555. (vport->port_type == LPFC_NPIV_PORT) &&
  1556. vport->cfg_restrict_login) {
  1557. out:
  1558. spin_lock_irq(shost->host_lock);
  1559. ndlp->nlp_flag |= NLP_TARGET_REMOVE;
  1560. spin_unlock_irq(shost->host_lock);
  1561. lpfc_issue_els_logo(vport, ndlp, 0);
  1562. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1563. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1564. return ndlp->nlp_state;
  1565. }
  1566. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1567. if (ndlp->nlp_type & NLP_FCP_TARGET)
  1568. lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
  1569. else
  1570. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1571. return ndlp->nlp_state;
  1572. }
  1573. /*! lpfc_device_rm_prli_issue
  1574. *
  1575. * \pre
  1576. * \post
  1577. * \param phba
  1578. * \param ndlp
  1579. * \param arg
  1580. * \param evt
  1581. * \return uint32_t
  1582. *
  1583. * \b Description:
  1584. * This routine is envoked when we a request to remove a nport we are in the
  1585. * process of PRLIing. We should software abort outstanding prli, unreg
  1586. * login, send a logout. We will change node state to UNUSED_NODE, put it
  1587. * on plogi list so it can be freed when LOGO completes.
  1588. *
  1589. */
  1590. static uint32_t
  1591. lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1592. void *arg, uint32_t evt)
  1593. {
  1594. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1595. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1596. spin_lock_irq(shost->host_lock);
  1597. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  1598. spin_unlock_irq(shost->host_lock);
  1599. return ndlp->nlp_state;
  1600. } else {
  1601. /* software abort outstanding PLOGI */
  1602. lpfc_els_abort(vport->phba, ndlp);
  1603. lpfc_drop_node(vport, ndlp);
  1604. return NLP_STE_FREED_NODE;
  1605. }
  1606. }
  1607. /*! lpfc_device_recov_prli_issue
  1608. *
  1609. * \pre
  1610. * \post
  1611. * \param phba
  1612. * \param ndlp
  1613. * \param arg
  1614. * \param evt
  1615. * \return uint32_t
  1616. *
  1617. * \b Description:
  1618. * The routine is envoked when the state of a device is unknown, like
  1619. * during a link down. We should remove the nodelist entry from the
  1620. * unmapped list, issue a UNREG_LOGIN, do a software abort of the
  1621. * outstanding PRLI command, then free the node entry.
  1622. */
  1623. static uint32_t
  1624. lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
  1625. struct lpfc_nodelist *ndlp,
  1626. void *arg,
  1627. uint32_t evt)
  1628. {
  1629. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1630. struct lpfc_hba *phba = vport->phba;
  1631. /* Don't do anything that will mess up processing of the
  1632. * previous RSCN.
  1633. */
  1634. if (vport->fc_flag & FC_RSCN_DEFERRED)
  1635. return ndlp->nlp_state;
  1636. /* software abort outstanding PRLI */
  1637. lpfc_els_abort(phba, ndlp);
  1638. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1639. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1640. spin_lock_irq(shost->host_lock);
  1641. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1642. spin_unlock_irq(shost->host_lock);
  1643. lpfc_disc_set_adisc(vport, ndlp);
  1644. return ndlp->nlp_state;
  1645. }
  1646. static uint32_t
  1647. lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1648. void *arg, uint32_t evt)
  1649. {
  1650. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
  1651. struct ls_rjt stat;
  1652. memset(&stat, 0, sizeof(struct ls_rjt));
  1653. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1654. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1655. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  1656. return ndlp->nlp_state;
  1657. }
  1658. static uint32_t
  1659. lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1660. void *arg, uint32_t evt)
  1661. {
  1662. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
  1663. struct ls_rjt stat;
  1664. memset(&stat, 0, sizeof(struct ls_rjt));
  1665. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1666. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1667. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  1668. return ndlp->nlp_state;
  1669. }
  1670. static uint32_t
  1671. lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1672. void *arg, uint32_t evt)
  1673. {
  1674. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1675. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
  1676. spin_lock_irq(shost->host_lock);
  1677. ndlp->nlp_flag |= NLP_LOGO_ACC;
  1678. spin_unlock_irq(shost->host_lock);
  1679. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  1680. return ndlp->nlp_state;
  1681. }
  1682. static uint32_t
  1683. lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1684. void *arg, uint32_t evt)
  1685. {
  1686. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
  1687. struct ls_rjt stat;
  1688. memset(&stat, 0, sizeof(struct ls_rjt));
  1689. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1690. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1691. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  1692. return ndlp->nlp_state;
  1693. }
  1694. static uint32_t
  1695. lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1696. void *arg, uint32_t evt)
  1697. {
  1698. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
  1699. struct ls_rjt stat;
  1700. memset(&stat, 0, sizeof(struct ls_rjt));
  1701. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1702. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1703. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  1704. return ndlp->nlp_state;
  1705. }
  1706. static uint32_t
  1707. lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1708. void *arg, uint32_t evt)
  1709. {
  1710. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1711. ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
  1712. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1713. spin_lock_irq(shost->host_lock);
  1714. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1715. spin_unlock_irq(shost->host_lock);
  1716. lpfc_disc_set_adisc(vport, ndlp);
  1717. return ndlp->nlp_state;
  1718. }
  1719. static uint32_t
  1720. lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1721. void *arg, uint32_t evt)
  1722. {
  1723. /*
  1724. * Take no action. If a LOGO is outstanding, then possibly DevLoss has
  1725. * timed out and is calling for Device Remove. In this case, the LOGO
  1726. * must be allowed to complete in state LOGO_ISSUE so that the rpi
  1727. * and other NLP flags are correctly cleaned up.
  1728. */
  1729. return ndlp->nlp_state;
  1730. }
  1731. static uint32_t
  1732. lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
  1733. struct lpfc_nodelist *ndlp,
  1734. void *arg, uint32_t evt)
  1735. {
  1736. /*
  1737. * Device Recovery events have no meaning for a node with a LOGO
  1738. * outstanding. The LOGO has to complete first and handle the
  1739. * node from that point.
  1740. */
  1741. return ndlp->nlp_state;
  1742. }
  1743. static uint32_t
  1744. lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1745. void *arg, uint32_t evt)
  1746. {
  1747. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1748. lpfc_rcv_plogi(vport, ndlp, cmdiocb);
  1749. return ndlp->nlp_state;
  1750. }
  1751. static uint32_t
  1752. lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1753. void *arg, uint32_t evt)
  1754. {
  1755. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1756. lpfc_rcv_prli(vport, ndlp, cmdiocb);
  1757. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  1758. return ndlp->nlp_state;
  1759. }
  1760. static uint32_t
  1761. lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1762. void *arg, uint32_t evt)
  1763. {
  1764. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1765. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1766. return ndlp->nlp_state;
  1767. }
  1768. static uint32_t
  1769. lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1770. void *arg, uint32_t evt)
  1771. {
  1772. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1773. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1774. return ndlp->nlp_state;
  1775. }
  1776. static uint32_t
  1777. lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1778. void *arg, uint32_t evt)
  1779. {
  1780. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1781. lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
  1782. return ndlp->nlp_state;
  1783. }
  1784. static uint32_t
  1785. lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
  1786. struct lpfc_nodelist *ndlp,
  1787. void *arg,
  1788. uint32_t evt)
  1789. {
  1790. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1791. ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
  1792. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1793. spin_lock_irq(shost->host_lock);
  1794. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1795. spin_unlock_irq(shost->host_lock);
  1796. lpfc_disc_set_adisc(vport, ndlp);
  1797. return ndlp->nlp_state;
  1798. }
  1799. static uint32_t
  1800. lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1801. void *arg, uint32_t evt)
  1802. {
  1803. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1804. lpfc_rcv_plogi(vport, ndlp, cmdiocb);
  1805. return ndlp->nlp_state;
  1806. }
  1807. static uint32_t
  1808. lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1809. void *arg, uint32_t evt)
  1810. {
  1811. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1812. lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
  1813. return ndlp->nlp_state;
  1814. }
  1815. static uint32_t
  1816. lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1817. void *arg, uint32_t evt)
  1818. {
  1819. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1820. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1821. return ndlp->nlp_state;
  1822. }
  1823. static uint32_t
  1824. lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
  1825. struct lpfc_nodelist *ndlp,
  1826. void *arg, uint32_t evt)
  1827. {
  1828. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1829. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1830. return ndlp->nlp_state;
  1831. }
  1832. static uint32_t
  1833. lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1834. void *arg, uint32_t evt)
  1835. {
  1836. struct lpfc_hba *phba = vport->phba;
  1837. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1838. /* flush the target */
  1839. lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
  1840. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  1841. /* Treat like rcv logo */
  1842. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
  1843. return ndlp->nlp_state;
  1844. }
  1845. static uint32_t
  1846. lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
  1847. struct lpfc_nodelist *ndlp,
  1848. void *arg,
  1849. uint32_t evt)
  1850. {
  1851. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1852. ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
  1853. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1854. spin_lock_irq(shost->host_lock);
  1855. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  1856. spin_unlock_irq(shost->host_lock);
  1857. lpfc_disc_set_adisc(vport, ndlp);
  1858. return ndlp->nlp_state;
  1859. }
  1860. static uint32_t
  1861. lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1862. void *arg, uint32_t evt)
  1863. {
  1864. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1865. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1866. /* Ignore PLOGI if we have an outstanding LOGO */
  1867. if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
  1868. return ndlp->nlp_state;
  1869. if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
  1870. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  1871. spin_lock_irq(shost->host_lock);
  1872. ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
  1873. spin_unlock_irq(shost->host_lock);
  1874. } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
  1875. /* send PLOGI immediately, move to PLOGI issue state */
  1876. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1877. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1878. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  1879. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  1880. }
  1881. }
  1882. return ndlp->nlp_state;
  1883. }
  1884. static uint32_t
  1885. lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1886. void *arg, uint32_t evt)
  1887. {
  1888. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1889. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1890. struct ls_rjt stat;
  1891. memset(&stat, 0, sizeof (struct ls_rjt));
  1892. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1893. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1894. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  1895. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1896. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  1897. spin_lock_irq(shost->host_lock);
  1898. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1899. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1900. spin_unlock_irq(shost->host_lock);
  1901. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  1902. lpfc_issue_els_adisc(vport, ndlp, 0);
  1903. } else {
  1904. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1905. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  1906. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  1907. }
  1908. }
  1909. return ndlp->nlp_state;
  1910. }
  1911. static uint32_t
  1912. lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1913. void *arg, uint32_t evt)
  1914. {
  1915. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1916. lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
  1917. return ndlp->nlp_state;
  1918. }
  1919. static uint32_t
  1920. lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1921. void *arg, uint32_t evt)
  1922. {
  1923. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1924. lpfc_rcv_padisc(vport, ndlp, cmdiocb);
  1925. /*
  1926. * Do not start discovery if discovery is about to start
  1927. * or discovery in progress for this node. Starting discovery
  1928. * here will affect the counting of discovery threads.
  1929. */
  1930. if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
  1931. !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
  1932. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  1933. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1934. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1935. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  1936. lpfc_issue_els_adisc(vport, ndlp, 0);
  1937. } else {
  1938. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1939. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  1940. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  1941. }
  1942. }
  1943. return ndlp->nlp_state;
  1944. }
  1945. static uint32_t
  1946. lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1947. void *arg, uint32_t evt)
  1948. {
  1949. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1950. struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
  1951. spin_lock_irq(shost->host_lock);
  1952. ndlp->nlp_flag |= NLP_LOGO_ACC;
  1953. spin_unlock_irq(shost->host_lock);
  1954. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  1955. if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
  1956. mod_timer(&ndlp->nlp_delayfunc,
  1957. jiffies + msecs_to_jiffies(1000 * 1));
  1958. spin_lock_irq(shost->host_lock);
  1959. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1960. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1961. spin_unlock_irq(shost->host_lock);
  1962. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  1963. } else {
  1964. spin_lock_irq(shost->host_lock);
  1965. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1966. spin_unlock_irq(shost->host_lock);
  1967. }
  1968. return ndlp->nlp_state;
  1969. }
  1970. static uint32_t
  1971. lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1972. void *arg, uint32_t evt)
  1973. {
  1974. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1975. IOCB_t *irsp;
  1976. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1977. cmdiocb = (struct lpfc_iocbq *) arg;
  1978. rspiocb = cmdiocb->context_un.rsp_iocb;
  1979. irsp = &rspiocb->iocb;
  1980. if (irsp->ulpStatus) {
  1981. spin_lock_irq(shost->host_lock);
  1982. ndlp->nlp_flag |= NLP_DEFER_RM;
  1983. spin_unlock_irq(shost->host_lock);
  1984. return NLP_STE_FREED_NODE;
  1985. }
  1986. return ndlp->nlp_state;
  1987. }
  1988. static uint32_t
  1989. lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1990. void *arg, uint32_t evt)
  1991. {
  1992. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1993. IOCB_t *irsp;
  1994. cmdiocb = (struct lpfc_iocbq *) arg;
  1995. rspiocb = cmdiocb->context_un.rsp_iocb;
  1996. irsp = &rspiocb->iocb;
  1997. if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
  1998. lpfc_drop_node(vport, ndlp);
  1999. return NLP_STE_FREED_NODE;
  2000. }
  2001. return ndlp->nlp_state;
  2002. }
  2003. static uint32_t
  2004. lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2005. void *arg, uint32_t evt)
  2006. {
  2007. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2008. /* For the fabric port just clear the fc flags. */
  2009. if (ndlp->nlp_DID == Fabric_DID) {
  2010. spin_lock_irq(shost->host_lock);
  2011. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  2012. spin_unlock_irq(shost->host_lock);
  2013. }
  2014. lpfc_unreg_rpi(vport, ndlp);
  2015. return ndlp->nlp_state;
  2016. }
  2017. static uint32_t
  2018. lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2019. void *arg, uint32_t evt)
  2020. {
  2021. struct lpfc_iocbq *cmdiocb, *rspiocb;
  2022. IOCB_t *irsp;
  2023. cmdiocb = (struct lpfc_iocbq *) arg;
  2024. rspiocb = cmdiocb->context_un.rsp_iocb;
  2025. irsp = &rspiocb->iocb;
  2026. if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
  2027. lpfc_drop_node(vport, ndlp);
  2028. return NLP_STE_FREED_NODE;
  2029. }
  2030. return ndlp->nlp_state;
  2031. }
  2032. static uint32_t
  2033. lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
  2034. struct lpfc_nodelist *ndlp,
  2035. void *arg, uint32_t evt)
  2036. {
  2037. LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
  2038. MAILBOX_t *mb = &pmb->u.mb;
  2039. if (!mb->mbxStatus) {
  2040. /* SLI4 ports have preallocated logical rpis. */
  2041. if (vport->phba->sli_rev < LPFC_SLI_REV4)
  2042. ndlp->nlp_rpi = mb->un.varWords[0];
  2043. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  2044. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  2045. lpfc_unreg_rpi(vport, ndlp);
  2046. }
  2047. } else {
  2048. if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
  2049. lpfc_drop_node(vport, ndlp);
  2050. return NLP_STE_FREED_NODE;
  2051. }
  2052. }
  2053. return ndlp->nlp_state;
  2054. }
  2055. static uint32_t
  2056. lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2057. void *arg, uint32_t evt)
  2058. {
  2059. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2060. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  2061. spin_lock_irq(shost->host_lock);
  2062. ndlp->nlp_flag |= NLP_NODEV_REMOVE;
  2063. spin_unlock_irq(shost->host_lock);
  2064. return ndlp->nlp_state;
  2065. }
  2066. lpfc_drop_node(vport, ndlp);
  2067. return NLP_STE_FREED_NODE;
  2068. }
  2069. static uint32_t
  2070. lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2071. void *arg, uint32_t evt)
  2072. {
  2073. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2074. /* Don't do anything that will mess up processing of the
  2075. * previous RSCN.
  2076. */
  2077. if (vport->fc_flag & FC_RSCN_DEFERRED)
  2078. return ndlp->nlp_state;
  2079. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2080. spin_lock_irq(shost->host_lock);
  2081. ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
  2082. spin_unlock_irq(shost->host_lock);
  2083. return ndlp->nlp_state;
  2084. }
  2085. /* This next section defines the NPort Discovery State Machine */
  2086. /* There are 4 different double linked lists nodelist entries can reside on.
  2087. * The plogi list and adisc list are used when Link Up discovery or RSCN
  2088. * processing is needed. Each list holds the nodes that we will send PLOGI
  2089. * or ADISC on. These lists will keep track of what nodes will be effected
  2090. * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
  2091. * The unmapped_list will contain all nodes that we have successfully logged
  2092. * into at the Fibre Channel level. The mapped_list will contain all nodes
  2093. * that are mapped FCP targets.
  2094. */
  2095. /*
  2096. * The bind list is a list of undiscovered (potentially non-existent) nodes
  2097. * that we have saved binding information on. This information is used when
  2098. * nodes transition from the unmapped to the mapped list.
  2099. */
  2100. /* For UNUSED_NODE state, the node has just been allocated .
  2101. * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
  2102. * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
  2103. * and put on the unmapped list. For ADISC processing, the node is taken off
  2104. * the ADISC list and placed on either the mapped or unmapped list (depending
  2105. * on its previous state). Once on the unmapped list, a PRLI is issued and the
  2106. * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
  2107. * changed to UNMAPPED_NODE. If the completion indicates a mapped
  2108. * node, the node is taken off the unmapped list. The binding list is checked
  2109. * for a valid binding, or a binding is automatically assigned. If binding
  2110. * assignment is unsuccessful, the node is left on the unmapped list. If
  2111. * binding assignment is successful, the associated binding list entry (if
  2112. * any) is removed, and the node is placed on the mapped list.
  2113. */
  2114. /*
  2115. * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
  2116. * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
  2117. * expire, all effected nodes will receive a DEVICE_RM event.
  2118. */
  2119. /*
  2120. * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
  2121. * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
  2122. * check, additional nodes may be added or removed (via DEVICE_RM) to / from
  2123. * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
  2124. * we will first process the ADISC list. 32 entries are processed initially and
  2125. * ADISC is initited for each one. Completions / Events for each node are
  2126. * funnelled thru the state machine. As each node finishes ADISC processing, it
  2127. * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
  2128. * waiting, and the ADISC list count is identically 0, then we are done. For
  2129. * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
  2130. * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
  2131. * list. 32 entries are processed initially and PLOGI is initited for each one.
  2132. * Completions / Events for each node are funnelled thru the state machine. As
  2133. * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
  2134. * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
  2135. * indentically 0, then we are done. We have now completed discovery / RSCN
  2136. * handling. Upon completion, ALL nodes should be on either the mapped or
  2137. * unmapped lists.
  2138. */
  2139. static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
  2140. (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
  2141. /* Action routine Event Current State */
  2142. lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
  2143. lpfc_rcv_els_unused_node, /* RCV_PRLI */
  2144. lpfc_rcv_logo_unused_node, /* RCV_LOGO */
  2145. lpfc_rcv_els_unused_node, /* RCV_ADISC */
  2146. lpfc_rcv_els_unused_node, /* RCV_PDISC */
  2147. lpfc_rcv_els_unused_node, /* RCV_PRLO */
  2148. lpfc_disc_illegal, /* CMPL_PLOGI */
  2149. lpfc_disc_illegal, /* CMPL_PRLI */
  2150. lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
  2151. lpfc_disc_illegal, /* CMPL_ADISC */
  2152. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2153. lpfc_device_rm_unused_node, /* DEVICE_RM */
  2154. lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
  2155. lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
  2156. lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
  2157. lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
  2158. lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
  2159. lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
  2160. lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
  2161. lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
  2162. lpfc_disc_illegal, /* CMPL_PRLI */
  2163. lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
  2164. lpfc_disc_illegal, /* CMPL_ADISC */
  2165. lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
  2166. lpfc_device_rm_plogi_issue, /* DEVICE_RM */
  2167. lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
  2168. lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
  2169. lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
  2170. lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
  2171. lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
  2172. lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
  2173. lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
  2174. lpfc_disc_illegal, /* CMPL_PLOGI */
  2175. lpfc_disc_illegal, /* CMPL_PRLI */
  2176. lpfc_disc_illegal, /* CMPL_LOGO */
  2177. lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
  2178. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2179. lpfc_device_rm_adisc_issue, /* DEVICE_RM */
  2180. lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
  2181. lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
  2182. lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
  2183. lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
  2184. lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
  2185. lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
  2186. lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
  2187. lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
  2188. lpfc_disc_illegal, /* CMPL_PRLI */
  2189. lpfc_disc_illegal, /* CMPL_LOGO */
  2190. lpfc_disc_illegal, /* CMPL_ADISC */
  2191. lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
  2192. lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
  2193. lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
  2194. lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
  2195. lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
  2196. lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
  2197. lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
  2198. lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
  2199. lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
  2200. lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
  2201. lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
  2202. lpfc_disc_illegal, /* CMPL_LOGO */
  2203. lpfc_disc_illegal, /* CMPL_ADISC */
  2204. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2205. lpfc_device_rm_prli_issue, /* DEVICE_RM */
  2206. lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
  2207. lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
  2208. lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
  2209. lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
  2210. lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
  2211. lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
  2212. lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
  2213. lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
  2214. lpfc_disc_illegal, /* CMPL_PRLI */
  2215. lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
  2216. lpfc_disc_illegal, /* CMPL_ADISC */
  2217. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2218. lpfc_device_rm_logo_issue, /* DEVICE_RM */
  2219. lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
  2220. lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
  2221. lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
  2222. lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
  2223. lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
  2224. lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
  2225. lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
  2226. lpfc_disc_illegal, /* CMPL_PLOGI */
  2227. lpfc_disc_illegal, /* CMPL_PRLI */
  2228. lpfc_disc_illegal, /* CMPL_LOGO */
  2229. lpfc_disc_illegal, /* CMPL_ADISC */
  2230. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2231. lpfc_disc_illegal, /* DEVICE_RM */
  2232. lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
  2233. lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
  2234. lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
  2235. lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
  2236. lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
  2237. lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
  2238. lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
  2239. lpfc_disc_illegal, /* CMPL_PLOGI */
  2240. lpfc_disc_illegal, /* CMPL_PRLI */
  2241. lpfc_disc_illegal, /* CMPL_LOGO */
  2242. lpfc_disc_illegal, /* CMPL_ADISC */
  2243. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  2244. lpfc_disc_illegal, /* DEVICE_RM */
  2245. lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
  2246. lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
  2247. lpfc_rcv_prli_npr_node, /* RCV_PRLI */
  2248. lpfc_rcv_logo_npr_node, /* RCV_LOGO */
  2249. lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
  2250. lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
  2251. lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
  2252. lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
  2253. lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
  2254. lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
  2255. lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
  2256. lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
  2257. lpfc_device_rm_npr_node, /* DEVICE_RM */
  2258. lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
  2259. };
  2260. int
  2261. lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2262. void *arg, uint32_t evt)
  2263. {
  2264. uint32_t cur_state, rc;
  2265. uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
  2266. uint32_t);
  2267. uint32_t got_ndlp = 0;
  2268. if (lpfc_nlp_get(ndlp))
  2269. got_ndlp = 1;
  2270. cur_state = ndlp->nlp_state;
  2271. /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
  2272. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2273. "0211 DSM in event x%x on NPort x%x in "
  2274. "state %d Data: x%x\n",
  2275. evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
  2276. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
  2277. "DSM in: evt:%d ste:%d did:x%x",
  2278. evt, cur_state, ndlp->nlp_DID);
  2279. func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
  2280. rc = (func) (vport, ndlp, arg, evt);
  2281. /* DSM out state <rc> on NPort <nlp_DID> */
  2282. if (got_ndlp) {
  2283. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2284. "0212 DSM out state %d on NPort x%x Data: x%x\n",
  2285. rc, ndlp->nlp_DID, ndlp->nlp_flag);
  2286. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
  2287. "DSM out: ste:%d did:x%x flg:x%x",
  2288. rc, ndlp->nlp_DID, ndlp->nlp_flag);
  2289. /* Decrement the ndlp reference count held for this function */
  2290. lpfc_nlp_put(ndlp);
  2291. } else {
  2292. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2293. "0213 DSM out state %d on NPort free\n", rc);
  2294. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
  2295. "DSM out: ste:%d did:x%x flg:x%x",
  2296. rc, 0, 0);
  2297. }
  2298. return rc;
  2299. }