lpfc_nportdisc.c 62 KB

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