lpfc_nportdisc.c 55 KB

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