lpfc_nportdisc.c 62 KB

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