lpfc_nportdisc.c 68 KB

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