lpfc_nportdisc.c 53 KB

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