lpfc_nportdisc.c 64 KB

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