lpfc_nportdisc.c 68 KB

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