lpfc_nportdisc.c 52 KB

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