lpfc_nportdisc.c 65 KB

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