lpfc_nportdisc.c 68 KB

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