| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 145e5a8 | 2020-01-27 16:23:12 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term * |
James Smart | 4ae2ebd | 2018-06-26 08:24:31 -0700 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 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. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 23 | /* See Fibre Channel protocol T11 FC-LS for details */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/blkdev.h> |
| 25 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 27 | #include <linux/interrupt.h> |
| 28 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 29 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 30 | #include <scsi/scsi_device.h> |
| 31 | #include <scsi/scsi_host.h> |
| 32 | #include <scsi/scsi_transport_fc.h> |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 33 | #include <uapi/scsi/fc/fc_fs.h> |
| 34 | #include <uapi/scsi/fc/fc_els.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 35 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 36 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | #include "lpfc_hw.h" |
| 38 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 39 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 40 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | #include "lpfc_disc.h" |
| 42 | #include "lpfc_scsi.h" |
| 43 | #include "lpfc.h" |
| 44 | #include "lpfc_logmsg.h" |
| 45 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 46 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 47 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 48 | |
| 49 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, |
| 50 | struct lpfc_iocbq *); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 51 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
| 52 | struct lpfc_iocbq *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 53 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
| 54 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, |
| 55 | struct lpfc_nodelist *ndlp, uint8_t retry); |
| 56 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, |
| 57 | struct lpfc_iocbq *iocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 58 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 59 | static int lpfc_max_els_tries = 3; |
| 60 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 61 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 62 | * lpfc_els_chk_latt - Check host link attention event for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 63 | * @vport: pointer to a host virtual N_Port data structure. |
| 64 | * |
| 65 | * This routine checks whether there is an outstanding host link |
| 66 | * attention event during the discovery process with the @vport. It is done |
| 67 | * by reading the HBA's Host Attention (HA) register. If there is any host |
| 68 | * link attention events during this @vport's discovery process, the @vport |
| 69 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall |
| 70 | * be issued if the link state is not already in host link cleared state, |
| 71 | * and a return code shall indicate whether the host link attention event |
| 72 | * had happened. |
| 73 | * |
| 74 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport |
| 75 | * state in LPFC_VPORT_READY, the request for checking host link attention |
| 76 | * event will be ignored and a return code shall indicate no host link |
| 77 | * attention event had happened. |
| 78 | * |
| 79 | * Return codes |
| 80 | * 0 - no host link attention event happened |
| 81 | * 1 - host link attention event happened |
| 82 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 83 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 84 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 85 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 86 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 87 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 88 | uint32_t ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 89 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 90 | if (vport->port_state >= LPFC_VPORT_READY || |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 91 | phba->link_state == LPFC_LINK_DOWN || |
| 92 | phba->sli_rev > LPFC_SLI_REV3) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 93 | return 0; |
| 94 | |
| 95 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 96 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 97 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 98 | |
| 99 | if (!(ha_copy & HA_LATT)) |
| 100 | return 0; |
| 101 | |
| 102 | /* Pending Link Event during Discovery */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 103 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 104 | "0237 Pending Link Event during " |
| 105 | "Discovery: State x%x\n", |
| 106 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 107 | |
| 108 | /* CLEAR_LA should re-enable link attention events and |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 109 | * we should then immediately take a LATT event. The |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 110 | * LATT processing should call lpfc_linkdown() which |
| 111 | * will cleanup any left over in-progress discovery |
| 112 | * events. |
| 113 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 114 | spin_lock_irq(shost->host_lock); |
| 115 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 116 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 117 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 118 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 119 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 120 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 121 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 122 | } |
| 123 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 124 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 125 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 126 | * @vport: pointer to a host virtual N_Port data structure. |
| 127 | * @expectRsp: flag indicating whether response is expected. |
| 128 | * @cmdSize: size of the ELS command. |
| 129 | * @retry: number of retries to the command IOCB when it fails. |
| 130 | * @ndlp: pointer to a node-list data structure. |
| 131 | * @did: destination identifier. |
| 132 | * @elscmd: the ELS command code. |
| 133 | * |
| 134 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 135 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 136 | * passed into the routine for discovery state machine to issue an Extended |
| 137 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 138 | * and preparation routine that is used by all the discovery state machine |
| 139 | * routines and the ELS command-specific fields will be later set up by |
| 140 | * the individual discovery machine routines after calling this routine |
| 141 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 142 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 143 | * payload and response payload (if expected). The reference count on the |
| 144 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 145 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 146 | * reference for the command's callback function to access later. |
| 147 | * |
| 148 | * Return code |
| 149 | * Pointer to the newly allocated/prepared els iocb data structure |
| 150 | * NULL - when els iocb data structure allocation/preparation failed |
| 151 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 152 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 153 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 154 | uint16_t cmdSize, uint8_t retry, |
| 155 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 156 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 157 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 158 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 159 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 160 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 161 | struct ulp_bde64 *bpl; |
| 162 | IOCB_t *icmd; |
| 163 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 164 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 165 | if (!lpfc_is_link_up(phba)) |
| 166 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 167 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 168 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 169 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 170 | |
| 171 | if (elsiocb == NULL) |
| 172 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 173 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 174 | /* |
| 175 | * If this command is for fabric controller and HBA running |
| 176 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. |
| 177 | */ |
| 178 | if ((did == Fabric_DID) && |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 179 | (phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 180 | ((elscmd == ELS_CMD_FLOGI) || |
| 181 | (elscmd == ELS_CMD_FDISC) || |
| 182 | (elscmd == ELS_CMD_LOGO))) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 183 | switch (elscmd) { |
| 184 | case ELS_CMD_FLOGI: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 185 | elsiocb->iocb_flag |= |
| 186 | ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 187 | & LPFC_FIP_ELS_ID_MASK); |
| 188 | break; |
| 189 | case ELS_CMD_FDISC: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 190 | elsiocb->iocb_flag |= |
| 191 | ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 192 | & LPFC_FIP_ELS_ID_MASK); |
| 193 | break; |
| 194 | case ELS_CMD_LOGO: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 195 | elsiocb->iocb_flag |= |
| 196 | ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 197 | & LPFC_FIP_ELS_ID_MASK); |
| 198 | break; |
| 199 | } |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 200 | else |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 201 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 202 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 203 | icmd = &elsiocb->iocb; |
| 204 | |
| 205 | /* fill in BDEs for command */ |
| 206 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 207 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 208 | if (pcmd) |
| 209 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 210 | if (!pcmd || !pcmd->virt) |
| 211 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 212 | |
| 213 | INIT_LIST_HEAD(&pcmd->list); |
| 214 | |
| 215 | /* Allocate buffer for response payload */ |
| 216 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 217 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 218 | if (prsp) |
| 219 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 220 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 221 | if (!prsp || !prsp->virt) |
| 222 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 223 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 224 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 225 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 226 | |
| 227 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 228 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 229 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 230 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 231 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 232 | if (!pbuflist || !pbuflist->virt) |
| 233 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 234 | |
| 235 | INIT_LIST_HEAD(&pbuflist->list); |
| 236 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | if (expectRsp) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 238 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 239 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
| 240 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 241 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 242 | |
| 243 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 244 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 245 | if (elscmd == ELS_CMD_FLOGI) |
| 246 | icmd->ulpTimeout = FF_DEF_RATOV * 2; |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 247 | else if (elscmd == ELS_CMD_LOGO) |
| 248 | icmd->ulpTimeout = phba->fc_ratov; |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 249 | else |
| 250 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 251 | } else { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 252 | icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 253 | icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
| 254 | icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 255 | icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| 256 | icmd->un.xseq64.xmit_els_remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 257 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 258 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 259 | icmd->ulpBdeCount = 1; |
| 260 | icmd->ulpLe = 1; |
| 261 | icmd->ulpClass = CLASS3; |
| 262 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 263 | /* |
| 264 | * If we have NPIV enabled, we want to send ELS traffic by VPI. |
| 265 | * For SLI4, since the driver controls VPIs we also want to include |
| 266 | * all ELS pt2pt protocol traffic as well. |
| 267 | */ |
| 268 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) || |
| 269 | ((phba->sli_rev == LPFC_SLI_REV4) && |
| 270 | (vport->fc_flag & FC_PT2PT))) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 271 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 272 | if (expectRsp) { |
| 273 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 274 | |
| 275 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
| 276 | icmd->ulpContext = phba->vpi_ids[vport->vpi]; |
| 277 | } |
| 278 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 279 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 280 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 281 | if (elscmd == ELS_CMD_ECHO) |
| 282 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 283 | else |
| 284 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 285 | } |
| 286 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 287 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 288 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 289 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 290 | bpl->tus.f.bdeSize = cmdSize; |
| 291 | bpl->tus.f.bdeFlags = 0; |
| 292 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 293 | |
| 294 | if (expectRsp) { |
| 295 | bpl++; |
| 296 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 297 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 298 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 299 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 300 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 301 | } |
| 302 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 303 | elsiocb->context2 = pcmd; |
| 304 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 305 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 306 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 307 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 308 | |
| 309 | if (prsp) { |
| 310 | list_add(&prsp->list, &pcmd->list); |
| 311 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 312 | if (expectRsp) { |
| 313 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 314 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 315 | "0116 Xmit ELS command x%x to remote " |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 316 | "NPORT x%x I/O tag: x%x, port state:x%x " |
| 317 | "rpi x%x fc_flag:x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 318 | elscmd, did, elsiocb->iotag, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 319 | vport->port_state, ndlp->nlp_rpi, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 320 | vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 321 | } else { |
| 322 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 323 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 324 | "0117 Xmit ELS response x%x to remote " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 325 | "NPORT x%x I/O tag: x%x, size: x%x " |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 326 | "port_state x%x rpi x%x fc_flag x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 327 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 328 | cmdSize, vport->port_state, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 329 | ndlp->nlp_rpi, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 330 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 331 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 332 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 333 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 334 | if (expectRsp) |
| 335 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 336 | kfree(pbuflist); |
| 337 | |
| 338 | els_iocb_free_prsp_exit: |
| 339 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 340 | kfree(prsp); |
| 341 | |
| 342 | els_iocb_free_pcmb_exit: |
| 343 | kfree(pcmd); |
| 344 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 345 | return NULL; |
| 346 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 347 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 348 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 349 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 350 | * @vport: pointer to a host virtual N_Port data structure. |
| 351 | * |
| 352 | * This routine issues a fabric registration login for a @vport. An |
| 353 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 354 | * The routine invokes two mailbox commands to carry out fabric registration |
| 355 | * login through the HBA firmware: the first mailbox command requests the |
| 356 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 357 | * command requests the HBA to perform the actual fabric registration login |
| 358 | * with the @vport. |
| 359 | * |
| 360 | * Return code |
| 361 | * 0 - successfully issued fabric registration login for @vport |
| 362 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 363 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 364 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 365 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 366 | { |
| 367 | struct lpfc_hba *phba = vport->phba; |
| 368 | LPFC_MBOXQ_t *mbox; |
| 369 | struct lpfc_dmabuf *mp; |
| 370 | struct lpfc_nodelist *ndlp; |
| 371 | struct serv_parm *sp; |
| 372 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 373 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 374 | |
| 375 | sp = &phba->fc_fabparam; |
| 376 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 377 | if (!ndlp) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 378 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 379 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 380 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 381 | |
| 382 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 383 | if (!mbox) { |
| 384 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 385 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 386 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 387 | |
| 388 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 389 | lpfc_config_link(phba, mbox); |
| 390 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 391 | mbox->vport = vport; |
| 392 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 393 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 394 | if (rc == MBX_NOT_FINISHED) { |
| 395 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 396 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 397 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 398 | |
| 399 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 400 | if (!mbox) { |
| 401 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 402 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 403 | } |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 404 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
| 405 | ndlp->nlp_rpi); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 406 | if (rc) { |
| 407 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 408 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 409 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 410 | |
| 411 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 412 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 413 | /* increment the reference count on ndlp to hold reference |
| 414 | * for the callback routine. |
| 415 | */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 416 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 417 | if (!mbox->ctx_ndlp) { |
| 418 | err = 6; |
| 419 | goto fail_no_ndlp; |
| 420 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 421 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 422 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 423 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 424 | err = 7; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 425 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 426 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 427 | |
| 428 | return 0; |
| 429 | |
| 430 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 431 | /* decrement the reference count on ndlp just incremented |
| 432 | * for the failed mbox command. |
| 433 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 434 | lpfc_nlp_put(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 435 | fail_no_ndlp: |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 436 | mp = (struct lpfc_dmabuf *)mbox->ctx_buf; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 437 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 438 | kfree(mp); |
| 439 | fail_free_mbox: |
| 440 | mempool_free(mbox, phba->mbox_mem_pool); |
| 441 | |
| 442 | fail: |
| 443 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 444 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 445 | "0249 Cannot issue Register Fabric login: Err %d\n", |
| 446 | err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 447 | return -ENXIO; |
| 448 | } |
| 449 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 450 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 451 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 452 | * @vport: pointer to a host virtual N_Port data structure. |
| 453 | * |
| 454 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 455 | * the @vport. This mailbox command is necessary for SLI4 port only. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 456 | * |
| 457 | * Return code |
| 458 | * 0 - successfully issued REG_VFI for @vport |
| 459 | * A failure code otherwise. |
| 460 | **/ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 461 | int |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 462 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 463 | { |
| 464 | struct lpfc_hba *phba = vport->phba; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 465 | LPFC_MBOXQ_t *mboxq = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 466 | struct lpfc_nodelist *ndlp; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 467 | struct lpfc_dmabuf *dmabuf = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 468 | int rc = 0; |
| 469 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 470 | /* move forward in case of SLI4 FC port loopback test and pt2pt mode */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 471 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 472 | !(phba->link_flag & LS_LOOPBACK_MODE) && |
| 473 | !(vport->fc_flag & FC_PT2PT)) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 474 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 475 | if (!ndlp) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 476 | rc = -ENODEV; |
| 477 | goto fail; |
| 478 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 479 | } |
| 480 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 481 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 482 | if (!mboxq) { |
| 483 | rc = -ENOMEM; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 484 | goto fail; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 485 | } |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 486 | |
| 487 | /* Supply CSP's only if we are fabric connect or pt-to-pt connect */ |
| 488 | if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) { |
| 489 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 490 | if (!dmabuf) { |
| 491 | rc = -ENOMEM; |
| 492 | goto fail; |
| 493 | } |
| 494 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 495 | if (!dmabuf->virt) { |
| 496 | rc = -ENOMEM; |
| 497 | goto fail; |
| 498 | } |
| 499 | memcpy(dmabuf->virt, &phba->fc_fabparam, |
| 500 | sizeof(struct serv_parm)); |
| 501 | } |
| 502 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 503 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 504 | if (dmabuf) |
| 505 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 506 | else |
| 507 | lpfc_reg_vfi(mboxq, vport, 0); |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 508 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 509 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 510 | mboxq->vport = vport; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 511 | mboxq->ctx_buf = dmabuf; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 512 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 513 | if (rc == MBX_NOT_FINISHED) { |
| 514 | rc = -ENXIO; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 515 | goto fail; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 516 | } |
| 517 | return 0; |
| 518 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 519 | fail: |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 520 | if (mboxq) |
| 521 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 522 | if (dmabuf) { |
| 523 | if (dmabuf->virt) |
| 524 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 525 | kfree(dmabuf); |
| 526 | } |
| 527 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 528 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 529 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 530 | "0289 Issue Register VFI failed: Err %d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 531 | return rc; |
| 532 | } |
| 533 | |
| 534 | /** |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 535 | * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login |
| 536 | * @vport: pointer to a host virtual N_Port data structure. |
| 537 | * |
| 538 | * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for |
| 539 | * the @vport. This mailbox command is necessary for SLI4 port only. |
| 540 | * |
| 541 | * Return code |
| 542 | * 0 - successfully issued REG_VFI for @vport |
| 543 | * A failure code otherwise. |
| 544 | **/ |
| 545 | int |
| 546 | lpfc_issue_unreg_vfi(struct lpfc_vport *vport) |
| 547 | { |
| 548 | struct lpfc_hba *phba = vport->phba; |
| 549 | struct Scsi_Host *shost; |
| 550 | LPFC_MBOXQ_t *mboxq; |
| 551 | int rc; |
| 552 | |
| 553 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 554 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 555 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 556 | "2556 UNREG_VFI mbox allocation failed" |
| 557 | "HBA state x%x\n", phba->pport->port_state); |
| 558 | return -ENOMEM; |
| 559 | } |
| 560 | |
| 561 | lpfc_unreg_vfi(mboxq, vport); |
| 562 | mboxq->vport = vport; |
| 563 | mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl; |
| 564 | |
| 565 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 566 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 567 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 568 | "2557 UNREG_VFI issue mbox failed rc x%x " |
| 569 | "HBA state x%x\n", |
| 570 | rc, phba->pport->port_state); |
| 571 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 572 | return -EIO; |
| 573 | } |
| 574 | |
| 575 | shost = lpfc_shost_from_vport(vport); |
| 576 | spin_lock_irq(shost->host_lock); |
| 577 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 578 | spin_unlock_irq(shost->host_lock); |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | /** |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 583 | * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean. |
| 584 | * @vport: pointer to a host virtual N_Port data structure. |
| 585 | * @sp: pointer to service parameter data structure. |
| 586 | * |
| 587 | * This routine is called from FLOGI/FDISC completion handler functions. |
| 588 | * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric |
| 589 | * node nodename is changed in the completion service parameter else return |
| 590 | * 0. This function also set flag in the vport data structure to delay |
| 591 | * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit |
| 592 | * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric |
| 593 | * node nodename is changed in the completion service parameter. |
| 594 | * |
| 595 | * Return code |
| 596 | * 0 - FCID and Fabric Nodename and Fabric portname is not changed. |
| 597 | * 1 - FCID or Fabric Nodename or Fabric portname is changed. |
| 598 | * |
| 599 | **/ |
| 600 | static uint8_t |
| 601 | lpfc_check_clean_addr_bit(struct lpfc_vport *vport, |
| 602 | struct serv_parm *sp) |
| 603 | { |
James Smart | 8eb8b96 | 2016-07-06 12:36:08 -0700 | [diff] [blame] | 604 | struct lpfc_hba *phba = vport->phba; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 605 | uint8_t fabric_param_changed = 0; |
| 606 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 607 | |
| 608 | if ((vport->fc_prevDID != vport->fc_myDID) || |
| 609 | memcmp(&vport->fabric_portname, &sp->portName, |
| 610 | sizeof(struct lpfc_name)) || |
| 611 | memcmp(&vport->fabric_nodename, &sp->nodeName, |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 612 | sizeof(struct lpfc_name)) || |
| 613 | (vport->vport_flag & FAWWPN_PARAM_CHG)) { |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 614 | fabric_param_changed = 1; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 615 | vport->vport_flag &= ~FAWWPN_PARAM_CHG; |
| 616 | } |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 617 | /* |
| 618 | * Word 1 Bit 31 in common service parameter is overloaded. |
| 619 | * Word 1 Bit 31 in FLOGI request is multiple NPort request |
| 620 | * Word 1 Bit 31 in FLOGI response is clean address bit |
| 621 | * |
| 622 | * If fabric parameter is changed and clean address bit is |
| 623 | * cleared delay nport discovery if |
| 624 | * - vport->fc_prevDID != 0 (not initial discovery) OR |
| 625 | * - lpfc_delay_discovery module parameter is set. |
| 626 | */ |
| 627 | if (fabric_param_changed && !sp->cmn.clean_address_bit && |
James Smart | 8eb8b96 | 2016-07-06 12:36:08 -0700 | [diff] [blame] | 628 | (vport->fc_prevDID || phba->cfg_delay_discovery)) { |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 629 | spin_lock_irq(shost->host_lock); |
| 630 | vport->fc_flag |= FC_DISC_DELAYED; |
| 631 | spin_unlock_irq(shost->host_lock); |
| 632 | } |
| 633 | |
| 634 | return fabric_param_changed; |
| 635 | } |
| 636 | |
| 637 | |
| 638 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 639 | * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 640 | * @vport: pointer to a host virtual N_Port data structure. |
| 641 | * @ndlp: pointer to a node-list data structure. |
| 642 | * @sp: pointer to service parameter data structure. |
| 643 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 644 | * |
| 645 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 646 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 647 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 648 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 649 | * @vport against the previously assigned N_Port ID. If it is different from |
| 650 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 651 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 652 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 653 | * is invoked to register login to the fabric. |
| 654 | * |
| 655 | * Return code |
| 656 | * 0 - Success (currently, always return 0) |
| 657 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 658 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 659 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 660 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 661 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 662 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 663 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 664 | struct lpfc_nodelist *np; |
| 665 | struct lpfc_nodelist *next_np; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 666 | uint8_t fabric_param_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 667 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 668 | spin_lock_irq(shost->host_lock); |
| 669 | vport->fc_flag |= FC_FABRIC; |
| 670 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 671 | |
| 672 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 673 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 674 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 675 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 676 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 677 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 678 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 679 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 680 | spin_lock_irq(shost->host_lock); |
| 681 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 682 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 683 | } |
| 684 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 685 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 686 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 687 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 688 | ndlp->nlp_class_sup = 0; |
| 689 | if (sp->cls1.classValid) |
| 690 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 691 | if (sp->cls2.classValid) |
| 692 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 693 | if (sp->cls3.classValid) |
| 694 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 695 | if (sp->cls4.classValid) |
| 696 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 697 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 698 | sp->cmn.bbRcvSizeLsb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 699 | |
| 700 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 701 | if (fabric_param_changed) { |
| 702 | /* Reset FDMI attribute masks based on config parameter */ |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 703 | if (phba->cfg_enable_SmartSAN || |
| 704 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 705 | /* Setup appropriate attribute masks */ |
| 706 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 707 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 708 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 709 | else |
| 710 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 711 | } else { |
| 712 | vport->fdmi_hba_mask = 0; |
| 713 | vport->fdmi_port_mask = 0; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | } |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 717 | memcpy(&vport->fabric_portname, &sp->portName, |
| 718 | sizeof(struct lpfc_name)); |
| 719 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 720 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 721 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 722 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 723 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 724 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 725 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 726 | LOG_ELS | LOG_VPORT, |
| 727 | "1816 FLOGI NPIV supported, " |
| 728 | "response data 0x%x\n", |
| 729 | sp->cmn.response_multiple_NPort); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 730 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 731 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 732 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 733 | } else { |
| 734 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 735 | to call reg_vnpid atleast for the physcial host */ |
| 736 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 737 | LOG_ELS | LOG_VPORT, |
| 738 | "1817 Fabric does not support NPIV " |
| 739 | "- configuring single port mode.\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 740 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 741 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 742 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 746 | /* |
| 747 | * For FC we need to do some special processing because of the SLI |
| 748 | * Port's default settings of the Common Service Parameters. |
| 749 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 750 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 751 | (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) { |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 752 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 753 | if (fabric_param_changed) |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 754 | lpfc_unregister_fcf_prep(phba); |
| 755 | |
| 756 | /* This should just update the VFI CSPs*/ |
| 757 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 758 | lpfc_issue_reg_vfi(vport); |
| 759 | } |
| 760 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 761 | if (fabric_param_changed && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 762 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 763 | |
| 764 | /* If our NportID changed, we need to ensure all |
| 765 | * remaining NPORTs get unreg_login'ed. |
| 766 | */ |
| 767 | list_for_each_entry_safe(np, next_np, |
| 768 | &vport->fc_nodes, nlp_listp) { |
| 769 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 770 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 771 | continue; |
| 772 | spin_lock_irq(shost->host_lock); |
| 773 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 774 | spin_unlock_irq(shost->host_lock); |
| 775 | lpfc_unreg_rpi(vport, np); |
| 776 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 777 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 778 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 779 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 780 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 781 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 782 | spin_lock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 783 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 784 | spin_unlock_irq(shost->host_lock); |
| 785 | } |
James Smart | 27aa1b7 | 2012-05-09 21:18:49 -0400 | [diff] [blame] | 786 | |
| 787 | /* |
| 788 | * For SLI3 and SLI4, the VPI needs to be reregistered in |
| 789 | * response to this fabric parameter change event. |
| 790 | */ |
| 791 | spin_lock_irq(shost->host_lock); |
| 792 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 793 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 794 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 795 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 796 | /* |
| 797 | * Driver needs to re-reg VPI in order for f/w |
| 798 | * to update the MAC address. |
| 799 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 800 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 801 | lpfc_register_new_vport(phba, vport, ndlp); |
| 802 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 803 | } |
| 804 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 805 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 806 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 807 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 808 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 809 | lpfc_register_new_vport(phba, vport, ndlp); |
| 810 | else |
| 811 | lpfc_issue_fabric_reglogin(vport); |
| 812 | } else { |
| 813 | ndlp->nlp_type |= NLP_FABRIC; |
| 814 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 815 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 816 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 817 | lpfc_start_fdiscs(phba); |
| 818 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 819 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 820 | lpfc_issue_init_vpi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 821 | else { |
| 822 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 823 | "3135 Need register VFI: (x%x/%x)\n", |
| 824 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 825 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 826 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 827 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 828 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 829 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 830 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 831 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 832 | * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 833 | * @vport: pointer to a host virtual N_Port data structure. |
| 834 | * @ndlp: pointer to a node-list data structure. |
| 835 | * @sp: pointer to service parameter data structure. |
| 836 | * |
| 837 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 838 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 839 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 840 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 841 | * the received N_Port Name lexicographically, this node shall assign local |
| 842 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 843 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 844 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 845 | * N_Port IDs. |
| 846 | * |
| 847 | * Return code |
| 848 | * 0 - Success |
| 849 | * -ENXIO - Fail |
| 850 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 851 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 852 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 853 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 854 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 855 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 856 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 857 | LPFC_MBOXQ_t *mbox; |
| 858 | int rc; |
| 859 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 860 | spin_lock_irq(shost->host_lock); |
| 861 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 862 | vport->fc_flag |= FC_PT2PT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 863 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 864 | |
James Smart | d33d0eb | 2017-11-20 16:00:34 -0800 | [diff] [blame] | 865 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 866 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 867 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 868 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
| 869 | if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) { |
| 870 | lpfc_unregister_fcf_prep(phba); |
| 871 | |
| 872 | spin_lock_irq(shost->host_lock); |
| 873 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 874 | spin_unlock_irq(shost->host_lock); |
| 875 | phba->fc_topology_changed = 0; |
| 876 | } |
| 877 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 878 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 879 | sizeof(vport->fc_portname)); |
James Smart | 2eb6862 | 2012-09-29 11:32:27 -0400 | [diff] [blame] | 880 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 881 | if (rc >= 0) { |
| 882 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 883 | spin_lock_irq(shost->host_lock); |
| 884 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 885 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 886 | |
| 887 | /* |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 888 | * N_Port ID cannot be 0, set our Id to LocalID |
| 889 | * the other side will be RemoteID. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 890 | */ |
| 891 | |
| 892 | /* not equal */ |
| 893 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 894 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 895 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 896 | /* Decrement ndlp reference count indicating that ndlp can be |
| 897 | * safely released when other references to it are done. |
| 898 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 899 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 900 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 901 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 902 | if (!ndlp) { |
| 903 | /* |
| 904 | * Cannot find existing Fabric ndlp, so allocate a |
| 905 | * new one |
| 906 | */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 907 | ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 908 | if (!ndlp) |
| 909 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 913 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 914 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 915 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 916 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 917 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 918 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 919 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 920 | spin_unlock_irq(shost->host_lock); |
James Smart | d33d0eb | 2017-11-20 16:00:34 -0800 | [diff] [blame] | 921 | |
| 922 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 923 | if (!mbox) |
| 924 | goto fail; |
| 925 | |
| 926 | lpfc_config_link(phba, mbox); |
| 927 | |
| 928 | mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
| 929 | mbox->vport = vport; |
| 930 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 931 | if (rc == MBX_NOT_FINISHED) { |
| 932 | mempool_free(mbox, phba->mbox_mem_pool); |
| 933 | goto fail; |
| 934 | } |
| 935 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 936 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 937 | * count indicating that ndlp can be released when other |
| 938 | * references to it are done. |
| 939 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 940 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 941 | |
James Smart | d33d0eb | 2017-11-20 16:00:34 -0800 | [diff] [blame] | 942 | /* Start discovery - this should just do CLEAR_LA */ |
| 943 | lpfc_disc_start(vport); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 944 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 945 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 946 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 947 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 948 | return -ENXIO; |
| 949 | } |
| 950 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 951 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 952 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 953 | * @phba: pointer to lpfc hba data structure. |
| 954 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 955 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 956 | * |
| 957 | * This routine is the top-level completion callback function for issuing |
| 958 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 959 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 960 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 961 | * returning 1), the command IOCB will be released and function returned. |
| 962 | * If the retry attempt has been given up (possibly reach the maximum |
| 963 | * number of retries), one additional decrement of ndlp reference shall be |
| 964 | * invoked before going out after releasing the command IOCB. This will |
| 965 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 966 | * invoke one decrement of ndlp reference count). If no error reported in |
| 967 | * the IOCB status, the command Port ID field is used to determine whether |
| 968 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 969 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 970 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 971 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 972 | * specific topology completion conditions. |
| 973 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 974 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 975 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 976 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 977 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 978 | struct lpfc_vport *vport = cmdiocb->vport; |
| 979 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 980 | IOCB_t *irsp = &rspiocb->iocb; |
| 981 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 982 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 983 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 984 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 985 | int rc; |
| 986 | |
| 987 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 988 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 989 | /* One additional decrement on node reference count to |
| 990 | * trigger the release of the node |
| 991 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 992 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 993 | goto out; |
| 994 | } |
| 995 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 996 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 997 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 998 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 999 | vport->port_state); |
| 1000 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1001 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1002 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1003 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1004 | * due to new FCF discovery |
| 1005 | */ |
| 1006 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1007 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 1008 | if (phba->link_state < LPFC_LINK_UP) |
| 1009 | goto stop_rr_fcf_flogi; |
| 1010 | if ((phba->fcoe_cvl_eventtag_attn == |
| 1011 | phba->fcoe_cvl_eventtag) && |
| 1012 | (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1013 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1014 | IOERR_SLI_ABORTED)) |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1015 | goto stop_rr_fcf_flogi; |
| 1016 | else |
| 1017 | phba->fcoe_cvl_eventtag_attn = |
| 1018 | phba->fcoe_cvl_eventtag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1019 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1020 | "2611 FLOGI failed on FCF (x%x), " |
| 1021 | "status:x%x/x%x, tmo:x%x, perform " |
| 1022 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1023 | phba->fcf.current_rec.fcf_indx, |
| 1024 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1025 | irsp->ulpTimeout); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1026 | lpfc_sli4_set_fcf_flogi_fail(phba, |
| 1027 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1028 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1029 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 1030 | if (rc) |
| 1031 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1032 | } |
| 1033 | |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1034 | stop_rr_fcf_flogi: |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1035 | /* FLOGI failure */ |
James Smart | c73455e | 2017-11-20 16:00:28 -0800 | [diff] [blame] | 1036 | if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 1037 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1038 | IOERR_LOOP_OPEN_FAILURE))) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1039 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 1040 | "2858 FLOGI failure Status:x%x/x%x TMO" |
| 1041 | ":x%x Data x%x x%x\n", |
| 1042 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1043 | irsp->ulpTimeout, phba->hba_flag, |
| 1044 | phba->fcf.fcf_flag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1045 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1046 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1047 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1048 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1049 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1050 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT, |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 1051 | "0150 FLOGI failure Status:x%x/x%x " |
| 1052 | "xri x%x TMO:x%x\n", |
| 1053 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1054 | cmdiocb->sli4_xritag, irsp->ulpTimeout); |
| 1055 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 1056 | /* If this is not a loop open failure, bail out */ |
| 1057 | if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 1058 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1059 | IOERR_LOOP_OPEN_FAILURE))) |
| 1060 | goto flogifail; |
| 1061 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1062 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1063 | spin_lock_irq(shost->host_lock); |
| 1064 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 1065 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1066 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1067 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1068 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 1069 | * alpa map would take too long otherwise. |
| 1070 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1071 | if (phba->alpa_map[0] == 0) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1072 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1073 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1074 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1075 | (vport->fc_prevDID != vport->fc_myDID) || |
| 1076 | phba->fc_topology_changed)) { |
| 1077 | if (vport->fc_flag & FC_VFI_REGISTERED) { |
| 1078 | if (phba->fc_topology_changed) { |
| 1079 | lpfc_unregister_fcf_prep(phba); |
| 1080 | spin_lock_irq(shost->host_lock); |
| 1081 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 1082 | spin_unlock_irq(shost->host_lock); |
| 1083 | phba->fc_topology_changed = 0; |
| 1084 | } else { |
| 1085 | lpfc_sli4_unreg_all_rpis(vport); |
| 1086 | } |
| 1087 | } |
James Smart | 342b59c | 2016-03-31 14:12:31 -0700 | [diff] [blame] | 1088 | |
| 1089 | /* Do not register VFI if the driver aborted FLOGI */ |
| 1090 | if (!lpfc_error_lost_link(irsp)) |
| 1091 | lpfc_issue_reg_vfi(vport); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 1092 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1093 | lpfc_nlp_put(ndlp); |
| 1094 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1095 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1096 | goto flogifail; |
| 1097 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1098 | spin_lock_irq(shost->host_lock); |
| 1099 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 1100 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1101 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1102 | |
| 1103 | /* |
| 1104 | * The FLogI succeeded. Sync the data for the CPU before |
| 1105 | * accessing it. |
| 1106 | */ |
| 1107 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 1108 | if (!prsp) |
| 1109 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1110 | sp = prsp->virt + sizeof(uint32_t); |
| 1111 | |
| 1112 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1113 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 1114 | "0101 FLOGI completes successfully, I/O tag:x%x, " |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 1115 | "xri x%x Data: x%x x%x x%x x%x x%x %x\n", |
| 1116 | cmdiocb->iotag, cmdiocb->sli4_xritag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1117 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1118 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution, |
| 1119 | vport->port_state, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1120 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1121 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1122 | /* |
| 1123 | * If Common Service Parameters indicate Nport |
| 1124 | * we are point to point, if Fport we are Fabric. |
| 1125 | */ |
| 1126 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1127 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1128 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1129 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1130 | else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1131 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1132 | "2831 FLOGI response with cleared Fabric " |
| 1133 | "bit fcf_index 0x%x " |
| 1134 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 1135 | "Fabric Name " |
| 1136 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 1137 | phba->fcf.current_rec.fcf_indx, |
| 1138 | phba->fcf.current_rec.switch_name[0], |
| 1139 | phba->fcf.current_rec.switch_name[1], |
| 1140 | phba->fcf.current_rec.switch_name[2], |
| 1141 | phba->fcf.current_rec.switch_name[3], |
| 1142 | phba->fcf.current_rec.switch_name[4], |
| 1143 | phba->fcf.current_rec.switch_name[5], |
| 1144 | phba->fcf.current_rec.switch_name[6], |
| 1145 | phba->fcf.current_rec.switch_name[7], |
| 1146 | phba->fcf.current_rec.fabric_name[0], |
| 1147 | phba->fcf.current_rec.fabric_name[1], |
| 1148 | phba->fcf.current_rec.fabric_name[2], |
| 1149 | phba->fcf.current_rec.fabric_name[3], |
| 1150 | phba->fcf.current_rec.fabric_name[4], |
| 1151 | phba->fcf.current_rec.fabric_name[5], |
| 1152 | phba->fcf.current_rec.fabric_name[6], |
| 1153 | phba->fcf.current_rec.fabric_name[7]); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 1154 | |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1155 | lpfc_nlp_put(ndlp); |
| 1156 | spin_lock_irq(&phba->hbalock); |
| 1157 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1158 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1159 | spin_unlock_irq(&phba->hbalock); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 1160 | phba->fcf.fcf_redisc_attempted = 0; /* reset */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1161 | goto out; |
| 1162 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1163 | if (!rc) { |
| 1164 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1165 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 1166 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 1167 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1168 | "2769 FLOGI to FCF (x%x) " |
| 1169 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1170 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1171 | spin_lock_irq(&phba->hbalock); |
| 1172 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1173 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1174 | spin_unlock_irq(&phba->hbalock); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 1175 | phba->fcf.fcf_redisc_attempted = 0; /* reset */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1176 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1177 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | flogifail: |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1181 | spin_lock_irq(&phba->hbalock); |
| 1182 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 1183 | spin_unlock_irq(&phba->hbalock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1184 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1185 | lpfc_nlp_put(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1186 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1187 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1188 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1189 | |
| 1190 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1191 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1192 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1193 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1194 | IOERR_SLI_ABORTED) && |
| 1195 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1196 | IOERR_SLI_DOWN))) && |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1197 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 1198 | /* If FLOGI failed enable link interrupt. */ |
| 1199 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1200 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1201 | out: |
| 1202 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 1203 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1204 | } |
| 1205 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1206 | /** |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 1207 | * lpfc_cmpl_els_link_down - Completion callback function for ELS command |
| 1208 | * aborted during a link down |
| 1209 | * @phba: pointer to lpfc hba data structure. |
| 1210 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1211 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1212 | * |
| 1213 | */ |
| 1214 | static void |
| 1215 | lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1216 | struct lpfc_iocbq *rspiocb) |
| 1217 | { |
| 1218 | IOCB_t *irsp; |
| 1219 | uint32_t *pcmd; |
| 1220 | uint32_t cmd; |
| 1221 | |
| 1222 | pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt); |
| 1223 | cmd = *pcmd; |
| 1224 | irsp = &rspiocb->iocb; |
| 1225 | |
| 1226 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 1227 | "6445 ELS completes after LINK_DOWN: " |
| 1228 | " Status %x/%x cmd x%x flg x%x\n", |
| 1229 | irsp->ulpStatus, irsp->un.ulpWord[4], cmd, |
| 1230 | cmdiocb->iocb_flag); |
| 1231 | |
| 1232 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) { |
| 1233 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 1234 | atomic_dec(&phba->fabric_iocb_count); |
| 1235 | } |
| 1236 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1237 | } |
| 1238 | |
| 1239 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1240 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1241 | * @vport: pointer to a host virtual N_Port data structure. |
| 1242 | * @ndlp: pointer to a node-list data structure. |
| 1243 | * @retry: number of retries to the command IOCB. |
| 1244 | * |
| 1245 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 1246 | * for a @vport. The initiator service parameters are put into the payload |
| 1247 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 1248 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 1249 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 1250 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 1251 | * |
| 1252 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1253 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1254 | * will be stored into the context1 field of the IOCB for the completion |
| 1255 | * callback function to the FLOGI ELS command. |
| 1256 | * |
| 1257 | * Return code |
| 1258 | * 0 - successfully issued flogi iocb for @vport |
| 1259 | * 1 - failed to issue flogi iocb for @vport |
| 1260 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1261 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1262 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1263 | uint8_t retry) |
| 1264 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1265 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1266 | struct serv_parm *sp; |
| 1267 | IOCB_t *icmd; |
| 1268 | struct lpfc_iocbq *elsiocb; |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1269 | struct lpfc_iocbq defer_flogi_acc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1270 | uint8_t *pcmd; |
| 1271 | uint16_t cmdsize; |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1272 | uint32_t tmo, did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1273 | int rc; |
| 1274 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1275 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1276 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1277 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1278 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1279 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1280 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1281 | |
| 1282 | icmd = &elsiocb->iocb; |
| 1283 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1284 | |
| 1285 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1286 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1287 | pcmd += sizeof(uint32_t); |
| 1288 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1289 | sp = (struct serv_parm *) pcmd; |
| 1290 | |
| 1291 | /* Setup CSPs accordingly for Fabric */ |
| 1292 | sp->cmn.e_d_tov = 0; |
| 1293 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 1294 | sp->cmn.virtual_fabric_support = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1295 | sp->cls1.classValid = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1296 | if (sp->cmn.fcphLow < FC_PH3) |
| 1297 | sp->cmn.fcphLow = FC_PH3; |
| 1298 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1299 | sp->cmn.fcphHigh = FC_PH3; |
| 1300 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 1301 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1302 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1303 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 1304 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1305 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1306 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1307 | /* Set the fcfi to the fcfi we registered with */ |
| 1308 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1309 | } |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1310 | /* Can't do SLI4 class2 without support sequence coalescing */ |
| 1311 | sp->cls2.classValid = 0; |
| 1312 | sp->cls2.seqDelivery = 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1313 | } else { |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1314 | /* Historical, setting sequential-delivery bit for SLI3 */ |
| 1315 | sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; |
| 1316 | sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1317 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 1318 | sp->cmn.request_multiple_Nport = 1; |
| 1319 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1320 | icmd->ulpCt_h = 1; |
| 1321 | icmd->ulpCt_l = 0; |
| 1322 | } else |
| 1323 | sp->cmn.request_multiple_Nport = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1324 | } |
| 1325 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1326 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1327 | icmd->un.elsreq64.myID = 0; |
| 1328 | icmd->un.elsreq64.fl = 1; |
| 1329 | } |
| 1330 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1331 | tmo = phba->fc_ratov; |
| 1332 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1333 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1334 | phba->fc_ratov = tmo; |
| 1335 | |
| 1336 | phba->fc_stat.elsXmitFLOGI++; |
| 1337 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1338 | |
| 1339 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1340 | "Issue FLOGI: opt:x%x", |
| 1341 | phba->sli3_options, 0, 0); |
| 1342 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 1343 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 1344 | if (!elsiocb->context1) |
| 1345 | goto out; |
| 1346 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1347 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 1348 | if (rc == IOCB_ERROR) |
| 1349 | lpfc_nlp_put(ndlp); |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1350 | |
| 1351 | phba->hba_flag |= HBA_FLOGI_ISSUED; |
| 1352 | |
| 1353 | /* Check for a deferred FLOGI ACC condition */ |
| 1354 | if (phba->defer_flogi_acc_flag) { |
| 1355 | did = vport->fc_myDID; |
| 1356 | vport->fc_myDID = Fabric_DID; |
| 1357 | |
| 1358 | memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq)); |
| 1359 | |
| 1360 | defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id; |
| 1361 | defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id = |
| 1362 | phba->defer_flogi_acc_ox_id; |
| 1363 | |
| 1364 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1365 | "3354 Xmit deferred FLOGI ACC: rx_id: x%x," |
| 1366 | " ox_id: x%x, hba_flag x%x\n", |
| 1367 | phba->defer_flogi_acc_rx_id, |
| 1368 | phba->defer_flogi_acc_ox_id, phba->hba_flag); |
| 1369 | |
| 1370 | /* Send deferred FLOGI ACC */ |
| 1371 | lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc, |
| 1372 | ndlp, NULL); |
| 1373 | |
| 1374 | phba->defer_flogi_acc_flag = false; |
| 1375 | |
| 1376 | vport->fc_myDID = did; |
| 1377 | } |
| 1378 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 1379 | if (!rc) |
| 1380 | return 0; |
| 1381 | out: |
| 1382 | lpfc_els_free_iocb(phba, elsiocb); |
| 1383 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1384 | } |
| 1385 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1386 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1387 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1388 | * @phba: pointer to lpfc hba data structure. |
| 1389 | * |
| 1390 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1391 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1392 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1393 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1394 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1395 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1396 | * |
| 1397 | * Return code |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1398 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1399 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1400 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1401 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1402 | { |
| 1403 | struct lpfc_sli_ring *pring; |
| 1404 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1405 | struct lpfc_nodelist *ndlp; |
| 1406 | IOCB_t *icmd; |
| 1407 | |
| 1408 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1409 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1410 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1411 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1412 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1413 | pring = lpfc_phba_elsring(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1414 | if (unlikely(!pring)) |
| 1415 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1416 | |
| 1417 | /* |
| 1418 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1419 | * searching for. |
| 1420 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1421 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1422 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1423 | icmd = &iocb->iocb; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1424 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1425 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1426 | if (ndlp && (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1427 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1428 | } |
| 1429 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1430 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1431 | |
| 1432 | return 0; |
| 1433 | } |
| 1434 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1435 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1436 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1437 | * @vport: pointer to a host virtual N_Port data structure. |
| 1438 | * |
| 1439 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1440 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1441 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1442 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1443 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1444 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1445 | * @vport. |
| 1446 | * |
| 1447 | * Return code |
| 1448 | * 0 - failed to issue initial flogi for @vport |
| 1449 | * 1 - successfully issued initial flogi for @vport |
| 1450 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1451 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1452 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1453 | { |
| 1454 | struct lpfc_nodelist *ndlp; |
| 1455 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1456 | vport->port_state = LPFC_FLOGI; |
| 1457 | lpfc_set_disctmo(vport); |
| 1458 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1459 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1460 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1461 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1462 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1463 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1464 | if (!ndlp) |
| 1465 | return 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1466 | /* Set the node type */ |
| 1467 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1468 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1469 | /* Put ndlp onto node list */ |
| 1470 | lpfc_enqueue_node(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1471 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1472 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1473 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1474 | /* This decrement of reference count to node shall kick off |
| 1475 | * the release of the node. |
| 1476 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1477 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1478 | return 0; |
| 1479 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1480 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1481 | } |
| 1482 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1483 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1484 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1485 | * @vport: pointer to a host virtual N_Port data structure. |
| 1486 | * |
| 1487 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1488 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1489 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1490 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1491 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1492 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1493 | * @vport. |
| 1494 | * |
| 1495 | * Return code |
| 1496 | * 0 - failed to issue initial fdisc for @vport |
| 1497 | * 1 - successfully issued initial fdisc for @vport |
| 1498 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1499 | int |
| 1500 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1501 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1502 | struct lpfc_nodelist *ndlp; |
| 1503 | |
| 1504 | /* First look for the Fabric ndlp */ |
| 1505 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1506 | if (!ndlp) { |
| 1507 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1508 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1509 | if (!ndlp) |
| 1510 | return 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1511 | /* Put ndlp onto node list */ |
| 1512 | lpfc_enqueue_node(vport, ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1513 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1514 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1515 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1516 | /* decrement node reference count to trigger the release of |
| 1517 | * the node. |
| 1518 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1519 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1520 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1521 | } |
| 1522 | return 1; |
| 1523 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1524 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1525 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1526 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1527 | * @vport: pointer to a host virtual N_Port data structure. |
| 1528 | * |
| 1529 | * This routine checks whether there are more remaining Port Logins |
| 1530 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1531 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1532 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1533 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1534 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1535 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1536 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1537 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1538 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1539 | if (vport->num_disc_nodes) |
| 1540 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1541 | |
| 1542 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1543 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1544 | "0232 Continue discovery with %d PLOGIs to go " |
| 1545 | "Data: x%x x%x x%x\n", |
| 1546 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1547 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1548 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1549 | if (vport->fc_flag & FC_NLP_MORE) |
| 1550 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 1551 | lpfc_els_disc_plogi(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1552 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1553 | return; |
| 1554 | } |
| 1555 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1556 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1557 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1558 | * @phba: pointer to lpfc hba data structure. |
| 1559 | * @prsp: pointer to response IOCB payload. |
| 1560 | * @ndlp: pointer to a node-list data structure. |
| 1561 | * |
| 1562 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1563 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1564 | * The following cases are considered N_Port confirmed: |
| 1565 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1566 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1567 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1568 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1569 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1570 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1571 | * on that node to release the RPI associated with the node; 2) if there is |
| 1572 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1573 | * into, a new node shall be allocated (or activated). In either case, the |
| 1574 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1575 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1576 | * its pointer returned as the confirmed node. |
| 1577 | * |
| 1578 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1579 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1580 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1581 | * into an inactive state on the vport node list and the vport node list |
| 1582 | * management algorithm does not allow two node with a same DID. |
| 1583 | * |
| 1584 | * Return code |
| 1585 | * pointer to the PLOGI N_Port @ndlp |
| 1586 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1587 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1588 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1589 | struct lpfc_nodelist *ndlp) |
| 1590 | { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1591 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1592 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1593 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1594 | struct lpfc_rport_data *rdata; |
| 1595 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1596 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1597 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1598 | uint32_t rc, keepDID = 0, keep_nlp_flag = 0; |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1599 | uint32_t keep_new_nlp_flag = 0; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1600 | uint16_t keep_nlp_state; |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1601 | u32 keep_nlp_fc4_type = 0; |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1602 | struct lpfc_nvme_rport *keep_nrport = NULL; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1603 | int put_node; |
| 1604 | int put_rport; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1605 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1606 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1607 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1608 | * by WWPN. Just return the ndlp that was given to us. |
| 1609 | */ |
| 1610 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1611 | return ndlp; |
| 1612 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1613 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1614 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1615 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1616 | /* Now we find out if the NPort we are logging into, matches the WWPN |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1617 | * we have for that ndlp. If not, we have some work to do. |
| 1618 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1619 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1620 | |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1621 | /* return immediately if the WWPN matches ndlp */ |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1622 | if (new_ndlp == ndlp) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1623 | return ndlp; |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1624 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1625 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1626 | active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool, |
| 1627 | GFP_KERNEL); |
| 1628 | if (active_rrqs_xri_bitmap) |
| 1629 | memset(active_rrqs_xri_bitmap, 0, |
| 1630 | phba->cfg_rrq_xri_bitmap_sz); |
| 1631 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1632 | |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1633 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE, |
| 1634 | "3178 PLOGI confirm: ndlp x%x x%x x%x: " |
| 1635 | "new_ndlp x%x x%x x%x\n", |
| 1636 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type, |
| 1637 | (new_ndlp ? new_ndlp->nlp_DID : 0), |
| 1638 | (new_ndlp ? new_ndlp->nlp_flag : 0), |
| 1639 | (new_ndlp ? new_ndlp->nlp_fc4_type : 0)); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1640 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1641 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1642 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1643 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1644 | if (!rc) { |
| 1645 | if (active_rrqs_xri_bitmap) |
| 1646 | mempool_free(active_rrqs_xri_bitmap, |
| 1647 | phba->active_rrq_pool); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1648 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1649 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1650 | new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1651 | if (!new_ndlp) { |
| 1652 | if (active_rrqs_xri_bitmap) |
| 1653 | mempool_free(active_rrqs_xri_bitmap, |
| 1654 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1655 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1656 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1657 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1658 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1659 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1660 | active_rrqs_xri_bitmap) |
| 1661 | memcpy(active_rrqs_xri_bitmap, |
| 1662 | new_ndlp->active_rrqs_xri_bitmap, |
| 1663 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1664 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1665 | |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1666 | /* At this point in this routine, we know new_ndlp will be |
| 1667 | * returned. however, any previous GID_FTs that were done |
| 1668 | * would have updated nlp_fc4_type in ndlp, so we must ensure |
| 1669 | * new_ndlp has the right value. |
| 1670 | */ |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1671 | if (vport->fc_flag & FC_FABRIC) { |
| 1672 | keep_nlp_fc4_type = new_ndlp->nlp_fc4_type; |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1673 | new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type; |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1674 | } |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1675 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1676 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1677 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1678 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1679 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1680 | memcpy(new_ndlp->active_rrqs_xri_bitmap, |
| 1681 | ndlp->active_rrqs_xri_bitmap, |
| 1682 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1683 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1684 | spin_lock_irq(shost->host_lock); |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1685 | keep_new_nlp_flag = new_ndlp->nlp_flag; |
| 1686 | keep_nlp_flag = ndlp->nlp_flag; |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1687 | new_ndlp->nlp_flag = ndlp->nlp_flag; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 1688 | |
| 1689 | /* if new_ndlp had NLP_UNREG_INP set, keep it */ |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1690 | if (keep_new_nlp_flag & NLP_UNREG_INP) |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 1691 | new_ndlp->nlp_flag |= NLP_UNREG_INP; |
| 1692 | else |
| 1693 | new_ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 1694 | |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1695 | /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */ |
| 1696 | if (keep_new_nlp_flag & NLP_RPI_REGISTERED) |
| 1697 | new_ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 1698 | else |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1699 | new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
| 1700 | |
| 1701 | ndlp->nlp_flag = keep_new_nlp_flag; |
| 1702 | |
| 1703 | /* if ndlp had NLP_UNREG_INP set, keep it */ |
| 1704 | if (keep_nlp_flag & NLP_UNREG_INP) |
| 1705 | ndlp->nlp_flag |= NLP_UNREG_INP; |
| 1706 | else |
| 1707 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 1708 | |
| 1709 | /* if ndlp had NLP_RPI_REGISTERED set, keep it */ |
| 1710 | if (keep_nlp_flag & NLP_RPI_REGISTERED) |
| 1711 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| 1712 | else |
| 1713 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 1714 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1715 | spin_unlock_irq(shost->host_lock); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1716 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1717 | /* Set nlp_states accordingly */ |
| 1718 | keep_nlp_state = new_ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1719 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1720 | |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1721 | /* interchange the nvme remoteport structs */ |
| 1722 | keep_nrport = new_ndlp->nrport; |
| 1723 | new_ndlp->nrport = ndlp->nrport; |
| 1724 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1725 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1726 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1727 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1728 | * to put ndlp on UNUSED list and try to free it. |
| 1729 | */ |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1730 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1731 | "3179 PLOGI confirm NEW: %x %x\n", |
| 1732 | new_ndlp->nlp_DID, keepDID); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1733 | |
| 1734 | /* Fix up the rport accordingly */ |
| 1735 | rport = ndlp->rport; |
| 1736 | if (rport) { |
| 1737 | rdata = rport->dd_data; |
| 1738 | if (rdata->pnode == ndlp) { |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1739 | /* break the link before dropping the ref */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1740 | ndlp->rport = NULL; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1741 | lpfc_nlp_put(ndlp); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1742 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1743 | new_ndlp->rport = rport; |
| 1744 | } |
| 1745 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1746 | } |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1747 | |
| 1748 | /* Fix up the nvme rport */ |
| 1749 | if (ndlp->nrport) { |
| 1750 | ndlp->nrport = NULL; |
| 1751 | lpfc_nlp_put(ndlp); |
| 1752 | } |
| 1753 | |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1754 | /* Two ndlps cannot have the same did on the nodelist. |
| 1755 | * Note: for this case, ndlp has a NULL WWPN so setting |
| 1756 | * the nlp_fc4_type isn't required. |
| 1757 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1758 | ndlp->nlp_DID = keepDID; |
James Smart | 4938250 | 2017-11-20 16:00:38 -0800 | [diff] [blame] | 1759 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1760 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1761 | active_rrqs_xri_bitmap) |
| 1762 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1763 | active_rrqs_xri_bitmap, |
| 1764 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1765 | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1766 | } else { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1767 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1768 | "3180 PLOGI confirm SWAP: %x %x\n", |
| 1769 | new_ndlp->nlp_DID, keepDID); |
| 1770 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1771 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1772 | |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1773 | /* Two ndlps cannot have the same did and the fc4 |
| 1774 | * type must be transferred because the ndlp is in |
| 1775 | * flight. |
| 1776 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1777 | ndlp->nlp_DID = keepDID; |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1778 | ndlp->nlp_fc4_type = keep_nlp_fc4_type; |
| 1779 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1780 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1781 | active_rrqs_xri_bitmap) |
| 1782 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1783 | active_rrqs_xri_bitmap, |
| 1784 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1785 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1786 | /* Since we are switching over to the new_ndlp, |
| 1787 | * reset the old ndlp state |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1788 | */ |
| 1789 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 1790 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1791 | keep_nlp_state = NLP_STE_NPR_NODE; |
| 1792 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1793 | |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1794 | /* Previous ndlp no longer active with nvme host transport. |
| 1795 | * Remove reference from earlier registration unless the |
| 1796 | * nvme host took care of it. |
| 1797 | */ |
| 1798 | if (ndlp->nrport) |
| 1799 | lpfc_nlp_put(ndlp); |
| 1800 | ndlp->nrport = keep_nrport; |
| 1801 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1802 | /* Fix up the rport accordingly */ |
| 1803 | rport = ndlp->rport; |
| 1804 | if (rport) { |
| 1805 | rdata = rport->dd_data; |
| 1806 | put_node = rdata->pnode != NULL; |
| 1807 | put_rport = ndlp->rport != NULL; |
| 1808 | rdata->pnode = NULL; |
| 1809 | ndlp->rport = NULL; |
| 1810 | if (put_node) |
| 1811 | lpfc_nlp_put(ndlp); |
| 1812 | if (put_rport) |
| 1813 | put_device(&rport->dev); |
| 1814 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1815 | } |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1816 | |
| 1817 | /* |
| 1818 | * If ndlp is not associated with any rport we can drop it here else |
| 1819 | * let dev_loss_tmo_callbk trigger DEVICE_RM event |
| 1820 | */ |
| 1821 | if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE)) |
| 1822 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
| 1823 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1824 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1825 | active_rrqs_xri_bitmap) |
| 1826 | mempool_free(active_rrqs_xri_bitmap, |
| 1827 | phba->active_rrq_pool); |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1828 | |
| 1829 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE, |
| 1830 | "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n", |
| 1831 | new_ndlp->nlp_DID, new_ndlp->nlp_flag, |
| 1832 | new_ndlp->nlp_fc4_type); |
| 1833 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1834 | return new_ndlp; |
| 1835 | } |
| 1836 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1837 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1838 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1839 | * @vport: pointer to a host virtual N_Port data structure. |
| 1840 | * |
| 1841 | * This routine checks whether more Registration State Change |
| 1842 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1843 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1844 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1845 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1846 | * handling the RSCNs. |
| 1847 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1848 | void |
| 1849 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1850 | { |
| 1851 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1852 | |
| 1853 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1854 | /* |
| 1855 | * Check to see if more RSCNs came in while we were |
| 1856 | * processing this one. |
| 1857 | */ |
| 1858 | if (vport->fc_rscn_id_cnt || |
| 1859 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1860 | lpfc_els_handle_rscn(vport); |
| 1861 | else { |
| 1862 | spin_lock_irq(shost->host_lock); |
| 1863 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1864 | spin_unlock_irq(shost->host_lock); |
| 1865 | } |
| 1866 | } |
| 1867 | } |
| 1868 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1869 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1870 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. |
| 1871 | * @phba: pointer to lpfc hba data structure. |
| 1872 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1873 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1874 | * |
| 1875 | * This routine will call the clear rrq function to free the rrq and |
| 1876 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not |
| 1877 | * exist then the clear_rrq is still called because the rrq needs to |
| 1878 | * be freed. |
| 1879 | **/ |
| 1880 | |
| 1881 | static void |
| 1882 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1883 | struct lpfc_iocbq *rspiocb) |
| 1884 | { |
| 1885 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1886 | IOCB_t *irsp; |
| 1887 | struct lpfc_nodelist *ndlp; |
| 1888 | struct lpfc_node_rrq *rrq; |
| 1889 | |
| 1890 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1891 | rrq = cmdiocb->context_un.rrq; |
| 1892 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1893 | |
| 1894 | irsp = &rspiocb->iocb; |
| 1895 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1896 | "RRQ cmpl: status:x%x/x%x did:x%x", |
| 1897 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1898 | irsp->un.elsreq64.remoteID); |
| 1899 | |
| 1900 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1901 | if (!ndlp || ndlp != rrq->ndlp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1902 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1903 | "2882 RRQ completes to NPort x%x " |
| 1904 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1905 | irsp->un.elsreq64.remoteID, |
| 1906 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1907 | irsp->ulpIoTag); |
| 1908 | goto out; |
| 1909 | } |
| 1910 | |
| 1911 | /* rrq completes to NPort <nlp_DID> */ |
| 1912 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1913 | "2880 RRQ completes to NPort x%x " |
| 1914 | "Data: x%x x%x x%x x%x x%x\n", |
| 1915 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1916 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); |
| 1917 | |
| 1918 | if (irsp->ulpStatus) { |
| 1919 | /* Check for retry */ |
| 1920 | /* RRQ failed Don't print the vport to vport rjts */ |
| 1921 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1922 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1923 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1924 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1925 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 1926 | "2881 RRQ failure DID:%06X Status:" |
| 1927 | "x%x/x%x\n", |
| 1928 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1929 | irsp->un.ulpWord[4]); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1930 | } |
| 1931 | out: |
| 1932 | if (rrq) |
| 1933 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 1934 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1935 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 1936 | lpfc_nlp_put(ndlp); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1937 | return; |
| 1938 | } |
| 1939 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1940 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1941 | * @phba: pointer to lpfc hba data structure. |
| 1942 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1943 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1944 | * |
| 1945 | * This routine is the completion callback function for issuing the Port |
| 1946 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1947 | * ndlp on the vport node list that matches the remote node ID from the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1948 | * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1949 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1950 | * checked for error conditons. If there is error status reported, PLOGI |
| 1951 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1952 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1953 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1954 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1955 | * there are additional N_Port nodes with the vport that need to perform |
| 1956 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1957 | * PLOGIs. |
| 1958 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1959 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1960 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1961 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1962 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1963 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1964 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1965 | IOCB_t *irsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 1966 | struct lpfc_nodelist *ndlp, *free_ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1967 | struct lpfc_dmabuf *prsp; |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 1968 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1969 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1970 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1971 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1972 | |
| 1973 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1974 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1975 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1976 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1977 | irsp->un.elsreq64.remoteID); |
| 1978 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1979 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1980 | if (!ndlp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1981 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1982 | "0136 PLOGI completes to NPort x%x " |
| 1983 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1984 | irsp->un.elsreq64.remoteID, |
| 1985 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1986 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1987 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1988 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1989 | |
| 1990 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1991 | * is being used during discovery. |
| 1992 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1993 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1995 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1996 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1997 | |
| 1998 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1999 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2000 | "0102 PLOGI completes to NPort x%06x " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2001 | "Data: x%x x%x x%x x%x x%x\n", |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2002 | ndlp->nlp_DID, ndlp->nlp_fc4_type, |
| 2003 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2004 | disc, vport->num_disc_nodes); |
| 2005 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2007 | if (lpfc_els_chk_latt(vport)) { |
| 2008 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2009 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2010 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2011 | goto out; |
| 2012 | } |
| 2013 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2014 | if (irsp->ulpStatus) { |
| 2015 | /* Check for retry */ |
| 2016 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2017 | /* ELS command is being retried */ |
| 2018 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2019 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2020 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2021 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2022 | } |
| 2023 | goto out; |
| 2024 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2025 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 2026 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 2027 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 2028 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 2029 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2030 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2031 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 2032 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2033 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2034 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 2035 | if (!lpfc_error_lost_link(irsp)) |
| 2036 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2037 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2038 | } else { |
| 2039 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 2040 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2041 | cmdiocb->context2)->list.next, |
| 2042 | struct lpfc_dmabuf, list); |
| 2043 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 2044 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2045 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2046 | } |
| 2047 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2048 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2049 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2050 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2051 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2052 | if (vport->num_disc_nodes == 0) { |
| 2053 | spin_lock_irq(shost->host_lock); |
| 2054 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2055 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2056 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2057 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2058 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2059 | } |
| 2060 | } |
| 2061 | |
| 2062 | out: |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2063 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 2064 | "PLOGI Cmpl PUT: did:x%x refcnt %d", |
| 2065 | ndlp->nlp_DID, kref_read(&ndlp->kref), 0); |
| 2066 | |
| 2067 | /* Release the reference on the original I/O request. */ |
| 2068 | free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
| 2069 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2070 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2071 | lpfc_nlp_put(free_ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2072 | return; |
| 2073 | } |
| 2074 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2075 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2076 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2077 | * @vport: pointer to a host virtual N_Port data structure. |
| 2078 | * @did: destination port identifier. |
| 2079 | * @retry: number of retries to the command IOCB. |
| 2080 | * |
| 2081 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 2082 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 2083 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 2084 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 2085 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 2086 | * |
| 2087 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2088 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2089 | * will be stored into the context1 field of the IOCB for the completion |
| 2090 | * callback function to the PLOGI ELS command. |
| 2091 | * |
| 2092 | * Return code |
| 2093 | * 0 - Successfully issued a plogi for @vport |
| 2094 | * 1 - failed to issue a plogi for @vport |
| 2095 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2096 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2097 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2098 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2099 | struct lpfc_hba *phba = vport->phba; |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 2100 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | struct serv_parm *sp; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2102 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | uint8_t *pcmd; |
| 2105 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2106 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2107 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2108 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2109 | |
| 2110 | if (ndlp) { |
| 2111 | /* Defer the processing of the issue PLOGI until after the |
| 2112 | * outstanding UNREG_RPI mbox command completes, unless we |
| 2113 | * are going offline. This logic does not apply for Fabric DIDs |
| 2114 | */ |
| 2115 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2116 | ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) && |
| 2117 | !(vport->fc_flag & FC_OFFLINE_MODE)) { |
| 2118 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2119 | "4110 Issue PLOGI x%x deferred " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2120 | "on NPort x%x rpi x%x Data: x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2121 | ndlp->nlp_defer_did, ndlp->nlp_DID, |
| 2122 | ndlp->nlp_rpi, ndlp); |
| 2123 | |
| 2124 | /* We can only defer 1st PLOGI */ |
| 2125 | if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING) |
| 2126 | ndlp->nlp_defer_did = did; |
| 2127 | return 0; |
| 2128 | } |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2129 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2130 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2131 | /* If ndlp is not NULL, we will bump the reference count on it */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2132 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2133 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2134 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2135 | if (!elsiocb) |
| 2136 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 2138 | shost = lpfc_shost_from_vport(vport); |
| 2139 | spin_lock_irq(shost->host_lock); |
| 2140 | ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT; |
| 2141 | spin_unlock_irq(shost->host_lock); |
| 2142 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2143 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2144 | |
| 2145 | /* For PLOGI request, remainder of payload is service parameters */ |
| 2146 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2147 | pcmd += sizeof(uint32_t); |
| 2148 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2149 | sp = (struct serv_parm *) pcmd; |
| 2150 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2151 | /* |
| 2152 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 2153 | * to device on remote loops work. |
| 2154 | */ |
| 2155 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 2156 | sp->cmn.altBbCredit = 1; |
| 2157 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2158 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 2159 | sp->cmn.fcphLow = FC_PH_4_3; |
| 2160 | |
| 2161 | if (sp->cmn.fcphHigh < FC_PH3) |
| 2162 | sp->cmn.fcphHigh = FC_PH3; |
| 2163 | |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 2164 | sp->cmn.valid_vendor_ver_level = 0; |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2165 | memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 2166 | sp->cmn.bbRcvSizeMsb &= 0xF; |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 2167 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2168 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2169 | "Issue PLOGI: did:x%x", |
| 2170 | did, 0, 0); |
| 2171 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2172 | /* If our firmware supports this feature, convey that |
| 2173 | * information to the target using the vendor specific field. |
| 2174 | */ |
| 2175 | if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { |
| 2176 | sp->cmn.valid_vendor_ver_level = 1; |
| 2177 | sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); |
| 2178 | sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP); |
| 2179 | } |
| 2180 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2181 | phba->fc_stat.elsXmitPLOGI++; |
| 2182 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2183 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2184 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2185 | "Issue PLOGI: did:x%x refcnt %d", |
| 2186 | did, kref_read(&ndlp->kref), 0); |
| 2187 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 2188 | if (!elsiocb->context1) |
| 2189 | goto io_err; |
| 2190 | |
| 2191 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 2192 | if (ret) { |
| 2193 | lpfc_nlp_put(ndlp); |
| 2194 | goto io_err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2195 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2196 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2197 | |
| 2198 | io_err: |
| 2199 | lpfc_els_free_iocb(phba, elsiocb); |
| 2200 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2201 | } |
| 2202 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2203 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2204 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2205 | * @phba: pointer to lpfc hba data structure. |
| 2206 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2207 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2208 | * |
| 2209 | * This routine is the completion callback function for a Process Login |
| 2210 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 2211 | * status. If there is error status reported, PRLI retry shall be attempted |
| 2212 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 2213 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 2214 | * ndlp to mark the PRLI completion. |
| 2215 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2217 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2218 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2219 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2220 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2221 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2222 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2223 | struct lpfc_nodelist *ndlp; |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 2224 | char *mode; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2225 | u32 loglevel; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2226 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2227 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2228 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2229 | |
| 2230 | irsp = &(rspiocb->iocb); |
| 2231 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2232 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2233 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 9de416a | 2017-12-08 17:18:07 -0800 | [diff] [blame] | 2234 | |
| 2235 | /* Driver supports multiple FC4 types. Counters matter. */ |
| 2236 | vport->fc_prli_sent--; |
| 2237 | ndlp->fc4_prli_sent--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2238 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2239 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2240 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2241 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 2242 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2243 | ndlp->nlp_DID); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2244 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2245 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2246 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2247 | "0103 PRLI completes to NPort x%06x " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2248 | "Data: x%x x%x x%x x%x\n", |
| 2249 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2250 | vport->num_disc_nodes, ndlp->fc4_prli_sent); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2251 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2253 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2254 | goto out; |
| 2255 | |
| 2256 | if (irsp->ulpStatus) { |
| 2257 | /* Check for retry */ |
| 2258 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2259 | /* ELS command is being retried */ |
| 2260 | goto out; |
| 2261 | } |
James Smart | 3120046 | 2017-05-15 15:20:42 -0700 | [diff] [blame] | 2262 | |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 2263 | /* If we don't send GFT_ID to Fabric, a PRLI error |
| 2264 | * could be expected. |
| 2265 | */ |
| 2266 | if ((vport->fc_flag & FC_FABRIC) || |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2267 | (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) { |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 2268 | mode = KERN_ERR; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2269 | loglevel = LOG_TRACE_EVENT; |
| 2270 | } else { |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 2271 | mode = KERN_INFO; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2272 | loglevel = LOG_ELS; |
| 2273 | } |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 2274 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2275 | /* PRLI failed */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2276 | lpfc_printf_vlog(vport, mode, loglevel, |
James Smart | 3120046 | 2017-05-15 15:20:42 -0700 | [diff] [blame] | 2277 | "2754 PRLI failure DID:%06X Status:x%x/x%x, " |
| 2278 | "data: x%x\n", |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2279 | ndlp->nlp_DID, irsp->ulpStatus, |
James Smart | 3120046 | 2017-05-15 15:20:42 -0700 | [diff] [blame] | 2280 | irsp->un.ulpWord[4], ndlp->fc4_prli_sent); |
| 2281 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2282 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2283 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2284 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2285 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2286 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2287 | NLP_EVT_CMPL_PRLI); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2288 | } else { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2289 | /* Good status, call state machine. However, if another |
| 2290 | * PRLI is outstanding, don't call the state machine |
| 2291 | * because final disposition to Mapped or Unmapped is |
| 2292 | * completed there. |
| 2293 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2294 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2295 | NLP_EVT_CMPL_PRLI); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2296 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2297 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2298 | out: |
| 2299 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2300 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2301 | return; |
| 2302 | } |
| 2303 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2304 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2305 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2306 | * @vport: pointer to a host virtual N_Port data structure. |
| 2307 | * @ndlp: pointer to a node-list data structure. |
| 2308 | * @retry: number of retries to the command IOCB. |
| 2309 | * |
| 2310 | * This routine issues a Process Login (PRLI) ELS command for the |
| 2311 | * @vport. The PRLI service parameters are set up in the payload of the |
| 2312 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 2313 | * is put to the IOCB completion callback func field before invoking the |
| 2314 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 2315 | * |
| 2316 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2317 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2318 | * will be stored into the context1 field of the IOCB for the completion |
| 2319 | * callback function to the PRLI ELS command. |
| 2320 | * |
| 2321 | * Return code |
| 2322 | * 0 - successfully issued prli iocb command for @vport |
| 2323 | * 1 - failed to issue prli iocb command for @vport |
| 2324 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2325 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2326 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2327 | uint8_t retry) |
| 2328 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2329 | int rc = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2330 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2331 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2332 | PRLI *npr; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2333 | struct lpfc_nvme_prli *npr_nvme; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2334 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2335 | uint8_t *pcmd; |
| 2336 | uint16_t cmdsize; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2337 | u32 local_nlp_type, elscmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2338 | |
Dick Kennedy | 991f0c0 | 2017-08-23 16:55:39 -0700 | [diff] [blame] | 2339 | /* |
| 2340 | * If we are in RSCN mode, the FC4 types supported from a |
| 2341 | * previous GFT_ID command may not be accurate. So, if we |
| 2342 | * are a NVME Initiator, always look for the possibility of |
| 2343 | * the remote NPort beng a NVME Target. |
| 2344 | */ |
| 2345 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2346 | vport->fc_flag & FC_RSCN_MODE && |
| 2347 | vport->nvmei_support) |
| 2348 | ndlp->nlp_fc4_type |= NLP_FC4_NVME; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2349 | local_nlp_type = ndlp->nlp_fc4_type; |
| 2350 | |
James Smart | 9de416a | 2017-12-08 17:18:07 -0800 | [diff] [blame] | 2351 | /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp |
| 2352 | * fields here before any of them can complete. |
| 2353 | */ |
| 2354 | ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); |
| 2355 | ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR); |
| 2356 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2357 | ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC); |
James Smart | 9de416a | 2017-12-08 17:18:07 -0800 | [diff] [blame] | 2358 | ndlp->nvme_fb_size = 0; |
| 2359 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2360 | send_next_prli: |
| 2361 | if (local_nlp_type & NLP_FC4_FCP) { |
| 2362 | /* Payload is 4 + 16 = 20 x14 bytes. */ |
| 2363 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
| 2364 | elscmd = ELS_CMD_PRLI; |
| 2365 | } else if (local_nlp_type & NLP_FC4_NVME) { |
| 2366 | /* Payload is 4 + 20 = 24 x18 bytes. */ |
| 2367 | cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli)); |
| 2368 | elscmd = ELS_CMD_NVMEPRLI; |
| 2369 | } else { |
| 2370 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2371 | "3083 Unknown FC_TYPE x%x ndlp x%06x\n", |
| 2372 | ndlp->nlp_fc4_type, ndlp->nlp_DID); |
| 2373 | return 1; |
| 2374 | } |
James Smart | 09559e8 | 2017-06-15 22:56:46 -0700 | [diff] [blame] | 2375 | |
| 2376 | /* SLI3 ports don't support NVME. If this rport is a strict NVME |
| 2377 | * FC4 type, implicitly LOGO. |
| 2378 | */ |
| 2379 | if (phba->sli_rev == LPFC_SLI_REV3 && |
| 2380 | ndlp->nlp_fc4_type == NLP_FC4_NVME) { |
| 2381 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2382 | "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n", |
| 2383 | ndlp->nlp_type); |
| 2384 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
| 2385 | return 1; |
| 2386 | } |
| 2387 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2388 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2389 | ndlp->nlp_DID, elscmd); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2390 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2391 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2392 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2393 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2394 | |
| 2395 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2396 | memset(pcmd, 0, cmdsize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2397 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2398 | if (local_nlp_type & NLP_FC4_FCP) { |
| 2399 | /* Remainder of payload is FCP PRLI parameter page. |
| 2400 | * Note: this data structure is defined as |
| 2401 | * BE/LE in the structure definition so no |
| 2402 | * byte swap call is made. |
| 2403 | */ |
| 2404 | *((uint32_t *)(pcmd)) = ELS_CMD_PRLI; |
| 2405 | pcmd += sizeof(uint32_t); |
| 2406 | npr = (PRLI *)pcmd; |
| 2407 | |
| 2408 | /* |
| 2409 | * If our firmware version is 3.20 or later, |
| 2410 | * set the following bits for FC-TAPE support. |
| 2411 | */ |
| 2412 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 2413 | npr->ConfmComplAllowed = 1; |
| 2414 | npr->Retry = 1; |
| 2415 | npr->TaskRetryIdReq = 1; |
| 2416 | } |
| 2417 | npr->estabImagePair = 1; |
| 2418 | npr->readXferRdyDis = 1; |
| 2419 | if (vport->cfg_first_burst_size) |
| 2420 | npr->writeXferRdyDis = 1; |
| 2421 | |
| 2422 | /* For FCP support */ |
| 2423 | npr->prliType = PRLI_FCP_TYPE; |
| 2424 | npr->initiatorFunc = 1; |
| 2425 | elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ; |
| 2426 | |
| 2427 | /* Remove FCP type - processed. */ |
| 2428 | local_nlp_type &= ~NLP_FC4_FCP; |
| 2429 | } else if (local_nlp_type & NLP_FC4_NVME) { |
| 2430 | /* Remainder of payload is NVME PRLI parameter page. |
| 2431 | * This data structure is the newer definition that |
| 2432 | * uses bf macros so a byte swap is required. |
| 2433 | */ |
| 2434 | *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI; |
| 2435 | pcmd += sizeof(uint32_t); |
| 2436 | npr_nvme = (struct lpfc_nvme_prli *)pcmd; |
| 2437 | bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); |
| 2438 | bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ |
James Smart | 0d8af09 | 2019-08-14 16:57:10 -0700 | [diff] [blame] | 2439 | if (phba->nsler) { |
| 2440 | bf_set(prli_nsler, npr_nvme, 1); |
| 2441 | bf_set(prli_conf, npr_nvme, 1); |
| 2442 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2443 | |
| 2444 | /* Only initiators request first burst. */ |
| 2445 | if ((phba->cfg_nvme_enable_fb) && |
| 2446 | !phba->nvmet_support) |
| 2447 | bf_set(prli_fba, npr_nvme, 1); |
| 2448 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2449 | if (phba->nvmet_support) { |
| 2450 | bf_set(prli_tgt, npr_nvme, 1); |
| 2451 | bf_set(prli_disc, npr_nvme, 1); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2452 | } else { |
| 2453 | bf_set(prli_init, npr_nvme, 1); |
James Smart | a5ff068 | 2018-01-30 15:58:56 -0800 | [diff] [blame] | 2454 | bf_set(prli_conf, npr_nvme, 1); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2455 | } |
James Smart | a5ff068 | 2018-01-30 15:58:56 -0800 | [diff] [blame] | 2456 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2457 | npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); |
| 2458 | npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); |
| 2459 | elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ; |
| 2460 | |
| 2461 | /* Remove NVME type - processed. */ |
| 2462 | local_nlp_type &= ~NLP_FC4_NVME; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2463 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2464 | |
| 2465 | phba->fc_stat.elsXmitPRLI++; |
| 2466 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2467 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2468 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 9de416a | 2017-12-08 17:18:07 -0800 | [diff] [blame] | 2469 | |
| 2470 | /* The vport counters are used for lpfc_scan_finished, but |
| 2471 | * the ndlp is used to track outstanding PRLIs for different |
| 2472 | * FC4 types. |
| 2473 | */ |
| 2474 | vport->fc_prli_sent++; |
| 2475 | ndlp->fc4_prli_sent++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2476 | spin_unlock_irq(shost->host_lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2477 | |
| 2478 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2479 | "Issue PRLI: did:x%x refcnt %d", |
| 2480 | ndlp->nlp_DID, kref_read(&ndlp->kref), 0); |
| 2481 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 2482 | if (!elsiocb->context1) |
| 2483 | goto io_err; |
| 2484 | |
| 2485 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 2486 | if (rc == IOCB_ERROR) |
| 2487 | goto node_err; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2488 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2489 | |
| 2490 | /* The driver supports 2 FC4 types. Make sure |
| 2491 | * a PRLI is issued for all types before exiting. |
| 2492 | */ |
James Smart | 09559e8 | 2017-06-15 22:56:46 -0700 | [diff] [blame] | 2493 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2494 | local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME)) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2495 | goto send_next_prli; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2496 | else |
| 2497 | return 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2498 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2499 | node_err: |
| 2500 | lpfc_nlp_put(ndlp); |
| 2501 | io_err: |
| 2502 | spin_lock_irq(shost->host_lock); |
| 2503 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
| 2504 | spin_unlock_irq(shost->host_lock); |
| 2505 | lpfc_els_free_iocb(phba, elsiocb); |
| 2506 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2507 | } |
| 2508 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2509 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2510 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2511 | * @vport: pointer to a host virtual N_Port data structure. |
| 2512 | * |
| 2513 | * This routine performs Registration State Change Notification (RSCN) |
| 2514 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 2515 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 2516 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 2517 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 2518 | * invoked to check and handle possible more RSCN came in during the period |
| 2519 | * of processing the current ones. |
| 2520 | **/ |
| 2521 | static void |
| 2522 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 2523 | { |
| 2524 | lpfc_can_disctmo(vport); |
| 2525 | |
| 2526 | /* RSCN discovery */ |
| 2527 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 2528 | if (vport->fc_npr_cnt) |
| 2529 | if (lpfc_els_disc_plogi(vport)) |
| 2530 | return; |
| 2531 | |
| 2532 | lpfc_end_rscn(vport); |
| 2533 | } |
| 2534 | |
| 2535 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2536 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2537 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 2538 | * |
| 2539 | * This function is called when the final ADISC is completed during discovery. |
| 2540 | * This function handles clearing link attention or issuing reg_vpi depending |
| 2541 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 2542 | * discovery. |
| 2543 | * This function is called with no locks held. |
| 2544 | **/ |
| 2545 | static void |
| 2546 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 2547 | { |
| 2548 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2549 | struct lpfc_hba *phba = vport->phba; |
| 2550 | |
| 2551 | /* |
| 2552 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 2553 | * and continue discovery. |
| 2554 | */ |
| 2555 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2556 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 2557 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | d454c91 | 2014-12-30 12:08:58 -0500 | [diff] [blame] | 2558 | /* The ADISCs are complete. Doesn't matter if they |
| 2559 | * succeeded or failed because the ADISC completion |
| 2560 | * routine guarantees to call the state machine and |
| 2561 | * the RPI is either unregistered (failed ADISC response) |
| 2562 | * or the RPI is still valid and the node is marked |
| 2563 | * mapped for a target. The exchanges should be in the |
| 2564 | * correct state. This code is specific to SLI3. |
| 2565 | */ |
| 2566 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2567 | lpfc_issue_reg_vpi(phba, vport); |
| 2568 | return; |
| 2569 | } |
| 2570 | /* |
| 2571 | * For SLI2, we need to set port_state to READY |
| 2572 | * and continue discovery. |
| 2573 | */ |
| 2574 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2575 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 2576 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2577 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 2578 | vport->num_disc_nodes = 0; |
| 2579 | /* go thru NPR list, issue ELS PLOGIs */ |
| 2580 | if (vport->fc_npr_cnt) |
| 2581 | lpfc_els_disc_plogi(vport); |
| 2582 | if (!vport->num_disc_nodes) { |
| 2583 | spin_lock_irq(shost->host_lock); |
| 2584 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2585 | spin_unlock_irq(shost->host_lock); |
| 2586 | lpfc_can_disctmo(vport); |
| 2587 | lpfc_end_rscn(vport); |
| 2588 | } |
| 2589 | } |
| 2590 | vport->port_state = LPFC_VPORT_READY; |
| 2591 | } else |
| 2592 | lpfc_rscn_disc(vport); |
| 2593 | } |
| 2594 | |
| 2595 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2596 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2597 | * @vport: pointer to a host virtual N_Port data structure. |
| 2598 | * |
| 2599 | * This routine determines whether there are more ndlps on a @vport |
| 2600 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 2601 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 2602 | * remaining nodes which need to have ADISC sent. |
| 2603 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2604 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2605 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2606 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2607 | if (vport->num_disc_nodes) |
| 2608 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2610 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2611 | "0210 Continue discovery with %d ADISCs to go " |
| 2612 | "Data: x%x x%x x%x\n", |
| 2613 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 2614 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2615 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2616 | if (vport->fc_flag & FC_NLP_MORE) { |
| 2617 | lpfc_set_disctmo(vport); |
| 2618 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 2619 | lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2620 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2621 | if (!vport->num_disc_nodes) |
| 2622 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2623 | return; |
| 2624 | } |
| 2625 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2626 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2627 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2628 | * @phba: pointer to lpfc hba data structure. |
| 2629 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2630 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2631 | * |
| 2632 | * This routine is the completion function for issuing the Address Discover |
| 2633 | * (ADISC) command. It first checks to see whether link went down during |
| 2634 | * the discovery process. If so, the node will be marked as node port |
| 2635 | * recovery for issuing discover IOCB by the link attention handler and |
| 2636 | * exit. Otherwise, the response status is checked. If error was reported |
| 2637 | * in the response status, the ADISC command shall be retried by invoking |
| 2638 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 2639 | * the response status, the state machine is invoked to set transition |
| 2640 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 2641 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2642 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2643 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2644 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2645 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2646 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2647 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2648 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2650 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2651 | |
| 2652 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2653 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2654 | |
| 2655 | irsp = &(rspiocb->iocb); |
| 2656 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2657 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2658 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2659 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 2660 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2661 | ndlp->nlp_DID); |
| 2662 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2663 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2664 | * is being used during discovery. |
| 2665 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2666 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2667 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2668 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2669 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2671 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2672 | "0104 ADISC completes to NPort x%x " |
| 2673 | "Data: x%x x%x x%x x%x x%x\n", |
| 2674 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2675 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2676 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2677 | if (lpfc_els_chk_latt(vport)) { |
| 2678 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2679 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2680 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2681 | goto out; |
| 2682 | } |
| 2683 | |
| 2684 | if (irsp->ulpStatus) { |
| 2685 | /* Check for retry */ |
| 2686 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2687 | /* ELS command is being retried */ |
| 2688 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2689 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2690 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2691 | spin_unlock_irq(shost->host_lock); |
| 2692 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2693 | } |
| 2694 | goto out; |
| 2695 | } |
| 2696 | /* ADISC failed */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2697 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2698 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2699 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2700 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2701 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2702 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2703 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2704 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2705 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2706 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2707 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2708 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2709 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2710 | /* Check to see if there are more ADISCs to be sent */ |
| 2711 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2712 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2713 | out: |
| 2714 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2715 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2716 | return; |
| 2717 | } |
| 2718 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2719 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2720 | * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2721 | * @vport: pointer to a virtual N_Port data structure. |
| 2722 | * @ndlp: pointer to a node-list data structure. |
| 2723 | * @retry: number of retries to the command IOCB. |
| 2724 | * |
| 2725 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2726 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2727 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2728 | * to issue the ADISC ELS command. |
| 2729 | * |
| 2730 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2731 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2732 | * will be stored into the context1 field of the IOCB for the completion |
| 2733 | * callback function to the ADISC ELS command. |
| 2734 | * |
| 2735 | * Return code |
| 2736 | * 0 - successfully issued adisc |
| 2737 | * 1 - failed to issue adisc |
| 2738 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2739 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2740 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 | uint8_t retry) |
| 2742 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2743 | int rc = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2744 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2745 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2746 | ADISC *ap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2747 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2748 | uint8_t *pcmd; |
| 2749 | uint16_t cmdsize; |
| 2750 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2751 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2752 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2753 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2754 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2755 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2756 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2757 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2758 | |
| 2759 | /* For ADISC request, remainder of payload is service parameters */ |
| 2760 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2761 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2762 | |
| 2763 | /* Fill in ADISC payload */ |
| 2764 | ap = (ADISC *) pcmd; |
| 2765 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2766 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2767 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2768 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2769 | |
| 2770 | phba->fc_stat.elsXmitADISC++; |
| 2771 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2772 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2773 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2774 | spin_unlock_irq(shost->host_lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2775 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 2776 | if (!elsiocb->context1) |
| 2777 | goto node_err; |
| 2778 | |
| 2779 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2780 | "Issue ADISC: did:x%x refcnt %d", |
| 2781 | ndlp->nlp_DID, kref_read(&ndlp->kref), 0); |
| 2782 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 2783 | if (rc == IOCB_ERROR) |
| 2784 | goto io_err; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2785 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2786 | |
| 2787 | io_err: |
| 2788 | lpfc_nlp_put(ndlp); |
| 2789 | node_err: |
| 2790 | spin_lock_irq(shost->host_lock); |
| 2791 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
| 2792 | spin_unlock_irq(shost->host_lock); |
| 2793 | lpfc_els_free_iocb(phba, elsiocb); |
| 2794 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2795 | } |
| 2796 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2797 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2798 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2799 | * @phba: pointer to lpfc hba data structure. |
| 2800 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2801 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2802 | * |
| 2803 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2804 | * command. If no error status was reported from the LOGO response, the |
| 2805 | * state machine of the associated ndlp shall be invoked for transition with |
| 2806 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2807 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2808 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2809 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2810 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2811 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2812 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2813 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2814 | struct lpfc_vport *vport = ndlp->vport; |
| 2815 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2816 | IOCB_t *irsp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2817 | struct lpfcMboxq *mbox; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2818 | unsigned long flags; |
| 2819 | uint32_t skip_recovery = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2820 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2821 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2822 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2823 | |
| 2824 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2825 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2826 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2827 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2828 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2829 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2830 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2831 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2832 | ndlp->nlp_DID); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2833 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2834 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2835 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2836 | "0105 LOGO completes to NPort x%x " |
| 2837 | "Data: x%x x%x x%x x%x\n", |
| 2838 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2839 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2840 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2841 | if (lpfc_els_chk_latt(vport)) { |
| 2842 | skip_recovery = 1; |
| 2843 | goto out; |
| 2844 | } |
| 2845 | |
| 2846 | /* Check to see if link went down during discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2847 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2848 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2849 | * which should abort all outstanding IOs. |
| 2850 | */ |
| 2851 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2852 | NLP_EVT_DEVICE_RM); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2853 | skip_recovery = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2854 | goto out; |
| 2855 | } |
| 2856 | |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 2857 | /* The LOGO will not be retried on failure. A LOGO was |
| 2858 | * issued to the remote rport and a ACC or RJT or no Answer are |
| 2859 | * all acceptable. Note the failure and move forward with |
| 2860 | * discovery. The PLOGI will retry. |
| 2861 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2862 | if (irsp->ulpStatus) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2863 | /* LOGO failed */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2864 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 2865 | "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n", |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2866 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2867 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2868 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2869 | if (lpfc_error_lost_link(irsp)) { |
| 2870 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2871 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2872 | } |
| 2873 | } |
| 2874 | |
| 2875 | /* Call state machine. This will unregister the rpi if needed. */ |
| 2876 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); |
| 2877 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2878 | out: |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2879 | /* Driver is done with the IO. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2880 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2881 | lpfc_nlp_put(ndlp); |
| 2882 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2883 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ |
| 2884 | if ((vport->fc_flag & FC_PT2PT) && |
| 2885 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { |
| 2886 | phba->pport->fc_myDID = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2887 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 2888 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 2889 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2890 | if (phba->nvmet_support) |
| 2891 | lpfc_nvmet_update_targetport(phba); |
| 2892 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2893 | lpfc_nvme_update_localport(phba->pport); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2894 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2895 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2896 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2897 | if (mbox) { |
| 2898 | lpfc_config_link(phba, mbox); |
| 2899 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2900 | mbox->vport = vport; |
| 2901 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 2902 | MBX_NOT_FINISHED) { |
| 2903 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2904 | skip_recovery = 1; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2905 | } |
| 2906 | } |
| 2907 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2908 | |
| 2909 | /* |
| 2910 | * If the node is a target, the handling attempts to recover the port. |
| 2911 | * For any other port type, the rpi is unregistered as an implicit |
| 2912 | * LOGO. |
| 2913 | */ |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 2914 | if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) && |
| 2915 | skip_recovery == 0) { |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2916 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 2917 | spin_lock_irqsave(shost->host_lock, flags); |
| 2918 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 2919 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2920 | |
| 2921 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2922 | "3187 LOGO completes to NPort x%x: Start " |
| 2923 | "Recovery Data: x%x x%x x%x x%x\n", |
| 2924 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2925 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 2926 | vport->num_disc_nodes); |
| 2927 | lpfc_disc_start(vport); |
| 2928 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2929 | return; |
| 2930 | } |
| 2931 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2932 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2933 | * lpfc_issue_els_logo - Issue a logo to an node on a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2934 | * @vport: pointer to a virtual N_Port data structure. |
| 2935 | * @ndlp: pointer to a node-list data structure. |
| 2936 | * @retry: number of retries to the command IOCB. |
| 2937 | * |
| 2938 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2939 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2940 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2941 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2942 | * |
| 2943 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2944 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2945 | * will be stored into the context1 field of the IOCB for the completion |
| 2946 | * callback function to the LOGO ELS command. |
| 2947 | * |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 2948 | * Callers of this routine are expected to unregister the RPI first |
| 2949 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2950 | * Return code |
| 2951 | * 0 - successfully issued logo |
| 2952 | * 1 - failed to issue logo |
| 2953 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2954 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2955 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2956 | uint8_t retry) |
| 2957 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2958 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2959 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2960 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2961 | uint8_t *pcmd; |
| 2962 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2963 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2964 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2965 | spin_lock_irq(shost->host_lock); |
| 2966 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2967 | spin_unlock_irq(shost->host_lock); |
| 2968 | return 0; |
| 2969 | } |
| 2970 | spin_unlock_irq(shost->host_lock); |
| 2971 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2972 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2973 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2974 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2975 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2976 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2977 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2978 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2979 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2980 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2981 | |
| 2982 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2983 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2984 | pcmd += sizeof(uint32_t); |
| 2985 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2986 | |
| 2987 | phba->fc_stat.elsXmitLOGO++; |
| 2988 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2989 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2990 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2991 | ndlp->nlp_flag &= ~NLP_ISSUE_LOGO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2992 | spin_unlock_irq(shost->host_lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 2993 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 2994 | if (!elsiocb->context1) |
| 2995 | goto node_err; |
| 2996 | |
| 2997 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2998 | "Issue LOGO: did:x%x refcnt %d", |
| 2999 | ndlp->nlp_DID, kref_read(&ndlp->kref), 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3000 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3001 | if (rc == IOCB_ERROR) |
| 3002 | goto io_err; |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 3003 | |
| 3004 | spin_lock_irq(shost->host_lock); |
| 3005 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3006 | spin_unlock_irq(shost->host_lock); |
| 3007 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3008 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3009 | |
| 3010 | io_err: |
| 3011 | lpfc_nlp_put(ndlp); |
| 3012 | node_err: |
| 3013 | spin_lock_irq(shost->host_lock); |
| 3014 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 3015 | spin_unlock_irq(shost->host_lock); |
| 3016 | lpfc_els_free_iocb(phba, elsiocb); |
| 3017 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3018 | } |
| 3019 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3020 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3021 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3022 | * @phba: pointer to lpfc hba data structure. |
| 3023 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3024 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3025 | * |
| 3026 | * This routine is a generic completion callback function for ELS commands. |
| 3027 | * Specifically, it is the callback function which does not need to perform |
| 3028 | * any command specific operations. It is currently used by the ELS command |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3029 | * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel |
| 3030 | * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). |
| 3031 | * Other than certain debug loggings, this callback function simply invokes the |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3032 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 3033 | * discovery process. |
| 3034 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3035 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3036 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3037 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3038 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3039 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3040 | struct lpfc_nodelist *free_ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3041 | IOCB_t *irsp; |
| 3042 | |
| 3043 | irsp = &rspiocb->iocb; |
| 3044 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3045 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3046 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 3047 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 3048 | irsp->un.elsreq64.remoteID); |
| 3049 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3050 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3051 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3052 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 3053 | irsp->ulpIoTag, irsp->ulpStatus, |
| 3054 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3055 | |
| 3056 | /* Check to see if link went down during discovery */ |
| 3057 | lpfc_els_chk_latt(vport); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3058 | |
| 3059 | free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
| 3060 | |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3061 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3062 | lpfc_nlp_put(free_ndlp); |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | /** |
| 3066 | * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd |
| 3067 | * @phba: pointer to lpfc hba data structure. |
| 3068 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3069 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3070 | * |
| 3071 | * This routine is a generic completion callback function for Discovery ELS cmd. |
| 3072 | * Currently used by the ELS command issuing routines for the ELS State Change |
| 3073 | * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf(). |
| 3074 | * These commands will be retried once only for ELS timeout errors. |
| 3075 | **/ |
| 3076 | static void |
| 3077 | lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3078 | struct lpfc_iocbq *rspiocb) |
| 3079 | { |
| 3080 | struct lpfc_vport *vport = cmdiocb->vport; |
| 3081 | IOCB_t *irsp; |
| 3082 | struct lpfc_els_rdf_rsp *prdf; |
| 3083 | struct lpfc_dmabuf *pcmd, *prsp; |
| 3084 | u32 *pdata; |
| 3085 | u32 cmd; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3086 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3087 | |
| 3088 | irsp = &rspiocb->iocb; |
| 3089 | |
| 3090 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3091 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 3092 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 3093 | irsp->un.elsreq64.remoteID); |
| 3094 | /* ELS cmd tag <ulpIoTag> completes */ |
| 3095 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3096 | "0217 ELS cmd tag x%x completes Data: x%x x%x x%x " |
| 3097 | "x%x\n", |
| 3098 | irsp->ulpIoTag, irsp->ulpStatus, |
| 3099 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 3100 | cmdiocb->retry); |
| 3101 | |
| 3102 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 3103 | if (!pcmd) |
| 3104 | goto out; |
| 3105 | |
| 3106 | pdata = (u32 *)pcmd->virt; |
| 3107 | if (!pdata) |
| 3108 | goto out; |
| 3109 | cmd = *pdata; |
| 3110 | |
| 3111 | /* Only 1 retry for ELS Timeout only */ |
| 3112 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 3113 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3114 | IOERR_SEQUENCE_TIMEOUT)) { |
| 3115 | cmdiocb->retry++; |
| 3116 | if (cmdiocb->retry <= 1) { |
| 3117 | switch (cmd) { |
| 3118 | case ELS_CMD_SCR: |
| 3119 | lpfc_issue_els_scr(vport, cmdiocb->retry); |
| 3120 | break; |
| 3121 | case ELS_CMD_RDF: |
| 3122 | cmdiocb->context1 = NULL; /* save ndlp refcnt */ |
| 3123 | lpfc_issue_els_rdf(vport, cmdiocb->retry); |
| 3124 | break; |
| 3125 | } |
| 3126 | goto out; |
| 3127 | } |
| 3128 | phba->fc_stat.elsRetryExceeded++; |
| 3129 | } |
| 3130 | if (irsp->ulpStatus) { |
| 3131 | /* ELS discovery cmd completes with error */ |
| 3132 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 3133 | "4203 ELS cmd x%x error: x%x x%X\n", cmd, |
| 3134 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
| 3135 | goto out; |
| 3136 | } |
| 3137 | |
| 3138 | /* The RDF response doesn't have any impact on the running driver |
| 3139 | * but the notification descriptors are dumped here for support. |
| 3140 | */ |
| 3141 | if (cmd == ELS_CMD_RDF) { |
| 3142 | int i; |
| 3143 | |
| 3144 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 3145 | if (!prsp) |
| 3146 | goto out; |
| 3147 | |
| 3148 | prdf = (struct lpfc_els_rdf_rsp *)prsp->virt; |
| 3149 | if (!prdf) |
| 3150 | goto out; |
| 3151 | |
| 3152 | for (i = 0; i < ELS_RDF_REG_TAG_CNT && |
| 3153 | i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++) |
| 3154 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
Colin Ian King | 162e250 | 2020-02-21 15:48:41 +0000 | [diff] [blame] | 3155 | "4677 Fabric RDF Notification Grant Data: " |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3156 | "0x%08x\n", |
| 3157 | be32_to_cpu( |
| 3158 | prdf->reg_d1.desc_tags[i])); |
| 3159 | } |
| 3160 | |
| 3161 | out: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3162 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3163 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3164 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3165 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3166 | return; |
| 3167 | } |
| 3168 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3169 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3170 | * lpfc_issue_els_scr - Issue a scr to an node on a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3171 | * @vport: pointer to a host virtual N_Port data structure. |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3172 | * @retry: retry counter for the command IOCB. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3173 | * |
| 3174 | * This routine issues a State Change Request (SCR) to a fabric node |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3175 | * on a @vport. The remote node is Fabric Controller (0xfffffd). It |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3176 | * first search the @vport node list to find the matching ndlp. If no such |
| 3177 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 3178 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 3179 | * routine is invoked to send the SCR IOCB. |
| 3180 | * |
| 3181 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3182 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3183 | * will be stored into the context1 field of the IOCB for the completion |
| 3184 | * callback function to the SCR ELS command. |
| 3185 | * |
| 3186 | * Return code |
| 3187 | * 0 - Successfully issued scr command |
| 3188 | * 1 - Failed to issue scr command |
| 3189 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3190 | int |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3191 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3192 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3193 | int rc = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3194 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3195 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3196 | uint8_t *pcmd; |
| 3197 | uint16_t cmdsize; |
| 3198 | struct lpfc_nodelist *ndlp; |
| 3199 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3200 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3201 | |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3202 | ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3203 | if (!ndlp) { |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3204 | ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3205 | if (!ndlp) |
| 3206 | return 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3207 | lpfc_enqueue_node(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3208 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3209 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3210 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 3211 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 3212 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3213 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3214 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3215 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3216 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3217 | |
| 3218 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3219 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3220 | |
| 3221 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3222 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3223 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 3224 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3225 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3226 | "Issue SCR: did:x%x", |
| 3227 | ndlp->nlp_DID, 0, 0); |
| 3228 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3229 | phba->fc_stat.elsXmitSCR++; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3230 | elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3231 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 3232 | if (!elsiocb->context1) |
| 3233 | goto node_err; |
| 3234 | |
| 3235 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3236 | "Issue SCR: did:x%x refcnt %d", |
| 3237 | ndlp->nlp_DID, kref_read(&ndlp->kref), 0); |
| 3238 | |
| 3239 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 3240 | if (rc == IOCB_ERROR) |
| 3241 | goto io_err; |
| 3242 | |
| 3243 | /* Keep the ndlp just in case RDF is being sent */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3244 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3245 | |
| 3246 | io_err: |
| 3247 | lpfc_nlp_put(ndlp); |
| 3248 | node_err: |
| 3249 | lpfc_els_free_iocb(phba, elsiocb); |
| 3250 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3251 | } |
| 3252 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3253 | /** |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3254 | * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric) |
| 3255 | * or the other nport (pt2pt). |
| 3256 | * @vport: pointer to a host virtual N_Port data structure. |
| 3257 | * @retry: number of retries to the command IOCB. |
| 3258 | * |
| 3259 | * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD) |
| 3260 | * when connected to a fabric, or to the remote port when connected |
| 3261 | * in point-to-point mode. When sent to the Fabric Controller, it will |
| 3262 | * replay the RSCN to registered recipients. |
| 3263 | * |
| 3264 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3265 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3266 | * will be stored into the context1 field of the IOCB for the completion |
| 3267 | * callback function to the RSCN ELS command. |
| 3268 | * |
| 3269 | * Return code |
| 3270 | * 0 - Successfully issued RSCN command |
| 3271 | * 1 - Failed to issue RSCN command |
| 3272 | **/ |
| 3273 | int |
| 3274 | lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry) |
| 3275 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3276 | int rc = 0; |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3277 | struct lpfc_hba *phba = vport->phba; |
| 3278 | struct lpfc_iocbq *elsiocb; |
| 3279 | struct lpfc_nodelist *ndlp; |
| 3280 | struct { |
| 3281 | struct fc_els_rscn rscn; |
| 3282 | struct fc_els_rscn_page portid; |
| 3283 | } *event; |
| 3284 | uint32_t nportid; |
| 3285 | uint16_t cmdsize = sizeof(*event); |
| 3286 | |
| 3287 | /* Not supported for private loop */ |
| 3288 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
| 3289 | !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 3290 | return 1; |
| 3291 | |
| 3292 | if (vport->fc_flag & FC_PT2PT) { |
| 3293 | /* find any mapped nport - that would be the other nport */ |
| 3294 | ndlp = lpfc_findnode_mapped(vport); |
| 3295 | if (!ndlp) |
| 3296 | return 1; |
| 3297 | } else { |
| 3298 | nportid = FC_FID_FCTRL; |
| 3299 | /* find the fabric controller node */ |
| 3300 | ndlp = lpfc_findnode_did(vport, nportid); |
| 3301 | if (!ndlp) { |
| 3302 | /* if one didn't exist, make one */ |
| 3303 | ndlp = lpfc_nlp_init(vport, nportid); |
| 3304 | if (!ndlp) |
| 3305 | return 1; |
| 3306 | lpfc_enqueue_node(vport, ndlp); |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3307 | } |
| 3308 | } |
| 3309 | |
| 3310 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 3311 | ndlp->nlp_DID, ELS_CMD_RSCN_XMT); |
| 3312 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3313 | if (!elsiocb) |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3314 | return 1; |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3315 | |
| 3316 | event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 3317 | |
| 3318 | event->rscn.rscn_cmd = ELS_RSCN; |
| 3319 | event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page); |
| 3320 | event->rscn.rscn_plen = cpu_to_be16(cmdsize); |
| 3321 | |
| 3322 | nportid = vport->fc_myDID; |
| 3323 | /* appears that page flags must be 0 for fabric to broadcast RSCN */ |
| 3324 | event->portid.rscn_page_flags = 0; |
| 3325 | event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16; |
| 3326 | event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8; |
| 3327 | event->portid.rscn_fid[2] = nportid & 0x000000FF; |
| 3328 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3329 | phba->fc_stat.elsXmitRSCN++; |
| 3330 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| 3331 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 3332 | if (!elsiocb->context1) |
| 3333 | goto node_err; |
| 3334 | |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3335 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3336 | "Issue RSCN: did:x%x", |
| 3337 | ndlp->nlp_DID, 0, 0); |
| 3338 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3339 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 3340 | if (rc == IOCB_ERROR) |
| 3341 | goto io_err; |
James Smart | 8aaa7bc | 2020-10-20 13:27:17 -0700 | [diff] [blame] | 3342 | |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3343 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 3344 | * trigger the release of node. |
| 3345 | */ |
| 3346 | if (!(vport->fc_flag & FC_PT2PT)) |
| 3347 | lpfc_nlp_put(ndlp); |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3348 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3349 | io_err: |
| 3350 | lpfc_nlp_put(ndlp); |
| 3351 | node_err: |
| 3352 | lpfc_els_free_iocb(phba, elsiocb); |
| 3353 | return 1; |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3357 | * lpfc_issue_els_farpr - Issue a farp to an node on a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3358 | * @vport: pointer to a host virtual N_Port data structure. |
| 3359 | * @nportid: N_Port identifier to the remote node. |
| 3360 | * @retry: number of retries to the command IOCB. |
| 3361 | * |
| 3362 | * This routine issues a Fibre Channel Address Resolution Response |
| 3363 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 3364 | * is passed into the function. It first search the @vport node list to find |
| 3365 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 3366 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 3367 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 3368 | * |
| 3369 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3370 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3371 | * will be stored into the context1 field of the IOCB for the completion |
| 3372 | * callback function to the PARPR ELS command. |
| 3373 | * |
| 3374 | * Return code |
| 3375 | * 0 - Successfully issued farpr command |
| 3376 | * 1 - Failed to issue farpr command |
| 3377 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3378 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3379 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3380 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3381 | int rc = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3382 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3383 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3384 | FARP *fp; |
| 3385 | uint8_t *pcmd; |
| 3386 | uint32_t *lp; |
| 3387 | uint16_t cmdsize; |
| 3388 | struct lpfc_nodelist *ondlp; |
| 3389 | struct lpfc_nodelist *ndlp; |
| 3390 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3391 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3393 | ndlp = lpfc_findnode_did(vport, nportid); |
| 3394 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3395 | ndlp = lpfc_nlp_init(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3396 | if (!ndlp) |
| 3397 | return 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3398 | lpfc_enqueue_node(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3399 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3400 | |
| 3401 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 3402 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3403 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3404 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3407 | |
| 3408 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3409 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | |
| 3411 | /* Fill in FARPR payload */ |
| 3412 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3413 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3414 | lp = (uint32_t *) pcmd; |
| 3415 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3416 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | fp->Rflags = 0; |
| 3418 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 3419 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3420 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3421 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3422 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3423 | if (ondlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3425 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3426 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3427 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3428 | } |
| 3429 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3430 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3431 | "Issue FARPR: did:x%x", |
| 3432 | ndlp->nlp_DID, 0, 0); |
| 3433 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3434 | phba->fc_stat.elsXmitFARPR++; |
| 3435 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3436 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 3437 | if (!elsiocb->context1) { |
| 3438 | lpfc_els_free_iocb(phba, elsiocb); |
| 3439 | return 1; |
| 3440 | } |
| 3441 | |
| 3442 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 3443 | if (rc == IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3444 | /* The additional lpfc_nlp_put will cause the following |
| 3445 | * lpfc_els_free_iocb routine to trigger the release of |
| 3446 | * the node. |
| 3447 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3448 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3449 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3450 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3451 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3452 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 3453 | * trigger the release of the node. |
| 3454 | */ |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3455 | /* Don't release reference count as RDF is likely outstanding */ |
| 3456 | return 0; |
| 3457 | } |
| 3458 | |
| 3459 | /** |
| 3460 | * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric. |
| 3461 | * @vport: pointer to a host virtual N_Port data structure. |
| 3462 | * @retry: retry counter for the command IOCB. |
| 3463 | * |
| 3464 | * This routine issues an ELS RDF to the Fabric Controller to register |
| 3465 | * for diagnostic functions. |
| 3466 | * |
| 3467 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3468 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3469 | * will be stored into the context1 field of the IOCB for the completion |
| 3470 | * callback function to the RDF ELS command. |
| 3471 | * |
| 3472 | * Return code |
| 3473 | * 0 - Successfully issued rdf command |
| 3474 | * 1 - Failed to issue rdf command |
| 3475 | **/ |
| 3476 | int |
| 3477 | lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry) |
| 3478 | { |
| 3479 | struct lpfc_hba *phba = vport->phba; |
| 3480 | struct lpfc_iocbq *elsiocb; |
| 3481 | struct lpfc_els_rdf_req *prdf; |
| 3482 | struct lpfc_nodelist *ndlp; |
| 3483 | uint16_t cmdsize; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3484 | int rc; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3485 | |
| 3486 | cmdsize = sizeof(*prdf); |
| 3487 | |
| 3488 | ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID); |
| 3489 | if (!ndlp) { |
| 3490 | ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID); |
| 3491 | if (!ndlp) |
| 3492 | return -ENODEV; |
| 3493 | lpfc_enqueue_node(vport, ndlp); |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | /* RDF ELS is not required on an NPIV VN_Port. */ |
| 3497 | if (vport->port_type == LPFC_NPIV_PORT) { |
| 3498 | lpfc_nlp_put(ndlp); |
| 3499 | return -EACCES; |
| 3500 | } |
| 3501 | |
| 3502 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 3503 | ndlp->nlp_DID, ELS_CMD_RDF); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3504 | if (!elsiocb) |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3505 | return -ENOMEM; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3506 | |
| 3507 | /* Configure the payload for the supported FPIN events. */ |
| 3508 | prdf = (struct lpfc_els_rdf_req *) |
| 3509 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 3510 | memset(prdf, 0, cmdsize); |
| 3511 | prdf->rdf.fpin_cmd = ELS_RDF; |
| 3512 | prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) - |
| 3513 | sizeof(struct fc_els_rdf)); |
| 3514 | prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER); |
| 3515 | prdf->reg_d1.reg_desc.desc_len = cpu_to_be32( |
| 3516 | FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1)); |
| 3517 | prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT); |
| 3518 | prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY); |
James Smart | 441f6b5 | 2020-08-28 10:53:31 -0700 | [diff] [blame] | 3519 | prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY); |
| 3520 | prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST); |
| 3521 | prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION); |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3522 | |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3523 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3524 | "6444 Xmit RDF to remote NPORT x%x\n", |
| 3525 | ndlp->nlp_DID); |
| 3526 | |
| 3527 | elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3528 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 3529 | if (!elsiocb->context1) |
| 3530 | goto node_err; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3531 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3532 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3533 | "Issue RDF: did:x%x refcnt %d", |
| 3534 | ndlp->nlp_DID, kref_read(&ndlp->kref), 0); |
| 3535 | |
| 3536 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 3537 | if (rc == IOCB_ERROR) |
| 3538 | goto io_err; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3539 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 3540 | |
| 3541 | io_err: |
| 3542 | lpfc_nlp_put(ndlp); |
| 3543 | node_err: |
| 3544 | lpfc_els_free_iocb(phba, elsiocb); |
| 3545 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3546 | } |
| 3547 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3548 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3549 | * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3550 | * @vport: pointer to a host virtual N_Port data structure. |
| 3551 | * @nlp: pointer to a node-list data structure. |
| 3552 | * |
| 3553 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 3554 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 3555 | * removes the ELS retry event if it presents. In addition, if the |
| 3556 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 3557 | * commands are sent for the @vport's nodes that require issuing discovery |
| 3558 | * ADISC. |
| 3559 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3560 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3561 | lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp) |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3562 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3563 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3564 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3565 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3566 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 3567 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3568 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3569 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3570 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3571 | del_timer_sync(&nlp->nlp_delayfunc); |
| 3572 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3573 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3574 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3575 | /* Decrement nlp reference count held for the delayed retry */ |
| 3576 | evtp = &nlp->els_retry_evt; |
| 3577 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 3578 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3579 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3580 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3581 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3582 | spin_unlock_irq(shost->host_lock); |
| 3583 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3584 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3585 | /* Check if there are more ADISCs to be sent */ |
| 3586 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3587 | } else { |
| 3588 | /* Check if there are more PLOGIs to be sent */ |
| 3589 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 3590 | if (vport->num_disc_nodes == 0) { |
| 3591 | spin_lock_irq(shost->host_lock); |
| 3592 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3593 | spin_unlock_irq(shost->host_lock); |
| 3594 | lpfc_can_disctmo(vport); |
| 3595 | lpfc_end_rscn(vport); |
| 3596 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3597 | } |
| 3598 | } |
| 3599 | } |
| 3600 | return; |
| 3601 | } |
| 3602 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3603 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3604 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
Lee Jones | a0e4a64 | 2020-07-23 13:24:07 +0100 | [diff] [blame] | 3605 | * @t: pointer to the timer function associated data (ndlp). |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3606 | * |
| 3607 | * This routine is invoked by the ndlp delayed-function timer to check |
| 3608 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 3609 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 3610 | * adds the delayed events to the HBA work list and invokes the |
| 3611 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 3612 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 3613 | * the work list to hold reference count of ndlp so that it guarantees the |
| 3614 | * reference to ndlp will still be available when the worker thread gets |
| 3615 | * to the event associated with the ndlp. |
| 3616 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3617 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3618 | lpfc_els_retry_delay(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3619 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3620 | struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3621 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3622 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3623 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3624 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3625 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3626 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3627 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3628 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3629 | return; |
| 3630 | } |
| 3631 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3632 | /* We need to hold the node by incrementing the reference |
| 3633 | * count until the queued work is done |
| 3634 | */ |
| 3635 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3636 | if (evtp->evt_arg1) { |
| 3637 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 3638 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3639 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3640 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3641 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3642 | return; |
| 3643 | } |
| 3644 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3645 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3646 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3647 | * @ndlp: pointer to a node-list data structure. |
| 3648 | * |
| 3649 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 3650 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 3651 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 3652 | * function according to the delayed ELS command to retry the command. |
| 3653 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3654 | void |
| 3655 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 3656 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3657 | struct lpfc_vport *vport = ndlp->vport; |
| 3658 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3659 | uint32_t cmd, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3660 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3661 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3662 | cmd = ndlp->nlp_last_elscmd; |
| 3663 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3664 | |
| 3665 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3666 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3667 | return; |
| 3668 | } |
| 3669 | |
| 3670 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3671 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 3672 | /* |
| 3673 | * If a discovery event readded nlp_delayfunc after timer |
| 3674 | * firing and before processing the timer, cancel the |
| 3675 | * nlp_delayfunc. |
| 3676 | */ |
| 3677 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3678 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3679 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3680 | |
| 3681 | switch (cmd) { |
| 3682 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3683 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3684 | break; |
| 3685 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3686 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3687 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3688 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3689 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3690 | break; |
| 3691 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3692 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3693 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3694 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3695 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3696 | break; |
| 3697 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3698 | case ELS_CMD_NVMEPRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3699 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3700 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3701 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3702 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3703 | break; |
| 3704 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3705 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3706 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3707 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3708 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3709 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3710 | case ELS_CMD_FDISC: |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3711 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
| 3712 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3713 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3714 | } |
| 3715 | return; |
| 3716 | } |
| 3717 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3718 | /** |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 3719 | * lpfc_link_reset - Issue link reset |
| 3720 | * @vport: pointer to a virtual N_Port data structure. |
| 3721 | * |
| 3722 | * This routine performs link reset by sending INIT_LINK mailbox command. |
| 3723 | * For SLI-3 adapter, link attention interrupt is enabled before issuing |
| 3724 | * INIT_LINK mailbox command. |
| 3725 | * |
| 3726 | * Return code |
| 3727 | * 0 - Link reset initiated successfully |
| 3728 | * 1 - Failed to initiate link reset |
| 3729 | **/ |
| 3730 | int |
| 3731 | lpfc_link_reset(struct lpfc_vport *vport) |
| 3732 | { |
| 3733 | struct lpfc_hba *phba = vport->phba; |
| 3734 | LPFC_MBOXQ_t *mbox; |
| 3735 | uint32_t control; |
| 3736 | int rc; |
| 3737 | |
| 3738 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3739 | "2851 Attempt link reset\n"); |
| 3740 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3741 | if (!mbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3742 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 3743 | "2852 Failed to allocate mbox memory"); |
| 3744 | return 1; |
| 3745 | } |
| 3746 | |
| 3747 | /* Enable Link attention interrupts */ |
| 3748 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3749 | spin_lock_irq(&phba->hbalock); |
| 3750 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
| 3751 | control = readl(phba->HCregaddr); |
| 3752 | control |= HC_LAINT_ENA; |
| 3753 | writel(control, phba->HCregaddr); |
| 3754 | readl(phba->HCregaddr); /* flush */ |
| 3755 | spin_unlock_irq(&phba->hbalock); |
| 3756 | } |
| 3757 | |
| 3758 | lpfc_init_link(phba, mbox, phba->cfg_topology, |
| 3759 | phba->cfg_link_speed); |
| 3760 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3761 | mbox->vport = vport; |
| 3762 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 3763 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3764 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 3765 | "2853 Failed to issue INIT_LINK " |
| 3766 | "mbox command, rc:x%x\n", rc); |
| 3767 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3768 | return 1; |
| 3769 | } |
| 3770 | |
| 3771 | return 0; |
| 3772 | } |
| 3773 | |
| 3774 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3775 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3776 | * @phba: pointer to lpfc hba data structure. |
| 3777 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3778 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3779 | * |
| 3780 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 3781 | * failed. The following ELS IOCBs use this function for retrying the command |
| 3782 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 3783 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 3784 | * returned error status, it makes the decision whether a retry shall be |
| 3785 | * issued for the command, and whether a retry shall be made immediately or |
| 3786 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 3787 | * is called to retry the command. In the later case, the ELS command shall |
| 3788 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 3789 | * ndlp for the delayed command issusing. |
| 3790 | * |
| 3791 | * Return code |
| 3792 | * 0 - No retry of els command is made |
| 3793 | * 1 - Immediate or delayed retry of els command is made |
| 3794 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3795 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3796 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3797 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3799 | struct lpfc_vport *vport = cmdiocb->vport; |
| 3800 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3801 | IOCB_t *irsp = &rspiocb->iocb; |
| 3802 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3803 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | uint32_t *elscmd; |
| 3805 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3806 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3807 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3808 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3809 | uint32_t did; |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 3810 | int link_reset = 0, rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3811 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3812 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3813 | /* Note: context2 may be 0 for internal driver abort |
| 3814 | * of delays ELS command. |
| 3815 | */ |
| 3816 | |
| 3817 | if (pcmd && pcmd->virt) { |
| 3818 | elscmd = (uint32_t *) (pcmd->virt); |
| 3819 | cmd = *elscmd++; |
| 3820 | } |
| 3821 | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3822 | if (ndlp) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3823 | did = ndlp->nlp_DID; |
| 3824 | else { |
| 3825 | /* We should only hit this case for retrying PLOGI */ |
| 3826 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3827 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3828 | if (!ndlp && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3829 | return 1; |
| 3830 | } |
| 3831 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3832 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3833 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 3834 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 3835 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3836 | switch (irsp->ulpStatus) { |
| 3837 | case IOSTAT_FCP_RSP_ERROR: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3838 | break; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3839 | case IOSTAT_REMOTE_STOP: |
| 3840 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3841 | /* This IO was aborted by the target, we don't |
| 3842 | * know the rxid and because we did not send the |
| 3843 | * ABTS we cannot generate and RRQ. |
| 3844 | */ |
| 3845 | lpfc_set_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 3846 | cmdiocb->sli4_lxritag, 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3847 | } |
| 3848 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | case IOSTAT_LOCAL_REJECT: |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3850 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3851 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3852 | if (cmd == ELS_CMD_FLOGI) { |
| 3853 | if (PCI_DEVICE_ID_HORNET == |
| 3854 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3855 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3856 | phba->pport->fc_myDID = 0; |
| 3857 | phba->alpa_map[0] = 0; |
| 3858 | phba->alpa_map[1] = 0; |
| 3859 | } |
| 3860 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3861 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3862 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3863 | retry = 1; |
| 3864 | break; |
| 3865 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3866 | case IOERR_ILLEGAL_COMMAND: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3867 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3868 | "0124 Retry illegal cmd x%x " |
| 3869 | "retry:x%x delay:x%x\n", |
| 3870 | cmd, cmdiocb->retry, delay); |
| 3871 | retry = 1; |
| 3872 | /* All command's retry policy */ |
| 3873 | maxretry = 8; |
| 3874 | if (cmdiocb->retry > 2) |
| 3875 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3876 | break; |
| 3877 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3878 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3879 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3880 | retry = 1; |
| 3881 | if (cmdiocb->retry > 100) |
| 3882 | delay = 100; |
| 3883 | maxretry = 250; |
| 3884 | break; |
| 3885 | |
| 3886 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3887 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3888 | retry = 1; |
| 3889 | break; |
| 3890 | |
| 3891 | case IOERR_INVALID_RPI: |
James Smart | 5b5b36a | 2013-01-03 15:43:19 -0500 | [diff] [blame] | 3892 | if (cmd == ELS_CMD_PLOGI && |
| 3893 | did == NameServer_DID) { |
| 3894 | /* Continue forever if plogi to */ |
| 3895 | /* the nameserver fails */ |
| 3896 | maxretry = 0; |
| 3897 | delay = 100; |
| 3898 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | retry = 1; |
| 3900 | break; |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 3901 | |
| 3902 | case IOERR_SEQUENCE_TIMEOUT: |
| 3903 | if (cmd == ELS_CMD_PLOGI && |
| 3904 | did == NameServer_DID && |
| 3905 | (cmdiocb->retry + 1) == maxretry) { |
| 3906 | /* Reset the Link */ |
| 3907 | link_reset = 1; |
| 3908 | break; |
| 3909 | } |
| 3910 | retry = 1; |
| 3911 | delay = 100; |
| 3912 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3913 | } |
| 3914 | break; |
| 3915 | |
| 3916 | case IOSTAT_NPORT_RJT: |
| 3917 | case IOSTAT_FABRIC_RJT: |
| 3918 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 3919 | retry = 1; |
| 3920 | break; |
| 3921 | } |
| 3922 | break; |
| 3923 | |
| 3924 | case IOSTAT_NPORT_BSY: |
| 3925 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3926 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3927 | retry = 1; |
| 3928 | break; |
| 3929 | |
| 3930 | case IOSTAT_LS_RJT: |
| 3931 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 3932 | /* Added for Vendor specifc support |
| 3933 | * Just keep retrying for these Rsn / Exp codes |
| 3934 | */ |
| 3935 | switch (stat.un.b.lsRjtRsnCode) { |
| 3936 | case LSRJT_UNABLE_TPC: |
James Smart | dea37e8 | 2017-06-01 21:07:07 -0700 | [diff] [blame] | 3937 | /* The driver has a VALID PLOGI but the rport has |
| 3938 | * rejected the PRLI - can't do it now. Delay |
Dick Kennedy | 678768d | 2020-08-03 14:02:26 -0700 | [diff] [blame] | 3939 | * for 1 second and try again. |
| 3940 | * |
| 3941 | * However, if explanation is REQ_UNSUPPORTED there's |
| 3942 | * no point to retry PRLI. |
James Smart | dea37e8 | 2017-06-01 21:07:07 -0700 | [diff] [blame] | 3943 | */ |
Dick Kennedy | 678768d | 2020-08-03 14:02:26 -0700 | [diff] [blame] | 3944 | if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) && |
| 3945 | stat.un.b.lsRjtRsnCodeExp != |
| 3946 | LSEXP_REQ_UNSUPPORTED) { |
James Smart | dea37e8 | 2017-06-01 21:07:07 -0700 | [diff] [blame] | 3947 | delay = 1000; |
| 3948 | maxretry = lpfc_max_els_tries + 1; |
| 3949 | retry = 1; |
| 3950 | break; |
| 3951 | } |
| 3952 | |
| 3953 | /* Legacy bug fix code for targets with PLOGI delays. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3954 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3955 | LSEXP_CMD_IN_PROGRESS) { |
| 3956 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3957 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3958 | maxretry = 48; |
| 3959 | } |
| 3960 | retry = 1; |
| 3961 | break; |
| 3962 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3963 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3964 | LSEXP_CANT_GIVE_DATA) { |
| 3965 | if (cmd == ELS_CMD_PLOGI) { |
| 3966 | delay = 1000; |
| 3967 | maxretry = 48; |
| 3968 | } |
| 3969 | retry = 1; |
| 3970 | break; |
| 3971 | } |
James Smart | dea37e8 | 2017-06-01 21:07:07 -0700 | [diff] [blame] | 3972 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3973 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3974 | maxretry = lpfc_max_els_tries + 1; |
| 3975 | retry = 1; |
| 3976 | break; |
| 3977 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3978 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3979 | (cmd == ELS_CMD_FDISC) && |
| 3980 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3981 | lpfc_printf_vlog(vport, KERN_ERR, |
| 3982 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3983 | "0125 FDISC Failed (x%x). " |
| 3984 | "Fabric out of resources\n", |
| 3985 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3986 | lpfc_vport_set_state(vport, |
| 3987 | FC_VPORT_NO_FABRIC_RSCS); |
| 3988 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3989 | break; |
| 3990 | |
| 3991 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3992 | if ((cmd == ELS_CMD_PLOGI) || |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3993 | (cmd == ELS_CMD_PRLI) || |
| 3994 | (cmd == ELS_CMD_NVMEPRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3995 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3996 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3997 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3998 | /* FDISC retry policy */ |
| 3999 | maxretry = 48; |
| 4000 | if (cmdiocb->retry >= 32) |
| 4001 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4002 | } |
| 4003 | retry = 1; |
| 4004 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4005 | |
| 4006 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4007 | /* There are some cases where switches return this |
| 4008 | * error when they are not ready and should be returning |
| 4009 | * Logical Busy. We should delay every time. |
| 4010 | */ |
| 4011 | if (cmd == ELS_CMD_FDISC && |
| 4012 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 4013 | maxretry = 3; |
| 4014 | delay = 1000; |
| 4015 | retry = 1; |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 4016 | } else if (cmd == ELS_CMD_FLOGI && |
| 4017 | stat.un.b.lsRjtRsnCodeExp == |
| 4018 | LSEXP_NOTHING_MORE) { |
| 4019 | vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf; |
| 4020 | retry = 1; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4021 | lpfc_printf_vlog(vport, KERN_ERR, |
| 4022 | LOG_TRACE_EVENT, |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 4023 | "0820 FLOGI Failed (x%x). " |
| 4024 | "BBCredit Not Supported\n", |
| 4025 | stat.un.lsRjtError); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4026 | } |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 4027 | break; |
| 4028 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4029 | case LSRJT_PROTOCOL_ERR: |
| 4030 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 4031 | (cmd == ELS_CMD_FDISC) && |
| 4032 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 4033 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 4034 | ) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4035 | lpfc_printf_vlog(vport, KERN_ERR, |
| 4036 | LOG_TRACE_EVENT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4037 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4038 | "Fabric Detected Bad WWN\n", |
| 4039 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4040 | lpfc_vport_set_state(vport, |
| 4041 | FC_VPORT_FABRIC_REJ_WWN); |
| 4042 | } |
| 4043 | break; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4044 | case LSRJT_VENDOR_UNIQUE: |
| 4045 | if ((stat.un.b.vendorUnique == 0x45) && |
| 4046 | (cmd == ELS_CMD_FLOGI)) { |
| 4047 | goto out_retry; |
| 4048 | } |
| 4049 | break; |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 4050 | case LSRJT_CMD_UNSUPPORTED: |
| 4051 | /* lpfc nvmet returns this type of LS_RJT when it |
| 4052 | * receives an FCP PRLI because lpfc nvmet only |
| 4053 | * support NVME. ELS request is terminated for FCP4 |
| 4054 | * on this rport. |
| 4055 | */ |
| 4056 | if (stat.un.b.lsRjtRsnCodeExp == |
| 4057 | LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) { |
| 4058 | spin_lock_irq(shost->host_lock); |
| 4059 | ndlp->nlp_flag |= NLP_FCP_PRLI_RJT; |
| 4060 | spin_unlock_irq(shost->host_lock); |
| 4061 | retry = 0; |
| 4062 | goto out_retry; |
| 4063 | } |
| 4064 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4065 | } |
| 4066 | break; |
| 4067 | |
| 4068 | case IOSTAT_INTERMED_RSP: |
| 4069 | case IOSTAT_BA_RJT: |
| 4070 | break; |
| 4071 | |
| 4072 | default: |
| 4073 | break; |
| 4074 | } |
| 4075 | |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 4076 | if (link_reset) { |
| 4077 | rc = lpfc_link_reset(vport); |
| 4078 | if (rc) { |
| 4079 | /* Do not give up. Retry PLOGI one more time and attempt |
| 4080 | * link reset if PLOGI fails again. |
| 4081 | */ |
| 4082 | retry = 1; |
| 4083 | delay = 100; |
| 4084 | goto out_retry; |
| 4085 | } |
| 4086 | return 1; |
| 4087 | } |
| 4088 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4089 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4090 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4091 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4092 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4093 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 4094 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4095 | /* FLOGI retry policy */ |
| 4096 | retry = 1; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4097 | /* retry FLOGI forever */ |
James Smart | 6eae430 | 2015-04-07 15:07:23 -0400 | [diff] [blame] | 4098 | if (phba->link_flag != LS_LOOPBACK_MODE) |
| 4099 | maxretry = 0; |
| 4100 | else |
| 4101 | maxretry = 2; |
| 4102 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4103 | if (cmdiocb->retry >= 100) |
| 4104 | delay = 5000; |
| 4105 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4106 | delay = 1000; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4107 | } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) { |
| 4108 | /* retry FDISCs every second up to devloss */ |
| 4109 | retry = 1; |
| 4110 | maxretry = vport->cfg_devloss_tmo; |
| 4111 | delay = 1000; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4112 | } |
| 4113 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4114 | cmdiocb->retry++; |
| 4115 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4116 | phba->fc_stat.elsRetryExceeded++; |
| 4117 | retry = 0; |
| 4118 | } |
| 4119 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4120 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 4121 | retry = 0; |
| 4122 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4123 | out_retry: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4124 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4125 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 4126 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 4127 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 4128 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4129 | "2849 Stop retry ELS command " |
| 4130 | "x%x to remote NPORT x%x, " |
| 4131 | "Data: x%x x%x\n", cmd, did, |
| 4132 | cmdiocb->retry, delay); |
| 4133 | return 0; |
| 4134 | } |
| 4135 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4136 | |
| 4137 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4138 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4139 | "0107 Retry ELS command x%x to remote " |
| 4140 | "NPORT x%x Data: x%x x%x\n", |
| 4141 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4142 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4143 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 4144 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 4145 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 4146 | IOERR_NO_RESOURCES))) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4147 | /* Don't reset timer for no resources */ |
| 4148 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4149 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4150 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4151 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4152 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | phba->fc_stat.elsXmitRetry++; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4156 | if (ndlp && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4157 | phba->fc_stat.elsDelayRetry++; |
| 4158 | ndlp->nlp_retry = cmdiocb->retry; |
| 4159 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4160 | /* delay is specified in milliseconds */ |
| 4161 | mod_timer(&ndlp->nlp_delayfunc, |
| 4162 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4163 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4164 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4165 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4166 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4167 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4168 | if ((cmd == ELS_CMD_PRLI) || |
| 4169 | (cmd == ELS_CMD_NVMEPRLI)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4170 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 4171 | NLP_STE_PRLI_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4172 | else |
| 4173 | lpfc_nlp_set_state(vport, ndlp, |
| 4174 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | ndlp->nlp_last_elscmd = cmd; |
| 4176 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4177 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4178 | } |
| 4179 | switch (cmd) { |
| 4180 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4181 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4182 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4183 | case ELS_CMD_FDISC: |
| 4184 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 4185 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4186 | case ELS_CMD_PLOGI: |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4187 | if (ndlp) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4188 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4189 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4190 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4191 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4192 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4193 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4194 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4195 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4196 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4197 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4198 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4199 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4200 | case ELS_CMD_NVMEPRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4201 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4202 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 4203 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4204 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4205 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4206 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4207 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4208 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4209 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4210 | } |
| 4211 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4212 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4213 | if (logerr) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4214 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4215 | "0137 No retry ELS command x%x to remote " |
| 4216 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 4217 | cmd, did, irsp->ulpStatus, |
| 4218 | irsp->un.ulpWord[4]); |
| 4219 | } |
| 4220 | else { |
| 4221 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4222 | "0108 No retry ELS command x%x to remote " |
| 4223 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 4224 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 4225 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4226 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4227 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4228 | } |
| 4229 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4230 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4231 | * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4232 | * @phba: pointer to lpfc hba data structure. |
| 4233 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 4234 | * |
| 4235 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 4236 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 4237 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 4238 | * response of the command IOCB. If so, it will be released before releasing |
| 4239 | * the lpfc DMA buffer associated with the IOCB itself. |
| 4240 | * |
| 4241 | * Return code |
| 4242 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 4243 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4244 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4245 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 4246 | { |
| 4247 | struct lpfc_dmabuf *buf_ptr; |
| 4248 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4249 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4250 | if (!list_empty(&buf_ptr1->list)) { |
| 4251 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 4252 | struct lpfc_dmabuf, |
| 4253 | list); |
| 4254 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 4255 | kfree(buf_ptr); |
| 4256 | } |
| 4257 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 4258 | kfree(buf_ptr1); |
| 4259 | return 0; |
| 4260 | } |
| 4261 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4262 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4263 | * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4264 | * @phba: pointer to lpfc hba data structure. |
| 4265 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 4266 | * |
| 4267 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 4268 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 4269 | * pool. |
| 4270 | * |
| 4271 | * Return code |
| 4272 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 4273 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4274 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4275 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 4276 | { |
| 4277 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 4278 | kfree(buf_ptr); |
| 4279 | return 0; |
| 4280 | } |
| 4281 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4282 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4283 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4284 | * @phba: pointer to lpfc hba data structure. |
| 4285 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 4286 | * |
| 4287 | * This routine frees a command IOCB and its associated resources. The |
| 4288 | * command IOCB data structure contains the reference to various associated |
| 4289 | * resources, these fields must be set to NULL if the associated reference |
| 4290 | * not present: |
| 4291 | * context1 - reference to ndlp |
| 4292 | * context2 - reference to cmd |
| 4293 | * context2->next - reference to rsp |
| 4294 | * context3 - reference to bpl |
| 4295 | * |
| 4296 | * It first properly decrements the reference count held on ndlp for the |
| 4297 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 4298 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 4299 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 4300 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 4301 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 4302 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 4303 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 4304 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 4305 | * |
| 4306 | * Return code |
| 4307 | * 0 - Success (currently, always return 0) |
| 4308 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4309 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4310 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | { |
| 4312 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
| 4313 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4314 | /* The I/O job is complete. Clear the context1 data. */ |
| 4315 | elsiocb->context1 = NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4316 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4317 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 4318 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4319 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 4320 | /* Firmware could still be in progress of DMAing |
| 4321 | * payload, so don't free data buffer till after |
| 4322 | * a hbeat. |
| 4323 | */ |
| 4324 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 4325 | buf_ptr = elsiocb->context2; |
| 4326 | elsiocb->context2 = NULL; |
| 4327 | if (buf_ptr) { |
| 4328 | buf_ptr1 = NULL; |
| 4329 | spin_lock_irq(&phba->hbalock); |
| 4330 | if (!list_empty(&buf_ptr->list)) { |
| 4331 | list_remove_head(&buf_ptr->list, |
| 4332 | buf_ptr1, struct lpfc_dmabuf, |
| 4333 | list); |
| 4334 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 4335 | list_add_tail(&buf_ptr1->list, |
| 4336 | &phba->elsbuf); |
| 4337 | phba->elsbuf_cnt++; |
| 4338 | } |
| 4339 | INIT_LIST_HEAD(&buf_ptr->list); |
| 4340 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 4341 | phba->elsbuf_cnt++; |
| 4342 | spin_unlock_irq(&phba->hbalock); |
| 4343 | } |
| 4344 | } else { |
| 4345 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 4346 | lpfc_els_free_data(phba, buf_ptr1); |
Johannes Thumshirn | 8667f51 | 2017-01-10 12:05:54 +0100 | [diff] [blame] | 4347 | elsiocb->context2 = NULL; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4348 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | if (elsiocb->context3) { |
| 4352 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4353 | lpfc_els_free_bpl(phba, buf_ptr); |
Johannes Thumshirn | 8667f51 | 2017-01-10 12:05:54 +0100 | [diff] [blame] | 4354 | elsiocb->context3 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4355 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4356 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4357 | return 0; |
| 4358 | } |
| 4359 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4360 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4361 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4362 | * @phba: pointer to lpfc hba data structure. |
| 4363 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4364 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 4365 | * |
| 4366 | * This routine is the completion callback function to the Logout (LOGO) |
| 4367 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 4368 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 4369 | * release the ndlp if it has the last reference remaining (reference count |
| 4370 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 4371 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 4372 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 4373 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 4374 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 4375 | * IOCB data structure. |
| 4376 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4377 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4378 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4379 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4380 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4381 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 4382 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4383 | IOCB_t *irsp; |
| 4384 | |
| 4385 | irsp = &rspiocb->iocb; |
| 4386 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4387 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 4388 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4389 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4390 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4391 | "0109 ACC to LOGO completes to NPort x%x " |
| 4392 | "Data: x%x x%x x%x\n", |
| 4393 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4394 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4395 | |
| 4396 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 4397 | /* NPort Recovery mode or node is just allocated */ |
| 4398 | if (!lpfc_nlp_not_used(ndlp)) { |
| 4399 | /* If the ndlp is being used by another discovery |
| 4400 | * thread, just unregister the RPI. |
| 4401 | */ |
| 4402 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4403 | } else { |
| 4404 | /* Indicate the node has already released, should |
| 4405 | * not reference to it from within lpfc_els_free_iocb. |
| 4406 | */ |
| 4407 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4408 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4409 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4410 | |
| 4411 | /* |
| 4412 | * The driver received a LOGO from the rport and has ACK'd it. |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4413 | * At this point, the driver is done so release the IOCB |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4414 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4415 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4416 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4417 | } |
| 4418 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4419 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4420 | * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4421 | * @phba: pointer to lpfc hba data structure. |
| 4422 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4423 | * |
| 4424 | * This routine is the completion callback function for unregister default |
| 4425 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 4426 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 4427 | * decrements the ndlp reference count held for this completion callback |
| 4428 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 4429 | * whether there is only one reference left on the ndlp. If so, it will |
| 4430 | * perform one more decrement and trigger the release of the ndlp. |
| 4431 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4432 | void |
| 4433 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4434 | { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4435 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 4436 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4437 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4438 | pmb->ctx_buf = NULL; |
| 4439 | pmb->ctx_ndlp = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4440 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4441 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4442 | kfree(mp); |
| 4443 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4444 | if (ndlp) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4445 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4446 | "0006 rpi%x DID:%x flg:%x %d x%px\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4447 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4448 | kref_read(&ndlp->kref), |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4449 | ndlp); |
| 4450 | lpfc_nlp_put(ndlp); |
| 4451 | /* This is the end of the default RPI cleanup logic for |
| 4452 | * this ndlp. If no other discovery threads are using |
| 4453 | * this ndlp, free all resources associated with it. |
| 4454 | */ |
| 4455 | lpfc_nlp_not_used(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4456 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4457 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4458 | return; |
| 4459 | } |
| 4460 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4461 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4462 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4463 | * @phba: pointer to lpfc hba data structure. |
| 4464 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4465 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 4466 | * |
| 4467 | * This routine is the completion callback function for ELS Response IOCB |
| 4468 | * command. In normal case, this callback function just properly sets the |
| 4469 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 4470 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 4471 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 4472 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 4473 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 4474 | * routine shall be invoked trying to release the ndlp if no other threads |
| 4475 | * are currently referring it. |
| 4476 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4477 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4478 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4479 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4480 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4481 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 4482 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 4483 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4484 | IOCB_t *irsp; |
| 4485 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4486 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4487 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4488 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4489 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 4490 | irsp = &rspiocb->iocb; |
| 4491 | |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 4492 | if (!vport) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4493 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | f84f8f9 | 2019-10-18 14:18:23 -0700 | [diff] [blame] | 4494 | "3177 ELS response failed\n"); |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 4495 | goto out; |
| 4496 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4497 | if (cmdiocb->context_un.mbox) |
| 4498 | mbox = cmdiocb->context_un.mbox; |
| 4499 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4500 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 4501 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 4502 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4503 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4504 | if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4505 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 4506 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4507 | */ |
| 4508 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 4509 | ls_rjt = 1; |
| 4510 | } |
| 4511 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4512 | /* Check to see if link went down during discovery */ |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4513 | if (!ndlp || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4514 | if (mbox) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4515 | mp = (struct lpfc_dmabuf *)mbox->ctx_buf; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 4516 | if (mp) { |
| 4517 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4518 | kfree(mp); |
| 4519 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4520 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4521 | } |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4522 | if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4523 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4524 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4525 | /* Indicate the node has already released, |
| 4526 | * should not reference to it from within |
| 4527 | * the routine lpfc_els_free_iocb. |
| 4528 | */ |
| 4529 | cmdiocb->context1 = NULL; |
| 4530 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4531 | goto out; |
| 4532 | } |
| 4533 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4534 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4535 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4536 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4537 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4538 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4539 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4540 | "0110 ELS response tag x%x completes " |
| 4541 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 4542 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 4543 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 4544 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4545 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4546 | if (mbox) { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4547 | if ((rspiocb->iocb.ulpStatus == 0) && |
| 4548 | (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
Dick Kennedy | 1fe6847 | 2017-08-23 16:55:30 -0700 | [diff] [blame] | 4549 | if (!lpfc_unreg_rpi(vport, ndlp) && |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4550 | (!(vport->fc_flag & FC_PT2PT))) { |
| 4551 | if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) { |
| 4552 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4553 | LOG_DISCOVERY, |
| 4554 | "0314 PLOGI recov " |
| 4555 | "DID x%x " |
| 4556 | "Data: x%x x%x x%x\n", |
| 4557 | ndlp->nlp_DID, |
| 4558 | ndlp->nlp_state, |
| 4559 | ndlp->nlp_rpi, |
| 4560 | ndlp->nlp_flag); |
| 4561 | mp = mbox->ctx_buf; |
| 4562 | if (mp) { |
| 4563 | lpfc_mbuf_free(phba, mp->virt, |
| 4564 | mp->phys); |
| 4565 | kfree(mp); |
| 4566 | } |
| 4567 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4568 | goto out; |
Dick Kennedy | 1fe6847 | 2017-08-23 16:55:30 -0700 | [diff] [blame] | 4569 | } |
Dick Kennedy | 1fe6847 | 2017-08-23 16:55:30 -0700 | [diff] [blame] | 4570 | } |
| 4571 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4572 | /* Increment reference count to ndlp to hold the |
| 4573 | * reference to ndlp for the callback function. |
| 4574 | */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4575 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4576 | if (!mbox->ctx_ndlp) |
| 4577 | goto out; |
| 4578 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4579 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4580 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 4581 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 4582 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 4583 | } |
| 4584 | else { |
| 4585 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 4586 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 4587 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4588 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4589 | } |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 4590 | |
| 4591 | ndlp->nlp_flag |= NLP_REG_LOGIN_SEND; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4592 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4593 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4594 | goto out; |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 4595 | |
| 4596 | /* Decrement the ndlp reference count we |
| 4597 | * set for this failed mailbox command. |
| 4598 | */ |
| 4599 | lpfc_nlp_put(ndlp); |
| 4600 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4601 | |
| 4602 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4603 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4604 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 4605 | "Data: x%x x%x x%x\n", |
| 4606 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4607 | ndlp->nlp_rpi); |
| 4608 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4609 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4610 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4611 | /* Indicate node has already been released, |
| 4612 | * should not reference to it from within |
| 4613 | * the routine lpfc_els_free_iocb. |
| 4614 | */ |
| 4615 | cmdiocb->context1 = NULL; |
| 4616 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4617 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4618 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 4619 | if (!lpfc_error_lost_link(irsp) && |
| 4620 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4621 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4622 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4623 | /* Indicate node has already been |
| 4624 | * released, should not reference |
| 4625 | * to it from within the routine |
| 4626 | * lpfc_els_free_iocb. |
| 4627 | */ |
| 4628 | cmdiocb->context1 = NULL; |
| 4629 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4630 | } |
| 4631 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4632 | mp = (struct lpfc_dmabuf *)mbox->ctx_buf; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 4633 | if (mp) { |
| 4634 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4635 | kfree(mp); |
| 4636 | } |
| 4637 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4638 | } |
| 4639 | out: |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4640 | if (ndlp && shost) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4641 | spin_lock_irq(shost->host_lock); |
James Smart | 7b08e89 | 2020-08-28 10:53:30 -0700 | [diff] [blame] | 4642 | if (mbox) |
| 4643 | ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN; |
| 4644 | ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4645 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4646 | |
| 4647 | /* If the node is not being used by another discovery thread, |
| 4648 | * and we are sending a reject, we are done with it. |
| 4649 | * Release driver reference count here and free associated |
| 4650 | * resources. |
| 4651 | */ |
| 4652 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4653 | if (lpfc_nlp_not_used(ndlp)) |
| 4654 | /* Indicate node has already been released, |
| 4655 | * should not reference to it from within |
| 4656 | * the routine lpfc_els_free_iocb. |
| 4657 | */ |
| 4658 | cmdiocb->context1 = NULL; |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 4659 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4660 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4661 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4662 | /* Release the originating I/O reference. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4663 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4664 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4665 | return; |
| 4666 | } |
| 4667 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4668 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4669 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4670 | * @vport: pointer to a host virtual N_Port data structure. |
| 4671 | * @flag: the els command code to be accepted. |
| 4672 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4673 | * @ndlp: pointer to a node-list data structure. |
| 4674 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4675 | * |
| 4676 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 4677 | * command. It uses the @flag to properly set up the IOCB field for the |
| 4678 | * specific ACC response command to be issued and invokes the |
| 4679 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 4680 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 4681 | * field of the IOCB for the completion callback function to issue the |
| 4682 | * mailbox command to the HBA later when callback is invoked. |
| 4683 | * |
| 4684 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4685 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4686 | * will be stored into the context1 field of the IOCB for the completion |
| 4687 | * callback function to the corresponding response ELS IOCB command. |
| 4688 | * |
| 4689 | * Return code |
| 4690 | * 0 - Successfully issued acc response |
| 4691 | * 1 - Failed to issue acc response |
| 4692 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4693 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4694 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 4695 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4696 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4697 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4698 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4699 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4700 | IOCB_t *icmd; |
| 4701 | IOCB_t *oldcmd; |
| 4702 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4703 | uint8_t *pcmd; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4704 | struct serv_parm *sp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4705 | uint16_t cmdsize; |
| 4706 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4707 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4708 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4709 | oldcmd = &oldiocb->iocb; |
| 4710 | |
| 4711 | switch (flag) { |
| 4712 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4713 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4714 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 4715 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4716 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4717 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4718 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4719 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4720 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4721 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4722 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4723 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4724 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4725 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4726 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4727 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4728 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4729 | |
| 4730 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4731 | "Issue ACC: did:x%x flg:x%x", |
| 4732 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4733 | break; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4734 | case ELS_CMD_FLOGI: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4735 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4736 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4737 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 4738 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4739 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4740 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4741 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4742 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4743 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4744 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4745 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4746 | |
| 4747 | if (mbox) |
| 4748 | elsiocb->context_un.mbox = mbox; |
| 4749 | |
| 4750 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4751 | pcmd += sizeof(uint32_t); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4752 | sp = (struct serv_parm *)pcmd; |
| 4753 | |
| 4754 | if (flag == ELS_CMD_FLOGI) { |
| 4755 | /* Copy the received service parameters back */ |
| 4756 | memcpy(sp, &phba->fc_fabparam, |
| 4757 | sizeof(struct serv_parm)); |
| 4758 | |
| 4759 | /* Clear the F_Port bit */ |
| 4760 | sp->cmn.fPort = 0; |
| 4761 | |
| 4762 | /* Mark all class service parameters as invalid */ |
| 4763 | sp->cls1.classValid = 0; |
| 4764 | sp->cls2.classValid = 0; |
| 4765 | sp->cls3.classValid = 0; |
| 4766 | sp->cls4.classValid = 0; |
| 4767 | |
| 4768 | /* Copy our worldwide names */ |
| 4769 | memcpy(&sp->portName, &vport->fc_sparam.portName, |
| 4770 | sizeof(struct lpfc_name)); |
| 4771 | memcpy(&sp->nodeName, &vport->fc_sparam.nodeName, |
| 4772 | sizeof(struct lpfc_name)); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4773 | } else { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4774 | memcpy(pcmd, &vport->fc_sparam, |
| 4775 | sizeof(struct serv_parm)); |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 4776 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4777 | sp->cmn.valid_vendor_ver_level = 0; |
| 4778 | memset(sp->un.vendorVersion, 0, |
| 4779 | sizeof(sp->un.vendorVersion)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 4780 | sp->cmn.bbRcvSizeMsb &= 0xF; |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4781 | |
| 4782 | /* If our firmware supports this feature, convey that |
| 4783 | * info to the target using the vendor specific field. |
| 4784 | */ |
| 4785 | if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { |
| 4786 | sp->cmn.valid_vendor_ver_level = 1; |
| 4787 | sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); |
| 4788 | sp->un.vv.flags = |
| 4789 | cpu_to_be32(LPFC_VV_SUPPRESS_RSP); |
| 4790 | } |
| 4791 | } |
| 4792 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4793 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4794 | "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4795 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4796 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4797 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4798 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4799 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4800 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 4801 | if (!elsiocb) |
| 4802 | return 1; |
| 4803 | |
| 4804 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4805 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4806 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4807 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4808 | |
| 4809 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4810 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4811 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 4812 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 4813 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4814 | |
| 4815 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4816 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 4817 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4818 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4819 | default: |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4820 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4821 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4822 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4823 | spin_lock_irq(shost->host_lock); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4824 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4825 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND)) |
| 4826 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4827 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4828 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 4829 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4830 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4831 | } |
| 4832 | |
| 4833 | phba->fc_stat.elsXmitACC++; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4834 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 4835 | if (!elsiocb->context1) |
| 4836 | goto node_err; |
| 4837 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4838 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4839 | if (rc == IOCB_ERROR) |
| 4840 | goto io_err; |
| 4841 | |
| 4842 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
| 4843 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4844 | "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, " |
| 4845 | "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x " |
| 4846 | "RPI: x%x, fc_flag x%x\n", |
| 4847 | rc, elsiocb->iotag, elsiocb->sli4_xritag, |
| 4848 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4849 | ndlp->nlp_rpi, vport->fc_flag); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4850 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4851 | |
| 4852 | io_err: |
| 4853 | lpfc_nlp_put(ndlp); |
| 4854 | node_err: |
| 4855 | lpfc_els_free_iocb(phba, elsiocb); |
| 4856 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4857 | } |
| 4858 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4859 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4860 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4861 | * @vport: pointer to a virtual N_Port data structure. |
Lee Jones | a0e4a64 | 2020-07-23 13:24:07 +0100 | [diff] [blame] | 4862 | * @rejectError: reject response to issue |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4863 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4864 | * @ndlp: pointer to a node-list data structure. |
| 4865 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4866 | * |
| 4867 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 4868 | * command. If a @mbox pointer is passed in, it will be put into the |
| 4869 | * context_un.mbox field of the IOCB for the completion callback function |
| 4870 | * to issue to the HBA later. |
| 4871 | * |
| 4872 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4873 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4874 | * will be stored into the context1 field of the IOCB for the completion |
| 4875 | * callback function to the reject response ELS IOCB command. |
| 4876 | * |
| 4877 | * Return code |
| 4878 | * 0 - Successfully issued reject response |
| 4879 | * 1 - Failed to issue reject response |
| 4880 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4881 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4882 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4883 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 4884 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4885 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4886 | int rc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4887 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4888 | IOCB_t *icmd; |
| 4889 | IOCB_t *oldcmd; |
| 4890 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4891 | uint8_t *pcmd; |
| 4892 | uint16_t cmdsize; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4893 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4894 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4895 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4896 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4897 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4898 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4899 | |
| 4900 | icmd = &elsiocb->iocb; |
| 4901 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4902 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4903 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4904 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4905 | |
| 4906 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4907 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4908 | *((uint32_t *) (pcmd)) = rejectError; |
| 4909 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4910 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4911 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4912 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4913 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4914 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4915 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 4916 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4917 | "rpi x%x\n", |
| 4918 | rejectError, elsiocb->iotag, |
| 4919 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 4920 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4921 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4922 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 4923 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 4924 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4925 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4926 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4927 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 4928 | if (!elsiocb->context1) |
| 4929 | goto node_err; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4930 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4931 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4932 | if (rc == IOCB_ERROR) |
| 4933 | goto io_err; |
| 4934 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4935 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 4936 | |
| 4937 | io_err: |
| 4938 | lpfc_nlp_put(ndlp); |
| 4939 | node_err: |
| 4940 | lpfc_els_free_iocb(phba, elsiocb); |
| 4941 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4942 | } |
| 4943 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4944 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4945 | * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4946 | * @vport: pointer to a virtual N_Port data structure. |
| 4947 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4948 | * @ndlp: pointer to a node-list data structure. |
| 4949 | * |
| 4950 | * This routine prepares and issues an Accept (ACC) response to Address |
| 4951 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 4952 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4953 | * |
| 4954 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4955 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4956 | * will be stored into the context1 field of the IOCB for the completion |
| 4957 | * callback function to the ADISC Accept response ELS IOCB command. |
| 4958 | * |
| 4959 | * Return code |
| 4960 | * 0 - Successfully issued acc adisc response |
| 4961 | * 1 - Failed to issue adisc acc response |
| 4962 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4963 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4964 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 4965 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4966 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4967 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4968 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4969 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4970 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4971 | uint8_t *pcmd; |
| 4972 | uint16_t cmdsize; |
| 4973 | int rc; |
| 4974 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4975 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4976 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4977 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4978 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4979 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4980 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4981 | icmd = &elsiocb->iocb; |
| 4982 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4983 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4984 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4985 | |
| 4986 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4987 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4988 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 4989 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 4990 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4991 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4992 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4993 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4994 | |
| 4995 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4996 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4997 | |
| 4998 | ap = (ADISC *) (pcmd); |
| 4999 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5000 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5001 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5002 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5003 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5004 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5005 | "Issue ACC ADISC: did:x%x flg:x%x refcnt %d", |
| 5006 | ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5007 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5008 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5009 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5010 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 5011 | if (!elsiocb->context1) |
| 5012 | goto node_err; |
| 5013 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5014 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5015 | if (rc == IOCB_ERROR) |
| 5016 | goto io_err; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 5017 | |
| 5018 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
| 5019 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5020 | "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, " |
| 5021 | "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x " |
| 5022 | "RPI: x%x, fc_flag x%x\n", |
| 5023 | rc, elsiocb->iotag, elsiocb->sli4_xritag, |
| 5024 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5025 | ndlp->nlp_rpi, vport->fc_flag); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5026 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5027 | |
| 5028 | io_err: |
| 5029 | lpfc_nlp_put(ndlp); |
| 5030 | node_err: |
| 5031 | lpfc_els_free_iocb(phba, elsiocb); |
| 5032 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5033 | } |
| 5034 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5035 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5036 | * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5037 | * @vport: pointer to a virtual N_Port data structure. |
| 5038 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5039 | * @ndlp: pointer to a node-list data structure. |
| 5040 | * |
| 5041 | * This routine prepares and issues an Accept (ACC) response to Process |
| 5042 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 5043 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 5044 | * |
| 5045 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5046 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5047 | * will be stored into the context1 field of the IOCB for the completion |
| 5048 | * callback function to the PRLI Accept response ELS IOCB command. |
| 5049 | * |
| 5050 | * Return code |
| 5051 | * 0 - Successfully issued acc prli response |
| 5052 | * 1 - Failed to issue acc prli response |
| 5053 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5054 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5055 | lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5056 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5057 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5058 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5059 | PRLI *npr; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5060 | struct lpfc_nvme_prli *npr_nvme; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5061 | lpfc_vpd_t *vpd; |
| 5062 | IOCB_t *icmd; |
| 5063 | IOCB_t *oldcmd; |
| 5064 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5065 | uint8_t *pcmd; |
| 5066 | uint16_t cmdsize; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5067 | uint32_t prli_fc4_req, *req_payload; |
| 5068 | struct lpfc_dmabuf *req_buf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5069 | int rc; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5070 | u32 elsrspcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5071 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5072 | /* Need the incoming PRLI payload to determine if the ACC is for an |
| 5073 | * FC4 or NVME PRLI type. The PRLI type is at word 1. |
| 5074 | */ |
| 5075 | req_buf = (struct lpfc_dmabuf *)oldiocb->context2; |
| 5076 | req_payload = (((uint32_t *)req_buf->virt) + 1); |
| 5077 | |
| 5078 | /* PRLI type payload is at byte 3 for FCP or NVME. */ |
| 5079 | prli_fc4_req = be32_to_cpu(*req_payload); |
| 5080 | prli_fc4_req = (prli_fc4_req >> 24) & 0xff; |
| 5081 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5082 | "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n", |
| 5083 | prli_fc4_req, *((uint32_t *)req_payload)); |
| 5084 | |
| 5085 | if (prli_fc4_req == PRLI_FCP_TYPE) { |
| 5086 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
| 5087 | elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
| 5088 | } else if (prli_fc4_req & PRLI_NVME_TYPE) { |
| 5089 | cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli); |
| 5090 | elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK)); |
| 5091 | } else { |
| 5092 | return 1; |
| 5093 | } |
| 5094 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5095 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5096 | ndlp->nlp_DID, elsrspcmd); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5097 | if (!elsiocb) |
| 5098 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5099 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5100 | icmd = &elsiocb->iocb; |
| 5101 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5102 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 5103 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 5104 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5105 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5106 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5107 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 5108 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 5109 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5110 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5111 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5112 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5113 | memset(pcmd, 0, cmdsize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5114 | |
James Smart | c07f10c | 2017-04-21 16:04:54 -0700 | [diff] [blame] | 5115 | *((uint32_t *)(pcmd)) = elsrspcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5116 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5117 | |
| 5118 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5119 | vpd = &phba->vpd; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5120 | |
| 5121 | if (prli_fc4_req == PRLI_FCP_TYPE) { |
| 5122 | /* |
| 5123 | * If the remote port is a target and our firmware version |
| 5124 | * is 3.20 or later, set the following bits for FC-TAPE |
| 5125 | * support. |
| 5126 | */ |
| 5127 | npr = (PRLI *) pcmd; |
| 5128 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 5129 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| 5130 | npr->ConfmComplAllowed = 1; |
| 5131 | npr->Retry = 1; |
| 5132 | npr->TaskRetryIdReq = 1; |
| 5133 | } |
| 5134 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 5135 | npr->estabImagePair = 1; |
| 5136 | npr->readXferRdyDis = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5137 | npr->ConfmComplAllowed = 1; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5138 | npr->prliType = PRLI_FCP_TYPE; |
| 5139 | npr->initiatorFunc = 1; |
| 5140 | } else if (prli_fc4_req & PRLI_NVME_TYPE) { |
| 5141 | /* Respond with an NVME PRLI Type */ |
| 5142 | npr_nvme = (struct lpfc_nvme_prli *) pcmd; |
| 5143 | bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); |
| 5144 | bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ |
| 5145 | bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5146 | if (phba->nvmet_support) { |
| 5147 | bf_set(prli_tgt, npr_nvme, 1); |
| 5148 | bf_set(prli_disc, npr_nvme, 1); |
| 5149 | if (phba->cfg_nvme_enable_fb) { |
| 5150 | bf_set(prli_fba, npr_nvme, 1); |
| 5151 | |
| 5152 | /* TBD. Target mode needs to post buffers |
| 5153 | * that support the configured first burst |
| 5154 | * byte size. |
| 5155 | */ |
| 5156 | bf_set(prli_fb_sz, npr_nvme, |
| 5157 | phba->cfg_nvmet_fb_size); |
| 5158 | } |
| 5159 | } else { |
| 5160 | bf_set(prli_init, npr_nvme, 1); |
| 5161 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5162 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5163 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, |
| 5164 | "6015 NVME issue PRLI ACC word1 x%08x " |
| 5165 | "word4 x%08x word5 x%08x flag x%x, " |
| 5166 | "fcp_info x%x nlp_type x%x\n", |
| 5167 | npr_nvme->word1, npr_nvme->word4, |
| 5168 | npr_nvme->word5, ndlp->nlp_flag, |
| 5169 | ndlp->nlp_fcp_info, ndlp->nlp_type); |
| 5170 | npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); |
| 5171 | npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); |
| 5172 | npr_nvme->word5 = cpu_to_be32(npr_nvme->word5); |
| 5173 | } else |
| 5174 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5175 | "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n", |
| 5176 | prli_fc4_req, ndlp->nlp_fc4_type, |
| 5177 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5178 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5179 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5180 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 5181 | ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5182 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5183 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5184 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5185 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 5186 | if (!elsiocb->context1) |
| 5187 | goto node_err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5188 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5189 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5190 | if (rc == IOCB_ERROR) |
| 5191 | goto io_err; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5192 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5193 | |
| 5194 | io_err: |
| 5195 | lpfc_nlp_put(ndlp); |
| 5196 | node_err: |
| 5197 | lpfc_els_free_iocb(phba, elsiocb); |
| 5198 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5199 | } |
| 5200 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5201 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5202 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5203 | * @vport: pointer to a virtual N_Port data structure. |
| 5204 | * @format: rnid command format. |
| 5205 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5206 | * @ndlp: pointer to a node-list data structure. |
| 5207 | * |
| 5208 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 5209 | * (ACC) response. It constructs the RNID ACC response command according to |
| 5210 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 5211 | * issue the response. Note that this command does not need to hold the ndlp |
| 5212 | * reference count for the callback. So, the ndlp reference count taken by |
| 5213 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 5214 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 5215 | * there is no ndlp reference available. |
| 5216 | * |
| 5217 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5218 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5219 | * will be stored into the context1 field of the IOCB for the completion |
| 5220 | * callback function. However, for the RNID Accept Response ELS command, |
| 5221 | * this is undone later by this routine after the IOCB is allocated. |
| 5222 | * |
| 5223 | * Return code |
| 5224 | * 0 - Successfully issued acc rnid response |
| 5225 | * 1 - Failed to issue acc rnid response |
| 5226 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5227 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5228 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5229 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5230 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5231 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5232 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5233 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5234 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5235 | uint8_t *pcmd; |
| 5236 | uint16_t cmdsize; |
| 5237 | int rc; |
| 5238 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5239 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 5240 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5241 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5242 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5243 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5244 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5245 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5246 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5247 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5248 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5249 | icmd = &elsiocb->iocb; |
| 5250 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5251 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 5252 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 5253 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5254 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5255 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5256 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 5257 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5258 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5259 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5260 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5261 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5262 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5263 | rn = (RNID *) (pcmd); |
| 5264 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5265 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 5266 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5267 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5268 | switch (format) { |
| 5269 | case 0: |
| 5270 | rn->SpecificLen = 0; |
| 5271 | break; |
| 5272 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5273 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5274 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5275 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5276 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 5277 | rn->un.topologyDisc.physPort = 0; |
| 5278 | rn->un.topologyDisc.attachedNodes = 0; |
| 5279 | break; |
| 5280 | default: |
| 5281 | rn->CommonLen = 0; |
| 5282 | rn->SpecificLen = 0; |
| 5283 | break; |
| 5284 | } |
| 5285 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5286 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5287 | "Issue ACC RNID: did:x%x flg:x%x refcnt %d", |
| 5288 | ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5289 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5290 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5291 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5292 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 5293 | if (!elsiocb->context1) |
| 5294 | goto node_err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5295 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5296 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5297 | if (rc == IOCB_ERROR) |
| 5298 | goto io_err; |
| 5299 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5300 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5301 | |
| 5302 | io_err: |
| 5303 | lpfc_nlp_put(ndlp); |
| 5304 | node_err: |
| 5305 | lpfc_els_free_iocb(phba, elsiocb); |
| 5306 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5307 | } |
| 5308 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5309 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5310 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. |
| 5311 | * @vport: pointer to a virtual N_Port data structure. |
| 5312 | * @iocb: pointer to the lpfc command iocb data structure. |
| 5313 | * @ndlp: pointer to a node-list data structure. |
| 5314 | * |
| 5315 | * Return |
| 5316 | **/ |
| 5317 | static void |
| 5318 | lpfc_els_clear_rrq(struct lpfc_vport *vport, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5319 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5320 | { |
| 5321 | struct lpfc_hba *phba = vport->phba; |
| 5322 | uint8_t *pcmd; |
| 5323 | struct RRQ *rrq; |
| 5324 | uint16_t rxid; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5325 | uint16_t xri; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5326 | struct lpfc_node_rrq *prrq; |
| 5327 | |
| 5328 | |
| 5329 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); |
| 5330 | pcmd += sizeof(uint32_t); |
| 5331 | rrq = (struct RRQ *)pcmd; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5332 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5333 | rxid = bf_get(rrq_rxid, rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5334 | |
| 5335 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5336 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" |
| 5337 | " x%x x%x\n", |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5338 | be32_to_cpu(bf_get(rrq_did, rrq)), |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5339 | bf_get(rrq_oxid, rrq), |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5340 | rxid, |
| 5341 | iocb->iotag, iocb->iocb.ulpContext); |
| 5342 | |
| 5343 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 5344 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", |
| 5345 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5346 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5347 | xri = bf_get(rrq_oxid, rrq); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5348 | else |
| 5349 | xri = rxid; |
| 5350 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5351 | if (prrq) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5352 | lpfc_clr_rrq_active(phba, xri, prrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5353 | return; |
| 5354 | } |
| 5355 | |
| 5356 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5357 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 5358 | * @vport: pointer to a virtual N_Port data structure. |
| 5359 | * @data: pointer to echo data to return in the accept. |
| 5360 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5361 | * @ndlp: pointer to a node-list data structure. |
| 5362 | * |
| 5363 | * Return code |
| 5364 | * 0 - Successfully issued acc echo response |
| 5365 | * 1 - Failed to issue acc echo response |
| 5366 | **/ |
| 5367 | static int |
| 5368 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 5369 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 5370 | { |
| 5371 | struct lpfc_hba *phba = vport->phba; |
| 5372 | struct lpfc_iocbq *elsiocb; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5373 | uint8_t *pcmd; |
| 5374 | uint16_t cmdsize; |
| 5375 | int rc; |
| 5376 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5377 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 5378 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5379 | /* The accumulated length can exceed the BPL_SIZE. For |
| 5380 | * now, use this as the limit |
| 5381 | */ |
| 5382 | if (cmdsize > LPFC_BPL_SIZE) |
| 5383 | cmdsize = LPFC_BPL_SIZE; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5384 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5385 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5386 | if (!elsiocb) |
| 5387 | return 1; |
| 5388 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5389 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 5390 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; |
| 5391 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5392 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 5393 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5394 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 5395 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 5396 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5397 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5398 | pcmd += sizeof(uint32_t); |
| 5399 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 5400 | |
| 5401 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5402 | "Issue ACC ECHO: did:x%x flg:x%x refcnt %d", |
| 5403 | ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5404 | |
| 5405 | phba->fc_stat.elsXmitACC++; |
| 5406 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5407 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 5408 | if (!elsiocb->context1) |
| 5409 | goto node_err; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5410 | |
| 5411 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5412 | if (rc == IOCB_ERROR) |
| 5413 | goto io_err; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5414 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 5415 | |
| 5416 | io_err: |
| 5417 | lpfc_nlp_put(ndlp); |
| 5418 | node_err: |
| 5419 | lpfc_els_free_iocb(phba, elsiocb); |
| 5420 | return 1; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5424 | * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5425 | * @vport: pointer to a host virtual N_Port data structure. |
| 5426 | * |
| 5427 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 5428 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 5429 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 5430 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 5431 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 5432 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 5433 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 5434 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 5435 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 5436 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 5437 | * no more ADISC need to be sent. |
| 5438 | * |
| 5439 | * Return code |
| 5440 | * The number of N_Ports with adisc issued. |
| 5441 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5442 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5443 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5444 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5445 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5446 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5447 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5448 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5449 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5450 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5451 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 5452 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 5453 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5454 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5455 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5456 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5457 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5458 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 5459 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5460 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5461 | vport->num_disc_nodes++; |
| 5462 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5463 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5464 | spin_lock_irq(shost->host_lock); |
| 5465 | vport->fc_flag |= FC_NLP_MORE; |
| 5466 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5467 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5468 | } |
| 5469 | } |
| 5470 | } |
| 5471 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5472 | spin_lock_irq(shost->host_lock); |
| 5473 | vport->fc_flag &= ~FC_NLP_MORE; |
| 5474 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5475 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5476 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5477 | } |
| 5478 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5479 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5480 | * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5481 | * @vport: pointer to a host virtual N_Port data structure. |
| 5482 | * |
| 5483 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 5484 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 5485 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 5486 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 5487 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 5488 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 5489 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 5490 | * later pick up. On the other hand, after walking through all the ndlps with |
| 5491 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 5492 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 5493 | * PLOGI need to be sent. |
| 5494 | * |
| 5495 | * Return code |
| 5496 | * The number of N_Ports with plogi issued. |
| 5497 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5498 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5499 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5500 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5501 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5502 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5503 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5504 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5505 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 5506 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5507 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5508 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 5509 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 5510 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5511 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5512 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5513 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5514 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5515 | vport->num_disc_nodes++; |
| 5516 | if (vport->num_disc_nodes >= |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5517 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5518 | spin_lock_irq(shost->host_lock); |
| 5519 | vport->fc_flag |= FC_NLP_MORE; |
| 5520 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5521 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5522 | } |
| 5523 | } |
| 5524 | } |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5525 | |
| 5526 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5527 | "6452 Discover PLOGI %d flag x%x\n", |
| 5528 | sentplogi, vport->fc_flag); |
| 5529 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5530 | if (sentplogi) { |
| 5531 | lpfc_set_disctmo(vport); |
| 5532 | } |
| 5533 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5534 | spin_lock_irq(shost->host_lock); |
| 5535 | vport->fc_flag &= ~FC_NLP_MORE; |
| 5536 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5537 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5538 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5539 | } |
| 5540 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5541 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5542 | lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc, |
| 5543 | uint32_t word0) |
| 5544 | { |
| 5545 | |
| 5546 | desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG); |
| 5547 | desc->payload.els_req = word0; |
| 5548 | desc->length = cpu_to_be32(sizeof(desc->payload)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5549 | |
| 5550 | return sizeof(struct fc_rdp_link_service_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5551 | } |
| 5552 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5553 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5554 | lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc, |
| 5555 | uint8_t *page_a0, uint8_t *page_a2) |
| 5556 | { |
| 5557 | uint16_t wavelength; |
| 5558 | uint16_t temperature; |
| 5559 | uint16_t rx_power; |
| 5560 | uint16_t tx_bias; |
| 5561 | uint16_t tx_power; |
| 5562 | uint16_t vcc; |
| 5563 | uint16_t flag = 0; |
| 5564 | struct sff_trasnceiver_codes_byte4 *trasn_code_byte4; |
| 5565 | struct sff_trasnceiver_codes_byte5 *trasn_code_byte5; |
| 5566 | |
| 5567 | desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG); |
| 5568 | |
| 5569 | trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *) |
| 5570 | &page_a0[SSF_TRANSCEIVER_CODE_B4]; |
| 5571 | trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *) |
| 5572 | &page_a0[SSF_TRANSCEIVER_CODE_B5]; |
| 5573 | |
| 5574 | if ((trasn_code_byte4->fc_sw_laser) || |
| 5575 | (trasn_code_byte5->fc_sw_laser_sl) || |
| 5576 | (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */ |
| 5577 | flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT); |
| 5578 | } else if (trasn_code_byte4->fc_lw_laser) { |
| 5579 | wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) | |
| 5580 | page_a0[SSF_WAVELENGTH_B0]; |
| 5581 | if (wavelength == SFP_WAVELENGTH_LC1310) |
| 5582 | flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT; |
| 5583 | if (wavelength == SFP_WAVELENGTH_LL1550) |
| 5584 | flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT; |
| 5585 | } |
| 5586 | /* check if its SFP+ */ |
| 5587 | flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ? |
| 5588 | SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN) |
| 5589 | << SFP_FLAG_CT_SHIFT; |
| 5590 | |
| 5591 | /* check if its OPTICAL */ |
| 5592 | flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ? |
| 5593 | SFP_FLAG_IS_OPTICAL_PORT : 0) |
| 5594 | << SFP_FLAG_IS_OPTICAL_SHIFT; |
| 5595 | |
| 5596 | temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 | |
| 5597 | page_a2[SFF_TEMPERATURE_B0]); |
| 5598 | vcc = (page_a2[SFF_VCC_B1] << 8 | |
| 5599 | page_a2[SFF_VCC_B0]); |
| 5600 | tx_power = (page_a2[SFF_TXPOWER_B1] << 8 | |
| 5601 | page_a2[SFF_TXPOWER_B0]); |
| 5602 | tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 | |
| 5603 | page_a2[SFF_TX_BIAS_CURRENT_B0]); |
| 5604 | rx_power = (page_a2[SFF_RXPOWER_B1] << 8 | |
| 5605 | page_a2[SFF_RXPOWER_B0]); |
| 5606 | desc->sfp_info.temperature = cpu_to_be16(temperature); |
| 5607 | desc->sfp_info.rx_power = cpu_to_be16(rx_power); |
| 5608 | desc->sfp_info.tx_bias = cpu_to_be16(tx_bias); |
| 5609 | desc->sfp_info.tx_power = cpu_to_be16(tx_power); |
| 5610 | desc->sfp_info.vcc = cpu_to_be16(vcc); |
| 5611 | |
| 5612 | desc->sfp_info.flags = cpu_to_be16(flag); |
| 5613 | desc->length = cpu_to_be32(sizeof(desc->sfp_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5614 | |
| 5615 | return sizeof(struct fc_rdp_sfp_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5616 | } |
| 5617 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5618 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5619 | lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc, |
| 5620 | READ_LNK_VAR *stat) |
| 5621 | { |
| 5622 | uint32_t type; |
| 5623 | |
| 5624 | desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG); |
| 5625 | |
| 5626 | type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT; |
| 5627 | |
| 5628 | desc->info.port_type = cpu_to_be32(type); |
| 5629 | |
| 5630 | desc->info.link_status.link_failure_cnt = |
| 5631 | cpu_to_be32(stat->linkFailureCnt); |
| 5632 | desc->info.link_status.loss_of_synch_cnt = |
| 5633 | cpu_to_be32(stat->lossSyncCnt); |
| 5634 | desc->info.link_status.loss_of_signal_cnt = |
| 5635 | cpu_to_be32(stat->lossSignalCnt); |
| 5636 | desc->info.link_status.primitive_seq_proto_err = |
| 5637 | cpu_to_be32(stat->primSeqErrCnt); |
| 5638 | desc->info.link_status.invalid_trans_word = |
| 5639 | cpu_to_be32(stat->invalidXmitWord); |
| 5640 | desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt); |
| 5641 | |
| 5642 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5643 | |
| 5644 | return sizeof(struct fc_rdp_link_error_status_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5645 | } |
| 5646 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5647 | static uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5648 | lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat, |
| 5649 | struct lpfc_vport *vport) |
| 5650 | { |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5651 | uint32_t bbCredit; |
| 5652 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5653 | desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG); |
| 5654 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5655 | bbCredit = vport->fc_sparam.cmn.bbCreditLsb | |
| 5656 | (vport->fc_sparam.cmn.bbCreditMsb << 8); |
| 5657 | desc->bbc_info.port_bbc = cpu_to_be32(bbCredit); |
| 5658 | if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
| 5659 | bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb | |
| 5660 | (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8); |
| 5661 | desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit); |
| 5662 | } else { |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5663 | desc->bbc_info.attached_port_bbc = 0; |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5664 | } |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5665 | |
| 5666 | desc->bbc_info.rtt = 0; |
| 5667 | desc->length = cpu_to_be32(sizeof(desc->bbc_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5668 | |
| 5669 | return sizeof(struct fc_rdp_bbc_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5670 | } |
| 5671 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5672 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5673 | lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba, |
| 5674 | struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2) |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5675 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5676 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5677 | |
| 5678 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5679 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5680 | desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM]; |
| 5681 | desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM]; |
| 5682 | desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING]; |
| 5683 | desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5684 | |
| 5685 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 5686 | flags |= RDP_OET_HIGH_ALARM; |
| 5687 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 5688 | flags |= RDP_OET_LOW_ALARM; |
| 5689 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 5690 | flags |= RDP_OET_HIGH_WARNING; |
| 5691 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 5692 | flags |= RDP_OET_LOW_WARNING; |
| 5693 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5694 | flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT); |
| 5695 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5696 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5697 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5698 | } |
| 5699 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5700 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5701 | lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba, |
| 5702 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5703 | uint8_t *page_a2) |
| 5704 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5705 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5706 | |
| 5707 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5708 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5709 | desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM]; |
| 5710 | desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM]; |
| 5711 | desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING]; |
| 5712 | desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5713 | |
| 5714 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 5715 | flags |= RDP_OET_HIGH_ALARM; |
| 5716 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 5717 | flags |= RDP_OET_LOW_ALARM; |
| 5718 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 5719 | flags |= RDP_OET_HIGH_WARNING; |
| 5720 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 5721 | flags |= RDP_OET_LOW_WARNING; |
| 5722 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5723 | flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT); |
| 5724 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5725 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5726 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5727 | } |
| 5728 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5729 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5730 | lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba, |
| 5731 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5732 | uint8_t *page_a2) |
| 5733 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5734 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5735 | |
| 5736 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5737 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5738 | desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM]; |
| 5739 | desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM]; |
| 5740 | desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING]; |
| 5741 | desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5742 | |
| 5743 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 5744 | flags |= RDP_OET_HIGH_ALARM; |
| 5745 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 5746 | flags |= RDP_OET_LOW_ALARM; |
| 5747 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 5748 | flags |= RDP_OET_HIGH_WARNING; |
| 5749 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 5750 | flags |= RDP_OET_LOW_WARNING; |
| 5751 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5752 | flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT); |
| 5753 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5754 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5755 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5756 | } |
| 5757 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5758 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5759 | lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba, |
| 5760 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5761 | uint8_t *page_a2) |
| 5762 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5763 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5764 | |
| 5765 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5766 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5767 | desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM]; |
| 5768 | desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM]; |
| 5769 | desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING]; |
| 5770 | desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5771 | |
| 5772 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 5773 | flags |= RDP_OET_HIGH_ALARM; |
| 5774 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 5775 | flags |= RDP_OET_LOW_ALARM; |
| 5776 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 5777 | flags |= RDP_OET_HIGH_WARNING; |
| 5778 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 5779 | flags |= RDP_OET_LOW_WARNING; |
| 5780 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5781 | flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT); |
| 5782 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5783 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5784 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5785 | } |
| 5786 | |
| 5787 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5788 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5789 | lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba, |
| 5790 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5791 | uint8_t *page_a2) |
| 5792 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5793 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5794 | |
| 5795 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5796 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5797 | desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM]; |
| 5798 | desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM]; |
| 5799 | desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING]; |
| 5800 | desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5801 | |
| 5802 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 5803 | flags |= RDP_OET_HIGH_ALARM; |
| 5804 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 5805 | flags |= RDP_OET_LOW_ALARM; |
| 5806 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 5807 | flags |= RDP_OET_HIGH_WARNING; |
| 5808 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 5809 | flags |= RDP_OET_LOW_WARNING; |
| 5810 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5811 | flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT); |
| 5812 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5813 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5814 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5815 | } |
| 5816 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5817 | static uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5818 | lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc, |
| 5819 | uint8_t *page_a0, struct lpfc_vport *vport) |
| 5820 | { |
| 5821 | desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG); |
| 5822 | memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16); |
| 5823 | memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16); |
| 5824 | memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5825 | memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5826 | memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8); |
| 5827 | desc->length = cpu_to_be32(sizeof(desc->opd_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5828 | return sizeof(struct fc_rdp_opd_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5829 | } |
| 5830 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5831 | static uint32_t |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5832 | lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat) |
| 5833 | { |
| 5834 | if (bf_get(lpfc_read_link_stat_gec2, stat) == 0) |
| 5835 | return 0; |
| 5836 | desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG); |
| 5837 | |
| 5838 | desc->info.CorrectedBlocks = |
| 5839 | cpu_to_be32(stat->fecCorrBlkCount); |
| 5840 | desc->info.UncorrectableBlocks = |
| 5841 | cpu_to_be32(stat->fecUncorrBlkCount); |
| 5842 | |
| 5843 | desc->length = cpu_to_be32(sizeof(desc->info)); |
| 5844 | |
| 5845 | return sizeof(struct fc_fec_rdp_desc); |
| 5846 | } |
| 5847 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5848 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5849 | lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba) |
| 5850 | { |
| 5851 | uint16_t rdp_cap = 0; |
| 5852 | uint16_t rdp_speed; |
| 5853 | |
| 5854 | desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG); |
| 5855 | |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5856 | switch (phba->fc_linkspeed) { |
| 5857 | case LPFC_LINK_SPEED_1GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5858 | rdp_speed = RDP_PS_1GB; |
| 5859 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5860 | case LPFC_LINK_SPEED_2GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5861 | rdp_speed = RDP_PS_2GB; |
| 5862 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5863 | case LPFC_LINK_SPEED_4GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5864 | rdp_speed = RDP_PS_4GB; |
| 5865 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5866 | case LPFC_LINK_SPEED_8GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5867 | rdp_speed = RDP_PS_8GB; |
| 5868 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5869 | case LPFC_LINK_SPEED_10GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5870 | rdp_speed = RDP_PS_10GB; |
| 5871 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5872 | case LPFC_LINK_SPEED_16GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5873 | rdp_speed = RDP_PS_16GB; |
| 5874 | break; |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 5875 | case LPFC_LINK_SPEED_32GHZ: |
| 5876 | rdp_speed = RDP_PS_32GB; |
| 5877 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 5878 | case LPFC_LINK_SPEED_64GHZ: |
| 5879 | rdp_speed = RDP_PS_64GB; |
| 5880 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5881 | default: |
| 5882 | rdp_speed = RDP_PS_UNKNOWN; |
| 5883 | break; |
| 5884 | } |
| 5885 | |
| 5886 | desc->info.port_speed.speed = cpu_to_be16(rdp_speed); |
| 5887 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5888 | if (phba->lmt & LMT_128Gb) |
| 5889 | rdp_cap |= RDP_PS_128GB; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 5890 | if (phba->lmt & LMT_64Gb) |
| 5891 | rdp_cap |= RDP_PS_64GB; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 5892 | if (phba->lmt & LMT_32Gb) |
| 5893 | rdp_cap |= RDP_PS_32GB; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5894 | if (phba->lmt & LMT_16Gb) |
| 5895 | rdp_cap |= RDP_PS_16GB; |
| 5896 | if (phba->lmt & LMT_10Gb) |
| 5897 | rdp_cap |= RDP_PS_10GB; |
| 5898 | if (phba->lmt & LMT_8Gb) |
| 5899 | rdp_cap |= RDP_PS_8GB; |
| 5900 | if (phba->lmt & LMT_4Gb) |
| 5901 | rdp_cap |= RDP_PS_4GB; |
| 5902 | if (phba->lmt & LMT_2Gb) |
| 5903 | rdp_cap |= RDP_PS_2GB; |
| 5904 | if (phba->lmt & LMT_1Gb) |
| 5905 | rdp_cap |= RDP_PS_1GB; |
| 5906 | |
| 5907 | if (rdp_cap == 0) |
| 5908 | rdp_cap = RDP_CAP_UNKNOWN; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5909 | if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO) |
| 5910 | rdp_cap |= RDP_CAP_USER_CONFIGURED; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5911 | |
| 5912 | desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap); |
| 5913 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5914 | return sizeof(struct fc_rdp_port_speed_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5915 | } |
| 5916 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5917 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5918 | lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc, |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 5919 | struct lpfc_vport *vport) |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5920 | { |
| 5921 | |
| 5922 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 5923 | |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 5924 | memcpy(desc->port_names.wwnn, &vport->fc_nodename, |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5925 | sizeof(desc->port_names.wwnn)); |
| 5926 | |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 5927 | memcpy(desc->port_names.wwpn, &vport->fc_portname, |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5928 | sizeof(desc->port_names.wwpn)); |
| 5929 | |
| 5930 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5931 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5932 | } |
| 5933 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5934 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5935 | lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc, |
| 5936 | struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 5937 | { |
| 5938 | |
| 5939 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 5940 | if (vport->fc_flag & FC_FABRIC) { |
| 5941 | memcpy(desc->port_names.wwnn, &vport->fabric_nodename, |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 5942 | sizeof(desc->port_names.wwnn)); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5943 | |
| 5944 | memcpy(desc->port_names.wwpn, &vport->fabric_portname, |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 5945 | sizeof(desc->port_names.wwpn)); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5946 | } else { /* Point to Point */ |
| 5947 | memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename, |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 5948 | sizeof(desc->port_names.wwnn)); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5949 | |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 5950 | memcpy(desc->port_names.wwpn, &ndlp->nlp_portname, |
| 5951 | sizeof(desc->port_names.wwpn)); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5952 | } |
| 5953 | |
| 5954 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5955 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5956 | } |
| 5957 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5958 | static void |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5959 | lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context, |
| 5960 | int status) |
| 5961 | { |
| 5962 | struct lpfc_nodelist *ndlp = rdp_context->ndlp; |
| 5963 | struct lpfc_vport *vport = ndlp->vport; |
| 5964 | struct lpfc_iocbq *elsiocb; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5965 | struct ulp_bde64 *bpl; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5966 | IOCB_t *icmd; |
| 5967 | uint8_t *pcmd; |
| 5968 | struct ls_rjt *stat; |
| 5969 | struct fc_rdp_res_frame *rdp_res; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5970 | uint32_t cmdsize, len; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5971 | uint16_t *flag_ptr; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5972 | int rc; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5973 | |
| 5974 | if (status != SUCCESS) |
| 5975 | goto error; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5976 | |
| 5977 | /* This will change once we know the true size of the RDP payload */ |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5978 | cmdsize = sizeof(struct fc_rdp_res_frame); |
| 5979 | |
| 5980 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, |
| 5981 | lpfc_max_els_tries, rdp_context->ndlp, |
| 5982 | rdp_context->ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5983 | if (!elsiocb) |
| 5984 | goto free_rdp_context; |
| 5985 | |
| 5986 | icmd = &elsiocb->iocb; |
| 5987 | icmd->ulpContext = rdp_context->rx_id; |
| 5988 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 5989 | |
| 5990 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5991 | "2171 Xmit RDP response tag x%x xri x%x, " |
| 5992 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x", |
| 5993 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5994 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5995 | ndlp->nlp_rpi); |
| 5996 | rdp_res = (struct fc_rdp_res_frame *) |
| 5997 | (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5998 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5999 | memset(pcmd, 0, sizeof(struct fc_rdp_res_frame)); |
| 6000 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6001 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 6002 | /* Update Alarm and Warning */ |
| 6003 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS); |
| 6004 | phba->sfp_alarm |= *flag_ptr; |
| 6005 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS); |
| 6006 | phba->sfp_warning |= *flag_ptr; |
| 6007 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6008 | /* For RDP payload */ |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6009 | len = 8; |
| 6010 | len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *) |
| 6011 | (len + pcmd), ELS_CMD_RDP); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6012 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6013 | len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd), |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6014 | rdp_context->page_a0, rdp_context->page_a2); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6015 | len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd), |
| 6016 | phba); |
| 6017 | len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *) |
| 6018 | (len + pcmd), &rdp_context->link_stat); |
| 6019 | len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *) |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 6020 | (len + pcmd), vport); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6021 | len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *) |
| 6022 | (len + pcmd), vport, ndlp); |
| 6023 | len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd), |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6024 | &rdp_context->link_stat); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6025 | len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd), |
| 6026 | &rdp_context->link_stat, vport); |
| 6027 | len += lpfc_rdp_res_oed_temp_desc(phba, |
| 6028 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 6029 | rdp_context->page_a2); |
| 6030 | len += lpfc_rdp_res_oed_voltage_desc(phba, |
| 6031 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 6032 | rdp_context->page_a2); |
| 6033 | len += lpfc_rdp_res_oed_txbias_desc(phba, |
| 6034 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 6035 | rdp_context->page_a2); |
| 6036 | len += lpfc_rdp_res_oed_txpower_desc(phba, |
| 6037 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 6038 | rdp_context->page_a2); |
| 6039 | len += lpfc_rdp_res_oed_rxpower_desc(phba, |
| 6040 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 6041 | rdp_context->page_a2); |
| 6042 | len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd), |
| 6043 | rdp_context->page_a0, vport); |
| 6044 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6045 | rdp_res->length = cpu_to_be32(len - 8); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6046 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6047 | |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 6048 | /* Now that we know the true size of the payload, update the BPL */ |
| 6049 | bpl = (struct ulp_bde64 *) |
| 6050 | (((struct lpfc_dmabuf *)(elsiocb->context3))->virt); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6051 | bpl->tus.f.bdeSize = len; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 6052 | bpl->tus.f.bdeFlags = 0; |
| 6053 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 6054 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6055 | phba->fc_stat.elsXmitACC++; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 6056 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 6057 | if (!elsiocb->context1) { |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6058 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 6059 | goto free_rdp_context; |
| 6060 | } |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6061 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 6062 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6063 | if (rc == IOCB_ERROR) { |
| 6064 | lpfc_nlp_put(ndlp); |
| 6065 | lpfc_els_free_iocb(phba, elsiocb); |
| 6066 | } |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6067 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 6068 | goto free_rdp_context; |
| 6069 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6070 | error: |
| 6071 | cmdsize = 2 * sizeof(uint32_t); |
| 6072 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries, |
| 6073 | ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6074 | if (!elsiocb) |
| 6075 | goto free_rdp_context; |
| 6076 | |
| 6077 | icmd = &elsiocb->iocb; |
| 6078 | icmd->ulpContext = rdp_context->rx_id; |
| 6079 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 6080 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6081 | |
| 6082 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
| 6083 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 6084 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6085 | |
| 6086 | phba->fc_stat.elsXmitLSRJT++; |
| 6087 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 6088 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 6089 | if (!elsiocb->context1) { |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6090 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 6091 | goto free_rdp_context; |
| 6092 | } |
| 6093 | |
| 6094 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6095 | if (rc == IOCB_ERROR) { |
| 6096 | lpfc_nlp_put(ndlp); |
| 6097 | lpfc_els_free_iocb(phba, elsiocb); |
| 6098 | } |
| 6099 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6100 | free_rdp_context: |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 6101 | /* This reference put is for the original unsolicited RDP. If the |
| 6102 | * iocb prep failed, there is no reference to remove. |
| 6103 | */ |
| 6104 | lpfc_nlp_put(ndlp); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6105 | kfree(rdp_context); |
| 6106 | } |
| 6107 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 6108 | static int |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6109 | lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) |
| 6110 | { |
| 6111 | LPFC_MBOXQ_t *mbox = NULL; |
| 6112 | int rc; |
| 6113 | |
| 6114 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6115 | if (!mbox) { |
| 6116 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, |
| 6117 | "7105 failed to allocate mailbox memory"); |
| 6118 | return 1; |
| 6119 | } |
| 6120 | |
| 6121 | if (lpfc_sli4_dump_page_a0(phba, mbox)) |
| 6122 | goto prep_mbox_fail; |
| 6123 | mbox->vport = rdp_context->ndlp->vport; |
| 6124 | mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6125 | mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6126 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6127 | if (rc == MBX_NOT_FINISHED) |
| 6128 | goto issue_mbox_fail; |
| 6129 | |
| 6130 | return 0; |
| 6131 | |
| 6132 | prep_mbox_fail: |
| 6133 | issue_mbox_fail: |
| 6134 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6135 | return 1; |
| 6136 | } |
| 6137 | |
| 6138 | /* |
| 6139 | * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS. |
| 6140 | * @vport: pointer to a host virtual N_Port data structure. |
| 6141 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6142 | * @ndlp: pointer to a node-list data structure. |
| 6143 | * |
| 6144 | * This routine processes an unsolicited RDP(Read Diagnostic Parameters) |
| 6145 | * IOCB. First, the payload of the unsolicited RDP is checked. |
| 6146 | * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3 |
| 6147 | * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2, |
| 6148 | * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl |
| 6149 | * gather all data and send RDP response. |
| 6150 | * |
| 6151 | * Return code |
| 6152 | * 0 - Sent the acc response |
| 6153 | * 1 - Sent the reject response. |
| 6154 | */ |
| 6155 | static int |
| 6156 | lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6157 | struct lpfc_nodelist *ndlp) |
| 6158 | { |
| 6159 | struct lpfc_hba *phba = vport->phba; |
| 6160 | struct lpfc_dmabuf *pcmd; |
| 6161 | uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE; |
| 6162 | struct fc_rdp_req_frame *rdp_req; |
| 6163 | struct lpfc_rdp_context *rdp_context; |
| 6164 | IOCB_t *cmd = NULL; |
| 6165 | struct ls_rjt stat; |
| 6166 | |
| 6167 | if (phba->sli_rev < LPFC_SLI_REV4 || |
James Smart | 719162b | 2018-12-10 19:37:01 -0800 | [diff] [blame] | 6168 | bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) < |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 6169 | LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6170 | rjt_err = LSRJT_UNABLE_TPC; |
| 6171 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 6172 | goto error; |
| 6173 | } |
| 6174 | |
| 6175 | if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) { |
| 6176 | rjt_err = LSRJT_UNABLE_TPC; |
| 6177 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 6178 | goto error; |
| 6179 | } |
| 6180 | |
| 6181 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6182 | rdp_req = (struct fc_rdp_req_frame *) pcmd->virt; |
| 6183 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6184 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6185 | "2422 ELS RDP Request " |
| 6186 | "dec len %d tag x%x port_id %d len %d\n", |
| 6187 | be32_to_cpu(rdp_req->rdp_des_length), |
| 6188 | be32_to_cpu(rdp_req->nport_id_desc.tag), |
| 6189 | be32_to_cpu(rdp_req->nport_id_desc.nport_id), |
| 6190 | be32_to_cpu(rdp_req->nport_id_desc.length)); |
| 6191 | |
| 6192 | if (sizeof(struct fc_rdp_nport_desc) != |
| 6193 | be32_to_cpu(rdp_req->rdp_des_length)) |
| 6194 | goto rjt_logerr; |
| 6195 | if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag)) |
| 6196 | goto rjt_logerr; |
| 6197 | if (RDP_NPORT_ID_SIZE != |
| 6198 | be32_to_cpu(rdp_req->nport_id_desc.length)) |
| 6199 | goto rjt_logerr; |
Punit Vara | 699acd6 | 2015-12-16 18:12:07 -0500 | [diff] [blame] | 6200 | rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6201 | if (!rdp_context) { |
| 6202 | rjt_err = LSRJT_UNABLE_TPC; |
| 6203 | goto error; |
| 6204 | } |
| 6205 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6206 | cmd = &cmdiocb->iocb; |
| 6207 | rdp_context->ndlp = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 6208 | if (!rdp_context->ndlp) { |
| 6209 | kfree(rdp_context); |
| 6210 | rjt_err = LSRJT_UNABLE_TPC; |
| 6211 | goto error; |
| 6212 | } |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6213 | rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id; |
| 6214 | rdp_context->rx_id = cmd->ulpContext; |
| 6215 | rdp_context->cmpl = lpfc_els_rdp_cmpl; |
| 6216 | if (lpfc_get_rdp_info(phba, rdp_context)) { |
| 6217 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS, |
| 6218 | "2423 Unable to send mailbox"); |
| 6219 | kfree(rdp_context); |
| 6220 | rjt_err = LSRJT_UNABLE_TPC; |
| 6221 | lpfc_nlp_put(ndlp); |
| 6222 | goto error; |
| 6223 | } |
| 6224 | |
| 6225 | return 0; |
| 6226 | |
| 6227 | rjt_logerr: |
| 6228 | rjt_err = LSRJT_LOGICAL_ERR; |
| 6229 | |
| 6230 | error: |
| 6231 | memset(&stat, 0, sizeof(stat)); |
| 6232 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 6233 | stat.un.b.lsRjtRsnCodeExp = rjt_expl; |
| 6234 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6235 | return 1; |
| 6236 | } |
| 6237 | |
| 6238 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6239 | static void |
| 6240 | lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6241 | { |
| 6242 | MAILBOX_t *mb; |
| 6243 | IOCB_t *icmd; |
| 6244 | uint8_t *pcmd; |
| 6245 | struct lpfc_iocbq *elsiocb; |
| 6246 | struct lpfc_nodelist *ndlp; |
| 6247 | struct ls_rjt *stat; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 6248 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6249 | struct lpfc_lcb_context *lcb_context; |
| 6250 | struct fc_lcb_res_frame *lcb_res; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 6251 | uint32_t cmdsize, shdr_status, shdr_add_status; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6252 | int rc; |
| 6253 | |
| 6254 | mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6255 | lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6256 | ndlp = lcb_context->ndlp; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6257 | pmb->ctx_ndlp = NULL; |
| 6258 | pmb->ctx_buf = NULL; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6259 | |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 6260 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6261 | &pmb->u.mqe.un.beacon_config.header.cfg_shdr; |
| 6262 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6263 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6264 | |
| 6265 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX, |
| 6266 | "0194 SET_BEACON_CONFIG mailbox " |
| 6267 | "completed with status x%x add_status x%x," |
| 6268 | " mbx status x%x\n", |
| 6269 | shdr_status, shdr_add_status, mb->mbxStatus); |
| 6270 | |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6271 | if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status || |
| 6272 | (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) || |
| 6273 | (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6274 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6275 | goto error; |
| 6276 | } |
| 6277 | |
| 6278 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6279 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 6280 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6281 | lpfc_max_els_tries, ndlp, |
| 6282 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6283 | |
| 6284 | /* Decrement the ndlp reference count from previous mbox command */ |
| 6285 | lpfc_nlp_put(ndlp); |
| 6286 | |
| 6287 | if (!elsiocb) |
| 6288 | goto free_lcb_context; |
| 6289 | |
| 6290 | lcb_res = (struct fc_lcb_res_frame *) |
| 6291 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 6292 | |
James Smart | 24bc311 | 2018-07-31 17:23:23 -0700 | [diff] [blame] | 6293 | memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame)); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6294 | icmd = &elsiocb->iocb; |
| 6295 | icmd->ulpContext = lcb_context->rx_id; |
| 6296 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 6297 | |
| 6298 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 6299 | *((uint32_t *)(pcmd)) = ELS_CMD_ACC; |
| 6300 | lcb_res->lcb_sub_command = lcb_context->sub_command; |
| 6301 | lcb_res->lcb_type = lcb_context->type; |
James Smart | 24bc311 | 2018-07-31 17:23:23 -0700 | [diff] [blame] | 6302 | lcb_res->capability = lcb_context->capability; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6303 | lcb_res->lcb_frequency = lcb_context->frequency; |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6304 | lcb_res->lcb_duration = lcb_context->duration; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6305 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6306 | phba->fc_stat.elsXmitACC++; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6307 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 6308 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 6309 | if (!elsiocb->context1) |
| 6310 | goto node_err; |
| 6311 | |
| 6312 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6313 | if (!rc) |
| 6314 | goto out; |
| 6315 | |
| 6316 | lpfc_nlp_put(ndlp); |
| 6317 | node_err: |
| 6318 | lpfc_els_free_iocb(phba, elsiocb); |
| 6319 | out: |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6320 | kfree(lcb_context); |
| 6321 | return; |
| 6322 | |
| 6323 | error: |
| 6324 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 6325 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6326 | lpfc_max_els_tries, ndlp, |
| 6327 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 6328 | lpfc_nlp_put(ndlp); |
| 6329 | if (!elsiocb) |
| 6330 | goto free_lcb_context; |
| 6331 | |
| 6332 | icmd = &elsiocb->iocb; |
| 6333 | icmd->ulpContext = lcb_context->rx_id; |
| 6334 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 6335 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 6336 | |
| 6337 | *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT; |
| 6338 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 6339 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6340 | |
James Smart | b114d90 | 2018-10-23 13:41:07 -0700 | [diff] [blame] | 6341 | if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) |
| 6342 | stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS; |
| 6343 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6344 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6345 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 6346 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 6347 | if (!elsiocb->context1) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6348 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 6349 | goto free_lcb_context; |
| 6350 | } |
| 6351 | |
| 6352 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6353 | if (rc == IOCB_ERROR) { |
| 6354 | lpfc_nlp_put(ndlp); |
| 6355 | lpfc_els_free_iocb(phba, elsiocb); |
| 6356 | } |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6357 | free_lcb_context: |
| 6358 | kfree(lcb_context); |
| 6359 | } |
| 6360 | |
| 6361 | static int |
| 6362 | lpfc_sli4_set_beacon(struct lpfc_vport *vport, |
| 6363 | struct lpfc_lcb_context *lcb_context, |
| 6364 | uint32_t beacon_state) |
| 6365 | { |
| 6366 | struct lpfc_hba *phba = vport->phba; |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6367 | union lpfc_sli4_cfg_shdr *cfg_shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6368 | LPFC_MBOXQ_t *mbox = NULL; |
| 6369 | uint32_t len; |
| 6370 | int rc; |
| 6371 | |
| 6372 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6373 | if (!mbox) |
| 6374 | return 1; |
| 6375 | |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6376 | cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6377 | len = sizeof(struct lpfc_mbx_set_beacon_config) - |
| 6378 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6379 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6380 | LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len, |
| 6381 | LPFC_SLI4_MBX_EMBED); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6382 | mbox->ctx_ndlp = (void *)lcb_context; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6383 | mbox->vport = phba->pport; |
| 6384 | mbox->mbox_cmpl = lpfc_els_lcb_rsp; |
| 6385 | bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config, |
| 6386 | phba->sli4_hba.physical_port); |
| 6387 | bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config, |
| 6388 | beacon_state); |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6389 | mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */ |
| 6390 | |
| 6391 | /* |
| 6392 | * Check bv1s bit before issuing the mailbox |
| 6393 | * if bv1s == 1, LCB V1 supported |
| 6394 | * else, LCB V0 supported |
| 6395 | */ |
| 6396 | |
| 6397 | if (phba->sli4_hba.pc_sli4_params.bv1s) { |
| 6398 | /* COMMON_SET_BEACON_CONFIG_V1 */ |
| 6399 | cfg_shdr->request.word9 = BEACON_VERSION_V1; |
| 6400 | lcb_context->capability |= LCB_CAPABILITY_DURATION; |
| 6401 | bf_set(lpfc_mbx_set_beacon_port_type, |
| 6402 | &mbox->u.mqe.un.beacon_config, 0); |
| 6403 | bf_set(lpfc_mbx_set_beacon_duration_v1, |
| 6404 | &mbox->u.mqe.un.beacon_config, |
| 6405 | be16_to_cpu(lcb_context->duration)); |
| 6406 | } else { |
| 6407 | /* COMMON_SET_BEACON_CONFIG_V0 */ |
| 6408 | if (be16_to_cpu(lcb_context->duration) != 0) { |
| 6409 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6410 | return 1; |
| 6411 | } |
| 6412 | cfg_shdr->request.word9 = BEACON_VERSION_V0; |
| 6413 | lcb_context->capability &= ~(LCB_CAPABILITY_DURATION); |
| 6414 | bf_set(lpfc_mbx_set_beacon_state, |
| 6415 | &mbox->u.mqe.un.beacon_config, beacon_state); |
| 6416 | bf_set(lpfc_mbx_set_beacon_port_type, |
| 6417 | &mbox->u.mqe.un.beacon_config, 1); |
| 6418 | bf_set(lpfc_mbx_set_beacon_duration, |
| 6419 | &mbox->u.mqe.un.beacon_config, |
| 6420 | be16_to_cpu(lcb_context->duration)); |
| 6421 | } |
| 6422 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6423 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6424 | if (rc == MBX_NOT_FINISHED) { |
| 6425 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6426 | return 1; |
| 6427 | } |
| 6428 | |
| 6429 | return 0; |
| 6430 | } |
| 6431 | |
| 6432 | |
| 6433 | /** |
| 6434 | * lpfc_els_rcv_lcb - Process an unsolicited LCB |
| 6435 | * @vport: pointer to a host virtual N_Port data structure. |
| 6436 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6437 | * @ndlp: pointer to a node-list data structure. |
| 6438 | * |
| 6439 | * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB. |
| 6440 | * First, the payload of the unsolicited LCB is checked. |
| 6441 | * Then based on Subcommand beacon will either turn on or off. |
| 6442 | * |
| 6443 | * Return code |
| 6444 | * 0 - Sent the acc response |
| 6445 | * 1 - Sent the reject response. |
| 6446 | **/ |
| 6447 | static int |
| 6448 | lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6449 | struct lpfc_nodelist *ndlp) |
| 6450 | { |
| 6451 | struct lpfc_hba *phba = vport->phba; |
| 6452 | struct lpfc_dmabuf *pcmd; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6453 | uint8_t *lp; |
| 6454 | struct fc_lcb_request_frame *beacon; |
| 6455 | struct lpfc_lcb_context *lcb_context; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 6456 | u8 state, rjt_err = 0; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6457 | struct ls_rjt stat; |
| 6458 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6459 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 6460 | lp = (uint8_t *)pcmd->virt; |
| 6461 | beacon = (struct fc_lcb_request_frame *)pcmd->virt; |
| 6462 | |
| 6463 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6464 | "0192 ELS LCB Data x%x x%x x%x x%x sub x%x " |
| 6465 | "type x%x frequency %x duration x%x\n", |
| 6466 | lp[0], lp[1], lp[2], |
| 6467 | beacon->lcb_command, |
| 6468 | beacon->lcb_sub_command, |
| 6469 | beacon->lcb_type, |
| 6470 | beacon->lcb_frequency, |
| 6471 | be16_to_cpu(beacon->lcb_duration)); |
| 6472 | |
James Smart | d6564e5 | 2017-06-15 22:56:50 -0700 | [diff] [blame] | 6473 | if (beacon->lcb_sub_command != LPFC_LCB_ON && |
| 6474 | beacon->lcb_sub_command != LPFC_LCB_OFF) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6475 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 6476 | goto rjt; |
| 6477 | } |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6478 | |
| 6479 | if (phba->sli_rev < LPFC_SLI_REV4 || |
| 6480 | phba->hba_flag & HBA_FCOE_MODE || |
| 6481 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) < |
| 6482 | LPFC_SLI_INTF_IF_TYPE_2)) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6483 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 6484 | goto rjt; |
| 6485 | } |
| 6486 | |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 6487 | lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL); |
| 6488 | if (!lcb_context) { |
| 6489 | rjt_err = LSRJT_UNABLE_TPC; |
| 6490 | goto rjt; |
| 6491 | } |
| 6492 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6493 | state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; |
| 6494 | lcb_context->sub_command = beacon->lcb_sub_command; |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6495 | lcb_context->capability = 0; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6496 | lcb_context->type = beacon->lcb_type; |
| 6497 | lcb_context->frequency = beacon->lcb_frequency; |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6498 | lcb_context->duration = beacon->lcb_duration; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6499 | lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
| 6500 | lcb_context->rx_id = cmdiocb->iocb.ulpContext; |
| 6501 | lcb_context->ndlp = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 6502 | if (!lcb_context->ndlp) { |
| 6503 | rjt_err = LSRJT_UNABLE_TPC; |
| 6504 | goto rjt; |
| 6505 | } |
| 6506 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6507 | if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6508 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT, |
| 6509 | "0193 failed to send mail box"); |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 6510 | kfree(lcb_context); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6511 | lpfc_nlp_put(ndlp); |
| 6512 | rjt_err = LSRJT_UNABLE_TPC; |
| 6513 | goto rjt; |
| 6514 | } |
| 6515 | return 0; |
| 6516 | rjt: |
| 6517 | memset(&stat, 0, sizeof(stat)); |
| 6518 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 6519 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6520 | return 1; |
| 6521 | } |
| 6522 | |
| 6523 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6524 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6525 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6526 | * @vport: pointer to a host virtual N_Port data structure. |
| 6527 | * |
| 6528 | * This routine cleans up any Registration State Change Notification |
| 6529 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 6530 | * @vport together with the host_lock is used to prevent multiple thread |
| 6531 | * trying to access the RSCN array on a same @vport at the same time. |
| 6532 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6533 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6534 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6535 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6536 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6537 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6538 | int i; |
| 6539 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6540 | spin_lock_irq(shost->host_lock); |
| 6541 | if (vport->fc_rscn_flush) { |
| 6542 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 6543 | spin_unlock_irq(shost->host_lock); |
| 6544 | return; |
| 6545 | } |
| 6546 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 6547 | vport->fc_rscn_flush = 1; |
| 6548 | spin_unlock_irq(shost->host_lock); |
| 6549 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6550 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6551 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6552 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6553 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6554 | spin_lock_irq(shost->host_lock); |
| 6555 | vport->fc_rscn_id_cnt = 0; |
| 6556 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 6557 | spin_unlock_irq(shost->host_lock); |
| 6558 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6559 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 6560 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6561 | } |
| 6562 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6563 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6564 | * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6565 | * @vport: pointer to a host virtual N_Port data structure. |
| 6566 | * @did: remote destination port identifier. |
| 6567 | * |
| 6568 | * This routine checks whether there is any pending Registration State |
| 6569 | * Configuration Notification (RSCN) to a @did on @vport. |
| 6570 | * |
| 6571 | * Return code |
| 6572 | * None zero - The @did matched with a pending rscn |
| 6573 | * 0 - not able to match @did with a pending rscn |
| 6574 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6575 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6576 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6577 | { |
| 6578 | D_ID ns_did; |
| 6579 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6580 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6581 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6582 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6583 | |
| 6584 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6585 | |
| 6586 | /* Never match fabric nodes for RSCNs */ |
| 6587 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6588 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6589 | |
| 6590 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6591 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6592 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6593 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6594 | spin_lock_irq(shost->host_lock); |
| 6595 | if (vport->fc_rscn_flush) { |
| 6596 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 6597 | spin_unlock_irq(shost->host_lock); |
| 6598 | return 0; |
| 6599 | } |
| 6600 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 6601 | vport->fc_rscn_flush = 1; |
| 6602 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6603 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6604 | lp = vport->fc_rscn_id_list[i]->virt; |
| 6605 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 6606 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6607 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6608 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 6609 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 6610 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 6611 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6612 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 6613 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 6614 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6615 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6616 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 6617 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6618 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 6619 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6620 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6621 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 6622 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6623 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6624 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6625 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 6626 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6627 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6628 | } |
| 6629 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6630 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6631 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 6632 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6633 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6634 | return_did_out: |
| 6635 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 6636 | vport->fc_rscn_flush = 0; |
| 6637 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6638 | } |
| 6639 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6640 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6641 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6642 | * @vport: pointer to a host virtual N_Port data structure. |
| 6643 | * |
| 6644 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 6645 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 6646 | * State Change Notification). |
| 6647 | * |
| 6648 | * Return code |
| 6649 | * 0 - Successful (currently alway return 0) |
| 6650 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6651 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6652 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6653 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6654 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6655 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6656 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6657 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6658 | if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6659 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6660 | continue; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6661 | |
| 6662 | /* NVME Target mode does not do RSCN Recovery. */ |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 6663 | if (vport->phba->nvmet_support) |
| 6664 | continue; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6665 | |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 6666 | /* If we are in the process of doing discovery on this |
| 6667 | * NPort, let it continue on its own. |
| 6668 | */ |
| 6669 | switch (ndlp->nlp_state) { |
| 6670 | case NLP_STE_PLOGI_ISSUE: |
| 6671 | case NLP_STE_ADISC_ISSUE: |
| 6672 | case NLP_STE_REG_LOGIN_ISSUE: |
| 6673 | case NLP_STE_PRLI_ISSUE: |
| 6674 | case NLP_STE_LOGO_ISSUE: |
| 6675 | continue; |
| 6676 | } |
| 6677 | |
James Smart | a6d10f2 | 2019-08-14 16:56:50 -0700 | [diff] [blame] | 6678 | /* Check to see if we need to NVME rescan this target |
| 6679 | * remoteport. |
| 6680 | */ |
| 6681 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME && |
| 6682 | ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) |
James Smart | 6f2589f | 2019-05-14 14:58:07 -0700 | [diff] [blame] | 6683 | lpfc_nvme_rescan_port(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 6684 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6685 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6686 | NLP_EVT_DEVICE_RECOVERY); |
| 6687 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6688 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6689 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6690 | } |
| 6691 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6692 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6693 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6694 | * @vport: pointer to a host virtual N_Port data structure. |
| 6695 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6696 | * |
| 6697 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 6698 | * applications. |
| 6699 | */ |
| 6700 | static void |
| 6701 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 6702 | struct lpfc_iocbq *cmdiocb) |
| 6703 | { |
| 6704 | struct lpfc_dmabuf *pcmd; |
| 6705 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6706 | uint32_t *payload_ptr; |
| 6707 | uint32_t payload_len; |
| 6708 | struct lpfc_rscn_event_header *rscn_event_data; |
| 6709 | |
| 6710 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6711 | payload_ptr = (uint32_t *) pcmd->virt; |
| 6712 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 6713 | |
| 6714 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 6715 | payload_len, GFP_KERNEL); |
| 6716 | if (!rscn_event_data) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6717 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6718 | "0147 Failed to allocate memory for RSCN event\n"); |
| 6719 | return; |
| 6720 | } |
| 6721 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 6722 | rscn_event_data->payload_length = payload_len; |
| 6723 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 6724 | payload_len); |
| 6725 | |
| 6726 | fc_host_post_vendor_event(shost, |
| 6727 | fc_get_event_number(), |
Ales Novak | 6599eaa | 2015-08-31 16:48:16 -0400 | [diff] [blame] | 6728 | sizeof(struct lpfc_rscn_event_header) + payload_len, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6729 | (char *)rscn_event_data, |
| 6730 | LPFC_NL_VENDOR_ID); |
| 6731 | |
| 6732 | kfree(rscn_event_data); |
| 6733 | } |
| 6734 | |
| 6735 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6736 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6737 | * @vport: pointer to a host virtual N_Port data structure. |
| 6738 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6739 | * @ndlp: pointer to a node-list data structure. |
| 6740 | * |
| 6741 | * This routine processes an unsolicited RSCN (Registration State Change |
| 6742 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 6743 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 6744 | * discover state machine is about to begin discovery, it just accepts the |
| 6745 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 6746 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 6747 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 6748 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 6749 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 6750 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 6751 | * routine is invoked to handle the RSCN event. |
| 6752 | * |
| 6753 | * Return code |
| 6754 | * 0 - Just sent the acc response |
| 6755 | * 1 - Sent the acc response and waited for name server completion |
| 6756 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6757 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6758 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6759 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6760 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6761 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6762 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6763 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6764 | uint32_t *lp, *datap; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6765 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6766 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6767 | int rscn_id = 0, hba_id = 0; |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 6768 | int i, tmo; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6769 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6770 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6771 | lp = (uint32_t *) pcmd->virt; |
| 6772 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6773 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 6774 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6775 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6776 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6777 | "0214 RSCN received Data: x%x x%x x%x x%x\n", |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6778 | vport->fc_flag, payload_len, *lp, |
| 6779 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6780 | |
| 6781 | /* Send an RSCN event to the management application */ |
| 6782 | lpfc_send_rscn_event(vport, cmdiocb); |
| 6783 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 6784 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6785 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 6786 | FCH_EVT_RSCN, lp[i]); |
| 6787 | |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 6788 | /* Check if RSCN is coming from a direct-connected remote NPort */ |
| 6789 | if (vport->fc_flag & FC_PT2PT) { |
| 6790 | /* If so, just ACC it, no other action needed for now */ |
| 6791 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6792 | "2024 pt2pt RSCN %08x Data: x%x x%x\n", |
| 6793 | *lp, vport->fc_flag, payload_len); |
| 6794 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 6f2589f | 2019-05-14 14:58:07 -0700 | [diff] [blame] | 6795 | |
James Smart | a6d10f2 | 2019-08-14 16:56:50 -0700 | [diff] [blame] | 6796 | /* Check to see if we need to NVME rescan this target |
| 6797 | * remoteport. |
| 6798 | */ |
| 6799 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME && |
| 6800 | ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) |
James Smart | 6f2589f | 2019-05-14 14:58:07 -0700 | [diff] [blame] | 6801 | lpfc_nvme_rescan_port(vport, ndlp); |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 6802 | return 0; |
| 6803 | } |
| 6804 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6805 | /* If we are about to begin discovery, just ACC the RSCN. |
| 6806 | * Discovery processing will satisfy it. |
| 6807 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6808 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6809 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6810 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 6811 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6812 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6813 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6814 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6815 | } |
| 6816 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6817 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 6818 | * just ACC and ignore it. |
| 6819 | */ |
| 6820 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6821 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6822 | i = payload_len; |
| 6823 | datap = lp; |
| 6824 | while (i > 0) { |
| 6825 | nportid = *datap++; |
| 6826 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 6827 | i -= sizeof(uint32_t); |
| 6828 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6829 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 6830 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6831 | } |
| 6832 | if (rscn_id == hba_id) { |
| 6833 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6834 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6835 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6836 | "Data: x%x x%x x%x x%x\n", |
| 6837 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6838 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6839 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6840 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 6841 | ndlp->nlp_DID, vport->port_state, |
| 6842 | ndlp->nlp_flag); |
| 6843 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6844 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6845 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6846 | return 0; |
| 6847 | } |
| 6848 | } |
| 6849 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6850 | spin_lock_irq(shost->host_lock); |
| 6851 | if (vport->fc_rscn_flush) { |
| 6852 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6853 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 6854 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6855 | /* Send back ACC */ |
| 6856 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6857 | return 0; |
| 6858 | } |
| 6859 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 6860 | vport->fc_rscn_flush = 1; |
| 6861 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6862 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6863 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6864 | /* If we are already processing an RSCN, save the received |
| 6865 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 6866 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6867 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6868 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6869 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 6870 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6871 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6872 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6873 | vport->fc_flag |= FC_RSCN_DEFERRED; |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 6874 | |
| 6875 | /* Restart disctmo if its already running */ |
| 6876 | if (vport->fc_flag & FC_DISC_TMO) { |
| 6877 | tmo = ((phba->fc_ratov * 3) + 3); |
| 6878 | mod_timer(&vport->fc_disctmo, |
| 6879 | jiffies + msecs_to_jiffies(1000 * tmo)); |
| 6880 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6881 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6882 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6883 | vport->fc_flag |= FC_RSCN_MODE; |
| 6884 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6885 | if (rscn_cnt) { |
| 6886 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 6887 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 6888 | } |
| 6889 | if ((rscn_cnt) && |
| 6890 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 6891 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6892 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6893 | memcpy(((uint8_t *)cmd) + length, lp, |
| 6894 | payload_len); |
| 6895 | } else { |
| 6896 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 6897 | vport->fc_rscn_id_cnt++; |
| 6898 | /* If we zero, cmdiocb->context2, the calling |
| 6899 | * routine will not try to free it. |
| 6900 | */ |
| 6901 | cmdiocb->context2 = NULL; |
| 6902 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6903 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6904 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6905 | "0235 Deferred RSCN " |
| 6906 | "Data: x%x x%x x%x\n", |
| 6907 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 6908 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6909 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6910 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 6911 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6912 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6913 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6914 | "0234 ReDiscovery RSCN " |
| 6915 | "Data: x%x x%x x%x\n", |
| 6916 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 6917 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6918 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6919 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 6920 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6921 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6922 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6923 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6924 | lpfc_rscn_recovery_check(vport); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6925 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6926 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6927 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6928 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 6929 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6930 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6931 | spin_lock_irq(shost->host_lock); |
| 6932 | vport->fc_flag |= FC_RSCN_MODE; |
| 6933 | spin_unlock_irq(shost->host_lock); |
| 6934 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6935 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 6936 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6937 | /* |
| 6938 | * If we zero, cmdiocb->context2, the calling routine will |
| 6939 | * not try to free it. |
| 6940 | */ |
| 6941 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6942 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6943 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6944 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6945 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6946 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6947 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6948 | } |
| 6949 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6950 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6951 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6952 | * @vport: pointer to a host virtual N_Port data structure. |
| 6953 | * |
| 6954 | * This routine handles the Registration State Configuration Notification |
| 6955 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 6956 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 6957 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 6958 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 6959 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 6960 | * RSCN activities with the @vport. |
| 6961 | * |
| 6962 | * Return code |
| 6963 | * 0 - Cleaned up rscn on the @vport |
| 6964 | * 1 - Wait for plogi to name server before proceed |
| 6965 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6966 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6967 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6968 | { |
| 6969 | struct lpfc_nodelist *ndlp; |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 6970 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6971 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6972 | /* Ignore RSCN if the port is being torn down. */ |
| 6973 | if (vport->load_flag & FC_UNLOADING) { |
| 6974 | lpfc_els_flush_rscn(vport); |
| 6975 | return 0; |
| 6976 | } |
| 6977 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6978 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6979 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6980 | |
| 6981 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6982 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 6983 | "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6984 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 6985 | vport->port_state, vport->num_disc_nodes, |
| 6986 | vport->gidft_inp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6987 | |
| 6988 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6989 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 6990 | vport->num_disc_nodes = 0; |
| 6991 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6992 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6993 | if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6994 | /* Good ndlp, issue CT Request to NameServer. Need to |
| 6995 | * know how many gidfts were issued. If none, then just |
| 6996 | * flush the RSCN. Otherwise, the outstanding requests |
| 6997 | * need to complete. |
| 6998 | */ |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 6999 | if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) { |
| 7000 | if (lpfc_issue_gidft(vport) > 0) |
| 7001 | return 1; |
| 7002 | } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) { |
| 7003 | if (lpfc_issue_gidpt(vport) > 0) |
| 7004 | return 1; |
| 7005 | } else { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7006 | return 1; |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 7007 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7008 | } else { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 7009 | /* Nameserver login in question. Revalidate. */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7010 | if (ndlp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7011 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 7012 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7013 | } else { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 7014 | ndlp = lpfc_nlp_init(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7015 | if (!ndlp) { |
| 7016 | lpfc_els_flush_rscn(vport); |
| 7017 | return 0; |
| 7018 | } |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7019 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7020 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7021 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7022 | ndlp->nlp_type |= NLP_FABRIC; |
| 7023 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 7024 | /* Wait for NameServer login cmpl before we can |
| 7025 | * continue |
| 7026 | */ |
| 7027 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7028 | } |
| 7029 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7030 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7031 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7032 | } |
| 7033 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7034 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7035 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7036 | * @vport: pointer to a host virtual N_Port data structure. |
| 7037 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7038 | * @ndlp: pointer to a node-list data structure. |
| 7039 | * |
| 7040 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 7041 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 7042 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 7043 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 7044 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 7045 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 7046 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 7047 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 7048 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 7049 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 7050 | * higher priority (as the winning port) and will initiate PLOGI and |
| 7051 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 7052 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 7053 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 7054 | * |
| 7055 | * Return code |
| 7056 | * 0 - Successfully processed the unsolicited flogi |
| 7057 | * 1 - Failed to process the unsolicited flogi |
| 7058 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7059 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7060 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7061 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7062 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7063 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7064 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7065 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7066 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 7067 | IOCB_t *icmd = &cmdiocb->iocb; |
| 7068 | struct serv_parm *sp; |
| 7069 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7070 | uint32_t cmd, did; |
| 7071 | int rc; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7072 | uint32_t fc_flag = 0; |
| 7073 | uint32_t port_state = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7074 | |
| 7075 | cmd = *lp++; |
| 7076 | sp = (struct serv_parm *) lp; |
| 7077 | |
| 7078 | /* FLOGI received */ |
| 7079 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7080 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7081 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7082 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7083 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 7084 | did = icmd->un.elsreq64.remoteID; |
| 7085 | |
| 7086 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 7087 | Loop Mode */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7088 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7089 | "0113 An FLOGI ELS command x%x was " |
| 7090 | "received from DID x%x in Loop Mode\n", |
| 7091 | cmd, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7092 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7093 | } |
| 7094 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7095 | (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7096 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7097 | /* |
| 7098 | * If our portname is greater than the remote portname, |
| 7099 | * then we initiate Nport login. |
| 7100 | */ |
| 7101 | |
| 7102 | rc = memcmp(&vport->fc_portname, &sp->portName, |
| 7103 | sizeof(struct lpfc_name)); |
| 7104 | |
| 7105 | if (!rc) { |
| 7106 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 7107 | mbox = mempool_alloc(phba->mbox_mem_pool, |
| 7108 | GFP_KERNEL); |
| 7109 | if (!mbox) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7110 | return 1; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7111 | lpfc_linkdown(phba); |
| 7112 | lpfc_init_link(phba, mbox, |
| 7113 | phba->cfg_topology, |
| 7114 | phba->cfg_link_speed); |
| 7115 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 7116 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 7117 | mbox->vport = vport; |
| 7118 | rc = lpfc_sli_issue_mbox(phba, mbox, |
| 7119 | MBX_NOWAIT); |
| 7120 | lpfc_set_loopback_flag(phba); |
| 7121 | if (rc == MBX_NOT_FINISHED) |
| 7122 | mempool_free(mbox, phba->mbox_mem_pool); |
| 7123 | return 1; |
| 7124 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7125 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7126 | /* abort the flogi coming back to ourselves |
| 7127 | * due to external loopback on the port. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7128 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7129 | lpfc_els_abort_flogi(phba); |
| 7130 | return 0; |
| 7131 | |
| 7132 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7133 | spin_lock_irq(shost->host_lock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7134 | vport->fc_flag |= FC_PT2PT_PLOGI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7135 | spin_unlock_irq(shost->host_lock); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7136 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7137 | /* If we have the high WWPN we can assign our own |
| 7138 | * myDID; otherwise, we have to WAIT for a PLOGI |
| 7139 | * from the remote NPort to find out what it |
| 7140 | * will be. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7141 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7142 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7143 | } else { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7144 | vport->fc_myDID = PT2PT_RemoteID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7145 | } |
| 7146 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7147 | /* |
| 7148 | * The vport state should go to LPFC_FLOGI only |
| 7149 | * AFTER we issue a FLOGI, not receive one. |
| 7150 | */ |
| 7151 | spin_lock_irq(shost->host_lock); |
| 7152 | fc_flag = vport->fc_flag; |
| 7153 | port_state = vport->port_state; |
| 7154 | vport->fc_flag |= FC_PT2PT; |
| 7155 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 7156 | |
| 7157 | /* Acking an unsol FLOGI. Count 1 for link bounce |
| 7158 | * work-around. |
| 7159 | */ |
| 7160 | vport->rcv_flogi_cnt++; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7161 | spin_unlock_irq(shost->host_lock); |
| 7162 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7163 | "3311 Rcv Flogi PS x%x new PS x%x " |
| 7164 | "fc_flag x%x new fc_flag x%x\n", |
| 7165 | port_state, vport->port_state, |
| 7166 | fc_flag, vport->fc_flag); |
| 7167 | |
| 7168 | /* |
| 7169 | * We temporarily set fc_myDID to make it look like we are |
| 7170 | * a Fabric. This is done just so we end up with the right |
| 7171 | * did / sid on the FLOGI ACC rsp. |
| 7172 | */ |
| 7173 | did = vport->fc_myDID; |
| 7174 | vport->fc_myDID = Fabric_DID; |
| 7175 | |
| 7176 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7177 | |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 7178 | /* Defer ACC response until AFTER we issue a FLOGI */ |
| 7179 | if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) { |
| 7180 | phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext; |
| 7181 | phba->defer_flogi_acc_ox_id = |
| 7182 | cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
| 7183 | |
| 7184 | vport->fc_myDID = did; |
| 7185 | |
| 7186 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7187 | "3344 Deferring FLOGI ACC: rx_id: x%x," |
| 7188 | " ox_id: x%x, hba_flag x%x\n", |
| 7189 | phba->defer_flogi_acc_rx_id, |
| 7190 | phba->defer_flogi_acc_ox_id, phba->hba_flag); |
| 7191 | |
| 7192 | phba->defer_flogi_acc_flag = true; |
| 7193 | |
| 7194 | return 0; |
| 7195 | } |
| 7196 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7197 | /* Send back ACC */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7198 | lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7199 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7200 | /* Now lets put fc_myDID back to what its supposed to be */ |
| 7201 | vport->fc_myDID = did; |
| 7202 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7203 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7204 | } |
| 7205 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7206 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7207 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7208 | * @vport: pointer to a host virtual N_Port data structure. |
| 7209 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7210 | * @ndlp: pointer to a node-list data structure. |
| 7211 | * |
| 7212 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 7213 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 7214 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 7215 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 7216 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 7217 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 7218 | * |
| 7219 | * Return code |
| 7220 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 7221 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7222 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7223 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7224 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7225 | { |
| 7226 | struct lpfc_dmabuf *pcmd; |
| 7227 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7228 | RNID *rn; |
| 7229 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7230 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7231 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7232 | lp = (uint32_t *) pcmd->virt; |
| 7233 | |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7234 | lp++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7235 | rn = (RNID *) lp; |
| 7236 | |
| 7237 | /* RNID received */ |
| 7238 | |
| 7239 | switch (rn->Format) { |
| 7240 | case 0: |
| 7241 | case RNID_TOPOLOGY_DISC: |
| 7242 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7243 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7244 | break; |
| 7245 | default: |
| 7246 | /* Reject this request because format not supported */ |
| 7247 | stat.un.b.lsRjtRsvd0 = 0; |
| 7248 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7249 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7250 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7251 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 7252 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7253 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7254 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7255 | } |
| 7256 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7257 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7258 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 7259 | * @vport: pointer to a host virtual N_Port data structure. |
| 7260 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7261 | * @ndlp: pointer to a node-list data structure. |
| 7262 | * |
| 7263 | * Return code |
| 7264 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 7265 | **/ |
| 7266 | static int |
| 7267 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7268 | struct lpfc_nodelist *ndlp) |
| 7269 | { |
| 7270 | uint8_t *pcmd; |
| 7271 | |
| 7272 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 7273 | |
| 7274 | /* skip over first word of echo command to find echo data */ |
| 7275 | pcmd += sizeof(uint32_t); |
| 7276 | |
| 7277 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 7278 | return 0; |
| 7279 | } |
| 7280 | |
| 7281 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7282 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7283 | * @vport: pointer to a host virtual N_Port data structure. |
| 7284 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7285 | * @ndlp: pointer to a node-list data structure. |
| 7286 | * |
| 7287 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 7288 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 7289 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 7290 | * |
| 7291 | * Return code |
| 7292 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 7293 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7294 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7295 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7296 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7297 | { |
| 7298 | struct ls_rjt stat; |
| 7299 | |
| 7300 | /* For now, unconditionally reject this command */ |
| 7301 | stat.un.b.lsRjtRsvd0 = 0; |
| 7302 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7303 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7304 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7305 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7306 | return 0; |
| 7307 | } |
| 7308 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7309 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7310 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 7311 | * @vport: pointer to a host virtual N_Port data structure. |
| 7312 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7313 | * @ndlp: pointer to a node-list data structure. |
| 7314 | * |
| 7315 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 7316 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 7317 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 7318 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 7319 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 7320 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 7321 | * command request" and reason code explanation "Invalid Originator |
| 7322 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 7323 | * RRQ from the target. |
| 7324 | **/ |
| 7325 | static void |
| 7326 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7327 | struct lpfc_nodelist *ndlp) |
| 7328 | { |
| 7329 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7330 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 7331 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7332 | } |
| 7333 | |
| 7334 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7335 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 7336 | * @phba: pointer to lpfc hba data structure. |
| 7337 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 7338 | * |
| 7339 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 7340 | * mailbox command. This callback function is to actually send the Accept |
| 7341 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 7342 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 7343 | * mailbox command, constructs the RPS response with the link statistics |
| 7344 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 7345 | * response to the RPS. |
| 7346 | * |
| 7347 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7348 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7349 | * will be stored into the context1 field of the IOCB for the completion |
| 7350 | * callback function to the RPS Accept Response ELS IOCB command. |
| 7351 | * |
| 7352 | **/ |
| 7353 | static void |
| 7354 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 7355 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 7356 | int rc = 0; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7357 | MAILBOX_t *mb; |
| 7358 | IOCB_t *icmd; |
| 7359 | struct RLS_RSP *rls_rsp; |
| 7360 | uint8_t *pcmd; |
| 7361 | struct lpfc_iocbq *elsiocb; |
| 7362 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7363 | uint16_t oxid; |
| 7364 | uint16_t rxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7365 | uint32_t cmdsize; |
| 7366 | |
| 7367 | mb = &pmb->u.mb; |
| 7368 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7369 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 7370 | rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff); |
| 7371 | oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff); |
| 7372 | pmb->ctx_buf = NULL; |
| 7373 | pmb->ctx_ndlp = NULL; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7374 | |
| 7375 | if (mb->mbxStatus) { |
| 7376 | mempool_free(pmb, phba->mbox_mem_pool); |
| 7377 | return; |
| 7378 | } |
| 7379 | |
| 7380 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7381 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 7382 | lpfc_max_els_tries, ndlp, |
| 7383 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 7384 | |
| 7385 | /* Decrement the ndlp reference count from previous mbox command */ |
| 7386 | lpfc_nlp_put(ndlp); |
| 7387 | |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 7388 | if (!elsiocb) { |
| 7389 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7390 | return; |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 7391 | } |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7392 | |
| 7393 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7394 | icmd->ulpContext = rxid; |
| 7395 | icmd->unsli3.rcvsli3.ox_id = oxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7396 | |
| 7397 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7398 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 7399 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 7400 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 7401 | |
| 7402 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 7403 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 7404 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 7405 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 7406 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 7407 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 7408 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7409 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 7410 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 7411 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 7412 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 7413 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 7414 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 7415 | ndlp->nlp_rpi); |
| 7416 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 7417 | phba->fc_stat.elsXmitACC++; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 7418 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 7419 | if (!elsiocb->context1) |
| 7420 | goto node_err; |
| 7421 | |
| 7422 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 7423 | if (rc == IOCB_ERROR) |
| 7424 | goto io_err; |
| 7425 | return; |
| 7426 | |
| 7427 | io_err: |
| 7428 | lpfc_nlp_put(ndlp); |
| 7429 | node_err: |
| 7430 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7431 | } |
| 7432 | |
| 7433 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7434 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 7435 | * @vport: pointer to a host virtual N_Port data structure. |
| 7436 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7437 | * @ndlp: pointer to a node-list data structure. |
| 7438 | * |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7439 | * This routine processes Read Link Status (RLS) IOCB received as an |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7440 | * ELS unsolicited event. It first checks the remote port state. If the |
| 7441 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 7442 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 7443 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 7444 | * for reading the HBA link statistics. It is for the callback function, |
| 7445 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 7446 | * to actually sending out RPL Accept (ACC) response. |
| 7447 | * |
| 7448 | * Return codes |
| 7449 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 7450 | **/ |
| 7451 | static int |
| 7452 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7453 | struct lpfc_nodelist *ndlp) |
| 7454 | { |
| 7455 | struct lpfc_hba *phba = vport->phba; |
| 7456 | LPFC_MBOXQ_t *mbox; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7457 | struct ls_rjt stat; |
| 7458 | |
| 7459 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 7460 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7461 | /* reject the unsolicited RLS request and done with it */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7462 | goto reject_out; |
| 7463 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7464 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 7465 | if (mbox) { |
| 7466 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7467 | mbox->ctx_buf = (void *)((unsigned long) |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7468 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 7469 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7470 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 7471 | if (!mbox->ctx_ndlp) |
| 7472 | goto node_err; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7473 | mbox->vport = vport; |
| 7474 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 7475 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 7476 | != MBX_NOT_FINISHED) |
| 7477 | /* Mbox completion will send ELS Response */ |
| 7478 | return 0; |
| 7479 | /* Decrement reference count used for the failed mbox |
| 7480 | * command. |
| 7481 | */ |
| 7482 | lpfc_nlp_put(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 7483 | node_err: |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7484 | mempool_free(mbox, phba->mbox_mem_pool); |
| 7485 | } |
| 7486 | reject_out: |
| 7487 | /* issue rejection response */ |
| 7488 | stat.un.b.lsRjtRsvd0 = 0; |
| 7489 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7490 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7491 | stat.un.b.vendorUnique = 0; |
| 7492 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 7493 | return 0; |
| 7494 | } |
| 7495 | |
| 7496 | /** |
| 7497 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 7498 | * @vport: pointer to a host virtual N_Port data structure. |
| 7499 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7500 | * @ndlp: pointer to a node-list data structure. |
| 7501 | * |
| 7502 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 7503 | * ELS unsolicited event. It first checks the remote port state. If the |
| 7504 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 7505 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 7506 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 7507 | * Value (RTV) unsolicited IOCB event. |
| 7508 | * |
| 7509 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7510 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7511 | * will be stored into the context1 field of the IOCB for the completion |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7512 | * callback function to the RTV Accept Response ELS IOCB command. |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7513 | * |
| 7514 | * Return codes |
| 7515 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 7516 | **/ |
| 7517 | static int |
| 7518 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7519 | struct lpfc_nodelist *ndlp) |
| 7520 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 7521 | int rc = 0; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7522 | struct lpfc_hba *phba = vport->phba; |
| 7523 | struct ls_rjt stat; |
| 7524 | struct RTV_RSP *rtv_rsp; |
| 7525 | uint8_t *pcmd; |
| 7526 | struct lpfc_iocbq *elsiocb; |
| 7527 | uint32_t cmdsize; |
| 7528 | |
| 7529 | |
| 7530 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 7531 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7532 | /* reject the unsolicited RTV request and done with it */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7533 | goto reject_out; |
| 7534 | |
| 7535 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 7536 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 7537 | lpfc_max_els_tries, ndlp, |
| 7538 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 7539 | |
| 7540 | if (!elsiocb) |
| 7541 | return 1; |
| 7542 | |
| 7543 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
Colin Ian King | 8fd03fd | 2017-12-22 00:39:36 +0000 | [diff] [blame] | 7544 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7545 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 7546 | |
| 7547 | /* use the command's xri in the response */ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7548 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 7549 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7550 | |
| 7551 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 7552 | |
| 7553 | /* populate RTV payload */ |
| 7554 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 7555 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 7556 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 7557 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 7558 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 7559 | |
| 7560 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 7561 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 7562 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 7563 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 7564 | "Data: x%x x%x x%x\n", |
| 7565 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 7566 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 7567 | ndlp->nlp_rpi, |
| 7568 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 7569 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 7570 | phba->fc_stat.elsXmitACC++; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 7571 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 7572 | if (!elsiocb->context1) { |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7573 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 7574 | return 0; |
| 7575 | } |
| 7576 | |
| 7577 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 7578 | if (rc == IOCB_ERROR) { |
| 7579 | lpfc_nlp_put(ndlp); |
| 7580 | lpfc_els_free_iocb(phba, elsiocb); |
| 7581 | } |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7582 | return 0; |
| 7583 | |
| 7584 | reject_out: |
| 7585 | /* issue rejection response */ |
| 7586 | stat.un.b.lsRjtRsvd0 = 0; |
| 7587 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7588 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7589 | stat.un.b.vendorUnique = 0; |
| 7590 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 7591 | return 0; |
| 7592 | } |
| 7593 | |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7594 | /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7595 | * @vport: pointer to a host virtual N_Port data structure. |
| 7596 | * @ndlp: pointer to a node-list data structure. |
| 7597 | * @did: DID of the target. |
| 7598 | * @rrq: Pointer to the rrq struct. |
| 7599 | * |
| 7600 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is |
| 7601 | * Successful the the completion handler will clear the RRQ. |
| 7602 | * |
| 7603 | * Return codes |
| 7604 | * 0 - Successfully sent rrq els iocb. |
| 7605 | * 1 - Failed to send rrq els iocb. |
| 7606 | **/ |
| 7607 | static int |
| 7608 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 7609 | uint32_t did, struct lpfc_node_rrq *rrq) |
| 7610 | { |
| 7611 | struct lpfc_hba *phba = vport->phba; |
| 7612 | struct RRQ *els_rrq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7613 | struct lpfc_iocbq *elsiocb; |
| 7614 | uint8_t *pcmd; |
| 7615 | uint16_t cmdsize; |
| 7616 | int ret; |
| 7617 | |
| 7618 | |
| 7619 | if (ndlp != rrq->ndlp) |
| 7620 | ndlp = rrq->ndlp; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 7621 | if (!ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7622 | return 1; |
| 7623 | |
| 7624 | /* If ndlp is not NULL, we will bump the reference count on it */ |
| 7625 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); |
| 7626 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, |
| 7627 | ELS_CMD_RRQ); |
| 7628 | if (!elsiocb) |
| 7629 | return 1; |
| 7630 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7631 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7632 | |
| 7633 | /* For RRQ request, remainder of payload is Exchange IDs */ |
| 7634 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; |
| 7635 | pcmd += sizeof(uint32_t); |
| 7636 | els_rrq = (struct RRQ *) pcmd; |
| 7637 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 7638 | bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7639 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
| 7640 | bf_set(rrq_did, els_rrq, vport->fc_myDID); |
| 7641 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); |
| 7642 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); |
| 7643 | |
| 7644 | |
| 7645 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7646 | "Issue RRQ: did:x%x", |
| 7647 | did, rrq->xritag, rrq->rxid); |
| 7648 | elsiocb->context_un.rrq = rrq; |
| 7649 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 7650 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 7651 | if (!elsiocb->context1) |
| 7652 | goto node_err; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7653 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 7654 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 7655 | if (ret == IOCB_ERROR) |
| 7656 | goto io_err; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7657 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 7658 | |
| 7659 | io_err: |
| 7660 | lpfc_nlp_put(ndlp); |
| 7661 | node_err: |
| 7662 | lpfc_els_free_iocb(phba, elsiocb); |
| 7663 | return 1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7664 | } |
| 7665 | |
| 7666 | /** |
| 7667 | * lpfc_send_rrq - Sends ELS RRQ if needed. |
| 7668 | * @phba: pointer to lpfc hba data structure. |
| 7669 | * @rrq: pointer to the active rrq. |
| 7670 | * |
| 7671 | * This routine will call the lpfc_issue_els_rrq if the rrq is |
| 7672 | * still active for the xri. If this function returns a failure then |
| 7673 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. |
| 7674 | * |
| 7675 | * Returns 0 Success. |
| 7676 | * 1 Failure. |
| 7677 | **/ |
| 7678 | int |
| 7679 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) |
| 7680 | { |
| 7681 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, |
James Smart | c8cb261 | 2019-05-06 17:26:49 -0700 | [diff] [blame] | 7682 | rrq->nlp_DID); |
| 7683 | if (!ndlp) |
| 7684 | return 1; |
| 7685 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7686 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) |
| 7687 | return lpfc_issue_els_rrq(rrq->vport, ndlp, |
| 7688 | rrq->nlp_DID, rrq); |
| 7689 | else |
| 7690 | return 1; |
| 7691 | } |
| 7692 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7693 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7694 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7695 | * @vport: pointer to a host virtual N_Port data structure. |
| 7696 | * @cmdsize: size of the ELS command. |
| 7697 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 7698 | * @ndlp: pointer to a node-list data structure. |
| 7699 | * |
| 7700 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 7701 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 7702 | * |
| 7703 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7704 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7705 | * will be stored into the context1 field of the IOCB for the completion |
| 7706 | * callback function to the RPL Accept Response ELS command. |
| 7707 | * |
| 7708 | * Return code |
| 7709 | * 0 - Successfully issued ACC RPL ELS command |
| 7710 | * 1 - Failed to issue ACC RPL ELS command |
| 7711 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 7712 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7713 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 7714 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7715 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 7716 | int rc = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7717 | struct lpfc_hba *phba = vport->phba; |
| 7718 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7719 | RPL_RSP rpl_rsp; |
| 7720 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7721 | uint8_t *pcmd; |
| 7722 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7723 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 7724 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7725 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 7726 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7727 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 7728 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7729 | icmd = &elsiocb->iocb; |
| 7730 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7731 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 7732 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7733 | |
| 7734 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7735 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7736 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7737 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 7738 | pcmd += sizeof(uint16_t); |
| 7739 | |
| 7740 | /* Setup the RPL ACC payload */ |
| 7741 | rpl_rsp.listLen = be32_to_cpu(1); |
| 7742 | rpl_rsp.index = 0; |
| 7743 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7744 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 7745 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7746 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7747 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7748 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7749 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7750 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 7751 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 7752 | "rpi x%x\n", |
| 7753 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 7754 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 7755 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7756 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7757 | phba->fc_stat.elsXmitACC++; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 7758 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 7759 | if (!elsiocb->context1) |
| 7760 | goto node_err; |
| 7761 | |
| 7762 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 7763 | if (rc == IOCB_ERROR) |
| 7764 | goto io_err; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7765 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 7766 | |
| 7767 | io_err: |
| 7768 | lpfc_nlp_put(ndlp); |
| 7769 | node_err: |
| 7770 | lpfc_els_free_iocb(phba, elsiocb); |
| 7771 | return 1; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7772 | } |
| 7773 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7774 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7775 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7776 | * @vport: pointer to a host virtual N_Port data structure. |
| 7777 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7778 | * @ndlp: pointer to a node-list data structure. |
| 7779 | * |
| 7780 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 7781 | * unsolicited event. It first checks the remote port state. If the remote |
| 7782 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 7783 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 7784 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 7785 | * to accept the RPL. |
| 7786 | * |
| 7787 | * Return code |
| 7788 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 7789 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7790 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7791 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7792 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7793 | { |
| 7794 | struct lpfc_dmabuf *pcmd; |
| 7795 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7796 | uint32_t maxsize; |
| 7797 | uint16_t cmdsize; |
| 7798 | RPL *rpl; |
| 7799 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7800 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 7801 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 7802 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 7803 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7804 | stat.un.b.lsRjtRsvd0 = 0; |
| 7805 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7806 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7807 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7808 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 7809 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 7810 | /* rejected the unsolicited RPL request and done with it */ |
| 7811 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7812 | } |
| 7813 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7814 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7815 | lp = (uint32_t *) pcmd->virt; |
| 7816 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7817 | maxsize = be32_to_cpu(rpl->maxsize); |
| 7818 | |
| 7819 | /* We support only one port */ |
| 7820 | if ((rpl->index == 0) && |
| 7821 | ((maxsize == 0) || |
| 7822 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 7823 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 7824 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7825 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 7826 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7827 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7828 | |
| 7829 | return 0; |
| 7830 | } |
| 7831 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7832 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7833 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7834 | * @vport: pointer to a virtual N_Port data structure. |
| 7835 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7836 | * @ndlp: pointer to a node-list data structure. |
| 7837 | * |
| 7838 | * This routine processes Fibre Channel Address Resolution Protocol |
| 7839 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 7840 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 7841 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 7842 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 7843 | * remote PortName is compared against the FC PortName stored in the @vport |
| 7844 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 7845 | * compared against the FC NodeName stored in the @vport data structure. |
| 7846 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 7847 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 7848 | * invoked to send out FARP Response to the remote node. Before sending the |
| 7849 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 7850 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 7851 | * routine is invoked to log into the remote port first. |
| 7852 | * |
| 7853 | * Return code |
| 7854 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 7855 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7856 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7857 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7858 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7859 | { |
| 7860 | struct lpfc_dmabuf *pcmd; |
| 7861 | uint32_t *lp; |
| 7862 | IOCB_t *icmd; |
| 7863 | FARP *fp; |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7864 | uint32_t cnt, did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7865 | |
| 7866 | icmd = &cmdiocb->iocb; |
| 7867 | did = icmd->un.elsreq64.remoteID; |
| 7868 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7869 | lp = (uint32_t *) pcmd->virt; |
| 7870 | |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7871 | lp++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7872 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7873 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7874 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7875 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7876 | /* We will only support match on WWPN or WWNN */ |
| 7877 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7878 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7879 | } |
| 7880 | |
| 7881 | cnt = 0; |
| 7882 | /* If this FARP command is searching for my portname */ |
| 7883 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7884 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7885 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7886 | cnt = 1; |
| 7887 | } |
| 7888 | |
| 7889 | /* If this FARP command is searching for my nodename */ |
| 7890 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7891 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7892 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7893 | cnt = 1; |
| 7894 | } |
| 7895 | |
| 7896 | if (cnt) { |
| 7897 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 7898 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 7899 | /* Log back into the node before sending the FARP. */ |
| 7900 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7901 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7902 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 7903 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7904 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7905 | } |
| 7906 | |
| 7907 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7908 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 7909 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7910 | } |
| 7911 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7912 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7913 | } |
| 7914 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7915 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7916 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7917 | * @vport: pointer to a host virtual N_Port data structure. |
| 7918 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7919 | * @ndlp: pointer to a node-list data structure. |
| 7920 | * |
| 7921 | * This routine processes Fibre Channel Address Resolution Protocol |
| 7922 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 7923 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 7924 | * the FARP response request. |
| 7925 | * |
| 7926 | * Return code |
| 7927 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 7928 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7929 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7930 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7931 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7932 | { |
| 7933 | struct lpfc_dmabuf *pcmd; |
| 7934 | uint32_t *lp; |
| 7935 | IOCB_t *icmd; |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7936 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7937 | |
| 7938 | icmd = &cmdiocb->iocb; |
| 7939 | did = icmd->un.elsreq64.remoteID; |
| 7940 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7941 | lp = (uint32_t *) pcmd->virt; |
| 7942 | |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7943 | lp++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7944 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7945 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7946 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7947 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7948 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7949 | |
| 7950 | return 0; |
| 7951 | } |
| 7952 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7953 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7954 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7955 | * @vport: pointer to a host virtual N_Port data structure. |
| 7956 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7957 | * @fan_ndlp: pointer to a node-list data structure. |
| 7958 | * |
| 7959 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 7960 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 7961 | * only be processed on a physical port (i.e., the @vport represents the |
| 7962 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 7963 | * compared against those in the phba data structure. If any of those is |
| 7964 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 7965 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 7966 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 7967 | * is invoked to register login to the fabric. |
| 7968 | * |
| 7969 | * Return code |
| 7970 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 7971 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7972 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7973 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7974 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7975 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7976 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7977 | uint32_t *lp; |
| 7978 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7979 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7980 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 7981 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 7982 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7983 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7984 | if ((vport == phba->pport) && |
| 7985 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7986 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7987 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7988 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7989 | sizeof(struct lpfc_name)))) { |
| 7990 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7991 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7992 | } else { |
| 7993 | /* FAN verified - skip FLOGI */ |
| 7994 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7995 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 7996 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7997 | else { |
| 7998 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7999 | "3138 Need register VFI: (x%x/%x)\n", |
| 8000 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8001 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8002 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8003 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8004 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 8005 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8006 | } |
| 8007 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8008 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8009 | * lpfc_els_timeout - Handler funciton to the els timer |
Lee Jones | a0e4a64 | 2020-07-23 13:24:07 +0100 | [diff] [blame] | 8010 | * @t: timer context used to obtain the vport. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8011 | * |
| 8012 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 8013 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 8014 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 8015 | * up the worker thread. It is for the worker thread to invoke the routine |
| 8016 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 8017 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8018 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 8019 | lpfc_els_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8020 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 8021 | struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8022 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8023 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8024 | unsigned long iflag; |
| 8025 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8026 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8027 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 8028 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8029 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8030 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8031 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 8032 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8033 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8034 | return; |
| 8035 | } |
| 8036 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8037 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8038 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8039 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8040 | * @vport: pointer to a virtual N_Port data structure. |
| 8041 | * |
| 8042 | * This routine is the actual handler function that processes an ELS timeout |
| 8043 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 8044 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 8045 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 8046 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8047 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8048 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8049 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8050 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8051 | struct lpfc_sli_ring *pring; |
| 8052 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 8053 | IOCB_t *cmd = NULL; |
| 8054 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8055 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8056 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8057 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8058 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8059 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8060 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8061 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 8062 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8063 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 8064 | if (unlikely(!pring)) |
| 8065 | return; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8066 | |
James Smart | e304142 | 2020-04-21 13:33:54 -0700 | [diff] [blame] | 8067 | if (phba->pport->load_flag & FC_UNLOADING) |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 8068 | return; |
James Smart | e304142 | 2020-04-21 13:33:54 -0700 | [diff] [blame] | 8069 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8070 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8071 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8072 | spin_lock(&pring->ring_lock); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8073 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8074 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8075 | cmd = &piocb->iocb; |
| 8076 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8077 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 8078 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 8079 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8080 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8081 | |
| 8082 | if (piocb->vport != vport) |
| 8083 | continue; |
| 8084 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8085 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8086 | if (pcmd) |
| 8087 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8088 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8089 | if (els_command == ELS_CMD_FARP || |
| 8090 | els_command == ELS_CMD_FARPR || |
| 8091 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8092 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8093 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8094 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8095 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8096 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8097 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8098 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8099 | continue; |
| 8100 | } |
| 8101 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8102 | remote_ID = 0xffffffff; |
| 8103 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8104 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8105 | else { |
| 8106 | struct lpfc_nodelist *ndlp; |
| 8107 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 8108 | if (ndlp) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8109 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8110 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8111 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8112 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8113 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8114 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8115 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 8116 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8117 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
James Smart | 15026c9 | 2013-12-17 20:30:09 -0500 | [diff] [blame] | 8118 | cmd = &piocb->iocb; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8119 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8120 | "0127 ELS timeout Data: x%x x%x x%x " |
| 8121 | "x%x\n", els_command, |
| 8122 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 8123 | spin_lock_irq(&phba->hbalock); |
| 8124 | list_del_init(&piocb->dlist); |
| 8125 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 8126 | spin_unlock_irq(&phba->hbalock); |
| 8127 | } |
| 8128 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8129 | if (!list_empty(&pring->txcmplq)) |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 8130 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 8131 | mod_timer(&vport->els_tmofunc, |
| 8132 | jiffies + msecs_to_jiffies(1000 * timeout)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8133 | } |
| 8134 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8135 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8136 | * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8137 | * @vport: pointer to a host virtual N_Port data structure. |
| 8138 | * |
| 8139 | * This routine is used to clean up all the outstanding ELS commands on a |
| 8140 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 8141 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 8142 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 8143 | * the IOCBs with a non-NULL completion callback function, the callback |
| 8144 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 8145 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 8146 | * callback function, the IOCB will simply be released. Finally, it walks |
| 8147 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 8148 | * completion queue IOCB that is associated with the @vport and is not |
| 8149 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 8150 | * part of the discovery state machine) out to HBA by invoking the |
| 8151 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 8152 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 8153 | * the IOCBs are aborted when this function returns. |
| 8154 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8155 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8156 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8157 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8158 | LIST_HEAD(abort_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8159 | struct lpfc_hba *phba = vport->phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8160 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8161 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 8162 | IOCB_t *cmd = NULL; |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8163 | unsigned long iflags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8164 | |
| 8165 | lpfc_fabric_abort_vport(vport); |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8166 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8167 | /* |
| 8168 | * For SLI3, only the hbalock is required. But SLI4 needs to coordinate |
| 8169 | * with the ring insert operation. Because lpfc_sli_issue_abort_iotag |
| 8170 | * ultimately grabs the ring_lock, the driver must splice the list into |
| 8171 | * a working list and release the locks before calling the abort. |
| 8172 | */ |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8173 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8174 | pring = lpfc_phba_elsring(phba); |
Guilherme G. Piccoli | 53cf29d | 2017-05-17 19:02:17 -0300 | [diff] [blame] | 8175 | |
| 8176 | /* Bail out if we've no ELS wq, like in PCI error recovery case. */ |
| 8177 | if (unlikely(!pring)) { |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8178 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
Guilherme G. Piccoli | 53cf29d | 2017-05-17 19:02:17 -0300 | [diff] [blame] | 8179 | return; |
| 8180 | } |
| 8181 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8182 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8183 | spin_lock(&pring->ring_lock); |
| 8184 | |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8185 | /* First we need to issue aborts to outstanding cmds on txcmpl */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8186 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 8187 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 8188 | continue; |
| 8189 | |
| 8190 | if (piocb->vport != vport) |
| 8191 | continue; |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8192 | |
James Smart | 15498dc | 2019-09-21 20:58:59 -0700 | [diff] [blame] | 8193 | if (piocb->iocb_flag & LPFC_DRIVER_ABORTED) |
| 8194 | continue; |
| 8195 | |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8196 | /* On the ELS ring we can have ELS_REQUESTs or |
| 8197 | * GEN_REQUESTs waiting for a response. |
| 8198 | */ |
| 8199 | cmd = &piocb->iocb; |
| 8200 | if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| 8201 | list_add_tail(&piocb->dlist, &abort_list); |
| 8202 | |
| 8203 | /* If the link is down when flushing ELS commands |
| 8204 | * the firmware will not complete them till after |
| 8205 | * the link comes back up. This may confuse |
| 8206 | * discovery for the new link up, so we need to |
| 8207 | * change the compl routine to just clean up the iocb |
| 8208 | * and avoid any retry logic. |
| 8209 | */ |
| 8210 | if (phba->link_state == LPFC_LINK_DOWN) |
| 8211 | piocb->iocb_cmpl = lpfc_cmpl_els_link_down; |
| 8212 | } |
| 8213 | if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) |
| 8214 | list_add_tail(&piocb->dlist, &abort_list); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8215 | } |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8216 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8217 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8218 | spin_unlock(&pring->ring_lock); |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8219 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8220 | |
| 8221 | /* Abort each txcmpl iocb on aborted list and remove the dlist links. */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8222 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8223 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8224 | list_del_init(&piocb->dlist); |
| 8225 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8226 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8227 | } |
| 8228 | if (!list_empty(&abort_list)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8229 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8230 | "3387 abort list for txq not empty\n"); |
| 8231 | INIT_LIST_HEAD(&abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8232 | |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8233 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8234 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8235 | spin_lock(&pring->ring_lock); |
| 8236 | |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8237 | /* No need to abort the txq list, |
| 8238 | * just queue them up for lpfc_sli_cancel_iocbs |
| 8239 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8240 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 8241 | cmd = &piocb->iocb; |
| 8242 | |
| 8243 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 8244 | continue; |
| 8245 | } |
| 8246 | |
| 8247 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 8248 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 8249 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 8250 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 8251 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8252 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8253 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8254 | if (piocb->vport != vport) |
| 8255 | continue; |
| 8256 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8257 | list_del_init(&piocb->list); |
| 8258 | list_add_tail(&piocb->list, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8259 | } |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8260 | |
| 8261 | /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */ |
| 8262 | if (vport == phba->pport) { |
| 8263 | list_for_each_entry_safe(piocb, tmp_iocb, |
| 8264 | &phba->fabric_iocb_list, list) { |
| 8265 | cmd = &piocb->iocb; |
| 8266 | list_del_init(&piocb->list); |
| 8267 | list_add_tail(&piocb->list, &abort_list); |
| 8268 | } |
| 8269 | } |
| 8270 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8271 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8272 | spin_unlock(&pring->ring_lock); |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8273 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 8274 | |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8275 | /* Cancel all the IOCBs from the completions list */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8276 | lpfc_sli_cancel_iocbs(phba, &abort_list, |
| 8277 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 8278 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8279 | return; |
| 8280 | } |
| 8281 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8282 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8283 | * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8284 | * @phba: pointer to lpfc hba data structure. |
| 8285 | * |
| 8286 | * This routine is used to clean up all the outstanding ELS commands on a |
| 8287 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 8288 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 8289 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 8290 | * the IOCBs with the completion callback function associated, the callback |
| 8291 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 8292 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 8293 | * callback function associated, the IOCB will simply be released. Finally, |
| 8294 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 8295 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 8296 | * management plane IOCBs that are not part of the discovery state machine) |
| 8297 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 8298 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 8299 | void |
| 8300 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 8301 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8302 | struct lpfc_vport *vport; |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 8303 | |
| 8304 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8305 | list_for_each_entry(vport, &phba->port_list, listentry) |
| 8306 | lpfc_els_flush_cmd(vport); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 8307 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8308 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 8309 | return; |
| 8310 | } |
| 8311 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8312 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8313 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8314 | * @phba: Pointer to hba context object. |
| 8315 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 8316 | * @rspiocbp: Pointer to response iocb which reported error. |
| 8317 | * |
| 8318 | * This function sends an event when there is an ELS command |
| 8319 | * failure. |
| 8320 | **/ |
| 8321 | void |
| 8322 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 8323 | struct lpfc_iocbq *cmdiocbp, |
| 8324 | struct lpfc_iocbq *rspiocbp) |
| 8325 | { |
| 8326 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 8327 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8328 | struct lpfc_lsrjt_event lsrjt_event; |
| 8329 | struct lpfc_fabric_event_header fabric_event; |
| 8330 | struct ls_rjt stat; |
| 8331 | struct lpfc_nodelist *ndlp; |
| 8332 | uint32_t *pcmd; |
| 8333 | |
| 8334 | ndlp = cmdiocbp->context1; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 8335 | if (!ndlp) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8336 | return; |
| 8337 | |
| 8338 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 8339 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 8340 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 8341 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 8342 | sizeof(struct lpfc_name)); |
| 8343 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 8344 | sizeof(struct lpfc_name)); |
| 8345 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8346 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 8347 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8348 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 8349 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 8350 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 8351 | fc_host_post_vendor_event(shost, |
| 8352 | fc_get_event_number(), |
| 8353 | sizeof(lsrjt_event), |
| 8354 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8355 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8356 | return; |
| 8357 | } |
| 8358 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 8359 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 8360 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 8361 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 8362 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 8363 | else |
| 8364 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 8365 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 8366 | sizeof(struct lpfc_name)); |
| 8367 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 8368 | sizeof(struct lpfc_name)); |
| 8369 | fc_host_post_vendor_event(shost, |
| 8370 | fc_get_event_number(), |
| 8371 | sizeof(fabric_event), |
| 8372 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8373 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8374 | return; |
| 8375 | } |
| 8376 | |
| 8377 | } |
| 8378 | |
| 8379 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8380 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8381 | * @vport: Pointer to vport object. |
| 8382 | * @ndlp: Pointer FC node object. |
Lee Jones | a0e4a64 | 2020-07-23 13:24:07 +0100 | [diff] [blame] | 8383 | * @payload: ELS command code type. |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8384 | * |
| 8385 | * This function posts an event when there is an incoming |
| 8386 | * unsolicited ELS command. |
| 8387 | **/ |
| 8388 | static void |
| 8389 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 8390 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8391 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8392 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8393 | struct lpfc_els_event_header *els_data = NULL; |
| 8394 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8395 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8396 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8397 | if (*payload == ELS_CMD_LOGO) { |
| 8398 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 8399 | if (!logo_data) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8400 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8401 | "0148 Failed to allocate memory " |
| 8402 | "for LOGO event\n"); |
| 8403 | return; |
| 8404 | } |
| 8405 | els_data = &logo_data->header; |
| 8406 | } else { |
| 8407 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 8408 | GFP_KERNEL); |
| 8409 | if (!els_data) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8410 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8411 | "0149 Failed to allocate memory " |
| 8412 | "for ELS event\n"); |
| 8413 | return; |
| 8414 | } |
| 8415 | } |
| 8416 | els_data->event_type = FC_REG_ELS_EVENT; |
| 8417 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8418 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8419 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8420 | break; |
| 8421 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8422 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8423 | break; |
| 8424 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8425 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 8426 | break; |
| 8427 | case ELS_CMD_LOGO: |
| 8428 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 8429 | /* Copy the WWPN in the LOGO payload */ |
| 8430 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 8431 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8432 | break; |
| 8433 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 8434 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8435 | return; |
| 8436 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8437 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 8438 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 8439 | if (*payload == ELS_CMD_LOGO) { |
| 8440 | fc_host_post_vendor_event(shost, |
| 8441 | fc_get_event_number(), |
| 8442 | sizeof(struct lpfc_logo_event), |
| 8443 | (char *)logo_data, |
| 8444 | LPFC_NL_VENDOR_ID); |
| 8445 | kfree(logo_data); |
| 8446 | } else { |
| 8447 | fc_host_post_vendor_event(shost, |
| 8448 | fc_get_event_number(), |
| 8449 | sizeof(struct lpfc_els_event_header), |
| 8450 | (char *)els_data, |
| 8451 | LPFC_NL_VENDOR_ID); |
| 8452 | kfree(els_data); |
| 8453 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8454 | |
| 8455 | return; |
| 8456 | } |
| 8457 | |
| 8458 | |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8459 | DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag, |
| 8460 | FC_LS_TLV_DTAG_INIT); |
| 8461 | |
| 8462 | DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types, |
| 8463 | FC_FPIN_LI_EVT_TYPES_INIT); |
| 8464 | |
| 8465 | /** |
| 8466 | * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event. |
| 8467 | * @vport: Pointer to vport object. |
Lee Jones | a0e4a64 | 2020-07-23 13:24:07 +0100 | [diff] [blame] | 8468 | * @tlv: Pointer to the Link Integrity Notification Descriptor. |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8469 | * |
| 8470 | * This function processes a link integrity FPIN event by |
| 8471 | * logging a message |
| 8472 | **/ |
| 8473 | static void |
| 8474 | lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv) |
| 8475 | { |
| 8476 | struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv; |
| 8477 | const char *li_evt_str; |
| 8478 | u32 li_evt; |
| 8479 | |
| 8480 | li_evt = be16_to_cpu(li->event_type); |
| 8481 | li_evt_str = lpfc_get_fpin_li_event_nm(li_evt); |
| 8482 | |
| 8483 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8484 | "4680 FPIN Link Integrity %s (x%x) " |
| 8485 | "Detecting PN x%016llx Attached PN x%016llx " |
| 8486 | "Duration %d mSecs Count %d Port Cnt %d\n", |
| 8487 | li_evt_str, li_evt, |
| 8488 | be64_to_cpu(li->detecting_wwpn), |
| 8489 | be64_to_cpu(li->attached_wwpn), |
| 8490 | be32_to_cpu(li->event_threshold), |
| 8491 | be32_to_cpu(li->event_count), |
| 8492 | be32_to_cpu(li->pname_count)); |
| 8493 | } |
| 8494 | |
| 8495 | static void |
| 8496 | lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin, |
| 8497 | u32 fpin_length) |
| 8498 | { |
| 8499 | struct fc_tlv_desc *tlv; |
| 8500 | const char *dtag_nm; |
| 8501 | uint32_t desc_cnt = 0, bytes_remain; |
| 8502 | u32 dtag; |
| 8503 | |
| 8504 | /* FPINs handled only if we are in the right discovery state */ |
| 8505 | if (vport->port_state < LPFC_DISC_AUTH) |
| 8506 | return; |
| 8507 | |
| 8508 | /* make sure there is the full fpin header */ |
| 8509 | if (fpin_length < sizeof(struct fc_els_fpin)) |
| 8510 | return; |
| 8511 | |
| 8512 | tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0]; |
| 8513 | bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc); |
| 8514 | bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len)); |
| 8515 | |
| 8516 | /* process each descriptor */ |
| 8517 | while (bytes_remain >= FC_TLV_DESC_HDR_SZ && |
| 8518 | bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) { |
| 8519 | |
| 8520 | dtag = be32_to_cpu(tlv->desc_tag); |
| 8521 | switch (dtag) { |
| 8522 | case ELS_DTAG_LNK_INTEGRITY: |
| 8523 | lpfc_els_rcv_fpin_li(vport, tlv); |
| 8524 | break; |
| 8525 | default: |
| 8526 | dtag_nm = lpfc_get_tlv_dtag_nm(dtag); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8527 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8528 | "4678 skipped FPIN descriptor[%d]: " |
| 8529 | "tag x%x (%s)\n", |
| 8530 | desc_cnt, dtag, dtag_nm); |
| 8531 | break; |
| 8532 | } |
| 8533 | |
| 8534 | desc_cnt++; |
| 8535 | bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv); |
| 8536 | tlv = fc_tlv_next_desc(tlv); |
| 8537 | } |
| 8538 | |
| 8539 | fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length, |
| 8540 | (char *)fpin); |
| 8541 | } |
| 8542 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8543 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8544 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8545 | * @phba: pointer to lpfc hba data structure. |
| 8546 | * @pring: pointer to a SLI ring. |
| 8547 | * @vport: pointer to a host virtual N_Port data structure. |
| 8548 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 8549 | * |
| 8550 | * This routine is used for processing the IOCB associated with a unsolicited |
| 8551 | * event. It first determines whether there is an existing ndlp that matches |
| 8552 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 8553 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 8554 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 8555 | * of the discovery state machine. |
| 8556 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8557 | static void |
| 8558 | lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8559 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8560 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8561 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8562 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8563 | struct ls_rjt stat; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8564 | uint32_t *payload, payload_len; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8565 | uint32_t cmd, did, newnode; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 8566 | uint8_t rjt_exp, rjt_err = 0, init_link = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8567 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 8568 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8569 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8570 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8571 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8572 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8573 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8574 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8575 | payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8576 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8577 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 8578 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8579 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8580 | did = icmd->un.rcvels.remoteID; |
| 8581 | if (icmd->ulpStatus) { |
| 8582 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8583 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 8584 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8585 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8586 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8587 | |
| 8588 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8589 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8590 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8591 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8592 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8593 | if (vport->load_flag & FC_UNLOADING) |
| 8594 | goto dropit; |
| 8595 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8596 | /* If NPort discovery is delayed drop incoming ELS */ |
| 8597 | if ((vport->fc_flag & FC_DISC_DELAYED) && |
| 8598 | (cmd != ELS_CMD_PLOGI)) |
| 8599 | goto dropit; |
| 8600 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8601 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 8602 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8603 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 8604 | ndlp = lpfc_nlp_init(vport, did); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8605 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8606 | goto dropit; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8607 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8608 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8609 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8610 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8611 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8612 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 8613 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8614 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8615 | |
| 8616 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8617 | |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 8618 | /* |
| 8619 | * Do not process any unsolicited ELS commands |
| 8620 | * if the ndlp is in DEV_LOSS |
| 8621 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 8622 | shost = lpfc_shost_from_vport(vport); |
| 8623 | spin_lock_irq(shost->host_lock); |
| 8624 | if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) { |
| 8625 | spin_unlock_irq(shost->host_lock); |
Xiyu Yang | 7217e6e | 2020-05-25 22:16:24 +0800 | [diff] [blame] | 8626 | if (newnode) |
| 8627 | lpfc_nlp_put(ndlp); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 8628 | goto dropit; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 8629 | } |
| 8630 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 8631 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 8632 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 8633 | if (!elsiocb->context1) |
| 8634 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8635 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8636 | |
| 8637 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 8638 | cmd &= ELS_CMD_MASK; |
| 8639 | } |
| 8640 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8641 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8642 | "0112 ELS command x%x received from NPORT x%x " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 8643 | "Data: x%x x%x x%x x%x\n", |
| 8644 | cmd, did, vport->port_state, vport->fc_flag, |
| 8645 | vport->fc_myDID, vport->fc_prevDID); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8646 | |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 8647 | /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */ |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8648 | if ((vport->port_state < LPFC_FABRIC_CFG_LINK) && |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 8649 | (cmd != ELS_CMD_FLOGI) && |
| 8650 | !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) { |
James Smart | 401304c | 2016-10-13 15:06:14 -0700 | [diff] [blame] | 8651 | rjt_err = LSRJT_LOGICAL_BSY; |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8652 | rjt_exp = LSEXP_NOTHING_MORE; |
| 8653 | goto lsrjt; |
| 8654 | } |
| 8655 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8656 | switch (cmd) { |
| 8657 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8658 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8659 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 8660 | did, vport->port_state, ndlp->nlp_flag); |
| 8661 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8662 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8663 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 8664 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 8665 | (phba->pport->fc_flag & FC_PT2PT)) { |
| 8666 | vport->fc_prevDID = vport->fc_myDID; |
| 8667 | /* Our DID needs to be updated before registering |
| 8668 | * the vfi. This is done in lpfc_rcv_plogi but |
| 8669 | * that is called after the reg_vfi. |
| 8670 | */ |
| 8671 | vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo; |
| 8672 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8673 | "3312 Remote port assigned DID x%x " |
| 8674 | "%x\n", vport->fc_myDID, |
| 8675 | vport->fc_prevDID); |
| 8676 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8677 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8678 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8679 | |
| 8680 | /* If Nport discovery is delayed, reject PLOGIs */ |
| 8681 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 8682 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8683 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8684 | break; |
| 8685 | } |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 8686 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8687 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 8688 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 8689 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 8690 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8691 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 8692 | break; |
| 8693 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8694 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8695 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8696 | spin_lock_irq(shost->host_lock); |
| 8697 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 8698 | spin_unlock_irq(shost->host_lock); |
| 8699 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8700 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 8701 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8702 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8703 | break; |
| 8704 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8705 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8706 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 8707 | did, vport->port_state, ndlp->nlp_flag); |
| 8708 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8709 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 8710 | |
| 8711 | /* If the driver believes fabric discovery is done and is ready, |
| 8712 | * bounce the link. There is some descrepancy. |
| 8713 | */ |
| 8714 | if (vport->port_state >= LPFC_LOCAL_CFG_LINK && |
| 8715 | vport->fc_flag & FC_PT2PT && |
| 8716 | vport->rcv_flogi_cnt >= 1) { |
| 8717 | rjt_err = LSRJT_LOGICAL_BSY; |
| 8718 | rjt_exp = LSEXP_NOTHING_MORE; |
| 8719 | init_link++; |
| 8720 | goto lsrjt; |
| 8721 | } |
| 8722 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 8723 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8724 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8725 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8726 | break; |
| 8727 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8728 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8729 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 8730 | did, vport->port_state, ndlp->nlp_flag); |
| 8731 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8732 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8733 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8734 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8735 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8736 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8737 | break; |
| 8738 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8739 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8740 | break; |
| 8741 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8742 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8743 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 8744 | did, vport->port_state, ndlp->nlp_flag); |
| 8745 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8746 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8747 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8748 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8749 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8750 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8751 | break; |
| 8752 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8753 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8754 | break; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 8755 | case ELS_CMD_LCB: |
| 8756 | phba->fc_stat.elsRcvLCB++; |
| 8757 | lpfc_els_rcv_lcb(vport, elsiocb, ndlp); |
| 8758 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 8759 | case ELS_CMD_RDP: |
| 8760 | phba->fc_stat.elsRcvRDP++; |
| 8761 | lpfc_els_rcv_rdp(vport, elsiocb, ndlp); |
| 8762 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8763 | case ELS_CMD_RSCN: |
| 8764 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 8765 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8766 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8767 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8768 | break; |
| 8769 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8770 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8771 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 8772 | did, vport->port_state, ndlp->nlp_flag); |
| 8773 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8774 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8775 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8776 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8777 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8778 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8779 | break; |
| 8780 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8781 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 8782 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8783 | break; |
| 8784 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8785 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8786 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 8787 | did, vport->port_state, ndlp->nlp_flag); |
| 8788 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8789 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8790 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8791 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8792 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8793 | break; |
| 8794 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8795 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 8796 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8797 | break; |
| 8798 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8799 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8800 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 8801 | did, vport->port_state, ndlp->nlp_flag); |
| 8802 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8803 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8804 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8805 | break; |
| 8806 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8807 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8808 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 8809 | did, vport->port_state, ndlp->nlp_flag); |
| 8810 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8811 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8812 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8813 | break; |
| 8814 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8815 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8816 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 8817 | did, vport->port_state, ndlp->nlp_flag); |
| 8818 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8819 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8820 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8821 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8822 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 8823 | case ELS_CMD_NVMEPRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8824 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8825 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 8826 | did, vport->port_state, ndlp->nlp_flag); |
| 8827 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8828 | phba->fc_stat.elsRcvPRLI++; |
Dick Kennedy | a71e3cd | 2017-03-23 08:47:18 -0400 | [diff] [blame] | 8829 | if ((vport->port_state < LPFC_DISC_AUTH) && |
| 8830 | (vport->fc_flag & FC_FABRIC)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8831 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8832 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8833 | break; |
| 8834 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8835 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8836 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8837 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8838 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8839 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 8840 | did, vport->port_state, ndlp->nlp_flag); |
| 8841 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8842 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8843 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8844 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8845 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8846 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8847 | case ELS_CMD_RLS: |
| 8848 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8849 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 8850 | did, vport->port_state, ndlp->nlp_flag); |
| 8851 | |
| 8852 | phba->fc_stat.elsRcvRLS++; |
| 8853 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 8854 | if (newnode) |
| 8855 | lpfc_nlp_put(ndlp); |
| 8856 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8857 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8858 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8859 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 8860 | did, vport->port_state, ndlp->nlp_flag); |
| 8861 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8862 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8863 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8864 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8865 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8866 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8867 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8868 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8869 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 8870 | did, vport->port_state, ndlp->nlp_flag); |
| 8871 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8872 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8873 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8874 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8875 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8876 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8877 | case ELS_CMD_RTV: |
| 8878 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8879 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 8880 | did, vport->port_state, ndlp->nlp_flag); |
| 8881 | phba->fc_stat.elsRcvRTV++; |
| 8882 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 8883 | if (newnode) |
| 8884 | lpfc_nlp_put(ndlp); |
| 8885 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8886 | case ELS_CMD_RRQ: |
| 8887 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8888 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 8889 | did, vport->port_state, ndlp->nlp_flag); |
| 8890 | |
| 8891 | phba->fc_stat.elsRcvRRQ++; |
| 8892 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 8893 | if (newnode) |
| 8894 | lpfc_nlp_put(ndlp); |
| 8895 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8896 | case ELS_CMD_ECHO: |
| 8897 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8898 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 8899 | did, vport->port_state, ndlp->nlp_flag); |
| 8900 | |
| 8901 | phba->fc_stat.elsRcvECHO++; |
| 8902 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 8903 | if (newnode) |
| 8904 | lpfc_nlp_put(ndlp); |
| 8905 | break; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8906 | case ELS_CMD_REC: |
Colin Ian King | 8fd03fd | 2017-12-22 00:39:36 +0000 | [diff] [blame] | 8907 | /* receive this due to exchange closed */ |
| 8908 | rjt_err = LSRJT_UNABLE_TPC; |
| 8909 | rjt_exp = LSEXP_INVALID_OX_RX; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8910 | break; |
James Smart | 1a61e54 | 2019-04-05 16:04:23 -0700 | [diff] [blame] | 8911 | case ELS_CMD_FPIN: |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8912 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8913 | "RCV FPIN: did:x%x/ste:x%x flg:x%x", |
| 8914 | did, vport->port_state, ndlp->nlp_flag); |
| 8915 | |
| 8916 | lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload, |
| 8917 | payload_len); |
| 8918 | |
| 8919 | /* There are no replies, so no rjt codes */ |
James Smart | 1a61e54 | 2019-04-05 16:04:23 -0700 | [diff] [blame] | 8920 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8921 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8922 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8923 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 8924 | cmd, did, vport->port_state); |
| 8925 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8926 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8927 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8928 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8929 | |
| 8930 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8931 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8932 | "0115 Unknown ELS command x%x " |
| 8933 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8934 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8935 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8936 | break; |
| 8937 | } |
| 8938 | |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8939 | lsrjt: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8940 | /* check if need to LS_RJT received ELS cmd */ |
| 8941 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8942 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8943 | stat.un.b.lsRjtRsnCode = rjt_err; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8944 | stat.un.b.lsRjtRsnCodeExp = rjt_exp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8945 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 8946 | NULL); |
| 8947 | /* Remove the reference from above for new nodes. */ |
| 8948 | if (newnode) |
| 8949 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8950 | } |
| 8951 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8952 | lpfc_nlp_put(elsiocb->context1); |
| 8953 | elsiocb->context1 = NULL; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 8954 | |
| 8955 | /* Special case. Driver received an unsolicited command that |
| 8956 | * unsupportable given the driver's current state. Reset the |
| 8957 | * link and start over. |
| 8958 | */ |
| 8959 | if (init_link) { |
| 8960 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8961 | if (!mbox) |
| 8962 | return; |
| 8963 | lpfc_linkdown(phba); |
| 8964 | lpfc_init_link(phba, mbox, |
| 8965 | phba->cfg_topology, |
| 8966 | phba->cfg_link_speed); |
| 8967 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 8968 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 8969 | mbox->vport = vport; |
| 8970 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 8971 | MBX_NOT_FINISHED) |
| 8972 | mempool_free(mbox, phba->mbox_mem_pool); |
| 8973 | } |
| 8974 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8975 | return; |
| 8976 | |
| 8977 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8978 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8979 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8980 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8981 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8982 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8983 | phba->fc_stat.elsRcvDrop++; |
| 8984 | } |
| 8985 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8986 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8987 | * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8988 | * @phba: pointer to lpfc hba data structure. |
| 8989 | * @pring: pointer to a SLI ring. |
| 8990 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 8991 | * |
| 8992 | * This routine is used to process an unsolicited event received from a SLI |
| 8993 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 8994 | * associated with the unsolicited event is done by invoking the routine |
| 8995 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 8996 | * SLI ring on which the unsolicited event was received. |
| 8997 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8998 | void |
| 8999 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9000 | struct lpfc_iocbq *elsiocb) |
| 9001 | { |
| 9002 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9003 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9004 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9005 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 9006 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9007 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9008 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9009 | elsiocb->context2 = NULL; |
| 9010 | elsiocb->context3 = NULL; |
| 9011 | |
| 9012 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 9013 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 9014 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 9015 | (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 9016 | IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9017 | phba->fc_stat.NoRcvBuf++; |
| 9018 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9019 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9020 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9021 | return; |
| 9022 | } |
| 9023 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9024 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 9025 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 9026 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 9027 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 9028 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9029 | else |
| 9030 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9031 | icmd->unsli3.rcvsli3.vpi); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9032 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9033 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9034 | /* If there are no BDEs associated |
| 9035 | * with this IOCB, there is nothing to do. |
| 9036 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9037 | if (icmd->ulpBdeCount == 0) |
| 9038 | return; |
| 9039 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9040 | /* type of ELS cmd is first 32bit word |
| 9041 | * in packet |
| 9042 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9043 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9044 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9045 | } else { |
| 9046 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 9047 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9048 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 9049 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9050 | } |
| 9051 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9052 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 9053 | /* |
| 9054 | * The different unsolicited event handlers would tell us |
| 9055 | * if they are done with "mp" by setting context2 to NULL. |
| 9056 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9057 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9058 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 9059 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9060 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9061 | |
| 9062 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9063 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9064 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9065 | elsiocb->context2 = bdeBuf2; |
| 9066 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9067 | /* free mp if we are done with it */ |
| 9068 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9069 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 9070 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9071 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9072 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9073 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9074 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 9075 | static void |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9076 | lpfc_start_fdmi(struct lpfc_vport *vport) |
| 9077 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9078 | struct lpfc_nodelist *ndlp; |
| 9079 | |
| 9080 | /* If this is the first time, allocate an ndlp and initialize |
| 9081 | * it. Otherwise, make sure the node is enabled and then do the |
| 9082 | * login. |
| 9083 | */ |
| 9084 | ndlp = lpfc_findnode_did(vport, FDMI_DID); |
| 9085 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 9086 | ndlp = lpfc_nlp_init(vport, FDMI_DID); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9087 | if (ndlp) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9088 | ndlp->nlp_type |= NLP_FABRIC; |
| 9089 | } else { |
| 9090 | return; |
| 9091 | } |
| 9092 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9093 | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 9094 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 9095 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9096 | } |
| 9097 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9098 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9099 | * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9100 | * @phba: pointer to lpfc hba data structure. |
| 9101 | * @vport: pointer to a virtual N_Port data structure. |
| 9102 | * |
| 9103 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 9104 | * State Change Request (SCR) for a @vport. This routine will create an |
| 9105 | * ndlp for the Name Server associated to the @vport if such node does |
| 9106 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 9107 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 9108 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 9109 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 9110 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9111 | void |
| 9112 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 9113 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9114 | struct lpfc_nodelist *ndlp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9115 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 9116 | |
| 9117 | /* |
| 9118 | * If lpfc_delay_discovery parameter is set and the clean address |
| 9119 | * bit is cleared and fc fabric parameters chenged, delay FC NPort |
| 9120 | * discovery. |
| 9121 | */ |
| 9122 | spin_lock_irq(shost->host_lock); |
| 9123 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 9124 | spin_unlock_irq(shost->host_lock); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9125 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1877570 | 2013-04-17 20:19:25 -0400 | [diff] [blame] | 9126 | "3334 Delay fc port discovery for %d seconds\n", |
| 9127 | phba->fc_ratov); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9128 | mod_timer(&vport->delayed_disc_tmo, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9129 | jiffies + msecs_to_jiffies(1000 * phba->fc_ratov)); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9130 | return; |
| 9131 | } |
| 9132 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9133 | |
| 9134 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 9135 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 9136 | ndlp = lpfc_nlp_init(vport, NameServer_DID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9137 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 9138 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9139 | lpfc_disc_start(vport); |
| 9140 | return; |
| 9141 | } |
| 9142 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9143 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9144 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9145 | return; |
| 9146 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9147 | } |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 9148 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9149 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9150 | |
| 9151 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 9152 | |
| 9153 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 9154 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9155 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9156 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9157 | return; |
| 9158 | } |
| 9159 | |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 9160 | if ((phba->cfg_enable_SmartSAN || |
| 9161 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) && |
| 9162 | (vport->load_flag & FC_ALLOW_FDMI)) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9163 | lpfc_start_fdmi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9164 | } |
| 9165 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9166 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9167 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9168 | * @phba: pointer to lpfc hba data structure. |
| 9169 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 9170 | * |
| 9171 | * This routine is the completion callback function to register new vport |
| 9172 | * mailbox command. If the new vport mailbox command completes successfully, |
| 9173 | * the fabric registration login shall be performed on physical port (the |
| 9174 | * new vport created is actually a physical port, with VPI 0) or the port |
| 9175 | * login to Name Server for State Change Request (SCR) will be performed |
| 9176 | * on virtual port (real virtual port, with VPI greater than 0). |
| 9177 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9178 | static void |
| 9179 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 9180 | { |
| 9181 | struct lpfc_vport *vport = pmb->vport; |
| 9182 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 9183 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9184 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9185 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9186 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9187 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9188 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9189 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9190 | |
| 9191 | if (mb->mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9192 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 9193 | "0915 Register VPI failed : Status: x%x" |
| 9194 | " upd bit: x%x \n", mb->mbxStatus, |
| 9195 | mb->un.varRegVpi.upd); |
| 9196 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 9197 | mb->un.varRegVpi.upd) |
| 9198 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9199 | |
| 9200 | switch (mb->mbxStatus) { |
| 9201 | case 0x11: /* unsupported feature */ |
| 9202 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9203 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9204 | /* giving up on vport registration */ |
| 9205 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 9206 | spin_lock_irq(shost->host_lock); |
| 9207 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 9208 | spin_unlock_irq(shost->host_lock); |
| 9209 | lpfc_can_disctmo(vport); |
| 9210 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9211 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 9212 | case 0x20: |
| 9213 | spin_lock_irq(shost->host_lock); |
| 9214 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 9215 | spin_unlock_irq(shost->host_lock); |
| 9216 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 9217 | pmb->vport = vport; |
| 9218 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 9219 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 9220 | MBX_NOWAIT); |
| 9221 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9222 | lpfc_printf_vlog(vport, KERN_ERR, |
| 9223 | LOG_TRACE_EVENT, |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9224 | "2732 Failed to issue INIT_VPI" |
| 9225 | " mailbox command\n"); |
| 9226 | } else { |
| 9227 | lpfc_nlp_put(ndlp); |
| 9228 | return; |
| 9229 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9230 | fallthrough; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9231 | default: |
| 9232 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9233 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9234 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9235 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9236 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9237 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9238 | spin_unlock_irq(shost->host_lock); |
James Smart | 5d18153 | 2017-03-04 09:30:25 -0800 | [diff] [blame] | 9239 | if (mb->mbxStatus == MBX_NOT_FINISHED) |
| 9240 | break; |
| 9241 | if ((vport->port_type == LPFC_PHYSICAL_PORT) && |
| 9242 | !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) { |
| 9243 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9244 | lpfc_issue_init_vfi(vport); |
| 9245 | else |
| 9246 | lpfc_initial_flogi(vport); |
| 9247 | } else { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9248 | lpfc_initial_fdisc(vport); |
James Smart | 5d18153 | 2017-03-04 09:30:25 -0800 | [diff] [blame] | 9249 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9250 | break; |
| 9251 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9252 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9253 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 9254 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9255 | spin_unlock_irq(shost->host_lock); |
| 9256 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9257 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 9258 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9259 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 9260 | /* |
| 9261 | * If the physical port is instantiated using |
| 9262 | * FDISC, do not start vport discovery. |
| 9263 | */ |
| 9264 | if (vport->port_state != LPFC_FDISC) |
| 9265 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9266 | lpfc_do_scr_ns_plogi(phba, vport); |
| 9267 | } |
| 9268 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9269 | lpfc_do_scr_ns_plogi(phba, vport); |
| 9270 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 9271 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9272 | /* Now, we decrement the ndlp reference count held for this |
| 9273 | * callback function |
| 9274 | */ |
| 9275 | lpfc_nlp_put(ndlp); |
| 9276 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9277 | mempool_free(pmb, phba->mbox_mem_pool); |
| 9278 | return; |
| 9279 | } |
| 9280 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9281 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9282 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9283 | * @phba: pointer to lpfc hba data structure. |
| 9284 | * @vport: pointer to a host virtual N_Port data structure. |
| 9285 | * @ndlp: pointer to a node-list data structure. |
| 9286 | * |
| 9287 | * This routine registers the @vport as a new virtual port with a HBA. |
| 9288 | * It is done through a registering vpi mailbox command. |
| 9289 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9290 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9291 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 9292 | struct lpfc_nodelist *ndlp) |
| 9293 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9294 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9295 | LPFC_MBOXQ_t *mbox; |
| 9296 | |
| 9297 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 9298 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9299 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9300 | mbox->vport = vport; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 9301 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 9302 | if (!mbox->ctx_ndlp) { |
| 9303 | mempool_free(mbox, phba->mbox_mem_pool); |
| 9304 | goto mbox_err_exit; |
| 9305 | } |
| 9306 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9307 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9308 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9309 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9310 | /* mailbox command not success, decrement ndlp |
| 9311 | * reference count for this command |
| 9312 | */ |
| 9313 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9314 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9315 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9316 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9317 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9318 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9319 | } |
| 9320 | } else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9321 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9322 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9323 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9324 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9325 | return; |
| 9326 | |
| 9327 | mbox_err_exit: |
| 9328 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 9329 | spin_lock_irq(shost->host_lock); |
| 9330 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 9331 | spin_unlock_irq(shost->host_lock); |
| 9332 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9333 | } |
| 9334 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9335 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9336 | * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9337 | * @phba: pointer to lpfc hba data structure. |
| 9338 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9339 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9340 | **/ |
| 9341 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9342 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9343 | { |
| 9344 | struct lpfc_vport **vports; |
| 9345 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9346 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9347 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9348 | |
| 9349 | /* Treat this failure as linkdown for all vports */ |
| 9350 | link_state = phba->link_state; |
| 9351 | lpfc_linkdown(phba); |
| 9352 | phba->link_state = link_state; |
| 9353 | |
| 9354 | vports = lpfc_create_vport_work_array(phba); |
| 9355 | |
| 9356 | if (vports) { |
| 9357 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 9358 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 9359 | if (ndlp) |
| 9360 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 9361 | lpfc_els_flush_cmd(vports[i]); |
| 9362 | } |
| 9363 | lpfc_destroy_vport_work_array(phba, vports); |
| 9364 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9365 | } |
| 9366 | |
| 9367 | /** |
| 9368 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 9369 | * @phba: pointer to lpfc hba data structure. |
| 9370 | * |
| 9371 | * This routine abort all pending discovery commands and |
| 9372 | * start a timer to retry FLOGI for the physical port |
| 9373 | * discovery. |
| 9374 | **/ |
| 9375 | void |
| 9376 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 9377 | { |
| 9378 | struct lpfc_nodelist *ndlp; |
| 9379 | struct Scsi_Host *shost; |
| 9380 | |
| 9381 | /* Cancel the all vports retry delay retry timers */ |
| 9382 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9383 | |
| 9384 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 9385 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 9386 | if (!ndlp) |
| 9387 | return; |
| 9388 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9389 | shost = lpfc_shost_from_vport(phba->pport); |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9390 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000)); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9391 | spin_lock_irq(shost->host_lock); |
| 9392 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 9393 | spin_unlock_irq(shost->host_lock); |
| 9394 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 9395 | phba->pport->port_state = LPFC_FLOGI; |
| 9396 | return; |
| 9397 | } |
| 9398 | |
| 9399 | /** |
| 9400 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 9401 | * @phba: pointer to lpfc hba data structure. |
| 9402 | * @cmdiocb: pointer to FDISC command iocb. |
| 9403 | * @rspiocb: pointer to FDISC response iocb. |
| 9404 | * |
| 9405 | * This routine checks if a FLOGI is reguired for FDISC |
| 9406 | * to succeed. |
| 9407 | **/ |
| 9408 | static int |
| 9409 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 9410 | struct lpfc_iocbq *cmdiocb, |
| 9411 | struct lpfc_iocbq *rspiocb) |
| 9412 | { |
| 9413 | |
| 9414 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 9415 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 9416 | return 0; |
| 9417 | else |
| 9418 | return 1; |
| 9419 | } |
| 9420 | |
| 9421 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9422 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9423 | * @phba: pointer to lpfc hba data structure. |
| 9424 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 9425 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 9426 | * |
| 9427 | * This routine is the completion callback function to a Fabric Discover |
| 9428 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 9429 | * single threaded, each FDISC completion callback function will reset |
| 9430 | * the discovery timer for all vports such that the timers will not get |
| 9431 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 9432 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 9433 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 9434 | * assigned to the vport has been changed with the completion of the FDISC |
| 9435 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 9436 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 9437 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 9438 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 9439 | * Server for State Change Request (SCR). |
| 9440 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9441 | static void |
| 9442 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9443 | struct lpfc_iocbq *rspiocb) |
| 9444 | { |
| 9445 | struct lpfc_vport *vport = cmdiocb->vport; |
| 9446 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 9447 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 9448 | struct lpfc_nodelist *np; |
| 9449 | struct lpfc_nodelist *next_np; |
| 9450 | IOCB_t *irsp = &rspiocb->iocb; |
| 9451 | struct lpfc_iocbq *piocb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9452 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 9453 | struct serv_parm *sp; |
| 9454 | uint8_t fabric_param_changed; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9455 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9456 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 9457 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 9458 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 9459 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9460 | /* Since all FDISCs are being single threaded, we |
| 9461 | * must reset the discovery timer for ALL vports |
| 9462 | * waiting to send FDISC when one completes. |
| 9463 | */ |
| 9464 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 9465 | lpfc_set_disctmo(piocb->vport); |
| 9466 | } |
| 9467 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9468 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 9469 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 9470 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 9471 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9472 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9473 | |
| 9474 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 9475 | lpfc_retry_pport_discovery(phba); |
| 9476 | goto out; |
| 9477 | } |
| 9478 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9479 | /* Check for retry */ |
| 9480 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 9481 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9482 | /* FDISC failed */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9483 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9484 | "0126 FDISC failed. (x%x/x%x)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9485 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9486 | goto fdisc_failed; |
| 9487 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9488 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9489 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 9490 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9491 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 9492 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9493 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 9494 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9495 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9496 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 9497 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9498 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 9499 | if (!prsp) |
| 9500 | goto out; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9501 | sp = prsp->virt + sizeof(uint32_t); |
| 9502 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 9503 | memcpy(&vport->fabric_portname, &sp->portName, |
| 9504 | sizeof(struct lpfc_name)); |
| 9505 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 9506 | sizeof(struct lpfc_name)); |
| 9507 | if (fabric_param_changed && |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9508 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 9509 | /* If our NportID changed, we need to ensure all |
| 9510 | * remaining NPORTs get unreg_login'ed so we can |
| 9511 | * issue unreg_vpi. |
| 9512 | */ |
| 9513 | list_for_each_entry_safe(np, next_np, |
| 9514 | &vport->fc_nodes, nlp_listp) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 9515 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9516 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 9517 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9518 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9519 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9520 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9521 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9522 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 9523 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9524 | |
| 9525 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9526 | lpfc_sli4_unreg_all_rpis(vport); |
| 9527 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9528 | lpfc_mbx_unreg_vpi(vport); |
| 9529 | spin_lock_irq(shost->host_lock); |
| 9530 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9531 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9532 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 9533 | else |
| 9534 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9535 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 9536 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 9537 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 9538 | /* |
| 9539 | * Driver needs to re-reg VPI in order for f/w |
| 9540 | * to update the MAC address. |
| 9541 | */ |
| 9542 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 9543 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9544 | } |
| 9545 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 9546 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 9547 | lpfc_issue_init_vpi(vport); |
| 9548 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9549 | lpfc_register_new_vport(phba, vport, ndlp); |
| 9550 | else |
| 9551 | lpfc_do_scr_ns_plogi(phba, vport); |
| 9552 | goto out; |
| 9553 | fdisc_failed: |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 9554 | if (vport->fc_vport && |
| 9555 | (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)) |
James Smart | c84163d | 2015-05-21 13:55:22 -0400 | [diff] [blame] | 9556 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9557 | /* Cancel discovery timer */ |
| 9558 | lpfc_can_disctmo(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9559 | out: |
| 9560 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 9561 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9562 | } |
| 9563 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9564 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9565 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9566 | * @vport: pointer to a virtual N_Port data structure. |
| 9567 | * @ndlp: pointer to a node-list data structure. |
| 9568 | * @retry: number of retries to the command IOCB. |
| 9569 | * |
| 9570 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 9571 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 9572 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 9573 | * IOCB will be sent off HBA at any given time. |
| 9574 | * |
| 9575 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 9576 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 9577 | * will be stored into the context1 field of the IOCB for the completion |
| 9578 | * callback function to the FDISC ELS command. |
| 9579 | * |
| 9580 | * Return code |
| 9581 | * 0 - Successfully issued fdisc iocb command |
| 9582 | * 1 - Failed to issue fdisc iocb command |
| 9583 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 9584 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9585 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 9586 | uint8_t retry) |
| 9587 | { |
| 9588 | struct lpfc_hba *phba = vport->phba; |
| 9589 | IOCB_t *icmd; |
| 9590 | struct lpfc_iocbq *elsiocb; |
| 9591 | struct serv_parm *sp; |
| 9592 | uint8_t *pcmd; |
| 9593 | uint16_t cmdsize; |
| 9594 | int did = ndlp->nlp_DID; |
| 9595 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9596 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9597 | vport->port_state = LPFC_FDISC; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9598 | vport->fc_myDID = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9599 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 9600 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 9601 | ELS_CMD_FDISC); |
| 9602 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9603 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9604 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9605 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9606 | return 1; |
| 9607 | } |
| 9608 | |
| 9609 | icmd = &elsiocb->iocb; |
| 9610 | icmd->un.elsreq64.myID = 0; |
| 9611 | icmd->un.elsreq64.fl = 1; |
| 9612 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9613 | /* |
| 9614 | * SLI3 ports require a different context type value than SLI4. |
| 9615 | * Catch SLI3 ports here and override the prep. |
| 9616 | */ |
| 9617 | if (phba->sli_rev == LPFC_SLI_REV3) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9618 | icmd->ulpCt_h = 1; |
| 9619 | icmd->ulpCt_l = 0; |
| 9620 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9621 | |
| 9622 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 9623 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 9624 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 9625 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 9626 | sp = (struct serv_parm *) pcmd; |
| 9627 | /* Setup CSPs accordingly for Fabric */ |
| 9628 | sp->cmn.e_d_tov = 0; |
| 9629 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 9630 | sp->cmn.virtual_fabric_support = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9631 | sp->cls1.classValid = 0; |
| 9632 | sp->cls2.seqDelivery = 1; |
| 9633 | sp->cls3.seqDelivery = 1; |
| 9634 | |
| 9635 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 9636 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 9637 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 9638 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 9639 | memcpy(pcmd, &vport->fc_portname, 8); |
| 9640 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 9641 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 9642 | memcpy(pcmd, &vport->fc_nodename, 8); |
Dick Kennedy | 176de5b | 2017-08-23 16:55:40 -0700 | [diff] [blame] | 9643 | sp->cmn.valid_vendor_ver_level = 0; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 9644 | memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9645 | lpfc_set_disctmo(vport); |
| 9646 | |
| 9647 | phba->fc_stat.elsXmitFDISC++; |
| 9648 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 9649 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9650 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 9651 | "Issue FDISC: did:x%x", |
| 9652 | did, 0, 0); |
| 9653 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 9654 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 9655 | if (!elsiocb->context1) |
| 9656 | goto err_out; |
| 9657 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9658 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 9659 | if (rc == IOCB_ERROR) { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 9660 | lpfc_nlp_put(ndlp); |
| 9661 | goto err_out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9662 | } |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 9663 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9664 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9665 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 9666 | |
| 9667 | err_out: |
| 9668 | lpfc_els_free_iocb(phba, elsiocb); |
| 9669 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 9670 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 9671 | "0256 Issue FDISC: Cannot send IOCB\n"); |
| 9672 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9673 | } |
| 9674 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9675 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9676 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9677 | * @phba: pointer to lpfc hba data structure. |
| 9678 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 9679 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 9680 | * |
| 9681 | * This routine is the completion callback function to the issuing of a LOGO |
| 9682 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 9683 | * reference count held on ndlp for this completion function, indicating that |
| 9684 | * the reference to the ndlp is no long needed. Note that the |
| 9685 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 9686 | * callback function and an additional explicit ndlp reference decrementation |
| 9687 | * will trigger the actual release of the ndlp. |
| 9688 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9689 | static void |
| 9690 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9691 | struct lpfc_iocbq *rspiocb) |
| 9692 | { |
| 9693 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9694 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 9695 | struct lpfc_nodelist *ndlp; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9696 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9697 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9698 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9699 | irsp = &rspiocb->iocb; |
| 9700 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 9701 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 9702 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9703 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 9704 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9705 | lpfc_els_free_iocb(phba, cmdiocb); |
| 9706 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 9707 | |
| 9708 | /* Trigger the release of the ndlp after logo */ |
| 9709 | lpfc_nlp_put(ndlp); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9710 | |
| 9711 | /* NPIV LOGO completes to NPort <nlp_DID> */ |
| 9712 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 9713 | "2928 NPIV LOGO completes to NPort x%x " |
| 9714 | "Data: x%x x%x x%x x%x\n", |
| 9715 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 9716 | irsp->ulpTimeout, vport->num_disc_nodes); |
| 9717 | |
| 9718 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 9719 | spin_lock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 9720 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9721 | vport->fc_flag &= ~FC_FABRIC; |
| 9722 | spin_unlock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 9723 | lpfc_can_disctmo(vport); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9724 | } |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 9725 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9726 | } |
| 9727 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9728 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9729 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9730 | * @vport: pointer to a virtual N_Port data structure. |
| 9731 | * @ndlp: pointer to a node-list data structure. |
| 9732 | * |
| 9733 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 9734 | * |
| 9735 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 9736 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 9737 | * will be stored into the context1 field of the IOCB for the completion |
| 9738 | * callback function to the LOGO ELS command. |
| 9739 | * |
| 9740 | * Return codes |
| 9741 | * 0 - Successfully issued logo off the @vport |
| 9742 | * 1 - Failed to issue logo off the @vport |
| 9743 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9744 | int |
| 9745 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 9746 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 9747 | int rc = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9748 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 9749 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9750 | struct lpfc_iocbq *elsiocb; |
| 9751 | uint8_t *pcmd; |
| 9752 | uint16_t cmdsize; |
| 9753 | |
| 9754 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 9755 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 9756 | ELS_CMD_LOGO); |
| 9757 | if (!elsiocb) |
| 9758 | return 1; |
| 9759 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9760 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 9761 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 9762 | pcmd += sizeof(uint32_t); |
| 9763 | |
| 9764 | /* Fill in LOGO payload */ |
| 9765 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 9766 | pcmd += sizeof(uint32_t); |
| 9767 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 9768 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9769 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 9770 | "Issue LOGO npiv did:x%x flg:x%x", |
| 9771 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 9772 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9773 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 9774 | spin_lock_irq(shost->host_lock); |
| 9775 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 9776 | spin_unlock_irq(shost->host_lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 9777 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 9778 | if (!elsiocb->context1) |
| 9779 | goto node_err; |
| 9780 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 9781 | if (rc == IOCB_ERROR) |
| 9782 | goto io_err; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9783 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame^] | 9784 | |
| 9785 | io_err: |
| 9786 | lpfc_nlp_put(ndlp); |
| 9787 | node_err: |
| 9788 | spin_lock_irq(shost->host_lock); |
| 9789 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 9790 | spin_unlock_irq(shost->host_lock); |
| 9791 | lpfc_els_free_iocb(phba, elsiocb); |
| 9792 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9793 | } |
| 9794 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9795 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9796 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
Lee Jones | a0e4a64 | 2020-07-23 13:24:07 +0100 | [diff] [blame] | 9797 | * @t: timer context used to obtain the lpfc hba. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9798 | * |
| 9799 | * This routine is invoked by the fabric iocb block timer after |
| 9800 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 9801 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 9802 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 9803 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 9804 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 9805 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9806 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 9807 | lpfc_fabric_block_timeout(struct timer_list *t) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9808 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 9809 | struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9810 | unsigned long iflags; |
| 9811 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9812 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9813 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 9814 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 9815 | if (!tmo_posted) |
| 9816 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 9817 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 9818 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9819 | if (!tmo_posted) |
| 9820 | lpfc_worker_wake_up(phba); |
| 9821 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9822 | } |
| 9823 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9824 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9825 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9826 | * @phba: pointer to lpfc hba data structure. |
| 9827 | * |
| 9828 | * This routine issues one fabric iocb from the driver internal list to |
| 9829 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 9830 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 9831 | * remove one pending fabric iocb from the driver internal list and invokes |
| 9832 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 9833 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9834 | static void |
| 9835 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 9836 | { |
| 9837 | struct lpfc_iocbq *iocb; |
| 9838 | unsigned long iflags; |
| 9839 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9840 | IOCB_t *cmd; |
| 9841 | |
| 9842 | repeat: |
| 9843 | iocb = NULL; |
| 9844 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9845 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9846 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 9847 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 9848 | list); |
| 9849 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9850 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9851 | atomic_inc(&phba->fabric_iocb_count); |
| 9852 | } |
| 9853 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9854 | if (iocb) { |
| 9855 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 9856 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 9857 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 9858 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9859 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 9860 | "Fabric sched1: ste:x%x", |
| 9861 | iocb->vport->port_state, 0, 0); |
| 9862 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9863 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9864 | |
| 9865 | if (ret == IOCB_ERROR) { |
| 9866 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 9867 | iocb->fabric_iocb_cmpl = NULL; |
| 9868 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 9869 | cmd = &iocb->iocb; |
| 9870 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 9871 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 9872 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 9873 | |
| 9874 | atomic_dec(&phba->fabric_iocb_count); |
| 9875 | goto repeat; |
| 9876 | } |
| 9877 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9878 | } |
| 9879 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9880 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9881 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9882 | * @phba: pointer to lpfc hba data structure. |
| 9883 | * |
| 9884 | * This routine unblocks the issuing fabric iocb command. The function |
| 9885 | * will clear the fabric iocb block bit and then invoke the routine |
| 9886 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 9887 | * from the driver internal fabric iocb list. |
| 9888 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9889 | void |
| 9890 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 9891 | { |
| 9892 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 9893 | |
| 9894 | lpfc_resume_fabric_iocbs(phba); |
| 9895 | return; |
| 9896 | } |
| 9897 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9898 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9899 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9900 | * @phba: pointer to lpfc hba data structure. |
| 9901 | * |
| 9902 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 9903 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 9904 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 9905 | * fabric iocb will be issued out of the HBA. |
| 9906 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9907 | static void |
| 9908 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 9909 | { |
| 9910 | int blocked; |
| 9911 | |
| 9912 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9913 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9914 | if (!blocked) |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9915 | mod_timer(&phba->fabric_block_timer, |
| 9916 | jiffies + msecs_to_jiffies(100)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9917 | |
| 9918 | return; |
| 9919 | } |
| 9920 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9921 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9922 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9923 | * @phba: pointer to lpfc hba data structure. |
| 9924 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 9925 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 9926 | * |
| 9927 | * This routine is the callback function that is put to the fabric iocb's |
| 9928 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 9929 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 9930 | * function first restores and invokes the original iocb's callback function |
| 9931 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 9932 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 9933 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9934 | static void |
| 9935 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9936 | struct lpfc_iocbq *rspiocb) |
| 9937 | { |
| 9938 | struct ls_rjt stat; |
| 9939 | |
Shyam Saini | e01ea5e | 2016-12-24 16:21:07 +0530 | [diff] [blame] | 9940 | BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9941 | |
| 9942 | switch (rspiocb->iocb.ulpStatus) { |
| 9943 | case IOSTAT_NPORT_RJT: |
| 9944 | case IOSTAT_FABRIC_RJT: |
| 9945 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 9946 | lpfc_block_fabric_iocbs(phba); |
| 9947 | } |
| 9948 | break; |
| 9949 | |
| 9950 | case IOSTAT_NPORT_BSY: |
| 9951 | case IOSTAT_FABRIC_BSY: |
| 9952 | lpfc_block_fabric_iocbs(phba); |
| 9953 | break; |
| 9954 | |
| 9955 | case IOSTAT_LS_RJT: |
| 9956 | stat.un.lsRjtError = |
| 9957 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 9958 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 9959 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 9960 | lpfc_block_fabric_iocbs(phba); |
| 9961 | break; |
| 9962 | } |
| 9963 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 9964 | BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9965 | |
| 9966 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 9967 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 9968 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 9969 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 9970 | |
| 9971 | atomic_dec(&phba->fabric_iocb_count); |
| 9972 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9973 | /* Post any pending iocbs to HBA */ |
| 9974 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9975 | } |
| 9976 | } |
| 9977 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9978 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9979 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9980 | * @phba: pointer to lpfc hba data structure. |
| 9981 | * @iocb: pointer to lpfc command iocb data structure. |
| 9982 | * |
| 9983 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 9984 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 9985 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 9986 | * any given time. As such, this function will first check to see whether there |
| 9987 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 9988 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 9989 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 9990 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 9991 | * |
| 9992 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 9993 | * order. The problem is caused by the construction of the "ready" boolen does |
| 9994 | * not include the condition that the internal fabric IOCB list is empty. As |
| 9995 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 9996 | * ahead of the fabric IOCBs in the internal list. |
| 9997 | * |
| 9998 | * Return code |
| 9999 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 10000 | * IOCB_ERROR - failed to issue fabric iocb |
| 10001 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 10002 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10003 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 10004 | { |
| 10005 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10006 | int ready; |
| 10007 | int ret; |
| 10008 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 10009 | BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10010 | |
| 10011 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10012 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 10013 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 10014 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 10015 | if (ready) |
| 10016 | /* Increment fabric iocb count to hold the position */ |
| 10017 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10018 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10019 | if (ready) { |
| 10020 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 10021 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 10022 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 10023 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10024 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 10025 | "Fabric sched2: ste:x%x", |
| 10026 | iocb->vport->port_state, 0, 0); |
| 10027 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10028 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10029 | |
| 10030 | if (ret == IOCB_ERROR) { |
| 10031 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 10032 | iocb->fabric_iocb_cmpl = NULL; |
| 10033 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 10034 | atomic_dec(&phba->fabric_iocb_count); |
| 10035 | } |
| 10036 | } else { |
| 10037 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10038 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 10039 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10040 | ret = IOCB_SUCCESS; |
| 10041 | } |
| 10042 | return ret; |
| 10043 | } |
| 10044 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10045 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10046 | * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10047 | * @vport: pointer to a virtual N_Port data structure. |
| 10048 | * |
| 10049 | * This routine aborts all the IOCBs associated with a @vport from the |
| 10050 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 10051 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 10052 | * list, removes each IOCB associated with the @vport off the list, set the |
| 10053 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 10054 | * associated with the IOCB. |
| 10055 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 10056 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10057 | { |
| 10058 | LIST_HEAD(completions); |
| 10059 | struct lpfc_hba *phba = vport->phba; |
| 10060 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10061 | |
| 10062 | spin_lock_irq(&phba->hbalock); |
| 10063 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 10064 | list) { |
| 10065 | |
| 10066 | if (piocb->vport != vport) |
| 10067 | continue; |
| 10068 | |
| 10069 | list_move_tail(&piocb->list, &completions); |
| 10070 | } |
| 10071 | spin_unlock_irq(&phba->hbalock); |
| 10072 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10073 | /* Cancel all the IOCBs from the completions list */ |
| 10074 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10075 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10076 | } |
| 10077 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10078 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10079 | * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10080 | * @ndlp: pointer to a node-list data structure. |
| 10081 | * |
| 10082 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 10083 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 10084 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 10085 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 10086 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 10087 | * associated with the IOCB. |
| 10088 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10089 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 10090 | { |
| 10091 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10092 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10093 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10094 | struct lpfc_sli_ring *pring; |
| 10095 | |
| 10096 | pring = lpfc_phba_elsring(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10097 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 10098 | if (unlikely(!pring)) |
| 10099 | return; |
| 10100 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10101 | spin_lock_irq(&phba->hbalock); |
| 10102 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 10103 | list) { |
| 10104 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 10105 | |
| 10106 | list_move_tail(&piocb->list, &completions); |
| 10107 | } |
| 10108 | } |
| 10109 | spin_unlock_irq(&phba->hbalock); |
| 10110 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10111 | /* Cancel all the IOCBs from the completions list */ |
| 10112 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10113 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10114 | } |
| 10115 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10116 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10117 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10118 | * @phba: pointer to lpfc hba data structure. |
| 10119 | * |
| 10120 | * This routine aborts all the IOCBs currently on the driver internal |
| 10121 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 10122 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 10123 | * list, removes IOCBs off the list, set the status feild to |
| 10124 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 10125 | * the IOCB. |
| 10126 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10127 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 10128 | { |
| 10129 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10130 | |
| 10131 | spin_lock_irq(&phba->hbalock); |
| 10132 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 10133 | spin_unlock_irq(&phba->hbalock); |
| 10134 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10135 | /* Cancel all the IOCBs from the completions list */ |
| 10136 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10137 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10138 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10139 | |
| 10140 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 10141 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport |
| 10142 | * @vport: pointer to lpfc vport data structure. |
| 10143 | * |
| 10144 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 10145 | * for an ndlp on removal. |
| 10146 | **/ |
| 10147 | void |
| 10148 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) |
| 10149 | { |
| 10150 | struct lpfc_hba *phba = vport->phba; |
| 10151 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 10152 | unsigned long iflag = 0; |
| 10153 | |
| 10154 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10155 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 10156 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 10157 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 10158 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) { |
| 10159 | lpfc_nlp_put(sglq_entry->ndlp); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 10160 | sglq_entry->ndlp = NULL; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 10161 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 10162 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10163 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 10164 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10165 | return; |
| 10166 | } |
| 10167 | |
| 10168 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10169 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 10170 | * @phba: pointer to lpfc hba data structure. |
| 10171 | * @axri: pointer to the els xri abort wcqe structure. |
| 10172 | * |
| 10173 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 10174 | * ELS aborted xri. |
| 10175 | **/ |
| 10176 | void |
| 10177 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 10178 | struct sli4_wcqe_xri_aborted *axri) |
| 10179 | { |
| 10180 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10181 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10182 | uint16_t lxri = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10183 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10184 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 10185 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10186 | struct lpfc_nodelist *ndlp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10187 | struct lpfc_sli_ring *pring; |
| 10188 | |
| 10189 | pring = lpfc_phba_elsring(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10190 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10191 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10192 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10193 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 10194 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 10195 | if (sglq_entry->sli4_xritag == xri) { |
| 10196 | list_del(&sglq_entry->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10197 | ndlp = sglq_entry->ndlp; |
| 10198 | sglq_entry->ndlp = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10199 | list_add_tail(&sglq_entry->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10200 | &phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10201 | sglq_entry->state = SGL_FREED; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10202 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10203 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 10204 | |
| 10205 | if (ndlp) { |
| 10206 | lpfc_set_rrq_active(phba, ndlp, |
| 10207 | sglq_entry->sli4_lxritag, |
| 10208 | rxid, 1); |
| 10209 | lpfc_nlp_put(ndlp); |
| 10210 | } |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 10211 | |
| 10212 | /* Check if TXQ queue needs to be serviced */ |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 10213 | if (pring && !list_empty(&pring->txq)) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 10214 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10215 | return; |
| 10216 | } |
| 10217 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10218 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10219 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 10220 | if (lxri == NO_XRI) { |
| 10221 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10222 | return; |
| 10223 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10224 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10225 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10226 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10227 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10228 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10229 | return; |
| 10230 | } |
| 10231 | sglq_entry->state = SGL_XRI_ABORTED; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10232 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10233 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10234 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10235 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 10236 | |
| 10237 | /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. |
| 10238 | * @vport: pointer to virtual port object. |
| 10239 | * @ndlp: nodelist pointer for the impacted node. |
| 10240 | * |
| 10241 | * The driver calls this routine in response to an SLI4 XRI ABORT CQE |
| 10242 | * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, |
| 10243 | * the driver is required to send a LOGO to the remote node before it |
| 10244 | * attempts to recover its login to the remote node. |
| 10245 | */ |
| 10246 | void |
| 10247 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 10248 | struct lpfc_nodelist *ndlp) |
| 10249 | { |
| 10250 | struct Scsi_Host *shost; |
| 10251 | struct lpfc_hba *phba; |
| 10252 | unsigned long flags = 0; |
| 10253 | |
| 10254 | shost = lpfc_shost_from_vport(vport); |
| 10255 | phba = vport->phba; |
| 10256 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 10257 | lpfc_printf_log(phba, KERN_INFO, |
| 10258 | LOG_SLI, "3093 No rport recovery needed. " |
| 10259 | "rport in state 0x%x\n", ndlp->nlp_state); |
| 10260 | return; |
| 10261 | } |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10262 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 10263 | "3094 Start rport recovery on shost id 0x%x " |
| 10264 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 10265 | "flags 0x%x\n", |
| 10266 | shost->host_no, ndlp->nlp_DID, |
| 10267 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 10268 | ndlp->nlp_flag); |
| 10269 | /* |
| 10270 | * The rport is not responding. Remove the FCP-2 flag to prevent |
| 10271 | * an ADISC in the follow-up recovery code. |
| 10272 | */ |
| 10273 | spin_lock_irqsave(shost->host_lock, flags); |
| 10274 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 10275 | ndlp->nlp_flag |= NLP_ISSUE_LOGO; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 10276 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 10277 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 10278 | } |
| 10279 | |