lpfc_nportdisc.c 65 KB

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