lpfc_nportdisc.c 62 KB

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