lpfc_nportdisc.c 66 KB

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