lpfc_nportdisc.c 52 KB

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