lpfc_nportdisc.c 71 KB

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