lpfc_nportdisc.c 63 KB

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