lpfc_nportdisc.c 69 KB

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