lpfc_nportdisc.c 65 KB

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