lpfc_nportdisc.c 75 KB

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