lpfc_nportdisc.c 65 KB

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