lpfc_nportdisc.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2006 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <scsi/scsi.h>
  25. #include <scsi/scsi_device.h>
  26. #include <scsi/scsi_host.h>
  27. #include <scsi/scsi_transport_fc.h>
  28. #include "lpfc_hw.h"
  29. #include "lpfc_sli.h"
  30. #include "lpfc_disc.h"
  31. #include "lpfc_scsi.h"
  32. #include "lpfc.h"
  33. #include "lpfc_logmsg.h"
  34. #include "lpfc_crtn.h"
  35. /* Called to verify a rcv'ed ADISC was intended for us. */
  36. static int
  37. lpfc_check_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  38. struct lpfc_name * nn, struct lpfc_name * pn)
  39. {
  40. /* Compare the ADISC rsp WWNN / WWPN matches our internal node
  41. * table entry for that node.
  42. */
  43. if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)) != 0)
  44. return 0;
  45. if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)) != 0)
  46. return 0;
  47. /* we match, return success */
  48. return 1;
  49. }
  50. int
  51. lpfc_check_sparm(struct lpfc_hba * phba,
  52. struct lpfc_nodelist * ndlp, struct serv_parm * sp,
  53. uint32_t class)
  54. {
  55. volatile struct serv_parm *hsp = &phba->fc_sparam;
  56. uint16_t hsp_value, ssp_value = 0;
  57. /*
  58. * The receive data field size and buffer-to-buffer receive data field
  59. * size entries are 16 bits but are represented as two 8-bit fields in
  60. * the driver data structure to account for rsvd bits and other control
  61. * bits. Reconstruct and compare the fields as a 16-bit values before
  62. * correcting the byte values.
  63. */
  64. if (sp->cls1.classValid) {
  65. hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
  66. hsp->cls1.rcvDataSizeLsb;
  67. ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
  68. sp->cls1.rcvDataSizeLsb;
  69. if (ssp_value > hsp_value) {
  70. sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
  71. sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
  72. }
  73. } else if (class == CLASS1) {
  74. return 0;
  75. }
  76. if (sp->cls2.classValid) {
  77. hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
  78. hsp->cls2.rcvDataSizeLsb;
  79. ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
  80. sp->cls2.rcvDataSizeLsb;
  81. if (ssp_value > hsp_value) {
  82. sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
  83. sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
  84. }
  85. } else if (class == CLASS2) {
  86. return 0;
  87. }
  88. if (sp->cls3.classValid) {
  89. hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
  90. hsp->cls3.rcvDataSizeLsb;
  91. ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
  92. sp->cls3.rcvDataSizeLsb;
  93. if (ssp_value > hsp_value) {
  94. sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
  95. sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
  96. }
  97. } else if (class == CLASS3) {
  98. return 0;
  99. }
  100. /*
  101. * Preserve the upper four bits of the MSB from the PLOGI response.
  102. * These bits contain the Buffer-to-Buffer State Change Number
  103. * from the target and need to be passed to the FW.
  104. */
  105. hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
  106. ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
  107. if (ssp_value > hsp_value) {
  108. sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
  109. sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
  110. (hsp->cmn.bbRcvSizeMsb & 0x0F);
  111. }
  112. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
  113. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
  114. return 1;
  115. }
  116. static void *
  117. lpfc_check_elscmpl_iocb(struct lpfc_hba * phba,
  118. struct lpfc_iocbq *cmdiocb,
  119. struct lpfc_iocbq *rspiocb)
  120. {
  121. struct lpfc_dmabuf *pcmd, *prsp;
  122. uint32_t *lp;
  123. void *ptr = NULL;
  124. IOCB_t *irsp;
  125. irsp = &rspiocb->iocb;
  126. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  127. /* For lpfc_els_abort, context2 could be zero'ed to delay
  128. * freeing associated memory till after ABTS completes.
  129. */
  130. if (pcmd) {
  131. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
  132. list);
  133. if (prsp) {
  134. lp = (uint32_t *) prsp->virt;
  135. ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
  136. }
  137. } else {
  138. /* Force ulpStatus error since we are returning NULL ptr */
  139. if (!(irsp->ulpStatus)) {
  140. irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
  141. irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
  142. }
  143. ptr = NULL;
  144. }
  145. return ptr;
  146. }
  147. /*
  148. * Free resources / clean up outstanding I/Os
  149. * associated with a LPFC_NODELIST entry. This
  150. * routine effectively results in a "software abort".
  151. */
  152. int
  153. lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  154. int send_abts)
  155. {
  156. struct lpfc_sli *psli;
  157. struct lpfc_sli_ring *pring;
  158. struct lpfc_iocbq *iocb, *next_iocb;
  159. IOCB_t *icmd;
  160. int found = 0;
  161. /* Abort outstanding I/O on NPort <nlp_DID> */
  162. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  163. "%d:0201 Abort outstanding I/O on NPort x%x "
  164. "Data: x%x x%x x%x\n",
  165. phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
  166. ndlp->nlp_state, ndlp->nlp_rpi);
  167. psli = &phba->sli;
  168. pring = &psli->ring[LPFC_ELS_RING];
  169. /* First check the txq */
  170. do {
  171. found = 0;
  172. spin_lock_irq(phba->host->host_lock);
  173. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  174. /* Check to see if iocb matches the nport we are looking
  175. for */
  176. if ((lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))) {
  177. found = 1;
  178. /* It matches, so deque and call compl with an
  179. error */
  180. list_del(&iocb->list);
  181. pring->txq_cnt--;
  182. if (iocb->iocb_cmpl) {
  183. icmd = &iocb->iocb;
  184. icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  185. icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  186. spin_unlock_irq(phba->host->host_lock);
  187. (iocb->iocb_cmpl) (phba, iocb, iocb);
  188. spin_lock_irq(phba->host->host_lock);
  189. } else
  190. lpfc_sli_release_iocbq(phba, iocb);
  191. break;
  192. }
  193. }
  194. spin_unlock_irq(phba->host->host_lock);
  195. } while (found);
  196. /* Everything on txcmplq will be returned by firmware
  197. * with a no rpi / linkdown / abort error. For ring 0,
  198. * ELS discovery, we want to get rid of it right here.
  199. */
  200. /* Next check the txcmplq */
  201. do {
  202. found = 0;
  203. spin_lock_irq(phba->host->host_lock);
  204. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  205. list) {
  206. /* Check to see if iocb matches the nport we are looking
  207. for */
  208. if ((lpfc_check_sli_ndlp (phba, pring, iocb, ndlp))) {
  209. found = 1;
  210. /* It matches, so deque and call compl with an
  211. error */
  212. list_del(&iocb->list);
  213. pring->txcmplq_cnt--;
  214. icmd = &iocb->iocb;
  215. /* If the driver is completing an ELS
  216. * command early, flush it out of the firmware.
  217. */
  218. if (send_abts &&
  219. (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) &&
  220. (icmd->un.elsreq64.bdl.ulpIoTag32)) {
  221. lpfc_sli_issue_abort_iotag32(phba,
  222. pring, iocb);
  223. }
  224. if (iocb->iocb_cmpl) {
  225. icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  226. icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  227. spin_unlock_irq(phba->host->host_lock);
  228. (iocb->iocb_cmpl) (phba, iocb, iocb);
  229. spin_lock_irq(phba->host->host_lock);
  230. } else
  231. lpfc_sli_release_iocbq(phba, iocb);
  232. break;
  233. }
  234. }
  235. spin_unlock_irq(phba->host->host_lock);
  236. } while(found);
  237. /* If we are delaying issuing an ELS command, cancel it */
  238. if (ndlp->nlp_flag & NLP_DELAY_TMO) {
  239. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  240. ndlp->nlp_last_elscmd = 0;
  241. del_timer_sync(&ndlp->nlp_delayfunc);
  242. if (!list_empty(&ndlp->els_retry_evt.evt_listp))
  243. list_del_init(&ndlp->els_retry_evt.evt_listp);
  244. }
  245. return 0;
  246. }
  247. static int
  248. lpfc_rcv_plogi(struct lpfc_hba * phba,
  249. struct lpfc_nodelist * ndlp,
  250. struct lpfc_iocbq *cmdiocb)
  251. {
  252. struct lpfc_dmabuf *pcmd;
  253. uint32_t *lp;
  254. IOCB_t *icmd;
  255. struct serv_parm *sp;
  256. LPFC_MBOXQ_t *mbox;
  257. struct ls_rjt stat;
  258. int rc;
  259. memset(&stat, 0, sizeof (struct ls_rjt));
  260. if (phba->hba_state <= LPFC_FLOGI) {
  261. /* Before responding to PLOGI, check for pt2pt mode.
  262. * If we are pt2pt, with an outstanding FLOGI, abort
  263. * the FLOGI and resend it first.
  264. */
  265. if (phba->fc_flag & FC_PT2PT) {
  266. lpfc_els_abort_flogi(phba);
  267. if (!(phba->fc_flag & FC_PT2PT_PLOGI)) {
  268. /* If the other side is supposed to initiate
  269. * the PLOGI anyway, just ACC it now and
  270. * move on with discovery.
  271. */
  272. phba->fc_edtov = FF_DEF_EDTOV;
  273. phba->fc_ratov = FF_DEF_RATOV;
  274. /* Start discovery - this should just do
  275. CLEAR_LA */
  276. lpfc_disc_start(phba);
  277. } else {
  278. lpfc_initial_flogi(phba);
  279. }
  280. } else {
  281. stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
  282. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  283. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb,
  284. ndlp);
  285. return 0;
  286. }
  287. }
  288. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  289. lp = (uint32_t *) pcmd->virt;
  290. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  291. if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3) == 0)) {
  292. /* Reject this request because invalid parameters */
  293. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  294. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  295. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  296. return 0;
  297. }
  298. icmd = &cmdiocb->iocb;
  299. /* PLOGI chkparm OK */
  300. lpfc_printf_log(phba,
  301. KERN_INFO,
  302. LOG_ELS,
  303. "%d:0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
  304. phba->brd_no,
  305. ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
  306. ndlp->nlp_rpi);
  307. if ((phba->cfg_fcp_class == 2) &&
  308. (sp->cls2.classValid)) {
  309. ndlp->nlp_fcp_info |= CLASS2;
  310. } else {
  311. ndlp->nlp_fcp_info |= CLASS3;
  312. }
  313. ndlp->nlp_class_sup = 0;
  314. if (sp->cls1.classValid)
  315. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  316. if (sp->cls2.classValid)
  317. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  318. if (sp->cls3.classValid)
  319. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  320. if (sp->cls4.classValid)
  321. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  322. ndlp->nlp_maxframe =
  323. ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
  324. /* no need to reg_login if we are already in one of these states */
  325. switch (ndlp->nlp_state) {
  326. case NLP_STE_NPR_NODE:
  327. if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
  328. break;
  329. case NLP_STE_REG_LOGIN_ISSUE:
  330. case NLP_STE_PRLI_ISSUE:
  331. case NLP_STE_UNMAPPED_NODE:
  332. case NLP_STE_MAPPED_NODE:
  333. lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
  334. return 1;
  335. }
  336. if ((phba->fc_flag & FC_PT2PT)
  337. && !(phba->fc_flag & FC_PT2PT_PLOGI)) {
  338. /* rcv'ed PLOGI decides what our NPortId will be */
  339. phba->fc_myDID = icmd->un.rcvels.parmRo;
  340. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  341. if (mbox == NULL)
  342. goto out;
  343. lpfc_config_link(phba, mbox);
  344. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  345. rc = lpfc_sli_issue_mbox
  346. (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
  347. if (rc == MBX_NOT_FINISHED) {
  348. mempool_free( mbox, phba->mbox_mem_pool);
  349. goto out;
  350. }
  351. lpfc_can_disctmo(phba);
  352. }
  353. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  354. if (mbox == NULL)
  355. goto out;
  356. if (lpfc_reg_login(phba, icmd->un.rcvels.remoteID,
  357. (uint8_t *) sp, mbox, 0)) {
  358. mempool_free( mbox, phba->mbox_mem_pool);
  359. goto out;
  360. }
  361. /* ACC PLOGI rsp command needs to execute first,
  362. * queue this mbox command to be processed later.
  363. */
  364. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  365. mbox->context2 = ndlp;
  366. ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
  367. lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
  368. return 1;
  369. out:
  370. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  371. stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
  372. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  373. return 0;
  374. }
  375. static int
  376. lpfc_rcv_padisc(struct lpfc_hba * phba,
  377. struct lpfc_nodelist * ndlp,
  378. struct lpfc_iocbq *cmdiocb)
  379. {
  380. struct lpfc_dmabuf *pcmd;
  381. struct serv_parm *sp;
  382. struct lpfc_name *pnn, *ppn;
  383. struct ls_rjt stat;
  384. ADISC *ap;
  385. IOCB_t *icmd;
  386. uint32_t *lp;
  387. uint32_t cmd;
  388. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  389. lp = (uint32_t *) pcmd->virt;
  390. cmd = *lp++;
  391. if (cmd == ELS_CMD_ADISC) {
  392. ap = (ADISC *) lp;
  393. pnn = (struct lpfc_name *) & ap->nodeName;
  394. ppn = (struct lpfc_name *) & ap->portName;
  395. } else {
  396. sp = (struct serv_parm *) lp;
  397. pnn = (struct lpfc_name *) & sp->nodeName;
  398. ppn = (struct lpfc_name *) & sp->portName;
  399. }
  400. icmd = &cmdiocb->iocb;
  401. if ((icmd->ulpStatus == 0) &&
  402. (lpfc_check_adisc(phba, ndlp, pnn, ppn))) {
  403. if (cmd == ELS_CMD_ADISC) {
  404. lpfc_els_rsp_adisc_acc(phba, cmdiocb, ndlp);
  405. } else {
  406. lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp,
  407. NULL, 0);
  408. }
  409. return 1;
  410. }
  411. /* Reject this request because invalid parameters */
  412. stat.un.b.lsRjtRsvd0 = 0;
  413. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  414. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  415. stat.un.b.vendorUnique = 0;
  416. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  417. /* 1 sec timeout */
  418. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  419. spin_lock_irq(phba->host->host_lock);
  420. ndlp->nlp_flag |= NLP_DELAY_TMO;
  421. spin_unlock_irq(phba->host->host_lock);
  422. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  423. ndlp->nlp_prev_state = ndlp->nlp_state;
  424. ndlp->nlp_state = NLP_STE_NPR_NODE;
  425. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  426. return 0;
  427. }
  428. static int
  429. lpfc_rcv_logo(struct lpfc_hba * phba,
  430. struct lpfc_nodelist * ndlp,
  431. struct lpfc_iocbq *cmdiocb)
  432. {
  433. /* Put ndlp on NPR list with 1 sec timeout for plogi, ACC logo */
  434. /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
  435. * PLOGIs during LOGO storms from a device.
  436. */
  437. ndlp->nlp_flag |= NLP_LOGO_ACC;
  438. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  439. if (!(ndlp->nlp_type & NLP_FABRIC) ||
  440. (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
  441. /* Only try to re-login if this is NOT a Fabric Node */
  442. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  443. spin_lock_irq(phba->host->host_lock);
  444. ndlp->nlp_flag |= NLP_DELAY_TMO;
  445. spin_unlock_irq(phba->host->host_lock);
  446. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  447. ndlp->nlp_prev_state = ndlp->nlp_state;
  448. ndlp->nlp_state = NLP_STE_NPR_NODE;
  449. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  450. } else {
  451. ndlp->nlp_prev_state = ndlp->nlp_state;
  452. ndlp->nlp_state = NLP_STE_UNUSED_NODE;
  453. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  454. }
  455. spin_lock_irq(phba->host->host_lock);
  456. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  457. spin_unlock_irq(phba->host->host_lock);
  458. /* The driver has to wait until the ACC completes before it continues
  459. * processing the LOGO. The action will resume in
  460. * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
  461. * unreg_login, the driver waits so the ACC does not get aborted.
  462. */
  463. return 0;
  464. }
  465. static void
  466. lpfc_rcv_prli(struct lpfc_hba * phba,
  467. struct lpfc_nodelist * ndlp,
  468. struct lpfc_iocbq *cmdiocb)
  469. {
  470. struct lpfc_dmabuf *pcmd;
  471. uint32_t *lp;
  472. PRLI *npr;
  473. struct fc_rport *rport = ndlp->rport;
  474. u32 roles;
  475. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  476. lp = (uint32_t *) pcmd->virt;
  477. npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
  478. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  479. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  480. if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
  481. (npr->prliType == PRLI_FCP_TYPE)) {
  482. if (npr->initiatorFunc)
  483. ndlp->nlp_type |= NLP_FCP_INITIATOR;
  484. if (npr->targetFunc)
  485. ndlp->nlp_type |= NLP_FCP_TARGET;
  486. if (npr->Retry)
  487. ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
  488. }
  489. if (rport) {
  490. /* We need to update the rport role values */
  491. roles = FC_RPORT_ROLE_UNKNOWN;
  492. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  493. roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  494. if (ndlp->nlp_type & NLP_FCP_TARGET)
  495. roles |= FC_RPORT_ROLE_FCP_TARGET;
  496. fc_remote_port_rolechg(rport, roles);
  497. }
  498. }
  499. static uint32_t
  500. lpfc_disc_set_adisc(struct lpfc_hba * phba,
  501. struct lpfc_nodelist * ndlp)
  502. {
  503. /* Check config parameter use-adisc or FCP-2 */
  504. if ((phba->cfg_use_adisc == 0) &&
  505. !(phba->fc_flag & FC_RSCN_MODE)) {
  506. if (!(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
  507. return 0;
  508. }
  509. spin_lock_irq(phba->host->host_lock);
  510. ndlp->nlp_flag |= NLP_NPR_ADISC;
  511. spin_unlock_irq(phba->host->host_lock);
  512. return 1;
  513. }
  514. static uint32_t
  515. lpfc_disc_illegal(struct lpfc_hba * phba,
  516. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  517. {
  518. lpfc_printf_log(phba,
  519. KERN_ERR,
  520. LOG_DISCOVERY,
  521. "%d:0253 Illegal State Transition: node x%x event x%x, "
  522. "state x%x Data: x%x x%x\n",
  523. phba->brd_no,
  524. ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
  525. ndlp->nlp_flag);
  526. return ndlp->nlp_state;
  527. }
  528. /* Start of Discovery State Machine routines */
  529. static uint32_t
  530. lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
  531. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  532. {
  533. struct lpfc_iocbq *cmdiocb;
  534. cmdiocb = (struct lpfc_iocbq *) arg;
  535. if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
  536. ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
  537. ndlp->nlp_state = NLP_STE_UNUSED_NODE;
  538. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  539. return ndlp->nlp_state;
  540. }
  541. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  542. return NLP_STE_FREED_NODE;
  543. }
  544. static uint32_t
  545. lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
  546. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  547. {
  548. lpfc_issue_els_logo(phba, ndlp, 0);
  549. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  550. return ndlp->nlp_state;
  551. }
  552. static uint32_t
  553. lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
  554. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  555. {
  556. struct lpfc_iocbq *cmdiocb;
  557. cmdiocb = (struct lpfc_iocbq *) arg;
  558. spin_lock_irq(phba->host->host_lock);
  559. ndlp->nlp_flag |= NLP_LOGO_ACC;
  560. spin_unlock_irq(phba->host->host_lock);
  561. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  562. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  563. return ndlp->nlp_state;
  564. }
  565. static uint32_t
  566. lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
  567. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  568. {
  569. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  570. return NLP_STE_FREED_NODE;
  571. }
  572. static uint32_t
  573. lpfc_device_rm_unused_node(struct lpfc_hba * phba,
  574. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  575. {
  576. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  577. return NLP_STE_FREED_NODE;
  578. }
  579. static uint32_t
  580. lpfc_rcv_plogi_plogi_issue(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  581. void *arg, uint32_t evt)
  582. {
  583. struct lpfc_iocbq *cmdiocb = arg;
  584. struct lpfc_dmabuf *pcmd;
  585. struct serv_parm *sp;
  586. uint32_t *lp;
  587. struct ls_rjt stat;
  588. int port_cmp;
  589. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  590. lp = (uint32_t *) pcmd->virt;
  591. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  592. memset(&stat, 0, sizeof (struct ls_rjt));
  593. /* For a PLOGI, we only accept if our portname is less
  594. * than the remote portname.
  595. */
  596. phba->fc_stat.elsLogiCol++;
  597. port_cmp = memcmp(&phba->fc_portname, &sp->portName,
  598. sizeof (struct lpfc_name));
  599. if (port_cmp >= 0) {
  600. /* Reject this request because the remote node will accept
  601. ours */
  602. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  603. stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
  604. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  605. } else {
  606. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  607. } /* if our portname was less */
  608. return ndlp->nlp_state;
  609. }
  610. static uint32_t
  611. lpfc_rcv_logo_plogi_issue(struct lpfc_hba * phba,
  612. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  613. {
  614. struct lpfc_iocbq *cmdiocb;
  615. cmdiocb = (struct lpfc_iocbq *) arg;
  616. /* software abort outstanding PLOGI */
  617. lpfc_els_abort(phba, ndlp, 1);
  618. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  619. return ndlp->nlp_state;
  620. }
  621. static uint32_t
  622. lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
  623. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  624. {
  625. struct lpfc_iocbq *cmdiocb;
  626. cmdiocb = (struct lpfc_iocbq *) arg;
  627. /* software abort outstanding PLOGI */
  628. lpfc_els_abort(phba, ndlp, 1);
  629. if (evt == NLP_EVT_RCV_LOGO) {
  630. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  631. } else {
  632. lpfc_issue_els_logo(phba, ndlp, 0);
  633. }
  634. /* Put ndlp in npr list set plogi timer for 1 sec */
  635. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  636. spin_lock_irq(phba->host->host_lock);
  637. ndlp->nlp_flag |= NLP_DELAY_TMO;
  638. spin_unlock_irq(phba->host->host_lock);
  639. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  640. ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
  641. ndlp->nlp_state = NLP_STE_NPR_NODE;
  642. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  643. return ndlp->nlp_state;
  644. }
  645. static uint32_t
  646. lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
  647. struct lpfc_nodelist * ndlp, void *arg,
  648. uint32_t evt)
  649. {
  650. struct lpfc_iocbq *cmdiocb, *rspiocb;
  651. struct lpfc_dmabuf *pcmd, *prsp;
  652. uint32_t *lp;
  653. IOCB_t *irsp;
  654. struct serv_parm *sp;
  655. LPFC_MBOXQ_t *mbox;
  656. cmdiocb = (struct lpfc_iocbq *) arg;
  657. rspiocb = cmdiocb->context_un.rsp_iocb;
  658. if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  659. /* Recovery from PLOGI collision logic */
  660. return ndlp->nlp_state;
  661. }
  662. irsp = &rspiocb->iocb;
  663. if (irsp->ulpStatus)
  664. goto out;
  665. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  666. prsp = list_get_first(&pcmd->list,
  667. struct lpfc_dmabuf,
  668. list);
  669. lp = (uint32_t *) prsp->virt;
  670. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  671. if (!lpfc_check_sparm(phba, ndlp, sp, CLASS3))
  672. goto out;
  673. /* PLOGI chkparm OK */
  674. lpfc_printf_log(phba,
  675. KERN_INFO,
  676. LOG_ELS,
  677. "%d:0121 PLOGI chkparm OK "
  678. "Data: x%x x%x x%x x%x\n",
  679. phba->brd_no,
  680. ndlp->nlp_DID, ndlp->nlp_state,
  681. ndlp->nlp_flag, ndlp->nlp_rpi);
  682. if ((phba->cfg_fcp_class == 2) &&
  683. (sp->cls2.classValid)) {
  684. ndlp->nlp_fcp_info |= CLASS2;
  685. } else {
  686. ndlp->nlp_fcp_info |= CLASS3;
  687. }
  688. ndlp->nlp_class_sup = 0;
  689. if (sp->cls1.classValid)
  690. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  691. if (sp->cls2.classValid)
  692. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  693. if (sp->cls3.classValid)
  694. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  695. if (sp->cls4.classValid)
  696. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  697. ndlp->nlp_maxframe =
  698. ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  699. sp->cmn.bbRcvSizeLsb;
  700. if (!(mbox = mempool_alloc(phba->mbox_mem_pool,
  701. GFP_KERNEL)))
  702. goto out;
  703. lpfc_unreg_rpi(phba, ndlp);
  704. if (lpfc_reg_login
  705. (phba, irsp->un.elsreq64.remoteID,
  706. (uint8_t *) sp, mbox, 0) == 0) {
  707. /* set_slim mailbox command needs to
  708. * execute first, queue this command to
  709. * be processed later.
  710. */
  711. switch (ndlp->nlp_DID) {
  712. case NameServer_DID:
  713. mbox->mbox_cmpl =
  714. lpfc_mbx_cmpl_ns_reg_login;
  715. break;
  716. case FDMI_DID:
  717. mbox->mbox_cmpl =
  718. lpfc_mbx_cmpl_fdmi_reg_login;
  719. break;
  720. default:
  721. mbox->mbox_cmpl =
  722. lpfc_mbx_cmpl_reg_login;
  723. }
  724. mbox->context2 = ndlp;
  725. if (lpfc_sli_issue_mbox(phba, mbox,
  726. (MBX_NOWAIT | MBX_STOP_IOCB))
  727. != MBX_NOT_FINISHED) {
  728. ndlp->nlp_state =
  729. NLP_STE_REG_LOGIN_ISSUE;
  730. lpfc_nlp_list(phba, ndlp,
  731. NLP_REGLOGIN_LIST);
  732. return ndlp->nlp_state;
  733. }
  734. mempool_free(mbox, phba->mbox_mem_pool);
  735. } else {
  736. mempool_free(mbox, phba->mbox_mem_pool);
  737. }
  738. out:
  739. /* Free this node since the driver cannot login or has the wrong
  740. sparm */
  741. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  742. return NLP_STE_FREED_NODE;
  743. }
  744. static uint32_t
  745. lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
  746. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  747. {
  748. /* software abort outstanding PLOGI */
  749. lpfc_els_abort(phba, ndlp, 1);
  750. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  751. return NLP_STE_FREED_NODE;
  752. }
  753. static uint32_t
  754. lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
  755. struct lpfc_nodelist * ndlp, void *arg,
  756. uint32_t evt)
  757. {
  758. /* software abort outstanding PLOGI */
  759. lpfc_els_abort(phba, ndlp, 1);
  760. ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
  761. ndlp->nlp_state = NLP_STE_NPR_NODE;
  762. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  763. spin_lock_irq(phba->host->host_lock);
  764. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  765. spin_unlock_irq(phba->host->host_lock);
  766. return ndlp->nlp_state;
  767. }
  768. static uint32_t
  769. lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
  770. struct lpfc_nodelist * ndlp, void *arg,
  771. uint32_t evt)
  772. {
  773. struct lpfc_iocbq *cmdiocb;
  774. /* software abort outstanding ADISC */
  775. lpfc_els_abort(phba, ndlp, 1);
  776. cmdiocb = (struct lpfc_iocbq *) arg;
  777. if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
  778. return ndlp->nlp_state;
  779. }
  780. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  781. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  782. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  783. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  784. return ndlp->nlp_state;
  785. }
  786. static uint32_t
  787. lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
  788. struct lpfc_nodelist * ndlp, void *arg,
  789. uint32_t evt)
  790. {
  791. struct lpfc_iocbq *cmdiocb;
  792. cmdiocb = (struct lpfc_iocbq *) arg;
  793. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  794. return ndlp->nlp_state;
  795. }
  796. static uint32_t
  797. lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
  798. struct lpfc_nodelist * ndlp, void *arg,
  799. uint32_t evt)
  800. {
  801. struct lpfc_iocbq *cmdiocb;
  802. cmdiocb = (struct lpfc_iocbq *) arg;
  803. /* software abort outstanding ADISC */
  804. lpfc_els_abort(phba, ndlp, 0);
  805. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  806. return ndlp->nlp_state;
  807. }
  808. static uint32_t
  809. lpfc_rcv_padisc_adisc_issue(struct lpfc_hba * phba,
  810. struct lpfc_nodelist * ndlp, void *arg,
  811. uint32_t evt)
  812. {
  813. struct lpfc_iocbq *cmdiocb;
  814. cmdiocb = (struct lpfc_iocbq *) arg;
  815. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  816. return ndlp->nlp_state;
  817. }
  818. static uint32_t
  819. lpfc_rcv_prlo_adisc_issue(struct lpfc_hba * phba,
  820. struct lpfc_nodelist * ndlp, void *arg,
  821. uint32_t evt)
  822. {
  823. struct lpfc_iocbq *cmdiocb;
  824. cmdiocb = (struct lpfc_iocbq *) arg;
  825. /* Treat like rcv logo */
  826. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  827. return ndlp->nlp_state;
  828. }
  829. static uint32_t
  830. lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
  831. struct lpfc_nodelist * ndlp, void *arg,
  832. uint32_t evt)
  833. {
  834. struct lpfc_iocbq *cmdiocb, *rspiocb;
  835. IOCB_t *irsp;
  836. ADISC *ap;
  837. cmdiocb = (struct lpfc_iocbq *) arg;
  838. rspiocb = cmdiocb->context_un.rsp_iocb;
  839. ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
  840. irsp = &rspiocb->iocb;
  841. if ((irsp->ulpStatus) ||
  842. (!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
  843. /* 1 sec timeout */
  844. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  845. spin_lock_irq(phba->host->host_lock);
  846. ndlp->nlp_flag |= NLP_DELAY_TMO;
  847. spin_unlock_irq(phba->host->host_lock);
  848. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  849. memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
  850. memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
  851. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  852. ndlp->nlp_state = NLP_STE_NPR_NODE;
  853. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  854. lpfc_unreg_rpi(phba, ndlp);
  855. return ndlp->nlp_state;
  856. }
  857. if (ndlp->nlp_type & NLP_FCP_TARGET) {
  858. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  859. ndlp->nlp_state = NLP_STE_MAPPED_NODE;
  860. lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
  861. } else {
  862. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  863. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  864. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  865. }
  866. return ndlp->nlp_state;
  867. }
  868. static uint32_t
  869. lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
  870. struct lpfc_nodelist * ndlp, void *arg,
  871. uint32_t evt)
  872. {
  873. /* software abort outstanding ADISC */
  874. lpfc_els_abort(phba, ndlp, 1);
  875. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  876. return NLP_STE_FREED_NODE;
  877. }
  878. static uint32_t
  879. lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
  880. struct lpfc_nodelist * ndlp, void *arg,
  881. uint32_t evt)
  882. {
  883. /* software abort outstanding ADISC */
  884. lpfc_els_abort(phba, ndlp, 1);
  885. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  886. ndlp->nlp_state = NLP_STE_NPR_NODE;
  887. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  888. spin_lock_irq(phba->host->host_lock);
  889. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  890. ndlp->nlp_flag |= NLP_NPR_ADISC;
  891. spin_unlock_irq(phba->host->host_lock);
  892. return ndlp->nlp_state;
  893. }
  894. static uint32_t
  895. lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
  896. struct lpfc_nodelist * ndlp, void *arg,
  897. uint32_t evt)
  898. {
  899. struct lpfc_iocbq *cmdiocb;
  900. cmdiocb = (struct lpfc_iocbq *) arg;
  901. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  902. return ndlp->nlp_state;
  903. }
  904. static uint32_t
  905. lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
  906. struct lpfc_nodelist * ndlp, void *arg,
  907. uint32_t evt)
  908. {
  909. struct lpfc_iocbq *cmdiocb;
  910. cmdiocb = (struct lpfc_iocbq *) arg;
  911. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  912. return ndlp->nlp_state;
  913. }
  914. static uint32_t
  915. lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
  916. struct lpfc_nodelist * ndlp, void *arg,
  917. uint32_t evt)
  918. {
  919. struct lpfc_iocbq *cmdiocb;
  920. cmdiocb = (struct lpfc_iocbq *) arg;
  921. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  922. return ndlp->nlp_state;
  923. }
  924. static uint32_t
  925. lpfc_rcv_padisc_reglogin_issue(struct lpfc_hba * phba,
  926. struct lpfc_nodelist * ndlp, void *arg,
  927. uint32_t evt)
  928. {
  929. struct lpfc_iocbq *cmdiocb;
  930. cmdiocb = (struct lpfc_iocbq *) arg;
  931. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  932. return ndlp->nlp_state;
  933. }
  934. static uint32_t
  935. lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
  936. struct lpfc_nodelist * ndlp, void *arg,
  937. uint32_t evt)
  938. {
  939. struct lpfc_iocbq *cmdiocb;
  940. cmdiocb = (struct lpfc_iocbq *) arg;
  941. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  942. return ndlp->nlp_state;
  943. }
  944. static uint32_t
  945. lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
  946. struct lpfc_nodelist * ndlp,
  947. void *arg, uint32_t evt)
  948. {
  949. LPFC_MBOXQ_t *pmb;
  950. MAILBOX_t *mb;
  951. uint32_t did;
  952. pmb = (LPFC_MBOXQ_t *) arg;
  953. mb = &pmb->mb;
  954. did = mb->un.varWords[1];
  955. if (mb->mbxStatus) {
  956. /* RegLogin failed */
  957. lpfc_printf_log(phba,
  958. KERN_ERR,
  959. LOG_DISCOVERY,
  960. "%d:0246 RegLogin failed Data: x%x x%x x%x\n",
  961. phba->brd_no,
  962. did, mb->mbxStatus, phba->hba_state);
  963. /* Put ndlp in npr list set plogi timer for 1 sec */
  964. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  965. spin_lock_irq(phba->host->host_lock);
  966. ndlp->nlp_flag |= NLP_DELAY_TMO;
  967. spin_unlock_irq(phba->host->host_lock);
  968. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  969. lpfc_issue_els_logo(phba, ndlp, 0);
  970. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  971. ndlp->nlp_state = NLP_STE_NPR_NODE;
  972. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  973. return ndlp->nlp_state;
  974. }
  975. ndlp->nlp_rpi = mb->un.varWords[0];
  976. /* Only if we are not a fabric nport do we issue PRLI */
  977. if (!(ndlp->nlp_type & NLP_FABRIC)) {
  978. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  979. ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
  980. lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
  981. lpfc_issue_els_prli(phba, ndlp, 0);
  982. } else {
  983. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  984. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  985. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  986. }
  987. return ndlp->nlp_state;
  988. }
  989. static uint32_t
  990. lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
  991. struct lpfc_nodelist * ndlp, void *arg,
  992. uint32_t evt)
  993. {
  994. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  995. return NLP_STE_FREED_NODE;
  996. }
  997. static uint32_t
  998. lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
  999. struct lpfc_nodelist * ndlp, void *arg,
  1000. uint32_t evt)
  1001. {
  1002. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1003. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1004. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1005. spin_lock_irq(phba->host->host_lock);
  1006. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1007. spin_unlock_irq(phba->host->host_lock);
  1008. return ndlp->nlp_state;
  1009. }
  1010. static uint32_t
  1011. lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
  1012. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1013. {
  1014. struct lpfc_iocbq *cmdiocb;
  1015. cmdiocb = (struct lpfc_iocbq *) arg;
  1016. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  1017. return ndlp->nlp_state;
  1018. }
  1019. static uint32_t
  1020. lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
  1021. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1022. {
  1023. struct lpfc_iocbq *cmdiocb;
  1024. cmdiocb = (struct lpfc_iocbq *) arg;
  1025. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  1026. return ndlp->nlp_state;
  1027. }
  1028. static uint32_t
  1029. lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
  1030. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1031. {
  1032. struct lpfc_iocbq *cmdiocb;
  1033. cmdiocb = (struct lpfc_iocbq *) arg;
  1034. /* Software abort outstanding PRLI before sending acc */
  1035. lpfc_els_abort(phba, ndlp, 1);
  1036. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  1037. return ndlp->nlp_state;
  1038. }
  1039. static uint32_t
  1040. lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
  1041. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1042. {
  1043. struct lpfc_iocbq *cmdiocb;
  1044. cmdiocb = (struct lpfc_iocbq *) arg;
  1045. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1046. return ndlp->nlp_state;
  1047. }
  1048. /* This routine is envoked when we rcv a PRLO request from a nport
  1049. * we are logged into. We should send back a PRLO rsp setting the
  1050. * appropriate bits.
  1051. * NEXT STATE = PRLI_ISSUE
  1052. */
  1053. static uint32_t
  1054. lpfc_rcv_prlo_prli_issue(struct lpfc_hba * phba,
  1055. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1056. {
  1057. struct lpfc_iocbq *cmdiocb;
  1058. cmdiocb = (struct lpfc_iocbq *) arg;
  1059. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  1060. return ndlp->nlp_state;
  1061. }
  1062. static uint32_t
  1063. lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
  1064. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1065. {
  1066. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1067. IOCB_t *irsp;
  1068. PRLI *npr;
  1069. cmdiocb = (struct lpfc_iocbq *) arg;
  1070. rspiocb = cmdiocb->context_un.rsp_iocb;
  1071. npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
  1072. irsp = &rspiocb->iocb;
  1073. if (irsp->ulpStatus) {
  1074. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1075. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  1076. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  1077. return ndlp->nlp_state;
  1078. }
  1079. /* Check out PRLI rsp */
  1080. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  1081. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  1082. if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
  1083. (npr->prliType == PRLI_FCP_TYPE)) {
  1084. if (npr->initiatorFunc)
  1085. ndlp->nlp_type |= NLP_FCP_INITIATOR;
  1086. if (npr->targetFunc)
  1087. ndlp->nlp_type |= NLP_FCP_TARGET;
  1088. if (npr->Retry)
  1089. ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
  1090. }
  1091. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1092. ndlp->nlp_state = NLP_STE_MAPPED_NODE;
  1093. lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
  1094. return ndlp->nlp_state;
  1095. }
  1096. /*! lpfc_device_rm_prli_issue
  1097. *
  1098. * \pre
  1099. * \post
  1100. * \param phba
  1101. * \param ndlp
  1102. * \param arg
  1103. * \param evt
  1104. * \return uint32_t
  1105. *
  1106. * \b Description:
  1107. * This routine is envoked when we a request to remove a nport we are in the
  1108. * process of PRLIing. We should software abort outstanding prli, unreg
  1109. * login, send a logout. We will change node state to UNUSED_NODE, put it
  1110. * on plogi list so it can be freed when LOGO completes.
  1111. *
  1112. */
  1113. static uint32_t
  1114. lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
  1115. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1116. {
  1117. /* software abort outstanding PRLI */
  1118. lpfc_els_abort(phba, ndlp, 1);
  1119. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1120. return NLP_STE_FREED_NODE;
  1121. }
  1122. /*! lpfc_device_recov_prli_issue
  1123. *
  1124. * \pre
  1125. * \post
  1126. * \param phba
  1127. * \param ndlp
  1128. * \param arg
  1129. * \param evt
  1130. * \return uint32_t
  1131. *
  1132. * \b Description:
  1133. * The routine is envoked when the state of a device is unknown, like
  1134. * during a link down. We should remove the nodelist entry from the
  1135. * unmapped list, issue a UNREG_LOGIN, do a software abort of the
  1136. * outstanding PRLI command, then free the node entry.
  1137. */
  1138. static uint32_t
  1139. lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
  1140. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1141. {
  1142. /* software abort outstanding PRLI */
  1143. lpfc_els_abort(phba, ndlp, 1);
  1144. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1145. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1146. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1147. spin_lock_irq(phba->host->host_lock);
  1148. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1149. spin_unlock_irq(phba->host->host_lock);
  1150. return ndlp->nlp_state;
  1151. }
  1152. static uint32_t
  1153. lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
  1154. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1155. {
  1156. struct lpfc_iocbq *cmdiocb;
  1157. cmdiocb = (struct lpfc_iocbq *) arg;
  1158. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  1159. return ndlp->nlp_state;
  1160. }
  1161. static uint32_t
  1162. lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
  1163. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1164. {
  1165. struct lpfc_iocbq *cmdiocb;
  1166. cmdiocb = (struct lpfc_iocbq *) arg;
  1167. lpfc_rcv_prli(phba, ndlp, cmdiocb);
  1168. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  1169. return ndlp->nlp_state;
  1170. }
  1171. static uint32_t
  1172. lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
  1173. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1174. {
  1175. struct lpfc_iocbq *cmdiocb;
  1176. cmdiocb = (struct lpfc_iocbq *) arg;
  1177. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  1178. return ndlp->nlp_state;
  1179. }
  1180. static uint32_t
  1181. lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
  1182. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1183. {
  1184. struct lpfc_iocbq *cmdiocb;
  1185. cmdiocb = (struct lpfc_iocbq *) arg;
  1186. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1187. return ndlp->nlp_state;
  1188. }
  1189. static uint32_t
  1190. lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
  1191. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1192. {
  1193. struct lpfc_iocbq *cmdiocb;
  1194. cmdiocb = (struct lpfc_iocbq *) arg;
  1195. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  1196. return ndlp->nlp_state;
  1197. }
  1198. static uint32_t
  1199. lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
  1200. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1201. {
  1202. ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
  1203. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1204. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1205. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1206. lpfc_disc_set_adisc(phba, ndlp);
  1207. return ndlp->nlp_state;
  1208. }
  1209. static uint32_t
  1210. lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
  1211. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1212. {
  1213. struct lpfc_iocbq *cmdiocb;
  1214. cmdiocb = (struct lpfc_iocbq *) arg;
  1215. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  1216. return ndlp->nlp_state;
  1217. }
  1218. static uint32_t
  1219. lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
  1220. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1221. {
  1222. struct lpfc_iocbq *cmdiocb;
  1223. cmdiocb = (struct lpfc_iocbq *) arg;
  1224. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  1225. return ndlp->nlp_state;
  1226. }
  1227. static uint32_t
  1228. lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
  1229. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1230. {
  1231. struct lpfc_iocbq *cmdiocb;
  1232. cmdiocb = (struct lpfc_iocbq *) arg;
  1233. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  1234. return ndlp->nlp_state;
  1235. }
  1236. static uint32_t
  1237. lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
  1238. struct lpfc_nodelist * ndlp, void *arg,
  1239. uint32_t evt)
  1240. {
  1241. struct lpfc_iocbq *cmdiocb;
  1242. cmdiocb = (struct lpfc_iocbq *) arg;
  1243. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1244. return ndlp->nlp_state;
  1245. }
  1246. static uint32_t
  1247. lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
  1248. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1249. {
  1250. struct lpfc_iocbq *cmdiocb;
  1251. cmdiocb = (struct lpfc_iocbq *) arg;
  1252. /* flush the target */
  1253. spin_lock_irq(phba->host->host_lock);
  1254. lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
  1255. ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
  1256. spin_unlock_irq(phba->host->host_lock);
  1257. /* Treat like rcv logo */
  1258. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  1259. return ndlp->nlp_state;
  1260. }
  1261. static uint32_t
  1262. lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
  1263. struct lpfc_nodelist * ndlp, void *arg,
  1264. uint32_t evt)
  1265. {
  1266. ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
  1267. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1268. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1269. spin_lock_irq(phba->host->host_lock);
  1270. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1271. spin_unlock_irq(phba->host->host_lock);
  1272. lpfc_disc_set_adisc(phba, ndlp);
  1273. return ndlp->nlp_state;
  1274. }
  1275. static uint32_t
  1276. lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
  1277. struct lpfc_nodelist * ndlp, void *arg,
  1278. uint32_t evt)
  1279. {
  1280. struct lpfc_iocbq *cmdiocb;
  1281. cmdiocb = (struct lpfc_iocbq *) arg;
  1282. /* Ignore PLOGI if we have an outstanding LOGO */
  1283. if (ndlp->nlp_flag & NLP_LOGO_SND) {
  1284. return ndlp->nlp_state;
  1285. }
  1286. if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
  1287. spin_lock_irq(phba->host->host_lock);
  1288. ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
  1289. spin_unlock_irq(phba->host->host_lock);
  1290. return ndlp->nlp_state;
  1291. }
  1292. /* send PLOGI immediately, move to PLOGI issue state */
  1293. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1294. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1295. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  1296. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  1297. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  1298. }
  1299. return ndlp->nlp_state;
  1300. }
  1301. static uint32_t
  1302. lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
  1303. struct lpfc_nodelist * ndlp, void *arg,
  1304. uint32_t evt)
  1305. {
  1306. struct lpfc_iocbq *cmdiocb;
  1307. struct ls_rjt stat;
  1308. cmdiocb = (struct lpfc_iocbq *) arg;
  1309. memset(&stat, 0, sizeof (struct ls_rjt));
  1310. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1311. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1312. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  1313. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1314. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  1315. spin_lock_irq(phba->host->host_lock);
  1316. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1317. spin_unlock_irq(phba->host->host_lock);
  1318. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1319. ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
  1320. lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
  1321. lpfc_issue_els_adisc(phba, ndlp, 0);
  1322. } else {
  1323. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1324. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  1325. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  1326. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  1327. }
  1328. }
  1329. return ndlp->nlp_state;
  1330. }
  1331. static uint32_t
  1332. lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
  1333. struct lpfc_nodelist * ndlp, void *arg,
  1334. uint32_t evt)
  1335. {
  1336. struct lpfc_iocbq *cmdiocb;
  1337. cmdiocb = (struct lpfc_iocbq *) arg;
  1338. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  1339. return ndlp->nlp_state;
  1340. }
  1341. static uint32_t
  1342. lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
  1343. struct lpfc_nodelist * ndlp, void *arg,
  1344. uint32_t evt)
  1345. {
  1346. struct lpfc_iocbq *cmdiocb;
  1347. cmdiocb = (struct lpfc_iocbq *) arg;
  1348. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1349. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1350. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  1351. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1352. ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
  1353. lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
  1354. lpfc_issue_els_adisc(phba, ndlp, 0);
  1355. } else {
  1356. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1357. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  1358. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  1359. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  1360. }
  1361. }
  1362. return ndlp->nlp_state;
  1363. }
  1364. static uint32_t
  1365. lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
  1366. struct lpfc_nodelist * ndlp, void *arg,
  1367. uint32_t evt)
  1368. {
  1369. struct lpfc_iocbq *cmdiocb;
  1370. cmdiocb = (struct lpfc_iocbq *) arg;
  1371. spin_lock_irq(phba->host->host_lock);
  1372. ndlp->nlp_flag |= NLP_LOGO_ACC;
  1373. spin_unlock_irq(phba->host->host_lock);
  1374. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  1375. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1376. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  1377. spin_lock_irq(phba->host->host_lock);
  1378. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1379. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1380. spin_unlock_irq(phba->host->host_lock);
  1381. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  1382. } else {
  1383. spin_lock_irq(phba->host->host_lock);
  1384. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1385. spin_unlock_irq(phba->host->host_lock);
  1386. }
  1387. return ndlp->nlp_state;
  1388. }
  1389. static uint32_t
  1390. lpfc_cmpl_plogi_npr_node(struct lpfc_hba * phba,
  1391. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1392. {
  1393. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1394. cmdiocb = (struct lpfc_iocbq *) arg;
  1395. rspiocb = cmdiocb->context_un.rsp_iocb;
  1396. return ndlp->nlp_state;
  1397. }
  1398. static uint32_t
  1399. lpfc_cmpl_prli_npr_node(struct lpfc_hba * phba,
  1400. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1401. {
  1402. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1403. cmdiocb = (struct lpfc_iocbq *) arg;
  1404. rspiocb = cmdiocb->context_un.rsp_iocb;
  1405. return ndlp->nlp_state;
  1406. }
  1407. static uint32_t
  1408. lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
  1409. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1410. {
  1411. lpfc_unreg_rpi(phba, ndlp);
  1412. /* This routine does nothing, just return the current state */
  1413. return ndlp->nlp_state;
  1414. }
  1415. static uint32_t
  1416. lpfc_cmpl_adisc_npr_node(struct lpfc_hba * phba,
  1417. struct lpfc_nodelist * ndlp, void *arg,
  1418. uint32_t evt)
  1419. {
  1420. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1421. cmdiocb = (struct lpfc_iocbq *) arg;
  1422. rspiocb = cmdiocb->context_un.rsp_iocb;
  1423. return ndlp->nlp_state;
  1424. }
  1425. static uint32_t
  1426. lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
  1427. struct lpfc_nodelist * ndlp, void *arg,
  1428. uint32_t evt)
  1429. {
  1430. LPFC_MBOXQ_t *pmb;
  1431. MAILBOX_t *mb;
  1432. pmb = (LPFC_MBOXQ_t *) arg;
  1433. mb = &pmb->mb;
  1434. if (!mb->mbxStatus)
  1435. ndlp->nlp_rpi = mb->un.varWords[0];
  1436. return ndlp->nlp_state;
  1437. }
  1438. static uint32_t
  1439. lpfc_device_rm_npr_node(struct lpfc_hba * phba,
  1440. struct lpfc_nodelist * ndlp, void *arg,
  1441. uint32_t evt)
  1442. {
  1443. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1444. return NLP_STE_FREED_NODE;
  1445. }
  1446. static uint32_t
  1447. lpfc_device_recov_npr_node(struct lpfc_hba * phba,
  1448. struct lpfc_nodelist * ndlp, void *arg,
  1449. uint32_t evt)
  1450. {
  1451. spin_lock_irq(phba->host->host_lock);
  1452. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1453. if (ndlp->nlp_flag & NLP_DELAY_TMO) {
  1454. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  1455. if (!list_empty(&ndlp->els_retry_evt.evt_listp))
  1456. list_del_init(&ndlp->els_retry_evt.evt_listp);
  1457. spin_unlock_irq(phba->host->host_lock);
  1458. ndlp->nlp_last_elscmd = 0;
  1459. del_timer_sync(&ndlp->nlp_delayfunc);
  1460. return ndlp->nlp_state;
  1461. }
  1462. spin_unlock_irq(phba->host->host_lock);
  1463. return ndlp->nlp_state;
  1464. }
  1465. /* This next section defines the NPort Discovery State Machine */
  1466. /* There are 4 different double linked lists nodelist entries can reside on.
  1467. * The plogi list and adisc list are used when Link Up discovery or RSCN
  1468. * processing is needed. Each list holds the nodes that we will send PLOGI
  1469. * or ADISC on. These lists will keep track of what nodes will be effected
  1470. * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
  1471. * The unmapped_list will contain all nodes that we have successfully logged
  1472. * into at the Fibre Channel level. The mapped_list will contain all nodes
  1473. * that are mapped FCP targets.
  1474. */
  1475. /*
  1476. * The bind list is a list of undiscovered (potentially non-existent) nodes
  1477. * that we have saved binding information on. This information is used when
  1478. * nodes transition from the unmapped to the mapped list.
  1479. */
  1480. /* For UNUSED_NODE state, the node has just been allocated .
  1481. * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
  1482. * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
  1483. * and put on the unmapped list. For ADISC processing, the node is taken off
  1484. * the ADISC list and placed on either the mapped or unmapped list (depending
  1485. * on its previous state). Once on the unmapped list, a PRLI is issued and the
  1486. * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
  1487. * changed to UNMAPPED_NODE. If the completion indicates a mapped
  1488. * node, the node is taken off the unmapped list. The binding list is checked
  1489. * for a valid binding, or a binding is automatically assigned. If binding
  1490. * assignment is unsuccessful, the node is left on the unmapped list. If
  1491. * binding assignment is successful, the associated binding list entry (if
  1492. * any) is removed, and the node is placed on the mapped list.
  1493. */
  1494. /*
  1495. * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
  1496. * lists will receive a DEVICE_RECOVERY event. If the linkdown or nodev timers
  1497. * expire, all effected nodes will receive a DEVICE_RM event.
  1498. */
  1499. /*
  1500. * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
  1501. * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
  1502. * check, additional nodes may be added or removed (via DEVICE_RM) to / from
  1503. * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
  1504. * we will first process the ADISC list. 32 entries are processed initially and
  1505. * ADISC is initited for each one. Completions / Events for each node are
  1506. * funnelled thru the state machine. As each node finishes ADISC processing, it
  1507. * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
  1508. * waiting, and the ADISC list count is identically 0, then we are done. For
  1509. * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
  1510. * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
  1511. * list. 32 entries are processed initially and PLOGI is initited for each one.
  1512. * Completions / Events for each node are funnelled thru the state machine. As
  1513. * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
  1514. * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
  1515. * indentically 0, then we are done. We have now completed discovery / RSCN
  1516. * handling. Upon completion, ALL nodes should be on either the mapped or
  1517. * unmapped lists.
  1518. */
  1519. static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
  1520. (struct lpfc_hba *, struct lpfc_nodelist *, void *, uint32_t) = {
  1521. /* Action routine Event Current State */
  1522. lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
  1523. lpfc_rcv_els_unused_node, /* RCV_PRLI */
  1524. lpfc_rcv_logo_unused_node, /* RCV_LOGO */
  1525. lpfc_rcv_els_unused_node, /* RCV_ADISC */
  1526. lpfc_rcv_els_unused_node, /* RCV_PDISC */
  1527. lpfc_rcv_els_unused_node, /* RCV_PRLO */
  1528. lpfc_disc_illegal, /* CMPL_PLOGI */
  1529. lpfc_disc_illegal, /* CMPL_PRLI */
  1530. lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
  1531. lpfc_disc_illegal, /* CMPL_ADISC */
  1532. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1533. lpfc_device_rm_unused_node, /* DEVICE_RM */
  1534. lpfc_disc_illegal, /* DEVICE_RECOVERY */
  1535. lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
  1536. lpfc_rcv_els_plogi_issue, /* RCV_PRLI */
  1537. lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
  1538. lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
  1539. lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
  1540. lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
  1541. lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
  1542. lpfc_disc_illegal, /* CMPL_PRLI */
  1543. lpfc_disc_illegal, /* CMPL_LOGO */
  1544. lpfc_disc_illegal, /* CMPL_ADISC */
  1545. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1546. lpfc_device_rm_plogi_issue, /* DEVICE_RM */
  1547. lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
  1548. lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
  1549. lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
  1550. lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
  1551. lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
  1552. lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
  1553. lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
  1554. lpfc_disc_illegal, /* CMPL_PLOGI */
  1555. lpfc_disc_illegal, /* CMPL_PRLI */
  1556. lpfc_disc_illegal, /* CMPL_LOGO */
  1557. lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
  1558. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1559. lpfc_device_rm_adisc_issue, /* DEVICE_RM */
  1560. lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
  1561. lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
  1562. lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
  1563. lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
  1564. lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
  1565. lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
  1566. lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
  1567. lpfc_disc_illegal, /* CMPL_PLOGI */
  1568. lpfc_disc_illegal, /* CMPL_PRLI */
  1569. lpfc_disc_illegal, /* CMPL_LOGO */
  1570. lpfc_disc_illegal, /* CMPL_ADISC */
  1571. lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
  1572. lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
  1573. lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
  1574. lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
  1575. lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
  1576. lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
  1577. lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
  1578. lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
  1579. lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
  1580. lpfc_disc_illegal, /* CMPL_PLOGI */
  1581. lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
  1582. lpfc_disc_illegal, /* CMPL_LOGO */
  1583. lpfc_disc_illegal, /* CMPL_ADISC */
  1584. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1585. lpfc_device_rm_prli_issue, /* DEVICE_RM */
  1586. lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
  1587. lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
  1588. lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
  1589. lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
  1590. lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
  1591. lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
  1592. lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
  1593. lpfc_disc_illegal, /* CMPL_PLOGI */
  1594. lpfc_disc_illegal, /* CMPL_PRLI */
  1595. lpfc_disc_illegal, /* CMPL_LOGO */
  1596. lpfc_disc_illegal, /* CMPL_ADISC */
  1597. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1598. lpfc_disc_illegal, /* DEVICE_RM */
  1599. lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
  1600. lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
  1601. lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
  1602. lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
  1603. lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
  1604. lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
  1605. lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
  1606. lpfc_disc_illegal, /* CMPL_PLOGI */
  1607. lpfc_disc_illegal, /* CMPL_PRLI */
  1608. lpfc_disc_illegal, /* CMPL_LOGO */
  1609. lpfc_disc_illegal, /* CMPL_ADISC */
  1610. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1611. lpfc_disc_illegal, /* DEVICE_RM */
  1612. lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
  1613. lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
  1614. lpfc_rcv_prli_npr_node, /* RCV_PRLI */
  1615. lpfc_rcv_logo_npr_node, /* RCV_LOGO */
  1616. lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
  1617. lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
  1618. lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
  1619. lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
  1620. lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
  1621. lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
  1622. lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
  1623. lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
  1624. lpfc_device_rm_npr_node, /* DEVICE_RM */
  1625. lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
  1626. };
  1627. int
  1628. lpfc_disc_state_machine(struct lpfc_hba * phba,
  1629. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1630. {
  1631. uint32_t cur_state, rc;
  1632. uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
  1633. uint32_t);
  1634. ndlp->nlp_disc_refcnt++;
  1635. cur_state = ndlp->nlp_state;
  1636. /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
  1637. lpfc_printf_log(phba,
  1638. KERN_INFO,
  1639. LOG_DISCOVERY,
  1640. "%d:0211 DSM in event x%x on NPort x%x in state %d "
  1641. "Data: x%x\n",
  1642. phba->brd_no,
  1643. evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
  1644. func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
  1645. rc = (func) (phba, ndlp, arg, evt);
  1646. /* DSM out state <rc> on NPort <nlp_DID> */
  1647. lpfc_printf_log(phba,
  1648. KERN_INFO,
  1649. LOG_DISCOVERY,
  1650. "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
  1651. phba->brd_no,
  1652. rc, ndlp->nlp_DID, ndlp->nlp_flag);
  1653. ndlp->nlp_disc_refcnt--;
  1654. /* Check to see if ndlp removal is deferred */
  1655. if ((ndlp->nlp_disc_refcnt == 0)
  1656. && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
  1657. spin_lock_irq(phba->host->host_lock);
  1658. ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
  1659. spin_unlock_irq(phba->host->host_lock);
  1660. lpfc_nlp_remove(phba, ndlp);
  1661. return NLP_STE_FREED_NODE;
  1662. }
  1663. if (rc == NLP_STE_FREED_NODE)
  1664. return NLP_STE_FREED_NODE;
  1665. return rc;
  1666. }