lpfc_nportdisc.c 76 KB

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