lpfc_nportdisc.c 52 KB

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