lpfc_nportdisc.c 76 KB

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