lpfc_nportdisc.c 75 KB

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