lpfc_nportdisc.c 65 KB

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