lpfc_nportdisc.c 75 KB

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