lpfc_nportdisc.c 64 KB

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