lpfc_nportdisc.c 77 KB

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