PageRenderTime 99ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 2ms

/drivers/scsi/lpfc/lpfc_els.c

http://github.com/mirrors/linux
C | 10152 lines | 6613 code | 1025 blank | 2514 comment | 1180 complexity | bff4b2cf65119e8010bb275c58f7b75d MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  10. * *
  11. * This program is free software; you can redistribute it and/or *
  12. * modify it under the terms of version 2 of the GNU General *
  13. * Public License as published by the Free Software Foundation. *
  14. * This program is distributed in the hope that it will be useful. *
  15. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  16. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  17. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  18. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  19. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  20. * more details, a copy of which can be found in the file COPYING *
  21. * included with this package. *
  22. *******************************************************************/
  23. /* See Fibre Channel protocol T11 FC-LS for details */
  24. #include <linux/blkdev.h>
  25. #include <linux/pci.h>
  26. #include <linux/slab.h>
  27. #include <linux/interrupt.h>
  28. #include <scsi/scsi.h>
  29. #include <scsi/scsi_device.h>
  30. #include <scsi/scsi_host.h>
  31. #include <scsi/scsi_transport_fc.h>
  32. #include <uapi/scsi/fc/fc_fs.h>
  33. #include <uapi/scsi/fc/fc_els.h>
  34. #include "lpfc_hw4.h"
  35. #include "lpfc_hw.h"
  36. #include "lpfc_sli.h"
  37. #include "lpfc_sli4.h"
  38. #include "lpfc_nl.h"
  39. #include "lpfc_disc.h"
  40. #include "lpfc_scsi.h"
  41. #include "lpfc.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_crtn.h"
  44. #include "lpfc_vport.h"
  45. #include "lpfc_debugfs.h"
  46. static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
  47. struct lpfc_iocbq *);
  48. static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
  49. struct lpfc_iocbq *);
  50. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
  51. static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
  52. struct lpfc_nodelist *ndlp, uint8_t retry);
  53. static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
  54. struct lpfc_iocbq *iocb);
  55. static int lpfc_max_els_tries = 3;
  56. /**
  57. * lpfc_els_chk_latt - Check host link attention event for a vport
  58. * @vport: pointer to a host virtual N_Port data structure.
  59. *
  60. * This routine checks whether there is an outstanding host link
  61. * attention event during the discovery process with the @vport. It is done
  62. * by reading the HBA's Host Attention (HA) register. If there is any host
  63. * link attention events during this @vport's discovery process, the @vport
  64. * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
  65. * be issued if the link state is not already in host link cleared state,
  66. * and a return code shall indicate whether the host link attention event
  67. * had happened.
  68. *
  69. * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
  70. * state in LPFC_VPORT_READY, the request for checking host link attention
  71. * event will be ignored and a return code shall indicate no host link
  72. * attention event had happened.
  73. *
  74. * Return codes
  75. * 0 - no host link attention event happened
  76. * 1 - host link attention event happened
  77. **/
  78. int
  79. lpfc_els_chk_latt(struct lpfc_vport *vport)
  80. {
  81. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  82. struct lpfc_hba *phba = vport->phba;
  83. uint32_t ha_copy;
  84. if (vport->port_state >= LPFC_VPORT_READY ||
  85. phba->link_state == LPFC_LINK_DOWN ||
  86. phba->sli_rev > LPFC_SLI_REV3)
  87. return 0;
  88. /* Read the HBA Host Attention Register */
  89. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  90. return 1;
  91. if (!(ha_copy & HA_LATT))
  92. return 0;
  93. /* Pending Link Event during Discovery */
  94. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  95. "0237 Pending Link Event during "
  96. "Discovery: State x%x\n",
  97. phba->pport->port_state);
  98. /* CLEAR_LA should re-enable link attention events and
  99. * we should then immediately take a LATT event. The
  100. * LATT processing should call lpfc_linkdown() which
  101. * will cleanup any left over in-progress discovery
  102. * events.
  103. */
  104. spin_lock_irq(shost->host_lock);
  105. vport->fc_flag |= FC_ABORT_DISCOVERY;
  106. spin_unlock_irq(shost->host_lock);
  107. if (phba->link_state != LPFC_CLEAR_LA)
  108. lpfc_issue_clear_la(phba, vport);
  109. return 1;
  110. }
  111. /**
  112. * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
  113. * @vport: pointer to a host virtual N_Port data structure.
  114. * @expectRsp: flag indicating whether response is expected.
  115. * @cmdSize: size of the ELS command.
  116. * @retry: number of retries to the command IOCB when it fails.
  117. * @ndlp: pointer to a node-list data structure.
  118. * @did: destination identifier.
  119. * @elscmd: the ELS command code.
  120. *
  121. * This routine is used for allocating a lpfc-IOCB data structure from
  122. * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
  123. * passed into the routine for discovery state machine to issue an Extended
  124. * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
  125. * and preparation routine that is used by all the discovery state machine
  126. * routines and the ELS command-specific fields will be later set up by
  127. * the individual discovery machine routines after calling this routine
  128. * allocating and preparing a generic IOCB data structure. It fills in the
  129. * Buffer Descriptor Entries (BDEs), allocates buffers for both command
  130. * payload and response payload (if expected). The reference count on the
  131. * ndlp is incremented by 1 and the reference to the ndlp is put into
  132. * context1 of the IOCB data structure for this IOCB to hold the ndlp
  133. * reference for the command's callback function to access later.
  134. *
  135. * Return code
  136. * Pointer to the newly allocated/prepared els iocb data structure
  137. * NULL - when els iocb data structure allocation/preparation failed
  138. **/
  139. struct lpfc_iocbq *
  140. lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
  141. uint16_t cmdSize, uint8_t retry,
  142. struct lpfc_nodelist *ndlp, uint32_t did,
  143. uint32_t elscmd)
  144. {
  145. struct lpfc_hba *phba = vport->phba;
  146. struct lpfc_iocbq *elsiocb;
  147. struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
  148. struct ulp_bde64 *bpl;
  149. IOCB_t *icmd;
  150. if (!lpfc_is_link_up(phba))
  151. return NULL;
  152. /* Allocate buffer for command iocb */
  153. elsiocb = lpfc_sli_get_iocbq(phba);
  154. if (elsiocb == NULL)
  155. return NULL;
  156. /*
  157. * If this command is for fabric controller and HBA running
  158. * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
  159. */
  160. if ((did == Fabric_DID) &&
  161. (phba->hba_flag & HBA_FIP_SUPPORT) &&
  162. ((elscmd == ELS_CMD_FLOGI) ||
  163. (elscmd == ELS_CMD_FDISC) ||
  164. (elscmd == ELS_CMD_LOGO)))
  165. switch (elscmd) {
  166. case ELS_CMD_FLOGI:
  167. elsiocb->iocb_flag |=
  168. ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
  169. & LPFC_FIP_ELS_ID_MASK);
  170. break;
  171. case ELS_CMD_FDISC:
  172. elsiocb->iocb_flag |=
  173. ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
  174. & LPFC_FIP_ELS_ID_MASK);
  175. break;
  176. case ELS_CMD_LOGO:
  177. elsiocb->iocb_flag |=
  178. ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
  179. & LPFC_FIP_ELS_ID_MASK);
  180. break;
  181. }
  182. else
  183. elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
  184. icmd = &elsiocb->iocb;
  185. /* fill in BDEs for command */
  186. /* Allocate buffer for command payload */
  187. pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  188. if (pcmd)
  189. pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
  190. if (!pcmd || !pcmd->virt)
  191. goto els_iocb_free_pcmb_exit;
  192. INIT_LIST_HEAD(&pcmd->list);
  193. /* Allocate buffer for response payload */
  194. if (expectRsp) {
  195. prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  196. if (prsp)
  197. prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  198. &prsp->phys);
  199. if (!prsp || !prsp->virt)
  200. goto els_iocb_free_prsp_exit;
  201. INIT_LIST_HEAD(&prsp->list);
  202. } else
  203. prsp = NULL;
  204. /* Allocate buffer for Buffer ptr list */
  205. pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  206. if (pbuflist)
  207. pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  208. &pbuflist->phys);
  209. if (!pbuflist || !pbuflist->virt)
  210. goto els_iocb_free_pbuf_exit;
  211. INIT_LIST_HEAD(&pbuflist->list);
  212. if (expectRsp) {
  213. icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
  214. icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
  215. icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  216. icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
  217. icmd->un.elsreq64.remoteID = did; /* DID */
  218. icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
  219. if (elscmd == ELS_CMD_FLOGI)
  220. icmd->ulpTimeout = FF_DEF_RATOV * 2;
  221. else if (elscmd == ELS_CMD_LOGO)
  222. icmd->ulpTimeout = phba->fc_ratov;
  223. else
  224. icmd->ulpTimeout = phba->fc_ratov * 2;
  225. } else {
  226. icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
  227. icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
  228. icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  229. icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
  230. icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
  231. icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
  232. }
  233. icmd->ulpBdeCount = 1;
  234. icmd->ulpLe = 1;
  235. icmd->ulpClass = CLASS3;
  236. /*
  237. * If we have NPIV enabled, we want to send ELS traffic by VPI.
  238. * For SLI4, since the driver controls VPIs we also want to include
  239. * all ELS pt2pt protocol traffic as well.
  240. */
  241. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
  242. ((phba->sli_rev == LPFC_SLI_REV4) &&
  243. (vport->fc_flag & FC_PT2PT))) {
  244. if (expectRsp) {
  245. icmd->un.elsreq64.myID = vport->fc_myDID;
  246. /* For ELS_REQUEST64_CR, use the VPI by default */
  247. icmd->ulpContext = phba->vpi_ids[vport->vpi];
  248. }
  249. icmd->ulpCt_h = 0;
  250. /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
  251. if (elscmd == ELS_CMD_ECHO)
  252. icmd->ulpCt_l = 0; /* context = invalid RPI */
  253. else
  254. icmd->ulpCt_l = 1; /* context = VPI */
  255. }
  256. bpl = (struct ulp_bde64 *) pbuflist->virt;
  257. bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
  258. bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
  259. bpl->tus.f.bdeSize = cmdSize;
  260. bpl->tus.f.bdeFlags = 0;
  261. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  262. if (expectRsp) {
  263. bpl++;
  264. bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
  265. bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
  266. bpl->tus.f.bdeSize = FCELSSIZE;
  267. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  268. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  269. }
  270. /* prevent preparing iocb with NULL ndlp reference */
  271. elsiocb->context1 = lpfc_nlp_get(ndlp);
  272. if (!elsiocb->context1)
  273. goto els_iocb_free_pbuf_exit;
  274. elsiocb->context2 = pcmd;
  275. elsiocb->context3 = pbuflist;
  276. elsiocb->retry = retry;
  277. elsiocb->vport = vport;
  278. elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
  279. if (prsp) {
  280. list_add(&prsp->list, &pcmd->list);
  281. }
  282. if (expectRsp) {
  283. /* Xmit ELS command <elsCmd> to remote NPORT <did> */
  284. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  285. "0116 Xmit ELS command x%x to remote "
  286. "NPORT x%x I/O tag: x%x, port state:x%x "
  287. "rpi x%x fc_flag:x%x\n",
  288. elscmd, did, elsiocb->iotag,
  289. vport->port_state, ndlp->nlp_rpi,
  290. vport->fc_flag);
  291. } else {
  292. /* Xmit ELS response <elsCmd> to remote NPORT <did> */
  293. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  294. "0117 Xmit ELS response x%x to remote "
  295. "NPORT x%x I/O tag: x%x, size: x%x "
  296. "port_state x%x rpi x%x fc_flag x%x\n",
  297. elscmd, ndlp->nlp_DID, elsiocb->iotag,
  298. cmdSize, vport->port_state,
  299. ndlp->nlp_rpi, vport->fc_flag);
  300. }
  301. return elsiocb;
  302. els_iocb_free_pbuf_exit:
  303. if (expectRsp)
  304. lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
  305. kfree(pbuflist);
  306. els_iocb_free_prsp_exit:
  307. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  308. kfree(prsp);
  309. els_iocb_free_pcmb_exit:
  310. kfree(pcmd);
  311. lpfc_sli_release_iocbq(phba, elsiocb);
  312. return NULL;
  313. }
  314. /**
  315. * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
  316. * @vport: pointer to a host virtual N_Port data structure.
  317. *
  318. * This routine issues a fabric registration login for a @vport. An
  319. * active ndlp node with Fabric_DID must already exist for this @vport.
  320. * The routine invokes two mailbox commands to carry out fabric registration
  321. * login through the HBA firmware: the first mailbox command requests the
  322. * HBA to perform link configuration for the @vport; and the second mailbox
  323. * command requests the HBA to perform the actual fabric registration login
  324. * with the @vport.
  325. *
  326. * Return code
  327. * 0 - successfully issued fabric registration login for @vport
  328. * -ENXIO -- failed to issue fabric registration login for @vport
  329. **/
  330. int
  331. lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
  332. {
  333. struct lpfc_hba *phba = vport->phba;
  334. LPFC_MBOXQ_t *mbox;
  335. struct lpfc_dmabuf *mp;
  336. struct lpfc_nodelist *ndlp;
  337. struct serv_parm *sp;
  338. int rc;
  339. int err = 0;
  340. sp = &phba->fc_fabparam;
  341. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  342. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  343. err = 1;
  344. goto fail;
  345. }
  346. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  347. if (!mbox) {
  348. err = 2;
  349. goto fail;
  350. }
  351. vport->port_state = LPFC_FABRIC_CFG_LINK;
  352. lpfc_config_link(phba, mbox);
  353. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  354. mbox->vport = vport;
  355. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  356. if (rc == MBX_NOT_FINISHED) {
  357. err = 3;
  358. goto fail_free_mbox;
  359. }
  360. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  361. if (!mbox) {
  362. err = 4;
  363. goto fail;
  364. }
  365. rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
  366. ndlp->nlp_rpi);
  367. if (rc) {
  368. err = 5;
  369. goto fail_free_mbox;
  370. }
  371. mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
  372. mbox->vport = vport;
  373. /* increment the reference count on ndlp to hold reference
  374. * for the callback routine.
  375. */
  376. mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
  377. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  378. if (rc == MBX_NOT_FINISHED) {
  379. err = 6;
  380. goto fail_issue_reg_login;
  381. }
  382. return 0;
  383. fail_issue_reg_login:
  384. /* decrement the reference count on ndlp just incremented
  385. * for the failed mbox command.
  386. */
  387. lpfc_nlp_put(ndlp);
  388. mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
  389. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  390. kfree(mp);
  391. fail_free_mbox:
  392. mempool_free(mbox, phba->mbox_mem_pool);
  393. fail:
  394. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  395. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  396. "0249 Cannot issue Register Fabric login: Err %d\n", err);
  397. return -ENXIO;
  398. }
  399. /**
  400. * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
  401. * @vport: pointer to a host virtual N_Port data structure.
  402. *
  403. * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
  404. * the @vport. This mailbox command is necessary for SLI4 port only.
  405. *
  406. * Return code
  407. * 0 - successfully issued REG_VFI for @vport
  408. * A failure code otherwise.
  409. **/
  410. int
  411. lpfc_issue_reg_vfi(struct lpfc_vport *vport)
  412. {
  413. struct lpfc_hba *phba = vport->phba;
  414. LPFC_MBOXQ_t *mboxq = NULL;
  415. struct lpfc_nodelist *ndlp;
  416. struct lpfc_dmabuf *dmabuf = NULL;
  417. int rc = 0;
  418. /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
  419. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  420. !(phba->link_flag & LS_LOOPBACK_MODE) &&
  421. !(vport->fc_flag & FC_PT2PT)) {
  422. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  423. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  424. rc = -ENODEV;
  425. goto fail;
  426. }
  427. }
  428. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  429. if (!mboxq) {
  430. rc = -ENOMEM;
  431. goto fail;
  432. }
  433. /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
  434. if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
  435. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  436. if (!dmabuf) {
  437. rc = -ENOMEM;
  438. goto fail;
  439. }
  440. dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
  441. if (!dmabuf->virt) {
  442. rc = -ENOMEM;
  443. goto fail;
  444. }
  445. memcpy(dmabuf->virt, &phba->fc_fabparam,
  446. sizeof(struct serv_parm));
  447. }
  448. vport->port_state = LPFC_FABRIC_CFG_LINK;
  449. if (dmabuf)
  450. lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
  451. else
  452. lpfc_reg_vfi(mboxq, vport, 0);
  453. mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
  454. mboxq->vport = vport;
  455. mboxq->ctx_buf = dmabuf;
  456. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  457. if (rc == MBX_NOT_FINISHED) {
  458. rc = -ENXIO;
  459. goto fail;
  460. }
  461. return 0;
  462. fail:
  463. if (mboxq)
  464. mempool_free(mboxq, phba->mbox_mem_pool);
  465. if (dmabuf) {
  466. if (dmabuf->virt)
  467. lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
  468. kfree(dmabuf);
  469. }
  470. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  471. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  472. "0289 Issue Register VFI failed: Err %d\n", rc);
  473. return rc;
  474. }
  475. /**
  476. * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
  477. * @vport: pointer to a host virtual N_Port data structure.
  478. *
  479. * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
  480. * the @vport. This mailbox command is necessary for SLI4 port only.
  481. *
  482. * Return code
  483. * 0 - successfully issued REG_VFI for @vport
  484. * A failure code otherwise.
  485. **/
  486. int
  487. lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
  488. {
  489. struct lpfc_hba *phba = vport->phba;
  490. struct Scsi_Host *shost;
  491. LPFC_MBOXQ_t *mboxq;
  492. int rc;
  493. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  494. if (!mboxq) {
  495. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  496. "2556 UNREG_VFI mbox allocation failed"
  497. "HBA state x%x\n", phba->pport->port_state);
  498. return -ENOMEM;
  499. }
  500. lpfc_unreg_vfi(mboxq, vport);
  501. mboxq->vport = vport;
  502. mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
  503. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  504. if (rc == MBX_NOT_FINISHED) {
  505. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  506. "2557 UNREG_VFI issue mbox failed rc x%x "
  507. "HBA state x%x\n",
  508. rc, phba->pport->port_state);
  509. mempool_free(mboxq, phba->mbox_mem_pool);
  510. return -EIO;
  511. }
  512. shost = lpfc_shost_from_vport(vport);
  513. spin_lock_irq(shost->host_lock);
  514. vport->fc_flag &= ~FC_VFI_REGISTERED;
  515. spin_unlock_irq(shost->host_lock);
  516. return 0;
  517. }
  518. /**
  519. * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
  520. * @vport: pointer to a host virtual N_Port data structure.
  521. * @sp: pointer to service parameter data structure.
  522. *
  523. * This routine is called from FLOGI/FDISC completion handler functions.
  524. * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
  525. * node nodename is changed in the completion service parameter else return
  526. * 0. This function also set flag in the vport data structure to delay
  527. * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
  528. * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
  529. * node nodename is changed in the completion service parameter.
  530. *
  531. * Return code
  532. * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
  533. * 1 - FCID or Fabric Nodename or Fabric portname is changed.
  534. *
  535. **/
  536. static uint8_t
  537. lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
  538. struct serv_parm *sp)
  539. {
  540. struct lpfc_hba *phba = vport->phba;
  541. uint8_t fabric_param_changed = 0;
  542. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  543. if ((vport->fc_prevDID != vport->fc_myDID) ||
  544. memcmp(&vport->fabric_portname, &sp->portName,
  545. sizeof(struct lpfc_name)) ||
  546. memcmp(&vport->fabric_nodename, &sp->nodeName,
  547. sizeof(struct lpfc_name)) ||
  548. (vport->vport_flag & FAWWPN_PARAM_CHG)) {
  549. fabric_param_changed = 1;
  550. vport->vport_flag &= ~FAWWPN_PARAM_CHG;
  551. }
  552. /*
  553. * Word 1 Bit 31 in common service parameter is overloaded.
  554. * Word 1 Bit 31 in FLOGI request is multiple NPort request
  555. * Word 1 Bit 31 in FLOGI response is clean address bit
  556. *
  557. * If fabric parameter is changed and clean address bit is
  558. * cleared delay nport discovery if
  559. * - vport->fc_prevDID != 0 (not initial discovery) OR
  560. * - lpfc_delay_discovery module parameter is set.
  561. */
  562. if (fabric_param_changed && !sp->cmn.clean_address_bit &&
  563. (vport->fc_prevDID || phba->cfg_delay_discovery)) {
  564. spin_lock_irq(shost->host_lock);
  565. vport->fc_flag |= FC_DISC_DELAYED;
  566. spin_unlock_irq(shost->host_lock);
  567. }
  568. return fabric_param_changed;
  569. }
  570. /**
  571. * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
  572. * @vport: pointer to a host virtual N_Port data structure.
  573. * @ndlp: pointer to a node-list data structure.
  574. * @sp: pointer to service parameter data structure.
  575. * @irsp: pointer to the IOCB within the lpfc response IOCB.
  576. *
  577. * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
  578. * function to handle the completion of a Fabric Login (FLOGI) into a fabric
  579. * port in a fabric topology. It properly sets up the parameters to the @ndlp
  580. * from the IOCB response. It also check the newly assigned N_Port ID to the
  581. * @vport against the previously assigned N_Port ID. If it is different from
  582. * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
  583. * is invoked on all the remaining nodes with the @vport to unregister the
  584. * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
  585. * is invoked to register login to the fabric.
  586. *
  587. * Return code
  588. * 0 - Success (currently, always return 0)
  589. **/
  590. static int
  591. lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  592. struct serv_parm *sp, IOCB_t *irsp)
  593. {
  594. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  595. struct lpfc_hba *phba = vport->phba;
  596. struct lpfc_nodelist *np;
  597. struct lpfc_nodelist *next_np;
  598. uint8_t fabric_param_changed;
  599. spin_lock_irq(shost->host_lock);
  600. vport->fc_flag |= FC_FABRIC;
  601. spin_unlock_irq(shost->host_lock);
  602. phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
  603. if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
  604. phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
  605. phba->fc_edtovResol = sp->cmn.edtovResolution;
  606. phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
  607. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  608. spin_lock_irq(shost->host_lock);
  609. vport->fc_flag |= FC_PUBLIC_LOOP;
  610. spin_unlock_irq(shost->host_lock);
  611. }
  612. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  613. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
  614. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
  615. ndlp->nlp_class_sup = 0;
  616. if (sp->cls1.classValid)
  617. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  618. if (sp->cls2.classValid)
  619. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  620. if (sp->cls3.classValid)
  621. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  622. if (sp->cls4.classValid)
  623. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  624. ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  625. sp->cmn.bbRcvSizeLsb;
  626. fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
  627. if (fabric_param_changed) {
  628. /* Reset FDMI attribute masks based on config parameter */
  629. if (phba->cfg_enable_SmartSAN ||
  630. (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
  631. /* Setup appropriate attribute masks */
  632. vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
  633. if (phba->cfg_enable_SmartSAN)
  634. vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
  635. else
  636. vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
  637. } else {
  638. vport->fdmi_hba_mask = 0;
  639. vport->fdmi_port_mask = 0;
  640. }
  641. }
  642. memcpy(&vport->fabric_portname, &sp->portName,
  643. sizeof(struct lpfc_name));
  644. memcpy(&vport->fabric_nodename, &sp->nodeName,
  645. sizeof(struct lpfc_name));
  646. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  647. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  648. if (sp->cmn.response_multiple_NPort) {
  649. lpfc_printf_vlog(vport, KERN_WARNING,
  650. LOG_ELS | LOG_VPORT,
  651. "1816 FLOGI NPIV supported, "
  652. "response data 0x%x\n",
  653. sp->cmn.response_multiple_NPort);
  654. spin_lock_irq(&phba->hbalock);
  655. phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
  656. spin_unlock_irq(&phba->hbalock);
  657. } else {
  658. /* Because we asked f/w for NPIV it still expects us
  659. to call reg_vnpid atleast for the physcial host */
  660. lpfc_printf_vlog(vport, KERN_WARNING,
  661. LOG_ELS | LOG_VPORT,
  662. "1817 Fabric does not support NPIV "
  663. "- configuring single port mode.\n");
  664. spin_lock_irq(&phba->hbalock);
  665. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  666. spin_unlock_irq(&phba->hbalock);
  667. }
  668. }
  669. /*
  670. * For FC we need to do some special processing because of the SLI
  671. * Port's default settings of the Common Service Parameters.
  672. */
  673. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  674. (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
  675. /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
  676. if (fabric_param_changed)
  677. lpfc_unregister_fcf_prep(phba);
  678. /* This should just update the VFI CSPs*/
  679. if (vport->fc_flag & FC_VFI_REGISTERED)
  680. lpfc_issue_reg_vfi(vport);
  681. }
  682. if (fabric_param_changed &&
  683. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  684. /* If our NportID changed, we need to ensure all
  685. * remaining NPORTs get unreg_login'ed.
  686. */
  687. list_for_each_entry_safe(np, next_np,
  688. &vport->fc_nodes, nlp_listp) {
  689. if (!NLP_CHK_NODE_ACT(np))
  690. continue;
  691. if ((np->nlp_state != NLP_STE_NPR_NODE) ||
  692. !(np->nlp_flag & NLP_NPR_ADISC))
  693. continue;
  694. spin_lock_irq(shost->host_lock);
  695. np->nlp_flag &= ~NLP_NPR_ADISC;
  696. spin_unlock_irq(shost->host_lock);
  697. lpfc_unreg_rpi(vport, np);
  698. }
  699. lpfc_cleanup_pending_mbox(vport);
  700. if (phba->sli_rev == LPFC_SLI_REV4) {
  701. lpfc_sli4_unreg_all_rpis(vport);
  702. lpfc_mbx_unreg_vpi(vport);
  703. spin_lock_irq(shost->host_lock);
  704. vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  705. spin_unlock_irq(shost->host_lock);
  706. }
  707. /*
  708. * For SLI3 and SLI4, the VPI needs to be reregistered in
  709. * response to this fabric parameter change event.
  710. */
  711. spin_lock_irq(shost->host_lock);
  712. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  713. spin_unlock_irq(shost->host_lock);
  714. } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
  715. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  716. /*
  717. * Driver needs to re-reg VPI in order for f/w
  718. * to update the MAC address.
  719. */
  720. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  721. lpfc_register_new_vport(phba, vport, ndlp);
  722. return 0;
  723. }
  724. if (phba->sli_rev < LPFC_SLI_REV4) {
  725. lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
  726. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
  727. vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  728. lpfc_register_new_vport(phba, vport, ndlp);
  729. else
  730. lpfc_issue_fabric_reglogin(vport);
  731. } else {
  732. ndlp->nlp_type |= NLP_FABRIC;
  733. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  734. if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
  735. (vport->vpi_state & LPFC_VPI_REGISTERED)) {
  736. lpfc_start_fdiscs(phba);
  737. lpfc_do_scr_ns_plogi(phba, vport);
  738. } else if (vport->fc_flag & FC_VFI_REGISTERED)
  739. lpfc_issue_init_vpi(vport);
  740. else {
  741. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  742. "3135 Need register VFI: (x%x/%x)\n",
  743. vport->fc_prevDID, vport->fc_myDID);
  744. lpfc_issue_reg_vfi(vport);
  745. }
  746. }
  747. return 0;
  748. }
  749. /**
  750. * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
  751. * @vport: pointer to a host virtual N_Port data structure.
  752. * @ndlp: pointer to a node-list data structure.
  753. * @sp: pointer to service parameter data structure.
  754. *
  755. * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
  756. * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
  757. * in a point-to-point topology. First, the @vport's N_Port Name is compared
  758. * with the received N_Port Name: if the @vport's N_Port Name is greater than
  759. * the received N_Port Name lexicographically, this node shall assign local
  760. * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
  761. * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
  762. * this node shall just wait for the remote node to issue PLOGI and assign
  763. * N_Port IDs.
  764. *
  765. * Return code
  766. * 0 - Success
  767. * -ENXIO - Fail
  768. **/
  769. static int
  770. lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  771. struct serv_parm *sp)
  772. {
  773. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  774. struct lpfc_hba *phba = vport->phba;
  775. LPFC_MBOXQ_t *mbox;
  776. int rc;
  777. spin_lock_irq(shost->host_lock);
  778. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  779. vport->fc_flag |= FC_PT2PT;
  780. spin_unlock_irq(shost->host_lock);
  781. /* If we are pt2pt with another NPort, force NPIV off! */
  782. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  783. /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
  784. if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
  785. lpfc_unregister_fcf_prep(phba);
  786. spin_lock_irq(shost->host_lock);
  787. vport->fc_flag &= ~FC_VFI_REGISTERED;
  788. spin_unlock_irq(shost->host_lock);
  789. phba->fc_topology_changed = 0;
  790. }
  791. rc = memcmp(&vport->fc_portname, &sp->portName,
  792. sizeof(vport->fc_portname));
  793. if (rc >= 0) {
  794. /* This side will initiate the PLOGI */
  795. spin_lock_irq(shost->host_lock);
  796. vport->fc_flag |= FC_PT2PT_PLOGI;
  797. spin_unlock_irq(shost->host_lock);
  798. /*
  799. * N_Port ID cannot be 0, set our Id to LocalID
  800. * the other side will be RemoteID.
  801. */
  802. /* not equal */
  803. if (rc)
  804. vport->fc_myDID = PT2PT_LocalID;
  805. /* Decrement ndlp reference count indicating that ndlp can be
  806. * safely released when other references to it are done.
  807. */
  808. lpfc_nlp_put(ndlp);
  809. ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
  810. if (!ndlp) {
  811. /*
  812. * Cannot find existing Fabric ndlp, so allocate a
  813. * new one
  814. */
  815. ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
  816. if (!ndlp)
  817. goto fail;
  818. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  819. ndlp = lpfc_enable_node(vport, ndlp,
  820. NLP_STE_UNUSED_NODE);
  821. if(!ndlp)
  822. goto fail;
  823. }
  824. memcpy(&ndlp->nlp_portname, &sp->portName,
  825. sizeof(struct lpfc_name));
  826. memcpy(&ndlp->nlp_nodename, &sp->nodeName,
  827. sizeof(struct lpfc_name));
  828. /* Set state will put ndlp onto node list if not already done */
  829. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  830. spin_lock_irq(shost->host_lock);
  831. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  832. spin_unlock_irq(shost->host_lock);
  833. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  834. if (!mbox)
  835. goto fail;
  836. lpfc_config_link(phba, mbox);
  837. mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
  838. mbox->vport = vport;
  839. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  840. if (rc == MBX_NOT_FINISHED) {
  841. mempool_free(mbox, phba->mbox_mem_pool);
  842. goto fail;
  843. }
  844. } else {
  845. /* This side will wait for the PLOGI, decrement ndlp reference
  846. * count indicating that ndlp can be released when other
  847. * references to it are done.
  848. */
  849. lpfc_nlp_put(ndlp);
  850. /* Start discovery - this should just do CLEAR_LA */
  851. lpfc_disc_start(vport);
  852. }
  853. return 0;
  854. fail:
  855. return -ENXIO;
  856. }
  857. /**
  858. * lpfc_cmpl_els_flogi - Completion callback function for flogi
  859. * @phba: pointer to lpfc hba data structure.
  860. * @cmdiocb: pointer to lpfc command iocb data structure.
  861. * @rspiocb: pointer to lpfc response iocb data structure.
  862. *
  863. * This routine is the top-level completion callback function for issuing
  864. * a Fabric Login (FLOGI) command. If the response IOCB reported error,
  865. * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
  866. * retry has been made (either immediately or delayed with lpfc_els_retry()
  867. * returning 1), the command IOCB will be released and function returned.
  868. * If the retry attempt has been given up (possibly reach the maximum
  869. * number of retries), one additional decrement of ndlp reference shall be
  870. * invoked before going out after releasing the command IOCB. This will
  871. * actually release the remote node (Note, lpfc_els_free_iocb() will also
  872. * invoke one decrement of ndlp reference count). If no error reported in
  873. * the IOCB status, the command Port ID field is used to determine whether
  874. * this is a point-to-point topology or a fabric topology: if the Port ID
  875. * field is assigned, it is a fabric topology; otherwise, it is a
  876. * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
  877. * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
  878. * specific topology completion conditions.
  879. **/
  880. static void
  881. lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  882. struct lpfc_iocbq *rspiocb)
  883. {
  884. struct lpfc_vport *vport = cmdiocb->vport;
  885. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  886. IOCB_t *irsp = &rspiocb->iocb;
  887. struct lpfc_nodelist *ndlp = cmdiocb->context1;
  888. struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
  889. struct serv_parm *sp;
  890. uint16_t fcf_index;
  891. int rc;
  892. /* Check to see if link went down during discovery */
  893. if (lpfc_els_chk_latt(vport)) {
  894. /* One additional decrement on node reference count to
  895. * trigger the release of the node
  896. */
  897. lpfc_nlp_put(ndlp);
  898. goto out;
  899. }
  900. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  901. "FLOGI cmpl: status:x%x/x%x state:x%x",
  902. irsp->ulpStatus, irsp->un.ulpWord[4],
  903. vport->port_state);
  904. if (irsp->ulpStatus) {
  905. /*
  906. * In case of FIP mode, perform roundrobin FCF failover
  907. * due to new FCF discovery
  908. */
  909. if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
  910. (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
  911. if (phba->link_state < LPFC_LINK_UP)
  912. goto stop_rr_fcf_flogi;
  913. if ((phba->fcoe_cvl_eventtag_attn ==
  914. phba->fcoe_cvl_eventtag) &&
  915. (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  916. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  917. IOERR_SLI_ABORTED))
  918. goto stop_rr_fcf_flogi;
  919. else
  920. phba->fcoe_cvl_eventtag_attn =
  921. phba->fcoe_cvl_eventtag;
  922. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
  923. "2611 FLOGI failed on FCF (x%x), "
  924. "status:x%x/x%x, tmo:x%x, perform "
  925. "roundrobin FCF failover\n",
  926. phba->fcf.current_rec.fcf_indx,
  927. irsp->ulpStatus, irsp->un.ulpWord[4],
  928. irsp->ulpTimeout);
  929. lpfc_sli4_set_fcf_flogi_fail(phba,
  930. phba->fcf.current_rec.fcf_indx);
  931. fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
  932. rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
  933. if (rc)
  934. goto out;
  935. }
  936. stop_rr_fcf_flogi:
  937. /* FLOGI failure */
  938. if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
  939. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  940. IOERR_LOOP_OPEN_FAILURE)))
  941. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  942. "2858 FLOGI failure Status:x%x/x%x "
  943. "TMO:x%x Data x%x x%x\n",
  944. irsp->ulpStatus, irsp->un.ulpWord[4],
  945. irsp->ulpTimeout, phba->hba_flag,
  946. phba->fcf.fcf_flag);
  947. /* Check for retry */
  948. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  949. goto out;
  950. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  951. "0150 FLOGI failure Status:x%x/x%x "
  952. "xri x%x TMO:x%x\n",
  953. irsp->ulpStatus, irsp->un.ulpWord[4],
  954. cmdiocb->sli4_xritag, irsp->ulpTimeout);
  955. /* If this is not a loop open failure, bail out */
  956. if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
  957. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  958. IOERR_LOOP_OPEN_FAILURE)))
  959. goto flogifail;
  960. /* FLOGI failed, so there is no fabric */
  961. spin_lock_irq(shost->host_lock);
  962. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  963. spin_unlock_irq(shost->host_lock);
  964. /* If private loop, then allow max outstanding els to be
  965. * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
  966. * alpa map would take too long otherwise.
  967. */
  968. if (phba->alpa_map[0] == 0)
  969. vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
  970. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  971. (!(vport->fc_flag & FC_VFI_REGISTERED) ||
  972. (vport->fc_prevDID != vport->fc_myDID) ||
  973. phba->fc_topology_changed)) {
  974. if (vport->fc_flag & FC_VFI_REGISTERED) {
  975. if (phba->fc_topology_changed) {
  976. lpfc_unregister_fcf_prep(phba);
  977. spin_lock_irq(shost->host_lock);
  978. vport->fc_flag &= ~FC_VFI_REGISTERED;
  979. spin_unlock_irq(shost->host_lock);
  980. phba->fc_topology_changed = 0;
  981. } else {
  982. lpfc_sli4_unreg_all_rpis(vport);
  983. }
  984. }
  985. /* Do not register VFI if the driver aborted FLOGI */
  986. if (!lpfc_error_lost_link(irsp))
  987. lpfc_issue_reg_vfi(vport);
  988. lpfc_nlp_put(ndlp);
  989. goto out;
  990. }
  991. goto flogifail;
  992. }
  993. spin_lock_irq(shost->host_lock);
  994. vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
  995. vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
  996. spin_unlock_irq(shost->host_lock);
  997. /*
  998. * The FLogI succeeded. Sync the data for the CPU before
  999. * accessing it.
  1000. */
  1001. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  1002. if (!prsp)
  1003. goto out;
  1004. sp = prsp->virt + sizeof(uint32_t);
  1005. /* FLOGI completes successfully */
  1006. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1007. "0101 FLOGI completes successfully, I/O tag:x%x, "
  1008. "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
  1009. cmdiocb->iotag, cmdiocb->sli4_xritag,
  1010. irsp->un.ulpWord[4], sp->cmn.e_d_tov,
  1011. sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
  1012. vport->port_state, vport->fc_flag);
  1013. if (vport->port_state == LPFC_FLOGI) {
  1014. /*
  1015. * If Common Service Parameters indicate Nport
  1016. * we are point to point, if Fport we are Fabric.
  1017. */
  1018. if (sp->cmn.fPort)
  1019. rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
  1020. else if (!(phba->hba_flag & HBA_FCOE_MODE))
  1021. rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
  1022. else {
  1023. lpfc_printf_vlog(vport, KERN_ERR,
  1024. LOG_FIP | LOG_ELS,
  1025. "2831 FLOGI response with cleared Fabric "
  1026. "bit fcf_index 0x%x "
  1027. "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
  1028. "Fabric Name "
  1029. "%02x%02x%02x%02x%02x%02x%02x%02x\n",
  1030. phba->fcf.current_rec.fcf_indx,
  1031. phba->fcf.current_rec.switch_name[0],
  1032. phba->fcf.current_rec.switch_name[1],
  1033. phba->fcf.current_rec.switch_name[2],
  1034. phba->fcf.current_rec.switch_name[3],
  1035. phba->fcf.current_rec.switch_name[4],
  1036. phba->fcf.current_rec.switch_name[5],
  1037. phba->fcf.current_rec.switch_name[6],
  1038. phba->fcf.current_rec.switch_name[7],
  1039. phba->fcf.current_rec.fabric_name[0],
  1040. phba->fcf.current_rec.fabric_name[1],
  1041. phba->fcf.current_rec.fabric_name[2],
  1042. phba->fcf.current_rec.fabric_name[3],
  1043. phba->fcf.current_rec.fabric_name[4],
  1044. phba->fcf.current_rec.fabric_name[5],
  1045. phba->fcf.current_rec.fabric_name[6],
  1046. phba->fcf.current_rec.fabric_name[7]);
  1047. lpfc_nlp_put(ndlp);
  1048. spin_lock_irq(&phba->hbalock);
  1049. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  1050. phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
  1051. spin_unlock_irq(&phba->hbalock);
  1052. phba->fcf.fcf_redisc_attempted = 0; /* reset */
  1053. goto out;
  1054. }
  1055. if (!rc) {
  1056. /* Mark the FCF discovery process done */
  1057. if (phba->hba_flag & HBA_FIP_SUPPORT)
  1058. lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
  1059. LOG_ELS,
  1060. "2769 FLOGI to FCF (x%x) "
  1061. "completed successfully\n",
  1062. phba->fcf.current_rec.fcf_indx);
  1063. spin_lock_irq(&phba->hbalock);
  1064. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  1065. phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
  1066. spin_unlock_irq(&phba->hbalock);
  1067. phba->fcf.fcf_redisc_attempted = 0; /* reset */
  1068. goto out;
  1069. }
  1070. }
  1071. flogifail:
  1072. spin_lock_irq(&phba->hbalock);
  1073. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  1074. spin_unlock_irq(&phba->hbalock);
  1075. lpfc_nlp_put(ndlp);
  1076. if (!lpfc_error_lost_link(irsp)) {
  1077. /* FLOGI failed, so just use loop map to make discovery list */
  1078. lpfc_disc_list_loopmap(vport);
  1079. /* Start discovery */
  1080. lpfc_disc_start(vport);
  1081. } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  1082. (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
  1083. IOERR_SLI_ABORTED) &&
  1084. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
  1085. IOERR_SLI_DOWN))) &&
  1086. (phba->link_state != LPFC_CLEAR_LA)) {
  1087. /* If FLOGI failed enable link interrupt. */
  1088. lpfc_issue_clear_la(phba, vport);
  1089. }
  1090. out:
  1091. lpfc_els_free_iocb(phba, cmdiocb);
  1092. }
  1093. /**
  1094. * lpfc_cmpl_els_link_down - Completion callback function for ELS command
  1095. * aborted during a link down
  1096. * @phba: pointer to lpfc hba data structure.
  1097. * @cmdiocb: pointer to lpfc command iocb data structure.
  1098. * @rspiocb: pointer to lpfc response iocb data structure.
  1099. *
  1100. */
  1101. static void
  1102. lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1103. struct lpfc_iocbq *rspiocb)
  1104. {
  1105. IOCB_t *irsp;
  1106. uint32_t *pcmd;
  1107. uint32_t cmd;
  1108. pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
  1109. cmd = *pcmd;
  1110. irsp = &rspiocb->iocb;
  1111. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  1112. "6445 ELS completes after LINK_DOWN: "
  1113. " Status %x/%x cmd x%x flg x%x\n",
  1114. irsp->ulpStatus, irsp->un.ulpWord[4], cmd,
  1115. cmdiocb->iocb_flag);
  1116. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) {
  1117. cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
  1118. atomic_dec(&phba->fabric_iocb_count);
  1119. }
  1120. lpfc_els_free_iocb(phba, cmdiocb);
  1121. }
  1122. /**
  1123. * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
  1124. * @vport: pointer to a host virtual N_Port data structure.
  1125. * @ndlp: pointer to a node-list data structure.
  1126. * @retry: number of retries to the command IOCB.
  1127. *
  1128. * This routine issues a Fabric Login (FLOGI) Request ELS command
  1129. * for a @vport. The initiator service parameters are put into the payload
  1130. * of the FLOGI Request IOCB and the top-level callback function pointer
  1131. * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
  1132. * function field. The lpfc_issue_fabric_iocb routine is invoked to send
  1133. * out FLOGI ELS command with one outstanding fabric IOCB at a time.
  1134. *
  1135. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1136. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1137. * will be stored into the context1 field of the IOCB for the completion
  1138. * callback function to the FLOGI ELS command.
  1139. *
  1140. * Return code
  1141. * 0 - successfully issued flogi iocb for @vport
  1142. * 1 - failed to issue flogi iocb for @vport
  1143. **/
  1144. static int
  1145. lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1146. uint8_t retry)
  1147. {
  1148. struct lpfc_hba *phba = vport->phba;
  1149. struct serv_parm *sp;
  1150. IOCB_t *icmd;
  1151. struct lpfc_iocbq *elsiocb;
  1152. struct lpfc_iocbq defer_flogi_acc;
  1153. uint8_t *pcmd;
  1154. uint16_t cmdsize;
  1155. uint32_t tmo, did;
  1156. int rc;
  1157. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  1158. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1159. ndlp->nlp_DID, ELS_CMD_FLOGI);
  1160. if (!elsiocb)
  1161. return 1;
  1162. icmd = &elsiocb->iocb;
  1163. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1164. /* For FLOGI request, remainder of payload is service parameters */
  1165. *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
  1166. pcmd += sizeof(uint32_t);
  1167. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  1168. sp = (struct serv_parm *) pcmd;
  1169. /* Setup CSPs accordingly for Fabric */
  1170. sp->cmn.e_d_tov = 0;
  1171. sp->cmn.w2.r_a_tov = 0;
  1172. sp->cmn.virtual_fabric_support = 0;
  1173. sp->cls1.classValid = 0;
  1174. if (sp->cmn.fcphLow < FC_PH3)
  1175. sp->cmn.fcphLow = FC_PH3;
  1176. if (sp->cmn.fcphHigh < FC_PH3)
  1177. sp->cmn.fcphHigh = FC_PH3;
  1178. if (phba->sli_rev == LPFC_SLI_REV4) {
  1179. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  1180. LPFC_SLI_INTF_IF_TYPE_0) {
  1181. elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
  1182. elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
  1183. /* FLOGI needs to be 3 for WQE FCFI */
  1184. /* Set the fcfi to the fcfi we registered with */
  1185. elsiocb->iocb.ulpContext = phba->fcf.fcfi;
  1186. }
  1187. /* Can't do SLI4 class2 without support sequence coalescing */
  1188. sp->cls2.classValid = 0;
  1189. sp->cls2.seqDelivery = 0;
  1190. } else {
  1191. /* Historical, setting sequential-delivery bit for SLI3 */
  1192. sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
  1193. sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
  1194. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  1195. sp->cmn.request_multiple_Nport = 1;
  1196. /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
  1197. icmd->ulpCt_h = 1;
  1198. icmd->ulpCt_l = 0;
  1199. } else
  1200. sp->cmn.request_multiple_Nport = 0;
  1201. }
  1202. if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
  1203. icmd->un.elsreq64.myID = 0;
  1204. icmd->un.elsreq64.fl = 1;
  1205. }
  1206. tmo = phba->fc_ratov;
  1207. phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
  1208. lpfc_set_disctmo(vport);
  1209. phba->fc_ratov = tmo;
  1210. phba->fc_stat.elsXmitFLOGI++;
  1211. elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
  1212. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1213. "Issue FLOGI: opt:x%x",
  1214. phba->sli3_options, 0, 0);
  1215. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  1216. phba->hba_flag |= HBA_FLOGI_ISSUED;
  1217. /* Check for a deferred FLOGI ACC condition */
  1218. if (phba->defer_flogi_acc_flag) {
  1219. did = vport->fc_myDID;
  1220. vport->fc_myDID = Fabric_DID;
  1221. memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
  1222. defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
  1223. defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
  1224. phba->defer_flogi_acc_ox_id;
  1225. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1226. "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
  1227. " ox_id: x%x, hba_flag x%x\n",
  1228. phba->defer_flogi_acc_rx_id,
  1229. phba->defer_flogi_acc_ox_id, phba->hba_flag);
  1230. /* Send deferred FLOGI ACC */
  1231. lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
  1232. ndlp, NULL);
  1233. phba->defer_flogi_acc_flag = false;
  1234. vport->fc_myDID = did;
  1235. }
  1236. if (rc == IOCB_ERROR) {
  1237. lpfc_els_free_iocb(phba, elsiocb);
  1238. return 1;
  1239. }
  1240. return 0;
  1241. }
  1242. /**
  1243. * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
  1244. * @phba: pointer to lpfc hba data structure.
  1245. *
  1246. * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
  1247. * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
  1248. * list and issues an abort IOCB commond on each outstanding IOCB that
  1249. * contains a active Fabric_DID ndlp. Note that this function is to issue
  1250. * the abort IOCB command on all the outstanding IOCBs, thus when this
  1251. * function returns, it does not guarantee all the IOCBs are actually aborted.
  1252. *
  1253. * Return code
  1254. * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
  1255. **/
  1256. int
  1257. lpfc_els_abort_flogi(struct lpfc_hba *phba)
  1258. {
  1259. struct lpfc_sli_ring *pring;
  1260. struct lpfc_iocbq *iocb, *next_iocb;
  1261. struct lpfc_nodelist *ndlp;
  1262. IOCB_t *icmd;
  1263. /* Abort outstanding I/O on NPort <nlp_DID> */
  1264. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1265. "0201 Abort outstanding I/O on NPort x%x\n",
  1266. Fabric_DID);
  1267. pring = lpfc_phba_elsring(phba);
  1268. if (unlikely(!pring))
  1269. return -EIO;
  1270. /*
  1271. * Check the txcmplq for an iocb that matches the nport the driver is
  1272. * searching for.
  1273. */
  1274. spin_lock_irq(&phba->hbalock);
  1275. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  1276. icmd = &iocb->iocb;
  1277. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
  1278. ndlp = (struct lpfc_nodelist *)(iocb->context1);
  1279. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  1280. (ndlp->nlp_DID == Fabric_DID))
  1281. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  1282. }
  1283. }
  1284. spin_unlock_irq(&phba->hbalock);
  1285. return 0;
  1286. }
  1287. /**
  1288. * lpfc_initial_flogi - Issue an initial fabric login for a vport
  1289. * @vport: pointer to a host virtual N_Port data structure.
  1290. *
  1291. * This routine issues an initial Fabric Login (FLOGI) for the @vport
  1292. * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
  1293. * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
  1294. * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
  1295. * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
  1296. * is then invoked with the @vport and the ndlp to perform the FLOGI for the
  1297. * @vport.
  1298. *
  1299. * Return code
  1300. * 0 - failed to issue initial flogi for @vport
  1301. * 1 - successfully issued initial flogi for @vport
  1302. **/
  1303. int
  1304. lpfc_initial_flogi(struct lpfc_vport *vport)
  1305. {
  1306. struct lpfc_nodelist *ndlp;
  1307. vport->port_state = LPFC_FLOGI;
  1308. lpfc_set_disctmo(vport);
  1309. /* First look for the Fabric ndlp */
  1310. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  1311. if (!ndlp) {
  1312. /* Cannot find existing Fabric ndlp, so allocate a new one */
  1313. ndlp = lpfc_nlp_init(vport, Fabric_DID);
  1314. if (!ndlp)
  1315. return 0;
  1316. /* Set the node type */
  1317. ndlp->nlp_type |= NLP_FABRIC;
  1318. /* Put ndlp onto node list */
  1319. lpfc_enqueue_node(vport, ndlp);
  1320. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  1321. /* re-setup ndlp without removing from node list */
  1322. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  1323. if (!ndlp)
  1324. return 0;
  1325. }
  1326. if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
  1327. /* This decrement of reference count to node shall kick off
  1328. * the release of the node.
  1329. */
  1330. lpfc_nlp_put(ndlp);
  1331. return 0;
  1332. }
  1333. return 1;
  1334. }
  1335. /**
  1336. * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
  1337. * @vport: pointer to a host virtual N_Port data structure.
  1338. *
  1339. * This routine issues an initial Fabric Discover (FDISC) for the @vport
  1340. * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
  1341. * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
  1342. * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
  1343. * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
  1344. * is then invoked with the @vport and the ndlp to perform the FDISC for the
  1345. * @vport.
  1346. *
  1347. * Return code
  1348. * 0 - failed to issue initial fdisc for @vport
  1349. * 1 - successfully issued initial fdisc for @vport
  1350. **/
  1351. int
  1352. lpfc_initial_fdisc(struct lpfc_vport *vport)
  1353. {
  1354. struct lpfc_nodelist *ndlp;
  1355. /* First look for the Fabric ndlp */
  1356. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  1357. if (!ndlp) {
  1358. /* Cannot find existing Fabric ndlp, so allocate a new one */
  1359. ndlp = lpfc_nlp_init(vport, Fabric_DID);
  1360. if (!ndlp)
  1361. return 0;
  1362. /* Put ndlp onto node list */
  1363. lpfc_enqueue_node(vport, ndlp);
  1364. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  1365. /* re-setup ndlp without removing from node list */
  1366. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  1367. if (!ndlp)
  1368. return 0;
  1369. }
  1370. if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
  1371. /* decrement node reference count to trigger the release of
  1372. * the node.
  1373. */
  1374. lpfc_nlp_put(ndlp);
  1375. return 0;
  1376. }
  1377. return 1;
  1378. }
  1379. /**
  1380. * lpfc_more_plogi - Check and issue remaining plogis for a vport
  1381. * @vport: pointer to a host virtual N_Port data structure.
  1382. *
  1383. * This routine checks whether there are more remaining Port Logins
  1384. * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
  1385. * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
  1386. * to issue ELS PLOGIs up to the configured discover threads with the
  1387. * @vport (@vport->cfg_discovery_threads). The function also decrement
  1388. * the @vport's num_disc_node by 1 if it is not already 0.
  1389. **/
  1390. void
  1391. lpfc_more_plogi(struct lpfc_vport *vport)
  1392. {
  1393. if (vport->num_disc_nodes)
  1394. vport->num_disc_nodes--;
  1395. /* Continue discovery with <num_disc_nodes> PLOGIs to go */
  1396. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1397. "0232 Continue discovery with %d PLOGIs to go "
  1398. "Data: x%x x%x x%x\n",
  1399. vport->num_disc_nodes, vport->fc_plogi_cnt,
  1400. vport->fc_flag, vport->port_state);
  1401. /* Check to see if there are more PLOGIs to be sent */
  1402. if (vport->fc_flag & FC_NLP_MORE)
  1403. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  1404. lpfc_els_disc_plogi(vport);
  1405. return;
  1406. }
  1407. /**
  1408. * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
  1409. * @phba: pointer to lpfc hba data structure.
  1410. * @prsp: pointer to response IOCB payload.
  1411. * @ndlp: pointer to a node-list data structure.
  1412. *
  1413. * This routine checks and indicates whether the WWPN of an N_Port, retrieved
  1414. * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
  1415. * The following cases are considered N_Port confirmed:
  1416. * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
  1417. * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
  1418. * it does not have WWPN assigned either. If the WWPN is confirmed, the
  1419. * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
  1420. * 1) if there is a node on vport list other than the @ndlp with the same
  1421. * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
  1422. * on that node to release the RPI associated with the node; 2) if there is
  1423. * no node found on vport list with the same WWPN of the N_Port PLOGI logged
  1424. * into, a new node shall be allocated (or activated). In either case, the
  1425. * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
  1426. * be released and the new_ndlp shall be put on to the vport node list and
  1427. * its pointer returned as the confirmed node.
  1428. *
  1429. * Note that before the @ndlp got "released", the keepDID from not-matching
  1430. * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
  1431. * of the @ndlp. This is because the release of @ndlp is actually to put it
  1432. * into an inactive state on the vport node list and the vport node list
  1433. * management algorithm does not allow two node with a same DID.
  1434. *
  1435. * Return code
  1436. * pointer to the PLOGI N_Port @ndlp
  1437. **/
  1438. static struct lpfc_nodelist *
  1439. lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
  1440. struct lpfc_nodelist *ndlp)
  1441. {
  1442. struct lpfc_vport *vport = ndlp->vport;
  1443. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1444. struct lpfc_nodelist *new_ndlp;
  1445. struct lpfc_rport_data *rdata;
  1446. struct fc_rport *rport;
  1447. struct serv_parm *sp;
  1448. uint8_t name[sizeof(struct lpfc_name)];
  1449. uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
  1450. uint32_t keep_new_nlp_flag = 0;
  1451. uint16_t keep_nlp_state;
  1452. u32 keep_nlp_fc4_type = 0;
  1453. struct lpfc_nvme_rport *keep_nrport = NULL;
  1454. int put_node;
  1455. int put_rport;
  1456. unsigned long *active_rrqs_xri_bitmap = NULL;
  1457. /* Fabric nodes can have the same WWPN so we don't bother searching
  1458. * by WWPN. Just return the ndlp that was given to us.
  1459. */
  1460. if (ndlp->nlp_type & NLP_FABRIC)
  1461. return ndlp;
  1462. sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
  1463. memset(name, 0, sizeof(struct lpfc_name));
  1464. /* Now we find out if the NPort we are logging into, matches the WWPN
  1465. * we have for that ndlp. If not, we have some work to do.
  1466. */
  1467. new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
  1468. /* return immediately if the WWPN matches ndlp */
  1469. if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
  1470. return ndlp;
  1471. if (phba->sli_rev == LPFC_SLI_REV4) {
  1472. active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
  1473. GFP_KERNEL);
  1474. if (active_rrqs_xri_bitmap)
  1475. memset(active_rrqs_xri_bitmap, 0,
  1476. phba->cfg_rrq_xri_bitmap_sz);
  1477. }
  1478. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
  1479. "3178 PLOGI confirm: ndlp x%x x%x x%x: "
  1480. "new_ndlp x%x x%x x%x\n",
  1481. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
  1482. (new_ndlp ? new_ndlp->nlp_DID : 0),
  1483. (new_ndlp ? new_ndlp->nlp_flag : 0),
  1484. (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
  1485. if (!new_ndlp) {
  1486. rc = memcmp(&ndlp->nlp_portname, name,
  1487. sizeof(struct lpfc_name));
  1488. if (!rc) {
  1489. if (active_rrqs_xri_bitmap)
  1490. mempool_free(active_rrqs_xri_bitmap,
  1491. phba->active_rrq_pool);
  1492. return ndlp;
  1493. }
  1494. new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
  1495. if (!new_ndlp) {
  1496. if (active_rrqs_xri_bitmap)
  1497. mempool_free(active_rrqs_xri_bitmap,
  1498. phba->active_rrq_pool);
  1499. return ndlp;
  1500. }
  1501. } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
  1502. rc = memcmp(&ndlp->nlp_portname, name,
  1503. sizeof(struct lpfc_name));
  1504. if (!rc) {
  1505. if (active_rrqs_xri_bitmap)
  1506. mempool_free(active_rrqs_xri_bitmap,
  1507. phba->active_rrq_pool);
  1508. return ndlp;
  1509. }
  1510. new_ndlp = lpfc_enable_node(vport, new_ndlp,
  1511. NLP_STE_UNUSED_NODE);
  1512. if (!new_ndlp) {
  1513. if (active_rrqs_xri_bitmap)
  1514. mempool_free(active_rrqs_xri_bitmap,
  1515. phba->active_rrq_pool);
  1516. return ndlp;
  1517. }
  1518. keepDID = new_ndlp->nlp_DID;
  1519. if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
  1520. memcpy(active_rrqs_xri_bitmap,
  1521. new_ndlp->active_rrqs_xri_bitmap,
  1522. phba->cfg_rrq_xri_bitmap_sz);
  1523. } else {
  1524. keepDID = new_ndlp->nlp_DID;
  1525. if (phba->sli_rev == LPFC_SLI_REV4 &&
  1526. active_rrqs_xri_bitmap)
  1527. memcpy(active_rrqs_xri_bitmap,
  1528. new_ndlp->active_rrqs_xri_bitmap,
  1529. phba->cfg_rrq_xri_bitmap_sz);
  1530. }
  1531. /* At this point in this routine, we know new_ndlp will be
  1532. * returned. however, any previous GID_FTs that were done
  1533. * would have updated nlp_fc4_type in ndlp, so we must ensure
  1534. * new_ndlp has the right value.
  1535. */
  1536. if (vport->fc_flag & FC_FABRIC) {
  1537. keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
  1538. new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
  1539. }
  1540. lpfc_unreg_rpi(vport, new_ndlp);
  1541. new_ndlp->nlp_DID = ndlp->nlp_DID;
  1542. new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
  1543. if (phba->sli_rev == LPFC_SLI_REV4)
  1544. memcpy(new_ndlp->active_rrqs_xri_bitmap,
  1545. ndlp->active_rrqs_xri_bitmap,
  1546. phba->cfg_rrq_xri_bitmap_sz);
  1547. spin_lock_irq(shost->host_lock);
  1548. keep_new_nlp_flag = new_ndlp->nlp_flag;
  1549. keep_nlp_flag = ndlp->nlp_flag;
  1550. new_ndlp->nlp_flag = ndlp->nlp_flag;
  1551. /* if new_ndlp had NLP_UNREG_INP set, keep it */
  1552. if (keep_new_nlp_flag & NLP_UNREG_INP)
  1553. new_ndlp->nlp_flag |= NLP_UNREG_INP;
  1554. else
  1555. new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
  1556. /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
  1557. if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
  1558. new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  1559. else
  1560. new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
  1561. ndlp->nlp_flag = keep_new_nlp_flag;
  1562. /* if ndlp had NLP_UNREG_INP set, keep it */
  1563. if (keep_nlp_flag & NLP_UNREG_INP)
  1564. ndlp->nlp_flag |= NLP_UNREG_INP;
  1565. else
  1566. ndlp->nlp_flag &= ~NLP_UNREG_INP;
  1567. /* if ndlp had NLP_RPI_REGISTERED set, keep it */
  1568. if (keep_nlp_flag & NLP_RPI_REGISTERED)
  1569. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  1570. else
  1571. ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
  1572. spin_unlock_irq(shost->host_lock);
  1573. /* Set nlp_states accordingly */
  1574. keep_nlp_state = new_ndlp->nlp_state;
  1575. lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
  1576. /* interchange the nvme remoteport structs */
  1577. keep_nrport = new_ndlp->nrport;
  1578. new_ndlp->nrport = ndlp->nrport;
  1579. /* Move this back to NPR state */
  1580. if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
  1581. /* The new_ndlp is replacing ndlp totally, so we need
  1582. * to put ndlp on UNUSED list and try to free it.
  1583. */
  1584. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1585. "3179 PLOGI confirm NEW: %x %x\n",
  1586. new_ndlp->nlp_DID, keepDID);
  1587. /* Fix up the rport accordingly */
  1588. rport = ndlp->rport;
  1589. if (rport) {
  1590. rdata = rport->dd_data;
  1591. if (rdata->pnode == ndlp) {
  1592. /* break the link before dropping the ref */
  1593. ndlp->rport = NULL;
  1594. lpfc_nlp_put(ndlp);
  1595. rdata->pnode = lpfc_nlp_get(new_ndlp);
  1596. new_ndlp->rport = rport;
  1597. }
  1598. new_ndlp->nlp_type = ndlp->nlp_type;
  1599. }
  1600. /* Fix up the nvme rport */
  1601. if (ndlp->nrport) {
  1602. ndlp->nrport = NULL;
  1603. lpfc_nlp_put(ndlp);
  1604. }
  1605. /* We shall actually free the ndlp with both nlp_DID and
  1606. * nlp_portname fields equals 0 to avoid any ndlp on the
  1607. * nodelist never to be used.
  1608. */
  1609. if (ndlp->nlp_DID == 0) {
  1610. spin_lock_irq(&phba->ndlp_lock);
  1611. NLP_SET_FREE_REQ(ndlp);
  1612. spin_unlock_irq(&phba->ndlp_lock);
  1613. }
  1614. /* Two ndlps cannot have the same did on the nodelist.
  1615. * Note: for this case, ndlp has a NULL WWPN so setting
  1616. * the nlp_fc4_type isn't required.
  1617. */
  1618. ndlp->nlp_DID = keepDID;
  1619. lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
  1620. if (phba->sli_rev == LPFC_SLI_REV4 &&
  1621. active_rrqs_xri_bitmap)
  1622. memcpy(ndlp->active_rrqs_xri_bitmap,
  1623. active_rrqs_xri_bitmap,
  1624. phba->cfg_rrq_xri_bitmap_sz);
  1625. if (!NLP_CHK_NODE_ACT(ndlp))
  1626. lpfc_drop_node(vport, ndlp);
  1627. }
  1628. else {
  1629. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1630. "3180 PLOGI confirm SWAP: %x %x\n",
  1631. new_ndlp->nlp_DID, keepDID);
  1632. lpfc_unreg_rpi(vport, ndlp);
  1633. /* Two ndlps cannot have the same did and the fc4
  1634. * type must be transferred because the ndlp is in
  1635. * flight.
  1636. */
  1637. ndlp->nlp_DID = keepDID;
  1638. ndlp->nlp_fc4_type = keep_nlp_fc4_type;
  1639. if (phba->sli_rev == LPFC_SLI_REV4 &&
  1640. active_rrqs_xri_bitmap)
  1641. memcpy(ndlp->active_rrqs_xri_bitmap,
  1642. active_rrqs_xri_bitmap,
  1643. phba->cfg_rrq_xri_bitmap_sz);
  1644. /* Since we are switching over to the new_ndlp,
  1645. * reset the old ndlp state
  1646. */
  1647. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  1648. (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
  1649. keep_nlp_state = NLP_STE_NPR_NODE;
  1650. lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
  1651. /* Previous ndlp no longer active with nvme host transport.
  1652. * Remove reference from earlier registration unless the
  1653. * nvme host took care of it.
  1654. */
  1655. if (ndlp->nrport)
  1656. lpfc_nlp_put(ndlp);
  1657. ndlp->nrport = keep_nrport;
  1658. /* Fix up the rport accordingly */
  1659. rport = ndlp->rport;
  1660. if (rport) {
  1661. rdata = rport->dd_data;
  1662. put_node = rdata->pnode != NULL;
  1663. put_rport = ndlp->rport != NULL;
  1664. rdata->pnode = NULL;
  1665. ndlp->rport = NULL;
  1666. if (put_node)
  1667. lpfc_nlp_put(ndlp);
  1668. if (put_rport)
  1669. put_device(&rport->dev);
  1670. }
  1671. }
  1672. if (phba->sli_rev == LPFC_SLI_REV4 &&
  1673. active_rrqs_xri_bitmap)
  1674. mempool_free(active_rrqs_xri_bitmap,
  1675. phba->active_rrq_pool);
  1676. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
  1677. "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
  1678. new_ndlp->nlp_DID, new_ndlp->nlp_flag,
  1679. new_ndlp->nlp_fc4_type);
  1680. return new_ndlp;
  1681. }
  1682. /**
  1683. * lpfc_end_rscn - Check and handle more rscn for a vport
  1684. * @vport: pointer to a host virtual N_Port data structure.
  1685. *
  1686. * This routine checks whether more Registration State Change
  1687. * Notifications (RSCNs) came in while the discovery state machine was in
  1688. * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
  1689. * invoked to handle the additional RSCNs for the @vport. Otherwise, the
  1690. * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
  1691. * handling the RSCNs.
  1692. **/
  1693. void
  1694. lpfc_end_rscn(struct lpfc_vport *vport)
  1695. {
  1696. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1697. if (vport->fc_flag & FC_RSCN_MODE) {
  1698. /*
  1699. * Check to see if more RSCNs came in while we were
  1700. * processing this one.
  1701. */
  1702. if (vport->fc_rscn_id_cnt ||
  1703. (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
  1704. lpfc_els_handle_rscn(vport);
  1705. else {
  1706. spin_lock_irq(shost->host_lock);
  1707. vport->fc_flag &= ~FC_RSCN_MODE;
  1708. spin_unlock_irq(shost->host_lock);
  1709. }
  1710. }
  1711. }
  1712. /**
  1713. * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
  1714. * @phba: pointer to lpfc hba data structure.
  1715. * @cmdiocb: pointer to lpfc command iocb data structure.
  1716. * @rspiocb: pointer to lpfc response iocb data structure.
  1717. *
  1718. * This routine will call the clear rrq function to free the rrq and
  1719. * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
  1720. * exist then the clear_rrq is still called because the rrq needs to
  1721. * be freed.
  1722. **/
  1723. static void
  1724. lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1725. struct lpfc_iocbq *rspiocb)
  1726. {
  1727. struct lpfc_vport *vport = cmdiocb->vport;
  1728. IOCB_t *irsp;
  1729. struct lpfc_nodelist *ndlp;
  1730. struct lpfc_node_rrq *rrq;
  1731. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1732. rrq = cmdiocb->context_un.rrq;
  1733. cmdiocb->context_un.rsp_iocb = rspiocb;
  1734. irsp = &rspiocb->iocb;
  1735. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1736. "RRQ cmpl: status:x%x/x%x did:x%x",
  1737. irsp->ulpStatus, irsp->un.ulpWord[4],
  1738. irsp->un.elsreq64.remoteID);
  1739. ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
  1740. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
  1741. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1742. "2882 RRQ completes to NPort x%x "
  1743. "with no ndlp. Data: x%x x%x x%x\n",
  1744. irsp->un.elsreq64.remoteID,
  1745. irsp->ulpStatus, irsp->un.ulpWord[4],
  1746. irsp->ulpIoTag);
  1747. goto out;
  1748. }
  1749. /* rrq completes to NPort <nlp_DID> */
  1750. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1751. "2880 RRQ completes to NPort x%x "
  1752. "Data: x%x x%x x%x x%x x%x\n",
  1753. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1754. irsp->ulpTimeout, rrq->xritag, rrq->rxid);
  1755. if (irsp->ulpStatus) {
  1756. /* Check for retry */
  1757. /* RRQ failed Don't print the vport to vport rjts */
  1758. if (irsp->ulpStatus != IOSTAT_LS_RJT ||
  1759. (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
  1760. ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
  1761. (phba)->pport->cfg_log_verbose & LOG_ELS)
  1762. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1763. "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
  1764. ndlp->nlp_DID, irsp->ulpStatus,
  1765. irsp->un.ulpWord[4]);
  1766. }
  1767. out:
  1768. if (rrq)
  1769. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  1770. lpfc_els_free_iocb(phba, cmdiocb);
  1771. return;
  1772. }
  1773. /**
  1774. * lpfc_cmpl_els_plogi - Completion callback function for plogi
  1775. * @phba: pointer to lpfc hba data structure.
  1776. * @cmdiocb: pointer to lpfc command iocb data structure.
  1777. * @rspiocb: pointer to lpfc response iocb data structure.
  1778. *
  1779. * This routine is the completion callback function for issuing the Port
  1780. * Login (PLOGI) command. For PLOGI completion, there must be an active
  1781. * ndlp on the vport node list that matches the remote node ID from the
  1782. * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
  1783. * ignored and command IOCB released. The PLOGI response IOCB status is
  1784. * checked for error conditons. If there is error status reported, PLOGI
  1785. * retry shall be attempted by invoking the lpfc_els_retry() routine.
  1786. * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
  1787. * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
  1788. * (DSM) is set for this PLOGI completion. Finally, it checks whether
  1789. * there are additional N_Port nodes with the vport that need to perform
  1790. * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
  1791. * PLOGIs.
  1792. **/
  1793. static void
  1794. lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1795. struct lpfc_iocbq *rspiocb)
  1796. {
  1797. struct lpfc_vport *vport = cmdiocb->vport;
  1798. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1799. IOCB_t *irsp;
  1800. struct lpfc_nodelist *ndlp;
  1801. struct lpfc_dmabuf *prsp;
  1802. int disc;
  1803. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1804. cmdiocb->context_un.rsp_iocb = rspiocb;
  1805. irsp = &rspiocb->iocb;
  1806. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1807. "PLOGI cmpl: status:x%x/x%x did:x%x",
  1808. irsp->ulpStatus, irsp->un.ulpWord[4],
  1809. irsp->un.elsreq64.remoteID);
  1810. ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
  1811. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  1812. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1813. "0136 PLOGI completes to NPort x%x "
  1814. "with no ndlp. Data: x%x x%x x%x\n",
  1815. irsp->un.elsreq64.remoteID,
  1816. irsp->ulpStatus, irsp->un.ulpWord[4],
  1817. irsp->ulpIoTag);
  1818. goto out;
  1819. }
  1820. /* Since ndlp can be freed in the disc state machine, note if this node
  1821. * is being used during discovery.
  1822. */
  1823. spin_lock_irq(shost->host_lock);
  1824. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  1825. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1826. spin_unlock_irq(shost->host_lock);
  1827. /* PLOGI completes to NPort <nlp_DID> */
  1828. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1829. "0102 PLOGI completes to NPort x%06x "
  1830. "Data: x%x x%x x%x x%x x%x\n",
  1831. ndlp->nlp_DID, ndlp->nlp_fc4_type,
  1832. irsp->ulpStatus, irsp->un.ulpWord[4],
  1833. disc, vport->num_disc_nodes);
  1834. /* Check to see if link went down during discovery */
  1835. if (lpfc_els_chk_latt(vport)) {
  1836. spin_lock_irq(shost->host_lock);
  1837. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1838. spin_unlock_irq(shost->host_lock);
  1839. goto out;
  1840. }
  1841. if (irsp->ulpStatus) {
  1842. /* Check for retry */
  1843. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1844. /* ELS command is being retried */
  1845. if (disc) {
  1846. spin_lock_irq(shost->host_lock);
  1847. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1848. spin_unlock_irq(shost->host_lock);
  1849. }
  1850. goto out;
  1851. }
  1852. /* PLOGI failed Don't print the vport to vport rjts */
  1853. if (irsp->ulpStatus != IOSTAT_LS_RJT ||
  1854. (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
  1855. ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
  1856. (phba)->pport->cfg_log_verbose & LOG_ELS)
  1857. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1858. "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
  1859. ndlp->nlp_DID, irsp->ulpStatus,
  1860. irsp->un.ulpWord[4]);
  1861. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1862. if (!lpfc_error_lost_link(irsp))
  1863. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1864. NLP_EVT_CMPL_PLOGI);
  1865. } else {
  1866. /* Good status, call state machine */
  1867. prsp = list_entry(((struct lpfc_dmabuf *)
  1868. cmdiocb->context2)->list.next,
  1869. struct lpfc_dmabuf, list);
  1870. ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
  1871. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1872. NLP_EVT_CMPL_PLOGI);
  1873. }
  1874. if (disc && vport->num_disc_nodes) {
  1875. /* Check to see if there are more PLOGIs to be sent */
  1876. lpfc_more_plogi(vport);
  1877. if (vport->num_disc_nodes == 0) {
  1878. spin_lock_irq(shost->host_lock);
  1879. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1880. spin_unlock_irq(shost->host_lock);
  1881. lpfc_can_disctmo(vport);
  1882. lpfc_end_rscn(vport);
  1883. }
  1884. }
  1885. out:
  1886. lpfc_els_free_iocb(phba, cmdiocb);
  1887. return;
  1888. }
  1889. /**
  1890. * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
  1891. * @vport: pointer to a host virtual N_Port data structure.
  1892. * @did: destination port identifier.
  1893. * @retry: number of retries to the command IOCB.
  1894. *
  1895. * This routine issues a Port Login (PLOGI) command to a remote N_Port
  1896. * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
  1897. * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
  1898. * This routine constructs the proper feilds of the PLOGI IOCB and invokes
  1899. * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
  1900. *
  1901. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1902. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1903. * will be stored into the context1 field of the IOCB for the completion
  1904. * callback function to the PLOGI ELS command.
  1905. *
  1906. * Return code
  1907. * 0 - Successfully issued a plogi for @vport
  1908. * 1 - failed to issue a plogi for @vport
  1909. **/
  1910. int
  1911. lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
  1912. {
  1913. struct lpfc_hba *phba = vport->phba;
  1914. struct Scsi_Host *shost;
  1915. struct serv_parm *sp;
  1916. struct lpfc_nodelist *ndlp;
  1917. struct lpfc_iocbq *elsiocb;
  1918. uint8_t *pcmd;
  1919. uint16_t cmdsize;
  1920. int ret;
  1921. ndlp = lpfc_findnode_did(vport, did);
  1922. if (ndlp) {
  1923. /* Defer the processing of the issue PLOGI until after the
  1924. * outstanding UNREG_RPI mbox command completes, unless we
  1925. * are going offline. This logic does not apply for Fabric DIDs
  1926. */
  1927. if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
  1928. ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
  1929. !(vport->fc_flag & FC_OFFLINE_MODE)) {
  1930. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1931. "4110 Issue PLOGI x%x deferred "
  1932. "on NPort x%x rpi x%x Data: x%px\n",
  1933. ndlp->nlp_defer_did, ndlp->nlp_DID,
  1934. ndlp->nlp_rpi, ndlp);
  1935. /* We can only defer 1st PLOGI */
  1936. if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
  1937. ndlp->nlp_defer_did = did;
  1938. return 0;
  1939. }
  1940. if (!NLP_CHK_NODE_ACT(ndlp))
  1941. ndlp = NULL;
  1942. }
  1943. /* If ndlp is not NULL, we will bump the reference count on it */
  1944. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  1945. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  1946. ELS_CMD_PLOGI);
  1947. if (!elsiocb)
  1948. return 1;
  1949. shost = lpfc_shost_from_vport(vport);
  1950. spin_lock_irq(shost->host_lock);
  1951. ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
  1952. spin_unlock_irq(shost->host_lock);
  1953. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1954. /* For PLOGI request, remainder of payload is service parameters */
  1955. *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
  1956. pcmd += sizeof(uint32_t);
  1957. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  1958. sp = (struct serv_parm *) pcmd;
  1959. /*
  1960. * If we are a N-port connected to a Fabric, fix-up paramm's so logins
  1961. * to device on remote loops work.
  1962. */
  1963. if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
  1964. sp->cmn.altBbCredit = 1;
  1965. if (sp->cmn.fcphLow < FC_PH_4_3)
  1966. sp->cmn.fcphLow = FC_PH_4_3;
  1967. if (sp->cmn.fcphHigh < FC_PH3)
  1968. sp->cmn.fcphHigh = FC_PH3;
  1969. sp->cmn.valid_vendor_ver_level = 0;
  1970. memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
  1971. sp->cmn.bbRcvSizeMsb &= 0xF;
  1972. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1973. "Issue PLOGI: did:x%x",
  1974. did, 0, 0);
  1975. /* If our firmware supports this feature, convey that
  1976. * information to the target using the vendor specific field.
  1977. */
  1978. if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
  1979. sp->cmn.valid_vendor_ver_level = 1;
  1980. sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
  1981. sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
  1982. }
  1983. phba->fc_stat.elsXmitPLOGI++;
  1984. elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
  1985. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  1986. if (ret == IOCB_ERROR) {
  1987. lpfc_els_free_iocb(phba, elsiocb);
  1988. return 1;
  1989. }
  1990. return 0;
  1991. }
  1992. /**
  1993. * lpfc_cmpl_els_prli - Completion callback function for prli
  1994. * @phba: pointer to lpfc hba data structure.
  1995. * @cmdiocb: pointer to lpfc command iocb data structure.
  1996. * @rspiocb: pointer to lpfc response iocb data structure.
  1997. *
  1998. * This routine is the completion callback function for a Process Login
  1999. * (PRLI) ELS command. The PRLI response IOCB status is checked for error
  2000. * status. If there is error status reported, PRLI retry shall be attempted
  2001. * by invoking the lpfc_els_retry() routine. Otherwise, the state
  2002. * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
  2003. * ndlp to mark the PRLI completion.
  2004. **/
  2005. static void
  2006. lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2007. struct lpfc_iocbq *rspiocb)
  2008. {
  2009. struct lpfc_vport *vport = cmdiocb->vport;
  2010. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2011. IOCB_t *irsp;
  2012. struct lpfc_nodelist *ndlp;
  2013. char *mode;
  2014. /* we pass cmdiocb to state machine which needs rspiocb as well */
  2015. cmdiocb->context_un.rsp_iocb = rspiocb;
  2016. irsp = &(rspiocb->iocb);
  2017. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2018. spin_lock_irq(shost->host_lock);
  2019. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  2020. /* Driver supports multiple FC4 types. Counters matter. */
  2021. vport->fc_prli_sent--;
  2022. ndlp->fc4_prli_sent--;
  2023. spin_unlock_irq(shost->host_lock);
  2024. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2025. "PRLI cmpl: status:x%x/x%x did:x%x",
  2026. irsp->ulpStatus, irsp->un.ulpWord[4],
  2027. ndlp->nlp_DID);
  2028. /* PRLI completes to NPort <nlp_DID> */
  2029. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2030. "0103 PRLI completes to NPort x%06x "
  2031. "Data: x%x x%x x%x x%x\n",
  2032. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  2033. vport->num_disc_nodes, ndlp->fc4_prli_sent);
  2034. /* Check to see if link went down during discovery */
  2035. if (lpfc_els_chk_latt(vport))
  2036. goto out;
  2037. if (irsp->ulpStatus) {
  2038. /* Check for retry */
  2039. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  2040. /* ELS command is being retried */
  2041. goto out;
  2042. }
  2043. /* If we don't send GFT_ID to Fabric, a PRLI error
  2044. * could be expected.
  2045. */
  2046. if ((vport->fc_flag & FC_FABRIC) ||
  2047. (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH))
  2048. mode = KERN_ERR;
  2049. else
  2050. mode = KERN_INFO;
  2051. /* PRLI failed */
  2052. lpfc_printf_vlog(vport, mode, LOG_ELS,
  2053. "2754 PRLI failure DID:%06X Status:x%x/x%x, "
  2054. "data: x%x\n",
  2055. ndlp->nlp_DID, irsp->ulpStatus,
  2056. irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
  2057. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  2058. if (lpfc_error_lost_link(irsp))
  2059. goto out;
  2060. else
  2061. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2062. NLP_EVT_CMPL_PRLI);
  2063. } else {
  2064. /* Good status, call state machine. However, if another
  2065. * PRLI is outstanding, don't call the state machine
  2066. * because final disposition to Mapped or Unmapped is
  2067. * completed there.
  2068. */
  2069. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2070. NLP_EVT_CMPL_PRLI);
  2071. }
  2072. out:
  2073. lpfc_els_free_iocb(phba, cmdiocb);
  2074. return;
  2075. }
  2076. /**
  2077. * lpfc_issue_els_prli - Issue a prli iocb command for a vport
  2078. * @vport: pointer to a host virtual N_Port data structure.
  2079. * @ndlp: pointer to a node-list data structure.
  2080. * @retry: number of retries to the command IOCB.
  2081. *
  2082. * This routine issues a Process Login (PRLI) ELS command for the
  2083. * @vport. The PRLI service parameters are set up in the payload of the
  2084. * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
  2085. * is put to the IOCB completion callback func field before invoking the
  2086. * routine lpfc_sli_issue_iocb() to send out PRLI command.
  2087. *
  2088. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2089. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2090. * will be stored into the context1 field of the IOCB for the completion
  2091. * callback function to the PRLI ELS command.
  2092. *
  2093. * Return code
  2094. * 0 - successfully issued prli iocb command for @vport
  2095. * 1 - failed to issue prli iocb command for @vport
  2096. **/
  2097. int
  2098. lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2099. uint8_t retry)
  2100. {
  2101. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2102. struct lpfc_hba *phba = vport->phba;
  2103. PRLI *npr;
  2104. struct lpfc_nvme_prli *npr_nvme;
  2105. struct lpfc_iocbq *elsiocb;
  2106. uint8_t *pcmd;
  2107. uint16_t cmdsize;
  2108. u32 local_nlp_type, elscmd;
  2109. /*
  2110. * If we are in RSCN mode, the FC4 types supported from a
  2111. * previous GFT_ID command may not be accurate. So, if we
  2112. * are a NVME Initiator, always look for the possibility of
  2113. * the remote NPort beng a NVME Target.
  2114. */
  2115. if (phba->sli_rev == LPFC_SLI_REV4 &&
  2116. vport->fc_flag & FC_RSCN_MODE &&
  2117. vport->nvmei_support)
  2118. ndlp->nlp_fc4_type |= NLP_FC4_NVME;
  2119. local_nlp_type = ndlp->nlp_fc4_type;
  2120. /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
  2121. * fields here before any of them can complete.
  2122. */
  2123. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  2124. ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
  2125. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  2126. ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
  2127. ndlp->nvme_fb_size = 0;
  2128. send_next_prli:
  2129. if (local_nlp_type & NLP_FC4_FCP) {
  2130. /* Payload is 4 + 16 = 20 x14 bytes. */
  2131. cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
  2132. elscmd = ELS_CMD_PRLI;
  2133. } else if (local_nlp_type & NLP_FC4_NVME) {
  2134. /* Payload is 4 + 20 = 24 x18 bytes. */
  2135. cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
  2136. elscmd = ELS_CMD_NVMEPRLI;
  2137. } else {
  2138. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2139. "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
  2140. ndlp->nlp_fc4_type, ndlp->nlp_DID);
  2141. return 1;
  2142. }
  2143. /* SLI3 ports don't support NVME. If this rport is a strict NVME
  2144. * FC4 type, implicitly LOGO.
  2145. */
  2146. if (phba->sli_rev == LPFC_SLI_REV3 &&
  2147. ndlp->nlp_fc4_type == NLP_FC4_NVME) {
  2148. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2149. "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
  2150. ndlp->nlp_type);
  2151. lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
  2152. return 1;
  2153. }
  2154. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2155. ndlp->nlp_DID, elscmd);
  2156. if (!elsiocb)
  2157. return 1;
  2158. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2159. /* For PRLI request, remainder of payload is service parameters */
  2160. memset(pcmd, 0, cmdsize);
  2161. if (local_nlp_type & NLP_FC4_FCP) {
  2162. /* Remainder of payload is FCP PRLI parameter page.
  2163. * Note: this data structure is defined as
  2164. * BE/LE in the structure definition so no
  2165. * byte swap call is made.
  2166. */
  2167. *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
  2168. pcmd += sizeof(uint32_t);
  2169. npr = (PRLI *)pcmd;
  2170. /*
  2171. * If our firmware version is 3.20 or later,
  2172. * set the following bits for FC-TAPE support.
  2173. */
  2174. if (phba->vpd.rev.feaLevelHigh >= 0x02) {
  2175. npr->ConfmComplAllowed = 1;
  2176. npr->Retry = 1;
  2177. npr->TaskRetryIdReq = 1;
  2178. }
  2179. npr->estabImagePair = 1;
  2180. npr->readXferRdyDis = 1;
  2181. if (vport->cfg_first_burst_size)
  2182. npr->writeXferRdyDis = 1;
  2183. /* For FCP support */
  2184. npr->prliType = PRLI_FCP_TYPE;
  2185. npr->initiatorFunc = 1;
  2186. elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
  2187. /* Remove FCP type - processed. */
  2188. local_nlp_type &= ~NLP_FC4_FCP;
  2189. } else if (local_nlp_type & NLP_FC4_NVME) {
  2190. /* Remainder of payload is NVME PRLI parameter page.
  2191. * This data structure is the newer definition that
  2192. * uses bf macros so a byte swap is required.
  2193. */
  2194. *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
  2195. pcmd += sizeof(uint32_t);
  2196. npr_nvme = (struct lpfc_nvme_prli *)pcmd;
  2197. bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
  2198. bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
  2199. if (phba->nsler) {
  2200. bf_set(prli_nsler, npr_nvme, 1);
  2201. bf_set(prli_conf, npr_nvme, 1);
  2202. }
  2203. /* Only initiators request first burst. */
  2204. if ((phba->cfg_nvme_enable_fb) &&
  2205. !phba->nvmet_support)
  2206. bf_set(prli_fba, npr_nvme, 1);
  2207. if (phba->nvmet_support) {
  2208. bf_set(prli_tgt, npr_nvme, 1);
  2209. bf_set(prli_disc, npr_nvme, 1);
  2210. } else {
  2211. bf_set(prli_init, npr_nvme, 1);
  2212. bf_set(prli_conf, npr_nvme, 1);
  2213. }
  2214. npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
  2215. npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
  2216. elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
  2217. /* Remove NVME type - processed. */
  2218. local_nlp_type &= ~NLP_FC4_NVME;
  2219. }
  2220. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2221. "Issue PRLI: did:x%x",
  2222. ndlp->nlp_DID, 0, 0);
  2223. phba->fc_stat.elsXmitPRLI++;
  2224. elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
  2225. spin_lock_irq(shost->host_lock);
  2226. ndlp->nlp_flag |= NLP_PRLI_SND;
  2227. /* The vport counters are used for lpfc_scan_finished, but
  2228. * the ndlp is used to track outstanding PRLIs for different
  2229. * FC4 types.
  2230. */
  2231. vport->fc_prli_sent++;
  2232. ndlp->fc4_prli_sent++;
  2233. spin_unlock_irq(shost->host_lock);
  2234. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  2235. IOCB_ERROR) {
  2236. spin_lock_irq(shost->host_lock);
  2237. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  2238. spin_unlock_irq(shost->host_lock);
  2239. lpfc_els_free_iocb(phba, elsiocb);
  2240. return 1;
  2241. }
  2242. /* The driver supports 2 FC4 types. Make sure
  2243. * a PRLI is issued for all types before exiting.
  2244. */
  2245. if (phba->sli_rev == LPFC_SLI_REV4 &&
  2246. local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
  2247. goto send_next_prli;
  2248. return 0;
  2249. }
  2250. /**
  2251. * lpfc_rscn_disc - Perform rscn discovery for a vport
  2252. * @vport: pointer to a host virtual N_Port data structure.
  2253. *
  2254. * This routine performs Registration State Change Notification (RSCN)
  2255. * discovery for a @vport. If the @vport's node port recovery count is not
  2256. * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
  2257. * the nodes that need recovery. If none of the PLOGI were needed through
  2258. * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
  2259. * invoked to check and handle possible more RSCN came in during the period
  2260. * of processing the current ones.
  2261. **/
  2262. static void
  2263. lpfc_rscn_disc(struct lpfc_vport *vport)
  2264. {
  2265. lpfc_can_disctmo(vport);
  2266. /* RSCN discovery */
  2267. /* go thru NPR nodes and issue ELS PLOGIs */
  2268. if (vport->fc_npr_cnt)
  2269. if (lpfc_els_disc_plogi(vport))
  2270. return;
  2271. lpfc_end_rscn(vport);
  2272. }
  2273. /**
  2274. * lpfc_adisc_done - Complete the adisc phase of discovery
  2275. * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
  2276. *
  2277. * This function is called when the final ADISC is completed during discovery.
  2278. * This function handles clearing link attention or issuing reg_vpi depending
  2279. * on whether npiv is enabled. This function also kicks off the PLOGI phase of
  2280. * discovery.
  2281. * This function is called with no locks held.
  2282. **/
  2283. static void
  2284. lpfc_adisc_done(struct lpfc_vport *vport)
  2285. {
  2286. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2287. struct lpfc_hba *phba = vport->phba;
  2288. /*
  2289. * For NPIV, cmpl_reg_vpi will set port_state to READY,
  2290. * and continue discovery.
  2291. */
  2292. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2293. !(vport->fc_flag & FC_RSCN_MODE) &&
  2294. (phba->sli_rev < LPFC_SLI_REV4)) {
  2295. /* The ADISCs are complete. Doesn't matter if they
  2296. * succeeded or failed because the ADISC completion
  2297. * routine guarantees to call the state machine and
  2298. * the RPI is either unregistered (failed ADISC response)
  2299. * or the RPI is still valid and the node is marked
  2300. * mapped for a target. The exchanges should be in the
  2301. * correct state. This code is specific to SLI3.
  2302. */
  2303. lpfc_issue_clear_la(phba, vport);
  2304. lpfc_issue_reg_vpi(phba, vport);
  2305. return;
  2306. }
  2307. /*
  2308. * For SLI2, we need to set port_state to READY
  2309. * and continue discovery.
  2310. */
  2311. if (vport->port_state < LPFC_VPORT_READY) {
  2312. /* If we get here, there is nothing to ADISC */
  2313. lpfc_issue_clear_la(phba, vport);
  2314. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  2315. vport->num_disc_nodes = 0;
  2316. /* go thru NPR list, issue ELS PLOGIs */
  2317. if (vport->fc_npr_cnt)
  2318. lpfc_els_disc_plogi(vport);
  2319. if (!vport->num_disc_nodes) {
  2320. spin_lock_irq(shost->host_lock);
  2321. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  2322. spin_unlock_irq(shost->host_lock);
  2323. lpfc_can_disctmo(vport);
  2324. lpfc_end_rscn(vport);
  2325. }
  2326. }
  2327. vport->port_state = LPFC_VPORT_READY;
  2328. } else
  2329. lpfc_rscn_disc(vport);
  2330. }
  2331. /**
  2332. * lpfc_more_adisc - Issue more adisc as needed
  2333. * @vport: pointer to a host virtual N_Port data structure.
  2334. *
  2335. * This routine determines whether there are more ndlps on a @vport
  2336. * node list need to have Address Discover (ADISC) issued. If so, it will
  2337. * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
  2338. * remaining nodes which need to have ADISC sent.
  2339. **/
  2340. void
  2341. lpfc_more_adisc(struct lpfc_vport *vport)
  2342. {
  2343. if (vport->num_disc_nodes)
  2344. vport->num_disc_nodes--;
  2345. /* Continue discovery with <num_disc_nodes> ADISCs to go */
  2346. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2347. "0210 Continue discovery with %d ADISCs to go "
  2348. "Data: x%x x%x x%x\n",
  2349. vport->num_disc_nodes, vport->fc_adisc_cnt,
  2350. vport->fc_flag, vport->port_state);
  2351. /* Check to see if there are more ADISCs to be sent */
  2352. if (vport->fc_flag & FC_NLP_MORE) {
  2353. lpfc_set_disctmo(vport);
  2354. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  2355. lpfc_els_disc_adisc(vport);
  2356. }
  2357. if (!vport->num_disc_nodes)
  2358. lpfc_adisc_done(vport);
  2359. return;
  2360. }
  2361. /**
  2362. * lpfc_cmpl_els_adisc - Completion callback function for adisc
  2363. * @phba: pointer to lpfc hba data structure.
  2364. * @cmdiocb: pointer to lpfc command iocb data structure.
  2365. * @rspiocb: pointer to lpfc response iocb data structure.
  2366. *
  2367. * This routine is the completion function for issuing the Address Discover
  2368. * (ADISC) command. It first checks to see whether link went down during
  2369. * the discovery process. If so, the node will be marked as node port
  2370. * recovery for issuing discover IOCB by the link attention handler and
  2371. * exit. Otherwise, the response status is checked. If error was reported
  2372. * in the response status, the ADISC command shall be retried by invoking
  2373. * the lpfc_els_retry() routine. Otherwise, if no error was reported in
  2374. * the response status, the state machine is invoked to set transition
  2375. * with respect to NLP_EVT_CMPL_ADISC event.
  2376. **/
  2377. static void
  2378. lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2379. struct lpfc_iocbq *rspiocb)
  2380. {
  2381. struct lpfc_vport *vport = cmdiocb->vport;
  2382. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2383. IOCB_t *irsp;
  2384. struct lpfc_nodelist *ndlp;
  2385. int disc;
  2386. /* we pass cmdiocb to state machine which needs rspiocb as well */
  2387. cmdiocb->context_un.rsp_iocb = rspiocb;
  2388. irsp = &(rspiocb->iocb);
  2389. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2390. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2391. "ADISC cmpl: status:x%x/x%x did:x%x",
  2392. irsp->ulpStatus, irsp->un.ulpWord[4],
  2393. ndlp->nlp_DID);
  2394. /* Since ndlp can be freed in the disc state machine, note if this node
  2395. * is being used during discovery.
  2396. */
  2397. spin_lock_irq(shost->host_lock);
  2398. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  2399. ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
  2400. spin_unlock_irq(shost->host_lock);
  2401. /* ADISC completes to NPort <nlp_DID> */
  2402. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2403. "0104 ADISC completes to NPort x%x "
  2404. "Data: x%x x%x x%x x%x x%x\n",
  2405. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  2406. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  2407. /* Check to see if link went down during discovery */
  2408. if (lpfc_els_chk_latt(vport)) {
  2409. spin_lock_irq(shost->host_lock);
  2410. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2411. spin_unlock_irq(shost->host_lock);
  2412. goto out;
  2413. }
  2414. if (irsp->ulpStatus) {
  2415. /* Check for retry */
  2416. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  2417. /* ELS command is being retried */
  2418. if (disc) {
  2419. spin_lock_irq(shost->host_lock);
  2420. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2421. spin_unlock_irq(shost->host_lock);
  2422. lpfc_set_disctmo(vport);
  2423. }
  2424. goto out;
  2425. }
  2426. /* ADISC failed */
  2427. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2428. "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
  2429. ndlp->nlp_DID, irsp->ulpStatus,
  2430. irsp->un.ulpWord[4]);
  2431. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  2432. if (!lpfc_error_lost_link(irsp))
  2433. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2434. NLP_EVT_CMPL_ADISC);
  2435. } else
  2436. /* Good status, call state machine */
  2437. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2438. NLP_EVT_CMPL_ADISC);
  2439. /* Check to see if there are more ADISCs to be sent */
  2440. if (disc && vport->num_disc_nodes)
  2441. lpfc_more_adisc(vport);
  2442. out:
  2443. lpfc_els_free_iocb(phba, cmdiocb);
  2444. return;
  2445. }
  2446. /**
  2447. * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
  2448. * @vport: pointer to a virtual N_Port data structure.
  2449. * @ndlp: pointer to a node-list data structure.
  2450. * @retry: number of retries to the command IOCB.
  2451. *
  2452. * This routine issues an Address Discover (ADISC) for an @ndlp on a
  2453. * @vport. It prepares the payload of the ADISC ELS command, updates the
  2454. * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
  2455. * to issue the ADISC ELS command.
  2456. *
  2457. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2458. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2459. * will be stored into the context1 field of the IOCB for the completion
  2460. * callback function to the ADISC ELS command.
  2461. *
  2462. * Return code
  2463. * 0 - successfully issued adisc
  2464. * 1 - failed to issue adisc
  2465. **/
  2466. int
  2467. lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2468. uint8_t retry)
  2469. {
  2470. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2471. struct lpfc_hba *phba = vport->phba;
  2472. ADISC *ap;
  2473. struct lpfc_iocbq *elsiocb;
  2474. uint8_t *pcmd;
  2475. uint16_t cmdsize;
  2476. cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
  2477. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2478. ndlp->nlp_DID, ELS_CMD_ADISC);
  2479. if (!elsiocb)
  2480. return 1;
  2481. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2482. /* For ADISC request, remainder of payload is service parameters */
  2483. *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
  2484. pcmd += sizeof(uint32_t);
  2485. /* Fill in ADISC payload */
  2486. ap = (ADISC *) pcmd;
  2487. ap->hardAL_PA = phba->fc_pref_ALPA;
  2488. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2489. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2490. ap->DID = be32_to_cpu(vport->fc_myDID);
  2491. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2492. "Issue ADISC: did:x%x",
  2493. ndlp->nlp_DID, 0, 0);
  2494. phba->fc_stat.elsXmitADISC++;
  2495. elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
  2496. spin_lock_irq(shost->host_lock);
  2497. ndlp->nlp_flag |= NLP_ADISC_SND;
  2498. spin_unlock_irq(shost->host_lock);
  2499. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  2500. IOCB_ERROR) {
  2501. spin_lock_irq(shost->host_lock);
  2502. ndlp->nlp_flag &= ~NLP_ADISC_SND;
  2503. spin_unlock_irq(shost->host_lock);
  2504. lpfc_els_free_iocb(phba, elsiocb);
  2505. return 1;
  2506. }
  2507. return 0;
  2508. }
  2509. /**
  2510. * lpfc_cmpl_els_logo - Completion callback function for logo
  2511. * @phba: pointer to lpfc hba data structure.
  2512. * @cmdiocb: pointer to lpfc command iocb data structure.
  2513. * @rspiocb: pointer to lpfc response iocb data structure.
  2514. *
  2515. * This routine is the completion function for issuing the ELS Logout (LOGO)
  2516. * command. If no error status was reported from the LOGO response, the
  2517. * state machine of the associated ndlp shall be invoked for transition with
  2518. * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
  2519. * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
  2520. **/
  2521. static void
  2522. lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2523. struct lpfc_iocbq *rspiocb)
  2524. {
  2525. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2526. struct lpfc_vport *vport = ndlp->vport;
  2527. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2528. IOCB_t *irsp;
  2529. struct lpfcMboxq *mbox;
  2530. unsigned long flags;
  2531. uint32_t skip_recovery = 0;
  2532. /* we pass cmdiocb to state machine which needs rspiocb as well */
  2533. cmdiocb->context_un.rsp_iocb = rspiocb;
  2534. irsp = &(rspiocb->iocb);
  2535. spin_lock_irq(shost->host_lock);
  2536. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  2537. spin_unlock_irq(shost->host_lock);
  2538. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2539. "LOGO cmpl: status:x%x/x%x did:x%x",
  2540. irsp->ulpStatus, irsp->un.ulpWord[4],
  2541. ndlp->nlp_DID);
  2542. /* LOGO completes to NPort <nlp_DID> */
  2543. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2544. "0105 LOGO completes to NPort x%x "
  2545. "Data: x%x x%x x%x x%x\n",
  2546. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  2547. irsp->ulpTimeout, vport->num_disc_nodes);
  2548. if (lpfc_els_chk_latt(vport)) {
  2549. skip_recovery = 1;
  2550. goto out;
  2551. }
  2552. /* Check to see if link went down during discovery */
  2553. if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
  2554. /* NLP_EVT_DEVICE_RM should unregister the RPI
  2555. * which should abort all outstanding IOs.
  2556. */
  2557. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2558. NLP_EVT_DEVICE_RM);
  2559. skip_recovery = 1;
  2560. goto out;
  2561. }
  2562. /* The LOGO will not be retried on failure. A LOGO was
  2563. * issued to the remote rport and a ACC or RJT or no Answer are
  2564. * all acceptable. Note the failure and move forward with
  2565. * discovery. The PLOGI will retry.
  2566. */
  2567. if (irsp->ulpStatus) {
  2568. /* LOGO failed */
  2569. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2570. "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
  2571. ndlp->nlp_DID, irsp->ulpStatus,
  2572. irsp->un.ulpWord[4]);
  2573. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  2574. if (lpfc_error_lost_link(irsp)) {
  2575. skip_recovery = 1;
  2576. goto out;
  2577. }
  2578. }
  2579. /* Call state machine. This will unregister the rpi if needed. */
  2580. lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
  2581. out:
  2582. lpfc_els_free_iocb(phba, cmdiocb);
  2583. /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
  2584. if ((vport->fc_flag & FC_PT2PT) &&
  2585. !(vport->fc_flag & FC_PT2PT_PLOGI)) {
  2586. phba->pport->fc_myDID = 0;
  2587. if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
  2588. (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
  2589. if (phba->nvmet_support)
  2590. lpfc_nvmet_update_targetport(phba);
  2591. else
  2592. lpfc_nvme_update_localport(phba->pport);
  2593. }
  2594. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2595. if (mbox) {
  2596. lpfc_config_link(phba, mbox);
  2597. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2598. mbox->vport = vport;
  2599. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
  2600. MBX_NOT_FINISHED) {
  2601. mempool_free(mbox, phba->mbox_mem_pool);
  2602. skip_recovery = 1;
  2603. }
  2604. }
  2605. }
  2606. /*
  2607. * If the node is a target, the handling attempts to recover the port.
  2608. * For any other port type, the rpi is unregistered as an implicit
  2609. * LOGO.
  2610. */
  2611. if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
  2612. skip_recovery == 0) {
  2613. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2614. spin_lock_irqsave(shost->host_lock, flags);
  2615. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2616. spin_unlock_irqrestore(shost->host_lock, flags);
  2617. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2618. "3187 LOGO completes to NPort x%x: Start "
  2619. "Recovery Data: x%x x%x x%x x%x\n",
  2620. ndlp->nlp_DID, irsp->ulpStatus,
  2621. irsp->un.ulpWord[4], irsp->ulpTimeout,
  2622. vport->num_disc_nodes);
  2623. lpfc_disc_start(vport);
  2624. }
  2625. return;
  2626. }
  2627. /**
  2628. * lpfc_issue_els_logo - Issue a logo to an node on a vport
  2629. * @vport: pointer to a virtual N_Port data structure.
  2630. * @ndlp: pointer to a node-list data structure.
  2631. * @retry: number of retries to the command IOCB.
  2632. *
  2633. * This routine constructs and issues an ELS Logout (LOGO) iocb command
  2634. * to a remote node, referred by an @ndlp on a @vport. It constructs the
  2635. * payload of the IOCB, properly sets up the @ndlp state, and invokes the
  2636. * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
  2637. *
  2638. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2639. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2640. * will be stored into the context1 field of the IOCB for the completion
  2641. * callback function to the LOGO ELS command.
  2642. *
  2643. * Callers of this routine are expected to unregister the RPI first
  2644. *
  2645. * Return code
  2646. * 0 - successfully issued logo
  2647. * 1 - failed to issue logo
  2648. **/
  2649. int
  2650. lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2651. uint8_t retry)
  2652. {
  2653. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2654. struct lpfc_hba *phba = vport->phba;
  2655. struct lpfc_iocbq *elsiocb;
  2656. uint8_t *pcmd;
  2657. uint16_t cmdsize;
  2658. int rc;
  2659. spin_lock_irq(shost->host_lock);
  2660. if (ndlp->nlp_flag & NLP_LOGO_SND) {
  2661. spin_unlock_irq(shost->host_lock);
  2662. return 0;
  2663. }
  2664. spin_unlock_irq(shost->host_lock);
  2665. cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
  2666. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2667. ndlp->nlp_DID, ELS_CMD_LOGO);
  2668. if (!elsiocb)
  2669. return 1;
  2670. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2671. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  2672. pcmd += sizeof(uint32_t);
  2673. /* Fill in LOGO payload */
  2674. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  2675. pcmd += sizeof(uint32_t);
  2676. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  2677. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2678. "Issue LOGO: did:x%x",
  2679. ndlp->nlp_DID, 0, 0);
  2680. phba->fc_stat.elsXmitLOGO++;
  2681. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
  2682. spin_lock_irq(shost->host_lock);
  2683. ndlp->nlp_flag |= NLP_LOGO_SND;
  2684. ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
  2685. spin_unlock_irq(shost->host_lock);
  2686. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  2687. if (rc == IOCB_ERROR) {
  2688. spin_lock_irq(shost->host_lock);
  2689. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  2690. spin_unlock_irq(shost->host_lock);
  2691. lpfc_els_free_iocb(phba, elsiocb);
  2692. return 1;
  2693. }
  2694. spin_lock_irq(shost->host_lock);
  2695. ndlp->nlp_prev_state = ndlp->nlp_state;
  2696. spin_unlock_irq(shost->host_lock);
  2697. lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
  2698. return 0;
  2699. }
  2700. /**
  2701. * lpfc_cmpl_els_cmd - Completion callback function for generic els command
  2702. * @phba: pointer to lpfc hba data structure.
  2703. * @cmdiocb: pointer to lpfc command iocb data structure.
  2704. * @rspiocb: pointer to lpfc response iocb data structure.
  2705. *
  2706. * This routine is a generic completion callback function for ELS commands.
  2707. * Specifically, it is the callback function which does not need to perform
  2708. * any command specific operations. It is currently used by the ELS command
  2709. * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
  2710. * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
  2711. * Other than certain debug loggings, this callback function simply invokes the
  2712. * lpfc_els_chk_latt() routine to check whether link went down during the
  2713. * discovery process.
  2714. **/
  2715. static void
  2716. lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2717. struct lpfc_iocbq *rspiocb)
  2718. {
  2719. struct lpfc_vport *vport = cmdiocb->vport;
  2720. IOCB_t *irsp;
  2721. irsp = &rspiocb->iocb;
  2722. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2723. "ELS cmd cmpl: status:x%x/x%x did:x%x",
  2724. irsp->ulpStatus, irsp->un.ulpWord[4],
  2725. irsp->un.elsreq64.remoteID);
  2726. /* ELS cmd tag <ulpIoTag> completes */
  2727. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2728. "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
  2729. irsp->ulpIoTag, irsp->ulpStatus,
  2730. irsp->un.ulpWord[4], irsp->ulpTimeout);
  2731. /* Check to see if link went down during discovery */
  2732. lpfc_els_chk_latt(vport);
  2733. lpfc_els_free_iocb(phba, cmdiocb);
  2734. }
  2735. /**
  2736. * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
  2737. * @phba: pointer to lpfc hba data structure.
  2738. * @cmdiocb: pointer to lpfc command iocb data structure.
  2739. * @rspiocb: pointer to lpfc response iocb data structure.
  2740. *
  2741. * This routine is a generic completion callback function for Discovery ELS cmd.
  2742. * Currently used by the ELS command issuing routines for the ELS State Change
  2743. * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
  2744. * These commands will be retried once only for ELS timeout errors.
  2745. **/
  2746. static void
  2747. lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2748. struct lpfc_iocbq *rspiocb)
  2749. {
  2750. struct lpfc_vport *vport = cmdiocb->vport;
  2751. IOCB_t *irsp;
  2752. struct lpfc_els_rdf_rsp *prdf;
  2753. struct lpfc_dmabuf *pcmd, *prsp;
  2754. u32 *pdata;
  2755. u32 cmd;
  2756. irsp = &rspiocb->iocb;
  2757. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2758. "ELS cmd cmpl: status:x%x/x%x did:x%x",
  2759. irsp->ulpStatus, irsp->un.ulpWord[4],
  2760. irsp->un.elsreq64.remoteID);
  2761. /* ELS cmd tag <ulpIoTag> completes */
  2762. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2763. "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
  2764. "x%x\n",
  2765. irsp->ulpIoTag, irsp->ulpStatus,
  2766. irsp->un.ulpWord[4], irsp->ulpTimeout,
  2767. cmdiocb->retry);
  2768. pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
  2769. if (!pcmd)
  2770. goto out;
  2771. pdata = (u32 *)pcmd->virt;
  2772. if (!pdata)
  2773. goto out;
  2774. cmd = *pdata;
  2775. /* Only 1 retry for ELS Timeout only */
  2776. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
  2777. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2778. IOERR_SEQUENCE_TIMEOUT)) {
  2779. cmdiocb->retry++;
  2780. if (cmdiocb->retry <= 1) {
  2781. switch (cmd) {
  2782. case ELS_CMD_SCR:
  2783. lpfc_issue_els_scr(vport, cmdiocb->retry);
  2784. break;
  2785. case ELS_CMD_RDF:
  2786. cmdiocb->context1 = NULL; /* save ndlp refcnt */
  2787. lpfc_issue_els_rdf(vport, cmdiocb->retry);
  2788. break;
  2789. }
  2790. goto out;
  2791. }
  2792. phba->fc_stat.elsRetryExceeded++;
  2793. }
  2794. if (irsp->ulpStatus) {
  2795. /* ELS discovery cmd completes with error */
  2796. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  2797. "4203 ELS cmd x%x error: x%x x%X\n", cmd,
  2798. irsp->ulpStatus, irsp->un.ulpWord[4]);
  2799. goto out;
  2800. }
  2801. /* The RDF response doesn't have any impact on the running driver
  2802. * but the notification descriptors are dumped here for support.
  2803. */
  2804. if (cmd == ELS_CMD_RDF) {
  2805. int i;
  2806. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  2807. if (!prsp)
  2808. goto out;
  2809. prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
  2810. if (!prdf)
  2811. goto out;
  2812. for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
  2813. i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
  2814. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2815. "4677 Fabric RDF Notification Grant Data: "
  2816. "0x%08x\n",
  2817. be32_to_cpu(
  2818. prdf->reg_d1.desc_tags[i]));
  2819. }
  2820. out:
  2821. /* Check to see if link went down during discovery */
  2822. lpfc_els_chk_latt(vport);
  2823. lpfc_els_free_iocb(phba, cmdiocb);
  2824. return;
  2825. }
  2826. /**
  2827. * lpfc_issue_els_scr - Issue a scr to an node on a vport
  2828. * @vport: pointer to a host virtual N_Port data structure.
  2829. * @retry: retry counter for the command IOCB.
  2830. *
  2831. * This routine issues a State Change Request (SCR) to a fabric node
  2832. * on a @vport. The remote node is Fabric Controller (0xfffffd). It
  2833. * first search the @vport node list to find the matching ndlp. If no such
  2834. * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
  2835. * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
  2836. * routine is invoked to send the SCR IOCB.
  2837. *
  2838. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2839. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2840. * will be stored into the context1 field of the IOCB for the completion
  2841. * callback function to the SCR ELS command.
  2842. *
  2843. * Return code
  2844. * 0 - Successfully issued scr command
  2845. * 1 - Failed to issue scr command
  2846. **/
  2847. int
  2848. lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
  2849. {
  2850. struct lpfc_hba *phba = vport->phba;
  2851. struct lpfc_iocbq *elsiocb;
  2852. uint8_t *pcmd;
  2853. uint16_t cmdsize;
  2854. struct lpfc_nodelist *ndlp;
  2855. cmdsize = (sizeof(uint32_t) + sizeof(SCR));
  2856. ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
  2857. if (!ndlp) {
  2858. ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
  2859. if (!ndlp)
  2860. return 1;
  2861. lpfc_enqueue_node(vport, ndlp);
  2862. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  2863. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  2864. if (!ndlp)
  2865. return 1;
  2866. }
  2867. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2868. ndlp->nlp_DID, ELS_CMD_SCR);
  2869. if (!elsiocb) {
  2870. /* This will trigger the release of the node just
  2871. * allocated
  2872. */
  2873. lpfc_nlp_put(ndlp);
  2874. return 1;
  2875. }
  2876. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2877. *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
  2878. pcmd += sizeof(uint32_t);
  2879. /* For SCR, remainder of payload is SCR parameter page */
  2880. memset(pcmd, 0, sizeof(SCR));
  2881. ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
  2882. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2883. "Issue SCR: did:x%x",
  2884. ndlp->nlp_DID, 0, 0);
  2885. phba->fc_stat.elsXmitSCR++;
  2886. elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
  2887. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  2888. IOCB_ERROR) {
  2889. /* The additional lpfc_nlp_put will cause the following
  2890. * lpfc_els_free_iocb routine to trigger the rlease of
  2891. * the node.
  2892. */
  2893. lpfc_nlp_put(ndlp);
  2894. lpfc_els_free_iocb(phba, elsiocb);
  2895. return 1;
  2896. }
  2897. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  2898. * trigger the release of node.
  2899. */
  2900. if (!(vport->fc_flag & FC_PT2PT))
  2901. lpfc_nlp_put(ndlp);
  2902. return 0;
  2903. }
  2904. /**
  2905. * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
  2906. * or the other nport (pt2pt).
  2907. * @vport: pointer to a host virtual N_Port data structure.
  2908. * @retry: number of retries to the command IOCB.
  2909. *
  2910. * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
  2911. * when connected to a fabric, or to the remote port when connected
  2912. * in point-to-point mode. When sent to the Fabric Controller, it will
  2913. * replay the RSCN to registered recipients.
  2914. *
  2915. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2916. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2917. * will be stored into the context1 field of the IOCB for the completion
  2918. * callback function to the RSCN ELS command.
  2919. *
  2920. * Return code
  2921. * 0 - Successfully issued RSCN command
  2922. * 1 - Failed to issue RSCN command
  2923. **/
  2924. int
  2925. lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
  2926. {
  2927. struct lpfc_hba *phba = vport->phba;
  2928. struct lpfc_iocbq *elsiocb;
  2929. struct lpfc_nodelist *ndlp;
  2930. struct {
  2931. struct fc_els_rscn rscn;
  2932. struct fc_els_rscn_page portid;
  2933. } *event;
  2934. uint32_t nportid;
  2935. uint16_t cmdsize = sizeof(*event);
  2936. /* Not supported for private loop */
  2937. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
  2938. !(vport->fc_flag & FC_PUBLIC_LOOP))
  2939. return 1;
  2940. if (vport->fc_flag & FC_PT2PT) {
  2941. /* find any mapped nport - that would be the other nport */
  2942. ndlp = lpfc_findnode_mapped(vport);
  2943. if (!ndlp)
  2944. return 1;
  2945. } else {
  2946. nportid = FC_FID_FCTRL;
  2947. /* find the fabric controller node */
  2948. ndlp = lpfc_findnode_did(vport, nportid);
  2949. if (!ndlp) {
  2950. /* if one didn't exist, make one */
  2951. ndlp = lpfc_nlp_init(vport, nportid);
  2952. if (!ndlp)
  2953. return 1;
  2954. lpfc_enqueue_node(vport, ndlp);
  2955. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  2956. ndlp = lpfc_enable_node(vport, ndlp,
  2957. NLP_STE_UNUSED_NODE);
  2958. if (!ndlp)
  2959. return 1;
  2960. }
  2961. }
  2962. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2963. ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
  2964. if (!elsiocb) {
  2965. /* This will trigger the release of the node just
  2966. * allocated
  2967. */
  2968. lpfc_nlp_put(ndlp);
  2969. return 1;
  2970. }
  2971. event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
  2972. event->rscn.rscn_cmd = ELS_RSCN;
  2973. event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
  2974. event->rscn.rscn_plen = cpu_to_be16(cmdsize);
  2975. nportid = vport->fc_myDID;
  2976. /* appears that page flags must be 0 for fabric to broadcast RSCN */
  2977. event->portid.rscn_page_flags = 0;
  2978. event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
  2979. event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
  2980. event->portid.rscn_fid[2] = nportid & 0x000000FF;
  2981. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2982. "Issue RSCN: did:x%x",
  2983. ndlp->nlp_DID, 0, 0);
  2984. phba->fc_stat.elsXmitRSCN++;
  2985. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  2986. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  2987. IOCB_ERROR) {
  2988. /* The additional lpfc_nlp_put will cause the following
  2989. * lpfc_els_free_iocb routine to trigger the rlease of
  2990. * the node.
  2991. */
  2992. lpfc_nlp_put(ndlp);
  2993. lpfc_els_free_iocb(phba, elsiocb);
  2994. return 1;
  2995. }
  2996. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  2997. * trigger the release of node.
  2998. */
  2999. if (!(vport->fc_flag & FC_PT2PT))
  3000. lpfc_nlp_put(ndlp);
  3001. return 0;
  3002. }
  3003. /**
  3004. * lpfc_issue_els_farpr - Issue a farp to an node on a vport
  3005. * @vport: pointer to a host virtual N_Port data structure.
  3006. * @nportid: N_Port identifier to the remote node.
  3007. * @retry: number of retries to the command IOCB.
  3008. *
  3009. * This routine issues a Fibre Channel Address Resolution Response
  3010. * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
  3011. * is passed into the function. It first search the @vport node list to find
  3012. * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
  3013. * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
  3014. * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
  3015. *
  3016. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3017. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3018. * will be stored into the context1 field of the IOCB for the completion
  3019. * callback function to the PARPR ELS command.
  3020. *
  3021. * Return code
  3022. * 0 - Successfully issued farpr command
  3023. * 1 - Failed to issue farpr command
  3024. **/
  3025. static int
  3026. lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  3027. {
  3028. struct lpfc_hba *phba = vport->phba;
  3029. struct lpfc_iocbq *elsiocb;
  3030. FARP *fp;
  3031. uint8_t *pcmd;
  3032. uint32_t *lp;
  3033. uint16_t cmdsize;
  3034. struct lpfc_nodelist *ondlp;
  3035. struct lpfc_nodelist *ndlp;
  3036. cmdsize = (sizeof(uint32_t) + sizeof(FARP));
  3037. ndlp = lpfc_findnode_did(vport, nportid);
  3038. if (!ndlp) {
  3039. ndlp = lpfc_nlp_init(vport, nportid);
  3040. if (!ndlp)
  3041. return 1;
  3042. lpfc_enqueue_node(vport, ndlp);
  3043. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3044. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  3045. if (!ndlp)
  3046. return 1;
  3047. }
  3048. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  3049. ndlp->nlp_DID, ELS_CMD_RNID);
  3050. if (!elsiocb) {
  3051. /* This will trigger the release of the node just
  3052. * allocated
  3053. */
  3054. lpfc_nlp_put(ndlp);
  3055. return 1;
  3056. }
  3057. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3058. *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
  3059. pcmd += sizeof(uint32_t);
  3060. /* Fill in FARPR payload */
  3061. fp = (FARP *) (pcmd);
  3062. memset(fp, 0, sizeof(FARP));
  3063. lp = (uint32_t *) pcmd;
  3064. *lp++ = be32_to_cpu(nportid);
  3065. *lp++ = be32_to_cpu(vport->fc_myDID);
  3066. fp->Rflags = 0;
  3067. fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
  3068. memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
  3069. memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  3070. ondlp = lpfc_findnode_did(vport, nportid);
  3071. if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
  3072. memcpy(&fp->OportName, &ondlp->nlp_portname,
  3073. sizeof(struct lpfc_name));
  3074. memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
  3075. sizeof(struct lpfc_name));
  3076. }
  3077. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3078. "Issue FARPR: did:x%x",
  3079. ndlp->nlp_DID, 0, 0);
  3080. phba->fc_stat.elsXmitFARPR++;
  3081. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  3082. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  3083. IOCB_ERROR) {
  3084. /* The additional lpfc_nlp_put will cause the following
  3085. * lpfc_els_free_iocb routine to trigger the release of
  3086. * the node.
  3087. */
  3088. lpfc_nlp_put(ndlp);
  3089. lpfc_els_free_iocb(phba, elsiocb);
  3090. return 1;
  3091. }
  3092. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  3093. * trigger the release of the node.
  3094. */
  3095. /* Don't release reference count as RDF is likely outstanding */
  3096. return 0;
  3097. }
  3098. /**
  3099. * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
  3100. * @vport: pointer to a host virtual N_Port data structure.
  3101. * @retry: retry counter for the command IOCB.
  3102. *
  3103. * This routine issues an ELS RDF to the Fabric Controller to register
  3104. * for diagnostic functions.
  3105. *
  3106. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3107. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3108. * will be stored into the context1 field of the IOCB for the completion
  3109. * callback function to the RDF ELS command.
  3110. *
  3111. * Return code
  3112. * 0 - Successfully issued rdf command
  3113. * 1 - Failed to issue rdf command
  3114. **/
  3115. int
  3116. lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
  3117. {
  3118. struct lpfc_hba *phba = vport->phba;
  3119. struct lpfc_iocbq *elsiocb;
  3120. struct lpfc_els_rdf_req *prdf;
  3121. struct lpfc_nodelist *ndlp;
  3122. uint16_t cmdsize;
  3123. cmdsize = sizeof(*prdf);
  3124. ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
  3125. if (!ndlp) {
  3126. ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
  3127. if (!ndlp)
  3128. return -ENODEV;
  3129. lpfc_enqueue_node(vport, ndlp);
  3130. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3131. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  3132. if (!ndlp)
  3133. return -ENODEV;
  3134. }
  3135. /* RDF ELS is not required on an NPIV VN_Port. */
  3136. if (vport->port_type == LPFC_NPIV_PORT) {
  3137. lpfc_nlp_put(ndlp);
  3138. return -EACCES;
  3139. }
  3140. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  3141. ndlp->nlp_DID, ELS_CMD_RDF);
  3142. if (!elsiocb) {
  3143. /* This will trigger the release of the node just
  3144. * allocated
  3145. */
  3146. lpfc_nlp_put(ndlp);
  3147. return -ENOMEM;
  3148. }
  3149. /* Configure the payload for the supported FPIN events. */
  3150. prdf = (struct lpfc_els_rdf_req *)
  3151. (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
  3152. memset(prdf, 0, cmdsize);
  3153. prdf->rdf.fpin_cmd = ELS_RDF;
  3154. prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
  3155. sizeof(struct fc_els_rdf));
  3156. prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
  3157. prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
  3158. FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
  3159. prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
  3160. prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
  3161. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3162. "Issue RDF: did:x%x",
  3163. ndlp->nlp_DID, 0, 0);
  3164. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3165. "6444 Xmit RDF to remote NPORT x%x\n",
  3166. ndlp->nlp_DID);
  3167. elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
  3168. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  3169. IOCB_ERROR) {
  3170. /* The additional lpfc_nlp_put will cause the following
  3171. * lpfc_els_free_iocb routine to trigger the rlease of
  3172. * the node.
  3173. */
  3174. lpfc_nlp_put(ndlp);
  3175. lpfc_els_free_iocb(phba, elsiocb);
  3176. return -EIO;
  3177. }
  3178. /* An RDF was issued - this put ensures the ndlp is cleaned up
  3179. * when the RDF completes.
  3180. */
  3181. lpfc_nlp_put(ndlp);
  3182. return 0;
  3183. }
  3184. /**
  3185. * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
  3186. * @vport: pointer to a host virtual N_Port data structure.
  3187. * @nlp: pointer to a node-list data structure.
  3188. *
  3189. * This routine cancels the timer with a delayed IOCB-command retry for
  3190. * a @vport's @ndlp. It stops the timer for the delayed function retrial and
  3191. * removes the ELS retry event if it presents. In addition, if the
  3192. * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
  3193. * commands are sent for the @vport's nodes that require issuing discovery
  3194. * ADISC.
  3195. **/
  3196. void
  3197. lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
  3198. {
  3199. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3200. struct lpfc_work_evt *evtp;
  3201. if (!(nlp->nlp_flag & NLP_DELAY_TMO))
  3202. return;
  3203. spin_lock_irq(shost->host_lock);
  3204. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  3205. spin_unlock_irq(shost->host_lock);
  3206. del_timer_sync(&nlp->nlp_delayfunc);
  3207. nlp->nlp_last_elscmd = 0;
  3208. if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
  3209. list_del_init(&nlp->els_retry_evt.evt_listp);
  3210. /* Decrement nlp reference count held for the delayed retry */
  3211. evtp = &nlp->els_retry_evt;
  3212. lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
  3213. }
  3214. if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
  3215. spin_lock_irq(shost->host_lock);
  3216. nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  3217. spin_unlock_irq(shost->host_lock);
  3218. if (vport->num_disc_nodes) {
  3219. if (vport->port_state < LPFC_VPORT_READY) {
  3220. /* Check if there are more ADISCs to be sent */
  3221. lpfc_more_adisc(vport);
  3222. } else {
  3223. /* Check if there are more PLOGIs to be sent */
  3224. lpfc_more_plogi(vport);
  3225. if (vport->num_disc_nodes == 0) {
  3226. spin_lock_irq(shost->host_lock);
  3227. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  3228. spin_unlock_irq(shost->host_lock);
  3229. lpfc_can_disctmo(vport);
  3230. lpfc_end_rscn(vport);
  3231. }
  3232. }
  3233. }
  3234. }
  3235. return;
  3236. }
  3237. /**
  3238. * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
  3239. * @ptr: holder for the pointer to the timer function associated data (ndlp).
  3240. *
  3241. * This routine is invoked by the ndlp delayed-function timer to check
  3242. * whether there is any pending ELS retry event(s) with the node. If not, it
  3243. * simply returns. Otherwise, if there is at least one ELS delayed event, it
  3244. * adds the delayed events to the HBA work list and invokes the
  3245. * lpfc_worker_wake_up() routine to wake up worker thread to process the
  3246. * event. Note that lpfc_nlp_get() is called before posting the event to
  3247. * the work list to hold reference count of ndlp so that it guarantees the
  3248. * reference to ndlp will still be available when the worker thread gets
  3249. * to the event associated with the ndlp.
  3250. **/
  3251. void
  3252. lpfc_els_retry_delay(struct timer_list *t)
  3253. {
  3254. struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
  3255. struct lpfc_vport *vport = ndlp->vport;
  3256. struct lpfc_hba *phba = vport->phba;
  3257. unsigned long flags;
  3258. struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
  3259. spin_lock_irqsave(&phba->hbalock, flags);
  3260. if (!list_empty(&evtp->evt_listp)) {
  3261. spin_unlock_irqrestore(&phba->hbalock, flags);
  3262. return;
  3263. }
  3264. /* We need to hold the node by incrementing the reference
  3265. * count until the queued work is done
  3266. */
  3267. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  3268. if (evtp->evt_arg1) {
  3269. evtp->evt = LPFC_EVT_ELS_RETRY;
  3270. list_add_tail(&evtp->evt_listp, &phba->work_list);
  3271. lpfc_worker_wake_up(phba);
  3272. }
  3273. spin_unlock_irqrestore(&phba->hbalock, flags);
  3274. return;
  3275. }
  3276. /**
  3277. * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
  3278. * @ndlp: pointer to a node-list data structure.
  3279. *
  3280. * This routine is the worker-thread handler for processing the @ndlp delayed
  3281. * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
  3282. * the last ELS command from the associated ndlp and invokes the proper ELS
  3283. * function according to the delayed ELS command to retry the command.
  3284. **/
  3285. void
  3286. lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
  3287. {
  3288. struct lpfc_vport *vport = ndlp->vport;
  3289. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3290. uint32_t cmd, retry;
  3291. spin_lock_irq(shost->host_lock);
  3292. cmd = ndlp->nlp_last_elscmd;
  3293. ndlp->nlp_last_elscmd = 0;
  3294. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  3295. spin_unlock_irq(shost->host_lock);
  3296. return;
  3297. }
  3298. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  3299. spin_unlock_irq(shost->host_lock);
  3300. /*
  3301. * If a discovery event readded nlp_delayfunc after timer
  3302. * firing and before processing the timer, cancel the
  3303. * nlp_delayfunc.
  3304. */
  3305. del_timer_sync(&ndlp->nlp_delayfunc);
  3306. retry = ndlp->nlp_retry;
  3307. ndlp->nlp_retry = 0;
  3308. switch (cmd) {
  3309. case ELS_CMD_FLOGI:
  3310. lpfc_issue_els_flogi(vport, ndlp, retry);
  3311. break;
  3312. case ELS_CMD_PLOGI:
  3313. if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
  3314. ndlp->nlp_prev_state = ndlp->nlp_state;
  3315. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  3316. }
  3317. break;
  3318. case ELS_CMD_ADISC:
  3319. if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
  3320. ndlp->nlp_prev_state = ndlp->nlp_state;
  3321. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  3322. }
  3323. break;
  3324. case ELS_CMD_PRLI:
  3325. case ELS_CMD_NVMEPRLI:
  3326. if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
  3327. ndlp->nlp_prev_state = ndlp->nlp_state;
  3328. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  3329. }
  3330. break;
  3331. case ELS_CMD_LOGO:
  3332. if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
  3333. ndlp->nlp_prev_state = ndlp->nlp_state;
  3334. lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
  3335. }
  3336. break;
  3337. case ELS_CMD_FDISC:
  3338. if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
  3339. lpfc_issue_els_fdisc(vport, ndlp, retry);
  3340. break;
  3341. }
  3342. return;
  3343. }
  3344. /**
  3345. * lpfc_link_reset - Issue link reset
  3346. * @vport: pointer to a virtual N_Port data structure.
  3347. *
  3348. * This routine performs link reset by sending INIT_LINK mailbox command.
  3349. * For SLI-3 adapter, link attention interrupt is enabled before issuing
  3350. * INIT_LINK mailbox command.
  3351. *
  3352. * Return code
  3353. * 0 - Link reset initiated successfully
  3354. * 1 - Failed to initiate link reset
  3355. **/
  3356. int
  3357. lpfc_link_reset(struct lpfc_vport *vport)
  3358. {
  3359. struct lpfc_hba *phba = vport->phba;
  3360. LPFC_MBOXQ_t *mbox;
  3361. uint32_t control;
  3362. int rc;
  3363. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3364. "2851 Attempt link reset\n");
  3365. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3366. if (!mbox) {
  3367. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  3368. "2852 Failed to allocate mbox memory");
  3369. return 1;
  3370. }
  3371. /* Enable Link attention interrupts */
  3372. if (phba->sli_rev <= LPFC_SLI_REV3) {
  3373. spin_lock_irq(&phba->hbalock);
  3374. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3375. control = readl(phba->HCregaddr);
  3376. control |= HC_LAINT_ENA;
  3377. writel(control, phba->HCregaddr);
  3378. readl(phba->HCregaddr); /* flush */
  3379. spin_unlock_irq(&phba->hbalock);
  3380. }
  3381. lpfc_init_link(phba, mbox, phba->cfg_topology,
  3382. phba->cfg_link_speed);
  3383. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3384. mbox->vport = vport;
  3385. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3386. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  3387. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  3388. "2853 Failed to issue INIT_LINK "
  3389. "mbox command, rc:x%x\n", rc);
  3390. mempool_free(mbox, phba->mbox_mem_pool);
  3391. return 1;
  3392. }
  3393. return 0;
  3394. }
  3395. /**
  3396. * lpfc_els_retry - Make retry decision on an els command iocb
  3397. * @phba: pointer to lpfc hba data structure.
  3398. * @cmdiocb: pointer to lpfc command iocb data structure.
  3399. * @rspiocb: pointer to lpfc response iocb data structure.
  3400. *
  3401. * This routine makes a retry decision on an ELS command IOCB, which has
  3402. * failed. The following ELS IOCBs use this function for retrying the command
  3403. * when previously issued command responsed with error status: FLOGI, PLOGI,
  3404. * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
  3405. * returned error status, it makes the decision whether a retry shall be
  3406. * issued for the command, and whether a retry shall be made immediately or
  3407. * delayed. In the former case, the corresponding ELS command issuing-function
  3408. * is called to retry the command. In the later case, the ELS command shall
  3409. * be posted to the ndlp delayed event and delayed function timer set to the
  3410. * ndlp for the delayed command issusing.
  3411. *
  3412. * Return code
  3413. * 0 - No retry of els command is made
  3414. * 1 - Immediate or delayed retry of els command is made
  3415. **/
  3416. static int
  3417. lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3418. struct lpfc_iocbq *rspiocb)
  3419. {
  3420. struct lpfc_vport *vport = cmdiocb->vport;
  3421. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3422. IOCB_t *irsp = &rspiocb->iocb;
  3423. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  3424. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3425. uint32_t *elscmd;
  3426. struct ls_rjt stat;
  3427. int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
  3428. int logerr = 0;
  3429. uint32_t cmd = 0;
  3430. uint32_t did;
  3431. int link_reset = 0, rc;
  3432. /* Note: context2 may be 0 for internal driver abort
  3433. * of delays ELS command.
  3434. */
  3435. if (pcmd && pcmd->virt) {
  3436. elscmd = (uint32_t *) (pcmd->virt);
  3437. cmd = *elscmd++;
  3438. }
  3439. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  3440. did = ndlp->nlp_DID;
  3441. else {
  3442. /* We should only hit this case for retrying PLOGI */
  3443. did = irsp->un.elsreq64.remoteID;
  3444. ndlp = lpfc_findnode_did(vport, did);
  3445. if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  3446. && (cmd != ELS_CMD_PLOGI))
  3447. return 1;
  3448. }
  3449. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3450. "Retry ELS: wd7:x%x wd4:x%x did:x%x",
  3451. *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
  3452. switch (irsp->ulpStatus) {
  3453. case IOSTAT_FCP_RSP_ERROR:
  3454. break;
  3455. case IOSTAT_REMOTE_STOP:
  3456. if (phba->sli_rev == LPFC_SLI_REV4) {
  3457. /* This IO was aborted by the target, we don't
  3458. * know the rxid and because we did not send the
  3459. * ABTS we cannot generate and RRQ.
  3460. */
  3461. lpfc_set_rrq_active(phba, ndlp,
  3462. cmdiocb->sli4_lxritag, 0, 0);
  3463. }
  3464. break;
  3465. case IOSTAT_LOCAL_REJECT:
  3466. switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
  3467. case IOERR_LOOP_OPEN_FAILURE:
  3468. if (cmd == ELS_CMD_FLOGI) {
  3469. if (PCI_DEVICE_ID_HORNET ==
  3470. phba->pcidev->device) {
  3471. phba->fc_topology = LPFC_TOPOLOGY_LOOP;
  3472. phba->pport->fc_myDID = 0;
  3473. phba->alpa_map[0] = 0;
  3474. phba->alpa_map[1] = 0;
  3475. }
  3476. }
  3477. if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
  3478. delay = 1000;
  3479. retry = 1;
  3480. break;
  3481. case IOERR_ILLEGAL_COMMAND:
  3482. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3483. "0124 Retry illegal cmd x%x "
  3484. "retry:x%x delay:x%x\n",
  3485. cmd, cmdiocb->retry, delay);
  3486. retry = 1;
  3487. /* All command's retry policy */
  3488. maxretry = 8;
  3489. if (cmdiocb->retry > 2)
  3490. delay = 1000;
  3491. break;
  3492. case IOERR_NO_RESOURCES:
  3493. logerr = 1; /* HBA out of resources */
  3494. retry = 1;
  3495. if (cmdiocb->retry > 100)
  3496. delay = 100;
  3497. maxretry = 250;
  3498. break;
  3499. case IOERR_ILLEGAL_FRAME:
  3500. delay = 100;
  3501. retry = 1;
  3502. break;
  3503. case IOERR_INVALID_RPI:
  3504. if (cmd == ELS_CMD_PLOGI &&
  3505. did == NameServer_DID) {
  3506. /* Continue forever if plogi to */
  3507. /* the nameserver fails */
  3508. maxretry = 0;
  3509. delay = 100;
  3510. }
  3511. retry = 1;
  3512. break;
  3513. case IOERR_SEQUENCE_TIMEOUT:
  3514. if (cmd == ELS_CMD_PLOGI &&
  3515. did == NameServer_DID &&
  3516. (cmdiocb->retry + 1) == maxretry) {
  3517. /* Reset the Link */
  3518. link_reset = 1;
  3519. break;
  3520. }
  3521. retry = 1;
  3522. delay = 100;
  3523. break;
  3524. }
  3525. break;
  3526. case IOSTAT_NPORT_RJT:
  3527. case IOSTAT_FABRIC_RJT:
  3528. if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  3529. retry = 1;
  3530. break;
  3531. }
  3532. break;
  3533. case IOSTAT_NPORT_BSY:
  3534. case IOSTAT_FABRIC_BSY:
  3535. logerr = 1; /* Fabric / Remote NPort out of resources */
  3536. retry = 1;
  3537. break;
  3538. case IOSTAT_LS_RJT:
  3539. stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
  3540. /* Added for Vendor specifc support
  3541. * Just keep retrying for these Rsn / Exp codes
  3542. */
  3543. switch (stat.un.b.lsRjtRsnCode) {
  3544. case LSRJT_UNABLE_TPC:
  3545. /* The driver has a VALID PLOGI but the rport has
  3546. * rejected the PRLI - can't do it now. Delay
  3547. * for 1 second and try again - don't care about
  3548. * the explanation.
  3549. */
  3550. if (cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) {
  3551. delay = 1000;
  3552. maxretry = lpfc_max_els_tries + 1;
  3553. retry = 1;
  3554. break;
  3555. }
  3556. /* Legacy bug fix code for targets with PLOGI delays. */
  3557. if (stat.un.b.lsRjtRsnCodeExp ==
  3558. LSEXP_CMD_IN_PROGRESS) {
  3559. if (cmd == ELS_CMD_PLOGI) {
  3560. delay = 1000;
  3561. maxretry = 48;
  3562. }
  3563. retry = 1;
  3564. break;
  3565. }
  3566. if (stat.un.b.lsRjtRsnCodeExp ==
  3567. LSEXP_CANT_GIVE_DATA) {
  3568. if (cmd == ELS_CMD_PLOGI) {
  3569. delay = 1000;
  3570. maxretry = 48;
  3571. }
  3572. retry = 1;
  3573. break;
  3574. }
  3575. if (cmd == ELS_CMD_PLOGI) {
  3576. delay = 1000;
  3577. maxretry = lpfc_max_els_tries + 1;
  3578. retry = 1;
  3579. break;
  3580. }
  3581. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3582. (cmd == ELS_CMD_FDISC) &&
  3583. (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
  3584. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3585. "0125 FDISC Failed (x%x). "
  3586. "Fabric out of resources\n",
  3587. stat.un.lsRjtError);
  3588. lpfc_vport_set_state(vport,
  3589. FC_VPORT_NO_FABRIC_RSCS);
  3590. }
  3591. break;
  3592. case LSRJT_LOGICAL_BSY:
  3593. if ((cmd == ELS_CMD_PLOGI) ||
  3594. (cmd == ELS_CMD_PRLI) ||
  3595. (cmd == ELS_CMD_NVMEPRLI)) {
  3596. delay = 1000;
  3597. maxretry = 48;
  3598. } else if (cmd == ELS_CMD_FDISC) {
  3599. /* FDISC retry policy */
  3600. maxretry = 48;
  3601. if (cmdiocb->retry >= 32)
  3602. delay = 1000;
  3603. }
  3604. retry = 1;
  3605. break;
  3606. case LSRJT_LOGICAL_ERR:
  3607. /* There are some cases where switches return this
  3608. * error when they are not ready and should be returning
  3609. * Logical Busy. We should delay every time.
  3610. */
  3611. if (cmd == ELS_CMD_FDISC &&
  3612. stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
  3613. maxretry = 3;
  3614. delay = 1000;
  3615. retry = 1;
  3616. } else if (cmd == ELS_CMD_FLOGI &&
  3617. stat.un.b.lsRjtRsnCodeExp ==
  3618. LSEXP_NOTHING_MORE) {
  3619. vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
  3620. retry = 1;
  3621. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3622. "0820 FLOGI Failed (x%x). "
  3623. "BBCredit Not Supported\n",
  3624. stat.un.lsRjtError);
  3625. }
  3626. break;
  3627. case LSRJT_PROTOCOL_ERR:
  3628. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3629. (cmd == ELS_CMD_FDISC) &&
  3630. ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
  3631. (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
  3632. ) {
  3633. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3634. "0122 FDISC Failed (x%x). "
  3635. "Fabric Detected Bad WWN\n",
  3636. stat.un.lsRjtError);
  3637. lpfc_vport_set_state(vport,
  3638. FC_VPORT_FABRIC_REJ_WWN);
  3639. }
  3640. break;
  3641. case LSRJT_VENDOR_UNIQUE:
  3642. if ((stat.un.b.vendorUnique == 0x45) &&
  3643. (cmd == ELS_CMD_FLOGI)) {
  3644. goto out_retry;
  3645. }
  3646. break;
  3647. case LSRJT_CMD_UNSUPPORTED:
  3648. /* lpfc nvmet returns this type of LS_RJT when it
  3649. * receives an FCP PRLI because lpfc nvmet only
  3650. * support NVME. ELS request is terminated for FCP4
  3651. * on this rport.
  3652. */
  3653. if (stat.un.b.lsRjtRsnCodeExp ==
  3654. LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
  3655. spin_lock_irq(shost->host_lock);
  3656. ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
  3657. spin_unlock_irq(shost->host_lock);
  3658. retry = 0;
  3659. goto out_retry;
  3660. }
  3661. break;
  3662. }
  3663. break;
  3664. case IOSTAT_INTERMED_RSP:
  3665. case IOSTAT_BA_RJT:
  3666. break;
  3667. default:
  3668. break;
  3669. }
  3670. if (link_reset) {
  3671. rc = lpfc_link_reset(vport);
  3672. if (rc) {
  3673. /* Do not give up. Retry PLOGI one more time and attempt
  3674. * link reset if PLOGI fails again.
  3675. */
  3676. retry = 1;
  3677. delay = 100;
  3678. goto out_retry;
  3679. }
  3680. return 1;
  3681. }
  3682. if (did == FDMI_DID)
  3683. retry = 1;
  3684. if ((cmd == ELS_CMD_FLOGI) &&
  3685. (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
  3686. !lpfc_error_lost_link(irsp)) {
  3687. /* FLOGI retry policy */
  3688. retry = 1;
  3689. /* retry FLOGI forever */
  3690. if (phba->link_flag != LS_LOOPBACK_MODE)
  3691. maxretry = 0;
  3692. else
  3693. maxretry = 2;
  3694. if (cmdiocb->retry >= 100)
  3695. delay = 5000;
  3696. else if (cmdiocb->retry >= 32)
  3697. delay = 1000;
  3698. } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
  3699. /* retry FDISCs every second up to devloss */
  3700. retry = 1;
  3701. maxretry = vport->cfg_devloss_tmo;
  3702. delay = 1000;
  3703. }
  3704. cmdiocb->retry++;
  3705. if (maxretry && (cmdiocb->retry >= maxretry)) {
  3706. phba->fc_stat.elsRetryExceeded++;
  3707. retry = 0;
  3708. }
  3709. if ((vport->load_flag & FC_UNLOADING) != 0)
  3710. retry = 0;
  3711. out_retry:
  3712. if (retry) {
  3713. if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
  3714. /* Stop retrying PLOGI and FDISC if in FCF discovery */
  3715. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3716. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3717. "2849 Stop retry ELS command "
  3718. "x%x to remote NPORT x%x, "
  3719. "Data: x%x x%x\n", cmd, did,
  3720. cmdiocb->retry, delay);
  3721. return 0;
  3722. }
  3723. }
  3724. /* Retry ELS command <elsCmd> to remote NPORT <did> */
  3725. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3726. "0107 Retry ELS command x%x to remote "
  3727. "NPORT x%x Data: x%x x%x\n",
  3728. cmd, did, cmdiocb->retry, delay);
  3729. if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
  3730. ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  3731. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
  3732. IOERR_NO_RESOURCES))) {
  3733. /* Don't reset timer for no resources */
  3734. /* If discovery / RSCN timer is running, reset it */
  3735. if (timer_pending(&vport->fc_disctmo) ||
  3736. (vport->fc_flag & FC_RSCN_MODE))
  3737. lpfc_set_disctmo(vport);
  3738. }
  3739. phba->fc_stat.elsXmitRetry++;
  3740. if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
  3741. phba->fc_stat.elsDelayRetry++;
  3742. ndlp->nlp_retry = cmdiocb->retry;
  3743. /* delay is specified in milliseconds */
  3744. mod_timer(&ndlp->nlp_delayfunc,
  3745. jiffies + msecs_to_jiffies(delay));
  3746. spin_lock_irq(shost->host_lock);
  3747. ndlp->nlp_flag |= NLP_DELAY_TMO;
  3748. spin_unlock_irq(shost->host_lock);
  3749. ndlp->nlp_prev_state = ndlp->nlp_state;
  3750. if ((cmd == ELS_CMD_PRLI) ||
  3751. (cmd == ELS_CMD_NVMEPRLI))
  3752. lpfc_nlp_set_state(vport, ndlp,
  3753. NLP_STE_PRLI_ISSUE);
  3754. else
  3755. lpfc_nlp_set_state(vport, ndlp,
  3756. NLP_STE_NPR_NODE);
  3757. ndlp->nlp_last_elscmd = cmd;
  3758. return 1;
  3759. }
  3760. switch (cmd) {
  3761. case ELS_CMD_FLOGI:
  3762. lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
  3763. return 1;
  3764. case ELS_CMD_FDISC:
  3765. lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
  3766. return 1;
  3767. case ELS_CMD_PLOGI:
  3768. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  3769. ndlp->nlp_prev_state = ndlp->nlp_state;
  3770. lpfc_nlp_set_state(vport, ndlp,
  3771. NLP_STE_PLOGI_ISSUE);
  3772. }
  3773. lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
  3774. return 1;
  3775. case ELS_CMD_ADISC:
  3776. ndlp->nlp_prev_state = ndlp->nlp_state;
  3777. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  3778. lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
  3779. return 1;
  3780. case ELS_CMD_PRLI:
  3781. case ELS_CMD_NVMEPRLI:
  3782. ndlp->nlp_prev_state = ndlp->nlp_state;
  3783. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  3784. lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
  3785. return 1;
  3786. case ELS_CMD_LOGO:
  3787. ndlp->nlp_prev_state = ndlp->nlp_state;
  3788. lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
  3789. lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
  3790. return 1;
  3791. }
  3792. }
  3793. /* No retry ELS command <elsCmd> to remote NPORT <did> */
  3794. if (logerr) {
  3795. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3796. "0137 No retry ELS command x%x to remote "
  3797. "NPORT x%x: Out of Resources: Error:x%x/%x\n",
  3798. cmd, did, irsp->ulpStatus,
  3799. irsp->un.ulpWord[4]);
  3800. }
  3801. else {
  3802. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3803. "0108 No retry ELS command x%x to remote "
  3804. "NPORT x%x Retried:%d Error:x%x/%x\n",
  3805. cmd, did, cmdiocb->retry, irsp->ulpStatus,
  3806. irsp->un.ulpWord[4]);
  3807. }
  3808. return 0;
  3809. }
  3810. /**
  3811. * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
  3812. * @phba: pointer to lpfc hba data structure.
  3813. * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
  3814. *
  3815. * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
  3816. * associated with a command IOCB back to the lpfc DMA buffer pool. It first
  3817. * checks to see whether there is a lpfc DMA buffer associated with the
  3818. * response of the command IOCB. If so, it will be released before releasing
  3819. * the lpfc DMA buffer associated with the IOCB itself.
  3820. *
  3821. * Return code
  3822. * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
  3823. **/
  3824. static int
  3825. lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
  3826. {
  3827. struct lpfc_dmabuf *buf_ptr;
  3828. /* Free the response before processing the command. */
  3829. if (!list_empty(&buf_ptr1->list)) {
  3830. list_remove_head(&buf_ptr1->list, buf_ptr,
  3831. struct lpfc_dmabuf,
  3832. list);
  3833. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  3834. kfree(buf_ptr);
  3835. }
  3836. lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
  3837. kfree(buf_ptr1);
  3838. return 0;
  3839. }
  3840. /**
  3841. * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
  3842. * @phba: pointer to lpfc hba data structure.
  3843. * @buf_ptr: pointer to the lpfc dma buffer data structure.
  3844. *
  3845. * This routine releases the lpfc Direct Memory Access (DMA) buffer
  3846. * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
  3847. * pool.
  3848. *
  3849. * Return code
  3850. * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
  3851. **/
  3852. static int
  3853. lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
  3854. {
  3855. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  3856. kfree(buf_ptr);
  3857. return 0;
  3858. }
  3859. /**
  3860. * lpfc_els_free_iocb - Free a command iocb and its associated resources
  3861. * @phba: pointer to lpfc hba data structure.
  3862. * @elsiocb: pointer to lpfc els command iocb data structure.
  3863. *
  3864. * This routine frees a command IOCB and its associated resources. The
  3865. * command IOCB data structure contains the reference to various associated
  3866. * resources, these fields must be set to NULL if the associated reference
  3867. * not present:
  3868. * context1 - reference to ndlp
  3869. * context2 - reference to cmd
  3870. * context2->next - reference to rsp
  3871. * context3 - reference to bpl
  3872. *
  3873. * It first properly decrements the reference count held on ndlp for the
  3874. * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
  3875. * set, it invokes the lpfc_els_free_data() routine to release the Direct
  3876. * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
  3877. * adds the DMA buffer the @phba data structure for the delayed release.
  3878. * If reference to the Buffer Pointer List (BPL) is present, the
  3879. * lpfc_els_free_bpl() routine is invoked to release the DMA memory
  3880. * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
  3881. * invoked to release the IOCB data structure back to @phba IOCBQ list.
  3882. *
  3883. * Return code
  3884. * 0 - Success (currently, always return 0)
  3885. **/
  3886. int
  3887. lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
  3888. {
  3889. struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
  3890. struct lpfc_nodelist *ndlp;
  3891. ndlp = (struct lpfc_nodelist *)elsiocb->context1;
  3892. if (ndlp) {
  3893. if (ndlp->nlp_flag & NLP_DEFER_RM) {
  3894. lpfc_nlp_put(ndlp);
  3895. /* If the ndlp is not being used by another discovery
  3896. * thread, free it.
  3897. */
  3898. if (!lpfc_nlp_not_used(ndlp)) {
  3899. /* If ndlp is being used by another discovery
  3900. * thread, just clear NLP_DEFER_RM
  3901. */
  3902. ndlp->nlp_flag &= ~NLP_DEFER_RM;
  3903. }
  3904. }
  3905. else
  3906. lpfc_nlp_put(ndlp);
  3907. elsiocb->context1 = NULL;
  3908. }
  3909. /* context2 = cmd, context2->next = rsp, context3 = bpl */
  3910. if (elsiocb->context2) {
  3911. if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
  3912. /* Firmware could still be in progress of DMAing
  3913. * payload, so don't free data buffer till after
  3914. * a hbeat.
  3915. */
  3916. elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
  3917. buf_ptr = elsiocb->context2;
  3918. elsiocb->context2 = NULL;
  3919. if (buf_ptr) {
  3920. buf_ptr1 = NULL;
  3921. spin_lock_irq(&phba->hbalock);
  3922. if (!list_empty(&buf_ptr->list)) {
  3923. list_remove_head(&buf_ptr->list,
  3924. buf_ptr1, struct lpfc_dmabuf,
  3925. list);
  3926. INIT_LIST_HEAD(&buf_ptr1->list);
  3927. list_add_tail(&buf_ptr1->list,
  3928. &phba->elsbuf);
  3929. phba->elsbuf_cnt++;
  3930. }
  3931. INIT_LIST_HEAD(&buf_ptr->list);
  3932. list_add_tail(&buf_ptr->list, &phba->elsbuf);
  3933. phba->elsbuf_cnt++;
  3934. spin_unlock_irq(&phba->hbalock);
  3935. }
  3936. } else {
  3937. buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
  3938. lpfc_els_free_data(phba, buf_ptr1);
  3939. elsiocb->context2 = NULL;
  3940. }
  3941. }
  3942. if (elsiocb->context3) {
  3943. buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
  3944. lpfc_els_free_bpl(phba, buf_ptr);
  3945. elsiocb->context3 = NULL;
  3946. }
  3947. lpfc_sli_release_iocbq(phba, elsiocb);
  3948. return 0;
  3949. }
  3950. /**
  3951. * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
  3952. * @phba: pointer to lpfc hba data structure.
  3953. * @cmdiocb: pointer to lpfc command iocb data structure.
  3954. * @rspiocb: pointer to lpfc response iocb data structure.
  3955. *
  3956. * This routine is the completion callback function to the Logout (LOGO)
  3957. * Accept (ACC) Response ELS command. This routine is invoked to indicate
  3958. * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
  3959. * release the ndlp if it has the last reference remaining (reference count
  3960. * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
  3961. * field to NULL to inform the following lpfc_els_free_iocb() routine no
  3962. * ndlp reference count needs to be decremented. Otherwise, the ndlp
  3963. * reference use-count shall be decremented by the lpfc_els_free_iocb()
  3964. * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
  3965. * IOCB data structure.
  3966. **/
  3967. static void
  3968. lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3969. struct lpfc_iocbq *rspiocb)
  3970. {
  3971. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  3972. struct lpfc_vport *vport = cmdiocb->vport;
  3973. IOCB_t *irsp;
  3974. irsp = &rspiocb->iocb;
  3975. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3976. "ACC LOGO cmpl: status:x%x/x%x did:x%x",
  3977. irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
  3978. /* ACC to LOGO completes to NPort <nlp_DID> */
  3979. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3980. "0109 ACC to LOGO completes to NPort x%x "
  3981. "Data: x%x x%x x%x\n",
  3982. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3983. ndlp->nlp_rpi);
  3984. if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
  3985. /* NPort Recovery mode or node is just allocated */
  3986. if (!lpfc_nlp_not_used(ndlp)) {
  3987. /* If the ndlp is being used by another discovery
  3988. * thread, just unregister the RPI.
  3989. */
  3990. lpfc_unreg_rpi(vport, ndlp);
  3991. } else {
  3992. /* Indicate the node has already released, should
  3993. * not reference to it from within lpfc_els_free_iocb.
  3994. */
  3995. cmdiocb->context1 = NULL;
  3996. }
  3997. }
  3998. /*
  3999. * The driver received a LOGO from the rport and has ACK'd it.
  4000. * At this point, the driver is done so release the IOCB
  4001. */
  4002. lpfc_els_free_iocb(phba, cmdiocb);
  4003. }
  4004. /**
  4005. * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
  4006. * @phba: pointer to lpfc hba data structure.
  4007. * @pmb: pointer to the driver internal queue element for mailbox command.
  4008. *
  4009. * This routine is the completion callback function for unregister default
  4010. * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
  4011. * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
  4012. * decrements the ndlp reference count held for this completion callback
  4013. * function. After that, it invokes the lpfc_nlp_not_used() to check
  4014. * whether there is only one reference left on the ndlp. If so, it will
  4015. * perform one more decrement and trigger the release of the ndlp.
  4016. **/
  4017. void
  4018. lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  4019. {
  4020. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
  4021. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
  4022. pmb->ctx_buf = NULL;
  4023. pmb->ctx_ndlp = NULL;
  4024. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4025. kfree(mp);
  4026. mempool_free(pmb, phba->mbox_mem_pool);
  4027. if (ndlp) {
  4028. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
  4029. "0006 rpi%x DID:%x flg:%x %d map:%x x%px\n",
  4030. ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
  4031. kref_read(&ndlp->kref),
  4032. ndlp->nlp_usg_map, ndlp);
  4033. if (NLP_CHK_NODE_ACT(ndlp)) {
  4034. lpfc_nlp_put(ndlp);
  4035. /* This is the end of the default RPI cleanup logic for
  4036. * this ndlp. If no other discovery threads are using
  4037. * this ndlp, free all resources associated with it.
  4038. */
  4039. lpfc_nlp_not_used(ndlp);
  4040. } else {
  4041. lpfc_drop_node(ndlp->vport, ndlp);
  4042. }
  4043. }
  4044. return;
  4045. }
  4046. /**
  4047. * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
  4048. * @phba: pointer to lpfc hba data structure.
  4049. * @cmdiocb: pointer to lpfc command iocb data structure.
  4050. * @rspiocb: pointer to lpfc response iocb data structure.
  4051. *
  4052. * This routine is the completion callback function for ELS Response IOCB
  4053. * command. In normal case, this callback function just properly sets the
  4054. * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
  4055. * field in the command IOCB is not NULL, the referred mailbox command will
  4056. * be send out, and then invokes the lpfc_els_free_iocb() routine to release
  4057. * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
  4058. * link down event occurred during the discovery, the lpfc_nlp_not_used()
  4059. * routine shall be invoked trying to release the ndlp if no other threads
  4060. * are currently referring it.
  4061. **/
  4062. static void
  4063. lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  4064. struct lpfc_iocbq *rspiocb)
  4065. {
  4066. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  4067. struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
  4068. struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
  4069. IOCB_t *irsp;
  4070. uint8_t *pcmd;
  4071. LPFC_MBOXQ_t *mbox = NULL;
  4072. struct lpfc_dmabuf *mp = NULL;
  4073. uint32_t ls_rjt = 0;
  4074. irsp = &rspiocb->iocb;
  4075. if (!vport) {
  4076. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  4077. "3177 ELS response failed\n");
  4078. goto out;
  4079. }
  4080. if (cmdiocb->context_un.mbox)
  4081. mbox = cmdiocb->context_un.mbox;
  4082. /* First determine if this is a LS_RJT cmpl. Note, this callback
  4083. * function can have cmdiocb->contest1 (ndlp) field set to NULL.
  4084. */
  4085. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
  4086. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  4087. (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
  4088. /* A LS_RJT associated with Default RPI cleanup has its own
  4089. * separate code path.
  4090. */
  4091. if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  4092. ls_rjt = 1;
  4093. }
  4094. /* Check to see if link went down during discovery */
  4095. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
  4096. if (mbox) {
  4097. mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
  4098. if (mp) {
  4099. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4100. kfree(mp);
  4101. }
  4102. mempool_free(mbox, phba->mbox_mem_pool);
  4103. }
  4104. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  4105. (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  4106. if (lpfc_nlp_not_used(ndlp)) {
  4107. ndlp = NULL;
  4108. /* Indicate the node has already released,
  4109. * should not reference to it from within
  4110. * the routine lpfc_els_free_iocb.
  4111. */
  4112. cmdiocb->context1 = NULL;
  4113. }
  4114. goto out;
  4115. }
  4116. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4117. "ELS rsp cmpl: status:x%x/x%x did:x%x",
  4118. irsp->ulpStatus, irsp->un.ulpWord[4],
  4119. cmdiocb->iocb.un.elsreq64.remoteID);
  4120. /* ELS response tag <ulpIoTag> completes */
  4121. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4122. "0110 ELS response tag x%x completes "
  4123. "Data: x%x x%x x%x x%x x%x x%x x%x\n",
  4124. cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
  4125. rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
  4126. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4127. ndlp->nlp_rpi);
  4128. if (mbox) {
  4129. if ((rspiocb->iocb.ulpStatus == 0)
  4130. && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
  4131. if (!lpfc_unreg_rpi(vport, ndlp) &&
  4132. (!(vport->fc_flag & FC_PT2PT)) &&
  4133. (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  4134. ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
  4135. lpfc_printf_vlog(vport, KERN_INFO,
  4136. LOG_DISCOVERY,
  4137. "0314 PLOGI recov DID x%x "
  4138. "Data: x%x x%x x%x\n",
  4139. ndlp->nlp_DID, ndlp->nlp_state,
  4140. ndlp->nlp_rpi, ndlp->nlp_flag);
  4141. mp = mbox->ctx_buf;
  4142. if (mp) {
  4143. lpfc_mbuf_free(phba, mp->virt,
  4144. mp->phys);
  4145. kfree(mp);
  4146. }
  4147. mempool_free(mbox, phba->mbox_mem_pool);
  4148. goto out;
  4149. }
  4150. /* Increment reference count to ndlp to hold the
  4151. * reference to ndlp for the callback function.
  4152. */
  4153. mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
  4154. mbox->vport = vport;
  4155. if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
  4156. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  4157. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  4158. }
  4159. else {
  4160. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  4161. ndlp->nlp_prev_state = ndlp->nlp_state;
  4162. lpfc_nlp_set_state(vport, ndlp,
  4163. NLP_STE_REG_LOGIN_ISSUE);
  4164. }
  4165. ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
  4166. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  4167. != MBX_NOT_FINISHED)
  4168. goto out;
  4169. /* Decrement the ndlp reference count we
  4170. * set for this failed mailbox command.
  4171. */
  4172. lpfc_nlp_put(ndlp);
  4173. ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
  4174. /* ELS rsp: Cannot issue reg_login for <NPortid> */
  4175. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4176. "0138 ELS rsp: Cannot issue reg_login for x%x "
  4177. "Data: x%x x%x x%x\n",
  4178. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4179. ndlp->nlp_rpi);
  4180. if (lpfc_nlp_not_used(ndlp)) {
  4181. ndlp = NULL;
  4182. /* Indicate node has already been released,
  4183. * should not reference to it from within
  4184. * the routine lpfc_els_free_iocb.
  4185. */
  4186. cmdiocb->context1 = NULL;
  4187. }
  4188. } else {
  4189. /* Do not drop node for lpfc_els_abort'ed ELS cmds */
  4190. if (!lpfc_error_lost_link(irsp) &&
  4191. ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  4192. if (lpfc_nlp_not_used(ndlp)) {
  4193. ndlp = NULL;
  4194. /* Indicate node has already been
  4195. * released, should not reference
  4196. * to it from within the routine
  4197. * lpfc_els_free_iocb.
  4198. */
  4199. cmdiocb->context1 = NULL;
  4200. }
  4201. }
  4202. }
  4203. mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
  4204. if (mp) {
  4205. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4206. kfree(mp);
  4207. }
  4208. mempool_free(mbox, phba->mbox_mem_pool);
  4209. }
  4210. out:
  4211. if (ndlp && NLP_CHK_NODE_ACT(ndlp) && shost) {
  4212. spin_lock_irq(shost->host_lock);
  4213. ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
  4214. spin_unlock_irq(shost->host_lock);
  4215. /* If the node is not being used by another discovery thread,
  4216. * and we are sending a reject, we are done with it.
  4217. * Release driver reference count here and free associated
  4218. * resources.
  4219. */
  4220. if (ls_rjt)
  4221. if (lpfc_nlp_not_used(ndlp))
  4222. /* Indicate node has already been released,
  4223. * should not reference to it from within
  4224. * the routine lpfc_els_free_iocb.
  4225. */
  4226. cmdiocb->context1 = NULL;
  4227. }
  4228. lpfc_els_free_iocb(phba, cmdiocb);
  4229. return;
  4230. }
  4231. /**
  4232. * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
  4233. * @vport: pointer to a host virtual N_Port data structure.
  4234. * @flag: the els command code to be accepted.
  4235. * @oldiocb: pointer to the original lpfc command iocb data structure.
  4236. * @ndlp: pointer to a node-list data structure.
  4237. * @mbox: pointer to the driver internal queue element for mailbox command.
  4238. *
  4239. * This routine prepares and issues an Accept (ACC) response IOCB
  4240. * command. It uses the @flag to properly set up the IOCB field for the
  4241. * specific ACC response command to be issued and invokes the
  4242. * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
  4243. * @mbox pointer is passed in, it will be put into the context_un.mbox
  4244. * field of the IOCB for the completion callback function to issue the
  4245. * mailbox command to the HBA later when callback is invoked.
  4246. *
  4247. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4248. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4249. * will be stored into the context1 field of the IOCB for the completion
  4250. * callback function to the corresponding response ELS IOCB command.
  4251. *
  4252. * Return code
  4253. * 0 - Successfully issued acc response
  4254. * 1 - Failed to issue acc response
  4255. **/
  4256. int
  4257. lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
  4258. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  4259. LPFC_MBOXQ_t *mbox)
  4260. {
  4261. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4262. struct lpfc_hba *phba = vport->phba;
  4263. IOCB_t *icmd;
  4264. IOCB_t *oldcmd;
  4265. struct lpfc_iocbq *elsiocb;
  4266. uint8_t *pcmd;
  4267. struct serv_parm *sp;
  4268. uint16_t cmdsize;
  4269. int rc;
  4270. ELS_PKT *els_pkt_ptr;
  4271. oldcmd = &oldiocb->iocb;
  4272. switch (flag) {
  4273. case ELS_CMD_ACC:
  4274. cmdsize = sizeof(uint32_t);
  4275. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  4276. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  4277. if (!elsiocb) {
  4278. spin_lock_irq(shost->host_lock);
  4279. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  4280. spin_unlock_irq(shost->host_lock);
  4281. return 1;
  4282. }
  4283. icmd = &elsiocb->iocb;
  4284. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  4285. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  4286. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4287. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4288. pcmd += sizeof(uint32_t);
  4289. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4290. "Issue ACC: did:x%x flg:x%x",
  4291. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  4292. break;
  4293. case ELS_CMD_FLOGI:
  4294. case ELS_CMD_PLOGI:
  4295. cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
  4296. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  4297. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  4298. if (!elsiocb)
  4299. return 1;
  4300. icmd = &elsiocb->iocb;
  4301. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  4302. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  4303. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4304. if (mbox)
  4305. elsiocb->context_un.mbox = mbox;
  4306. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4307. pcmd += sizeof(uint32_t);
  4308. sp = (struct serv_parm *)pcmd;
  4309. if (flag == ELS_CMD_FLOGI) {
  4310. /* Copy the received service parameters back */
  4311. memcpy(sp, &phba->fc_fabparam,
  4312. sizeof(struct serv_parm));
  4313. /* Clear the F_Port bit */
  4314. sp->cmn.fPort = 0;
  4315. /* Mark all class service parameters as invalid */
  4316. sp->cls1.classValid = 0;
  4317. sp->cls2.classValid = 0;
  4318. sp->cls3.classValid = 0;
  4319. sp->cls4.classValid = 0;
  4320. /* Copy our worldwide names */
  4321. memcpy(&sp->portName, &vport->fc_sparam.portName,
  4322. sizeof(struct lpfc_name));
  4323. memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
  4324. sizeof(struct lpfc_name));
  4325. } else {
  4326. memcpy(pcmd, &vport->fc_sparam,
  4327. sizeof(struct serv_parm));
  4328. sp->cmn.valid_vendor_ver_level = 0;
  4329. memset(sp->un.vendorVersion, 0,
  4330. sizeof(sp->un.vendorVersion));
  4331. sp->cmn.bbRcvSizeMsb &= 0xF;
  4332. /* If our firmware supports this feature, convey that
  4333. * info to the target using the vendor specific field.
  4334. */
  4335. if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
  4336. sp->cmn.valid_vendor_ver_level = 1;
  4337. sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
  4338. sp->un.vv.flags =
  4339. cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
  4340. }
  4341. }
  4342. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4343. "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
  4344. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  4345. break;
  4346. case ELS_CMD_PRLO:
  4347. cmdsize = sizeof(uint32_t) + sizeof(PRLO);
  4348. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  4349. ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
  4350. if (!elsiocb)
  4351. return 1;
  4352. icmd = &elsiocb->iocb;
  4353. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  4354. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  4355. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4356. memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
  4357. sizeof(uint32_t) + sizeof(PRLO));
  4358. *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
  4359. els_pkt_ptr = (ELS_PKT *) pcmd;
  4360. els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
  4361. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4362. "Issue ACC PRLO: did:x%x flg:x%x",
  4363. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  4364. break;
  4365. default:
  4366. return 1;
  4367. }
  4368. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  4369. spin_lock_irq(shost->host_lock);
  4370. if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
  4371. ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
  4372. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  4373. spin_unlock_irq(shost->host_lock);
  4374. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
  4375. } else {
  4376. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4377. }
  4378. phba->fc_stat.elsXmitACC++;
  4379. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  4380. if (rc == IOCB_ERROR) {
  4381. lpfc_els_free_iocb(phba, elsiocb);
  4382. return 1;
  4383. }
  4384. return 0;
  4385. }
  4386. /**
  4387. * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
  4388. * @vport: pointer to a virtual N_Port data structure.
  4389. * @rejectError:
  4390. * @oldiocb: pointer to the original lpfc command iocb data structure.
  4391. * @ndlp: pointer to a node-list data structure.
  4392. * @mbox: pointer to the driver internal queue element for mailbox command.
  4393. *
  4394. * This routine prepares and issue an Reject (RJT) response IOCB
  4395. * command. If a @mbox pointer is passed in, it will be put into the
  4396. * context_un.mbox field of the IOCB for the completion callback function
  4397. * to issue to the HBA later.
  4398. *
  4399. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4400. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4401. * will be stored into the context1 field of the IOCB for the completion
  4402. * callback function to the reject response ELS IOCB command.
  4403. *
  4404. * Return code
  4405. * 0 - Successfully issued reject response
  4406. * 1 - Failed to issue reject response
  4407. **/
  4408. int
  4409. lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
  4410. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  4411. LPFC_MBOXQ_t *mbox)
  4412. {
  4413. struct lpfc_hba *phba = vport->phba;
  4414. IOCB_t *icmd;
  4415. IOCB_t *oldcmd;
  4416. struct lpfc_iocbq *elsiocb;
  4417. uint8_t *pcmd;
  4418. uint16_t cmdsize;
  4419. int rc;
  4420. cmdsize = 2 * sizeof(uint32_t);
  4421. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  4422. ndlp->nlp_DID, ELS_CMD_LS_RJT);
  4423. if (!elsiocb)
  4424. return 1;
  4425. icmd = &elsiocb->iocb;
  4426. oldcmd = &oldiocb->iocb;
  4427. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  4428. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  4429. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4430. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  4431. pcmd += sizeof(uint32_t);
  4432. *((uint32_t *) (pcmd)) = rejectError;
  4433. if (mbox)
  4434. elsiocb->context_un.mbox = mbox;
  4435. /* Xmit ELS RJT <err> response tag <ulpIoTag> */
  4436. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4437. "0129 Xmit ELS RJT x%x response tag x%x "
  4438. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  4439. "rpi x%x\n",
  4440. rejectError, elsiocb->iotag,
  4441. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  4442. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  4443. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4444. "Issue LS_RJT: did:x%x flg:x%x err:x%x",
  4445. ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
  4446. phba->fc_stat.elsXmitLSRJT++;
  4447. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4448. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  4449. if (rc == IOCB_ERROR) {
  4450. lpfc_els_free_iocb(phba, elsiocb);
  4451. return 1;
  4452. }
  4453. return 0;
  4454. }
  4455. /**
  4456. * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
  4457. * @vport: pointer to a virtual N_Port data structure.
  4458. * @oldiocb: pointer to the original lpfc command iocb data structure.
  4459. * @ndlp: pointer to a node-list data structure.
  4460. *
  4461. * This routine prepares and issues an Accept (ACC) response to Address
  4462. * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
  4463. * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
  4464. *
  4465. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4466. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4467. * will be stored into the context1 field of the IOCB for the completion
  4468. * callback function to the ADISC Accept response ELS IOCB command.
  4469. *
  4470. * Return code
  4471. * 0 - Successfully issued acc adisc response
  4472. * 1 - Failed to issue adisc acc response
  4473. **/
  4474. int
  4475. lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  4476. struct lpfc_nodelist *ndlp)
  4477. {
  4478. struct lpfc_hba *phba = vport->phba;
  4479. ADISC *ap;
  4480. IOCB_t *icmd, *oldcmd;
  4481. struct lpfc_iocbq *elsiocb;
  4482. uint8_t *pcmd;
  4483. uint16_t cmdsize;
  4484. int rc;
  4485. cmdsize = sizeof(uint32_t) + sizeof(ADISC);
  4486. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  4487. ndlp->nlp_DID, ELS_CMD_ACC);
  4488. if (!elsiocb)
  4489. return 1;
  4490. icmd = &elsiocb->iocb;
  4491. oldcmd = &oldiocb->iocb;
  4492. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  4493. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  4494. /* Xmit ADISC ACC response tag <ulpIoTag> */
  4495. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4496. "0130 Xmit ADISC ACC response iotag x%x xri: "
  4497. "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
  4498. elsiocb->iotag, elsiocb->iocb.ulpContext,
  4499. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4500. ndlp->nlp_rpi);
  4501. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4502. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4503. pcmd += sizeof(uint32_t);
  4504. ap = (ADISC *) (pcmd);
  4505. ap->hardAL_PA = phba->fc_pref_ALPA;
  4506. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  4507. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  4508. ap->DID = be32_to_cpu(vport->fc_myDID);
  4509. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4510. "Issue ACC ADISC: did:x%x flg:x%x",
  4511. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  4512. phba->fc_stat.elsXmitACC++;
  4513. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4514. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  4515. if (rc == IOCB_ERROR) {
  4516. lpfc_els_free_iocb(phba, elsiocb);
  4517. return 1;
  4518. }
  4519. /* Xmit ELS ACC response tag <ulpIoTag> */
  4520. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4521. "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
  4522. "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
  4523. "RPI: x%x, fc_flag x%x\n",
  4524. rc, elsiocb->iotag, elsiocb->sli4_xritag,
  4525. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4526. ndlp->nlp_rpi, vport->fc_flag);
  4527. return 0;
  4528. }
  4529. /**
  4530. * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
  4531. * @vport: pointer to a virtual N_Port data structure.
  4532. * @oldiocb: pointer to the original lpfc command iocb data structure.
  4533. * @ndlp: pointer to a node-list data structure.
  4534. *
  4535. * This routine prepares and issues an Accept (ACC) response to Process
  4536. * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
  4537. * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
  4538. *
  4539. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4540. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4541. * will be stored into the context1 field of the IOCB for the completion
  4542. * callback function to the PRLI Accept response ELS IOCB command.
  4543. *
  4544. * Return code
  4545. * 0 - Successfully issued acc prli response
  4546. * 1 - Failed to issue acc prli response
  4547. **/
  4548. int
  4549. lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  4550. struct lpfc_nodelist *ndlp)
  4551. {
  4552. struct lpfc_hba *phba = vport->phba;
  4553. PRLI *npr;
  4554. struct lpfc_nvme_prli *npr_nvme;
  4555. lpfc_vpd_t *vpd;
  4556. IOCB_t *icmd;
  4557. IOCB_t *oldcmd;
  4558. struct lpfc_iocbq *elsiocb;
  4559. uint8_t *pcmd;
  4560. uint16_t cmdsize;
  4561. uint32_t prli_fc4_req, *req_payload;
  4562. struct lpfc_dmabuf *req_buf;
  4563. int rc;
  4564. u32 elsrspcmd;
  4565. /* Need the incoming PRLI payload to determine if the ACC is for an
  4566. * FC4 or NVME PRLI type. The PRLI type is at word 1.
  4567. */
  4568. req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
  4569. req_payload = (((uint32_t *)req_buf->virt) + 1);
  4570. /* PRLI type payload is at byte 3 for FCP or NVME. */
  4571. prli_fc4_req = be32_to_cpu(*req_payload);
  4572. prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
  4573. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4574. "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
  4575. prli_fc4_req, *((uint32_t *)req_payload));
  4576. if (prli_fc4_req == PRLI_FCP_TYPE) {
  4577. cmdsize = sizeof(uint32_t) + sizeof(PRLI);
  4578. elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
  4579. } else if (prli_fc4_req & PRLI_NVME_TYPE) {
  4580. cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
  4581. elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
  4582. } else {
  4583. return 1;
  4584. }
  4585. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  4586. ndlp->nlp_DID, elsrspcmd);
  4587. if (!elsiocb)
  4588. return 1;
  4589. icmd = &elsiocb->iocb;
  4590. oldcmd = &oldiocb->iocb;
  4591. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  4592. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  4593. /* Xmit PRLI ACC response tag <ulpIoTag> */
  4594. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4595. "0131 Xmit PRLI ACC response tag x%x xri x%x, "
  4596. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  4597. elsiocb->iotag, elsiocb->iocb.ulpContext,
  4598. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4599. ndlp->nlp_rpi);
  4600. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4601. memset(pcmd, 0, cmdsize);
  4602. *((uint32_t *)(pcmd)) = elsrspcmd;
  4603. pcmd += sizeof(uint32_t);
  4604. /* For PRLI, remainder of payload is PRLI parameter page */
  4605. vpd = &phba->vpd;
  4606. if (prli_fc4_req == PRLI_FCP_TYPE) {
  4607. /*
  4608. * If the remote port is a target and our firmware version
  4609. * is 3.20 or later, set the following bits for FC-TAPE
  4610. * support.
  4611. */
  4612. npr = (PRLI *) pcmd;
  4613. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  4614. (vpd->rev.feaLevelHigh >= 0x02)) {
  4615. npr->ConfmComplAllowed = 1;
  4616. npr->Retry = 1;
  4617. npr->TaskRetryIdReq = 1;
  4618. }
  4619. npr->acceptRspCode = PRLI_REQ_EXECUTED;
  4620. npr->estabImagePair = 1;
  4621. npr->readXferRdyDis = 1;
  4622. npr->ConfmComplAllowed = 1;
  4623. npr->prliType = PRLI_FCP_TYPE;
  4624. npr->initiatorFunc = 1;
  4625. } else if (prli_fc4_req & PRLI_NVME_TYPE) {
  4626. /* Respond with an NVME PRLI Type */
  4627. npr_nvme = (struct lpfc_nvme_prli *) pcmd;
  4628. bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
  4629. bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
  4630. bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
  4631. if (phba->nvmet_support) {
  4632. bf_set(prli_tgt, npr_nvme, 1);
  4633. bf_set(prli_disc, npr_nvme, 1);
  4634. if (phba->cfg_nvme_enable_fb) {
  4635. bf_set(prli_fba, npr_nvme, 1);
  4636. /* TBD. Target mode needs to post buffers
  4637. * that support the configured first burst
  4638. * byte size.
  4639. */
  4640. bf_set(prli_fb_sz, npr_nvme,
  4641. phba->cfg_nvmet_fb_size);
  4642. }
  4643. } else {
  4644. bf_set(prli_init, npr_nvme, 1);
  4645. }
  4646. lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
  4647. "6015 NVME issue PRLI ACC word1 x%08x "
  4648. "word4 x%08x word5 x%08x flag x%x, "
  4649. "fcp_info x%x nlp_type x%x\n",
  4650. npr_nvme->word1, npr_nvme->word4,
  4651. npr_nvme->word5, ndlp->nlp_flag,
  4652. ndlp->nlp_fcp_info, ndlp->nlp_type);
  4653. npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
  4654. npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
  4655. npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
  4656. } else
  4657. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4658. "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
  4659. prli_fc4_req, ndlp->nlp_fc4_type,
  4660. ndlp->nlp_DID);
  4661. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4662. "Issue ACC PRLI: did:x%x flg:x%x",
  4663. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  4664. phba->fc_stat.elsXmitACC++;
  4665. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4666. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  4667. if (rc == IOCB_ERROR) {
  4668. lpfc_els_free_iocb(phba, elsiocb);
  4669. return 1;
  4670. }
  4671. return 0;
  4672. }
  4673. /**
  4674. * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
  4675. * @vport: pointer to a virtual N_Port data structure.
  4676. * @format: rnid command format.
  4677. * @oldiocb: pointer to the original lpfc command iocb data structure.
  4678. * @ndlp: pointer to a node-list data structure.
  4679. *
  4680. * This routine issues a Request Node Identification Data (RNID) Accept
  4681. * (ACC) response. It constructs the RNID ACC response command according to
  4682. * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
  4683. * issue the response. Note that this command does not need to hold the ndlp
  4684. * reference count for the callback. So, the ndlp reference count taken by
  4685. * the lpfc_prep_els_iocb() routine is put back and the context1 field of
  4686. * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
  4687. * there is no ndlp reference available.
  4688. *
  4689. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4690. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4691. * will be stored into the context1 field of the IOCB for the completion
  4692. * callback function. However, for the RNID Accept Response ELS command,
  4693. * this is undone later by this routine after the IOCB is allocated.
  4694. *
  4695. * Return code
  4696. * 0 - Successfully issued acc rnid response
  4697. * 1 - Failed to issue acc rnid response
  4698. **/
  4699. static int
  4700. lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
  4701. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  4702. {
  4703. struct lpfc_hba *phba = vport->phba;
  4704. RNID *rn;
  4705. IOCB_t *icmd, *oldcmd;
  4706. struct lpfc_iocbq *elsiocb;
  4707. uint8_t *pcmd;
  4708. uint16_t cmdsize;
  4709. int rc;
  4710. cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
  4711. + (2 * sizeof(struct lpfc_name));
  4712. if (format)
  4713. cmdsize += sizeof(RNID_TOP_DISC);
  4714. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  4715. ndlp->nlp_DID, ELS_CMD_ACC);
  4716. if (!elsiocb)
  4717. return 1;
  4718. icmd = &elsiocb->iocb;
  4719. oldcmd = &oldiocb->iocb;
  4720. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  4721. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  4722. /* Xmit RNID ACC response tag <ulpIoTag> */
  4723. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4724. "0132 Xmit RNID ACC response tag x%x xri x%x\n",
  4725. elsiocb->iotag, elsiocb->iocb.ulpContext);
  4726. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4727. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4728. pcmd += sizeof(uint32_t);
  4729. memset(pcmd, 0, sizeof(RNID));
  4730. rn = (RNID *) (pcmd);
  4731. rn->Format = format;
  4732. rn->CommonLen = (2 * sizeof(struct lpfc_name));
  4733. memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  4734. memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  4735. switch (format) {
  4736. case 0:
  4737. rn->SpecificLen = 0;
  4738. break;
  4739. case RNID_TOPOLOGY_DISC:
  4740. rn->SpecificLen = sizeof(RNID_TOP_DISC);
  4741. memcpy(&rn->un.topologyDisc.portName,
  4742. &vport->fc_portname, sizeof(struct lpfc_name));
  4743. rn->un.topologyDisc.unitType = RNID_HBA;
  4744. rn->un.topologyDisc.physPort = 0;
  4745. rn->un.topologyDisc.attachedNodes = 0;
  4746. break;
  4747. default:
  4748. rn->CommonLen = 0;
  4749. rn->SpecificLen = 0;
  4750. break;
  4751. }
  4752. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4753. "Issue ACC RNID: did:x%x flg:x%x",
  4754. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  4755. phba->fc_stat.elsXmitACC++;
  4756. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4757. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  4758. if (rc == IOCB_ERROR) {
  4759. lpfc_els_free_iocb(phba, elsiocb);
  4760. return 1;
  4761. }
  4762. return 0;
  4763. }
  4764. /**
  4765. * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
  4766. * @vport: pointer to a virtual N_Port data structure.
  4767. * @iocb: pointer to the lpfc command iocb data structure.
  4768. * @ndlp: pointer to a node-list data structure.
  4769. *
  4770. * Return
  4771. **/
  4772. static void
  4773. lpfc_els_clear_rrq(struct lpfc_vport *vport,
  4774. struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
  4775. {
  4776. struct lpfc_hba *phba = vport->phba;
  4777. uint8_t *pcmd;
  4778. struct RRQ *rrq;
  4779. uint16_t rxid;
  4780. uint16_t xri;
  4781. struct lpfc_node_rrq *prrq;
  4782. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
  4783. pcmd += sizeof(uint32_t);
  4784. rrq = (struct RRQ *)pcmd;
  4785. rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
  4786. rxid = bf_get(rrq_rxid, rrq);
  4787. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4788. "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
  4789. " x%x x%x\n",
  4790. be32_to_cpu(bf_get(rrq_did, rrq)),
  4791. bf_get(rrq_oxid, rrq),
  4792. rxid,
  4793. iocb->iotag, iocb->iocb.ulpContext);
  4794. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4795. "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
  4796. ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
  4797. if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
  4798. xri = bf_get(rrq_oxid, rrq);
  4799. else
  4800. xri = rxid;
  4801. prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
  4802. if (prrq)
  4803. lpfc_clr_rrq_active(phba, xri, prrq);
  4804. return;
  4805. }
  4806. /**
  4807. * lpfc_els_rsp_echo_acc - Issue echo acc response
  4808. * @vport: pointer to a virtual N_Port data structure.
  4809. * @data: pointer to echo data to return in the accept.
  4810. * @oldiocb: pointer to the original lpfc command iocb data structure.
  4811. * @ndlp: pointer to a node-list data structure.
  4812. *
  4813. * Return code
  4814. * 0 - Successfully issued acc echo response
  4815. * 1 - Failed to issue acc echo response
  4816. **/
  4817. static int
  4818. lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
  4819. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  4820. {
  4821. struct lpfc_hba *phba = vport->phba;
  4822. struct lpfc_iocbq *elsiocb;
  4823. uint8_t *pcmd;
  4824. uint16_t cmdsize;
  4825. int rc;
  4826. cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
  4827. /* The accumulated length can exceed the BPL_SIZE. For
  4828. * now, use this as the limit
  4829. */
  4830. if (cmdsize > LPFC_BPL_SIZE)
  4831. cmdsize = LPFC_BPL_SIZE;
  4832. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  4833. ndlp->nlp_DID, ELS_CMD_ACC);
  4834. if (!elsiocb)
  4835. return 1;
  4836. elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
  4837. elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
  4838. /* Xmit ECHO ACC response tag <ulpIoTag> */
  4839. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4840. "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
  4841. elsiocb->iotag, elsiocb->iocb.ulpContext);
  4842. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4843. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4844. pcmd += sizeof(uint32_t);
  4845. memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
  4846. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4847. "Issue ACC ECHO: did:x%x flg:x%x",
  4848. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  4849. phba->fc_stat.elsXmitACC++;
  4850. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4851. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  4852. if (rc == IOCB_ERROR) {
  4853. lpfc_els_free_iocb(phba, elsiocb);
  4854. return 1;
  4855. }
  4856. return 0;
  4857. }
  4858. /**
  4859. * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
  4860. * @vport: pointer to a host virtual N_Port data structure.
  4861. *
  4862. * This routine issues Address Discover (ADISC) ELS commands to those
  4863. * N_Ports which are in node port recovery state and ADISC has not been issued
  4864. * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
  4865. * lpfc_issue_els_adisc() routine, the per @vport number of discover count
  4866. * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
  4867. * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
  4868. * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
  4869. * IOCBs quit for later pick up. On the other hand, after walking through
  4870. * all the ndlps with the @vport and there is none ADISC IOCB issued, the
  4871. * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
  4872. * no more ADISC need to be sent.
  4873. *
  4874. * Return code
  4875. * The number of N_Ports with adisc issued.
  4876. **/
  4877. int
  4878. lpfc_els_disc_adisc(struct lpfc_vport *vport)
  4879. {
  4880. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4881. struct lpfc_nodelist *ndlp, *next_ndlp;
  4882. int sentadisc = 0;
  4883. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  4884. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  4885. if (!NLP_CHK_NODE_ACT(ndlp))
  4886. continue;
  4887. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  4888. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  4889. (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
  4890. spin_lock_irq(shost->host_lock);
  4891. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  4892. spin_unlock_irq(shost->host_lock);
  4893. ndlp->nlp_prev_state = ndlp->nlp_state;
  4894. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  4895. lpfc_issue_els_adisc(vport, ndlp, 0);
  4896. sentadisc++;
  4897. vport->num_disc_nodes++;
  4898. if (vport->num_disc_nodes >=
  4899. vport->cfg_discovery_threads) {
  4900. spin_lock_irq(shost->host_lock);
  4901. vport->fc_flag |= FC_NLP_MORE;
  4902. spin_unlock_irq(shost->host_lock);
  4903. break;
  4904. }
  4905. }
  4906. }
  4907. if (sentadisc == 0) {
  4908. spin_lock_irq(shost->host_lock);
  4909. vport->fc_flag &= ~FC_NLP_MORE;
  4910. spin_unlock_irq(shost->host_lock);
  4911. }
  4912. return sentadisc;
  4913. }
  4914. /**
  4915. * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
  4916. * @vport: pointer to a host virtual N_Port data structure.
  4917. *
  4918. * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
  4919. * which are in node port recovery state, with a @vport. Each time an ELS
  4920. * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
  4921. * the per @vport number of discover count (num_disc_nodes) shall be
  4922. * incremented. If the num_disc_nodes reaches a pre-configured threshold
  4923. * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
  4924. * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
  4925. * later pick up. On the other hand, after walking through all the ndlps with
  4926. * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
  4927. * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
  4928. * PLOGI need to be sent.
  4929. *
  4930. * Return code
  4931. * The number of N_Ports with plogi issued.
  4932. **/
  4933. int
  4934. lpfc_els_disc_plogi(struct lpfc_vport *vport)
  4935. {
  4936. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4937. struct lpfc_nodelist *ndlp, *next_ndlp;
  4938. int sentplogi = 0;
  4939. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  4940. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  4941. if (!NLP_CHK_NODE_ACT(ndlp))
  4942. continue;
  4943. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  4944. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  4945. (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
  4946. (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
  4947. ndlp->nlp_prev_state = ndlp->nlp_state;
  4948. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  4949. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  4950. sentplogi++;
  4951. vport->num_disc_nodes++;
  4952. if (vport->num_disc_nodes >=
  4953. vport->cfg_discovery_threads) {
  4954. spin_lock_irq(shost->host_lock);
  4955. vport->fc_flag |= FC_NLP_MORE;
  4956. spin_unlock_irq(shost->host_lock);
  4957. break;
  4958. }
  4959. }
  4960. }
  4961. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4962. "6452 Discover PLOGI %d flag x%x\n",
  4963. sentplogi, vport->fc_flag);
  4964. if (sentplogi) {
  4965. lpfc_set_disctmo(vport);
  4966. }
  4967. else {
  4968. spin_lock_irq(shost->host_lock);
  4969. vport->fc_flag &= ~FC_NLP_MORE;
  4970. spin_unlock_irq(shost->host_lock);
  4971. }
  4972. return sentplogi;
  4973. }
  4974. static uint32_t
  4975. lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
  4976. uint32_t word0)
  4977. {
  4978. desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
  4979. desc->payload.els_req = word0;
  4980. desc->length = cpu_to_be32(sizeof(desc->payload));
  4981. return sizeof(struct fc_rdp_link_service_desc);
  4982. }
  4983. static uint32_t
  4984. lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
  4985. uint8_t *page_a0, uint8_t *page_a2)
  4986. {
  4987. uint16_t wavelength;
  4988. uint16_t temperature;
  4989. uint16_t rx_power;
  4990. uint16_t tx_bias;
  4991. uint16_t tx_power;
  4992. uint16_t vcc;
  4993. uint16_t flag = 0;
  4994. struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
  4995. struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
  4996. desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
  4997. trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
  4998. &page_a0[SSF_TRANSCEIVER_CODE_B4];
  4999. trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
  5000. &page_a0[SSF_TRANSCEIVER_CODE_B5];
  5001. if ((trasn_code_byte4->fc_sw_laser) ||
  5002. (trasn_code_byte5->fc_sw_laser_sl) ||
  5003. (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
  5004. flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
  5005. } else if (trasn_code_byte4->fc_lw_laser) {
  5006. wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
  5007. page_a0[SSF_WAVELENGTH_B0];
  5008. if (wavelength == SFP_WAVELENGTH_LC1310)
  5009. flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
  5010. if (wavelength == SFP_WAVELENGTH_LL1550)
  5011. flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
  5012. }
  5013. /* check if its SFP+ */
  5014. flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
  5015. SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
  5016. << SFP_FLAG_CT_SHIFT;
  5017. /* check if its OPTICAL */
  5018. flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
  5019. SFP_FLAG_IS_OPTICAL_PORT : 0)
  5020. << SFP_FLAG_IS_OPTICAL_SHIFT;
  5021. temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
  5022. page_a2[SFF_TEMPERATURE_B0]);
  5023. vcc = (page_a2[SFF_VCC_B1] << 8 |
  5024. page_a2[SFF_VCC_B0]);
  5025. tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
  5026. page_a2[SFF_TXPOWER_B0]);
  5027. tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
  5028. page_a2[SFF_TX_BIAS_CURRENT_B0]);
  5029. rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
  5030. page_a2[SFF_RXPOWER_B0]);
  5031. desc->sfp_info.temperature = cpu_to_be16(temperature);
  5032. desc->sfp_info.rx_power = cpu_to_be16(rx_power);
  5033. desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
  5034. desc->sfp_info.tx_power = cpu_to_be16(tx_power);
  5035. desc->sfp_info.vcc = cpu_to_be16(vcc);
  5036. desc->sfp_info.flags = cpu_to_be16(flag);
  5037. desc->length = cpu_to_be32(sizeof(desc->sfp_info));
  5038. return sizeof(struct fc_rdp_sfp_desc);
  5039. }
  5040. static uint32_t
  5041. lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
  5042. READ_LNK_VAR *stat)
  5043. {
  5044. uint32_t type;
  5045. desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
  5046. type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
  5047. desc->info.port_type = cpu_to_be32(type);
  5048. desc->info.link_status.link_failure_cnt =
  5049. cpu_to_be32(stat->linkFailureCnt);
  5050. desc->info.link_status.loss_of_synch_cnt =
  5051. cpu_to_be32(stat->lossSyncCnt);
  5052. desc->info.link_status.loss_of_signal_cnt =
  5053. cpu_to_be32(stat->lossSignalCnt);
  5054. desc->info.link_status.primitive_seq_proto_err =
  5055. cpu_to_be32(stat->primSeqErrCnt);
  5056. desc->info.link_status.invalid_trans_word =
  5057. cpu_to_be32(stat->invalidXmitWord);
  5058. desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
  5059. desc->length = cpu_to_be32(sizeof(desc->info));
  5060. return sizeof(struct fc_rdp_link_error_status_desc);
  5061. }
  5062. static uint32_t
  5063. lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
  5064. struct lpfc_vport *vport)
  5065. {
  5066. uint32_t bbCredit;
  5067. desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
  5068. bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
  5069. (vport->fc_sparam.cmn.bbCreditMsb << 8);
  5070. desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
  5071. if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
  5072. bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
  5073. (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
  5074. desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
  5075. } else {
  5076. desc->bbc_info.attached_port_bbc = 0;
  5077. }
  5078. desc->bbc_info.rtt = 0;
  5079. desc->length = cpu_to_be32(sizeof(desc->bbc_info));
  5080. return sizeof(struct fc_rdp_bbc_desc);
  5081. }
  5082. static uint32_t
  5083. lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
  5084. struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
  5085. {
  5086. uint32_t flags = 0;
  5087. desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
  5088. desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
  5089. desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
  5090. desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
  5091. desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
  5092. if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
  5093. flags |= RDP_OET_HIGH_ALARM;
  5094. if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
  5095. flags |= RDP_OET_LOW_ALARM;
  5096. if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
  5097. flags |= RDP_OET_HIGH_WARNING;
  5098. if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
  5099. flags |= RDP_OET_LOW_WARNING;
  5100. flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
  5101. desc->oed_info.function_flags = cpu_to_be32(flags);
  5102. desc->length = cpu_to_be32(sizeof(desc->oed_info));
  5103. return sizeof(struct fc_rdp_oed_sfp_desc);
  5104. }
  5105. static uint32_t
  5106. lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
  5107. struct fc_rdp_oed_sfp_desc *desc,
  5108. uint8_t *page_a2)
  5109. {
  5110. uint32_t flags = 0;
  5111. desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
  5112. desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
  5113. desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
  5114. desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
  5115. desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
  5116. if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
  5117. flags |= RDP_OET_HIGH_ALARM;
  5118. if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
  5119. flags |= RDP_OET_LOW_ALARM;
  5120. if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
  5121. flags |= RDP_OET_HIGH_WARNING;
  5122. if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
  5123. flags |= RDP_OET_LOW_WARNING;
  5124. flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
  5125. desc->oed_info.function_flags = cpu_to_be32(flags);
  5126. desc->length = cpu_to_be32(sizeof(desc->oed_info));
  5127. return sizeof(struct fc_rdp_oed_sfp_desc);
  5128. }
  5129. static uint32_t
  5130. lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
  5131. struct fc_rdp_oed_sfp_desc *desc,
  5132. uint8_t *page_a2)
  5133. {
  5134. uint32_t flags = 0;
  5135. desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
  5136. desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
  5137. desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
  5138. desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
  5139. desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
  5140. if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
  5141. flags |= RDP_OET_HIGH_ALARM;
  5142. if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
  5143. flags |= RDP_OET_LOW_ALARM;
  5144. if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
  5145. flags |= RDP_OET_HIGH_WARNING;
  5146. if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
  5147. flags |= RDP_OET_LOW_WARNING;
  5148. flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
  5149. desc->oed_info.function_flags = cpu_to_be32(flags);
  5150. desc->length = cpu_to_be32(sizeof(desc->oed_info));
  5151. return sizeof(struct fc_rdp_oed_sfp_desc);
  5152. }
  5153. static uint32_t
  5154. lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
  5155. struct fc_rdp_oed_sfp_desc *desc,
  5156. uint8_t *page_a2)
  5157. {
  5158. uint32_t flags = 0;
  5159. desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
  5160. desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
  5161. desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
  5162. desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
  5163. desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
  5164. if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
  5165. flags |= RDP_OET_HIGH_ALARM;
  5166. if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
  5167. flags |= RDP_OET_LOW_ALARM;
  5168. if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
  5169. flags |= RDP_OET_HIGH_WARNING;
  5170. if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
  5171. flags |= RDP_OET_LOW_WARNING;
  5172. flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
  5173. desc->oed_info.function_flags = cpu_to_be32(flags);
  5174. desc->length = cpu_to_be32(sizeof(desc->oed_info));
  5175. return sizeof(struct fc_rdp_oed_sfp_desc);
  5176. }
  5177. static uint32_t
  5178. lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
  5179. struct fc_rdp_oed_sfp_desc *desc,
  5180. uint8_t *page_a2)
  5181. {
  5182. uint32_t flags = 0;
  5183. desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
  5184. desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
  5185. desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
  5186. desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
  5187. desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
  5188. if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
  5189. flags |= RDP_OET_HIGH_ALARM;
  5190. if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
  5191. flags |= RDP_OET_LOW_ALARM;
  5192. if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
  5193. flags |= RDP_OET_HIGH_WARNING;
  5194. if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
  5195. flags |= RDP_OET_LOW_WARNING;
  5196. flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
  5197. desc->oed_info.function_flags = cpu_to_be32(flags);
  5198. desc->length = cpu_to_be32(sizeof(desc->oed_info));
  5199. return sizeof(struct fc_rdp_oed_sfp_desc);
  5200. }
  5201. static uint32_t
  5202. lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
  5203. uint8_t *page_a0, struct lpfc_vport *vport)
  5204. {
  5205. desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
  5206. memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
  5207. memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
  5208. memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
  5209. memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
  5210. memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
  5211. desc->length = cpu_to_be32(sizeof(desc->opd_info));
  5212. return sizeof(struct fc_rdp_opd_sfp_desc);
  5213. }
  5214. static uint32_t
  5215. lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
  5216. {
  5217. if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
  5218. return 0;
  5219. desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
  5220. desc->info.CorrectedBlocks =
  5221. cpu_to_be32(stat->fecCorrBlkCount);
  5222. desc->info.UncorrectableBlocks =
  5223. cpu_to_be32(stat->fecUncorrBlkCount);
  5224. desc->length = cpu_to_be32(sizeof(desc->info));
  5225. return sizeof(struct fc_fec_rdp_desc);
  5226. }
  5227. static uint32_t
  5228. lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
  5229. {
  5230. uint16_t rdp_cap = 0;
  5231. uint16_t rdp_speed;
  5232. desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
  5233. switch (phba->fc_linkspeed) {
  5234. case LPFC_LINK_SPEED_1GHZ:
  5235. rdp_speed = RDP_PS_1GB;
  5236. break;
  5237. case LPFC_LINK_SPEED_2GHZ:
  5238. rdp_speed = RDP_PS_2GB;
  5239. break;
  5240. case LPFC_LINK_SPEED_4GHZ:
  5241. rdp_speed = RDP_PS_4GB;
  5242. break;
  5243. case LPFC_LINK_SPEED_8GHZ:
  5244. rdp_speed = RDP_PS_8GB;
  5245. break;
  5246. case LPFC_LINK_SPEED_10GHZ:
  5247. rdp_speed = RDP_PS_10GB;
  5248. break;
  5249. case LPFC_LINK_SPEED_16GHZ:
  5250. rdp_speed = RDP_PS_16GB;
  5251. break;
  5252. case LPFC_LINK_SPEED_32GHZ:
  5253. rdp_speed = RDP_PS_32GB;
  5254. break;
  5255. case LPFC_LINK_SPEED_64GHZ:
  5256. rdp_speed = RDP_PS_64GB;
  5257. break;
  5258. default:
  5259. rdp_speed = RDP_PS_UNKNOWN;
  5260. break;
  5261. }
  5262. desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
  5263. if (phba->lmt & LMT_128Gb)
  5264. rdp_cap |= RDP_PS_128GB;
  5265. if (phba->lmt & LMT_64Gb)
  5266. rdp_cap |= RDP_PS_64GB;
  5267. if (phba->lmt & LMT_32Gb)
  5268. rdp_cap |= RDP_PS_32GB;
  5269. if (phba->lmt & LMT_16Gb)
  5270. rdp_cap |= RDP_PS_16GB;
  5271. if (phba->lmt & LMT_10Gb)
  5272. rdp_cap |= RDP_PS_10GB;
  5273. if (phba->lmt & LMT_8Gb)
  5274. rdp_cap |= RDP_PS_8GB;
  5275. if (phba->lmt & LMT_4Gb)
  5276. rdp_cap |= RDP_PS_4GB;
  5277. if (phba->lmt & LMT_2Gb)
  5278. rdp_cap |= RDP_PS_2GB;
  5279. if (phba->lmt & LMT_1Gb)
  5280. rdp_cap |= RDP_PS_1GB;
  5281. if (rdp_cap == 0)
  5282. rdp_cap = RDP_CAP_UNKNOWN;
  5283. if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
  5284. rdp_cap |= RDP_CAP_USER_CONFIGURED;
  5285. desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
  5286. desc->length = cpu_to_be32(sizeof(desc->info));
  5287. return sizeof(struct fc_rdp_port_speed_desc);
  5288. }
  5289. static uint32_t
  5290. lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
  5291. struct lpfc_vport *vport)
  5292. {
  5293. desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
  5294. memcpy(desc->port_names.wwnn, &vport->fc_nodename,
  5295. sizeof(desc->port_names.wwnn));
  5296. memcpy(desc->port_names.wwpn, &vport->fc_portname,
  5297. sizeof(desc->port_names.wwpn));
  5298. desc->length = cpu_to_be32(sizeof(desc->port_names));
  5299. return sizeof(struct fc_rdp_port_name_desc);
  5300. }
  5301. static uint32_t
  5302. lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
  5303. struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  5304. {
  5305. desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
  5306. if (vport->fc_flag & FC_FABRIC) {
  5307. memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
  5308. sizeof(desc->port_names.wwnn));
  5309. memcpy(desc->port_names.wwpn, &vport->fabric_portname,
  5310. sizeof(desc->port_names.wwpn));
  5311. } else { /* Point to Point */
  5312. memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
  5313. sizeof(desc->port_names.wwnn));
  5314. memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
  5315. sizeof(desc->port_names.wwpn));
  5316. }
  5317. desc->length = cpu_to_be32(sizeof(desc->port_names));
  5318. return sizeof(struct fc_rdp_port_name_desc);
  5319. }
  5320. static void
  5321. lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
  5322. int status)
  5323. {
  5324. struct lpfc_nodelist *ndlp = rdp_context->ndlp;
  5325. struct lpfc_vport *vport = ndlp->vport;
  5326. struct lpfc_iocbq *elsiocb;
  5327. struct ulp_bde64 *bpl;
  5328. IOCB_t *icmd;
  5329. uint8_t *pcmd;
  5330. struct ls_rjt *stat;
  5331. struct fc_rdp_res_frame *rdp_res;
  5332. uint32_t cmdsize, len;
  5333. uint16_t *flag_ptr;
  5334. int rc;
  5335. if (status != SUCCESS)
  5336. goto error;
  5337. /* This will change once we know the true size of the RDP payload */
  5338. cmdsize = sizeof(struct fc_rdp_res_frame);
  5339. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
  5340. lpfc_max_els_tries, rdp_context->ndlp,
  5341. rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
  5342. lpfc_nlp_put(ndlp);
  5343. if (!elsiocb)
  5344. goto free_rdp_context;
  5345. icmd = &elsiocb->iocb;
  5346. icmd->ulpContext = rdp_context->rx_id;
  5347. icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
  5348. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5349. "2171 Xmit RDP response tag x%x xri x%x, "
  5350. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
  5351. elsiocb->iotag, elsiocb->iocb.ulpContext,
  5352. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  5353. ndlp->nlp_rpi);
  5354. rdp_res = (struct fc_rdp_res_frame *)
  5355. (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  5356. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  5357. memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
  5358. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  5359. /* Update Alarm and Warning */
  5360. flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
  5361. phba->sfp_alarm |= *flag_ptr;
  5362. flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
  5363. phba->sfp_warning |= *flag_ptr;
  5364. /* For RDP payload */
  5365. len = 8;
  5366. len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
  5367. (len + pcmd), ELS_CMD_RDP);
  5368. len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
  5369. rdp_context->page_a0, rdp_context->page_a2);
  5370. len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
  5371. phba);
  5372. len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
  5373. (len + pcmd), &rdp_context->link_stat);
  5374. len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
  5375. (len + pcmd), vport);
  5376. len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
  5377. (len + pcmd), vport, ndlp);
  5378. len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
  5379. &rdp_context->link_stat);
  5380. len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
  5381. &rdp_context->link_stat, vport);
  5382. len += lpfc_rdp_res_oed_temp_desc(phba,
  5383. (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
  5384. rdp_context->page_a2);
  5385. len += lpfc_rdp_res_oed_voltage_desc(phba,
  5386. (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
  5387. rdp_context->page_a2);
  5388. len += lpfc_rdp_res_oed_txbias_desc(phba,
  5389. (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
  5390. rdp_context->page_a2);
  5391. len += lpfc_rdp_res_oed_txpower_desc(phba,
  5392. (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
  5393. rdp_context->page_a2);
  5394. len += lpfc_rdp_res_oed_rxpower_desc(phba,
  5395. (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
  5396. rdp_context->page_a2);
  5397. len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
  5398. rdp_context->page_a0, vport);
  5399. rdp_res->length = cpu_to_be32(len - 8);
  5400. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  5401. /* Now that we know the true size of the payload, update the BPL */
  5402. bpl = (struct ulp_bde64 *)
  5403. (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
  5404. bpl->tus.f.bdeSize = len;
  5405. bpl->tus.f.bdeFlags = 0;
  5406. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  5407. phba->fc_stat.elsXmitACC++;
  5408. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5409. if (rc == IOCB_ERROR)
  5410. lpfc_els_free_iocb(phba, elsiocb);
  5411. kfree(rdp_context);
  5412. return;
  5413. error:
  5414. cmdsize = 2 * sizeof(uint32_t);
  5415. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
  5416. ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
  5417. lpfc_nlp_put(ndlp);
  5418. if (!elsiocb)
  5419. goto free_rdp_context;
  5420. icmd = &elsiocb->iocb;
  5421. icmd->ulpContext = rdp_context->rx_id;
  5422. icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
  5423. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  5424. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  5425. stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
  5426. stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  5427. phba->fc_stat.elsXmitLSRJT++;
  5428. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  5429. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5430. if (rc == IOCB_ERROR)
  5431. lpfc_els_free_iocb(phba, elsiocb);
  5432. free_rdp_context:
  5433. kfree(rdp_context);
  5434. }
  5435. static int
  5436. lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
  5437. {
  5438. LPFC_MBOXQ_t *mbox = NULL;
  5439. int rc;
  5440. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5441. if (!mbox) {
  5442. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
  5443. "7105 failed to allocate mailbox memory");
  5444. return 1;
  5445. }
  5446. if (lpfc_sli4_dump_page_a0(phba, mbox))
  5447. goto prep_mbox_fail;
  5448. mbox->vport = rdp_context->ndlp->vport;
  5449. mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
  5450. mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
  5451. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  5452. if (rc == MBX_NOT_FINISHED)
  5453. goto issue_mbox_fail;
  5454. return 0;
  5455. prep_mbox_fail:
  5456. issue_mbox_fail:
  5457. mempool_free(mbox, phba->mbox_mem_pool);
  5458. return 1;
  5459. }
  5460. /*
  5461. * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
  5462. * @vport: pointer to a host virtual N_Port data structure.
  5463. * @cmdiocb: pointer to lpfc command iocb data structure.
  5464. * @ndlp: pointer to a node-list data structure.
  5465. *
  5466. * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
  5467. * IOCB. First, the payload of the unsolicited RDP is checked.
  5468. * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
  5469. * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
  5470. * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
  5471. * gather all data and send RDP response.
  5472. *
  5473. * Return code
  5474. * 0 - Sent the acc response
  5475. * 1 - Sent the reject response.
  5476. */
  5477. static int
  5478. lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5479. struct lpfc_nodelist *ndlp)
  5480. {
  5481. struct lpfc_hba *phba = vport->phba;
  5482. struct lpfc_dmabuf *pcmd;
  5483. uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
  5484. struct fc_rdp_req_frame *rdp_req;
  5485. struct lpfc_rdp_context *rdp_context;
  5486. IOCB_t *cmd = NULL;
  5487. struct ls_rjt stat;
  5488. if (phba->sli_rev < LPFC_SLI_REV4 ||
  5489. bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
  5490. LPFC_SLI_INTF_IF_TYPE_2) {
  5491. rjt_err = LSRJT_UNABLE_TPC;
  5492. rjt_expl = LSEXP_REQ_UNSUPPORTED;
  5493. goto error;
  5494. }
  5495. if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
  5496. rjt_err = LSRJT_UNABLE_TPC;
  5497. rjt_expl = LSEXP_REQ_UNSUPPORTED;
  5498. goto error;
  5499. }
  5500. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5501. rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
  5502. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5503. "2422 ELS RDP Request "
  5504. "dec len %d tag x%x port_id %d len %d\n",
  5505. be32_to_cpu(rdp_req->rdp_des_length),
  5506. be32_to_cpu(rdp_req->nport_id_desc.tag),
  5507. be32_to_cpu(rdp_req->nport_id_desc.nport_id),
  5508. be32_to_cpu(rdp_req->nport_id_desc.length));
  5509. if (sizeof(struct fc_rdp_nport_desc) !=
  5510. be32_to_cpu(rdp_req->rdp_des_length))
  5511. goto rjt_logerr;
  5512. if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
  5513. goto rjt_logerr;
  5514. if (RDP_NPORT_ID_SIZE !=
  5515. be32_to_cpu(rdp_req->nport_id_desc.length))
  5516. goto rjt_logerr;
  5517. rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
  5518. if (!rdp_context) {
  5519. rjt_err = LSRJT_UNABLE_TPC;
  5520. goto error;
  5521. }
  5522. cmd = &cmdiocb->iocb;
  5523. rdp_context->ndlp = lpfc_nlp_get(ndlp);
  5524. rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
  5525. rdp_context->rx_id = cmd->ulpContext;
  5526. rdp_context->cmpl = lpfc_els_rdp_cmpl;
  5527. if (lpfc_get_rdp_info(phba, rdp_context)) {
  5528. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
  5529. "2423 Unable to send mailbox");
  5530. kfree(rdp_context);
  5531. rjt_err = LSRJT_UNABLE_TPC;
  5532. lpfc_nlp_put(ndlp);
  5533. goto error;
  5534. }
  5535. return 0;
  5536. rjt_logerr:
  5537. rjt_err = LSRJT_LOGICAL_ERR;
  5538. error:
  5539. memset(&stat, 0, sizeof(stat));
  5540. stat.un.b.lsRjtRsnCode = rjt_err;
  5541. stat.un.b.lsRjtRsnCodeExp = rjt_expl;
  5542. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  5543. return 1;
  5544. }
  5545. static void
  5546. lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  5547. {
  5548. MAILBOX_t *mb;
  5549. IOCB_t *icmd;
  5550. uint8_t *pcmd;
  5551. struct lpfc_iocbq *elsiocb;
  5552. struct lpfc_nodelist *ndlp;
  5553. struct ls_rjt *stat;
  5554. union lpfc_sli4_cfg_shdr *shdr;
  5555. struct lpfc_lcb_context *lcb_context;
  5556. struct fc_lcb_res_frame *lcb_res;
  5557. uint32_t cmdsize, shdr_status, shdr_add_status;
  5558. int rc;
  5559. mb = &pmb->u.mb;
  5560. lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
  5561. ndlp = lcb_context->ndlp;
  5562. pmb->ctx_ndlp = NULL;
  5563. pmb->ctx_buf = NULL;
  5564. shdr = (union lpfc_sli4_cfg_shdr *)
  5565. &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
  5566. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  5567. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  5568. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
  5569. "0194 SET_BEACON_CONFIG mailbox "
  5570. "completed with status x%x add_status x%x,"
  5571. " mbx status x%x\n",
  5572. shdr_status, shdr_add_status, mb->mbxStatus);
  5573. if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
  5574. (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
  5575. (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
  5576. mempool_free(pmb, phba->mbox_mem_pool);
  5577. goto error;
  5578. }
  5579. mempool_free(pmb, phba->mbox_mem_pool);
  5580. cmdsize = sizeof(struct fc_lcb_res_frame);
  5581. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  5582. lpfc_max_els_tries, ndlp,
  5583. ndlp->nlp_DID, ELS_CMD_ACC);
  5584. /* Decrement the ndlp reference count from previous mbox command */
  5585. lpfc_nlp_put(ndlp);
  5586. if (!elsiocb)
  5587. goto free_lcb_context;
  5588. lcb_res = (struct fc_lcb_res_frame *)
  5589. (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
  5590. memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
  5591. icmd = &elsiocb->iocb;
  5592. icmd->ulpContext = lcb_context->rx_id;
  5593. icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
  5594. pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
  5595. *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
  5596. lcb_res->lcb_sub_command = lcb_context->sub_command;
  5597. lcb_res->lcb_type = lcb_context->type;
  5598. lcb_res->capability = lcb_context->capability;
  5599. lcb_res->lcb_frequency = lcb_context->frequency;
  5600. lcb_res->lcb_duration = lcb_context->duration;
  5601. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  5602. phba->fc_stat.elsXmitACC++;
  5603. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5604. if (rc == IOCB_ERROR)
  5605. lpfc_els_free_iocb(phba, elsiocb);
  5606. kfree(lcb_context);
  5607. return;
  5608. error:
  5609. cmdsize = sizeof(struct fc_lcb_res_frame);
  5610. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  5611. lpfc_max_els_tries, ndlp,
  5612. ndlp->nlp_DID, ELS_CMD_LS_RJT);
  5613. lpfc_nlp_put(ndlp);
  5614. if (!elsiocb)
  5615. goto free_lcb_context;
  5616. icmd = &elsiocb->iocb;
  5617. icmd->ulpContext = lcb_context->rx_id;
  5618. icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
  5619. pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
  5620. *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
  5621. stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
  5622. stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  5623. if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
  5624. stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
  5625. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  5626. phba->fc_stat.elsXmitLSRJT++;
  5627. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5628. if (rc == IOCB_ERROR)
  5629. lpfc_els_free_iocb(phba, elsiocb);
  5630. free_lcb_context:
  5631. kfree(lcb_context);
  5632. }
  5633. static int
  5634. lpfc_sli4_set_beacon(struct lpfc_vport *vport,
  5635. struct lpfc_lcb_context *lcb_context,
  5636. uint32_t beacon_state)
  5637. {
  5638. struct lpfc_hba *phba = vport->phba;
  5639. union lpfc_sli4_cfg_shdr *cfg_shdr;
  5640. LPFC_MBOXQ_t *mbox = NULL;
  5641. uint32_t len;
  5642. int rc;
  5643. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5644. if (!mbox)
  5645. return 1;
  5646. cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  5647. len = sizeof(struct lpfc_mbx_set_beacon_config) -
  5648. sizeof(struct lpfc_sli4_cfg_mhdr);
  5649. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5650. LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
  5651. LPFC_SLI4_MBX_EMBED);
  5652. mbox->ctx_ndlp = (void *)lcb_context;
  5653. mbox->vport = phba->pport;
  5654. mbox->mbox_cmpl = lpfc_els_lcb_rsp;
  5655. bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
  5656. phba->sli4_hba.physical_port);
  5657. bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
  5658. beacon_state);
  5659. mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
  5660. /*
  5661. * Check bv1s bit before issuing the mailbox
  5662. * if bv1s == 1, LCB V1 supported
  5663. * else, LCB V0 supported
  5664. */
  5665. if (phba->sli4_hba.pc_sli4_params.bv1s) {
  5666. /* COMMON_SET_BEACON_CONFIG_V1 */
  5667. cfg_shdr->request.word9 = BEACON_VERSION_V1;
  5668. lcb_context->capability |= LCB_CAPABILITY_DURATION;
  5669. bf_set(lpfc_mbx_set_beacon_port_type,
  5670. &mbox->u.mqe.un.beacon_config, 0);
  5671. bf_set(lpfc_mbx_set_beacon_duration_v1,
  5672. &mbox->u.mqe.un.beacon_config,
  5673. be16_to_cpu(lcb_context->duration));
  5674. } else {
  5675. /* COMMON_SET_BEACON_CONFIG_V0 */
  5676. if (be16_to_cpu(lcb_context->duration) != 0) {
  5677. mempool_free(mbox, phba->mbox_mem_pool);
  5678. return 1;
  5679. }
  5680. cfg_shdr->request.word9 = BEACON_VERSION_V0;
  5681. lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
  5682. bf_set(lpfc_mbx_set_beacon_state,
  5683. &mbox->u.mqe.un.beacon_config, beacon_state);
  5684. bf_set(lpfc_mbx_set_beacon_port_type,
  5685. &mbox->u.mqe.un.beacon_config, 1);
  5686. bf_set(lpfc_mbx_set_beacon_duration,
  5687. &mbox->u.mqe.un.beacon_config,
  5688. be16_to_cpu(lcb_context->duration));
  5689. }
  5690. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  5691. if (rc == MBX_NOT_FINISHED) {
  5692. mempool_free(mbox, phba->mbox_mem_pool);
  5693. return 1;
  5694. }
  5695. return 0;
  5696. }
  5697. /**
  5698. * lpfc_els_rcv_lcb - Process an unsolicited LCB
  5699. * @vport: pointer to a host virtual N_Port data structure.
  5700. * @cmdiocb: pointer to lpfc command iocb data structure.
  5701. * @ndlp: pointer to a node-list data structure.
  5702. *
  5703. * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
  5704. * First, the payload of the unsolicited LCB is checked.
  5705. * Then based on Subcommand beacon will either turn on or off.
  5706. *
  5707. * Return code
  5708. * 0 - Sent the acc response
  5709. * 1 - Sent the reject response.
  5710. **/
  5711. static int
  5712. lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5713. struct lpfc_nodelist *ndlp)
  5714. {
  5715. struct lpfc_hba *phba = vport->phba;
  5716. struct lpfc_dmabuf *pcmd;
  5717. uint8_t *lp;
  5718. struct fc_lcb_request_frame *beacon;
  5719. struct lpfc_lcb_context *lcb_context;
  5720. uint8_t state, rjt_err;
  5721. struct ls_rjt stat;
  5722. pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
  5723. lp = (uint8_t *)pcmd->virt;
  5724. beacon = (struct fc_lcb_request_frame *)pcmd->virt;
  5725. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5726. "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
  5727. "type x%x frequency %x duration x%x\n",
  5728. lp[0], lp[1], lp[2],
  5729. beacon->lcb_command,
  5730. beacon->lcb_sub_command,
  5731. beacon->lcb_type,
  5732. beacon->lcb_frequency,
  5733. be16_to_cpu(beacon->lcb_duration));
  5734. if (beacon->lcb_sub_command != LPFC_LCB_ON &&
  5735. beacon->lcb_sub_command != LPFC_LCB_OFF) {
  5736. rjt_err = LSRJT_CMD_UNSUPPORTED;
  5737. goto rjt;
  5738. }
  5739. if (phba->sli_rev < LPFC_SLI_REV4 ||
  5740. phba->hba_flag & HBA_FCOE_MODE ||
  5741. (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
  5742. LPFC_SLI_INTF_IF_TYPE_2)) {
  5743. rjt_err = LSRJT_CMD_UNSUPPORTED;
  5744. goto rjt;
  5745. }
  5746. lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
  5747. if (!lcb_context) {
  5748. rjt_err = LSRJT_UNABLE_TPC;
  5749. goto rjt;
  5750. }
  5751. state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
  5752. lcb_context->sub_command = beacon->lcb_sub_command;
  5753. lcb_context->capability = 0;
  5754. lcb_context->type = beacon->lcb_type;
  5755. lcb_context->frequency = beacon->lcb_frequency;
  5756. lcb_context->duration = beacon->lcb_duration;
  5757. lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
  5758. lcb_context->rx_id = cmdiocb->iocb.ulpContext;
  5759. lcb_context->ndlp = lpfc_nlp_get(ndlp);
  5760. if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
  5761. lpfc_printf_vlog(ndlp->vport, KERN_ERR,
  5762. LOG_ELS, "0193 failed to send mail box");
  5763. kfree(lcb_context);
  5764. lpfc_nlp_put(ndlp);
  5765. rjt_err = LSRJT_UNABLE_TPC;
  5766. goto rjt;
  5767. }
  5768. return 0;
  5769. rjt:
  5770. memset(&stat, 0, sizeof(stat));
  5771. stat.un.b.lsRjtRsnCode = rjt_err;
  5772. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  5773. return 1;
  5774. }
  5775. /**
  5776. * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
  5777. * @vport: pointer to a host virtual N_Port data structure.
  5778. *
  5779. * This routine cleans up any Registration State Change Notification
  5780. * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
  5781. * @vport together with the host_lock is used to prevent multiple thread
  5782. * trying to access the RSCN array on a same @vport at the same time.
  5783. **/
  5784. void
  5785. lpfc_els_flush_rscn(struct lpfc_vport *vport)
  5786. {
  5787. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5788. struct lpfc_hba *phba = vport->phba;
  5789. int i;
  5790. spin_lock_irq(shost->host_lock);
  5791. if (vport->fc_rscn_flush) {
  5792. /* Another thread is walking fc_rscn_id_list on this vport */
  5793. spin_unlock_irq(shost->host_lock);
  5794. return;
  5795. }
  5796. /* Indicate we are walking lpfc_els_flush_rscn on this vport */
  5797. vport->fc_rscn_flush = 1;
  5798. spin_unlock_irq(shost->host_lock);
  5799. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  5800. lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
  5801. vport->fc_rscn_id_list[i] = NULL;
  5802. }
  5803. spin_lock_irq(shost->host_lock);
  5804. vport->fc_rscn_id_cnt = 0;
  5805. vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
  5806. spin_unlock_irq(shost->host_lock);
  5807. lpfc_can_disctmo(vport);
  5808. /* Indicate we are done walking this fc_rscn_id_list */
  5809. vport->fc_rscn_flush = 0;
  5810. }
  5811. /**
  5812. * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
  5813. * @vport: pointer to a host virtual N_Port data structure.
  5814. * @did: remote destination port identifier.
  5815. *
  5816. * This routine checks whether there is any pending Registration State
  5817. * Configuration Notification (RSCN) to a @did on @vport.
  5818. *
  5819. * Return code
  5820. * None zero - The @did matched with a pending rscn
  5821. * 0 - not able to match @did with a pending rscn
  5822. **/
  5823. int
  5824. lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
  5825. {
  5826. D_ID ns_did;
  5827. D_ID rscn_did;
  5828. uint32_t *lp;
  5829. uint32_t payload_len, i;
  5830. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5831. ns_did.un.word = did;
  5832. /* Never match fabric nodes for RSCNs */
  5833. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  5834. return 0;
  5835. /* If we are doing a FULL RSCN rediscovery, match everything */
  5836. if (vport->fc_flag & FC_RSCN_DISCOVERY)
  5837. return did;
  5838. spin_lock_irq(shost->host_lock);
  5839. if (vport->fc_rscn_flush) {
  5840. /* Another thread is walking fc_rscn_id_list on this vport */
  5841. spin_unlock_irq(shost->host_lock);
  5842. return 0;
  5843. }
  5844. /* Indicate we are walking fc_rscn_id_list on this vport */
  5845. vport->fc_rscn_flush = 1;
  5846. spin_unlock_irq(shost->host_lock);
  5847. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  5848. lp = vport->fc_rscn_id_list[i]->virt;
  5849. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  5850. payload_len -= sizeof(uint32_t); /* take off word 0 */
  5851. while (payload_len) {
  5852. rscn_did.un.word = be32_to_cpu(*lp++);
  5853. payload_len -= sizeof(uint32_t);
  5854. switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
  5855. case RSCN_ADDRESS_FORMAT_PORT:
  5856. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  5857. && (ns_did.un.b.area == rscn_did.un.b.area)
  5858. && (ns_did.un.b.id == rscn_did.un.b.id))
  5859. goto return_did_out;
  5860. break;
  5861. case RSCN_ADDRESS_FORMAT_AREA:
  5862. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  5863. && (ns_did.un.b.area == rscn_did.un.b.area))
  5864. goto return_did_out;
  5865. break;
  5866. case RSCN_ADDRESS_FORMAT_DOMAIN:
  5867. if (ns_did.un.b.domain == rscn_did.un.b.domain)
  5868. goto return_did_out;
  5869. break;
  5870. case RSCN_ADDRESS_FORMAT_FABRIC:
  5871. goto return_did_out;
  5872. }
  5873. }
  5874. }
  5875. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  5876. vport->fc_rscn_flush = 0;
  5877. return 0;
  5878. return_did_out:
  5879. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  5880. vport->fc_rscn_flush = 0;
  5881. return did;
  5882. }
  5883. /**
  5884. * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
  5885. * @vport: pointer to a host virtual N_Port data structure.
  5886. *
  5887. * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
  5888. * state machine for a @vport's nodes that are with pending RSCN (Registration
  5889. * State Change Notification).
  5890. *
  5891. * Return code
  5892. * 0 - Successful (currently alway return 0)
  5893. **/
  5894. static int
  5895. lpfc_rscn_recovery_check(struct lpfc_vport *vport)
  5896. {
  5897. struct lpfc_nodelist *ndlp = NULL;
  5898. /* Move all affected nodes by pending RSCNs to NPR state. */
  5899. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  5900. if (!NLP_CHK_NODE_ACT(ndlp) ||
  5901. (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
  5902. !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
  5903. continue;
  5904. /* NVME Target mode does not do RSCN Recovery. */
  5905. if (vport->phba->nvmet_support)
  5906. continue;
  5907. /* If we are in the process of doing discovery on this
  5908. * NPort, let it continue on its own.
  5909. */
  5910. switch (ndlp->nlp_state) {
  5911. case NLP_STE_PLOGI_ISSUE:
  5912. case NLP_STE_ADISC_ISSUE:
  5913. case NLP_STE_REG_LOGIN_ISSUE:
  5914. case NLP_STE_PRLI_ISSUE:
  5915. case NLP_STE_LOGO_ISSUE:
  5916. continue;
  5917. }
  5918. /* Check to see if we need to NVME rescan this target
  5919. * remoteport.
  5920. */
  5921. if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
  5922. ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
  5923. lpfc_nvme_rescan_port(vport, ndlp);
  5924. lpfc_disc_state_machine(vport, ndlp, NULL,
  5925. NLP_EVT_DEVICE_RECOVERY);
  5926. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  5927. }
  5928. return 0;
  5929. }
  5930. /**
  5931. * lpfc_send_rscn_event - Send an RSCN event to management application
  5932. * @vport: pointer to a host virtual N_Port data structure.
  5933. * @cmdiocb: pointer to lpfc command iocb data structure.
  5934. *
  5935. * lpfc_send_rscn_event sends an RSCN netlink event to management
  5936. * applications.
  5937. */
  5938. static void
  5939. lpfc_send_rscn_event(struct lpfc_vport *vport,
  5940. struct lpfc_iocbq *cmdiocb)
  5941. {
  5942. struct lpfc_dmabuf *pcmd;
  5943. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5944. uint32_t *payload_ptr;
  5945. uint32_t payload_len;
  5946. struct lpfc_rscn_event_header *rscn_event_data;
  5947. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5948. payload_ptr = (uint32_t *) pcmd->virt;
  5949. payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
  5950. rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
  5951. payload_len, GFP_KERNEL);
  5952. if (!rscn_event_data) {
  5953. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  5954. "0147 Failed to allocate memory for RSCN event\n");
  5955. return;
  5956. }
  5957. rscn_event_data->event_type = FC_REG_RSCN_EVENT;
  5958. rscn_event_data->payload_length = payload_len;
  5959. memcpy(rscn_event_data->rscn_payload, payload_ptr,
  5960. payload_len);
  5961. fc_host_post_vendor_event(shost,
  5962. fc_get_event_number(),
  5963. sizeof(struct lpfc_rscn_event_header) + payload_len,
  5964. (char *)rscn_event_data,
  5965. LPFC_NL_VENDOR_ID);
  5966. kfree(rscn_event_data);
  5967. }
  5968. /**
  5969. * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
  5970. * @vport: pointer to a host virtual N_Port data structure.
  5971. * @cmdiocb: pointer to lpfc command iocb data structure.
  5972. * @ndlp: pointer to a node-list data structure.
  5973. *
  5974. * This routine processes an unsolicited RSCN (Registration State Change
  5975. * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
  5976. * to invoke fc_host_post_event() routine to the FC transport layer. If the
  5977. * discover state machine is about to begin discovery, it just accepts the
  5978. * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
  5979. * contains N_Port IDs for other vports on this HBA, it just accepts the
  5980. * RSCN and ignore processing it. If the state machine is in the recovery
  5981. * state, the fc_rscn_id_list of this @vport is walked and the
  5982. * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
  5983. * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
  5984. * routine is invoked to handle the RSCN event.
  5985. *
  5986. * Return code
  5987. * 0 - Just sent the acc response
  5988. * 1 - Sent the acc response and waited for name server completion
  5989. **/
  5990. static int
  5991. lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5992. struct lpfc_nodelist *ndlp)
  5993. {
  5994. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5995. struct lpfc_hba *phba = vport->phba;
  5996. struct lpfc_dmabuf *pcmd;
  5997. uint32_t *lp, *datap;
  5998. uint32_t payload_len, length, nportid, *cmd;
  5999. int rscn_cnt;
  6000. int rscn_id = 0, hba_id = 0;
  6001. int i, tmo;
  6002. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  6003. lp = (uint32_t *) pcmd->virt;
  6004. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  6005. payload_len -= sizeof(uint32_t); /* take off word 0 */
  6006. /* RSCN received */
  6007. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  6008. "0214 RSCN received Data: x%x x%x x%x x%x\n",
  6009. vport->fc_flag, payload_len, *lp,
  6010. vport->fc_rscn_id_cnt);
  6011. /* Send an RSCN event to the management application */
  6012. lpfc_send_rscn_event(vport, cmdiocb);
  6013. for (i = 0; i < payload_len/sizeof(uint32_t); i++)
  6014. fc_host_post_event(shost, fc_get_event_number(),
  6015. FCH_EVT_RSCN, lp[i]);
  6016. /* Check if RSCN is coming from a direct-connected remote NPort */
  6017. if (vport->fc_flag & FC_PT2PT) {
  6018. /* If so, just ACC it, no other action needed for now */
  6019. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6020. "2024 pt2pt RSCN %08x Data: x%x x%x\n",
  6021. *lp, vport->fc_flag, payload_len);
  6022. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  6023. /* Check to see if we need to NVME rescan this target
  6024. * remoteport.
  6025. */
  6026. if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
  6027. ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
  6028. lpfc_nvme_rescan_port(vport, ndlp);
  6029. return 0;
  6030. }
  6031. /* If we are about to begin discovery, just ACC the RSCN.
  6032. * Discovery processing will satisfy it.
  6033. */
  6034. if (vport->port_state <= LPFC_NS_QRY) {
  6035. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6036. "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
  6037. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  6038. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  6039. return 0;
  6040. }
  6041. /* If this RSCN just contains NPortIDs for other vports on this HBA,
  6042. * just ACC and ignore it.
  6043. */
  6044. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  6045. !(vport->cfg_peer_port_login)) {
  6046. i = payload_len;
  6047. datap = lp;
  6048. while (i > 0) {
  6049. nportid = *datap++;
  6050. nportid = ((be32_to_cpu(nportid)) & Mask_DID);
  6051. i -= sizeof(uint32_t);
  6052. rscn_id++;
  6053. if (lpfc_find_vport_by_did(phba, nportid))
  6054. hba_id++;
  6055. }
  6056. if (rscn_id == hba_id) {
  6057. /* ALL NPortIDs in RSCN are on HBA */
  6058. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  6059. "0219 Ignore RSCN "
  6060. "Data: x%x x%x x%x x%x\n",
  6061. vport->fc_flag, payload_len,
  6062. *lp, vport->fc_rscn_id_cnt);
  6063. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6064. "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
  6065. ndlp->nlp_DID, vport->port_state,
  6066. ndlp->nlp_flag);
  6067. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
  6068. ndlp, NULL);
  6069. return 0;
  6070. }
  6071. }
  6072. spin_lock_irq(shost->host_lock);
  6073. if (vport->fc_rscn_flush) {
  6074. /* Another thread is walking fc_rscn_id_list on this vport */
  6075. vport->fc_flag |= FC_RSCN_DISCOVERY;
  6076. spin_unlock_irq(shost->host_lock);
  6077. /* Send back ACC */
  6078. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  6079. return 0;
  6080. }
  6081. /* Indicate we are walking fc_rscn_id_list on this vport */
  6082. vport->fc_rscn_flush = 1;
  6083. spin_unlock_irq(shost->host_lock);
  6084. /* Get the array count after successfully have the token */
  6085. rscn_cnt = vport->fc_rscn_id_cnt;
  6086. /* If we are already processing an RSCN, save the received
  6087. * RSCN payload buffer, cmdiocb->context2 to process later.
  6088. */
  6089. if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
  6090. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6091. "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
  6092. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  6093. spin_lock_irq(shost->host_lock);
  6094. vport->fc_flag |= FC_RSCN_DEFERRED;
  6095. /* Restart disctmo if its already running */
  6096. if (vport->fc_flag & FC_DISC_TMO) {
  6097. tmo = ((phba->fc_ratov * 3) + 3);
  6098. mod_timer(&vport->fc_disctmo,
  6099. jiffies + msecs_to_jiffies(1000 * tmo));
  6100. }
  6101. if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
  6102. !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
  6103. vport->fc_flag |= FC_RSCN_MODE;
  6104. spin_unlock_irq(shost->host_lock);
  6105. if (rscn_cnt) {
  6106. cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
  6107. length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
  6108. }
  6109. if ((rscn_cnt) &&
  6110. (payload_len + length <= LPFC_BPL_SIZE)) {
  6111. *cmd &= ELS_CMD_MASK;
  6112. *cmd |= cpu_to_be32(payload_len + length);
  6113. memcpy(((uint8_t *)cmd) + length, lp,
  6114. payload_len);
  6115. } else {
  6116. vport->fc_rscn_id_list[rscn_cnt] = pcmd;
  6117. vport->fc_rscn_id_cnt++;
  6118. /* If we zero, cmdiocb->context2, the calling
  6119. * routine will not try to free it.
  6120. */
  6121. cmdiocb->context2 = NULL;
  6122. }
  6123. /* Deferred RSCN */
  6124. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  6125. "0235 Deferred RSCN "
  6126. "Data: x%x x%x x%x\n",
  6127. vport->fc_rscn_id_cnt, vport->fc_flag,
  6128. vport->port_state);
  6129. } else {
  6130. vport->fc_flag |= FC_RSCN_DISCOVERY;
  6131. spin_unlock_irq(shost->host_lock);
  6132. /* ReDiscovery RSCN */
  6133. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  6134. "0234 ReDiscovery RSCN "
  6135. "Data: x%x x%x x%x\n",
  6136. vport->fc_rscn_id_cnt, vport->fc_flag,
  6137. vport->port_state);
  6138. }
  6139. /* Indicate we are done walking fc_rscn_id_list on this vport */
  6140. vport->fc_rscn_flush = 0;
  6141. /* Send back ACC */
  6142. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  6143. /* send RECOVERY event for ALL nodes that match RSCN payload */
  6144. lpfc_rscn_recovery_check(vport);
  6145. return 0;
  6146. }
  6147. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6148. "RCV RSCN: did:x%x/ste:x%x flg:x%x",
  6149. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  6150. spin_lock_irq(shost->host_lock);
  6151. vport->fc_flag |= FC_RSCN_MODE;
  6152. spin_unlock_irq(shost->host_lock);
  6153. vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
  6154. /* Indicate we are done walking fc_rscn_id_list on this vport */
  6155. vport->fc_rscn_flush = 0;
  6156. /*
  6157. * If we zero, cmdiocb->context2, the calling routine will
  6158. * not try to free it.
  6159. */
  6160. cmdiocb->context2 = NULL;
  6161. lpfc_set_disctmo(vport);
  6162. /* Send back ACC */
  6163. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  6164. /* send RECOVERY event for ALL nodes that match RSCN payload */
  6165. lpfc_rscn_recovery_check(vport);
  6166. return lpfc_els_handle_rscn(vport);
  6167. }
  6168. /**
  6169. * lpfc_els_handle_rscn - Handle rscn for a vport
  6170. * @vport: pointer to a host virtual N_Port data structure.
  6171. *
  6172. * This routine handles the Registration State Configuration Notification
  6173. * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
  6174. * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
  6175. * if the ndlp to NameServer exists, a Common Transport (CT) command to the
  6176. * NameServer shall be issued. If CT command to the NameServer fails to be
  6177. * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
  6178. * RSCN activities with the @vport.
  6179. *
  6180. * Return code
  6181. * 0 - Cleaned up rscn on the @vport
  6182. * 1 - Wait for plogi to name server before proceed
  6183. **/
  6184. int
  6185. lpfc_els_handle_rscn(struct lpfc_vport *vport)
  6186. {
  6187. struct lpfc_nodelist *ndlp;
  6188. struct lpfc_hba *phba = vport->phba;
  6189. /* Ignore RSCN if the port is being torn down. */
  6190. if (vport->load_flag & FC_UNLOADING) {
  6191. lpfc_els_flush_rscn(vport);
  6192. return 0;
  6193. }
  6194. /* Start timer for RSCN processing */
  6195. lpfc_set_disctmo(vport);
  6196. /* RSCN processed */
  6197. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  6198. "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
  6199. vport->fc_flag, 0, vport->fc_rscn_id_cnt,
  6200. vport->port_state, vport->num_disc_nodes,
  6201. vport->gidft_inp);
  6202. /* To process RSCN, first compare RSCN data with NameServer */
  6203. vport->fc_ns_retry = 0;
  6204. vport->num_disc_nodes = 0;
  6205. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  6206. if (ndlp && NLP_CHK_NODE_ACT(ndlp)
  6207. && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  6208. /* Good ndlp, issue CT Request to NameServer. Need to
  6209. * know how many gidfts were issued. If none, then just
  6210. * flush the RSCN. Otherwise, the outstanding requests
  6211. * need to complete.
  6212. */
  6213. if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
  6214. if (lpfc_issue_gidft(vport) > 0)
  6215. return 1;
  6216. } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
  6217. if (lpfc_issue_gidpt(vport) > 0)
  6218. return 1;
  6219. } else {
  6220. return 1;
  6221. }
  6222. } else {
  6223. /* Nameserver login in question. Revalidate. */
  6224. if (ndlp) {
  6225. ndlp = lpfc_enable_node(vport, ndlp,
  6226. NLP_STE_PLOGI_ISSUE);
  6227. if (!ndlp) {
  6228. lpfc_els_flush_rscn(vport);
  6229. return 0;
  6230. }
  6231. ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
  6232. } else {
  6233. ndlp = lpfc_nlp_init(vport, NameServer_DID);
  6234. if (!ndlp) {
  6235. lpfc_els_flush_rscn(vport);
  6236. return 0;
  6237. }
  6238. ndlp->nlp_prev_state = ndlp->nlp_state;
  6239. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  6240. }
  6241. ndlp->nlp_type |= NLP_FABRIC;
  6242. lpfc_issue_els_plogi(vport, NameServer_DID, 0);
  6243. /* Wait for NameServer login cmpl before we can
  6244. * continue
  6245. */
  6246. return 1;
  6247. }
  6248. lpfc_els_flush_rscn(vport);
  6249. return 0;
  6250. }
  6251. /**
  6252. * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
  6253. * @vport: pointer to a host virtual N_Port data structure.
  6254. * @cmdiocb: pointer to lpfc command iocb data structure.
  6255. * @ndlp: pointer to a node-list data structure.
  6256. *
  6257. * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
  6258. * unsolicited event. An unsolicited FLOGI can be received in a point-to-
  6259. * point topology. As an unsolicited FLOGI should not be received in a loop
  6260. * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
  6261. * lpfc_check_sparm() routine is invoked to check the parameters in the
  6262. * unsolicited FLOGI. If parameters validation failed, the routine
  6263. * lpfc_els_rsp_reject() shall be called with reject reason code set to
  6264. * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
  6265. * FLOGI shall be compared with the Port WWN of the @vport to determine who
  6266. * will initiate PLOGI. The higher lexicographical value party shall has
  6267. * higher priority (as the winning port) and will initiate PLOGI and
  6268. * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
  6269. * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
  6270. * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
  6271. *
  6272. * Return code
  6273. * 0 - Successfully processed the unsolicited flogi
  6274. * 1 - Failed to process the unsolicited flogi
  6275. **/
  6276. static int
  6277. lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  6278. struct lpfc_nodelist *ndlp)
  6279. {
  6280. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6281. struct lpfc_hba *phba = vport->phba;
  6282. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  6283. uint32_t *lp = (uint32_t *) pcmd->virt;
  6284. IOCB_t *icmd = &cmdiocb->iocb;
  6285. struct serv_parm *sp;
  6286. LPFC_MBOXQ_t *mbox;
  6287. uint32_t cmd, did;
  6288. int rc;
  6289. uint32_t fc_flag = 0;
  6290. uint32_t port_state = 0;
  6291. cmd = *lp++;
  6292. sp = (struct serv_parm *) lp;
  6293. /* FLOGI received */
  6294. lpfc_set_disctmo(vport);
  6295. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  6296. /* We should never receive a FLOGI in loop mode, ignore it */
  6297. did = icmd->un.elsreq64.remoteID;
  6298. /* An FLOGI ELS command <elsCmd> was received from DID <did> in
  6299. Loop Mode */
  6300. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6301. "0113 An FLOGI ELS command x%x was "
  6302. "received from DID x%x in Loop Mode\n",
  6303. cmd, did);
  6304. return 1;
  6305. }
  6306. (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
  6307. /*
  6308. * If our portname is greater than the remote portname,
  6309. * then we initiate Nport login.
  6310. */
  6311. rc = memcmp(&vport->fc_portname, &sp->portName,
  6312. sizeof(struct lpfc_name));
  6313. if (!rc) {
  6314. if (phba->sli_rev < LPFC_SLI_REV4) {
  6315. mbox = mempool_alloc(phba->mbox_mem_pool,
  6316. GFP_KERNEL);
  6317. if (!mbox)
  6318. return 1;
  6319. lpfc_linkdown(phba);
  6320. lpfc_init_link(phba, mbox,
  6321. phba->cfg_topology,
  6322. phba->cfg_link_speed);
  6323. mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  6324. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6325. mbox->vport = vport;
  6326. rc = lpfc_sli_issue_mbox(phba, mbox,
  6327. MBX_NOWAIT);
  6328. lpfc_set_loopback_flag(phba);
  6329. if (rc == MBX_NOT_FINISHED)
  6330. mempool_free(mbox, phba->mbox_mem_pool);
  6331. return 1;
  6332. }
  6333. /* abort the flogi coming back to ourselves
  6334. * due to external loopback on the port.
  6335. */
  6336. lpfc_els_abort_flogi(phba);
  6337. return 0;
  6338. } else if (rc > 0) { /* greater than */
  6339. spin_lock_irq(shost->host_lock);
  6340. vport->fc_flag |= FC_PT2PT_PLOGI;
  6341. spin_unlock_irq(shost->host_lock);
  6342. /* If we have the high WWPN we can assign our own
  6343. * myDID; otherwise, we have to WAIT for a PLOGI
  6344. * from the remote NPort to find out what it
  6345. * will be.
  6346. */
  6347. vport->fc_myDID = PT2PT_LocalID;
  6348. } else {
  6349. vport->fc_myDID = PT2PT_RemoteID;
  6350. }
  6351. /*
  6352. * The vport state should go to LPFC_FLOGI only
  6353. * AFTER we issue a FLOGI, not receive one.
  6354. */
  6355. spin_lock_irq(shost->host_lock);
  6356. fc_flag = vport->fc_flag;
  6357. port_state = vport->port_state;
  6358. vport->fc_flag |= FC_PT2PT;
  6359. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  6360. /* Acking an unsol FLOGI. Count 1 for link bounce
  6361. * work-around.
  6362. */
  6363. vport->rcv_flogi_cnt++;
  6364. spin_unlock_irq(shost->host_lock);
  6365. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6366. "3311 Rcv Flogi PS x%x new PS x%x "
  6367. "fc_flag x%x new fc_flag x%x\n",
  6368. port_state, vport->port_state,
  6369. fc_flag, vport->fc_flag);
  6370. /*
  6371. * We temporarily set fc_myDID to make it look like we are
  6372. * a Fabric. This is done just so we end up with the right
  6373. * did / sid on the FLOGI ACC rsp.
  6374. */
  6375. did = vport->fc_myDID;
  6376. vport->fc_myDID = Fabric_DID;
  6377. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  6378. /* Defer ACC response until AFTER we issue a FLOGI */
  6379. if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
  6380. phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
  6381. phba->defer_flogi_acc_ox_id =
  6382. cmdiocb->iocb.unsli3.rcvsli3.ox_id;
  6383. vport->fc_myDID = did;
  6384. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6385. "3344 Deferring FLOGI ACC: rx_id: x%x,"
  6386. " ox_id: x%x, hba_flag x%x\n",
  6387. phba->defer_flogi_acc_rx_id,
  6388. phba->defer_flogi_acc_ox_id, phba->hba_flag);
  6389. phba->defer_flogi_acc_flag = true;
  6390. return 0;
  6391. }
  6392. /* Send back ACC */
  6393. lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
  6394. /* Now lets put fc_myDID back to what its supposed to be */
  6395. vport->fc_myDID = did;
  6396. return 0;
  6397. }
  6398. /**
  6399. * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
  6400. * @vport: pointer to a host virtual N_Port data structure.
  6401. * @cmdiocb: pointer to lpfc command iocb data structure.
  6402. * @ndlp: pointer to a node-list data structure.
  6403. *
  6404. * This routine processes Request Node Identification Data (RNID) IOCB
  6405. * received as an ELS unsolicited event. Only when the RNID specified format
  6406. * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
  6407. * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
  6408. * Accept (ACC) the RNID ELS command. All the other RNID formats are
  6409. * rejected by invoking the lpfc_els_rsp_reject() routine.
  6410. *
  6411. * Return code
  6412. * 0 - Successfully processed rnid iocb (currently always return 0)
  6413. **/
  6414. static int
  6415. lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  6416. struct lpfc_nodelist *ndlp)
  6417. {
  6418. struct lpfc_dmabuf *pcmd;
  6419. uint32_t *lp;
  6420. RNID *rn;
  6421. struct ls_rjt stat;
  6422. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  6423. lp = (uint32_t *) pcmd->virt;
  6424. lp++;
  6425. rn = (RNID *) lp;
  6426. /* RNID received */
  6427. switch (rn->Format) {
  6428. case 0:
  6429. case RNID_TOPOLOGY_DISC:
  6430. /* Send back ACC */
  6431. lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
  6432. break;
  6433. default:
  6434. /* Reject this request because format not supported */
  6435. stat.un.b.lsRjtRsvd0 = 0;
  6436. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  6437. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  6438. stat.un.b.vendorUnique = 0;
  6439. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  6440. NULL);
  6441. }
  6442. return 0;
  6443. }
  6444. /**
  6445. * lpfc_els_rcv_echo - Process an unsolicited echo iocb
  6446. * @vport: pointer to a host virtual N_Port data structure.
  6447. * @cmdiocb: pointer to lpfc command iocb data structure.
  6448. * @ndlp: pointer to a node-list data structure.
  6449. *
  6450. * Return code
  6451. * 0 - Successfully processed echo iocb (currently always return 0)
  6452. **/
  6453. static int
  6454. lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  6455. struct lpfc_nodelist *ndlp)
  6456. {
  6457. uint8_t *pcmd;
  6458. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
  6459. /* skip over first word of echo command to find echo data */
  6460. pcmd += sizeof(uint32_t);
  6461. lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
  6462. return 0;
  6463. }
  6464. /**
  6465. * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
  6466. * @vport: pointer to a host virtual N_Port data structure.
  6467. * @cmdiocb: pointer to lpfc command iocb data structure.
  6468. * @ndlp: pointer to a node-list data structure.
  6469. *
  6470. * This routine processes a Link Incident Report Registration(LIRR) IOCB
  6471. * received as an ELS unsolicited event. Currently, this function just invokes
  6472. * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
  6473. *
  6474. * Return code
  6475. * 0 - Successfully processed lirr iocb (currently always return 0)
  6476. **/
  6477. static int
  6478. lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  6479. struct lpfc_nodelist *ndlp)
  6480. {
  6481. struct ls_rjt stat;
  6482. /* For now, unconditionally reject this command */
  6483. stat.un.b.lsRjtRsvd0 = 0;
  6484. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  6485. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  6486. stat.un.b.vendorUnique = 0;
  6487. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  6488. return 0;
  6489. }
  6490. /**
  6491. * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
  6492. * @vport: pointer to a host virtual N_Port data structure.
  6493. * @cmdiocb: pointer to lpfc command iocb data structure.
  6494. * @ndlp: pointer to a node-list data structure.
  6495. *
  6496. * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
  6497. * received as an ELS unsolicited event. A request to RRQ shall only
  6498. * be accepted if the Originator Nx_Port N_Port_ID or the Responder
  6499. * Nx_Port N_Port_ID of the target Exchange is the same as the
  6500. * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
  6501. * not accepted, an LS_RJT with reason code "Unable to perform
  6502. * command request" and reason code explanation "Invalid Originator
  6503. * S_ID" shall be returned. For now, we just unconditionally accept
  6504. * RRQ from the target.
  6505. **/
  6506. static void
  6507. lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  6508. struct lpfc_nodelist *ndlp)
  6509. {
  6510. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  6511. if (vport->phba->sli_rev == LPFC_SLI_REV4)
  6512. lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
  6513. }
  6514. /**
  6515. * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
  6516. * @phba: pointer to lpfc hba data structure.
  6517. * @pmb: pointer to the driver internal queue element for mailbox command.
  6518. *
  6519. * This routine is the completion callback function for the MBX_READ_LNK_STAT
  6520. * mailbox command. This callback function is to actually send the Accept
  6521. * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
  6522. * collects the link statistics from the completion of the MBX_READ_LNK_STAT
  6523. * mailbox command, constructs the RPS response with the link statistics
  6524. * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
  6525. * response to the RPS.
  6526. *
  6527. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  6528. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  6529. * will be stored into the context1 field of the IOCB for the completion
  6530. * callback function to the RPS Accept Response ELS IOCB command.
  6531. *
  6532. **/
  6533. static void
  6534. lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  6535. {
  6536. MAILBOX_t *mb;
  6537. IOCB_t *icmd;
  6538. struct RLS_RSP *rls_rsp;
  6539. uint8_t *pcmd;
  6540. struct lpfc_iocbq *elsiocb;
  6541. struct lpfc_nodelist *ndlp;
  6542. uint16_t oxid;
  6543. uint16_t rxid;
  6544. uint32_t cmdsize;
  6545. mb = &pmb->u.mb;
  6546. ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
  6547. rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
  6548. oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
  6549. pmb->ctx_buf = NULL;
  6550. pmb->ctx_ndlp = NULL;
  6551. if (mb->mbxStatus) {
  6552. mempool_free(pmb, phba->mbox_mem_pool);
  6553. return;
  6554. }
  6555. cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
  6556. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  6557. lpfc_max_els_tries, ndlp,
  6558. ndlp->nlp_DID, ELS_CMD_ACC);
  6559. /* Decrement the ndlp reference count from previous mbox command */
  6560. lpfc_nlp_put(ndlp);
  6561. if (!elsiocb) {
  6562. mempool_free(pmb, phba->mbox_mem_pool);
  6563. return;
  6564. }
  6565. icmd = &elsiocb->iocb;
  6566. icmd->ulpContext = rxid;
  6567. icmd->unsli3.rcvsli3.ox_id = oxid;
  6568. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  6569. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  6570. pcmd += sizeof(uint32_t); /* Skip past command */
  6571. rls_rsp = (struct RLS_RSP *)pcmd;
  6572. rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
  6573. rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
  6574. rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
  6575. rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
  6576. rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
  6577. rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
  6578. mempool_free(pmb, phba->mbox_mem_pool);
  6579. /* Xmit ELS RLS ACC response tag <ulpIoTag> */
  6580. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  6581. "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
  6582. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  6583. elsiocb->iotag, elsiocb->iocb.ulpContext,
  6584. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  6585. ndlp->nlp_rpi);
  6586. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  6587. phba->fc_stat.elsXmitACC++;
  6588. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
  6589. lpfc_els_free_iocb(phba, elsiocb);
  6590. }
  6591. /**
  6592. * lpfc_els_rcv_rls - Process an unsolicited rls iocb
  6593. * @vport: pointer to a host virtual N_Port data structure.
  6594. * @cmdiocb: pointer to lpfc command iocb data structure.
  6595. * @ndlp: pointer to a node-list data structure.
  6596. *
  6597. * This routine processes Read Link Status (RLS) IOCB received as an
  6598. * ELS unsolicited event. It first checks the remote port state. If the
  6599. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  6600. * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
  6601. * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
  6602. * for reading the HBA link statistics. It is for the callback function,
  6603. * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
  6604. * to actually sending out RPL Accept (ACC) response.
  6605. *
  6606. * Return codes
  6607. * 0 - Successfully processed rls iocb (currently always return 0)
  6608. **/
  6609. static int
  6610. lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  6611. struct lpfc_nodelist *ndlp)
  6612. {
  6613. struct lpfc_hba *phba = vport->phba;
  6614. LPFC_MBOXQ_t *mbox;
  6615. struct ls_rjt stat;
  6616. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  6617. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  6618. /* reject the unsolicited RLS request and done with it */
  6619. goto reject_out;
  6620. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
  6621. if (mbox) {
  6622. lpfc_read_lnk_stat(phba, mbox);
  6623. mbox->ctx_buf = (void *)((unsigned long)
  6624. ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
  6625. cmdiocb->iocb.ulpContext)); /* rx_id */
  6626. mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
  6627. mbox->vport = vport;
  6628. mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
  6629. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  6630. != MBX_NOT_FINISHED)
  6631. /* Mbox completion will send ELS Response */
  6632. return 0;
  6633. /* Decrement reference count used for the failed mbox
  6634. * command.
  6635. */
  6636. lpfc_nlp_put(ndlp);
  6637. mempool_free(mbox, phba->mbox_mem_pool);
  6638. }
  6639. reject_out:
  6640. /* issue rejection response */
  6641. stat.un.b.lsRjtRsvd0 = 0;
  6642. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  6643. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  6644. stat.un.b.vendorUnique = 0;
  6645. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  6646. return 0;
  6647. }
  6648. /**
  6649. * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
  6650. * @vport: pointer to a host virtual N_Port data structure.
  6651. * @cmdiocb: pointer to lpfc command iocb data structure.
  6652. * @ndlp: pointer to a node-list data structure.
  6653. *
  6654. * This routine processes Read Timout Value (RTV) IOCB received as an
  6655. * ELS unsolicited event. It first checks the remote port state. If the
  6656. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  6657. * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
  6658. * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
  6659. * Value (RTV) unsolicited IOCB event.
  6660. *
  6661. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  6662. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  6663. * will be stored into the context1 field of the IOCB for the completion
  6664. * callback function to the RTV Accept Response ELS IOCB command.
  6665. *
  6666. * Return codes
  6667. * 0 - Successfully processed rtv iocb (currently always return 0)
  6668. **/
  6669. static int
  6670. lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  6671. struct lpfc_nodelist *ndlp)
  6672. {
  6673. struct lpfc_hba *phba = vport->phba;
  6674. struct ls_rjt stat;
  6675. struct RTV_RSP *rtv_rsp;
  6676. uint8_t *pcmd;
  6677. struct lpfc_iocbq *elsiocb;
  6678. uint32_t cmdsize;
  6679. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  6680. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  6681. /* reject the unsolicited RTV request and done with it */
  6682. goto reject_out;
  6683. cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
  6684. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  6685. lpfc_max_els_tries, ndlp,
  6686. ndlp->nlp_DID, ELS_CMD_ACC);
  6687. if (!elsiocb)
  6688. return 1;
  6689. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  6690. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  6691. pcmd += sizeof(uint32_t); /* Skip past command */
  6692. /* use the command's xri in the response */
  6693. elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
  6694. elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
  6695. rtv_rsp = (struct RTV_RSP *)pcmd;
  6696. /* populate RTV payload */
  6697. rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
  6698. rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
  6699. bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
  6700. bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
  6701. rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
  6702. /* Xmit ELS RLS ACC response tag <ulpIoTag> */
  6703. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  6704. "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
  6705. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
  6706. "Data: x%x x%x x%x\n",
  6707. elsiocb->iotag, elsiocb->iocb.ulpContext,
  6708. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  6709. ndlp->nlp_rpi,
  6710. rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
  6711. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  6712. phba->fc_stat.elsXmitACC++;
  6713. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
  6714. lpfc_els_free_iocb(phba, elsiocb);
  6715. return 0;
  6716. reject_out:
  6717. /* issue rejection response */
  6718. stat.un.b.lsRjtRsvd0 = 0;
  6719. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  6720. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  6721. stat.un.b.vendorUnique = 0;
  6722. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  6723. return 0;
  6724. }
  6725. /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
  6726. * @vport: pointer to a host virtual N_Port data structure.
  6727. * @ndlp: pointer to a node-list data structure.
  6728. * @did: DID of the target.
  6729. * @rrq: Pointer to the rrq struct.
  6730. *
  6731. * Build a ELS RRQ command and send it to the target. If the issue_iocb is
  6732. * Successful the the completion handler will clear the RRQ.
  6733. *
  6734. * Return codes
  6735. * 0 - Successfully sent rrq els iocb.
  6736. * 1 - Failed to send rrq els iocb.
  6737. **/
  6738. static int
  6739. lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  6740. uint32_t did, struct lpfc_node_rrq *rrq)
  6741. {
  6742. struct lpfc_hba *phba = vport->phba;
  6743. struct RRQ *els_rrq;
  6744. struct lpfc_iocbq *elsiocb;
  6745. uint8_t *pcmd;
  6746. uint16_t cmdsize;
  6747. int ret;
  6748. if (ndlp != rrq->ndlp)
  6749. ndlp = rrq->ndlp;
  6750. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  6751. return 1;
  6752. /* If ndlp is not NULL, we will bump the reference count on it */
  6753. cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
  6754. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
  6755. ELS_CMD_RRQ);
  6756. if (!elsiocb)
  6757. return 1;
  6758. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  6759. /* For RRQ request, remainder of payload is Exchange IDs */
  6760. *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
  6761. pcmd += sizeof(uint32_t);
  6762. els_rrq = (struct RRQ *) pcmd;
  6763. bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
  6764. bf_set(rrq_rxid, els_rrq, rrq->rxid);
  6765. bf_set(rrq_did, els_rrq, vport->fc_myDID);
  6766. els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
  6767. els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
  6768. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  6769. "Issue RRQ: did:x%x",
  6770. did, rrq->xritag, rrq->rxid);
  6771. elsiocb->context_un.rrq = rrq;
  6772. elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
  6773. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  6774. if (ret == IOCB_ERROR) {
  6775. lpfc_els_free_iocb(phba, elsiocb);
  6776. return 1;
  6777. }
  6778. return 0;
  6779. }
  6780. /**
  6781. * lpfc_send_rrq - Sends ELS RRQ if needed.
  6782. * @phba: pointer to lpfc hba data structure.
  6783. * @rrq: pointer to the active rrq.
  6784. *
  6785. * This routine will call the lpfc_issue_els_rrq if the rrq is
  6786. * still active for the xri. If this function returns a failure then
  6787. * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
  6788. *
  6789. * Returns 0 Success.
  6790. * 1 Failure.
  6791. **/
  6792. int
  6793. lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
  6794. {
  6795. struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
  6796. rrq->nlp_DID);
  6797. if (!ndlp)
  6798. return 1;
  6799. if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
  6800. return lpfc_issue_els_rrq(rrq->vport, ndlp,
  6801. rrq->nlp_DID, rrq);
  6802. else
  6803. return 1;
  6804. }
  6805. /**
  6806. * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
  6807. * @vport: pointer to a host virtual N_Port data structure.
  6808. * @cmdsize: size of the ELS command.
  6809. * @oldiocb: pointer to the original lpfc command iocb data structure.
  6810. * @ndlp: pointer to a node-list data structure.
  6811. *
  6812. * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
  6813. * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
  6814. *
  6815. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  6816. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  6817. * will be stored into the context1 field of the IOCB for the completion
  6818. * callback function to the RPL Accept Response ELS command.
  6819. *
  6820. * Return code
  6821. * 0 - Successfully issued ACC RPL ELS command
  6822. * 1 - Failed to issue ACC RPL ELS command
  6823. **/
  6824. static int
  6825. lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
  6826. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  6827. {
  6828. struct lpfc_hba *phba = vport->phba;
  6829. IOCB_t *icmd, *oldcmd;
  6830. RPL_RSP rpl_rsp;
  6831. struct lpfc_iocbq *elsiocb;
  6832. uint8_t *pcmd;
  6833. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  6834. ndlp->nlp_DID, ELS_CMD_ACC);
  6835. if (!elsiocb)
  6836. return 1;
  6837. icmd = &elsiocb->iocb;
  6838. oldcmd = &oldiocb->iocb;
  6839. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  6840. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  6841. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  6842. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  6843. pcmd += sizeof(uint16_t);
  6844. *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
  6845. pcmd += sizeof(uint16_t);
  6846. /* Setup the RPL ACC payload */
  6847. rpl_rsp.listLen = be32_to_cpu(1);
  6848. rpl_rsp.index = 0;
  6849. rpl_rsp.port_num_blk.portNum = 0;
  6850. rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
  6851. memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
  6852. sizeof(struct lpfc_name));
  6853. memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
  6854. /* Xmit ELS RPL ACC response tag <ulpIoTag> */
  6855. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6856. "0120 Xmit ELS RPL ACC response tag x%x "
  6857. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  6858. "rpi x%x\n",
  6859. elsiocb->iotag, elsiocb->iocb.ulpContext,
  6860. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  6861. ndlp->nlp_rpi);
  6862. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  6863. phba->fc_stat.elsXmitACC++;
  6864. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  6865. IOCB_ERROR) {
  6866. lpfc_els_free_iocb(phba, elsiocb);
  6867. return 1;
  6868. }
  6869. return 0;
  6870. }
  6871. /**
  6872. * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
  6873. * @vport: pointer to a host virtual N_Port data structure.
  6874. * @cmdiocb: pointer to lpfc command iocb data structure.
  6875. * @ndlp: pointer to a node-list data structure.
  6876. *
  6877. * This routine processes Read Port List (RPL) IOCB received as an ELS
  6878. * unsolicited event. It first checks the remote port state. If the remote
  6879. * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
  6880. * invokes the lpfc_els_rsp_reject() routine to send reject response.
  6881. * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
  6882. * to accept the RPL.
  6883. *
  6884. * Return code
  6885. * 0 - Successfully processed rpl iocb (currently always return 0)
  6886. **/
  6887. static int
  6888. lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  6889. struct lpfc_nodelist *ndlp)
  6890. {
  6891. struct lpfc_dmabuf *pcmd;
  6892. uint32_t *lp;
  6893. uint32_t maxsize;
  6894. uint16_t cmdsize;
  6895. RPL *rpl;
  6896. struct ls_rjt stat;
  6897. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  6898. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  6899. /* issue rejection response */
  6900. stat.un.b.lsRjtRsvd0 = 0;
  6901. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  6902. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  6903. stat.un.b.vendorUnique = 0;
  6904. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  6905. NULL);
  6906. /* rejected the unsolicited RPL request and done with it */
  6907. return 0;
  6908. }
  6909. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  6910. lp = (uint32_t *) pcmd->virt;
  6911. rpl = (RPL *) (lp + 1);
  6912. maxsize = be32_to_cpu(rpl->maxsize);
  6913. /* We support only one port */
  6914. if ((rpl->index == 0) &&
  6915. ((maxsize == 0) ||
  6916. ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
  6917. cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
  6918. } else {
  6919. cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
  6920. }
  6921. lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
  6922. return 0;
  6923. }
  6924. /**
  6925. * lpfc_els_rcv_farp - Process an unsolicited farp request els command
  6926. * @vport: pointer to a virtual N_Port data structure.
  6927. * @cmdiocb: pointer to lpfc command iocb data structure.
  6928. * @ndlp: pointer to a node-list data structure.
  6929. *
  6930. * This routine processes Fibre Channel Address Resolution Protocol
  6931. * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
  6932. * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
  6933. * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
  6934. * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
  6935. * remote PortName is compared against the FC PortName stored in the @vport
  6936. * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
  6937. * compared against the FC NodeName stored in the @vport data structure.
  6938. * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
  6939. * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
  6940. * invoked to send out FARP Response to the remote node. Before sending the
  6941. * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
  6942. * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
  6943. * routine is invoked to log into the remote port first.
  6944. *
  6945. * Return code
  6946. * 0 - Either the FARP Match Mode not supported or successfully processed
  6947. **/
  6948. static int
  6949. lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  6950. struct lpfc_nodelist *ndlp)
  6951. {
  6952. struct lpfc_dmabuf *pcmd;
  6953. uint32_t *lp;
  6954. IOCB_t *icmd;
  6955. FARP *fp;
  6956. uint32_t cnt, did;
  6957. icmd = &cmdiocb->iocb;
  6958. did = icmd->un.elsreq64.remoteID;
  6959. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  6960. lp = (uint32_t *) pcmd->virt;
  6961. lp++;
  6962. fp = (FARP *) lp;
  6963. /* FARP-REQ received from DID <did> */
  6964. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6965. "0601 FARP-REQ received from DID x%x\n", did);
  6966. /* We will only support match on WWPN or WWNN */
  6967. if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
  6968. return 0;
  6969. }
  6970. cnt = 0;
  6971. /* If this FARP command is searching for my portname */
  6972. if (fp->Mflags & FARP_MATCH_PORT) {
  6973. if (memcmp(&fp->RportName, &vport->fc_portname,
  6974. sizeof(struct lpfc_name)) == 0)
  6975. cnt = 1;
  6976. }
  6977. /* If this FARP command is searching for my nodename */
  6978. if (fp->Mflags & FARP_MATCH_NODE) {
  6979. if (memcmp(&fp->RnodeName, &vport->fc_nodename,
  6980. sizeof(struct lpfc_name)) == 0)
  6981. cnt = 1;
  6982. }
  6983. if (cnt) {
  6984. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  6985. (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
  6986. /* Log back into the node before sending the FARP. */
  6987. if (fp->Rflags & FARP_REQUEST_PLOGI) {
  6988. ndlp->nlp_prev_state = ndlp->nlp_state;
  6989. lpfc_nlp_set_state(vport, ndlp,
  6990. NLP_STE_PLOGI_ISSUE);
  6991. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  6992. }
  6993. /* Send a FARP response to that node */
  6994. if (fp->Rflags & FARP_REQUEST_FARPR)
  6995. lpfc_issue_els_farpr(vport, did, 0);
  6996. }
  6997. }
  6998. return 0;
  6999. }
  7000. /**
  7001. * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
  7002. * @vport: pointer to a host virtual N_Port data structure.
  7003. * @cmdiocb: pointer to lpfc command iocb data structure.
  7004. * @ndlp: pointer to a node-list data structure.
  7005. *
  7006. * This routine processes Fibre Channel Address Resolution Protocol
  7007. * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
  7008. * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
  7009. * the FARP response request.
  7010. *
  7011. * Return code
  7012. * 0 - Successfully processed FARPR IOCB (currently always return 0)
  7013. **/
  7014. static int
  7015. lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  7016. struct lpfc_nodelist *ndlp)
  7017. {
  7018. struct lpfc_dmabuf *pcmd;
  7019. uint32_t *lp;
  7020. IOCB_t *icmd;
  7021. uint32_t did;
  7022. icmd = &cmdiocb->iocb;
  7023. did = icmd->un.elsreq64.remoteID;
  7024. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  7025. lp = (uint32_t *) pcmd->virt;
  7026. lp++;
  7027. /* FARP-RSP received from DID <did> */
  7028. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  7029. "0600 FARP-RSP received from DID x%x\n", did);
  7030. /* ACCEPT the Farp resp request */
  7031. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  7032. return 0;
  7033. }
  7034. /**
  7035. * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
  7036. * @vport: pointer to a host virtual N_Port data structure.
  7037. * @cmdiocb: pointer to lpfc command iocb data structure.
  7038. * @fan_ndlp: pointer to a node-list data structure.
  7039. *
  7040. * This routine processes a Fabric Address Notification (FAN) IOCB
  7041. * command received as an ELS unsolicited event. The FAN ELS command will
  7042. * only be processed on a physical port (i.e., the @vport represents the
  7043. * physical port). The fabric NodeName and PortName from the FAN IOCB are
  7044. * compared against those in the phba data structure. If any of those is
  7045. * different, the lpfc_initial_flogi() routine is invoked to initialize
  7046. * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
  7047. * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
  7048. * is invoked to register login to the fabric.
  7049. *
  7050. * Return code
  7051. * 0 - Successfully processed fan iocb (currently always return 0).
  7052. **/
  7053. static int
  7054. lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  7055. struct lpfc_nodelist *fan_ndlp)
  7056. {
  7057. struct lpfc_hba *phba = vport->phba;
  7058. uint32_t *lp;
  7059. FAN *fp;
  7060. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
  7061. lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
  7062. fp = (FAN *) ++lp;
  7063. /* FAN received; Fan does not have a reply sequence */
  7064. if ((vport == phba->pport) &&
  7065. (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
  7066. if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
  7067. sizeof(struct lpfc_name))) ||
  7068. (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
  7069. sizeof(struct lpfc_name)))) {
  7070. /* This port has switched fabrics. FLOGI is required */
  7071. lpfc_issue_init_vfi(vport);
  7072. } else {
  7073. /* FAN verified - skip FLOGI */
  7074. vport->fc_myDID = vport->fc_prevDID;
  7075. if (phba->sli_rev < LPFC_SLI_REV4)
  7076. lpfc_issue_fabric_reglogin(vport);
  7077. else {
  7078. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  7079. "3138 Need register VFI: (x%x/%x)\n",
  7080. vport->fc_prevDID, vport->fc_myDID);
  7081. lpfc_issue_reg_vfi(vport);
  7082. }
  7083. }
  7084. }
  7085. return 0;
  7086. }
  7087. /**
  7088. * lpfc_els_timeout - Handler funciton to the els timer
  7089. * @ptr: holder for the timer function associated data.
  7090. *
  7091. * This routine is invoked by the ELS timer after timeout. It posts the ELS
  7092. * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
  7093. * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
  7094. * up the worker thread. It is for the worker thread to invoke the routine
  7095. * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
  7096. **/
  7097. void
  7098. lpfc_els_timeout(struct timer_list *t)
  7099. {
  7100. struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
  7101. struct lpfc_hba *phba = vport->phba;
  7102. uint32_t tmo_posted;
  7103. unsigned long iflag;
  7104. spin_lock_irqsave(&vport->work_port_lock, iflag);
  7105. tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
  7106. if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
  7107. vport->work_port_events |= WORKER_ELS_TMO;
  7108. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  7109. if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
  7110. lpfc_worker_wake_up(phba);
  7111. return;
  7112. }
  7113. /**
  7114. * lpfc_els_timeout_handler - Process an els timeout event
  7115. * @vport: pointer to a virtual N_Port data structure.
  7116. *
  7117. * This routine is the actual handler function that processes an ELS timeout
  7118. * event. It walks the ELS ring to get and abort all the IOCBs (except the
  7119. * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
  7120. * invoking the lpfc_sli_issue_abort_iotag() routine.
  7121. **/
  7122. void
  7123. lpfc_els_timeout_handler(struct lpfc_vport *vport)
  7124. {
  7125. struct lpfc_hba *phba = vport->phba;
  7126. struct lpfc_sli_ring *pring;
  7127. struct lpfc_iocbq *tmp_iocb, *piocb;
  7128. IOCB_t *cmd = NULL;
  7129. struct lpfc_dmabuf *pcmd;
  7130. uint32_t els_command = 0;
  7131. uint32_t timeout;
  7132. uint32_t remote_ID = 0xffffffff;
  7133. LIST_HEAD(abort_list);
  7134. timeout = (uint32_t)(phba->fc_ratov << 1);
  7135. pring = lpfc_phba_elsring(phba);
  7136. if (unlikely(!pring))
  7137. return;
  7138. if ((phba->pport->load_flag & FC_UNLOADING))
  7139. return;
  7140. spin_lock_irq(&phba->hbalock);
  7141. if (phba->sli_rev == LPFC_SLI_REV4)
  7142. spin_lock(&pring->ring_lock);
  7143. if ((phba->pport->load_flag & FC_UNLOADING)) {
  7144. if (phba->sli_rev == LPFC_SLI_REV4)
  7145. spin_unlock(&pring->ring_lock);
  7146. spin_unlock_irq(&phba->hbalock);
  7147. return;
  7148. }
  7149. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  7150. cmd = &piocb->iocb;
  7151. if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
  7152. piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  7153. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  7154. continue;
  7155. if (piocb->vport != vport)
  7156. continue;
  7157. pcmd = (struct lpfc_dmabuf *) piocb->context2;
  7158. if (pcmd)
  7159. els_command = *(uint32_t *) (pcmd->virt);
  7160. if (els_command == ELS_CMD_FARP ||
  7161. els_command == ELS_CMD_FARPR ||
  7162. els_command == ELS_CMD_FDISC)
  7163. continue;
  7164. if (piocb->drvrTimeout > 0) {
  7165. if (piocb->drvrTimeout >= timeout)
  7166. piocb->drvrTimeout -= timeout;
  7167. else
  7168. piocb->drvrTimeout = 0;
  7169. continue;
  7170. }
  7171. remote_ID = 0xffffffff;
  7172. if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
  7173. remote_ID = cmd->un.elsreq64.remoteID;
  7174. else {
  7175. struct lpfc_nodelist *ndlp;
  7176. ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
  7177. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  7178. remote_ID = ndlp->nlp_DID;
  7179. }
  7180. list_add_tail(&piocb->dlist, &abort_list);
  7181. }
  7182. if (phba->sli_rev == LPFC_SLI_REV4)
  7183. spin_unlock(&pring->ring_lock);
  7184. spin_unlock_irq(&phba->hbalock);
  7185. list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
  7186. cmd = &piocb->iocb;
  7187. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  7188. "0127 ELS timeout Data: x%x x%x x%x "
  7189. "x%x\n", els_command,
  7190. remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
  7191. spin_lock_irq(&phba->hbalock);
  7192. list_del_init(&piocb->dlist);
  7193. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  7194. spin_unlock_irq(&phba->hbalock);
  7195. }
  7196. if (!list_empty(&pring->txcmplq))
  7197. if (!(phba->pport->load_flag & FC_UNLOADING))
  7198. mod_timer(&vport->els_tmofunc,
  7199. jiffies + msecs_to_jiffies(1000 * timeout));
  7200. }
  7201. /**
  7202. * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
  7203. * @vport: pointer to a host virtual N_Port data structure.
  7204. *
  7205. * This routine is used to clean up all the outstanding ELS commands on a
  7206. * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
  7207. * routine. After that, it walks the ELS transmit queue to remove all the
  7208. * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
  7209. * the IOCBs with a non-NULL completion callback function, the callback
  7210. * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
  7211. * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
  7212. * callback function, the IOCB will simply be released. Finally, it walks
  7213. * the ELS transmit completion queue to issue an abort IOCB to any transmit
  7214. * completion queue IOCB that is associated with the @vport and is not
  7215. * an IOCB from libdfc (i.e., the management plane IOCBs that are not
  7216. * part of the discovery state machine) out to HBA by invoking the
  7217. * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
  7218. * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
  7219. * the IOCBs are aborted when this function returns.
  7220. **/
  7221. void
  7222. lpfc_els_flush_cmd(struct lpfc_vport *vport)
  7223. {
  7224. LIST_HEAD(abort_list);
  7225. struct lpfc_hba *phba = vport->phba;
  7226. struct lpfc_sli_ring *pring;
  7227. struct lpfc_iocbq *tmp_iocb, *piocb;
  7228. IOCB_t *cmd = NULL;
  7229. unsigned long iflags = 0;
  7230. lpfc_fabric_abort_vport(vport);
  7231. /*
  7232. * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
  7233. * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
  7234. * ultimately grabs the ring_lock, the driver must splice the list into
  7235. * a working list and release the locks before calling the abort.
  7236. */
  7237. spin_lock_irqsave(&phba->hbalock, iflags);
  7238. pring = lpfc_phba_elsring(phba);
  7239. /* Bail out if we've no ELS wq, like in PCI error recovery case. */
  7240. if (unlikely(!pring)) {
  7241. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7242. return;
  7243. }
  7244. if (phba->sli_rev == LPFC_SLI_REV4)
  7245. spin_lock(&pring->ring_lock);
  7246. /* First we need to issue aborts to outstanding cmds on txcmpl */
  7247. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  7248. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  7249. continue;
  7250. if (piocb->vport != vport)
  7251. continue;
  7252. if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
  7253. continue;
  7254. /* On the ELS ring we can have ELS_REQUESTs or
  7255. * GEN_REQUESTs waiting for a response.
  7256. */
  7257. cmd = &piocb->iocb;
  7258. if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
  7259. list_add_tail(&piocb->dlist, &abort_list);
  7260. /* If the link is down when flushing ELS commands
  7261. * the firmware will not complete them till after
  7262. * the link comes back up. This may confuse
  7263. * discovery for the new link up, so we need to
  7264. * change the compl routine to just clean up the iocb
  7265. * and avoid any retry logic.
  7266. */
  7267. if (phba->link_state == LPFC_LINK_DOWN)
  7268. piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
  7269. }
  7270. if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
  7271. list_add_tail(&piocb->dlist, &abort_list);
  7272. }
  7273. if (phba->sli_rev == LPFC_SLI_REV4)
  7274. spin_unlock(&pring->ring_lock);
  7275. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7276. /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
  7277. list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
  7278. spin_lock_irqsave(&phba->hbalock, iflags);
  7279. list_del_init(&piocb->dlist);
  7280. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  7281. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7282. }
  7283. if (!list_empty(&abort_list))
  7284. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  7285. "3387 abort list for txq not empty\n");
  7286. INIT_LIST_HEAD(&abort_list);
  7287. spin_lock_irqsave(&phba->hbalock, iflags);
  7288. if (phba->sli_rev == LPFC_SLI_REV4)
  7289. spin_lock(&pring->ring_lock);
  7290. /* No need to abort the txq list,
  7291. * just queue them up for lpfc_sli_cancel_iocbs
  7292. */
  7293. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  7294. cmd = &piocb->iocb;
  7295. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  7296. continue;
  7297. }
  7298. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  7299. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  7300. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  7301. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7302. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  7303. continue;
  7304. if (piocb->vport != vport)
  7305. continue;
  7306. list_del_init(&piocb->list);
  7307. list_add_tail(&piocb->list, &abort_list);
  7308. }
  7309. /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
  7310. if (vport == phba->pport) {
  7311. list_for_each_entry_safe(piocb, tmp_iocb,
  7312. &phba->fabric_iocb_list, list) {
  7313. cmd = &piocb->iocb;
  7314. list_del_init(&piocb->list);
  7315. list_add_tail(&piocb->list, &abort_list);
  7316. }
  7317. }
  7318. if (phba->sli_rev == LPFC_SLI_REV4)
  7319. spin_unlock(&pring->ring_lock);
  7320. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7321. /* Cancel all the IOCBs from the completions list */
  7322. lpfc_sli_cancel_iocbs(phba, &abort_list,
  7323. IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
  7324. return;
  7325. }
  7326. /**
  7327. * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
  7328. * @phba: pointer to lpfc hba data structure.
  7329. *
  7330. * This routine is used to clean up all the outstanding ELS commands on a
  7331. * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
  7332. * routine. After that, it walks the ELS transmit queue to remove all the
  7333. * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
  7334. * the IOCBs with the completion callback function associated, the callback
  7335. * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
  7336. * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
  7337. * callback function associated, the IOCB will simply be released. Finally,
  7338. * it walks the ELS transmit completion queue to issue an abort IOCB to any
  7339. * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
  7340. * management plane IOCBs that are not part of the discovery state machine)
  7341. * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
  7342. **/
  7343. void
  7344. lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
  7345. {
  7346. struct lpfc_vport *vport;
  7347. spin_lock_irq(&phba->port_list_lock);
  7348. list_for_each_entry(vport, &phba->port_list, listentry)
  7349. lpfc_els_flush_cmd(vport);
  7350. spin_unlock_irq(&phba->port_list_lock);
  7351. return;
  7352. }
  7353. /**
  7354. * lpfc_send_els_failure_event - Posts an ELS command failure event
  7355. * @phba: Pointer to hba context object.
  7356. * @cmdiocbp: Pointer to command iocb which reported error.
  7357. * @rspiocbp: Pointer to response iocb which reported error.
  7358. *
  7359. * This function sends an event when there is an ELS command
  7360. * failure.
  7361. **/
  7362. void
  7363. lpfc_send_els_failure_event(struct lpfc_hba *phba,
  7364. struct lpfc_iocbq *cmdiocbp,
  7365. struct lpfc_iocbq *rspiocbp)
  7366. {
  7367. struct lpfc_vport *vport = cmdiocbp->vport;
  7368. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  7369. struct lpfc_lsrjt_event lsrjt_event;
  7370. struct lpfc_fabric_event_header fabric_event;
  7371. struct ls_rjt stat;
  7372. struct lpfc_nodelist *ndlp;
  7373. uint32_t *pcmd;
  7374. ndlp = cmdiocbp->context1;
  7375. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  7376. return;
  7377. if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
  7378. lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
  7379. lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
  7380. memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
  7381. sizeof(struct lpfc_name));
  7382. memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
  7383. sizeof(struct lpfc_name));
  7384. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7385. cmdiocbp->context2)->virt);
  7386. lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
  7387. stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
  7388. lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
  7389. lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
  7390. fc_host_post_vendor_event(shost,
  7391. fc_get_event_number(),
  7392. sizeof(lsrjt_event),
  7393. (char *)&lsrjt_event,
  7394. LPFC_NL_VENDOR_ID);
  7395. return;
  7396. }
  7397. if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
  7398. (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
  7399. fabric_event.event_type = FC_REG_FABRIC_EVENT;
  7400. if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
  7401. fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
  7402. else
  7403. fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
  7404. memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
  7405. sizeof(struct lpfc_name));
  7406. memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
  7407. sizeof(struct lpfc_name));
  7408. fc_host_post_vendor_event(shost,
  7409. fc_get_event_number(),
  7410. sizeof(fabric_event),
  7411. (char *)&fabric_event,
  7412. LPFC_NL_VENDOR_ID);
  7413. return;
  7414. }
  7415. }
  7416. /**
  7417. * lpfc_send_els_event - Posts unsolicited els event
  7418. * @vport: Pointer to vport object.
  7419. * @ndlp: Pointer FC node object.
  7420. * @cmd: ELS command code.
  7421. *
  7422. * This function posts an event when there is an incoming
  7423. * unsolicited ELS command.
  7424. **/
  7425. static void
  7426. lpfc_send_els_event(struct lpfc_vport *vport,
  7427. struct lpfc_nodelist *ndlp,
  7428. uint32_t *payload)
  7429. {
  7430. struct lpfc_els_event_header *els_data = NULL;
  7431. struct lpfc_logo_event *logo_data = NULL;
  7432. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  7433. if (*payload == ELS_CMD_LOGO) {
  7434. logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
  7435. if (!logo_data) {
  7436. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  7437. "0148 Failed to allocate memory "
  7438. "for LOGO event\n");
  7439. return;
  7440. }
  7441. els_data = &logo_data->header;
  7442. } else {
  7443. els_data = kmalloc(sizeof(struct lpfc_els_event_header),
  7444. GFP_KERNEL);
  7445. if (!els_data) {
  7446. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  7447. "0149 Failed to allocate memory "
  7448. "for ELS event\n");
  7449. return;
  7450. }
  7451. }
  7452. els_data->event_type = FC_REG_ELS_EVENT;
  7453. switch (*payload) {
  7454. case ELS_CMD_PLOGI:
  7455. els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
  7456. break;
  7457. case ELS_CMD_PRLO:
  7458. els_data->subcategory = LPFC_EVENT_PRLO_RCV;
  7459. break;
  7460. case ELS_CMD_ADISC:
  7461. els_data->subcategory = LPFC_EVENT_ADISC_RCV;
  7462. break;
  7463. case ELS_CMD_LOGO:
  7464. els_data->subcategory = LPFC_EVENT_LOGO_RCV;
  7465. /* Copy the WWPN in the LOGO payload */
  7466. memcpy(logo_data->logo_wwpn, &payload[2],
  7467. sizeof(struct lpfc_name));
  7468. break;
  7469. default:
  7470. kfree(els_data);
  7471. return;
  7472. }
  7473. memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
  7474. memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
  7475. if (*payload == ELS_CMD_LOGO) {
  7476. fc_host_post_vendor_event(shost,
  7477. fc_get_event_number(),
  7478. sizeof(struct lpfc_logo_event),
  7479. (char *)logo_data,
  7480. LPFC_NL_VENDOR_ID);
  7481. kfree(logo_data);
  7482. } else {
  7483. fc_host_post_vendor_event(shost,
  7484. fc_get_event_number(),
  7485. sizeof(struct lpfc_els_event_header),
  7486. (char *)els_data,
  7487. LPFC_NL_VENDOR_ID);
  7488. kfree(els_data);
  7489. }
  7490. return;
  7491. }
  7492. DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
  7493. FC_LS_TLV_DTAG_INIT);
  7494. DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
  7495. FC_FPIN_LI_EVT_TYPES_INIT);
  7496. /**
  7497. * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
  7498. * @vport: Pointer to vport object.
  7499. * @lnk_not: Pointer to the Link Integrity Notification Descriptor.
  7500. *
  7501. * This function processes a link integrity FPIN event by
  7502. * logging a message
  7503. **/
  7504. static void
  7505. lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv)
  7506. {
  7507. struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
  7508. const char *li_evt_str;
  7509. u32 li_evt;
  7510. li_evt = be16_to_cpu(li->event_type);
  7511. li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
  7512. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  7513. "4680 FPIN Link Integrity %s (x%x) "
  7514. "Detecting PN x%016llx Attached PN x%016llx "
  7515. "Duration %d mSecs Count %d Port Cnt %d\n",
  7516. li_evt_str, li_evt,
  7517. be64_to_cpu(li->detecting_wwpn),
  7518. be64_to_cpu(li->attached_wwpn),
  7519. be32_to_cpu(li->event_threshold),
  7520. be32_to_cpu(li->event_count),
  7521. be32_to_cpu(li->pname_count));
  7522. }
  7523. static void
  7524. lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin,
  7525. u32 fpin_length)
  7526. {
  7527. struct fc_tlv_desc *tlv;
  7528. const char *dtag_nm;
  7529. uint32_t desc_cnt = 0, bytes_remain;
  7530. u32 dtag;
  7531. /* FPINs handled only if we are in the right discovery state */
  7532. if (vport->port_state < LPFC_DISC_AUTH)
  7533. return;
  7534. /* make sure there is the full fpin header */
  7535. if (fpin_length < sizeof(struct fc_els_fpin))
  7536. return;
  7537. tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
  7538. bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
  7539. bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
  7540. /* process each descriptor */
  7541. while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
  7542. bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
  7543. dtag = be32_to_cpu(tlv->desc_tag);
  7544. switch (dtag) {
  7545. case ELS_DTAG_LNK_INTEGRITY:
  7546. lpfc_els_rcv_fpin_li(vport, tlv);
  7547. break;
  7548. default:
  7549. dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
  7550. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  7551. "4678 skipped FPIN descriptor[%d]: "
  7552. "tag x%x (%s)\n",
  7553. desc_cnt, dtag, dtag_nm);
  7554. break;
  7555. }
  7556. desc_cnt++;
  7557. bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
  7558. tlv = fc_tlv_next_desc(tlv);
  7559. }
  7560. fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length,
  7561. (char *)fpin);
  7562. }
  7563. /**
  7564. * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
  7565. * @phba: pointer to lpfc hba data structure.
  7566. * @pring: pointer to a SLI ring.
  7567. * @vport: pointer to a host virtual N_Port data structure.
  7568. * @elsiocb: pointer to lpfc els command iocb data structure.
  7569. *
  7570. * This routine is used for processing the IOCB associated with a unsolicited
  7571. * event. It first determines whether there is an existing ndlp that matches
  7572. * the DID from the unsolicited IOCB. If not, it will create a new one with
  7573. * the DID from the unsolicited IOCB. The ELS command from the unsolicited
  7574. * IOCB is then used to invoke the proper routine and to set up proper state
  7575. * of the discovery state machine.
  7576. **/
  7577. static void
  7578. lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7579. struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
  7580. {
  7581. struct Scsi_Host *shost;
  7582. struct lpfc_nodelist *ndlp;
  7583. struct ls_rjt stat;
  7584. uint32_t *payload, payload_len;
  7585. uint32_t cmd, did, newnode;
  7586. uint8_t rjt_exp, rjt_err = 0, init_link = 0;
  7587. IOCB_t *icmd = &elsiocb->iocb;
  7588. LPFC_MBOXQ_t *mbox;
  7589. if (!vport || !(elsiocb->context2))
  7590. goto dropit;
  7591. newnode = 0;
  7592. payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
  7593. payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
  7594. cmd = *payload;
  7595. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
  7596. lpfc_post_buffer(phba, pring, 1);
  7597. did = icmd->un.rcvels.remoteID;
  7598. if (icmd->ulpStatus) {
  7599. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7600. "RCV Unsol ELS: status:x%x/x%x did:x%x",
  7601. icmd->ulpStatus, icmd->un.ulpWord[4], did);
  7602. goto dropit;
  7603. }
  7604. /* Check to see if link went down during discovery */
  7605. if (lpfc_els_chk_latt(vport))
  7606. goto dropit;
  7607. /* Ignore traffic received during vport shutdown. */
  7608. if (vport->load_flag & FC_UNLOADING)
  7609. goto dropit;
  7610. /* If NPort discovery is delayed drop incoming ELS */
  7611. if ((vport->fc_flag & FC_DISC_DELAYED) &&
  7612. (cmd != ELS_CMD_PLOGI))
  7613. goto dropit;
  7614. ndlp = lpfc_findnode_did(vport, did);
  7615. if (!ndlp) {
  7616. /* Cannot find existing Fabric ndlp, so allocate a new one */
  7617. ndlp = lpfc_nlp_init(vport, did);
  7618. if (!ndlp)
  7619. goto dropit;
  7620. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  7621. newnode = 1;
  7622. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  7623. ndlp->nlp_type |= NLP_FABRIC;
  7624. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  7625. ndlp = lpfc_enable_node(vport, ndlp,
  7626. NLP_STE_UNUSED_NODE);
  7627. if (!ndlp)
  7628. goto dropit;
  7629. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  7630. newnode = 1;
  7631. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  7632. ndlp->nlp_type |= NLP_FABRIC;
  7633. } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  7634. /* This is similar to the new node path */
  7635. ndlp = lpfc_nlp_get(ndlp);
  7636. if (!ndlp)
  7637. goto dropit;
  7638. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  7639. newnode = 1;
  7640. }
  7641. phba->fc_stat.elsRcvFrame++;
  7642. /*
  7643. * Do not process any unsolicited ELS commands
  7644. * if the ndlp is in DEV_LOSS
  7645. */
  7646. shost = lpfc_shost_from_vport(vport);
  7647. spin_lock_irq(shost->host_lock);
  7648. if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
  7649. spin_unlock_irq(shost->host_lock);
  7650. goto dropit;
  7651. }
  7652. spin_unlock_irq(shost->host_lock);
  7653. elsiocb->context1 = lpfc_nlp_get(ndlp);
  7654. elsiocb->vport = vport;
  7655. if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
  7656. cmd &= ELS_CMD_MASK;
  7657. }
  7658. /* ELS command <elsCmd> received from NPORT <did> */
  7659. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  7660. "0112 ELS command x%x received from NPORT x%x "
  7661. "Data: x%x x%x x%x x%x\n",
  7662. cmd, did, vport->port_state, vport->fc_flag,
  7663. vport->fc_myDID, vport->fc_prevDID);
  7664. /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
  7665. if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
  7666. (cmd != ELS_CMD_FLOGI) &&
  7667. !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
  7668. rjt_err = LSRJT_LOGICAL_BSY;
  7669. rjt_exp = LSEXP_NOTHING_MORE;
  7670. goto lsrjt;
  7671. }
  7672. switch (cmd) {
  7673. case ELS_CMD_PLOGI:
  7674. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7675. "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
  7676. did, vport->port_state, ndlp->nlp_flag);
  7677. phba->fc_stat.elsRcvPLOGI++;
  7678. ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
  7679. if (phba->sli_rev == LPFC_SLI_REV4 &&
  7680. (phba->pport->fc_flag & FC_PT2PT)) {
  7681. vport->fc_prevDID = vport->fc_myDID;
  7682. /* Our DID needs to be updated before registering
  7683. * the vfi. This is done in lpfc_rcv_plogi but
  7684. * that is called after the reg_vfi.
  7685. */
  7686. vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
  7687. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  7688. "3312 Remote port assigned DID x%x "
  7689. "%x\n", vport->fc_myDID,
  7690. vport->fc_prevDID);
  7691. }
  7692. lpfc_send_els_event(vport, ndlp, payload);
  7693. /* If Nport discovery is delayed, reject PLOGIs */
  7694. if (vport->fc_flag & FC_DISC_DELAYED) {
  7695. rjt_err = LSRJT_UNABLE_TPC;
  7696. rjt_exp = LSEXP_NOTHING_MORE;
  7697. break;
  7698. }
  7699. if (vport->port_state < LPFC_DISC_AUTH) {
  7700. if (!(phba->pport->fc_flag & FC_PT2PT) ||
  7701. (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
  7702. rjt_err = LSRJT_UNABLE_TPC;
  7703. rjt_exp = LSEXP_NOTHING_MORE;
  7704. break;
  7705. }
  7706. }
  7707. spin_lock_irq(shost->host_lock);
  7708. ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
  7709. spin_unlock_irq(shost->host_lock);
  7710. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  7711. NLP_EVT_RCV_PLOGI);
  7712. break;
  7713. case ELS_CMD_FLOGI:
  7714. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7715. "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
  7716. did, vport->port_state, ndlp->nlp_flag);
  7717. phba->fc_stat.elsRcvFLOGI++;
  7718. /* If the driver believes fabric discovery is done and is ready,
  7719. * bounce the link. There is some descrepancy.
  7720. */
  7721. if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
  7722. vport->fc_flag & FC_PT2PT &&
  7723. vport->rcv_flogi_cnt >= 1) {
  7724. rjt_err = LSRJT_LOGICAL_BSY;
  7725. rjt_exp = LSEXP_NOTHING_MORE;
  7726. init_link++;
  7727. goto lsrjt;
  7728. }
  7729. lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
  7730. if (newnode)
  7731. lpfc_nlp_put(ndlp);
  7732. break;
  7733. case ELS_CMD_LOGO:
  7734. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7735. "RCV LOGO: did:x%x/ste:x%x flg:x%x",
  7736. did, vport->port_state, ndlp->nlp_flag);
  7737. phba->fc_stat.elsRcvLOGO++;
  7738. lpfc_send_els_event(vport, ndlp, payload);
  7739. if (vport->port_state < LPFC_DISC_AUTH) {
  7740. rjt_err = LSRJT_UNABLE_TPC;
  7741. rjt_exp = LSEXP_NOTHING_MORE;
  7742. break;
  7743. }
  7744. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
  7745. break;
  7746. case ELS_CMD_PRLO:
  7747. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7748. "RCV PRLO: did:x%x/ste:x%x flg:x%x",
  7749. did, vport->port_state, ndlp->nlp_flag);
  7750. phba->fc_stat.elsRcvPRLO++;
  7751. lpfc_send_els_event(vport, ndlp, payload);
  7752. if (vport->port_state < LPFC_DISC_AUTH) {
  7753. rjt_err = LSRJT_UNABLE_TPC;
  7754. rjt_exp = LSEXP_NOTHING_MORE;
  7755. break;
  7756. }
  7757. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
  7758. break;
  7759. case ELS_CMD_LCB:
  7760. phba->fc_stat.elsRcvLCB++;
  7761. lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
  7762. break;
  7763. case ELS_CMD_RDP:
  7764. phba->fc_stat.elsRcvRDP++;
  7765. lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
  7766. break;
  7767. case ELS_CMD_RSCN:
  7768. phba->fc_stat.elsRcvRSCN++;
  7769. lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
  7770. if (newnode)
  7771. lpfc_nlp_put(ndlp);
  7772. break;
  7773. case ELS_CMD_ADISC:
  7774. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7775. "RCV ADISC: did:x%x/ste:x%x flg:x%x",
  7776. did, vport->port_state, ndlp->nlp_flag);
  7777. lpfc_send_els_event(vport, ndlp, payload);
  7778. phba->fc_stat.elsRcvADISC++;
  7779. if (vport->port_state < LPFC_DISC_AUTH) {
  7780. rjt_err = LSRJT_UNABLE_TPC;
  7781. rjt_exp = LSEXP_NOTHING_MORE;
  7782. break;
  7783. }
  7784. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  7785. NLP_EVT_RCV_ADISC);
  7786. break;
  7787. case ELS_CMD_PDISC:
  7788. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7789. "RCV PDISC: did:x%x/ste:x%x flg:x%x",
  7790. did, vport->port_state, ndlp->nlp_flag);
  7791. phba->fc_stat.elsRcvPDISC++;
  7792. if (vport->port_state < LPFC_DISC_AUTH) {
  7793. rjt_err = LSRJT_UNABLE_TPC;
  7794. rjt_exp = LSEXP_NOTHING_MORE;
  7795. break;
  7796. }
  7797. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  7798. NLP_EVT_RCV_PDISC);
  7799. break;
  7800. case ELS_CMD_FARPR:
  7801. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7802. "RCV FARPR: did:x%x/ste:x%x flg:x%x",
  7803. did, vport->port_state, ndlp->nlp_flag);
  7804. phba->fc_stat.elsRcvFARPR++;
  7805. lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
  7806. break;
  7807. case ELS_CMD_FARP:
  7808. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7809. "RCV FARP: did:x%x/ste:x%x flg:x%x",
  7810. did, vport->port_state, ndlp->nlp_flag);
  7811. phba->fc_stat.elsRcvFARP++;
  7812. lpfc_els_rcv_farp(vport, elsiocb, ndlp);
  7813. break;
  7814. case ELS_CMD_FAN:
  7815. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7816. "RCV FAN: did:x%x/ste:x%x flg:x%x",
  7817. did, vport->port_state, ndlp->nlp_flag);
  7818. phba->fc_stat.elsRcvFAN++;
  7819. lpfc_els_rcv_fan(vport, elsiocb, ndlp);
  7820. break;
  7821. case ELS_CMD_PRLI:
  7822. case ELS_CMD_NVMEPRLI:
  7823. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7824. "RCV PRLI: did:x%x/ste:x%x flg:x%x",
  7825. did, vport->port_state, ndlp->nlp_flag);
  7826. phba->fc_stat.elsRcvPRLI++;
  7827. if ((vport->port_state < LPFC_DISC_AUTH) &&
  7828. (vport->fc_flag & FC_FABRIC)) {
  7829. rjt_err = LSRJT_UNABLE_TPC;
  7830. rjt_exp = LSEXP_NOTHING_MORE;
  7831. break;
  7832. }
  7833. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
  7834. break;
  7835. case ELS_CMD_LIRR:
  7836. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7837. "RCV LIRR: did:x%x/ste:x%x flg:x%x",
  7838. did, vport->port_state, ndlp->nlp_flag);
  7839. phba->fc_stat.elsRcvLIRR++;
  7840. lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
  7841. if (newnode)
  7842. lpfc_nlp_put(ndlp);
  7843. break;
  7844. case ELS_CMD_RLS:
  7845. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7846. "RCV RLS: did:x%x/ste:x%x flg:x%x",
  7847. did, vport->port_state, ndlp->nlp_flag);
  7848. phba->fc_stat.elsRcvRLS++;
  7849. lpfc_els_rcv_rls(vport, elsiocb, ndlp);
  7850. if (newnode)
  7851. lpfc_nlp_put(ndlp);
  7852. break;
  7853. case ELS_CMD_RPL:
  7854. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7855. "RCV RPL: did:x%x/ste:x%x flg:x%x",
  7856. did, vport->port_state, ndlp->nlp_flag);
  7857. phba->fc_stat.elsRcvRPL++;
  7858. lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
  7859. if (newnode)
  7860. lpfc_nlp_put(ndlp);
  7861. break;
  7862. case ELS_CMD_RNID:
  7863. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7864. "RCV RNID: did:x%x/ste:x%x flg:x%x",
  7865. did, vport->port_state, ndlp->nlp_flag);
  7866. phba->fc_stat.elsRcvRNID++;
  7867. lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
  7868. if (newnode)
  7869. lpfc_nlp_put(ndlp);
  7870. break;
  7871. case ELS_CMD_RTV:
  7872. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7873. "RCV RTV: did:x%x/ste:x%x flg:x%x",
  7874. did, vport->port_state, ndlp->nlp_flag);
  7875. phba->fc_stat.elsRcvRTV++;
  7876. lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
  7877. if (newnode)
  7878. lpfc_nlp_put(ndlp);
  7879. break;
  7880. case ELS_CMD_RRQ:
  7881. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7882. "RCV RRQ: did:x%x/ste:x%x flg:x%x",
  7883. did, vport->port_state, ndlp->nlp_flag);
  7884. phba->fc_stat.elsRcvRRQ++;
  7885. lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
  7886. if (newnode)
  7887. lpfc_nlp_put(ndlp);
  7888. break;
  7889. case ELS_CMD_ECHO:
  7890. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7891. "RCV ECHO: did:x%x/ste:x%x flg:x%x",
  7892. did, vport->port_state, ndlp->nlp_flag);
  7893. phba->fc_stat.elsRcvECHO++;
  7894. lpfc_els_rcv_echo(vport, elsiocb, ndlp);
  7895. if (newnode)
  7896. lpfc_nlp_put(ndlp);
  7897. break;
  7898. case ELS_CMD_REC:
  7899. /* receive this due to exchange closed */
  7900. rjt_err = LSRJT_UNABLE_TPC;
  7901. rjt_exp = LSEXP_INVALID_OX_RX;
  7902. break;
  7903. case ELS_CMD_FPIN:
  7904. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7905. "RCV FPIN: did:x%x/ste:x%x flg:x%x",
  7906. did, vport->port_state, ndlp->nlp_flag);
  7907. lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
  7908. payload_len);
  7909. /* There are no replies, so no rjt codes */
  7910. break;
  7911. default:
  7912. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7913. "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
  7914. cmd, did, vport->port_state);
  7915. /* Unsupported ELS command, reject */
  7916. rjt_err = LSRJT_CMD_UNSUPPORTED;
  7917. rjt_exp = LSEXP_NOTHING_MORE;
  7918. /* Unknown ELS command <elsCmd> received from NPORT <did> */
  7919. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  7920. "0115 Unknown ELS command x%x "
  7921. "received from NPORT x%x\n", cmd, did);
  7922. if (newnode)
  7923. lpfc_nlp_put(ndlp);
  7924. break;
  7925. }
  7926. lsrjt:
  7927. /* check if need to LS_RJT received ELS cmd */
  7928. if (rjt_err) {
  7929. memset(&stat, 0, sizeof(stat));
  7930. stat.un.b.lsRjtRsnCode = rjt_err;
  7931. stat.un.b.lsRjtRsnCodeExp = rjt_exp;
  7932. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
  7933. NULL);
  7934. }
  7935. lpfc_nlp_put(elsiocb->context1);
  7936. elsiocb->context1 = NULL;
  7937. /* Special case. Driver received an unsolicited command that
  7938. * unsupportable given the driver's current state. Reset the
  7939. * link and start over.
  7940. */
  7941. if (init_link) {
  7942. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  7943. if (!mbox)
  7944. return;
  7945. lpfc_linkdown(phba);
  7946. lpfc_init_link(phba, mbox,
  7947. phba->cfg_topology,
  7948. phba->cfg_link_speed);
  7949. mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  7950. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7951. mbox->vport = vport;
  7952. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
  7953. MBX_NOT_FINISHED)
  7954. mempool_free(mbox, phba->mbox_mem_pool);
  7955. }
  7956. return;
  7957. dropit:
  7958. if (vport && !(vport->load_flag & FC_UNLOADING))
  7959. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  7960. "0111 Dropping received ELS cmd "
  7961. "Data: x%x x%x x%x\n",
  7962. icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
  7963. phba->fc_stat.elsRcvDrop++;
  7964. }
  7965. /**
  7966. * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
  7967. * @phba: pointer to lpfc hba data structure.
  7968. * @pring: pointer to a SLI ring.
  7969. * @elsiocb: pointer to lpfc els iocb data structure.
  7970. *
  7971. * This routine is used to process an unsolicited event received from a SLI
  7972. * (Service Level Interface) ring. The actual processing of the data buffer
  7973. * associated with the unsolicited event is done by invoking the routine
  7974. * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
  7975. * SLI ring on which the unsolicited event was received.
  7976. **/
  7977. void
  7978. lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7979. struct lpfc_iocbq *elsiocb)
  7980. {
  7981. struct lpfc_vport *vport = phba->pport;
  7982. IOCB_t *icmd = &elsiocb->iocb;
  7983. dma_addr_t paddr;
  7984. struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
  7985. struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
  7986. elsiocb->context1 = NULL;
  7987. elsiocb->context2 = NULL;
  7988. elsiocb->context3 = NULL;
  7989. if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
  7990. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  7991. } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
  7992. (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  7993. IOERR_RCV_BUFFER_WAITING) {
  7994. phba->fc_stat.NoRcvBuf++;
  7995. /* Not enough posted buffers; Try posting more buffers */
  7996. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  7997. lpfc_post_buffer(phba, pring, 0);
  7998. return;
  7999. }
  8000. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  8001. (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
  8002. icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  8003. if (icmd->unsli3.rcvsli3.vpi == 0xffff)
  8004. vport = phba->pport;
  8005. else
  8006. vport = lpfc_find_vport_by_vpid(phba,
  8007. icmd->unsli3.rcvsli3.vpi);
  8008. }
  8009. /* If there are no BDEs associated
  8010. * with this IOCB, there is nothing to do.
  8011. */
  8012. if (icmd->ulpBdeCount == 0)
  8013. return;
  8014. /* type of ELS cmd is first 32bit word
  8015. * in packet
  8016. */
  8017. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  8018. elsiocb->context2 = bdeBuf1;
  8019. } else {
  8020. paddr = getPaddr(icmd->un.cont64[0].addrHigh,
  8021. icmd->un.cont64[0].addrLow);
  8022. elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
  8023. paddr);
  8024. }
  8025. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  8026. /*
  8027. * The different unsolicited event handlers would tell us
  8028. * if they are done with "mp" by setting context2 to NULL.
  8029. */
  8030. if (elsiocb->context2) {
  8031. lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
  8032. elsiocb->context2 = NULL;
  8033. }
  8034. /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
  8035. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
  8036. icmd->ulpBdeCount == 2) {
  8037. elsiocb->context2 = bdeBuf2;
  8038. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  8039. /* free mp if we are done with it */
  8040. if (elsiocb->context2) {
  8041. lpfc_in_buf_free(phba, elsiocb->context2);
  8042. elsiocb->context2 = NULL;
  8043. }
  8044. }
  8045. }
  8046. static void
  8047. lpfc_start_fdmi(struct lpfc_vport *vport)
  8048. {
  8049. struct lpfc_nodelist *ndlp;
  8050. /* If this is the first time, allocate an ndlp and initialize
  8051. * it. Otherwise, make sure the node is enabled and then do the
  8052. * login.
  8053. */
  8054. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  8055. if (!ndlp) {
  8056. ndlp = lpfc_nlp_init(vport, FDMI_DID);
  8057. if (ndlp) {
  8058. ndlp->nlp_type |= NLP_FABRIC;
  8059. } else {
  8060. return;
  8061. }
  8062. }
  8063. if (!NLP_CHK_NODE_ACT(ndlp))
  8064. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
  8065. if (ndlp) {
  8066. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  8067. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  8068. }
  8069. }
  8070. /**
  8071. * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
  8072. * @phba: pointer to lpfc hba data structure.
  8073. * @vport: pointer to a virtual N_Port data structure.
  8074. *
  8075. * This routine issues a Port Login (PLOGI) to the Name Server with
  8076. * State Change Request (SCR) for a @vport. This routine will create an
  8077. * ndlp for the Name Server associated to the @vport if such node does
  8078. * not already exist. The PLOGI to Name Server is issued by invoking the
  8079. * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
  8080. * (FDMI) is configured to the @vport, a FDMI node will be created and
  8081. * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
  8082. **/
  8083. void
  8084. lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  8085. {
  8086. struct lpfc_nodelist *ndlp;
  8087. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  8088. /*
  8089. * If lpfc_delay_discovery parameter is set and the clean address
  8090. * bit is cleared and fc fabric parameters chenged, delay FC NPort
  8091. * discovery.
  8092. */
  8093. spin_lock_irq(shost->host_lock);
  8094. if (vport->fc_flag & FC_DISC_DELAYED) {
  8095. spin_unlock_irq(shost->host_lock);
  8096. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  8097. "3334 Delay fc port discovery for %d seconds\n",
  8098. phba->fc_ratov);
  8099. mod_timer(&vport->delayed_disc_tmo,
  8100. jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
  8101. return;
  8102. }
  8103. spin_unlock_irq(shost->host_lock);
  8104. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  8105. if (!ndlp) {
  8106. ndlp = lpfc_nlp_init(vport, NameServer_DID);
  8107. if (!ndlp) {
  8108. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  8109. lpfc_disc_start(vport);
  8110. return;
  8111. }
  8112. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  8113. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  8114. "0251 NameServer login: no memory\n");
  8115. return;
  8116. }
  8117. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  8118. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  8119. if (!ndlp) {
  8120. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  8121. lpfc_disc_start(vport);
  8122. return;
  8123. }
  8124. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  8125. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  8126. "0348 NameServer login: node freed\n");
  8127. return;
  8128. }
  8129. }
  8130. ndlp->nlp_type |= NLP_FABRIC;
  8131. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  8132. if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
  8133. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  8134. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  8135. "0252 Cannot issue NameServer login\n");
  8136. return;
  8137. }
  8138. if ((phba->cfg_enable_SmartSAN ||
  8139. (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
  8140. (vport->load_flag & FC_ALLOW_FDMI))
  8141. lpfc_start_fdmi(vport);
  8142. }
  8143. /**
  8144. * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
  8145. * @phba: pointer to lpfc hba data structure.
  8146. * @pmb: pointer to the driver internal queue element for mailbox command.
  8147. *
  8148. * This routine is the completion callback function to register new vport
  8149. * mailbox command. If the new vport mailbox command completes successfully,
  8150. * the fabric registration login shall be performed on physical port (the
  8151. * new vport created is actually a physical port, with VPI 0) or the port
  8152. * login to Name Server for State Change Request (SCR) will be performed
  8153. * on virtual port (real virtual port, with VPI greater than 0).
  8154. **/
  8155. static void
  8156. lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  8157. {
  8158. struct lpfc_vport *vport = pmb->vport;
  8159. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  8160. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
  8161. MAILBOX_t *mb = &pmb->u.mb;
  8162. int rc;
  8163. spin_lock_irq(shost->host_lock);
  8164. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  8165. spin_unlock_irq(shost->host_lock);
  8166. if (mb->mbxStatus) {
  8167. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  8168. "0915 Register VPI failed : Status: x%x"
  8169. " upd bit: x%x \n", mb->mbxStatus,
  8170. mb->un.varRegVpi.upd);
  8171. if (phba->sli_rev == LPFC_SLI_REV4 &&
  8172. mb->un.varRegVpi.upd)
  8173. goto mbox_err_exit ;
  8174. switch (mb->mbxStatus) {
  8175. case 0x11: /* unsupported feature */
  8176. case 0x9603: /* max_vpi exceeded */
  8177. case 0x9602: /* Link event since CLEAR_LA */
  8178. /* giving up on vport registration */
  8179. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  8180. spin_lock_irq(shost->host_lock);
  8181. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  8182. spin_unlock_irq(shost->host_lock);
  8183. lpfc_can_disctmo(vport);
  8184. break;
  8185. /* If reg_vpi fail with invalid VPI status, re-init VPI */
  8186. case 0x20:
  8187. spin_lock_irq(shost->host_lock);
  8188. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  8189. spin_unlock_irq(shost->host_lock);
  8190. lpfc_init_vpi(phba, pmb, vport->vpi);
  8191. pmb->vport = vport;
  8192. pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
  8193. rc = lpfc_sli_issue_mbox(phba, pmb,
  8194. MBX_NOWAIT);
  8195. if (rc == MBX_NOT_FINISHED) {
  8196. lpfc_printf_vlog(vport,
  8197. KERN_ERR, LOG_MBOX,
  8198. "2732 Failed to issue INIT_VPI"
  8199. " mailbox command\n");
  8200. } else {
  8201. lpfc_nlp_put(ndlp);
  8202. return;
  8203. }
  8204. /* fall through */
  8205. default:
  8206. /* Try to recover from this error */
  8207. if (phba->sli_rev == LPFC_SLI_REV4)
  8208. lpfc_sli4_unreg_all_rpis(vport);
  8209. lpfc_mbx_unreg_vpi(vport);
  8210. spin_lock_irq(shost->host_lock);
  8211. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  8212. spin_unlock_irq(shost->host_lock);
  8213. if (mb->mbxStatus == MBX_NOT_FINISHED)
  8214. break;
  8215. if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
  8216. !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
  8217. if (phba->sli_rev == LPFC_SLI_REV4)
  8218. lpfc_issue_init_vfi(vport);
  8219. else
  8220. lpfc_initial_flogi(vport);
  8221. } else {
  8222. lpfc_initial_fdisc(vport);
  8223. }
  8224. break;
  8225. }
  8226. } else {
  8227. spin_lock_irq(shost->host_lock);
  8228. vport->vpi_state |= LPFC_VPI_REGISTERED;
  8229. spin_unlock_irq(shost->host_lock);
  8230. if (vport == phba->pport) {
  8231. if (phba->sli_rev < LPFC_SLI_REV4)
  8232. lpfc_issue_fabric_reglogin(vport);
  8233. else {
  8234. /*
  8235. * If the physical port is instantiated using
  8236. * FDISC, do not start vport discovery.
  8237. */
  8238. if (vport->port_state != LPFC_FDISC)
  8239. lpfc_start_fdiscs(phba);
  8240. lpfc_do_scr_ns_plogi(phba, vport);
  8241. }
  8242. } else
  8243. lpfc_do_scr_ns_plogi(phba, vport);
  8244. }
  8245. mbox_err_exit:
  8246. /* Now, we decrement the ndlp reference count held for this
  8247. * callback function
  8248. */
  8249. lpfc_nlp_put(ndlp);
  8250. mempool_free(pmb, phba->mbox_mem_pool);
  8251. return;
  8252. }
  8253. /**
  8254. * lpfc_register_new_vport - Register a new vport with a HBA
  8255. * @phba: pointer to lpfc hba data structure.
  8256. * @vport: pointer to a host virtual N_Port data structure.
  8257. * @ndlp: pointer to a node-list data structure.
  8258. *
  8259. * This routine registers the @vport as a new virtual port with a HBA.
  8260. * It is done through a registering vpi mailbox command.
  8261. **/
  8262. void
  8263. lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
  8264. struct lpfc_nodelist *ndlp)
  8265. {
  8266. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  8267. LPFC_MBOXQ_t *mbox;
  8268. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8269. if (mbox) {
  8270. lpfc_reg_vpi(vport, mbox);
  8271. mbox->vport = vport;
  8272. mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
  8273. mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
  8274. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  8275. == MBX_NOT_FINISHED) {
  8276. /* mailbox command not success, decrement ndlp
  8277. * reference count for this command
  8278. */
  8279. lpfc_nlp_put(ndlp);
  8280. mempool_free(mbox, phba->mbox_mem_pool);
  8281. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  8282. "0253 Register VPI: Can't send mbox\n");
  8283. goto mbox_err_exit;
  8284. }
  8285. } else {
  8286. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  8287. "0254 Register VPI: no memory\n");
  8288. goto mbox_err_exit;
  8289. }
  8290. return;
  8291. mbox_err_exit:
  8292. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  8293. spin_lock_irq(shost->host_lock);
  8294. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  8295. spin_unlock_irq(shost->host_lock);
  8296. return;
  8297. }
  8298. /**
  8299. * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
  8300. * @phba: pointer to lpfc hba data structure.
  8301. *
  8302. * This routine cancels the retry delay timers to all the vports.
  8303. **/
  8304. void
  8305. lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
  8306. {
  8307. struct lpfc_vport **vports;
  8308. struct lpfc_nodelist *ndlp;
  8309. uint32_t link_state;
  8310. int i;
  8311. /* Treat this failure as linkdown for all vports */
  8312. link_state = phba->link_state;
  8313. lpfc_linkdown(phba);
  8314. phba->link_state = link_state;
  8315. vports = lpfc_create_vport_work_array(phba);
  8316. if (vports) {
  8317. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  8318. ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
  8319. if (ndlp)
  8320. lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
  8321. lpfc_els_flush_cmd(vports[i]);
  8322. }
  8323. lpfc_destroy_vport_work_array(phba, vports);
  8324. }
  8325. }
  8326. /**
  8327. * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
  8328. * @phba: pointer to lpfc hba data structure.
  8329. *
  8330. * This routine abort all pending discovery commands and
  8331. * start a timer to retry FLOGI for the physical port
  8332. * discovery.
  8333. **/
  8334. void
  8335. lpfc_retry_pport_discovery(struct lpfc_hba *phba)
  8336. {
  8337. struct lpfc_nodelist *ndlp;
  8338. struct Scsi_Host *shost;
  8339. /* Cancel the all vports retry delay retry timers */
  8340. lpfc_cancel_all_vport_retry_delay_timer(phba);
  8341. /* If fabric require FLOGI, then re-instantiate physical login */
  8342. ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
  8343. if (!ndlp)
  8344. return;
  8345. shost = lpfc_shost_from_vport(phba->pport);
  8346. mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
  8347. spin_lock_irq(shost->host_lock);
  8348. ndlp->nlp_flag |= NLP_DELAY_TMO;
  8349. spin_unlock_irq(shost->host_lock);
  8350. ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
  8351. phba->pport->port_state = LPFC_FLOGI;
  8352. return;
  8353. }
  8354. /**
  8355. * lpfc_fabric_login_reqd - Check if FLOGI required.
  8356. * @phba: pointer to lpfc hba data structure.
  8357. * @cmdiocb: pointer to FDISC command iocb.
  8358. * @rspiocb: pointer to FDISC response iocb.
  8359. *
  8360. * This routine checks if a FLOGI is reguired for FDISC
  8361. * to succeed.
  8362. **/
  8363. static int
  8364. lpfc_fabric_login_reqd(struct lpfc_hba *phba,
  8365. struct lpfc_iocbq *cmdiocb,
  8366. struct lpfc_iocbq *rspiocb)
  8367. {
  8368. if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
  8369. (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
  8370. return 0;
  8371. else
  8372. return 1;
  8373. }
  8374. /**
  8375. * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
  8376. * @phba: pointer to lpfc hba data structure.
  8377. * @cmdiocb: pointer to lpfc command iocb data structure.
  8378. * @rspiocb: pointer to lpfc response iocb data structure.
  8379. *
  8380. * This routine is the completion callback function to a Fabric Discover
  8381. * (FDISC) ELS command. Since all the FDISC ELS commands are issued
  8382. * single threaded, each FDISC completion callback function will reset
  8383. * the discovery timer for all vports such that the timers will not get
  8384. * unnecessary timeout. The function checks the FDISC IOCB status. If error
  8385. * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
  8386. * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
  8387. * assigned to the vport has been changed with the completion of the FDISC
  8388. * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
  8389. * are unregistered from the HBA, and then the lpfc_register_new_vport()
  8390. * routine is invoked to register new vport with the HBA. Otherwise, the
  8391. * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
  8392. * Server for State Change Request (SCR).
  8393. **/
  8394. static void
  8395. lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8396. struct lpfc_iocbq *rspiocb)
  8397. {
  8398. struct lpfc_vport *vport = cmdiocb->vport;
  8399. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  8400. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  8401. struct lpfc_nodelist *np;
  8402. struct lpfc_nodelist *next_np;
  8403. IOCB_t *irsp = &rspiocb->iocb;
  8404. struct lpfc_iocbq *piocb;
  8405. struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
  8406. struct serv_parm *sp;
  8407. uint8_t fabric_param_changed;
  8408. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  8409. "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
  8410. irsp->ulpStatus, irsp->un.ulpWord[4],
  8411. vport->fc_prevDID);
  8412. /* Since all FDISCs are being single threaded, we
  8413. * must reset the discovery timer for ALL vports
  8414. * waiting to send FDISC when one completes.
  8415. */
  8416. list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
  8417. lpfc_set_disctmo(piocb->vport);
  8418. }
  8419. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  8420. "FDISC cmpl: status:x%x/x%x prevdid:x%x",
  8421. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
  8422. if (irsp->ulpStatus) {
  8423. if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
  8424. lpfc_retry_pport_discovery(phba);
  8425. goto out;
  8426. }
  8427. /* Check for retry */
  8428. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  8429. goto out;
  8430. /* FDISC failed */
  8431. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  8432. "0126 FDISC failed. (x%x/x%x)\n",
  8433. irsp->ulpStatus, irsp->un.ulpWord[4]);
  8434. goto fdisc_failed;
  8435. }
  8436. spin_lock_irq(shost->host_lock);
  8437. vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
  8438. vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
  8439. vport->fc_flag |= FC_FABRIC;
  8440. if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
  8441. vport->fc_flag |= FC_PUBLIC_LOOP;
  8442. spin_unlock_irq(shost->host_lock);
  8443. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  8444. lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
  8445. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  8446. if (!prsp)
  8447. goto out;
  8448. sp = prsp->virt + sizeof(uint32_t);
  8449. fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
  8450. memcpy(&vport->fabric_portname, &sp->portName,
  8451. sizeof(struct lpfc_name));
  8452. memcpy(&vport->fabric_nodename, &sp->nodeName,
  8453. sizeof(struct lpfc_name));
  8454. if (fabric_param_changed &&
  8455. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  8456. /* If our NportID changed, we need to ensure all
  8457. * remaining NPORTs get unreg_login'ed so we can
  8458. * issue unreg_vpi.
  8459. */
  8460. list_for_each_entry_safe(np, next_np,
  8461. &vport->fc_nodes, nlp_listp) {
  8462. if (!NLP_CHK_NODE_ACT(ndlp) ||
  8463. (np->nlp_state != NLP_STE_NPR_NODE) ||
  8464. !(np->nlp_flag & NLP_NPR_ADISC))
  8465. continue;
  8466. spin_lock_irq(shost->host_lock);
  8467. np->nlp_flag &= ~NLP_NPR_ADISC;
  8468. spin_unlock_irq(shost->host_lock);
  8469. lpfc_unreg_rpi(vport, np);
  8470. }
  8471. lpfc_cleanup_pending_mbox(vport);
  8472. if (phba->sli_rev == LPFC_SLI_REV4)
  8473. lpfc_sli4_unreg_all_rpis(vport);
  8474. lpfc_mbx_unreg_vpi(vport);
  8475. spin_lock_irq(shost->host_lock);
  8476. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  8477. if (phba->sli_rev == LPFC_SLI_REV4)
  8478. vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  8479. else
  8480. vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
  8481. spin_unlock_irq(shost->host_lock);
  8482. } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
  8483. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  8484. /*
  8485. * Driver needs to re-reg VPI in order for f/w
  8486. * to update the MAC address.
  8487. */
  8488. lpfc_register_new_vport(phba, vport, ndlp);
  8489. goto out;
  8490. }
  8491. if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
  8492. lpfc_issue_init_vpi(vport);
  8493. else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  8494. lpfc_register_new_vport(phba, vport, ndlp);
  8495. else
  8496. lpfc_do_scr_ns_plogi(phba, vport);
  8497. goto out;
  8498. fdisc_failed:
  8499. if (vport->fc_vport &&
  8500. (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
  8501. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  8502. /* Cancel discovery timer */
  8503. lpfc_can_disctmo(vport);
  8504. lpfc_nlp_put(ndlp);
  8505. out:
  8506. lpfc_els_free_iocb(phba, cmdiocb);
  8507. }
  8508. /**
  8509. * lpfc_issue_els_fdisc - Issue a fdisc iocb command
  8510. * @vport: pointer to a virtual N_Port data structure.
  8511. * @ndlp: pointer to a node-list data structure.
  8512. * @retry: number of retries to the command IOCB.
  8513. *
  8514. * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
  8515. * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
  8516. * routine to issue the IOCB, which makes sure only one outstanding fabric
  8517. * IOCB will be sent off HBA at any given time.
  8518. *
  8519. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  8520. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  8521. * will be stored into the context1 field of the IOCB for the completion
  8522. * callback function to the FDISC ELS command.
  8523. *
  8524. * Return code
  8525. * 0 - Successfully issued fdisc iocb command
  8526. * 1 - Failed to issue fdisc iocb command
  8527. **/
  8528. static int
  8529. lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  8530. uint8_t retry)
  8531. {
  8532. struct lpfc_hba *phba = vport->phba;
  8533. IOCB_t *icmd;
  8534. struct lpfc_iocbq *elsiocb;
  8535. struct serv_parm *sp;
  8536. uint8_t *pcmd;
  8537. uint16_t cmdsize;
  8538. int did = ndlp->nlp_DID;
  8539. int rc;
  8540. vport->port_state = LPFC_FDISC;
  8541. vport->fc_myDID = 0;
  8542. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  8543. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  8544. ELS_CMD_FDISC);
  8545. if (!elsiocb) {
  8546. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  8547. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  8548. "0255 Issue FDISC: no IOCB\n");
  8549. return 1;
  8550. }
  8551. icmd = &elsiocb->iocb;
  8552. icmd->un.elsreq64.myID = 0;
  8553. icmd->un.elsreq64.fl = 1;
  8554. /*
  8555. * SLI3 ports require a different context type value than SLI4.
  8556. * Catch SLI3 ports here and override the prep.
  8557. */
  8558. if (phba->sli_rev == LPFC_SLI_REV3) {
  8559. icmd->ulpCt_h = 1;
  8560. icmd->ulpCt_l = 0;
  8561. }
  8562. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  8563. *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
  8564. pcmd += sizeof(uint32_t); /* CSP Word 1 */
  8565. memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
  8566. sp = (struct serv_parm *) pcmd;
  8567. /* Setup CSPs accordingly for Fabric */
  8568. sp->cmn.e_d_tov = 0;
  8569. sp->cmn.w2.r_a_tov = 0;
  8570. sp->cmn.virtual_fabric_support = 0;
  8571. sp->cls1.classValid = 0;
  8572. sp->cls2.seqDelivery = 1;
  8573. sp->cls3.seqDelivery = 1;
  8574. pcmd += sizeof(uint32_t); /* CSP Word 2 */
  8575. pcmd += sizeof(uint32_t); /* CSP Word 3 */
  8576. pcmd += sizeof(uint32_t); /* CSP Word 4 */
  8577. pcmd += sizeof(uint32_t); /* Port Name */
  8578. memcpy(pcmd, &vport->fc_portname, 8);
  8579. pcmd += sizeof(uint32_t); /* Node Name */
  8580. pcmd += sizeof(uint32_t); /* Node Name */
  8581. memcpy(pcmd, &vport->fc_nodename, 8);
  8582. sp->cmn.valid_vendor_ver_level = 0;
  8583. memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
  8584. lpfc_set_disctmo(vport);
  8585. phba->fc_stat.elsXmitFDISC++;
  8586. elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
  8587. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  8588. "Issue FDISC: did:x%x",
  8589. did, 0, 0);
  8590. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  8591. if (rc == IOCB_ERROR) {
  8592. lpfc_els_free_iocb(phba, elsiocb);
  8593. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  8594. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  8595. "0256 Issue FDISC: Cannot send IOCB\n");
  8596. return 1;
  8597. }
  8598. lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
  8599. return 0;
  8600. }
  8601. /**
  8602. * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
  8603. * @phba: pointer to lpfc hba data structure.
  8604. * @cmdiocb: pointer to lpfc command iocb data structure.
  8605. * @rspiocb: pointer to lpfc response iocb data structure.
  8606. *
  8607. * This routine is the completion callback function to the issuing of a LOGO
  8608. * ELS command off a vport. It frees the command IOCB and then decrement the
  8609. * reference count held on ndlp for this completion function, indicating that
  8610. * the reference to the ndlp is no long needed. Note that the
  8611. * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
  8612. * callback function and an additional explicit ndlp reference decrementation
  8613. * will trigger the actual release of the ndlp.
  8614. **/
  8615. static void
  8616. lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8617. struct lpfc_iocbq *rspiocb)
  8618. {
  8619. struct lpfc_vport *vport = cmdiocb->vport;
  8620. IOCB_t *irsp;
  8621. struct lpfc_nodelist *ndlp;
  8622. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  8623. ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
  8624. irsp = &rspiocb->iocb;
  8625. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  8626. "LOGO npiv cmpl: status:x%x/x%x did:x%x",
  8627. irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
  8628. lpfc_els_free_iocb(phba, cmdiocb);
  8629. vport->unreg_vpi_cmpl = VPORT_ERROR;
  8630. /* Trigger the release of the ndlp after logo */
  8631. lpfc_nlp_put(ndlp);
  8632. /* NPIV LOGO completes to NPort <nlp_DID> */
  8633. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  8634. "2928 NPIV LOGO completes to NPort x%x "
  8635. "Data: x%x x%x x%x x%x\n",
  8636. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  8637. irsp->ulpTimeout, vport->num_disc_nodes);
  8638. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  8639. spin_lock_irq(shost->host_lock);
  8640. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  8641. vport->fc_flag &= ~FC_FABRIC;
  8642. spin_unlock_irq(shost->host_lock);
  8643. lpfc_can_disctmo(vport);
  8644. }
  8645. }
  8646. /**
  8647. * lpfc_issue_els_npiv_logo - Issue a logo off a vport
  8648. * @vport: pointer to a virtual N_Port data structure.
  8649. * @ndlp: pointer to a node-list data structure.
  8650. *
  8651. * This routine issues a LOGO ELS command to an @ndlp off a @vport.
  8652. *
  8653. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  8654. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  8655. * will be stored into the context1 field of the IOCB for the completion
  8656. * callback function to the LOGO ELS command.
  8657. *
  8658. * Return codes
  8659. * 0 - Successfully issued logo off the @vport
  8660. * 1 - Failed to issue logo off the @vport
  8661. **/
  8662. int
  8663. lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  8664. {
  8665. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  8666. struct lpfc_hba *phba = vport->phba;
  8667. struct lpfc_iocbq *elsiocb;
  8668. uint8_t *pcmd;
  8669. uint16_t cmdsize;
  8670. cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
  8671. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
  8672. ELS_CMD_LOGO);
  8673. if (!elsiocb)
  8674. return 1;
  8675. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  8676. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  8677. pcmd += sizeof(uint32_t);
  8678. /* Fill in LOGO payload */
  8679. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  8680. pcmd += sizeof(uint32_t);
  8681. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  8682. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  8683. "Issue LOGO npiv did:x%x flg:x%x",
  8684. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  8685. elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
  8686. spin_lock_irq(shost->host_lock);
  8687. ndlp->nlp_flag |= NLP_LOGO_SND;
  8688. spin_unlock_irq(shost->host_lock);
  8689. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  8690. IOCB_ERROR) {
  8691. spin_lock_irq(shost->host_lock);
  8692. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  8693. spin_unlock_irq(shost->host_lock);
  8694. lpfc_els_free_iocb(phba, elsiocb);
  8695. return 1;
  8696. }
  8697. return 0;
  8698. }
  8699. /**
  8700. * lpfc_fabric_block_timeout - Handler function to the fabric block timer
  8701. * @ptr: holder for the timer function associated data.
  8702. *
  8703. * This routine is invoked by the fabric iocb block timer after
  8704. * timeout. It posts the fabric iocb block timeout event by setting the
  8705. * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
  8706. * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
  8707. * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
  8708. * posted event WORKER_FABRIC_BLOCK_TMO.
  8709. **/
  8710. void
  8711. lpfc_fabric_block_timeout(struct timer_list *t)
  8712. {
  8713. struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
  8714. unsigned long iflags;
  8715. uint32_t tmo_posted;
  8716. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  8717. tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
  8718. if (!tmo_posted)
  8719. phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
  8720. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  8721. if (!tmo_posted)
  8722. lpfc_worker_wake_up(phba);
  8723. return;
  8724. }
  8725. /**
  8726. * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
  8727. * @phba: pointer to lpfc hba data structure.
  8728. *
  8729. * This routine issues one fabric iocb from the driver internal list to
  8730. * the HBA. It first checks whether it's ready to issue one fabric iocb to
  8731. * the HBA (whether there is no outstanding fabric iocb). If so, it shall
  8732. * remove one pending fabric iocb from the driver internal list and invokes
  8733. * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
  8734. **/
  8735. static void
  8736. lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
  8737. {
  8738. struct lpfc_iocbq *iocb;
  8739. unsigned long iflags;
  8740. int ret;
  8741. IOCB_t *cmd;
  8742. repeat:
  8743. iocb = NULL;
  8744. spin_lock_irqsave(&phba->hbalock, iflags);
  8745. /* Post any pending iocb to the SLI layer */
  8746. if (atomic_read(&phba->fabric_iocb_count) == 0) {
  8747. list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
  8748. list);
  8749. if (iocb)
  8750. /* Increment fabric iocb count to hold the position */
  8751. atomic_inc(&phba->fabric_iocb_count);
  8752. }
  8753. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8754. if (iocb) {
  8755. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  8756. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  8757. iocb->iocb_flag |= LPFC_IO_FABRIC;
  8758. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  8759. "Fabric sched1: ste:x%x",
  8760. iocb->vport->port_state, 0, 0);
  8761. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
  8762. if (ret == IOCB_ERROR) {
  8763. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  8764. iocb->fabric_iocb_cmpl = NULL;
  8765. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  8766. cmd = &iocb->iocb;
  8767. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  8768. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  8769. iocb->iocb_cmpl(phba, iocb, iocb);
  8770. atomic_dec(&phba->fabric_iocb_count);
  8771. goto repeat;
  8772. }
  8773. }
  8774. return;
  8775. }
  8776. /**
  8777. * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
  8778. * @phba: pointer to lpfc hba data structure.
  8779. *
  8780. * This routine unblocks the issuing fabric iocb command. The function
  8781. * will clear the fabric iocb block bit and then invoke the routine
  8782. * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
  8783. * from the driver internal fabric iocb list.
  8784. **/
  8785. void
  8786. lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
  8787. {
  8788. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  8789. lpfc_resume_fabric_iocbs(phba);
  8790. return;
  8791. }
  8792. /**
  8793. * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
  8794. * @phba: pointer to lpfc hba data structure.
  8795. *
  8796. * This routine blocks the issuing fabric iocb for a specified amount of
  8797. * time (currently 100 ms). This is done by set the fabric iocb block bit
  8798. * and set up a timeout timer for 100ms. When the block bit is set, no more
  8799. * fabric iocb will be issued out of the HBA.
  8800. **/
  8801. static void
  8802. lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
  8803. {
  8804. int blocked;
  8805. blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  8806. /* Start a timer to unblock fabric iocbs after 100ms */
  8807. if (!blocked)
  8808. mod_timer(&phba->fabric_block_timer,
  8809. jiffies + msecs_to_jiffies(100));
  8810. return;
  8811. }
  8812. /**
  8813. * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
  8814. * @phba: pointer to lpfc hba data structure.
  8815. * @cmdiocb: pointer to lpfc command iocb data structure.
  8816. * @rspiocb: pointer to lpfc response iocb data structure.
  8817. *
  8818. * This routine is the callback function that is put to the fabric iocb's
  8819. * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
  8820. * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
  8821. * function first restores and invokes the original iocb's callback function
  8822. * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
  8823. * fabric bound iocb from the driver internal fabric iocb list onto the wire.
  8824. **/
  8825. static void
  8826. lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8827. struct lpfc_iocbq *rspiocb)
  8828. {
  8829. struct ls_rjt stat;
  8830. BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
  8831. switch (rspiocb->iocb.ulpStatus) {
  8832. case IOSTAT_NPORT_RJT:
  8833. case IOSTAT_FABRIC_RJT:
  8834. if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  8835. lpfc_block_fabric_iocbs(phba);
  8836. }
  8837. break;
  8838. case IOSTAT_NPORT_BSY:
  8839. case IOSTAT_FABRIC_BSY:
  8840. lpfc_block_fabric_iocbs(phba);
  8841. break;
  8842. case IOSTAT_LS_RJT:
  8843. stat.un.lsRjtError =
  8844. be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
  8845. if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
  8846. (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
  8847. lpfc_block_fabric_iocbs(phba);
  8848. break;
  8849. }
  8850. BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
  8851. cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
  8852. cmdiocb->fabric_iocb_cmpl = NULL;
  8853. cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
  8854. cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
  8855. atomic_dec(&phba->fabric_iocb_count);
  8856. if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
  8857. /* Post any pending iocbs to HBA */
  8858. lpfc_resume_fabric_iocbs(phba);
  8859. }
  8860. }
  8861. /**
  8862. * lpfc_issue_fabric_iocb - Issue a fabric iocb command
  8863. * @phba: pointer to lpfc hba data structure.
  8864. * @iocb: pointer to lpfc command iocb data structure.
  8865. *
  8866. * This routine is used as the top-level API for issuing a fabric iocb command
  8867. * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
  8868. * function makes sure that only one fabric bound iocb will be outstanding at
  8869. * any given time. As such, this function will first check to see whether there
  8870. * is already an outstanding fabric iocb on the wire. If so, it will put the
  8871. * newly issued iocb onto the driver internal fabric iocb list, waiting to be
  8872. * issued later. Otherwise, it will issue the iocb on the wire and update the
  8873. * fabric iocb count it indicate that there is one fabric iocb on the wire.
  8874. *
  8875. * Note, this implementation has a potential sending out fabric IOCBs out of
  8876. * order. The problem is caused by the construction of the "ready" boolen does
  8877. * not include the condition that the internal fabric IOCB list is empty. As
  8878. * such, it is possible a fabric IOCB issued by this routine might be "jump"
  8879. * ahead of the fabric IOCBs in the internal list.
  8880. *
  8881. * Return code
  8882. * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
  8883. * IOCB_ERROR - failed to issue fabric iocb
  8884. **/
  8885. static int
  8886. lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
  8887. {
  8888. unsigned long iflags;
  8889. int ready;
  8890. int ret;
  8891. BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
  8892. spin_lock_irqsave(&phba->hbalock, iflags);
  8893. ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
  8894. !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  8895. if (ready)
  8896. /* Increment fabric iocb count to hold the position */
  8897. atomic_inc(&phba->fabric_iocb_count);
  8898. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8899. if (ready) {
  8900. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  8901. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  8902. iocb->iocb_flag |= LPFC_IO_FABRIC;
  8903. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  8904. "Fabric sched2: ste:x%x",
  8905. iocb->vport->port_state, 0, 0);
  8906. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
  8907. if (ret == IOCB_ERROR) {
  8908. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  8909. iocb->fabric_iocb_cmpl = NULL;
  8910. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  8911. atomic_dec(&phba->fabric_iocb_count);
  8912. }
  8913. } else {
  8914. spin_lock_irqsave(&phba->hbalock, iflags);
  8915. list_add_tail(&iocb->list, &phba->fabric_iocb_list);
  8916. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8917. ret = IOCB_SUCCESS;
  8918. }
  8919. return ret;
  8920. }
  8921. /**
  8922. * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
  8923. * @vport: pointer to a virtual N_Port data structure.
  8924. *
  8925. * This routine aborts all the IOCBs associated with a @vport from the
  8926. * driver internal fabric IOCB list. The list contains fabric IOCBs to be
  8927. * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
  8928. * list, removes each IOCB associated with the @vport off the list, set the
  8929. * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
  8930. * associated with the IOCB.
  8931. **/
  8932. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
  8933. {
  8934. LIST_HEAD(completions);
  8935. struct lpfc_hba *phba = vport->phba;
  8936. struct lpfc_iocbq *tmp_iocb, *piocb;
  8937. spin_lock_irq(&phba->hbalock);
  8938. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  8939. list) {
  8940. if (piocb->vport != vport)
  8941. continue;
  8942. list_move_tail(&piocb->list, &completions);
  8943. }
  8944. spin_unlock_irq(&phba->hbalock);
  8945. /* Cancel all the IOCBs from the completions list */
  8946. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8947. IOERR_SLI_ABORTED);
  8948. }
  8949. /**
  8950. * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
  8951. * @ndlp: pointer to a node-list data structure.
  8952. *
  8953. * This routine aborts all the IOCBs associated with an @ndlp from the
  8954. * driver internal fabric IOCB list. The list contains fabric IOCBs to be
  8955. * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
  8956. * list, removes each IOCB associated with the @ndlp off the list, set the
  8957. * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
  8958. * associated with the IOCB.
  8959. **/
  8960. void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
  8961. {
  8962. LIST_HEAD(completions);
  8963. struct lpfc_hba *phba = ndlp->phba;
  8964. struct lpfc_iocbq *tmp_iocb, *piocb;
  8965. struct lpfc_sli_ring *pring;
  8966. pring = lpfc_phba_elsring(phba);
  8967. if (unlikely(!pring))
  8968. return;
  8969. spin_lock_irq(&phba->hbalock);
  8970. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  8971. list) {
  8972. if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
  8973. list_move_tail(&piocb->list, &completions);
  8974. }
  8975. }
  8976. spin_unlock_irq(&phba->hbalock);
  8977. /* Cancel all the IOCBs from the completions list */
  8978. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8979. IOERR_SLI_ABORTED);
  8980. }
  8981. /**
  8982. * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
  8983. * @phba: pointer to lpfc hba data structure.
  8984. *
  8985. * This routine aborts all the IOCBs currently on the driver internal
  8986. * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
  8987. * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
  8988. * list, removes IOCBs off the list, set the status feild to
  8989. * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
  8990. * the IOCB.
  8991. **/
  8992. void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
  8993. {
  8994. LIST_HEAD(completions);
  8995. spin_lock_irq(&phba->hbalock);
  8996. list_splice_init(&phba->fabric_iocb_list, &completions);
  8997. spin_unlock_irq(&phba->hbalock);
  8998. /* Cancel all the IOCBs from the completions list */
  8999. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  9000. IOERR_SLI_ABORTED);
  9001. }
  9002. /**
  9003. * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
  9004. * @vport: pointer to lpfc vport data structure.
  9005. *
  9006. * This routine is invoked by the vport cleanup for deletions and the cleanup
  9007. * for an ndlp on removal.
  9008. **/
  9009. void
  9010. lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
  9011. {
  9012. struct lpfc_hba *phba = vport->phba;
  9013. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  9014. unsigned long iflag = 0;
  9015. spin_lock_irqsave(&phba->hbalock, iflag);
  9016. spin_lock(&phba->sli4_hba.sgl_list_lock);
  9017. list_for_each_entry_safe(sglq_entry, sglq_next,
  9018. &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
  9019. if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
  9020. sglq_entry->ndlp = NULL;
  9021. }
  9022. spin_unlock(&phba->sli4_hba.sgl_list_lock);
  9023. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9024. return;
  9025. }
  9026. /**
  9027. * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
  9028. * @phba: pointer to lpfc hba data structure.
  9029. * @axri: pointer to the els xri abort wcqe structure.
  9030. *
  9031. * This routine is invoked by the worker thread to process a SLI4 slow-path
  9032. * ELS aborted xri.
  9033. **/
  9034. void
  9035. lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
  9036. struct sli4_wcqe_xri_aborted *axri)
  9037. {
  9038. uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
  9039. uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
  9040. uint16_t lxri = 0;
  9041. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  9042. unsigned long iflag = 0;
  9043. struct lpfc_nodelist *ndlp;
  9044. struct lpfc_sli_ring *pring;
  9045. pring = lpfc_phba_elsring(phba);
  9046. spin_lock_irqsave(&phba->hbalock, iflag);
  9047. spin_lock(&phba->sli4_hba.sgl_list_lock);
  9048. list_for_each_entry_safe(sglq_entry, sglq_next,
  9049. &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
  9050. if (sglq_entry->sli4_xritag == xri) {
  9051. list_del(&sglq_entry->list);
  9052. ndlp = sglq_entry->ndlp;
  9053. sglq_entry->ndlp = NULL;
  9054. list_add_tail(&sglq_entry->list,
  9055. &phba->sli4_hba.lpfc_els_sgl_list);
  9056. sglq_entry->state = SGL_FREED;
  9057. spin_unlock(&phba->sli4_hba.sgl_list_lock);
  9058. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9059. lpfc_set_rrq_active(phba, ndlp,
  9060. sglq_entry->sli4_lxritag,
  9061. rxid, 1);
  9062. /* Check if TXQ queue needs to be serviced */
  9063. if (pring && !list_empty(&pring->txq))
  9064. lpfc_worker_wake_up(phba);
  9065. return;
  9066. }
  9067. }
  9068. spin_unlock(&phba->sli4_hba.sgl_list_lock);
  9069. lxri = lpfc_sli4_xri_inrange(phba, xri);
  9070. if (lxri == NO_XRI) {
  9071. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9072. return;
  9073. }
  9074. spin_lock(&phba->sli4_hba.sgl_list_lock);
  9075. sglq_entry = __lpfc_get_active_sglq(phba, lxri);
  9076. if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
  9077. spin_unlock(&phba->sli4_hba.sgl_list_lock);
  9078. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9079. return;
  9080. }
  9081. sglq_entry->state = SGL_XRI_ABORTED;
  9082. spin_unlock(&phba->sli4_hba.sgl_list_lock);
  9083. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9084. return;
  9085. }
  9086. /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
  9087. * @vport: pointer to virtual port object.
  9088. * @ndlp: nodelist pointer for the impacted node.
  9089. *
  9090. * The driver calls this routine in response to an SLI4 XRI ABORT CQE
  9091. * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
  9092. * the driver is required to send a LOGO to the remote node before it
  9093. * attempts to recover its login to the remote node.
  9094. */
  9095. void
  9096. lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
  9097. struct lpfc_nodelist *ndlp)
  9098. {
  9099. struct Scsi_Host *shost;
  9100. struct lpfc_hba *phba;
  9101. unsigned long flags = 0;
  9102. shost = lpfc_shost_from_vport(vport);
  9103. phba = vport->phba;
  9104. if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
  9105. lpfc_printf_log(phba, KERN_INFO,
  9106. LOG_SLI, "3093 No rport recovery needed. "
  9107. "rport in state 0x%x\n", ndlp->nlp_state);
  9108. return;
  9109. }
  9110. lpfc_printf_log(phba, KERN_ERR,
  9111. LOG_ELS | LOG_FCP_ERROR | LOG_NVME_IOERR,
  9112. "3094 Start rport recovery on shost id 0x%x "
  9113. "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
  9114. "flags 0x%x\n",
  9115. shost->host_no, ndlp->nlp_DID,
  9116. vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
  9117. ndlp->nlp_flag);
  9118. /*
  9119. * The rport is not responding. Remove the FCP-2 flag to prevent
  9120. * an ADISC in the follow-up recovery code.
  9121. */
  9122. spin_lock_irqsave(shost->host_lock, flags);
  9123. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  9124. ndlp->nlp_flag |= NLP_ISSUE_LOGO;
  9125. spin_unlock_irqrestore(shost->host_lock, flags);
  9126. lpfc_unreg_rpi(vport, ndlp);
  9127. }