| 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 */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 103 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 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 | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 303 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 304 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 305 | if (!elsiocb->context1) |
| 306 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 307 | elsiocb->context2 = pcmd; |
| 308 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 309 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 310 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 311 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 312 | |
| 313 | if (prsp) { |
| 314 | list_add(&prsp->list, &pcmd->list); |
| 315 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 316 | if (expectRsp) { |
| 317 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 318 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 319 | "0116 Xmit ELS command x%x to remote " |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 320 | "NPORT x%x I/O tag: x%x, port state:x%x " |
| 321 | "rpi x%x fc_flag:x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 322 | elscmd, did, elsiocb->iotag, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 323 | vport->port_state, ndlp->nlp_rpi, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 324 | vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 325 | } else { |
| 326 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 327 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 328 | "0117 Xmit ELS response x%x to remote " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 329 | "NPORT x%x I/O tag: x%x, size: x%x " |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 330 | "port_state x%x rpi x%x fc_flag x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 331 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 332 | cmdSize, vport->port_state, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 333 | ndlp->nlp_rpi, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 334 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 335 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 336 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 337 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 338 | if (expectRsp) |
| 339 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 340 | kfree(pbuflist); |
| 341 | |
| 342 | els_iocb_free_prsp_exit: |
| 343 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 344 | kfree(prsp); |
| 345 | |
| 346 | els_iocb_free_pcmb_exit: |
| 347 | kfree(pcmd); |
| 348 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 349 | return NULL; |
| 350 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 351 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 352 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 353 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 354 | * @vport: pointer to a host virtual N_Port data structure. |
| 355 | * |
| 356 | * This routine issues a fabric registration login for a @vport. An |
| 357 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 358 | * The routine invokes two mailbox commands to carry out fabric registration |
| 359 | * login through the HBA firmware: the first mailbox command requests the |
| 360 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 361 | * command requests the HBA to perform the actual fabric registration login |
| 362 | * with the @vport. |
| 363 | * |
| 364 | * Return code |
| 365 | * 0 - successfully issued fabric registration login for @vport |
| 366 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 367 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 368 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 369 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 370 | { |
| 371 | struct lpfc_hba *phba = vport->phba; |
| 372 | LPFC_MBOXQ_t *mbox; |
| 373 | struct lpfc_dmabuf *mp; |
| 374 | struct lpfc_nodelist *ndlp; |
| 375 | struct serv_parm *sp; |
| 376 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 377 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 378 | |
| 379 | sp = &phba->fc_fabparam; |
| 380 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 381 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 382 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 383 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 384 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 385 | |
| 386 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 387 | if (!mbox) { |
| 388 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 389 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 390 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 391 | |
| 392 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 393 | lpfc_config_link(phba, mbox); |
| 394 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 395 | mbox->vport = vport; |
| 396 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 397 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 398 | if (rc == MBX_NOT_FINISHED) { |
| 399 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 400 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 401 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 402 | |
| 403 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 404 | if (!mbox) { |
| 405 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 406 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 407 | } |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 408 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
| 409 | ndlp->nlp_rpi); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 410 | if (rc) { |
| 411 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 412 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 413 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 414 | |
| 415 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 416 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 417 | /* increment the reference count on ndlp to hold reference |
| 418 | * for the callback routine. |
| 419 | */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 420 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
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) { |
| 424 | err = 6; |
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 | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 435 | mp = (struct lpfc_dmabuf *)mbox->ctx_buf; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 436 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 437 | kfree(mp); |
| 438 | fail_free_mbox: |
| 439 | mempool_free(mbox, phba->mbox_mem_pool); |
| 440 | |
| 441 | fail: |
| 442 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 443 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 444 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 445 | return -ENXIO; |
| 446 | } |
| 447 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 448 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 449 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 450 | * @vport: pointer to a host virtual N_Port data structure. |
| 451 | * |
| 452 | * 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] | 453 | * the @vport. This mailbox command is necessary for SLI4 port only. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 454 | * |
| 455 | * Return code |
| 456 | * 0 - successfully issued REG_VFI for @vport |
| 457 | * A failure code otherwise. |
| 458 | **/ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 459 | int |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 460 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 461 | { |
| 462 | struct lpfc_hba *phba = vport->phba; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 463 | LPFC_MBOXQ_t *mboxq = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 464 | struct lpfc_nodelist *ndlp; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 465 | struct lpfc_dmabuf *dmabuf = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 466 | int rc = 0; |
| 467 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 468 | /* 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] | 469 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 470 | !(phba->link_flag & LS_LOOPBACK_MODE) && |
| 471 | !(vport->fc_flag & FC_PT2PT)) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 472 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 473 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 474 | rc = -ENODEV; |
| 475 | goto fail; |
| 476 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 477 | } |
| 478 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 479 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 480 | if (!mboxq) { |
| 481 | rc = -ENOMEM; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 482 | goto fail; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 483 | } |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 484 | |
| 485 | /* Supply CSP's only if we are fabric connect or pt-to-pt connect */ |
| 486 | if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) { |
| 487 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 488 | if (!dmabuf) { |
| 489 | rc = -ENOMEM; |
| 490 | goto fail; |
| 491 | } |
| 492 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 493 | if (!dmabuf->virt) { |
| 494 | rc = -ENOMEM; |
| 495 | goto fail; |
| 496 | } |
| 497 | memcpy(dmabuf->virt, &phba->fc_fabparam, |
| 498 | sizeof(struct serv_parm)); |
| 499 | } |
| 500 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 501 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 502 | if (dmabuf) |
| 503 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 504 | else |
| 505 | lpfc_reg_vfi(mboxq, vport, 0); |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 506 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 507 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 508 | mboxq->vport = vport; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 509 | mboxq->ctx_buf = dmabuf; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 510 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 511 | if (rc == MBX_NOT_FINISHED) { |
| 512 | rc = -ENXIO; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 513 | goto fail; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 514 | } |
| 515 | return 0; |
| 516 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 517 | fail: |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 518 | if (mboxq) |
| 519 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 520 | if (dmabuf) { |
| 521 | if (dmabuf->virt) |
| 522 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 523 | kfree(dmabuf); |
| 524 | } |
| 525 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 526 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 527 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 528 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 529 | return rc; |
| 530 | } |
| 531 | |
| 532 | /** |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 533 | * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login |
| 534 | * @vport: pointer to a host virtual N_Port data structure. |
| 535 | * |
| 536 | * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for |
| 537 | * the @vport. This mailbox command is necessary for SLI4 port only. |
| 538 | * |
| 539 | * Return code |
| 540 | * 0 - successfully issued REG_VFI for @vport |
| 541 | * A failure code otherwise. |
| 542 | **/ |
| 543 | int |
| 544 | lpfc_issue_unreg_vfi(struct lpfc_vport *vport) |
| 545 | { |
| 546 | struct lpfc_hba *phba = vport->phba; |
| 547 | struct Scsi_Host *shost; |
| 548 | LPFC_MBOXQ_t *mboxq; |
| 549 | int rc; |
| 550 | |
| 551 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 552 | if (!mboxq) { |
| 553 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 554 | "2556 UNREG_VFI mbox allocation failed" |
| 555 | "HBA state x%x\n", phba->pport->port_state); |
| 556 | return -ENOMEM; |
| 557 | } |
| 558 | |
| 559 | lpfc_unreg_vfi(mboxq, vport); |
| 560 | mboxq->vport = vport; |
| 561 | mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl; |
| 562 | |
| 563 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 564 | if (rc == MBX_NOT_FINISHED) { |
| 565 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 566 | "2557 UNREG_VFI issue mbox failed rc x%x " |
| 567 | "HBA state x%x\n", |
| 568 | rc, phba->pport->port_state); |
| 569 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 570 | return -EIO; |
| 571 | } |
| 572 | |
| 573 | shost = lpfc_shost_from_vport(vport); |
| 574 | spin_lock_irq(shost->host_lock); |
| 575 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 576 | spin_unlock_irq(shost->host_lock); |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | /** |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 581 | * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean. |
| 582 | * @vport: pointer to a host virtual N_Port data structure. |
| 583 | * @sp: pointer to service parameter data structure. |
| 584 | * |
| 585 | * This routine is called from FLOGI/FDISC completion handler functions. |
| 586 | * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric |
| 587 | * node nodename is changed in the completion service parameter else return |
| 588 | * 0. This function also set flag in the vport data structure to delay |
| 589 | * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit |
| 590 | * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric |
| 591 | * node nodename is changed in the completion service parameter. |
| 592 | * |
| 593 | * Return code |
| 594 | * 0 - FCID and Fabric Nodename and Fabric portname is not changed. |
| 595 | * 1 - FCID or Fabric Nodename or Fabric portname is changed. |
| 596 | * |
| 597 | **/ |
| 598 | static uint8_t |
| 599 | lpfc_check_clean_addr_bit(struct lpfc_vport *vport, |
| 600 | struct serv_parm *sp) |
| 601 | { |
James Smart | 8eb8b96 | 2016-07-06 12:36:08 -0700 | [diff] [blame] | 602 | struct lpfc_hba *phba = vport->phba; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 603 | uint8_t fabric_param_changed = 0; |
| 604 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 605 | |
| 606 | if ((vport->fc_prevDID != vport->fc_myDID) || |
| 607 | memcmp(&vport->fabric_portname, &sp->portName, |
| 608 | sizeof(struct lpfc_name)) || |
| 609 | memcmp(&vport->fabric_nodename, &sp->nodeName, |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 610 | sizeof(struct lpfc_name)) || |
| 611 | (vport->vport_flag & FAWWPN_PARAM_CHG)) { |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 612 | fabric_param_changed = 1; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 613 | vport->vport_flag &= ~FAWWPN_PARAM_CHG; |
| 614 | } |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 615 | /* |
| 616 | * Word 1 Bit 31 in common service parameter is overloaded. |
| 617 | * Word 1 Bit 31 in FLOGI request is multiple NPort request |
| 618 | * Word 1 Bit 31 in FLOGI response is clean address bit |
| 619 | * |
| 620 | * If fabric parameter is changed and clean address bit is |
| 621 | * cleared delay nport discovery if |
| 622 | * - vport->fc_prevDID != 0 (not initial discovery) OR |
| 623 | * - lpfc_delay_discovery module parameter is set. |
| 624 | */ |
| 625 | if (fabric_param_changed && !sp->cmn.clean_address_bit && |
James Smart | 8eb8b96 | 2016-07-06 12:36:08 -0700 | [diff] [blame] | 626 | (vport->fc_prevDID || phba->cfg_delay_discovery)) { |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 627 | spin_lock_irq(shost->host_lock); |
| 628 | vport->fc_flag |= FC_DISC_DELAYED; |
| 629 | spin_unlock_irq(shost->host_lock); |
| 630 | } |
| 631 | |
| 632 | return fabric_param_changed; |
| 633 | } |
| 634 | |
| 635 | |
| 636 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 637 | * 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] | 638 | * @vport: pointer to a host virtual N_Port data structure. |
| 639 | * @ndlp: pointer to a node-list data structure. |
| 640 | * @sp: pointer to service parameter data structure. |
| 641 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 642 | * |
| 643 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 644 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 645 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 646 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 647 | * @vport against the previously assigned N_Port ID. If it is different from |
| 648 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 649 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 650 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 651 | * is invoked to register login to the fabric. |
| 652 | * |
| 653 | * Return code |
| 654 | * 0 - Success (currently, always return 0) |
| 655 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 656 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 657 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 658 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 659 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 660 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 661 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 662 | struct lpfc_nodelist *np; |
| 663 | struct lpfc_nodelist *next_np; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 664 | uint8_t fabric_param_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 665 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 666 | spin_lock_irq(shost->host_lock); |
| 667 | vport->fc_flag |= FC_FABRIC; |
| 668 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 669 | |
| 670 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 671 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 672 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 673 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 674 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 675 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 676 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 677 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 678 | spin_lock_irq(shost->host_lock); |
| 679 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 680 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 681 | } |
| 682 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 683 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 684 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 685 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 686 | ndlp->nlp_class_sup = 0; |
| 687 | if (sp->cls1.classValid) |
| 688 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 689 | if (sp->cls2.classValid) |
| 690 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 691 | if (sp->cls3.classValid) |
| 692 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 693 | if (sp->cls4.classValid) |
| 694 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 695 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 696 | sp->cmn.bbRcvSizeLsb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 697 | |
| 698 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 699 | if (fabric_param_changed) { |
| 700 | /* Reset FDMI attribute masks based on config parameter */ |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 701 | if (phba->cfg_enable_SmartSAN || |
| 702 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 703 | /* Setup appropriate attribute masks */ |
| 704 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 705 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 706 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 707 | else |
| 708 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 709 | } else { |
| 710 | vport->fdmi_hba_mask = 0; |
| 711 | vport->fdmi_port_mask = 0; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | } |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 715 | memcpy(&vport->fabric_portname, &sp->portName, |
| 716 | sizeof(struct lpfc_name)); |
| 717 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 718 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 719 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 720 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 721 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 722 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 723 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 724 | LOG_ELS | LOG_VPORT, |
| 725 | "1816 FLOGI NPIV supported, " |
| 726 | "response data 0x%x\n", |
| 727 | sp->cmn.response_multiple_NPort); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 728 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 729 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 730 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 731 | } else { |
| 732 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 733 | to call reg_vnpid atleast for the physcial host */ |
| 734 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 735 | LOG_ELS | LOG_VPORT, |
| 736 | "1817 Fabric does not support NPIV " |
| 737 | "- configuring single port mode.\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 738 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 739 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 740 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 741 | } |
| 742 | } |
| 743 | |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 744 | /* |
| 745 | * For FC we need to do some special processing because of the SLI |
| 746 | * Port's default settings of the Common Service Parameters. |
| 747 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 748 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 749 | (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) { |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 750 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 751 | if (fabric_param_changed) |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 752 | lpfc_unregister_fcf_prep(phba); |
| 753 | |
| 754 | /* This should just update the VFI CSPs*/ |
| 755 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 756 | lpfc_issue_reg_vfi(vport); |
| 757 | } |
| 758 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 759 | if (fabric_param_changed && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 760 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 761 | |
| 762 | /* If our NportID changed, we need to ensure all |
| 763 | * remaining NPORTs get unreg_login'ed. |
| 764 | */ |
| 765 | list_for_each_entry_safe(np, next_np, |
| 766 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 767 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 768 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 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; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 910 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 911 | ndlp = lpfc_enable_node(vport, ndlp, |
| 912 | NLP_STE_UNUSED_NODE); |
| 913 | if(!ndlp) |
| 914 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 918 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 919 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 920 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 921 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 922 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 923 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 924 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 925 | spin_unlock_irq(shost->host_lock); |
James Smart | d33d0eb | 2017-11-20 16:00:34 -0800 | [diff] [blame] | 926 | |
| 927 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 928 | if (!mbox) |
| 929 | goto fail; |
| 930 | |
| 931 | lpfc_config_link(phba, mbox); |
| 932 | |
| 933 | mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
| 934 | mbox->vport = vport; |
| 935 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 936 | if (rc == MBX_NOT_FINISHED) { |
| 937 | mempool_free(mbox, phba->mbox_mem_pool); |
| 938 | goto fail; |
| 939 | } |
| 940 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 941 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 942 | * count indicating that ndlp can be released when other |
| 943 | * references to it are done. |
| 944 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 945 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 946 | |
James Smart | d33d0eb | 2017-11-20 16:00:34 -0800 | [diff] [blame] | 947 | /* Start discovery - this should just do CLEAR_LA */ |
| 948 | lpfc_disc_start(vport); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 949 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 950 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 951 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 952 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 953 | return -ENXIO; |
| 954 | } |
| 955 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 956 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 957 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 958 | * @phba: pointer to lpfc hba data structure. |
| 959 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 960 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 961 | * |
| 962 | * This routine is the top-level completion callback function for issuing |
| 963 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 964 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 965 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 966 | * returning 1), the command IOCB will be released and function returned. |
| 967 | * If the retry attempt has been given up (possibly reach the maximum |
| 968 | * number of retries), one additional decrement of ndlp reference shall be |
| 969 | * invoked before going out after releasing the command IOCB. This will |
| 970 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 971 | * invoke one decrement of ndlp reference count). If no error reported in |
| 972 | * the IOCB status, the command Port ID field is used to determine whether |
| 973 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 974 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 975 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 976 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 977 | * specific topology completion conditions. |
| 978 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 979 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 980 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 981 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 982 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 983 | struct lpfc_vport *vport = cmdiocb->vport; |
| 984 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 985 | IOCB_t *irsp = &rspiocb->iocb; |
| 986 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 987 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 988 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 989 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 990 | int rc; |
| 991 | |
| 992 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 993 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 994 | /* One additional decrement on node reference count to |
| 995 | * trigger the release of the node |
| 996 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 997 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 998 | goto out; |
| 999 | } |
| 1000 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1001 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1002 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 1003 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1004 | vport->port_state); |
| 1005 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1006 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1007 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1008 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1009 | * due to new FCF discovery |
| 1010 | */ |
| 1011 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1012 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 1013 | if (phba->link_state < LPFC_LINK_UP) |
| 1014 | goto stop_rr_fcf_flogi; |
| 1015 | if ((phba->fcoe_cvl_eventtag_attn == |
| 1016 | phba->fcoe_cvl_eventtag) && |
| 1017 | (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1018 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1019 | IOERR_SLI_ABORTED)) |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1020 | goto stop_rr_fcf_flogi; |
| 1021 | else |
| 1022 | phba->fcoe_cvl_eventtag_attn = |
| 1023 | phba->fcoe_cvl_eventtag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1024 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1025 | "2611 FLOGI failed on FCF (x%x), " |
| 1026 | "status:x%x/x%x, tmo:x%x, perform " |
| 1027 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1028 | phba->fcf.current_rec.fcf_indx, |
| 1029 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1030 | irsp->ulpTimeout); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1031 | lpfc_sli4_set_fcf_flogi_fail(phba, |
| 1032 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1033 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1034 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 1035 | if (rc) |
| 1036 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1037 | } |
| 1038 | |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1039 | stop_rr_fcf_flogi: |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1040 | /* FLOGI failure */ |
James Smart | c73455e | 2017-11-20 16:00:28 -0800 | [diff] [blame] | 1041 | if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 1042 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1043 | IOERR_LOOP_OPEN_FAILURE))) |
| 1044 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1045 | "2858 FLOGI failure Status:x%x/x%x " |
| 1046 | "TMO:x%x Data x%x x%x\n", |
| 1047 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1048 | irsp->ulpTimeout, phba->hba_flag, |
| 1049 | phba->fcf.fcf_flag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1050 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1051 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1052 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1053 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1054 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 1055 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 1056 | "0150 FLOGI failure Status:x%x/x%x " |
| 1057 | "xri x%x TMO:x%x\n", |
| 1058 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1059 | cmdiocb->sli4_xritag, irsp->ulpTimeout); |
| 1060 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 1061 | /* If this is not a loop open failure, bail out */ |
| 1062 | if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 1063 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1064 | IOERR_LOOP_OPEN_FAILURE))) |
| 1065 | goto flogifail; |
| 1066 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1067 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1068 | spin_lock_irq(shost->host_lock); |
| 1069 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 1070 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1071 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1072 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1073 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 1074 | * alpa map would take too long otherwise. |
| 1075 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1076 | if (phba->alpa_map[0] == 0) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1077 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1078 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1079 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1080 | (vport->fc_prevDID != vport->fc_myDID) || |
| 1081 | phba->fc_topology_changed)) { |
| 1082 | if (vport->fc_flag & FC_VFI_REGISTERED) { |
| 1083 | if (phba->fc_topology_changed) { |
| 1084 | lpfc_unregister_fcf_prep(phba); |
| 1085 | spin_lock_irq(shost->host_lock); |
| 1086 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 1087 | spin_unlock_irq(shost->host_lock); |
| 1088 | phba->fc_topology_changed = 0; |
| 1089 | } else { |
| 1090 | lpfc_sli4_unreg_all_rpis(vport); |
| 1091 | } |
| 1092 | } |
James Smart | 342b59c | 2016-03-31 14:12:31 -0700 | [diff] [blame] | 1093 | |
| 1094 | /* Do not register VFI if the driver aborted FLOGI */ |
| 1095 | if (!lpfc_error_lost_link(irsp)) |
| 1096 | lpfc_issue_reg_vfi(vport); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1097 | lpfc_nlp_put(ndlp); |
| 1098 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1099 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1100 | goto flogifail; |
| 1101 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1102 | spin_lock_irq(shost->host_lock); |
| 1103 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 1104 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1105 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1106 | |
| 1107 | /* |
| 1108 | * The FLogI succeeded. Sync the data for the CPU before |
| 1109 | * accessing it. |
| 1110 | */ |
| 1111 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 1112 | if (!prsp) |
| 1113 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1114 | sp = prsp->virt + sizeof(uint32_t); |
| 1115 | |
| 1116 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1117 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 1118 | "0101 FLOGI completes successfully, I/O tag:x%x, " |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 1119 | "xri x%x Data: x%x x%x x%x x%x x%x %x\n", |
| 1120 | cmdiocb->iotag, cmdiocb->sli4_xritag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1121 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1122 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution, |
| 1123 | vport->port_state, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1124 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1125 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1126 | /* |
| 1127 | * If Common Service Parameters indicate Nport |
| 1128 | * we are point to point, if Fport we are Fabric. |
| 1129 | */ |
| 1130 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1131 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1132 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1133 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1134 | else { |
| 1135 | lpfc_printf_vlog(vport, KERN_ERR, |
| 1136 | LOG_FIP | LOG_ELS, |
| 1137 | "2831 FLOGI response with cleared Fabric " |
| 1138 | "bit fcf_index 0x%x " |
| 1139 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 1140 | "Fabric Name " |
| 1141 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 1142 | phba->fcf.current_rec.fcf_indx, |
| 1143 | phba->fcf.current_rec.switch_name[0], |
| 1144 | phba->fcf.current_rec.switch_name[1], |
| 1145 | phba->fcf.current_rec.switch_name[2], |
| 1146 | phba->fcf.current_rec.switch_name[3], |
| 1147 | phba->fcf.current_rec.switch_name[4], |
| 1148 | phba->fcf.current_rec.switch_name[5], |
| 1149 | phba->fcf.current_rec.switch_name[6], |
| 1150 | phba->fcf.current_rec.switch_name[7], |
| 1151 | phba->fcf.current_rec.fabric_name[0], |
| 1152 | phba->fcf.current_rec.fabric_name[1], |
| 1153 | phba->fcf.current_rec.fabric_name[2], |
| 1154 | phba->fcf.current_rec.fabric_name[3], |
| 1155 | phba->fcf.current_rec.fabric_name[4], |
| 1156 | phba->fcf.current_rec.fabric_name[5], |
| 1157 | phba->fcf.current_rec.fabric_name[6], |
| 1158 | phba->fcf.current_rec.fabric_name[7]); |
| 1159 | lpfc_nlp_put(ndlp); |
| 1160 | spin_lock_irq(&phba->hbalock); |
| 1161 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1162 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1163 | spin_unlock_irq(&phba->hbalock); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 1164 | phba->fcf.fcf_redisc_attempted = 0; /* reset */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1165 | goto out; |
| 1166 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1167 | if (!rc) { |
| 1168 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1169 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 1170 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 1171 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1172 | "2769 FLOGI to FCF (x%x) " |
| 1173 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1174 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1175 | spin_lock_irq(&phba->hbalock); |
| 1176 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1177 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1178 | spin_unlock_irq(&phba->hbalock); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 1179 | phba->fcf.fcf_redisc_attempted = 0; /* reset */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1180 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1181 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | flogifail: |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1185 | spin_lock_irq(&phba->hbalock); |
| 1186 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 1187 | spin_unlock_irq(&phba->hbalock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1188 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1189 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1190 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1191 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1192 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1193 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1194 | |
| 1195 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1196 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1197 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1198 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1199 | IOERR_SLI_ABORTED) && |
| 1200 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1201 | IOERR_SLI_DOWN))) && |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1202 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 1203 | /* If FLOGI failed enable link interrupt. */ |
| 1204 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1205 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1206 | out: |
| 1207 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1208 | } |
| 1209 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1210 | /** |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 1211 | * lpfc_cmpl_els_link_down - Completion callback function for ELS command |
| 1212 | * aborted during a link down |
| 1213 | * @phba: pointer to lpfc hba data structure. |
| 1214 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1215 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1216 | * |
| 1217 | */ |
| 1218 | static void |
| 1219 | lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1220 | struct lpfc_iocbq *rspiocb) |
| 1221 | { |
| 1222 | IOCB_t *irsp; |
| 1223 | uint32_t *pcmd; |
| 1224 | uint32_t cmd; |
| 1225 | |
| 1226 | pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt); |
| 1227 | cmd = *pcmd; |
| 1228 | irsp = &rspiocb->iocb; |
| 1229 | |
| 1230 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 1231 | "6445 ELS completes after LINK_DOWN: " |
| 1232 | " Status %x/%x cmd x%x flg x%x\n", |
| 1233 | irsp->ulpStatus, irsp->un.ulpWord[4], cmd, |
| 1234 | cmdiocb->iocb_flag); |
| 1235 | |
| 1236 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) { |
| 1237 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 1238 | atomic_dec(&phba->fabric_iocb_count); |
| 1239 | } |
| 1240 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1241 | } |
| 1242 | |
| 1243 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1244 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1245 | * @vport: pointer to a host virtual N_Port data structure. |
| 1246 | * @ndlp: pointer to a node-list data structure. |
| 1247 | * @retry: number of retries to the command IOCB. |
| 1248 | * |
| 1249 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 1250 | * for a @vport. The initiator service parameters are put into the payload |
| 1251 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 1252 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 1253 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 1254 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 1255 | * |
| 1256 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1257 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1258 | * will be stored into the context1 field of the IOCB for the completion |
| 1259 | * callback function to the FLOGI ELS command. |
| 1260 | * |
| 1261 | * Return code |
| 1262 | * 0 - successfully issued flogi iocb for @vport |
| 1263 | * 1 - failed to issue flogi iocb for @vport |
| 1264 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1265 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1266 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1267 | uint8_t retry) |
| 1268 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1269 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1270 | struct serv_parm *sp; |
| 1271 | IOCB_t *icmd; |
| 1272 | struct lpfc_iocbq *elsiocb; |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1273 | struct lpfc_iocbq defer_flogi_acc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1274 | uint8_t *pcmd; |
| 1275 | uint16_t cmdsize; |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1276 | uint32_t tmo, did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1277 | int rc; |
| 1278 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1279 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1280 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1281 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1282 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1283 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1284 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1285 | |
| 1286 | icmd = &elsiocb->iocb; |
| 1287 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1288 | |
| 1289 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1290 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1291 | pcmd += sizeof(uint32_t); |
| 1292 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1293 | sp = (struct serv_parm *) pcmd; |
| 1294 | |
| 1295 | /* Setup CSPs accordingly for Fabric */ |
| 1296 | sp->cmn.e_d_tov = 0; |
| 1297 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 1298 | sp->cmn.virtual_fabric_support = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1299 | sp->cls1.classValid = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1300 | if (sp->cmn.fcphLow < FC_PH3) |
| 1301 | sp->cmn.fcphLow = FC_PH3; |
| 1302 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1303 | sp->cmn.fcphHigh = FC_PH3; |
| 1304 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 1305 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1306 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1307 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 1308 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1309 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1310 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1311 | /* Set the fcfi to the fcfi we registered with */ |
| 1312 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1313 | } |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1314 | /* Can't do SLI4 class2 without support sequence coalescing */ |
| 1315 | sp->cls2.classValid = 0; |
| 1316 | sp->cls2.seqDelivery = 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1317 | } else { |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1318 | /* Historical, setting sequential-delivery bit for SLI3 */ |
| 1319 | sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; |
| 1320 | sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1321 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 1322 | sp->cmn.request_multiple_Nport = 1; |
| 1323 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1324 | icmd->ulpCt_h = 1; |
| 1325 | icmd->ulpCt_l = 0; |
| 1326 | } else |
| 1327 | sp->cmn.request_multiple_Nport = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1328 | } |
| 1329 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1330 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1331 | icmd->un.elsreq64.myID = 0; |
| 1332 | icmd->un.elsreq64.fl = 1; |
| 1333 | } |
| 1334 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | tmo = phba->fc_ratov; |
| 1336 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1337 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1338 | phba->fc_ratov = tmo; |
| 1339 | |
| 1340 | phba->fc_stat.elsXmitFLOGI++; |
| 1341 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1342 | |
| 1343 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1344 | "Issue FLOGI: opt:x%x", |
| 1345 | phba->sli3_options, 0, 0); |
| 1346 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1347 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1348 | |
| 1349 | phba->hba_flag |= HBA_FLOGI_ISSUED; |
| 1350 | |
| 1351 | /* Check for a deferred FLOGI ACC condition */ |
| 1352 | if (phba->defer_flogi_acc_flag) { |
| 1353 | did = vport->fc_myDID; |
| 1354 | vport->fc_myDID = Fabric_DID; |
| 1355 | |
| 1356 | memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq)); |
| 1357 | |
| 1358 | defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id; |
| 1359 | defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id = |
| 1360 | phba->defer_flogi_acc_ox_id; |
| 1361 | |
| 1362 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1363 | "3354 Xmit deferred FLOGI ACC: rx_id: x%x," |
| 1364 | " ox_id: x%x, hba_flag x%x\n", |
| 1365 | phba->defer_flogi_acc_rx_id, |
| 1366 | phba->defer_flogi_acc_ox_id, phba->hba_flag); |
| 1367 | |
| 1368 | /* Send deferred FLOGI ACC */ |
| 1369 | lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc, |
| 1370 | ndlp, NULL); |
| 1371 | |
| 1372 | phba->defer_flogi_acc_flag = false; |
| 1373 | |
| 1374 | vport->fc_myDID = did; |
| 1375 | } |
| 1376 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1377 | if (rc == IOCB_ERROR) { |
| 1378 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1379 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1380 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1381 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1382 | } |
| 1383 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1384 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1385 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1386 | * @phba: pointer to lpfc hba data structure. |
| 1387 | * |
| 1388 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1389 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1390 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1391 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1392 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1393 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1394 | * |
| 1395 | * Return code |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1396 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1397 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1398 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1399 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1400 | { |
| 1401 | struct lpfc_sli_ring *pring; |
| 1402 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1403 | struct lpfc_nodelist *ndlp; |
| 1404 | IOCB_t *icmd; |
| 1405 | |
| 1406 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1407 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1408 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1409 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1410 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1411 | pring = lpfc_phba_elsring(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1412 | if (unlikely(!pring)) |
| 1413 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1414 | |
| 1415 | /* |
| 1416 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1417 | * searching for. |
| 1418 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1419 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1420 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1421 | icmd = &iocb->iocb; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1422 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1423 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1424 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1425 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1426 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1427 | } |
| 1428 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1429 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1430 | |
| 1431 | return 0; |
| 1432 | } |
| 1433 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1434 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1435 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1436 | * @vport: pointer to a host virtual N_Port data structure. |
| 1437 | * |
| 1438 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1439 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1440 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1441 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1442 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1443 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1444 | * @vport. |
| 1445 | * |
| 1446 | * Return code |
| 1447 | * 0 - failed to issue initial flogi for @vport |
| 1448 | * 1 - successfully issued initial flogi for @vport |
| 1449 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1450 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1451 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1452 | { |
| 1453 | struct lpfc_nodelist *ndlp; |
| 1454 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1455 | vport->port_state = LPFC_FLOGI; |
| 1456 | lpfc_set_disctmo(vport); |
| 1457 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1458 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1459 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1460 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1462 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1463 | if (!ndlp) |
| 1464 | return 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1465 | /* Set the node type */ |
| 1466 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1467 | /* Put ndlp onto node list */ |
| 1468 | lpfc_enqueue_node(vport, ndlp); |
| 1469 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1470 | /* re-setup ndlp without removing from node list */ |
| 1471 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1472 | if (!ndlp) |
| 1473 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1474 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1475 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1476 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1477 | /* This decrement of reference count to node shall kick off |
| 1478 | * the release of the node. |
| 1479 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1480 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1481 | return 0; |
| 1482 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1483 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1484 | } |
| 1485 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1486 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1487 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1488 | * @vport: pointer to a host virtual N_Port data structure. |
| 1489 | * |
| 1490 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1491 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1492 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1493 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1494 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1495 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1496 | * @vport. |
| 1497 | * |
| 1498 | * Return code |
| 1499 | * 0 - failed to issue initial fdisc for @vport |
| 1500 | * 1 - successfully issued initial fdisc for @vport |
| 1501 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1502 | int |
| 1503 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1504 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1505 | struct lpfc_nodelist *ndlp; |
| 1506 | |
| 1507 | /* First look for the Fabric ndlp */ |
| 1508 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1509 | if (!ndlp) { |
| 1510 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1511 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1512 | if (!ndlp) |
| 1513 | return 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1514 | /* Put ndlp onto node list */ |
| 1515 | lpfc_enqueue_node(vport, ndlp); |
| 1516 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1517 | /* re-setup ndlp without removing from node list */ |
| 1518 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1519 | if (!ndlp) |
| 1520 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1521 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1522 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1523 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1524 | /* decrement node reference count to trigger the release of |
| 1525 | * the node. |
| 1526 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1527 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1528 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1529 | } |
| 1530 | return 1; |
| 1531 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1532 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1533 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1534 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1535 | * @vport: pointer to a host virtual N_Port data structure. |
| 1536 | * |
| 1537 | * This routine checks whether there are more remaining Port Logins |
| 1538 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1539 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1540 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1541 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1542 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1543 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1544 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1545 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1546 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1547 | if (vport->num_disc_nodes) |
| 1548 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1549 | |
| 1550 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1551 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1552 | "0232 Continue discovery with %d PLOGIs to go " |
| 1553 | "Data: x%x x%x x%x\n", |
| 1554 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1555 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1556 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1557 | if (vport->fc_flag & FC_NLP_MORE) |
| 1558 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 1559 | lpfc_els_disc_plogi(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1560 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1561 | return; |
| 1562 | } |
| 1563 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1564 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1565 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1566 | * @phba: pointer to lpfc hba data structure. |
| 1567 | * @prsp: pointer to response IOCB payload. |
| 1568 | * @ndlp: pointer to a node-list data structure. |
| 1569 | * |
| 1570 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1571 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1572 | * The following cases are considered N_Port confirmed: |
| 1573 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1574 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1575 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1576 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1577 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1578 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1579 | * on that node to release the RPI associated with the node; 2) if there is |
| 1580 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1581 | * into, a new node shall be allocated (or activated). In either case, the |
| 1582 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1583 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1584 | * its pointer returned as the confirmed node. |
| 1585 | * |
| 1586 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1587 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1588 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1589 | * into an inactive state on the vport node list and the vport node list |
| 1590 | * management algorithm does not allow two node with a same DID. |
| 1591 | * |
| 1592 | * Return code |
| 1593 | * pointer to the PLOGI N_Port @ndlp |
| 1594 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1595 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1596 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1597 | struct lpfc_nodelist *ndlp) |
| 1598 | { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1599 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1600 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1601 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1602 | struct lpfc_rport_data *rdata; |
| 1603 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1604 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1605 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1606 | uint32_t rc, keepDID = 0, keep_nlp_flag = 0; |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1607 | uint32_t keep_new_nlp_flag = 0; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1608 | uint16_t keep_nlp_state; |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1609 | u32 keep_nlp_fc4_type = 0; |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1610 | struct lpfc_nvme_rport *keep_nrport = NULL; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1611 | int put_node; |
| 1612 | int put_rport; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1613 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1614 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1615 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1616 | * by WWPN. Just return the ndlp that was given to us. |
| 1617 | */ |
| 1618 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1619 | return ndlp; |
| 1620 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1621 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1622 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1623 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1624 | /* 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] | 1625 | * we have for that ndlp. If not, we have some work to do. |
| 1626 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1627 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1628 | |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1629 | /* return immediately if the WWPN matches ndlp */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1630 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1631 | return ndlp; |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1632 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1633 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1634 | active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool, |
| 1635 | GFP_KERNEL); |
| 1636 | if (active_rrqs_xri_bitmap) |
| 1637 | memset(active_rrqs_xri_bitmap, 0, |
| 1638 | phba->cfg_rrq_xri_bitmap_sz); |
| 1639 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1640 | |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1641 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE, |
| 1642 | "3178 PLOGI confirm: ndlp x%x x%x x%x: " |
| 1643 | "new_ndlp x%x x%x x%x\n", |
| 1644 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type, |
| 1645 | (new_ndlp ? new_ndlp->nlp_DID : 0), |
| 1646 | (new_ndlp ? new_ndlp->nlp_flag : 0), |
| 1647 | (new_ndlp ? new_ndlp->nlp_fc4_type : 0)); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1648 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1649 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1650 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1651 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1652 | if (!rc) { |
| 1653 | if (active_rrqs_xri_bitmap) |
| 1654 | mempool_free(active_rrqs_xri_bitmap, |
| 1655 | phba->active_rrq_pool); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1656 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1657 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1658 | new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1659 | if (!new_ndlp) { |
| 1660 | if (active_rrqs_xri_bitmap) |
| 1661 | mempool_free(active_rrqs_xri_bitmap, |
| 1662 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1663 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1664 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1665 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1666 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1667 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1668 | if (!rc) { |
| 1669 | if (active_rrqs_xri_bitmap) |
| 1670 | mempool_free(active_rrqs_xri_bitmap, |
| 1671 | phba->active_rrq_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1672 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1673 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1674 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1675 | NLP_STE_UNUSED_NODE); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1676 | if (!new_ndlp) { |
| 1677 | if (active_rrqs_xri_bitmap) |
| 1678 | mempool_free(active_rrqs_xri_bitmap, |
| 1679 | phba->active_rrq_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1680 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1681 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1682 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1683 | if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap) |
| 1684 | memcpy(active_rrqs_xri_bitmap, |
| 1685 | new_ndlp->active_rrqs_xri_bitmap, |
| 1686 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1687 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1688 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1689 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1690 | active_rrqs_xri_bitmap) |
| 1691 | memcpy(active_rrqs_xri_bitmap, |
| 1692 | new_ndlp->active_rrqs_xri_bitmap, |
| 1693 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1694 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1695 | |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1696 | /* At this point in this routine, we know new_ndlp will be |
| 1697 | * returned. however, any previous GID_FTs that were done |
| 1698 | * would have updated nlp_fc4_type in ndlp, so we must ensure |
| 1699 | * new_ndlp has the right value. |
| 1700 | */ |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1701 | if (vport->fc_flag & FC_FABRIC) { |
| 1702 | keep_nlp_fc4_type = new_ndlp->nlp_fc4_type; |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1703 | new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type; |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1704 | } |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1705 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1706 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1707 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1708 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1709 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1710 | memcpy(new_ndlp->active_rrqs_xri_bitmap, |
| 1711 | ndlp->active_rrqs_xri_bitmap, |
| 1712 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1713 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1714 | spin_lock_irq(shost->host_lock); |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1715 | keep_new_nlp_flag = new_ndlp->nlp_flag; |
| 1716 | keep_nlp_flag = ndlp->nlp_flag; |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1717 | new_ndlp->nlp_flag = ndlp->nlp_flag; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 1718 | |
| 1719 | /* if new_ndlp had NLP_UNREG_INP set, keep it */ |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1720 | if (keep_new_nlp_flag & NLP_UNREG_INP) |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 1721 | new_ndlp->nlp_flag |= NLP_UNREG_INP; |
| 1722 | else |
| 1723 | new_ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 1724 | |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1725 | /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */ |
| 1726 | if (keep_new_nlp_flag & NLP_RPI_REGISTERED) |
| 1727 | new_ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 1728 | else |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1729 | new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
| 1730 | |
| 1731 | ndlp->nlp_flag = keep_new_nlp_flag; |
| 1732 | |
| 1733 | /* if ndlp had NLP_UNREG_INP set, keep it */ |
| 1734 | if (keep_nlp_flag & NLP_UNREG_INP) |
| 1735 | ndlp->nlp_flag |= NLP_UNREG_INP; |
| 1736 | else |
| 1737 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 1738 | |
| 1739 | /* if ndlp had NLP_RPI_REGISTERED set, keep it */ |
| 1740 | if (keep_nlp_flag & NLP_RPI_REGISTERED) |
| 1741 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| 1742 | else |
| 1743 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 1744 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1745 | spin_unlock_irq(shost->host_lock); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1746 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1747 | /* Set nlp_states accordingly */ |
| 1748 | keep_nlp_state = new_ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1749 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1750 | |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1751 | /* interchange the nvme remoteport structs */ |
| 1752 | keep_nrport = new_ndlp->nrport; |
| 1753 | new_ndlp->nrport = ndlp->nrport; |
| 1754 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1755 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1756 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1757 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1758 | * to put ndlp on UNUSED list and try to free it. |
| 1759 | */ |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1760 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1761 | "3179 PLOGI confirm NEW: %x %x\n", |
| 1762 | new_ndlp->nlp_DID, keepDID); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1763 | |
| 1764 | /* Fix up the rport accordingly */ |
| 1765 | rport = ndlp->rport; |
| 1766 | if (rport) { |
| 1767 | rdata = rport->dd_data; |
| 1768 | if (rdata->pnode == ndlp) { |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1769 | /* break the link before dropping the ref */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1770 | ndlp->rport = NULL; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1771 | lpfc_nlp_put(ndlp); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1772 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1773 | new_ndlp->rport = rport; |
| 1774 | } |
| 1775 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1776 | } |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1777 | |
| 1778 | /* Fix up the nvme rport */ |
| 1779 | if (ndlp->nrport) { |
| 1780 | ndlp->nrport = NULL; |
| 1781 | lpfc_nlp_put(ndlp); |
| 1782 | } |
| 1783 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1784 | /* We shall actually free the ndlp with both nlp_DID and |
| 1785 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1786 | * nodelist never to be used. |
| 1787 | */ |
| 1788 | if (ndlp->nlp_DID == 0) { |
| 1789 | spin_lock_irq(&phba->ndlp_lock); |
| 1790 | NLP_SET_FREE_REQ(ndlp); |
| 1791 | spin_unlock_irq(&phba->ndlp_lock); |
| 1792 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1793 | |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1794 | /* Two ndlps cannot have the same did on the nodelist. |
| 1795 | * Note: for this case, ndlp has a NULL WWPN so setting |
| 1796 | * the nlp_fc4_type isn't required. |
| 1797 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1798 | ndlp->nlp_DID = keepDID; |
James Smart | 4938250 | 2017-11-20 16:00:38 -0800 | [diff] [blame] | 1799 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1800 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1801 | active_rrqs_xri_bitmap) |
| 1802 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1803 | active_rrqs_xri_bitmap, |
| 1804 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1805 | |
| 1806 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 1807 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1808 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1809 | else { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1810 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1811 | "3180 PLOGI confirm SWAP: %x %x\n", |
| 1812 | new_ndlp->nlp_DID, keepDID); |
| 1813 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1814 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1815 | |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1816 | /* Two ndlps cannot have the same did and the fc4 |
| 1817 | * type must be transferred because the ndlp is in |
| 1818 | * flight. |
| 1819 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1820 | ndlp->nlp_DID = keepDID; |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1821 | ndlp->nlp_fc4_type = keep_nlp_fc4_type; |
| 1822 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1823 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1824 | active_rrqs_xri_bitmap) |
| 1825 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1826 | active_rrqs_xri_bitmap, |
| 1827 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1828 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1829 | /* Since we are switching over to the new_ndlp, |
| 1830 | * reset the old ndlp state |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1831 | */ |
| 1832 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 1833 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1834 | keep_nlp_state = NLP_STE_NPR_NODE; |
| 1835 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1836 | |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1837 | /* Previous ndlp no longer active with nvme host transport. |
| 1838 | * Remove reference from earlier registration unless the |
| 1839 | * nvme host took care of it. |
| 1840 | */ |
| 1841 | if (ndlp->nrport) |
| 1842 | lpfc_nlp_put(ndlp); |
| 1843 | ndlp->nrport = keep_nrport; |
| 1844 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1845 | /* Fix up the rport accordingly */ |
| 1846 | rport = ndlp->rport; |
| 1847 | if (rport) { |
| 1848 | rdata = rport->dd_data; |
| 1849 | put_node = rdata->pnode != NULL; |
| 1850 | put_rport = ndlp->rport != NULL; |
| 1851 | rdata->pnode = NULL; |
| 1852 | ndlp->rport = NULL; |
| 1853 | if (put_node) |
| 1854 | lpfc_nlp_put(ndlp); |
| 1855 | if (put_rport) |
| 1856 | put_device(&rport->dev); |
| 1857 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1858 | } |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1859 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1860 | active_rrqs_xri_bitmap) |
| 1861 | mempool_free(active_rrqs_xri_bitmap, |
| 1862 | phba->active_rrq_pool); |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1863 | |
| 1864 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE, |
| 1865 | "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n", |
| 1866 | new_ndlp->nlp_DID, new_ndlp->nlp_flag, |
| 1867 | new_ndlp->nlp_fc4_type); |
| 1868 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1869 | return new_ndlp; |
| 1870 | } |
| 1871 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1872 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1873 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1874 | * @vport: pointer to a host virtual N_Port data structure. |
| 1875 | * |
| 1876 | * This routine checks whether more Registration State Change |
| 1877 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1878 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1879 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1880 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1881 | * handling the RSCNs. |
| 1882 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1883 | void |
| 1884 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1885 | { |
| 1886 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1887 | |
| 1888 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1889 | /* |
| 1890 | * Check to see if more RSCNs came in while we were |
| 1891 | * processing this one. |
| 1892 | */ |
| 1893 | if (vport->fc_rscn_id_cnt || |
| 1894 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1895 | lpfc_els_handle_rscn(vport); |
| 1896 | else { |
| 1897 | spin_lock_irq(shost->host_lock); |
| 1898 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1899 | spin_unlock_irq(shost->host_lock); |
| 1900 | } |
| 1901 | } |
| 1902 | } |
| 1903 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1904 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1905 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. |
| 1906 | * @phba: pointer to lpfc hba data structure. |
| 1907 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1908 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1909 | * |
| 1910 | * This routine will call the clear rrq function to free the rrq and |
| 1911 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not |
| 1912 | * exist then the clear_rrq is still called because the rrq needs to |
| 1913 | * be freed. |
| 1914 | **/ |
| 1915 | |
| 1916 | static void |
| 1917 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1918 | struct lpfc_iocbq *rspiocb) |
| 1919 | { |
| 1920 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1921 | IOCB_t *irsp; |
| 1922 | struct lpfc_nodelist *ndlp; |
| 1923 | struct lpfc_node_rrq *rrq; |
| 1924 | |
| 1925 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1926 | rrq = cmdiocb->context_un.rrq; |
| 1927 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1928 | |
| 1929 | irsp = &rspiocb->iocb; |
| 1930 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1931 | "RRQ cmpl: status:x%x/x%x did:x%x", |
| 1932 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1933 | irsp->un.elsreq64.remoteID); |
| 1934 | |
| 1935 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
| 1936 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { |
| 1937 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1938 | "2882 RRQ completes to NPort x%x " |
| 1939 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1940 | irsp->un.elsreq64.remoteID, |
| 1941 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1942 | irsp->ulpIoTag); |
| 1943 | goto out; |
| 1944 | } |
| 1945 | |
| 1946 | /* rrq completes to NPort <nlp_DID> */ |
| 1947 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1948 | "2880 RRQ completes to NPort x%x " |
| 1949 | "Data: x%x x%x x%x x%x x%x\n", |
| 1950 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1951 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); |
| 1952 | |
| 1953 | if (irsp->ulpStatus) { |
| 1954 | /* Check for retry */ |
| 1955 | /* RRQ failed Don't print the vport to vport rjts */ |
| 1956 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1957 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1958 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1959 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1960 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1961 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", |
| 1962 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1963 | irsp->un.ulpWord[4]); |
| 1964 | } |
| 1965 | out: |
| 1966 | if (rrq) |
| 1967 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1968 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1969 | return; |
| 1970 | } |
| 1971 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1972 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1973 | * @phba: pointer to lpfc hba data structure. |
| 1974 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1975 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1976 | * |
| 1977 | * This routine is the completion callback function for issuing the Port |
| 1978 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1979 | * 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] | 1980 | * 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] | 1981 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1982 | * checked for error conditons. If there is error status reported, PLOGI |
| 1983 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1984 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1985 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1986 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1987 | * there are additional N_Port nodes with the vport that need to perform |
| 1988 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1989 | * PLOGIs. |
| 1990 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1991 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1992 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1993 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1995 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1996 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1997 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1998 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1999 | struct lpfc_dmabuf *prsp; |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 2000 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2001 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2002 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2003 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2004 | |
| 2005 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2006 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2007 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 2008 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2009 | irsp->un.elsreq64.remoteID); |
| 2010 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2011 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2012 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2013 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2014 | "0136 PLOGI completes to NPort x%x " |
| 2015 | "with no ndlp. Data: x%x x%x x%x\n", |
| 2016 | irsp->un.elsreq64.remoteID, |
| 2017 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2018 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2019 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2020 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2021 | |
| 2022 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2023 | * is being used during discovery. |
| 2024 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2025 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2026 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2027 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2028 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2029 | |
| 2030 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2031 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2032 | "0102 PLOGI completes to NPort x%06x " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2033 | "Data: x%x x%x x%x x%x x%x\n", |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2034 | ndlp->nlp_DID, ndlp->nlp_fc4_type, |
| 2035 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2036 | disc, vport->num_disc_nodes); |
| 2037 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2038 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2039 | if (lpfc_els_chk_latt(vport)) { |
| 2040 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2041 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2042 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2043 | goto out; |
| 2044 | } |
| 2045 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2046 | if (irsp->ulpStatus) { |
| 2047 | /* Check for retry */ |
| 2048 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2049 | /* ELS command is being retried */ |
| 2050 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2051 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2052 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2053 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2054 | } |
| 2055 | goto out; |
| 2056 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2057 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 2058 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 2059 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 2060 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 2061 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 2062 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2063 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 2064 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2065 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2066 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 2067 | if (!lpfc_error_lost_link(irsp)) |
| 2068 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2069 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2070 | } else { |
| 2071 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 2072 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2073 | cmdiocb->context2)->list.next, |
| 2074 | struct lpfc_dmabuf, list); |
| 2075 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 2076 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2077 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | } |
| 2079 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2080 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2081 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2082 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2083 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2084 | if (vport->num_disc_nodes == 0) { |
| 2085 | spin_lock_irq(shost->host_lock); |
| 2086 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2087 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2088 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2089 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2090 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | out: |
| 2095 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2096 | return; |
| 2097 | } |
| 2098 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2099 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2100 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2101 | * @vport: pointer to a host virtual N_Port data structure. |
| 2102 | * @did: destination port identifier. |
| 2103 | * @retry: number of retries to the command IOCB. |
| 2104 | * |
| 2105 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 2106 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 2107 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 2108 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 2109 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 2110 | * |
| 2111 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2112 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2113 | * will be stored into the context1 field of the IOCB for the completion |
| 2114 | * callback function to the PLOGI ELS command. |
| 2115 | * |
| 2116 | * Return code |
| 2117 | * 0 - Successfully issued a plogi for @vport |
| 2118 | * 1 - failed to issue a plogi for @vport |
| 2119 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2121 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2123 | struct lpfc_hba *phba = vport->phba; |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 2124 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | struct serv_parm *sp; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2126 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2127 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2128 | uint8_t *pcmd; |
| 2129 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2130 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2131 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2132 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2133 | |
| 2134 | if (ndlp) { |
| 2135 | /* Defer the processing of the issue PLOGI until after the |
| 2136 | * outstanding UNREG_RPI mbox command completes, unless we |
| 2137 | * are going offline. This logic does not apply for Fabric DIDs |
| 2138 | */ |
| 2139 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2140 | ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) && |
| 2141 | !(vport->fc_flag & FC_OFFLINE_MODE)) { |
| 2142 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2143 | "4110 Issue PLOGI x%x deferred " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2144 | "on NPort x%x rpi x%x Data: x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2145 | ndlp->nlp_defer_did, ndlp->nlp_DID, |
| 2146 | ndlp->nlp_rpi, ndlp); |
| 2147 | |
| 2148 | /* We can only defer 1st PLOGI */ |
| 2149 | if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING) |
| 2150 | ndlp->nlp_defer_did = did; |
| 2151 | return 0; |
| 2152 | } |
| 2153 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2154 | ndlp = NULL; |
| 2155 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2156 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2157 | /* 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] | 2158 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2159 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2160 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2161 | if (!elsiocb) |
| 2162 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2163 | |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 2164 | shost = lpfc_shost_from_vport(vport); |
| 2165 | spin_lock_irq(shost->host_lock); |
| 2166 | ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT; |
| 2167 | spin_unlock_irq(shost->host_lock); |
| 2168 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2170 | |
| 2171 | /* For PLOGI request, remainder of payload is service parameters */ |
| 2172 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2173 | pcmd += sizeof(uint32_t); |
| 2174 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2175 | sp = (struct serv_parm *) pcmd; |
| 2176 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2177 | /* |
| 2178 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 2179 | * to device on remote loops work. |
| 2180 | */ |
| 2181 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 2182 | sp->cmn.altBbCredit = 1; |
| 2183 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2184 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 2185 | sp->cmn.fcphLow = FC_PH_4_3; |
| 2186 | |
| 2187 | if (sp->cmn.fcphHigh < FC_PH3) |
| 2188 | sp->cmn.fcphHigh = FC_PH3; |
| 2189 | |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 2190 | sp->cmn.valid_vendor_ver_level = 0; |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2191 | memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 2192 | sp->cmn.bbRcvSizeMsb &= 0xF; |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 2193 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2194 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2195 | "Issue PLOGI: did:x%x", |
| 2196 | did, 0, 0); |
| 2197 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2198 | /* If our firmware supports this feature, convey that |
| 2199 | * information to the target using the vendor specific field. |
| 2200 | */ |
| 2201 | if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { |
| 2202 | sp->cmn.valid_vendor_ver_level = 1; |
| 2203 | sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); |
| 2204 | sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP); |
| 2205 | } |
| 2206 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2207 | phba->fc_stat.elsXmitPLOGI++; |
| 2208 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2209 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2210 | |
| 2211 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2212 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2213 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2214 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2215 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | } |
| 2217 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2218 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2219 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2220 | * @phba: pointer to lpfc hba data structure. |
| 2221 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2222 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2223 | * |
| 2224 | * This routine is the completion callback function for a Process Login |
| 2225 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 2226 | * status. If there is error status reported, PRLI retry shall be attempted |
| 2227 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 2228 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 2229 | * ndlp to mark the PRLI completion. |
| 2230 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2232 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2233 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2234 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2235 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2236 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2237 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2238 | struct lpfc_nodelist *ndlp; |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 2239 | char *mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2240 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2241 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2242 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2243 | |
| 2244 | irsp = &(rspiocb->iocb); |
| 2245 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2246 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2247 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 9de416a | 2017-12-08 17:18:07 -0800 | [diff] [blame] | 2248 | |
| 2249 | /* Driver supports multiple FC4 types. Counters matter. */ |
| 2250 | vport->fc_prli_sent--; |
| 2251 | ndlp->fc4_prli_sent--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2252 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2253 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2254 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2255 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 2256 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2257 | ndlp->nlp_DID); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2258 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2259 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2260 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2261 | "0103 PRLI completes to NPort x%06x " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2262 | "Data: x%x x%x x%x x%x\n", |
| 2263 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2264 | vport->num_disc_nodes, ndlp->fc4_prli_sent); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2265 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2266 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2267 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2268 | goto out; |
| 2269 | |
| 2270 | if (irsp->ulpStatus) { |
| 2271 | /* Check for retry */ |
| 2272 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2273 | /* ELS command is being retried */ |
| 2274 | goto out; |
| 2275 | } |
James Smart | 3120046 | 2017-05-15 15:20:42 -0700 | [diff] [blame] | 2276 | |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 2277 | /* If we don't send GFT_ID to Fabric, a PRLI error |
| 2278 | * could be expected. |
| 2279 | */ |
| 2280 | if ((vport->fc_flag & FC_FABRIC) || |
| 2281 | (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) |
| 2282 | mode = KERN_ERR; |
| 2283 | else |
| 2284 | mode = KERN_INFO; |
| 2285 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2286 | /* PRLI failed */ |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 2287 | lpfc_printf_vlog(vport, mode, LOG_ELS, |
James Smart | 3120046 | 2017-05-15 15:20:42 -0700 | [diff] [blame] | 2288 | "2754 PRLI failure DID:%06X Status:x%x/x%x, " |
| 2289 | "data: x%x\n", |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2290 | ndlp->nlp_DID, irsp->ulpStatus, |
James Smart | 3120046 | 2017-05-15 15:20:42 -0700 | [diff] [blame] | 2291 | irsp->un.ulpWord[4], ndlp->fc4_prli_sent); |
| 2292 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2293 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2294 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2295 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2296 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2297 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2298 | NLP_EVT_CMPL_PRLI); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2299 | } else { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2300 | /* Good status, call state machine. However, if another |
| 2301 | * PRLI is outstanding, don't call the state machine |
| 2302 | * because final disposition to Mapped or Unmapped is |
| 2303 | * completed there. |
| 2304 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2305 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2306 | NLP_EVT_CMPL_PRLI); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2307 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2308 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | out: |
| 2310 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2311 | return; |
| 2312 | } |
| 2313 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2314 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2315 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2316 | * @vport: pointer to a host virtual N_Port data structure. |
| 2317 | * @ndlp: pointer to a node-list data structure. |
| 2318 | * @retry: number of retries to the command IOCB. |
| 2319 | * |
| 2320 | * This routine issues a Process Login (PRLI) ELS command for the |
| 2321 | * @vport. The PRLI service parameters are set up in the payload of the |
| 2322 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 2323 | * is put to the IOCB completion callback func field before invoking the |
| 2324 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 2325 | * |
| 2326 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2327 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2328 | * will be stored into the context1 field of the IOCB for the completion |
| 2329 | * callback function to the PRLI ELS command. |
| 2330 | * |
| 2331 | * Return code |
| 2332 | * 0 - successfully issued prli iocb command for @vport |
| 2333 | * 1 - failed to issue prli iocb command for @vport |
| 2334 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2335 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2336 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2337 | uint8_t retry) |
| 2338 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2339 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2340 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2341 | PRLI *npr; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2342 | struct lpfc_nvme_prli *npr_nvme; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2343 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2344 | uint8_t *pcmd; |
| 2345 | uint16_t cmdsize; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2346 | u32 local_nlp_type, elscmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2347 | |
Dick Kennedy | 991f0c0 | 2017-08-23 16:55:39 -0700 | [diff] [blame] | 2348 | /* |
| 2349 | * If we are in RSCN mode, the FC4 types supported from a |
| 2350 | * previous GFT_ID command may not be accurate. So, if we |
| 2351 | * are a NVME Initiator, always look for the possibility of |
| 2352 | * the remote NPort beng a NVME Target. |
| 2353 | */ |
| 2354 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2355 | vport->fc_flag & FC_RSCN_MODE && |
| 2356 | vport->nvmei_support) |
| 2357 | ndlp->nlp_fc4_type |= NLP_FC4_NVME; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2358 | local_nlp_type = ndlp->nlp_fc4_type; |
| 2359 | |
James Smart | 9de416a | 2017-12-08 17:18:07 -0800 | [diff] [blame] | 2360 | /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp |
| 2361 | * fields here before any of them can complete. |
| 2362 | */ |
| 2363 | ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); |
| 2364 | ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR); |
| 2365 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2366 | ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC); |
James Smart | 9de416a | 2017-12-08 17:18:07 -0800 | [diff] [blame] | 2367 | ndlp->nvme_fb_size = 0; |
| 2368 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2369 | send_next_prli: |
| 2370 | if (local_nlp_type & NLP_FC4_FCP) { |
| 2371 | /* Payload is 4 + 16 = 20 x14 bytes. */ |
| 2372 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
| 2373 | elscmd = ELS_CMD_PRLI; |
| 2374 | } else if (local_nlp_type & NLP_FC4_NVME) { |
| 2375 | /* Payload is 4 + 20 = 24 x18 bytes. */ |
| 2376 | cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli)); |
| 2377 | elscmd = ELS_CMD_NVMEPRLI; |
| 2378 | } else { |
| 2379 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2380 | "3083 Unknown FC_TYPE x%x ndlp x%06x\n", |
| 2381 | ndlp->nlp_fc4_type, ndlp->nlp_DID); |
| 2382 | return 1; |
| 2383 | } |
James Smart | 09559e8 | 2017-06-15 22:56:46 -0700 | [diff] [blame] | 2384 | |
| 2385 | /* SLI3 ports don't support NVME. If this rport is a strict NVME |
| 2386 | * FC4 type, implicitly LOGO. |
| 2387 | */ |
| 2388 | if (phba->sli_rev == LPFC_SLI_REV3 && |
| 2389 | ndlp->nlp_fc4_type == NLP_FC4_NVME) { |
| 2390 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2391 | "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n", |
| 2392 | ndlp->nlp_type); |
| 2393 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
| 2394 | return 1; |
| 2395 | } |
| 2396 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2397 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2398 | ndlp->nlp_DID, elscmd); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2399 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2400 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2401 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2402 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2403 | |
| 2404 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2405 | memset(pcmd, 0, cmdsize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2407 | if (local_nlp_type & NLP_FC4_FCP) { |
| 2408 | /* Remainder of payload is FCP PRLI parameter page. |
| 2409 | * Note: this data structure is defined as |
| 2410 | * BE/LE in the structure definition so no |
| 2411 | * byte swap call is made. |
| 2412 | */ |
| 2413 | *((uint32_t *)(pcmd)) = ELS_CMD_PRLI; |
| 2414 | pcmd += sizeof(uint32_t); |
| 2415 | npr = (PRLI *)pcmd; |
| 2416 | |
| 2417 | /* |
| 2418 | * If our firmware version is 3.20 or later, |
| 2419 | * set the following bits for FC-TAPE support. |
| 2420 | */ |
| 2421 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 2422 | npr->ConfmComplAllowed = 1; |
| 2423 | npr->Retry = 1; |
| 2424 | npr->TaskRetryIdReq = 1; |
| 2425 | } |
| 2426 | npr->estabImagePair = 1; |
| 2427 | npr->readXferRdyDis = 1; |
| 2428 | if (vport->cfg_first_burst_size) |
| 2429 | npr->writeXferRdyDis = 1; |
| 2430 | |
| 2431 | /* For FCP support */ |
| 2432 | npr->prliType = PRLI_FCP_TYPE; |
| 2433 | npr->initiatorFunc = 1; |
| 2434 | elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ; |
| 2435 | |
| 2436 | /* Remove FCP type - processed. */ |
| 2437 | local_nlp_type &= ~NLP_FC4_FCP; |
| 2438 | } else if (local_nlp_type & NLP_FC4_NVME) { |
| 2439 | /* Remainder of payload is NVME PRLI parameter page. |
| 2440 | * This data structure is the newer definition that |
| 2441 | * uses bf macros so a byte swap is required. |
| 2442 | */ |
| 2443 | *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI; |
| 2444 | pcmd += sizeof(uint32_t); |
| 2445 | npr_nvme = (struct lpfc_nvme_prli *)pcmd; |
| 2446 | bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); |
| 2447 | bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ |
James Smart | 0d8af09 | 2019-08-14 16:57:10 -0700 | [diff] [blame] | 2448 | if (phba->nsler) { |
| 2449 | bf_set(prli_nsler, npr_nvme, 1); |
| 2450 | bf_set(prli_conf, npr_nvme, 1); |
| 2451 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2452 | |
| 2453 | /* Only initiators request first burst. */ |
| 2454 | if ((phba->cfg_nvme_enable_fb) && |
| 2455 | !phba->nvmet_support) |
| 2456 | bf_set(prli_fba, npr_nvme, 1); |
| 2457 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2458 | if (phba->nvmet_support) { |
| 2459 | bf_set(prli_tgt, npr_nvme, 1); |
| 2460 | bf_set(prli_disc, npr_nvme, 1); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2461 | } else { |
| 2462 | bf_set(prli_init, npr_nvme, 1); |
James Smart | a5ff068 | 2018-01-30 15:58:56 -0800 | [diff] [blame] | 2463 | bf_set(prli_conf, npr_nvme, 1); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2464 | } |
James Smart | a5ff068 | 2018-01-30 15:58:56 -0800 | [diff] [blame] | 2465 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2466 | npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); |
| 2467 | npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); |
| 2468 | elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ; |
| 2469 | |
| 2470 | /* Remove NVME type - processed. */ |
| 2471 | local_nlp_type &= ~NLP_FC4_NVME; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2472 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2473 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2474 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2475 | "Issue PRLI: did:x%x", |
| 2476 | ndlp->nlp_DID, 0, 0); |
| 2477 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2478 | phba->fc_stat.elsXmitPRLI++; |
| 2479 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2480 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2481 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 9de416a | 2017-12-08 17:18:07 -0800 | [diff] [blame] | 2482 | |
| 2483 | /* The vport counters are used for lpfc_scan_finished, but |
| 2484 | * the ndlp is used to track outstanding PRLIs for different |
| 2485 | * FC4 types. |
| 2486 | */ |
| 2487 | vport->fc_prli_sent++; |
| 2488 | ndlp->fc4_prli_sent++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2489 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2490 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2491 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2492 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2493 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2494 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2495 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2496 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2497 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2498 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2499 | |
| 2500 | /* The driver supports 2 FC4 types. Make sure |
| 2501 | * a PRLI is issued for all types before exiting. |
| 2502 | */ |
James Smart | 09559e8 | 2017-06-15 22:56:46 -0700 | [diff] [blame] | 2503 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2504 | local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME)) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2505 | goto send_next_prli; |
| 2506 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2507 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2508 | } |
| 2509 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2510 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2511 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2512 | * @vport: pointer to a host virtual N_Port data structure. |
| 2513 | * |
| 2514 | * This routine performs Registration State Change Notification (RSCN) |
| 2515 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 2516 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 2517 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 2518 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 2519 | * invoked to check and handle possible more RSCN came in during the period |
| 2520 | * of processing the current ones. |
| 2521 | **/ |
| 2522 | static void |
| 2523 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 2524 | { |
| 2525 | lpfc_can_disctmo(vport); |
| 2526 | |
| 2527 | /* RSCN discovery */ |
| 2528 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 2529 | if (vport->fc_npr_cnt) |
| 2530 | if (lpfc_els_disc_plogi(vport)) |
| 2531 | return; |
| 2532 | |
| 2533 | lpfc_end_rscn(vport); |
| 2534 | } |
| 2535 | |
| 2536 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2537 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2538 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 2539 | * |
| 2540 | * This function is called when the final ADISC is completed during discovery. |
| 2541 | * This function handles clearing link attention or issuing reg_vpi depending |
| 2542 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 2543 | * discovery. |
| 2544 | * This function is called with no locks held. |
| 2545 | **/ |
| 2546 | static void |
| 2547 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 2548 | { |
| 2549 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2550 | struct lpfc_hba *phba = vport->phba; |
| 2551 | |
| 2552 | /* |
| 2553 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 2554 | * and continue discovery. |
| 2555 | */ |
| 2556 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2557 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 2558 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | d454c91 | 2014-12-30 12:08:58 -0500 | [diff] [blame] | 2559 | /* The ADISCs are complete. Doesn't matter if they |
| 2560 | * succeeded or failed because the ADISC completion |
| 2561 | * routine guarantees to call the state machine and |
| 2562 | * the RPI is either unregistered (failed ADISC response) |
| 2563 | * or the RPI is still valid and the node is marked |
| 2564 | * mapped for a target. The exchanges should be in the |
| 2565 | * correct state. This code is specific to SLI3. |
| 2566 | */ |
| 2567 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2568 | lpfc_issue_reg_vpi(phba, vport); |
| 2569 | return; |
| 2570 | } |
| 2571 | /* |
| 2572 | * For SLI2, we need to set port_state to READY |
| 2573 | * and continue discovery. |
| 2574 | */ |
| 2575 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2576 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 2577 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2578 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 2579 | vport->num_disc_nodes = 0; |
| 2580 | /* go thru NPR list, issue ELS PLOGIs */ |
| 2581 | if (vport->fc_npr_cnt) |
| 2582 | lpfc_els_disc_plogi(vport); |
| 2583 | if (!vport->num_disc_nodes) { |
| 2584 | spin_lock_irq(shost->host_lock); |
| 2585 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2586 | spin_unlock_irq(shost->host_lock); |
| 2587 | lpfc_can_disctmo(vport); |
| 2588 | lpfc_end_rscn(vport); |
| 2589 | } |
| 2590 | } |
| 2591 | vport->port_state = LPFC_VPORT_READY; |
| 2592 | } else |
| 2593 | lpfc_rscn_disc(vport); |
| 2594 | } |
| 2595 | |
| 2596 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2597 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2598 | * @vport: pointer to a host virtual N_Port data structure. |
| 2599 | * |
| 2600 | * This routine determines whether there are more ndlps on a @vport |
| 2601 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 2602 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 2603 | * remaining nodes which need to have ADISC sent. |
| 2604 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2605 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2606 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2607 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2608 | if (vport->num_disc_nodes) |
| 2609 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2610 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2611 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2612 | "0210 Continue discovery with %d ADISCs to go " |
| 2613 | "Data: x%x x%x x%x\n", |
| 2614 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 2615 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2616 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2617 | if (vport->fc_flag & FC_NLP_MORE) { |
| 2618 | lpfc_set_disctmo(vport); |
| 2619 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 2620 | lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2622 | if (!vport->num_disc_nodes) |
| 2623 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2624 | return; |
| 2625 | } |
| 2626 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2627 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2628 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2629 | * @phba: pointer to lpfc hba data structure. |
| 2630 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2631 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2632 | * |
| 2633 | * This routine is the completion function for issuing the Address Discover |
| 2634 | * (ADISC) command. It first checks to see whether link went down during |
| 2635 | * the discovery process. If so, the node will be marked as node port |
| 2636 | * recovery for issuing discover IOCB by the link attention handler and |
| 2637 | * exit. Otherwise, the response status is checked. If error was reported |
| 2638 | * in the response status, the ADISC command shall be retried by invoking |
| 2639 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 2640 | * the response status, the state machine is invoked to set transition |
| 2641 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 2642 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2643 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2644 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2645 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2646 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2647 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2648 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2650 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2651 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2652 | |
| 2653 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2654 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2655 | |
| 2656 | irsp = &(rspiocb->iocb); |
| 2657 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2659 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2660 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 2661 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2662 | ndlp->nlp_DID); |
| 2663 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2664 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2665 | * is being used during discovery. |
| 2666 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2667 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2668 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2669 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2670 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2671 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2672 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2673 | "0104 ADISC completes to NPort x%x " |
| 2674 | "Data: x%x x%x x%x x%x x%x\n", |
| 2675 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2676 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2678 | if (lpfc_els_chk_latt(vport)) { |
| 2679 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2680 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2681 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | goto out; |
| 2683 | } |
| 2684 | |
| 2685 | if (irsp->ulpStatus) { |
| 2686 | /* Check for retry */ |
| 2687 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2688 | /* ELS command is being retried */ |
| 2689 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2690 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2691 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2692 | spin_unlock_irq(shost->host_lock); |
| 2693 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2694 | } |
| 2695 | goto out; |
| 2696 | } |
| 2697 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2698 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2699 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2700 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2701 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2702 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2703 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2704 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2705 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2706 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2707 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2708 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2709 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2710 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2711 | /* Check to see if there are more ADISCs to be sent */ |
| 2712 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2713 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2714 | out: |
| 2715 | lpfc_els_free_iocb(phba, cmdiocb); |
| 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 | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2743 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2744 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2745 | ADISC *ap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2746 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2747 | uint8_t *pcmd; |
| 2748 | uint16_t cmdsize; |
| 2749 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2750 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2751 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2752 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2753 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2754 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2755 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2756 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2757 | |
| 2758 | /* For ADISC request, remainder of payload is service parameters */ |
| 2759 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2760 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2761 | |
| 2762 | /* Fill in ADISC payload */ |
| 2763 | ap = (ADISC *) pcmd; |
| 2764 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2765 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2766 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2767 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2768 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2769 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2770 | "Issue ADISC: did:x%x", |
| 2771 | ndlp->nlp_DID, 0, 0); |
| 2772 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2773 | phba->fc_stat.elsXmitADISC++; |
| 2774 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2775 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2777 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2778 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2779 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2780 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2781 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2782 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2783 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2784 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2785 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2786 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2787 | } |
| 2788 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2789 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2790 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2791 | * @phba: pointer to lpfc hba data structure. |
| 2792 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2793 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2794 | * |
| 2795 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2796 | * command. If no error status was reported from the LOGO response, the |
| 2797 | * state machine of the associated ndlp shall be invoked for transition with |
| 2798 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2799 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2800 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2801 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2802 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2803 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2804 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2805 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2806 | struct lpfc_vport *vport = ndlp->vport; |
| 2807 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2808 | IOCB_t *irsp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2809 | struct lpfcMboxq *mbox; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2810 | unsigned long flags; |
| 2811 | uint32_t skip_recovery = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2812 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2813 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2814 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2815 | |
| 2816 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2817 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2818 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2819 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2820 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2821 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2822 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2823 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2824 | ndlp->nlp_DID); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2825 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2826 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2827 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2828 | "0105 LOGO completes to NPort x%x " |
| 2829 | "Data: x%x x%x x%x x%x\n", |
| 2830 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2831 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2832 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2833 | if (lpfc_els_chk_latt(vport)) { |
| 2834 | skip_recovery = 1; |
| 2835 | goto out; |
| 2836 | } |
| 2837 | |
| 2838 | /* Check to see if link went down during discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2839 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2840 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2841 | * which should abort all outstanding IOs. |
| 2842 | */ |
| 2843 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2844 | NLP_EVT_DEVICE_RM); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2845 | skip_recovery = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2846 | goto out; |
| 2847 | } |
| 2848 | |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 2849 | /* The LOGO will not be retried on failure. A LOGO was |
| 2850 | * issued to the remote rport and a ACC or RJT or no Answer are |
| 2851 | * all acceptable. Note the failure and move forward with |
| 2852 | * discovery. The PLOGI will retry. |
| 2853 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2854 | if (irsp->ulpStatus) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2855 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2856 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 2857 | "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] | 2858 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2859 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2860 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2861 | if (lpfc_error_lost_link(irsp)) { |
| 2862 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2863 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2864 | } |
| 2865 | } |
| 2866 | |
| 2867 | /* Call state machine. This will unregister the rpi if needed. */ |
| 2868 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); |
| 2869 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2870 | out: |
| 2871 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2872 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ |
| 2873 | if ((vport->fc_flag & FC_PT2PT) && |
| 2874 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { |
| 2875 | phba->pport->fc_myDID = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2876 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 2877 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 2878 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2879 | if (phba->nvmet_support) |
| 2880 | lpfc_nvmet_update_targetport(phba); |
| 2881 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2882 | lpfc_nvme_update_localport(phba->pport); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2883 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2884 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2885 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2886 | if (mbox) { |
| 2887 | lpfc_config_link(phba, mbox); |
| 2888 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2889 | mbox->vport = vport; |
| 2890 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 2891 | MBX_NOT_FINISHED) { |
| 2892 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2893 | skip_recovery = 1; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2894 | } |
| 2895 | } |
| 2896 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2897 | |
| 2898 | /* |
| 2899 | * If the node is a target, the handling attempts to recover the port. |
| 2900 | * For any other port type, the rpi is unregistered as an implicit |
| 2901 | * LOGO. |
| 2902 | */ |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 2903 | if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) && |
| 2904 | skip_recovery == 0) { |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2905 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 2906 | spin_lock_irqsave(shost->host_lock, flags); |
| 2907 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 2908 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2909 | |
| 2910 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2911 | "3187 LOGO completes to NPort x%x: Start " |
| 2912 | "Recovery Data: x%x x%x x%x x%x\n", |
| 2913 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2914 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 2915 | vport->num_disc_nodes); |
| 2916 | lpfc_disc_start(vport); |
| 2917 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2918 | return; |
| 2919 | } |
| 2920 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2921 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2922 | * 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] | 2923 | * @vport: pointer to a virtual N_Port data structure. |
| 2924 | * @ndlp: pointer to a node-list data structure. |
| 2925 | * @retry: number of retries to the command IOCB. |
| 2926 | * |
| 2927 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2928 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2929 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2930 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2931 | * |
| 2932 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2933 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2934 | * will be stored into the context1 field of the IOCB for the completion |
| 2935 | * callback function to the LOGO ELS command. |
| 2936 | * |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 2937 | * Callers of this routine are expected to unregister the RPI first |
| 2938 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2939 | * Return code |
| 2940 | * 0 - successfully issued logo |
| 2941 | * 1 - failed to issue logo |
| 2942 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2943 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2944 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2945 | uint8_t retry) |
| 2946 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2947 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2948 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2949 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2950 | uint8_t *pcmd; |
| 2951 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2952 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2953 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2954 | spin_lock_irq(shost->host_lock); |
| 2955 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2956 | spin_unlock_irq(shost->host_lock); |
| 2957 | return 0; |
| 2958 | } |
| 2959 | spin_unlock_irq(shost->host_lock); |
| 2960 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2961 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2962 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2963 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2964 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2965 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2966 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2967 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2968 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2969 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2970 | |
| 2971 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2972 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2973 | pcmd += sizeof(uint32_t); |
| 2974 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2975 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2976 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2977 | "Issue LOGO: did:x%x", |
| 2978 | ndlp->nlp_DID, 0, 0); |
| 2979 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2980 | phba->fc_stat.elsXmitLOGO++; |
| 2981 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2982 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2984 | ndlp->nlp_flag &= ~NLP_ISSUE_LOGO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2985 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2986 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2987 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2988 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2989 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2990 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2991 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2992 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2993 | } |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 2994 | |
| 2995 | spin_lock_irq(shost->host_lock); |
| 2996 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 2997 | spin_unlock_irq(shost->host_lock); |
| 2998 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2999 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3000 | } |
| 3001 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3002 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3003 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3004 | * @phba: pointer to lpfc hba data structure. |
| 3005 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3006 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3007 | * |
| 3008 | * This routine is a generic completion callback function for ELS commands. |
| 3009 | * Specifically, it is the callback function which does not need to perform |
| 3010 | * any command specific operations. It is currently used by the ELS command |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3011 | * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel |
| 3012 | * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). |
| 3013 | * Other than certain debug loggings, this callback function simply invokes the |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3014 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 3015 | * discovery process. |
| 3016 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3017 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3018 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3019 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3020 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3021 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3022 | IOCB_t *irsp; |
| 3023 | |
| 3024 | irsp = &rspiocb->iocb; |
| 3025 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3026 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3027 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 3028 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 3029 | irsp->un.elsreq64.remoteID); |
| 3030 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3031 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3032 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3033 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 3034 | irsp->ulpIoTag, irsp->ulpStatus, |
| 3035 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3036 | |
| 3037 | /* Check to see if link went down during discovery */ |
| 3038 | lpfc_els_chk_latt(vport); |
| 3039 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3040 | } |
| 3041 | |
| 3042 | /** |
| 3043 | * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd |
| 3044 | * @phba: pointer to lpfc hba data structure. |
| 3045 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3046 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3047 | * |
| 3048 | * This routine is a generic completion callback function for Discovery ELS cmd. |
| 3049 | * Currently used by the ELS command issuing routines for the ELS State Change |
| 3050 | * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf(). |
| 3051 | * These commands will be retried once only for ELS timeout errors. |
| 3052 | **/ |
| 3053 | static void |
| 3054 | lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3055 | struct lpfc_iocbq *rspiocb) |
| 3056 | { |
| 3057 | struct lpfc_vport *vport = cmdiocb->vport; |
| 3058 | IOCB_t *irsp; |
| 3059 | struct lpfc_els_rdf_rsp *prdf; |
| 3060 | struct lpfc_dmabuf *pcmd, *prsp; |
| 3061 | u32 *pdata; |
| 3062 | u32 cmd; |
| 3063 | |
| 3064 | irsp = &rspiocb->iocb; |
| 3065 | |
| 3066 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3067 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 3068 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 3069 | irsp->un.elsreq64.remoteID); |
| 3070 | /* ELS cmd tag <ulpIoTag> completes */ |
| 3071 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3072 | "0217 ELS cmd tag x%x completes Data: x%x x%x x%x " |
| 3073 | "x%x\n", |
| 3074 | irsp->ulpIoTag, irsp->ulpStatus, |
| 3075 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 3076 | cmdiocb->retry); |
| 3077 | |
| 3078 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 3079 | if (!pcmd) |
| 3080 | goto out; |
| 3081 | |
| 3082 | pdata = (u32 *)pcmd->virt; |
| 3083 | if (!pdata) |
| 3084 | goto out; |
| 3085 | cmd = *pdata; |
| 3086 | |
| 3087 | /* Only 1 retry for ELS Timeout only */ |
| 3088 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 3089 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3090 | IOERR_SEQUENCE_TIMEOUT)) { |
| 3091 | cmdiocb->retry++; |
| 3092 | if (cmdiocb->retry <= 1) { |
| 3093 | switch (cmd) { |
| 3094 | case ELS_CMD_SCR: |
| 3095 | lpfc_issue_els_scr(vport, cmdiocb->retry); |
| 3096 | break; |
| 3097 | case ELS_CMD_RDF: |
| 3098 | cmdiocb->context1 = NULL; /* save ndlp refcnt */ |
| 3099 | lpfc_issue_els_rdf(vport, cmdiocb->retry); |
| 3100 | break; |
| 3101 | } |
| 3102 | goto out; |
| 3103 | } |
| 3104 | phba->fc_stat.elsRetryExceeded++; |
| 3105 | } |
| 3106 | if (irsp->ulpStatus) { |
| 3107 | /* ELS discovery cmd completes with error */ |
| 3108 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 3109 | "4203 ELS cmd x%x error: x%x x%X\n", cmd, |
| 3110 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
| 3111 | goto out; |
| 3112 | } |
| 3113 | |
| 3114 | /* The RDF response doesn't have any impact on the running driver |
| 3115 | * but the notification descriptors are dumped here for support. |
| 3116 | */ |
| 3117 | if (cmd == ELS_CMD_RDF) { |
| 3118 | int i; |
| 3119 | |
| 3120 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 3121 | if (!prsp) |
| 3122 | goto out; |
| 3123 | |
| 3124 | prdf = (struct lpfc_els_rdf_rsp *)prsp->virt; |
| 3125 | if (!prdf) |
| 3126 | goto out; |
| 3127 | |
| 3128 | for (i = 0; i < ELS_RDF_REG_TAG_CNT && |
| 3129 | i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++) |
| 3130 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3131 | "4677 Fabric RDF Notication Grant Data: " |
| 3132 | "0x%08x\n", |
| 3133 | be32_to_cpu( |
| 3134 | prdf->reg_d1.desc_tags[i])); |
| 3135 | } |
| 3136 | |
| 3137 | out: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3138 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3139 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3140 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3141 | return; |
| 3142 | } |
| 3143 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3144 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3145 | * 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] | 3146 | * @vport: pointer to a host virtual N_Port data structure. |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3147 | * @retry: retry counter for the command IOCB. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3148 | * |
| 3149 | * This routine issues a State Change Request (SCR) to a fabric node |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3150 | * on a @vport. The remote node is Fabric Controller (0xfffffd). It |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3151 | * first search the @vport node list to find the matching ndlp. If no such |
| 3152 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 3153 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 3154 | * routine is invoked to send the SCR IOCB. |
| 3155 | * |
| 3156 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3157 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3158 | * will be stored into the context1 field of the IOCB for the completion |
| 3159 | * callback function to the SCR ELS command. |
| 3160 | * |
| 3161 | * Return code |
| 3162 | * 0 - Successfully issued scr command |
| 3163 | * 1 - Failed to issue scr command |
| 3164 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3165 | int |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3166 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3167 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3168 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3169 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3170 | uint8_t *pcmd; |
| 3171 | uint16_t cmdsize; |
| 3172 | struct lpfc_nodelist *ndlp; |
| 3173 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3174 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3175 | |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3176 | ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3177 | if (!ndlp) { |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3178 | ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3179 | if (!ndlp) |
| 3180 | return 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3181 | lpfc_enqueue_node(vport, ndlp); |
| 3182 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 3183 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 3184 | if (!ndlp) |
| 3185 | return 1; |
| 3186 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3187 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3188 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 3189 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 3190 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3191 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3192 | /* This will trigger the release of the node just |
| 3193 | * allocated |
| 3194 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3195 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3196 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3197 | } |
| 3198 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3199 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3200 | |
| 3201 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3202 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3203 | |
| 3204 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3205 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3206 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 3207 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3208 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3209 | "Issue SCR: did:x%x", |
| 3210 | ndlp->nlp_DID, 0, 0); |
| 3211 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3212 | phba->fc_stat.elsXmitSCR++; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3213 | elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3214 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 3215 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3216 | /* The additional lpfc_nlp_put will cause the following |
| 3217 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 3218 | * the node. |
| 3219 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3220 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3221 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3222 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3223 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3224 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 3225 | * trigger the release of node. |
| 3226 | */ |
James Smart | b7e50c5 | 2017-11-20 16:00:37 -0800 | [diff] [blame] | 3227 | if (!(vport->fc_flag & FC_PT2PT)) |
| 3228 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3229 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3230 | } |
| 3231 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3232 | /** |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3233 | * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric) |
| 3234 | * or the other nport (pt2pt). |
| 3235 | * @vport: pointer to a host virtual N_Port data structure. |
| 3236 | * @retry: number of retries to the command IOCB. |
| 3237 | * |
| 3238 | * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD) |
| 3239 | * when connected to a fabric, or to the remote port when connected |
| 3240 | * in point-to-point mode. When sent to the Fabric Controller, it will |
| 3241 | * replay the RSCN to registered recipients. |
| 3242 | * |
| 3243 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3244 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3245 | * will be stored into the context1 field of the IOCB for the completion |
| 3246 | * callback function to the RSCN ELS command. |
| 3247 | * |
| 3248 | * Return code |
| 3249 | * 0 - Successfully issued RSCN command |
| 3250 | * 1 - Failed to issue RSCN command |
| 3251 | **/ |
| 3252 | int |
| 3253 | lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry) |
| 3254 | { |
| 3255 | struct lpfc_hba *phba = vport->phba; |
| 3256 | struct lpfc_iocbq *elsiocb; |
| 3257 | struct lpfc_nodelist *ndlp; |
| 3258 | struct { |
| 3259 | struct fc_els_rscn rscn; |
| 3260 | struct fc_els_rscn_page portid; |
| 3261 | } *event; |
| 3262 | uint32_t nportid; |
| 3263 | uint16_t cmdsize = sizeof(*event); |
| 3264 | |
| 3265 | /* Not supported for private loop */ |
| 3266 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
| 3267 | !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 3268 | return 1; |
| 3269 | |
| 3270 | if (vport->fc_flag & FC_PT2PT) { |
| 3271 | /* find any mapped nport - that would be the other nport */ |
| 3272 | ndlp = lpfc_findnode_mapped(vport); |
| 3273 | if (!ndlp) |
| 3274 | return 1; |
| 3275 | } else { |
| 3276 | nportid = FC_FID_FCTRL; |
| 3277 | /* find the fabric controller node */ |
| 3278 | ndlp = lpfc_findnode_did(vport, nportid); |
| 3279 | if (!ndlp) { |
| 3280 | /* if one didn't exist, make one */ |
| 3281 | ndlp = lpfc_nlp_init(vport, nportid); |
| 3282 | if (!ndlp) |
| 3283 | return 1; |
| 3284 | lpfc_enqueue_node(vport, ndlp); |
| 3285 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 3286 | ndlp = lpfc_enable_node(vport, ndlp, |
| 3287 | NLP_STE_UNUSED_NODE); |
| 3288 | if (!ndlp) |
| 3289 | return 1; |
| 3290 | } |
| 3291 | } |
| 3292 | |
| 3293 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 3294 | ndlp->nlp_DID, ELS_CMD_RSCN_XMT); |
| 3295 | |
| 3296 | if (!elsiocb) { |
| 3297 | /* This will trigger the release of the node just |
| 3298 | * allocated |
| 3299 | */ |
| 3300 | lpfc_nlp_put(ndlp); |
| 3301 | return 1; |
| 3302 | } |
| 3303 | |
| 3304 | event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 3305 | |
| 3306 | event->rscn.rscn_cmd = ELS_RSCN; |
| 3307 | event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page); |
| 3308 | event->rscn.rscn_plen = cpu_to_be16(cmdsize); |
| 3309 | |
| 3310 | nportid = vport->fc_myDID; |
| 3311 | /* appears that page flags must be 0 for fabric to broadcast RSCN */ |
| 3312 | event->portid.rscn_page_flags = 0; |
| 3313 | event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16; |
| 3314 | event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8; |
| 3315 | event->portid.rscn_fid[2] = nportid & 0x000000FF; |
| 3316 | |
| 3317 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3318 | "Issue RSCN: did:x%x", |
| 3319 | ndlp->nlp_DID, 0, 0); |
| 3320 | |
| 3321 | phba->fc_stat.elsXmitRSCN++; |
| 3322 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| 3323 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 3324 | IOCB_ERROR) { |
| 3325 | /* The additional lpfc_nlp_put will cause the following |
| 3326 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 3327 | * the node. |
| 3328 | */ |
| 3329 | lpfc_nlp_put(ndlp); |
| 3330 | lpfc_els_free_iocb(phba, elsiocb); |
| 3331 | return 1; |
| 3332 | } |
| 3333 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 3334 | * trigger the release of node. |
| 3335 | */ |
| 3336 | if (!(vport->fc_flag & FC_PT2PT)) |
| 3337 | lpfc_nlp_put(ndlp); |
| 3338 | |
| 3339 | return 0; |
| 3340 | } |
| 3341 | |
| 3342 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3343 | * 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] | 3344 | * @vport: pointer to a host virtual N_Port data structure. |
| 3345 | * @nportid: N_Port identifier to the remote node. |
| 3346 | * @retry: number of retries to the command IOCB. |
| 3347 | * |
| 3348 | * This routine issues a Fibre Channel Address Resolution Response |
| 3349 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 3350 | * is passed into the function. It first search the @vport node list to find |
| 3351 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 3352 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 3353 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 3354 | * |
| 3355 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3356 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3357 | * will be stored into the context1 field of the IOCB for the completion |
| 3358 | * callback function to the PARPR ELS command. |
| 3359 | * |
| 3360 | * Return code |
| 3361 | * 0 - Successfully issued farpr command |
| 3362 | * 1 - Failed to issue farpr command |
| 3363 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3364 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3365 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3366 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3367 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3368 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3369 | FARP *fp; |
| 3370 | uint8_t *pcmd; |
| 3371 | uint32_t *lp; |
| 3372 | uint16_t cmdsize; |
| 3373 | struct lpfc_nodelist *ondlp; |
| 3374 | struct lpfc_nodelist *ndlp; |
| 3375 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3376 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3377 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3378 | ndlp = lpfc_findnode_did(vport, nportid); |
| 3379 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3380 | ndlp = lpfc_nlp_init(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3381 | if (!ndlp) |
| 3382 | return 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3383 | lpfc_enqueue_node(vport, ndlp); |
| 3384 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 3385 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 3386 | if (!ndlp) |
| 3387 | return 1; |
| 3388 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3389 | |
| 3390 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 3391 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3392 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3393 | /* This will trigger the release of the node just |
| 3394 | * allocated |
| 3395 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3396 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3397 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3398 | } |
| 3399 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3400 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3401 | |
| 3402 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3403 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3404 | |
| 3405 | /* Fill in FARPR payload */ |
| 3406 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3407 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | lp = (uint32_t *) pcmd; |
| 3409 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3410 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3411 | fp->Rflags = 0; |
| 3412 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 3413 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3414 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3415 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3416 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3417 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3418 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3419 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3420 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3421 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3422 | } |
| 3423 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3424 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3425 | "Issue FARPR: did:x%x", |
| 3426 | ndlp->nlp_DID, 0, 0); |
| 3427 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3428 | phba->fc_stat.elsXmitFARPR++; |
| 3429 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3430 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 3431 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3432 | /* The additional lpfc_nlp_put will cause the following |
| 3433 | * lpfc_els_free_iocb routine to trigger the release of |
| 3434 | * the node. |
| 3435 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3436 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3437 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3438 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3439 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3440 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 3441 | * trigger the release of the node. |
| 3442 | */ |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3443 | /* Don't release reference count as RDF is likely outstanding */ |
| 3444 | return 0; |
| 3445 | } |
| 3446 | |
| 3447 | /** |
| 3448 | * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric. |
| 3449 | * @vport: pointer to a host virtual N_Port data structure. |
| 3450 | * @retry: retry counter for the command IOCB. |
| 3451 | * |
| 3452 | * This routine issues an ELS RDF to the Fabric Controller to register |
| 3453 | * for diagnostic functions. |
| 3454 | * |
| 3455 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3456 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3457 | * will be stored into the context1 field of the IOCB for the completion |
| 3458 | * callback function to the RDF ELS command. |
| 3459 | * |
| 3460 | * Return code |
| 3461 | * 0 - Successfully issued rdf command |
| 3462 | * 1 - Failed to issue rdf command |
| 3463 | **/ |
| 3464 | int |
| 3465 | lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry) |
| 3466 | { |
| 3467 | struct lpfc_hba *phba = vport->phba; |
| 3468 | struct lpfc_iocbq *elsiocb; |
| 3469 | struct lpfc_els_rdf_req *prdf; |
| 3470 | struct lpfc_nodelist *ndlp; |
| 3471 | uint16_t cmdsize; |
| 3472 | |
| 3473 | cmdsize = sizeof(*prdf); |
| 3474 | |
| 3475 | ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID); |
| 3476 | if (!ndlp) { |
| 3477 | ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID); |
| 3478 | if (!ndlp) |
| 3479 | return -ENODEV; |
| 3480 | lpfc_enqueue_node(vport, ndlp); |
| 3481 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 3482 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 3483 | if (!ndlp) |
| 3484 | return -ENODEV; |
| 3485 | } |
| 3486 | |
| 3487 | /* RDF ELS is not required on an NPIV VN_Port. */ |
| 3488 | if (vport->port_type == LPFC_NPIV_PORT) { |
| 3489 | lpfc_nlp_put(ndlp); |
| 3490 | return -EACCES; |
| 3491 | } |
| 3492 | |
| 3493 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 3494 | ndlp->nlp_DID, ELS_CMD_RDF); |
| 3495 | if (!elsiocb) { |
| 3496 | /* This will trigger the release of the node just |
| 3497 | * allocated |
| 3498 | */ |
| 3499 | lpfc_nlp_put(ndlp); |
| 3500 | return -ENOMEM; |
| 3501 | } |
| 3502 | |
| 3503 | /* Configure the payload for the supported FPIN events. */ |
| 3504 | prdf = (struct lpfc_els_rdf_req *) |
| 3505 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 3506 | memset(prdf, 0, cmdsize); |
| 3507 | prdf->rdf.fpin_cmd = ELS_RDF; |
| 3508 | prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) - |
| 3509 | sizeof(struct fc_els_rdf)); |
| 3510 | prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER); |
| 3511 | prdf->reg_d1.reg_desc.desc_len = cpu_to_be32( |
| 3512 | FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1)); |
| 3513 | prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT); |
| 3514 | prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY); |
| 3515 | |
| 3516 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3517 | "Issue RDF: did:x%x", |
| 3518 | ndlp->nlp_DID, 0, 0); |
| 3519 | |
| 3520 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3521 | "6444 Xmit RDF to remote NPORT x%x\n", |
| 3522 | ndlp->nlp_DID); |
| 3523 | |
| 3524 | elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd; |
| 3525 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 3526 | IOCB_ERROR) { |
| 3527 | /* The additional lpfc_nlp_put will cause the following |
| 3528 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 3529 | * the node. |
| 3530 | */ |
| 3531 | lpfc_nlp_put(ndlp); |
| 3532 | lpfc_els_free_iocb(phba, elsiocb); |
| 3533 | return -EIO; |
| 3534 | } |
| 3535 | |
| 3536 | /* An RDF was issued - this put ensures the ndlp is cleaned up |
| 3537 | * when the RDF completes. |
| 3538 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3539 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3540 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3541 | } |
| 3542 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3543 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3544 | * 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] | 3545 | * @vport: pointer to a host virtual N_Port data structure. |
| 3546 | * @nlp: pointer to a node-list data structure. |
| 3547 | * |
| 3548 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 3549 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 3550 | * removes the ELS retry event if it presents. In addition, if the |
| 3551 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 3552 | * commands are sent for the @vport's nodes that require issuing discovery |
| 3553 | * ADISC. |
| 3554 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3555 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3556 | 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] | 3557 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3558 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3559 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3560 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3561 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 3562 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3563 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3564 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3565 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3566 | del_timer_sync(&nlp->nlp_delayfunc); |
| 3567 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3568 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3569 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3570 | /* Decrement nlp reference count held for the delayed retry */ |
| 3571 | evtp = &nlp->els_retry_evt; |
| 3572 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 3573 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3574 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3575 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3576 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3577 | spin_unlock_irq(shost->host_lock); |
| 3578 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3579 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3580 | /* Check if there are more ADISCs to be sent */ |
| 3581 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3582 | } else { |
| 3583 | /* Check if there are more PLOGIs to be sent */ |
| 3584 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 3585 | if (vport->num_disc_nodes == 0) { |
| 3586 | spin_lock_irq(shost->host_lock); |
| 3587 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3588 | spin_unlock_irq(shost->host_lock); |
| 3589 | lpfc_can_disctmo(vport); |
| 3590 | lpfc_end_rscn(vport); |
| 3591 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3592 | } |
| 3593 | } |
| 3594 | } |
| 3595 | return; |
| 3596 | } |
| 3597 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3598 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3599 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3600 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 3601 | * |
| 3602 | * This routine is invoked by the ndlp delayed-function timer to check |
| 3603 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 3604 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 3605 | * adds the delayed events to the HBA work list and invokes the |
| 3606 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 3607 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 3608 | * the work list to hold reference count of ndlp so that it guarantees the |
| 3609 | * reference to ndlp will still be available when the worker thread gets |
| 3610 | * to the event associated with the ndlp. |
| 3611 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3612 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3613 | lpfc_els_retry_delay(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3614 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3615 | struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3616 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3617 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3618 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3619 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3620 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3621 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3622 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3623 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3624 | return; |
| 3625 | } |
| 3626 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3627 | /* We need to hold the node by incrementing the reference |
| 3628 | * count until the queued work is done |
| 3629 | */ |
| 3630 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3631 | if (evtp->evt_arg1) { |
| 3632 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 3633 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3634 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3635 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3636 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3637 | return; |
| 3638 | } |
| 3639 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3640 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3641 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3642 | * @ndlp: pointer to a node-list data structure. |
| 3643 | * |
| 3644 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 3645 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 3646 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 3647 | * function according to the delayed ELS command to retry the command. |
| 3648 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3649 | void |
| 3650 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 3651 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3652 | struct lpfc_vport *vport = ndlp->vport; |
| 3653 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3654 | uint32_t cmd, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3655 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3656 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3657 | cmd = ndlp->nlp_last_elscmd; |
| 3658 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3659 | |
| 3660 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3661 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3662 | return; |
| 3663 | } |
| 3664 | |
| 3665 | 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); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 3667 | /* |
| 3668 | * If a discovery event readded nlp_delayfunc after timer |
| 3669 | * firing and before processing the timer, cancel the |
| 3670 | * nlp_delayfunc. |
| 3671 | */ |
| 3672 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3673 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3674 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3675 | |
| 3676 | switch (cmd) { |
| 3677 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3678 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3679 | break; |
| 3680 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3681 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3682 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3683 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3684 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3685 | break; |
| 3686 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3687 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3688 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3689 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3690 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3691 | break; |
| 3692 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3693 | case ELS_CMD_NVMEPRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3694 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3695 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3696 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3697 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3698 | break; |
| 3699 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3700 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3701 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3702 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3703 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3704 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3705 | case ELS_CMD_FDISC: |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3706 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
| 3707 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3708 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3709 | } |
| 3710 | return; |
| 3711 | } |
| 3712 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3713 | /** |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 3714 | * lpfc_link_reset - Issue link reset |
| 3715 | * @vport: pointer to a virtual N_Port data structure. |
| 3716 | * |
| 3717 | * This routine performs link reset by sending INIT_LINK mailbox command. |
| 3718 | * For SLI-3 adapter, link attention interrupt is enabled before issuing |
| 3719 | * INIT_LINK mailbox command. |
| 3720 | * |
| 3721 | * Return code |
| 3722 | * 0 - Link reset initiated successfully |
| 3723 | * 1 - Failed to initiate link reset |
| 3724 | **/ |
| 3725 | int |
| 3726 | lpfc_link_reset(struct lpfc_vport *vport) |
| 3727 | { |
| 3728 | struct lpfc_hba *phba = vport->phba; |
| 3729 | LPFC_MBOXQ_t *mbox; |
| 3730 | uint32_t control; |
| 3731 | int rc; |
| 3732 | |
| 3733 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3734 | "2851 Attempt link reset\n"); |
| 3735 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3736 | if (!mbox) { |
| 3737 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 3738 | "2852 Failed to allocate mbox memory"); |
| 3739 | return 1; |
| 3740 | } |
| 3741 | |
| 3742 | /* Enable Link attention interrupts */ |
| 3743 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3744 | spin_lock_irq(&phba->hbalock); |
| 3745 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
| 3746 | control = readl(phba->HCregaddr); |
| 3747 | control |= HC_LAINT_ENA; |
| 3748 | writel(control, phba->HCregaddr); |
| 3749 | readl(phba->HCregaddr); /* flush */ |
| 3750 | spin_unlock_irq(&phba->hbalock); |
| 3751 | } |
| 3752 | |
| 3753 | lpfc_init_link(phba, mbox, phba->cfg_topology, |
| 3754 | phba->cfg_link_speed); |
| 3755 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3756 | mbox->vport = vport; |
| 3757 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 3758 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 3759 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 3760 | "2853 Failed to issue INIT_LINK " |
| 3761 | "mbox command, rc:x%x\n", rc); |
| 3762 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3763 | return 1; |
| 3764 | } |
| 3765 | |
| 3766 | return 0; |
| 3767 | } |
| 3768 | |
| 3769 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3770 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3771 | * @phba: pointer to lpfc hba data structure. |
| 3772 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3773 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3774 | * |
| 3775 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 3776 | * failed. The following ELS IOCBs use this function for retrying the command |
| 3777 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 3778 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 3779 | * returned error status, it makes the decision whether a retry shall be |
| 3780 | * issued for the command, and whether a retry shall be made immediately or |
| 3781 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 3782 | * is called to retry the command. In the later case, the ELS command shall |
| 3783 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 3784 | * ndlp for the delayed command issusing. |
| 3785 | * |
| 3786 | * Return code |
| 3787 | * 0 - No retry of els command is made |
| 3788 | * 1 - Immediate or delayed retry of els command is made |
| 3789 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3790 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3791 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3792 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3793 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3794 | struct lpfc_vport *vport = cmdiocb->vport; |
| 3795 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3796 | IOCB_t *irsp = &rspiocb->iocb; |
| 3797 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3798 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3799 | uint32_t *elscmd; |
| 3800 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3801 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3802 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3803 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3804 | uint32_t did; |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 3805 | int link_reset = 0, rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3806 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3807 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3808 | /* Note: context2 may be 0 for internal driver abort |
| 3809 | * of delays ELS command. |
| 3810 | */ |
| 3811 | |
| 3812 | if (pcmd && pcmd->virt) { |
| 3813 | elscmd = (uint32_t *) (pcmd->virt); |
| 3814 | cmd = *elscmd++; |
| 3815 | } |
| 3816 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3817 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3818 | did = ndlp->nlp_DID; |
| 3819 | else { |
| 3820 | /* We should only hit this case for retrying PLOGI */ |
| 3821 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3822 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3823 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 3824 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3825 | return 1; |
| 3826 | } |
| 3827 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3828 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3829 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 3830 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 3831 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3832 | switch (irsp->ulpStatus) { |
| 3833 | case IOSTAT_FCP_RSP_ERROR: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | break; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3835 | case IOSTAT_REMOTE_STOP: |
| 3836 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3837 | /* This IO was aborted by the target, we don't |
| 3838 | * know the rxid and because we did not send the |
| 3839 | * ABTS we cannot generate and RRQ. |
| 3840 | */ |
| 3841 | lpfc_set_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 3842 | cmdiocb->sli4_lxritag, 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3843 | } |
| 3844 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3845 | case IOSTAT_LOCAL_REJECT: |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3846 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3847 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3848 | if (cmd == ELS_CMD_FLOGI) { |
| 3849 | if (PCI_DEVICE_ID_HORNET == |
| 3850 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3851 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3852 | phba->pport->fc_myDID = 0; |
| 3853 | phba->alpa_map[0] = 0; |
| 3854 | phba->alpa_map[1] = 0; |
| 3855 | } |
| 3856 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3857 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3858 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3859 | retry = 1; |
| 3860 | break; |
| 3861 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3862 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3863 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3864 | "0124 Retry illegal cmd x%x " |
| 3865 | "retry:x%x delay:x%x\n", |
| 3866 | cmd, cmdiocb->retry, delay); |
| 3867 | retry = 1; |
| 3868 | /* All command's retry policy */ |
| 3869 | maxretry = 8; |
| 3870 | if (cmdiocb->retry > 2) |
| 3871 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3872 | break; |
| 3873 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3874 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3875 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3876 | retry = 1; |
| 3877 | if (cmdiocb->retry > 100) |
| 3878 | delay = 100; |
| 3879 | maxretry = 250; |
| 3880 | break; |
| 3881 | |
| 3882 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3883 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3884 | retry = 1; |
| 3885 | break; |
| 3886 | |
| 3887 | case IOERR_INVALID_RPI: |
James Smart | 5b5b36a | 2013-01-03 15:43:19 -0500 | [diff] [blame] | 3888 | if (cmd == ELS_CMD_PLOGI && |
| 3889 | did == NameServer_DID) { |
| 3890 | /* Continue forever if plogi to */ |
| 3891 | /* the nameserver fails */ |
| 3892 | maxretry = 0; |
| 3893 | delay = 100; |
| 3894 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3895 | retry = 1; |
| 3896 | break; |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 3897 | |
| 3898 | case IOERR_SEQUENCE_TIMEOUT: |
| 3899 | if (cmd == ELS_CMD_PLOGI && |
| 3900 | did == NameServer_DID && |
| 3901 | (cmdiocb->retry + 1) == maxretry) { |
| 3902 | /* Reset the Link */ |
| 3903 | link_reset = 1; |
| 3904 | break; |
| 3905 | } |
| 3906 | retry = 1; |
| 3907 | delay = 100; |
| 3908 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | } |
| 3910 | break; |
| 3911 | |
| 3912 | case IOSTAT_NPORT_RJT: |
| 3913 | case IOSTAT_FABRIC_RJT: |
| 3914 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 3915 | retry = 1; |
| 3916 | break; |
| 3917 | } |
| 3918 | break; |
| 3919 | |
| 3920 | case IOSTAT_NPORT_BSY: |
| 3921 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3922 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3923 | retry = 1; |
| 3924 | break; |
| 3925 | |
| 3926 | case IOSTAT_LS_RJT: |
| 3927 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 3928 | /* Added for Vendor specifc support |
| 3929 | * Just keep retrying for these Rsn / Exp codes |
| 3930 | */ |
| 3931 | switch (stat.un.b.lsRjtRsnCode) { |
| 3932 | case LSRJT_UNABLE_TPC: |
James Smart | dea37e8 | 2017-06-01 21:07:07 -0700 | [diff] [blame] | 3933 | /* The driver has a VALID PLOGI but the rport has |
| 3934 | * rejected the PRLI - can't do it now. Delay |
| 3935 | * for 1 second and try again - don't care about |
| 3936 | * the explanation. |
| 3937 | */ |
| 3938 | if (cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) { |
| 3939 | delay = 1000; |
| 3940 | maxretry = lpfc_max_els_tries + 1; |
| 3941 | retry = 1; |
| 3942 | break; |
| 3943 | } |
| 3944 | |
| 3945 | /* Legacy bug fix code for targets with PLOGI delays. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3946 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3947 | LSEXP_CMD_IN_PROGRESS) { |
| 3948 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3949 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3950 | maxretry = 48; |
| 3951 | } |
| 3952 | retry = 1; |
| 3953 | break; |
| 3954 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3955 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3956 | LSEXP_CANT_GIVE_DATA) { |
| 3957 | if (cmd == ELS_CMD_PLOGI) { |
| 3958 | delay = 1000; |
| 3959 | maxretry = 48; |
| 3960 | } |
| 3961 | retry = 1; |
| 3962 | break; |
| 3963 | } |
James Smart | dea37e8 | 2017-06-01 21:07:07 -0700 | [diff] [blame] | 3964 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3965 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3966 | maxretry = lpfc_max_els_tries + 1; |
| 3967 | retry = 1; |
| 3968 | break; |
| 3969 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3970 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3971 | (cmd == ELS_CMD_FDISC) && |
| 3972 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3973 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3974 | "0125 FDISC Failed (x%x). " |
| 3975 | "Fabric out of resources\n", |
| 3976 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3977 | lpfc_vport_set_state(vport, |
| 3978 | FC_VPORT_NO_FABRIC_RSCS); |
| 3979 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3980 | break; |
| 3981 | |
| 3982 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3983 | if ((cmd == ELS_CMD_PLOGI) || |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3984 | (cmd == ELS_CMD_PRLI) || |
| 3985 | (cmd == ELS_CMD_NVMEPRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3986 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3987 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3988 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3989 | /* FDISC retry policy */ |
| 3990 | maxretry = 48; |
| 3991 | if (cmdiocb->retry >= 32) |
| 3992 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3993 | } |
| 3994 | retry = 1; |
| 3995 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3996 | |
| 3997 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3998 | /* There are some cases where switches return this |
| 3999 | * error when they are not ready and should be returning |
| 4000 | * Logical Busy. We should delay every time. |
| 4001 | */ |
| 4002 | if (cmd == ELS_CMD_FDISC && |
| 4003 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 4004 | maxretry = 3; |
| 4005 | delay = 1000; |
| 4006 | retry = 1; |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 4007 | } else if (cmd == ELS_CMD_FLOGI && |
| 4008 | stat.un.b.lsRjtRsnCodeExp == |
| 4009 | LSEXP_NOTHING_MORE) { |
| 4010 | vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf; |
| 4011 | retry = 1; |
| 4012 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4013 | "0820 FLOGI Failed (x%x). " |
| 4014 | "BBCredit Not Supported\n", |
| 4015 | stat.un.lsRjtError); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4016 | } |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 4017 | break; |
| 4018 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4019 | case LSRJT_PROTOCOL_ERR: |
| 4020 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 4021 | (cmd == ELS_CMD_FDISC) && |
| 4022 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 4023 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 4024 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4025 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4026 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4027 | "Fabric Detected Bad WWN\n", |
| 4028 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4029 | lpfc_vport_set_state(vport, |
| 4030 | FC_VPORT_FABRIC_REJ_WWN); |
| 4031 | } |
| 4032 | break; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4033 | case LSRJT_VENDOR_UNIQUE: |
| 4034 | if ((stat.un.b.vendorUnique == 0x45) && |
| 4035 | (cmd == ELS_CMD_FLOGI)) { |
| 4036 | goto out_retry; |
| 4037 | } |
| 4038 | break; |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 4039 | case LSRJT_CMD_UNSUPPORTED: |
| 4040 | /* lpfc nvmet returns this type of LS_RJT when it |
| 4041 | * receives an FCP PRLI because lpfc nvmet only |
| 4042 | * support NVME. ELS request is terminated for FCP4 |
| 4043 | * on this rport. |
| 4044 | */ |
| 4045 | if (stat.un.b.lsRjtRsnCodeExp == |
| 4046 | LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) { |
| 4047 | spin_lock_irq(shost->host_lock); |
| 4048 | ndlp->nlp_flag |= NLP_FCP_PRLI_RJT; |
| 4049 | spin_unlock_irq(shost->host_lock); |
| 4050 | retry = 0; |
| 4051 | goto out_retry; |
| 4052 | } |
| 4053 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4054 | } |
| 4055 | break; |
| 4056 | |
| 4057 | case IOSTAT_INTERMED_RSP: |
| 4058 | case IOSTAT_BA_RJT: |
| 4059 | break; |
| 4060 | |
| 4061 | default: |
| 4062 | break; |
| 4063 | } |
| 4064 | |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 4065 | if (link_reset) { |
| 4066 | rc = lpfc_link_reset(vport); |
| 4067 | if (rc) { |
| 4068 | /* Do not give up. Retry PLOGI one more time and attempt |
| 4069 | * link reset if PLOGI fails again. |
| 4070 | */ |
| 4071 | retry = 1; |
| 4072 | delay = 100; |
| 4073 | goto out_retry; |
| 4074 | } |
| 4075 | return 1; |
| 4076 | } |
| 4077 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4078 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4080 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4081 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4082 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 4083 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4084 | /* FLOGI retry policy */ |
| 4085 | retry = 1; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4086 | /* retry FLOGI forever */ |
James Smart | 6eae430 | 2015-04-07 15:07:23 -0400 | [diff] [blame] | 4087 | if (phba->link_flag != LS_LOOPBACK_MODE) |
| 4088 | maxretry = 0; |
| 4089 | else |
| 4090 | maxretry = 2; |
| 4091 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4092 | if (cmdiocb->retry >= 100) |
| 4093 | delay = 5000; |
| 4094 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4095 | delay = 1000; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4096 | } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) { |
| 4097 | /* retry FDISCs every second up to devloss */ |
| 4098 | retry = 1; |
| 4099 | maxretry = vport->cfg_devloss_tmo; |
| 4100 | delay = 1000; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4101 | } |
| 4102 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4103 | cmdiocb->retry++; |
| 4104 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4105 | phba->fc_stat.elsRetryExceeded++; |
| 4106 | retry = 0; |
| 4107 | } |
| 4108 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4109 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 4110 | retry = 0; |
| 4111 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4112 | out_retry: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4113 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4114 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 4115 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 4116 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 4117 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4118 | "2849 Stop retry ELS command " |
| 4119 | "x%x to remote NPORT x%x, " |
| 4120 | "Data: x%x x%x\n", cmd, did, |
| 4121 | cmdiocb->retry, delay); |
| 4122 | return 0; |
| 4123 | } |
| 4124 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4125 | |
| 4126 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4127 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4128 | "0107 Retry ELS command x%x to remote " |
| 4129 | "NPORT x%x Data: x%x x%x\n", |
| 4130 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4131 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4132 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 4133 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 4134 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 4135 | IOERR_NO_RESOURCES))) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4136 | /* Don't reset timer for no resources */ |
| 4137 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4138 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4139 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4140 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4141 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4142 | } |
| 4143 | |
| 4144 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4145 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4146 | phba->fc_stat.elsDelayRetry++; |
| 4147 | ndlp->nlp_retry = cmdiocb->retry; |
| 4148 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4149 | /* delay is specified in milliseconds */ |
| 4150 | mod_timer(&ndlp->nlp_delayfunc, |
| 4151 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4152 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4153 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4154 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4155 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4156 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4157 | if ((cmd == ELS_CMD_PRLI) || |
| 4158 | (cmd == ELS_CMD_NVMEPRLI)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4159 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 4160 | NLP_STE_PRLI_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4161 | else |
| 4162 | lpfc_nlp_set_state(vport, ndlp, |
| 4163 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4164 | ndlp->nlp_last_elscmd = cmd; |
| 4165 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4166 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4167 | } |
| 4168 | switch (cmd) { |
| 4169 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4170 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4171 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4172 | case ELS_CMD_FDISC: |
| 4173 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 4174 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4176 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4177 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4178 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4179 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4180 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4181 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4182 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4183 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4184 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4185 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4186 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4187 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4188 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4189 | case ELS_CMD_NVMEPRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4190 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4191 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 4192 | lpfc_issue_els_prli(vport, ndlp, 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_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4195 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4196 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4197 | lpfc_issue_els_logo(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 | } |
| 4200 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4201 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4202 | if (logerr) { |
| 4203 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4204 | "0137 No retry ELS command x%x to remote " |
| 4205 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 4206 | cmd, did, irsp->ulpStatus, |
| 4207 | irsp->un.ulpWord[4]); |
| 4208 | } |
| 4209 | else { |
| 4210 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4211 | "0108 No retry ELS command x%x to remote " |
| 4212 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 4213 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 4214 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4215 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4216 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4217 | } |
| 4218 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4219 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4220 | * 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] | 4221 | * @phba: pointer to lpfc hba data structure. |
| 4222 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 4223 | * |
| 4224 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 4225 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 4226 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 4227 | * response of the command IOCB. If so, it will be released before releasing |
| 4228 | * the lpfc DMA buffer associated with the IOCB itself. |
| 4229 | * |
| 4230 | * Return code |
| 4231 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 4232 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4233 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4234 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 4235 | { |
| 4236 | struct lpfc_dmabuf *buf_ptr; |
| 4237 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4238 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4239 | if (!list_empty(&buf_ptr1->list)) { |
| 4240 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 4241 | struct lpfc_dmabuf, |
| 4242 | list); |
| 4243 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 4244 | kfree(buf_ptr); |
| 4245 | } |
| 4246 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 4247 | kfree(buf_ptr1); |
| 4248 | return 0; |
| 4249 | } |
| 4250 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4251 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4252 | * 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] | 4253 | * @phba: pointer to lpfc hba data structure. |
| 4254 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 4255 | * |
| 4256 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 4257 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 4258 | * pool. |
| 4259 | * |
| 4260 | * Return code |
| 4261 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 4262 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4263 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4264 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 4265 | { |
| 4266 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 4267 | kfree(buf_ptr); |
| 4268 | return 0; |
| 4269 | } |
| 4270 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4271 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4272 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4273 | * @phba: pointer to lpfc hba data structure. |
| 4274 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 4275 | * |
| 4276 | * This routine frees a command IOCB and its associated resources. The |
| 4277 | * command IOCB data structure contains the reference to various associated |
| 4278 | * resources, these fields must be set to NULL if the associated reference |
| 4279 | * not present: |
| 4280 | * context1 - reference to ndlp |
| 4281 | * context2 - reference to cmd |
| 4282 | * context2->next - reference to rsp |
| 4283 | * context3 - reference to bpl |
| 4284 | * |
| 4285 | * It first properly decrements the reference count held on ndlp for the |
| 4286 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 4287 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 4288 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 4289 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 4290 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 4291 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 4292 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 4293 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 4294 | * |
| 4295 | * Return code |
| 4296 | * 0 - Success (currently, always return 0) |
| 4297 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4298 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4299 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4300 | { |
| 4301 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4302 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4303 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4304 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 4305 | if (ndlp) { |
| 4306 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 4307 | lpfc_nlp_put(ndlp); |
| 4308 | |
| 4309 | /* If the ndlp is not being used by another discovery |
| 4310 | * thread, free it. |
| 4311 | */ |
| 4312 | if (!lpfc_nlp_not_used(ndlp)) { |
| 4313 | /* If ndlp is being used by another discovery |
| 4314 | * thread, just clear NLP_DEFER_RM |
| 4315 | */ |
| 4316 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 4317 | } |
| 4318 | } |
| 4319 | else |
| 4320 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4321 | elsiocb->context1 = NULL; |
| 4322 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4323 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 4324 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4325 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 4326 | /* Firmware could still be in progress of DMAing |
| 4327 | * payload, so don't free data buffer till after |
| 4328 | * a hbeat. |
| 4329 | */ |
| 4330 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 4331 | buf_ptr = elsiocb->context2; |
| 4332 | elsiocb->context2 = NULL; |
| 4333 | if (buf_ptr) { |
| 4334 | buf_ptr1 = NULL; |
| 4335 | spin_lock_irq(&phba->hbalock); |
| 4336 | if (!list_empty(&buf_ptr->list)) { |
| 4337 | list_remove_head(&buf_ptr->list, |
| 4338 | buf_ptr1, struct lpfc_dmabuf, |
| 4339 | list); |
| 4340 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 4341 | list_add_tail(&buf_ptr1->list, |
| 4342 | &phba->elsbuf); |
| 4343 | phba->elsbuf_cnt++; |
| 4344 | } |
| 4345 | INIT_LIST_HEAD(&buf_ptr->list); |
| 4346 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 4347 | phba->elsbuf_cnt++; |
| 4348 | spin_unlock_irq(&phba->hbalock); |
| 4349 | } |
| 4350 | } else { |
| 4351 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 4352 | lpfc_els_free_data(phba, buf_ptr1); |
Johannes Thumshirn | 8667f51 | 2017-01-10 12:05:54 +0100 | [diff] [blame] | 4353 | elsiocb->context2 = NULL; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4354 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4355 | } |
| 4356 | |
| 4357 | if (elsiocb->context3) { |
| 4358 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4359 | lpfc_els_free_bpl(phba, buf_ptr); |
Johannes Thumshirn | 8667f51 | 2017-01-10 12:05:54 +0100 | [diff] [blame] | 4360 | elsiocb->context3 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4361 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4362 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4363 | return 0; |
| 4364 | } |
| 4365 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4366 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4367 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4368 | * @phba: pointer to lpfc hba data structure. |
| 4369 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4370 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 4371 | * |
| 4372 | * This routine is the completion callback function to the Logout (LOGO) |
| 4373 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 4374 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 4375 | * release the ndlp if it has the last reference remaining (reference count |
| 4376 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 4377 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 4378 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 4379 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 4380 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 4381 | * IOCB data structure. |
| 4382 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4383 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4384 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4385 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4386 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4387 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 4388 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4389 | IOCB_t *irsp; |
| 4390 | |
| 4391 | irsp = &rspiocb->iocb; |
| 4392 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4393 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 4394 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4395 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4396 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4397 | "0109 ACC to LOGO completes to NPort x%x " |
| 4398 | "Data: x%x x%x x%x\n", |
| 4399 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4400 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4401 | |
| 4402 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 4403 | /* NPort Recovery mode or node is just allocated */ |
| 4404 | if (!lpfc_nlp_not_used(ndlp)) { |
| 4405 | /* If the ndlp is being used by another discovery |
| 4406 | * thread, just unregister the RPI. |
| 4407 | */ |
| 4408 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4409 | } else { |
| 4410 | /* Indicate the node has already released, should |
| 4411 | * not reference to it from within lpfc_els_free_iocb. |
| 4412 | */ |
| 4413 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4414 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4415 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4416 | |
| 4417 | /* |
| 4418 | * 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] | 4419 | * At this point, the driver is done so release the IOCB |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4420 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4421 | lpfc_els_free_iocb(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4422 | } |
| 4423 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4424 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4425 | * 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] | 4426 | * @phba: pointer to lpfc hba data structure. |
| 4427 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4428 | * |
| 4429 | * This routine is the completion callback function for unregister default |
| 4430 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 4431 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 4432 | * decrements the ndlp reference count held for this completion callback |
| 4433 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 4434 | * whether there is only one reference left on the ndlp. If so, it will |
| 4435 | * perform one more decrement and trigger the release of the ndlp. |
| 4436 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4437 | void |
| 4438 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4439 | { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4440 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 4441 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4442 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4443 | pmb->ctx_buf = NULL; |
| 4444 | pmb->ctx_ndlp = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4445 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4446 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4447 | kfree(mp); |
| 4448 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4449 | if (ndlp) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4450 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4451 | "0006 rpi%x DID:%x flg:%x %d map:%x x%px\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4452 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4453 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4454 | ndlp->nlp_usg_map, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4455 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 4456 | lpfc_nlp_put(ndlp); |
| 4457 | /* This is the end of the default RPI cleanup logic for |
| 4458 | * this ndlp. If no other discovery threads are using |
| 4459 | * this ndlp, free all resources associated with it. |
| 4460 | */ |
| 4461 | lpfc_nlp_not_used(ndlp); |
| 4462 | } else { |
| 4463 | lpfc_drop_node(ndlp->vport, ndlp); |
| 4464 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4465 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4466 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4467 | return; |
| 4468 | } |
| 4469 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4470 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4471 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4472 | * @phba: pointer to lpfc hba data structure. |
| 4473 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4474 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 4475 | * |
| 4476 | * This routine is the completion callback function for ELS Response IOCB |
| 4477 | * command. In normal case, this callback function just properly sets the |
| 4478 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 4479 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 4480 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 4481 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 4482 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 4483 | * routine shall be invoked trying to release the ndlp if no other threads |
| 4484 | * are currently referring it. |
| 4485 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4486 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4487 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4488 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4489 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4490 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 4491 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 4492 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4493 | IOCB_t *irsp; |
| 4494 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4495 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4496 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4497 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4498 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 4499 | irsp = &rspiocb->iocb; |
| 4500 | |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 4501 | if (!vport) { |
James Smart | f84f8f9 | 2019-10-18 14:18:23 -0700 | [diff] [blame] | 4502 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 4503 | "3177 ELS response failed\n"); |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 4504 | goto out; |
| 4505 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4506 | if (cmdiocb->context_un.mbox) |
| 4507 | mbox = cmdiocb->context_un.mbox; |
| 4508 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4509 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 4510 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 4511 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4512 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4513 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 4514 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4515 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 4516 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4517 | */ |
| 4518 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 4519 | ls_rjt = 1; |
| 4520 | } |
| 4521 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4523 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4524 | if (mbox) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4525 | mp = (struct lpfc_dmabuf *)mbox->ctx_buf; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 4526 | if (mp) { |
| 4527 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4528 | kfree(mp); |
| 4529 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4530 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4531 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4532 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 4533 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4534 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4535 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4536 | /* Indicate the node has already released, |
| 4537 | * should not reference to it from within |
| 4538 | * the routine lpfc_els_free_iocb. |
| 4539 | */ |
| 4540 | cmdiocb->context1 = NULL; |
| 4541 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4542 | goto out; |
| 4543 | } |
| 4544 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4545 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4546 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4547 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4548 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4549 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4550 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4551 | "0110 ELS response tag x%x completes " |
| 4552 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 4553 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 4554 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 4555 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4556 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4557 | if (mbox) { |
| 4558 | if ((rspiocb->iocb.ulpStatus == 0) |
| 4559 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
Dick Kennedy | 1fe6847 | 2017-08-23 16:55:30 -0700 | [diff] [blame] | 4560 | if (!lpfc_unreg_rpi(vport, ndlp) && |
James Smart | f22bfe8 | 2019-05-21 17:48:58 -0700 | [diff] [blame] | 4561 | (!(vport->fc_flag & FC_PT2PT)) && |
Dick Kennedy | 1fe6847 | 2017-08-23 16:55:30 -0700 | [diff] [blame] | 4562 | (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 4563 | ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) { |
| 4564 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4565 | LOG_DISCOVERY, |
| 4566 | "0314 PLOGI recov DID x%x " |
| 4567 | "Data: x%x x%x x%x\n", |
| 4568 | ndlp->nlp_DID, ndlp->nlp_state, |
| 4569 | ndlp->nlp_rpi, ndlp->nlp_flag); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4570 | mp = mbox->ctx_buf; |
Dick Kennedy | 1fe6847 | 2017-08-23 16:55:30 -0700 | [diff] [blame] | 4571 | if (mp) { |
| 4572 | lpfc_mbuf_free(phba, mp->virt, |
| 4573 | mp->phys); |
| 4574 | kfree(mp); |
| 4575 | } |
| 4576 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4577 | goto out; |
| 4578 | } |
| 4579 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4580 | /* Increment reference count to ndlp to hold the |
| 4581 | * reference to ndlp for the callback function. |
| 4582 | */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4583 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4584 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4585 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 4586 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 4587 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 4588 | } |
| 4589 | else { |
| 4590 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 4591 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 4592 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4593 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4594 | } |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 4595 | |
| 4596 | ndlp->nlp_flag |= NLP_REG_LOGIN_SEND; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4597 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4598 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4599 | goto out; |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 4600 | |
| 4601 | /* Decrement the ndlp reference count we |
| 4602 | * set for this failed mailbox command. |
| 4603 | */ |
| 4604 | lpfc_nlp_put(ndlp); |
| 4605 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4606 | |
| 4607 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 4608 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4609 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 4610 | "Data: x%x x%x x%x\n", |
| 4611 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4612 | ndlp->nlp_rpi); |
| 4613 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4614 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4615 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4616 | /* Indicate node has already been released, |
| 4617 | * should not reference to it from within |
| 4618 | * the routine lpfc_els_free_iocb. |
| 4619 | */ |
| 4620 | cmdiocb->context1 = NULL; |
| 4621 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4622 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4623 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 4624 | if (!lpfc_error_lost_link(irsp) && |
| 4625 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4626 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4627 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4628 | /* Indicate node has already been |
| 4629 | * released, should not reference |
| 4630 | * to it from within the routine |
| 4631 | * lpfc_els_free_iocb. |
| 4632 | */ |
| 4633 | cmdiocb->context1 = NULL; |
| 4634 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4635 | } |
| 4636 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4637 | mp = (struct lpfc_dmabuf *)mbox->ctx_buf; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 4638 | if (mp) { |
| 4639 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4640 | kfree(mp); |
| 4641 | } |
| 4642 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4643 | } |
| 4644 | out: |
James Smart | 6c6d59e | 2019-11-11 15:03:57 -0800 | [diff] [blame] | 4645 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && shost) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4646 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4647 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4648 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4649 | |
| 4650 | /* If the node is not being used by another discovery thread, |
| 4651 | * and we are sending a reject, we are done with it. |
| 4652 | * Release driver reference count here and free associated |
| 4653 | * resources. |
| 4654 | */ |
| 4655 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4656 | if (lpfc_nlp_not_used(ndlp)) |
| 4657 | /* Indicate node has already been released, |
| 4658 | * should not reference to it from within |
| 4659 | * the routine lpfc_els_free_iocb. |
| 4660 | */ |
| 4661 | cmdiocb->context1 = NULL; |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 4662 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4663 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4664 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4665 | lpfc_els_free_iocb(phba, cmdiocb); |
| 4666 | return; |
| 4667 | } |
| 4668 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4669 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4670 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4671 | * @vport: pointer to a host virtual N_Port data structure. |
| 4672 | * @flag: the els command code to be accepted. |
| 4673 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4674 | * @ndlp: pointer to a node-list data structure. |
| 4675 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4676 | * |
| 4677 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 4678 | * command. It uses the @flag to properly set up the IOCB field for the |
| 4679 | * specific ACC response command to be issued and invokes the |
| 4680 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 4681 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 4682 | * field of the IOCB for the completion callback function to issue the |
| 4683 | * mailbox command to the HBA later when callback is invoked. |
| 4684 | * |
| 4685 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4686 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4687 | * will be stored into the context1 field of the IOCB for the completion |
| 4688 | * callback function to the corresponding response ELS IOCB command. |
| 4689 | * |
| 4690 | * Return code |
| 4691 | * 0 - Successfully issued acc response |
| 4692 | * 1 - Failed to issue acc response |
| 4693 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4694 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4695 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 4696 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4697 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4698 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4699 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4700 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4701 | IOCB_t *icmd; |
| 4702 | IOCB_t *oldcmd; |
| 4703 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4704 | uint8_t *pcmd; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4705 | struct serv_parm *sp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4706 | uint16_t cmdsize; |
| 4707 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4708 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4709 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4710 | oldcmd = &oldiocb->iocb; |
| 4711 | |
| 4712 | switch (flag) { |
| 4713 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4714 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4715 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 4716 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4717 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4718 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4719 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4720 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4721 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4722 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4723 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4724 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4725 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4726 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4727 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4728 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4729 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4730 | |
| 4731 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4732 | "Issue ACC: did:x%x flg:x%x", |
| 4733 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4734 | break; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4735 | case ELS_CMD_FLOGI: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4736 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4737 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4738 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 4739 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4740 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4741 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4742 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4743 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4744 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4745 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4746 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4747 | |
| 4748 | if (mbox) |
| 4749 | elsiocb->context_un.mbox = mbox; |
| 4750 | |
| 4751 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4752 | pcmd += sizeof(uint32_t); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4753 | sp = (struct serv_parm *)pcmd; |
| 4754 | |
| 4755 | if (flag == ELS_CMD_FLOGI) { |
| 4756 | /* Copy the received service parameters back */ |
| 4757 | memcpy(sp, &phba->fc_fabparam, |
| 4758 | sizeof(struct serv_parm)); |
| 4759 | |
| 4760 | /* Clear the F_Port bit */ |
| 4761 | sp->cmn.fPort = 0; |
| 4762 | |
| 4763 | /* Mark all class service parameters as invalid */ |
| 4764 | sp->cls1.classValid = 0; |
| 4765 | sp->cls2.classValid = 0; |
| 4766 | sp->cls3.classValid = 0; |
| 4767 | sp->cls4.classValid = 0; |
| 4768 | |
| 4769 | /* Copy our worldwide names */ |
| 4770 | memcpy(&sp->portName, &vport->fc_sparam.portName, |
| 4771 | sizeof(struct lpfc_name)); |
| 4772 | memcpy(&sp->nodeName, &vport->fc_sparam.nodeName, |
| 4773 | sizeof(struct lpfc_name)); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4774 | } else { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4775 | memcpy(pcmd, &vport->fc_sparam, |
| 4776 | sizeof(struct serv_parm)); |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 4777 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4778 | sp->cmn.valid_vendor_ver_level = 0; |
| 4779 | memset(sp->un.vendorVersion, 0, |
| 4780 | sizeof(sp->un.vendorVersion)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 4781 | sp->cmn.bbRcvSizeMsb &= 0xF; |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4782 | |
| 4783 | /* If our firmware supports this feature, convey that |
| 4784 | * info to the target using the vendor specific field. |
| 4785 | */ |
| 4786 | if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { |
| 4787 | sp->cmn.valid_vendor_ver_level = 1; |
| 4788 | sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); |
| 4789 | sp->un.vv.flags = |
| 4790 | cpu_to_be32(LPFC_VV_SUPPRESS_RSP); |
| 4791 | } |
| 4792 | } |
| 4793 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4794 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4795 | "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4796 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4797 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4798 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4799 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4800 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4801 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 4802 | if (!elsiocb) |
| 4803 | return 1; |
| 4804 | |
| 4805 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4806 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4807 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4808 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4809 | |
| 4810 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4811 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4812 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 4813 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 4814 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4815 | |
| 4816 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4817 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 4818 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4819 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4820 | default: |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4821 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4822 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4823 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4824 | spin_lock_irq(shost->host_lock); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4825 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4826 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND)) |
| 4827 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4828 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4829 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 4830 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4831 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4832 | } |
| 4833 | |
| 4834 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4835 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4836 | if (rc == IOCB_ERROR) { |
| 4837 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4838 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4839 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4840 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4841 | } |
| 4842 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4843 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4844 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4845 | * @vport: pointer to a virtual N_Port data structure. |
| 4846 | * @rejectError: |
| 4847 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4848 | * @ndlp: pointer to a node-list data structure. |
| 4849 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4850 | * |
| 4851 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 4852 | * command. If a @mbox pointer is passed in, it will be put into the |
| 4853 | * context_un.mbox field of the IOCB for the completion callback function |
| 4854 | * to issue to the HBA later. |
| 4855 | * |
| 4856 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4857 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4858 | * will be stored into the context1 field of the IOCB for the completion |
| 4859 | * callback function to the reject response ELS IOCB command. |
| 4860 | * |
| 4861 | * Return code |
| 4862 | * 0 - Successfully issued reject response |
| 4863 | * 1 - Failed to issue reject response |
| 4864 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4865 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4866 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4867 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 4868 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4869 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4870 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4871 | IOCB_t *icmd; |
| 4872 | IOCB_t *oldcmd; |
| 4873 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4874 | uint8_t *pcmd; |
| 4875 | uint16_t cmdsize; |
| 4876 | int rc; |
| 4877 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4878 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4879 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4880 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4881 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4882 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4883 | |
| 4884 | icmd = &elsiocb->iocb; |
| 4885 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4886 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4887 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4888 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4889 | |
| 4890 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4891 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4892 | *((uint32_t *) (pcmd)) = rejectError; |
| 4893 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4894 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4895 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4896 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4897 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4898 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4899 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 4900 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4901 | "rpi x%x\n", |
| 4902 | rejectError, elsiocb->iotag, |
| 4903 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 4904 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4905 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4906 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 4907 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 4908 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4909 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4910 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4911 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4912 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4913 | if (rc == IOCB_ERROR) { |
| 4914 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4915 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4916 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4917 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4918 | } |
| 4919 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4920 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4921 | * 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] | 4922 | * @vport: pointer to a virtual N_Port data structure. |
| 4923 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4924 | * @ndlp: pointer to a node-list data structure. |
| 4925 | * |
| 4926 | * This routine prepares and issues an Accept (ACC) response to Address |
| 4927 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 4928 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4929 | * |
| 4930 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4931 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4932 | * will be stored into the context1 field of the IOCB for the completion |
| 4933 | * callback function to the ADISC Accept response ELS IOCB command. |
| 4934 | * |
| 4935 | * Return code |
| 4936 | * 0 - Successfully issued acc adisc response |
| 4937 | * 1 - Failed to issue adisc acc response |
| 4938 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4939 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4940 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 4941 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4942 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4943 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4944 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4945 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4946 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4947 | uint8_t *pcmd; |
| 4948 | uint16_t cmdsize; |
| 4949 | int rc; |
| 4950 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4951 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4952 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4953 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4954 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4955 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4956 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4957 | icmd = &elsiocb->iocb; |
| 4958 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4959 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4960 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4961 | |
| 4962 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4963 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4964 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 4965 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 4966 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4967 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4968 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4969 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4970 | |
| 4971 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4972 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4973 | |
| 4974 | ap = (ADISC *) (pcmd); |
| 4975 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4976 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4977 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4978 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4979 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4980 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4981 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 4982 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4983 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4984 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4985 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4986 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4987 | if (rc == IOCB_ERROR) { |
| 4988 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4989 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4990 | } |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 4991 | |
| 4992 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
| 4993 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4994 | "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, " |
| 4995 | "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x " |
| 4996 | "RPI: x%x, fc_flag x%x\n", |
| 4997 | rc, elsiocb->iotag, elsiocb->sli4_xritag, |
| 4998 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4999 | ndlp->nlp_rpi, vport->fc_flag); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5000 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5001 | } |
| 5002 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5003 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5004 | * 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] | 5005 | * @vport: pointer to a virtual N_Port data structure. |
| 5006 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5007 | * @ndlp: pointer to a node-list data structure. |
| 5008 | * |
| 5009 | * This routine prepares and issues an Accept (ACC) response to Process |
| 5010 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 5011 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 5012 | * |
| 5013 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5014 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5015 | * will be stored into the context1 field of the IOCB for the completion |
| 5016 | * callback function to the PRLI Accept response ELS IOCB command. |
| 5017 | * |
| 5018 | * Return code |
| 5019 | * 0 - Successfully issued acc prli response |
| 5020 | * 1 - Failed to issue acc prli response |
| 5021 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5022 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5023 | 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] | 5024 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5025 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5026 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5027 | PRLI *npr; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5028 | struct lpfc_nvme_prli *npr_nvme; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5029 | lpfc_vpd_t *vpd; |
| 5030 | IOCB_t *icmd; |
| 5031 | IOCB_t *oldcmd; |
| 5032 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5033 | uint8_t *pcmd; |
| 5034 | uint16_t cmdsize; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5035 | uint32_t prli_fc4_req, *req_payload; |
| 5036 | struct lpfc_dmabuf *req_buf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5037 | int rc; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5038 | u32 elsrspcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5039 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5040 | /* Need the incoming PRLI payload to determine if the ACC is for an |
| 5041 | * FC4 or NVME PRLI type. The PRLI type is at word 1. |
| 5042 | */ |
| 5043 | req_buf = (struct lpfc_dmabuf *)oldiocb->context2; |
| 5044 | req_payload = (((uint32_t *)req_buf->virt) + 1); |
| 5045 | |
| 5046 | /* PRLI type payload is at byte 3 for FCP or NVME. */ |
| 5047 | prli_fc4_req = be32_to_cpu(*req_payload); |
| 5048 | prli_fc4_req = (prli_fc4_req >> 24) & 0xff; |
| 5049 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5050 | "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n", |
| 5051 | prli_fc4_req, *((uint32_t *)req_payload)); |
| 5052 | |
| 5053 | if (prli_fc4_req == PRLI_FCP_TYPE) { |
| 5054 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
| 5055 | elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
| 5056 | } else if (prli_fc4_req & PRLI_NVME_TYPE) { |
| 5057 | cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli); |
| 5058 | elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK)); |
| 5059 | } else { |
| 5060 | return 1; |
| 5061 | } |
| 5062 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5063 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5064 | ndlp->nlp_DID, elsrspcmd); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5065 | if (!elsiocb) |
| 5066 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5067 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5068 | icmd = &elsiocb->iocb; |
| 5069 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5070 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 5071 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 5072 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5073 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5074 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5075 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 5076 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 5077 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5078 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5079 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5080 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5081 | memset(pcmd, 0, cmdsize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5082 | |
James Smart | c07f10c | 2017-04-21 16:04:54 -0700 | [diff] [blame] | 5083 | *((uint32_t *)(pcmd)) = elsrspcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5084 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5085 | |
| 5086 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5087 | vpd = &phba->vpd; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5088 | |
| 5089 | if (prli_fc4_req == PRLI_FCP_TYPE) { |
| 5090 | /* |
| 5091 | * If the remote port is a target and our firmware version |
| 5092 | * is 3.20 or later, set the following bits for FC-TAPE |
| 5093 | * support. |
| 5094 | */ |
| 5095 | npr = (PRLI *) pcmd; |
| 5096 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 5097 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| 5098 | npr->ConfmComplAllowed = 1; |
| 5099 | npr->Retry = 1; |
| 5100 | npr->TaskRetryIdReq = 1; |
| 5101 | } |
| 5102 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 5103 | npr->estabImagePair = 1; |
| 5104 | npr->readXferRdyDis = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5105 | npr->ConfmComplAllowed = 1; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5106 | npr->prliType = PRLI_FCP_TYPE; |
| 5107 | npr->initiatorFunc = 1; |
| 5108 | } else if (prli_fc4_req & PRLI_NVME_TYPE) { |
| 5109 | /* Respond with an NVME PRLI Type */ |
| 5110 | npr_nvme = (struct lpfc_nvme_prli *) pcmd; |
| 5111 | bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); |
| 5112 | bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ |
| 5113 | bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5114 | if (phba->nvmet_support) { |
| 5115 | bf_set(prli_tgt, npr_nvme, 1); |
| 5116 | bf_set(prli_disc, npr_nvme, 1); |
| 5117 | if (phba->cfg_nvme_enable_fb) { |
| 5118 | bf_set(prli_fba, npr_nvme, 1); |
| 5119 | |
| 5120 | /* TBD. Target mode needs to post buffers |
| 5121 | * that support the configured first burst |
| 5122 | * byte size. |
| 5123 | */ |
| 5124 | bf_set(prli_fb_sz, npr_nvme, |
| 5125 | phba->cfg_nvmet_fb_size); |
| 5126 | } |
| 5127 | } else { |
| 5128 | bf_set(prli_init, npr_nvme, 1); |
| 5129 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5130 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5131 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, |
| 5132 | "6015 NVME issue PRLI ACC word1 x%08x " |
| 5133 | "word4 x%08x word5 x%08x flag x%x, " |
| 5134 | "fcp_info x%x nlp_type x%x\n", |
| 5135 | npr_nvme->word1, npr_nvme->word4, |
| 5136 | npr_nvme->word5, ndlp->nlp_flag, |
| 5137 | ndlp->nlp_fcp_info, ndlp->nlp_type); |
| 5138 | npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); |
| 5139 | npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); |
| 5140 | npr_nvme->word5 = cpu_to_be32(npr_nvme->word5); |
| 5141 | } else |
| 5142 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5143 | "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n", |
| 5144 | prli_fc4_req, ndlp->nlp_fc4_type, |
| 5145 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5146 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5147 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 5148 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 5149 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 5150 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5151 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5152 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5153 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5154 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5155 | if (rc == IOCB_ERROR) { |
| 5156 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5157 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5158 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5159 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5160 | } |
| 5161 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5162 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5163 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5164 | * @vport: pointer to a virtual N_Port data structure. |
| 5165 | * @format: rnid command format. |
| 5166 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5167 | * @ndlp: pointer to a node-list data structure. |
| 5168 | * |
| 5169 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 5170 | * (ACC) response. It constructs the RNID ACC response command according to |
| 5171 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 5172 | * issue the response. Note that this command does not need to hold the ndlp |
| 5173 | * reference count for the callback. So, the ndlp reference count taken by |
| 5174 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 5175 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 5176 | * there is no ndlp reference available. |
| 5177 | * |
| 5178 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5179 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5180 | * will be stored into the context1 field of the IOCB for the completion |
| 5181 | * callback function. However, for the RNID Accept Response ELS command, |
| 5182 | * this is undone later by this routine after the IOCB is allocated. |
| 5183 | * |
| 5184 | * Return code |
| 5185 | * 0 - Successfully issued acc rnid response |
| 5186 | * 1 - Failed to issue acc rnid response |
| 5187 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5188 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5189 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5190 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5191 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5192 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5193 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5194 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5195 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5196 | uint8_t *pcmd; |
| 5197 | uint16_t cmdsize; |
| 5198 | int rc; |
| 5199 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5200 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 5201 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5202 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5203 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5204 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5205 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5206 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5207 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5208 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5209 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5210 | icmd = &elsiocb->iocb; |
| 5211 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5212 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 5213 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 5214 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5215 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5216 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5217 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 5218 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5219 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5220 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5221 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5222 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5223 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5224 | rn = (RNID *) (pcmd); |
| 5225 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5226 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 5227 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5228 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5229 | switch (format) { |
| 5230 | case 0: |
| 5231 | rn->SpecificLen = 0; |
| 5232 | break; |
| 5233 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5234 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5235 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5236 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5237 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 5238 | rn->un.topologyDisc.physPort = 0; |
| 5239 | rn->un.topologyDisc.attachedNodes = 0; |
| 5240 | break; |
| 5241 | default: |
| 5242 | rn->CommonLen = 0; |
| 5243 | rn->SpecificLen = 0; |
| 5244 | break; |
| 5245 | } |
| 5246 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5247 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 5248 | "Issue ACC RNID: did:x%x flg:x%x", |
| 5249 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 5250 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5251 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5252 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5253 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5254 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5255 | if (rc == IOCB_ERROR) { |
| 5256 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5257 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5258 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5259 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5260 | } |
| 5261 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5262 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5263 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. |
| 5264 | * @vport: pointer to a virtual N_Port data structure. |
| 5265 | * @iocb: pointer to the lpfc command iocb data structure. |
| 5266 | * @ndlp: pointer to a node-list data structure. |
| 5267 | * |
| 5268 | * Return |
| 5269 | **/ |
| 5270 | static void |
| 5271 | lpfc_els_clear_rrq(struct lpfc_vport *vport, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5272 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5273 | { |
| 5274 | struct lpfc_hba *phba = vport->phba; |
| 5275 | uint8_t *pcmd; |
| 5276 | struct RRQ *rrq; |
| 5277 | uint16_t rxid; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5278 | uint16_t xri; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5279 | struct lpfc_node_rrq *prrq; |
| 5280 | |
| 5281 | |
| 5282 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); |
| 5283 | pcmd += sizeof(uint32_t); |
| 5284 | rrq = (struct RRQ *)pcmd; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5285 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5286 | rxid = bf_get(rrq_rxid, rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5287 | |
| 5288 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5289 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" |
| 5290 | " x%x x%x\n", |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5291 | be32_to_cpu(bf_get(rrq_did, rrq)), |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5292 | bf_get(rrq_oxid, rrq), |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5293 | rxid, |
| 5294 | iocb->iotag, iocb->iocb.ulpContext); |
| 5295 | |
| 5296 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 5297 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", |
| 5298 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5299 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5300 | xri = bf_get(rrq_oxid, rrq); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5301 | else |
| 5302 | xri = rxid; |
| 5303 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5304 | if (prrq) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5305 | lpfc_clr_rrq_active(phba, xri, prrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5306 | return; |
| 5307 | } |
| 5308 | |
| 5309 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5310 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 5311 | * @vport: pointer to a virtual N_Port data structure. |
| 5312 | * @data: pointer to echo data to return in the accept. |
| 5313 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5314 | * @ndlp: pointer to a node-list data structure. |
| 5315 | * |
| 5316 | * Return code |
| 5317 | * 0 - Successfully issued acc echo response |
| 5318 | * 1 - Failed to issue acc echo response |
| 5319 | **/ |
| 5320 | static int |
| 5321 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 5322 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 5323 | { |
| 5324 | struct lpfc_hba *phba = vport->phba; |
| 5325 | struct lpfc_iocbq *elsiocb; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5326 | uint8_t *pcmd; |
| 5327 | uint16_t cmdsize; |
| 5328 | int rc; |
| 5329 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5330 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 5331 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5332 | /* The accumulated length can exceed the BPL_SIZE. For |
| 5333 | * now, use this as the limit |
| 5334 | */ |
| 5335 | if (cmdsize > LPFC_BPL_SIZE) |
| 5336 | cmdsize = LPFC_BPL_SIZE; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5337 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5338 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5339 | if (!elsiocb) |
| 5340 | return 1; |
| 5341 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5342 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 5343 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; |
| 5344 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5345 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 5346 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5347 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 5348 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 5349 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5350 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5351 | pcmd += sizeof(uint32_t); |
| 5352 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 5353 | |
| 5354 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 5355 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 5356 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 5357 | |
| 5358 | phba->fc_stat.elsXmitACC++; |
| 5359 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5360 | |
| 5361 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5362 | if (rc == IOCB_ERROR) { |
| 5363 | lpfc_els_free_iocb(phba, elsiocb); |
| 5364 | return 1; |
| 5365 | } |
| 5366 | return 0; |
| 5367 | } |
| 5368 | |
| 5369 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5370 | * 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] | 5371 | * @vport: pointer to a host virtual N_Port data structure. |
| 5372 | * |
| 5373 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 5374 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 5375 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 5376 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 5377 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 5378 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 5379 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 5380 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 5381 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 5382 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 5383 | * no more ADISC need to be sent. |
| 5384 | * |
| 5385 | * Return code |
| 5386 | * The number of N_Ports with adisc issued. |
| 5387 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5388 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5389 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5390 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5391 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5392 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5393 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5394 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5395 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5396 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5397 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5398 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5399 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 5400 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 5401 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5402 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5403 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5404 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5405 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5406 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 5407 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5408 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5409 | vport->num_disc_nodes++; |
| 5410 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5411 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5412 | spin_lock_irq(shost->host_lock); |
| 5413 | vport->fc_flag |= FC_NLP_MORE; |
| 5414 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5415 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5416 | } |
| 5417 | } |
| 5418 | } |
| 5419 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5420 | spin_lock_irq(shost->host_lock); |
| 5421 | vport->fc_flag &= ~FC_NLP_MORE; |
| 5422 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5423 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5424 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5425 | } |
| 5426 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5427 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5428 | * 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] | 5429 | * @vport: pointer to a host virtual N_Port data structure. |
| 5430 | * |
| 5431 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 5432 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 5433 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 5434 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 5435 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 5436 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 5437 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 5438 | * later pick up. On the other hand, after walking through all the ndlps with |
| 5439 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 5440 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 5441 | * PLOGI need to be sent. |
| 5442 | * |
| 5443 | * Return code |
| 5444 | * The number of N_Ports with plogi issued. |
| 5445 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5446 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5447 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5448 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5449 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5450 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5451 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5452 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5453 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 5454 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5455 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5456 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5457 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5458 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 5459 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 5460 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5461 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5462 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5463 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5464 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5465 | vport->num_disc_nodes++; |
| 5466 | if (vport->num_disc_nodes >= |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5467 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5468 | spin_lock_irq(shost->host_lock); |
| 5469 | vport->fc_flag |= FC_NLP_MORE; |
| 5470 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5471 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5472 | } |
| 5473 | } |
| 5474 | } |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5475 | |
| 5476 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5477 | "6452 Discover PLOGI %d flag x%x\n", |
| 5478 | sentplogi, vport->fc_flag); |
| 5479 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5480 | if (sentplogi) { |
| 5481 | lpfc_set_disctmo(vport); |
| 5482 | } |
| 5483 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5484 | spin_lock_irq(shost->host_lock); |
| 5485 | vport->fc_flag &= ~FC_NLP_MORE; |
| 5486 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5487 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5488 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5489 | } |
| 5490 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5491 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5492 | lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc, |
| 5493 | uint32_t word0) |
| 5494 | { |
| 5495 | |
| 5496 | desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG); |
| 5497 | desc->payload.els_req = word0; |
| 5498 | desc->length = cpu_to_be32(sizeof(desc->payload)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5499 | |
| 5500 | return sizeof(struct fc_rdp_link_service_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5501 | } |
| 5502 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5503 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5504 | lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc, |
| 5505 | uint8_t *page_a0, uint8_t *page_a2) |
| 5506 | { |
| 5507 | uint16_t wavelength; |
| 5508 | uint16_t temperature; |
| 5509 | uint16_t rx_power; |
| 5510 | uint16_t tx_bias; |
| 5511 | uint16_t tx_power; |
| 5512 | uint16_t vcc; |
| 5513 | uint16_t flag = 0; |
| 5514 | struct sff_trasnceiver_codes_byte4 *trasn_code_byte4; |
| 5515 | struct sff_trasnceiver_codes_byte5 *trasn_code_byte5; |
| 5516 | |
| 5517 | desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG); |
| 5518 | |
| 5519 | trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *) |
| 5520 | &page_a0[SSF_TRANSCEIVER_CODE_B4]; |
| 5521 | trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *) |
| 5522 | &page_a0[SSF_TRANSCEIVER_CODE_B5]; |
| 5523 | |
| 5524 | if ((trasn_code_byte4->fc_sw_laser) || |
| 5525 | (trasn_code_byte5->fc_sw_laser_sl) || |
| 5526 | (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */ |
| 5527 | flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT); |
| 5528 | } else if (trasn_code_byte4->fc_lw_laser) { |
| 5529 | wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) | |
| 5530 | page_a0[SSF_WAVELENGTH_B0]; |
| 5531 | if (wavelength == SFP_WAVELENGTH_LC1310) |
| 5532 | flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT; |
| 5533 | if (wavelength == SFP_WAVELENGTH_LL1550) |
| 5534 | flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT; |
| 5535 | } |
| 5536 | /* check if its SFP+ */ |
| 5537 | flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ? |
| 5538 | SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN) |
| 5539 | << SFP_FLAG_CT_SHIFT; |
| 5540 | |
| 5541 | /* check if its OPTICAL */ |
| 5542 | flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ? |
| 5543 | SFP_FLAG_IS_OPTICAL_PORT : 0) |
| 5544 | << SFP_FLAG_IS_OPTICAL_SHIFT; |
| 5545 | |
| 5546 | temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 | |
| 5547 | page_a2[SFF_TEMPERATURE_B0]); |
| 5548 | vcc = (page_a2[SFF_VCC_B1] << 8 | |
| 5549 | page_a2[SFF_VCC_B0]); |
| 5550 | tx_power = (page_a2[SFF_TXPOWER_B1] << 8 | |
| 5551 | page_a2[SFF_TXPOWER_B0]); |
| 5552 | tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 | |
| 5553 | page_a2[SFF_TX_BIAS_CURRENT_B0]); |
| 5554 | rx_power = (page_a2[SFF_RXPOWER_B1] << 8 | |
| 5555 | page_a2[SFF_RXPOWER_B0]); |
| 5556 | desc->sfp_info.temperature = cpu_to_be16(temperature); |
| 5557 | desc->sfp_info.rx_power = cpu_to_be16(rx_power); |
| 5558 | desc->sfp_info.tx_bias = cpu_to_be16(tx_bias); |
| 5559 | desc->sfp_info.tx_power = cpu_to_be16(tx_power); |
| 5560 | desc->sfp_info.vcc = cpu_to_be16(vcc); |
| 5561 | |
| 5562 | desc->sfp_info.flags = cpu_to_be16(flag); |
| 5563 | desc->length = cpu_to_be32(sizeof(desc->sfp_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5564 | |
| 5565 | return sizeof(struct fc_rdp_sfp_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5566 | } |
| 5567 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5568 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5569 | lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc, |
| 5570 | READ_LNK_VAR *stat) |
| 5571 | { |
| 5572 | uint32_t type; |
| 5573 | |
| 5574 | desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG); |
| 5575 | |
| 5576 | type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT; |
| 5577 | |
| 5578 | desc->info.port_type = cpu_to_be32(type); |
| 5579 | |
| 5580 | desc->info.link_status.link_failure_cnt = |
| 5581 | cpu_to_be32(stat->linkFailureCnt); |
| 5582 | desc->info.link_status.loss_of_synch_cnt = |
| 5583 | cpu_to_be32(stat->lossSyncCnt); |
| 5584 | desc->info.link_status.loss_of_signal_cnt = |
| 5585 | cpu_to_be32(stat->lossSignalCnt); |
| 5586 | desc->info.link_status.primitive_seq_proto_err = |
| 5587 | cpu_to_be32(stat->primSeqErrCnt); |
| 5588 | desc->info.link_status.invalid_trans_word = |
| 5589 | cpu_to_be32(stat->invalidXmitWord); |
| 5590 | desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt); |
| 5591 | |
| 5592 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5593 | |
| 5594 | return sizeof(struct fc_rdp_link_error_status_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5595 | } |
| 5596 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5597 | static uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5598 | lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat, |
| 5599 | struct lpfc_vport *vport) |
| 5600 | { |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5601 | uint32_t bbCredit; |
| 5602 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5603 | desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG); |
| 5604 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5605 | bbCredit = vport->fc_sparam.cmn.bbCreditLsb | |
| 5606 | (vport->fc_sparam.cmn.bbCreditMsb << 8); |
| 5607 | desc->bbc_info.port_bbc = cpu_to_be32(bbCredit); |
| 5608 | if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
| 5609 | bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb | |
| 5610 | (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8); |
| 5611 | desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit); |
| 5612 | } else { |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5613 | desc->bbc_info.attached_port_bbc = 0; |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5614 | } |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5615 | |
| 5616 | desc->bbc_info.rtt = 0; |
| 5617 | desc->length = cpu_to_be32(sizeof(desc->bbc_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5618 | |
| 5619 | return sizeof(struct fc_rdp_bbc_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5620 | } |
| 5621 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5622 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5623 | lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba, |
| 5624 | struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2) |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5625 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5626 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5627 | |
| 5628 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5629 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5630 | desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM]; |
| 5631 | desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM]; |
| 5632 | desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING]; |
| 5633 | desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5634 | |
| 5635 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 5636 | flags |= RDP_OET_HIGH_ALARM; |
| 5637 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 5638 | flags |= RDP_OET_LOW_ALARM; |
| 5639 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 5640 | flags |= RDP_OET_HIGH_WARNING; |
| 5641 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 5642 | flags |= RDP_OET_LOW_WARNING; |
| 5643 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5644 | flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT); |
| 5645 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5646 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5647 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5648 | } |
| 5649 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5650 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5651 | lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba, |
| 5652 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5653 | uint8_t *page_a2) |
| 5654 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5655 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5656 | |
| 5657 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5658 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5659 | desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM]; |
| 5660 | desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM]; |
| 5661 | desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING]; |
| 5662 | desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5663 | |
| 5664 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 5665 | flags |= RDP_OET_HIGH_ALARM; |
| 5666 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 5667 | flags |= RDP_OET_LOW_ALARM; |
| 5668 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 5669 | flags |= RDP_OET_HIGH_WARNING; |
| 5670 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 5671 | flags |= RDP_OET_LOW_WARNING; |
| 5672 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5673 | flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT); |
| 5674 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5675 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5676 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5677 | } |
| 5678 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5679 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5680 | lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba, |
| 5681 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5682 | uint8_t *page_a2) |
| 5683 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5684 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5685 | |
| 5686 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5687 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5688 | desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM]; |
| 5689 | desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM]; |
| 5690 | desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING]; |
| 5691 | desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5692 | |
| 5693 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 5694 | flags |= RDP_OET_HIGH_ALARM; |
| 5695 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 5696 | flags |= RDP_OET_LOW_ALARM; |
| 5697 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 5698 | flags |= RDP_OET_HIGH_WARNING; |
| 5699 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 5700 | flags |= RDP_OET_LOW_WARNING; |
| 5701 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5702 | flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT); |
| 5703 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5704 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5705 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5706 | } |
| 5707 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5708 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5709 | lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba, |
| 5710 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5711 | uint8_t *page_a2) |
| 5712 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5713 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5714 | |
| 5715 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5716 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5717 | desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM]; |
| 5718 | desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM]; |
| 5719 | desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING]; |
| 5720 | desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5721 | |
| 5722 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 5723 | flags |= RDP_OET_HIGH_ALARM; |
| 5724 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 5725 | flags |= RDP_OET_LOW_ALARM; |
| 5726 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 5727 | flags |= RDP_OET_HIGH_WARNING; |
| 5728 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 5729 | flags |= RDP_OET_LOW_WARNING; |
| 5730 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5731 | flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT); |
| 5732 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5733 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5734 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5735 | } |
| 5736 | |
| 5737 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5738 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5739 | lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba, |
| 5740 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5741 | uint8_t *page_a2) |
| 5742 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5743 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5744 | |
| 5745 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5746 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5747 | desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM]; |
| 5748 | desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM]; |
| 5749 | desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING]; |
| 5750 | desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5751 | |
| 5752 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 5753 | flags |= RDP_OET_HIGH_ALARM; |
| 5754 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 5755 | flags |= RDP_OET_LOW_ALARM; |
| 5756 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 5757 | flags |= RDP_OET_HIGH_WARNING; |
| 5758 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 5759 | flags |= RDP_OET_LOW_WARNING; |
| 5760 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5761 | flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT); |
| 5762 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5763 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5764 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5765 | } |
| 5766 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5767 | static uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5768 | lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc, |
| 5769 | uint8_t *page_a0, struct lpfc_vport *vport) |
| 5770 | { |
| 5771 | desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG); |
| 5772 | memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16); |
| 5773 | memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16); |
| 5774 | memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5775 | memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5776 | memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8); |
| 5777 | desc->length = cpu_to_be32(sizeof(desc->opd_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5778 | return sizeof(struct fc_rdp_opd_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5779 | } |
| 5780 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5781 | static uint32_t |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5782 | lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat) |
| 5783 | { |
| 5784 | if (bf_get(lpfc_read_link_stat_gec2, stat) == 0) |
| 5785 | return 0; |
| 5786 | desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG); |
| 5787 | |
| 5788 | desc->info.CorrectedBlocks = |
| 5789 | cpu_to_be32(stat->fecCorrBlkCount); |
| 5790 | desc->info.UncorrectableBlocks = |
| 5791 | cpu_to_be32(stat->fecUncorrBlkCount); |
| 5792 | |
| 5793 | desc->length = cpu_to_be32(sizeof(desc->info)); |
| 5794 | |
| 5795 | return sizeof(struct fc_fec_rdp_desc); |
| 5796 | } |
| 5797 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5798 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5799 | lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba) |
| 5800 | { |
| 5801 | uint16_t rdp_cap = 0; |
| 5802 | uint16_t rdp_speed; |
| 5803 | |
| 5804 | desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG); |
| 5805 | |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5806 | switch (phba->fc_linkspeed) { |
| 5807 | case LPFC_LINK_SPEED_1GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5808 | rdp_speed = RDP_PS_1GB; |
| 5809 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5810 | case LPFC_LINK_SPEED_2GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5811 | rdp_speed = RDP_PS_2GB; |
| 5812 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5813 | case LPFC_LINK_SPEED_4GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5814 | rdp_speed = RDP_PS_4GB; |
| 5815 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5816 | case LPFC_LINK_SPEED_8GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5817 | rdp_speed = RDP_PS_8GB; |
| 5818 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5819 | case LPFC_LINK_SPEED_10GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5820 | rdp_speed = RDP_PS_10GB; |
| 5821 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5822 | case LPFC_LINK_SPEED_16GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5823 | rdp_speed = RDP_PS_16GB; |
| 5824 | break; |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 5825 | case LPFC_LINK_SPEED_32GHZ: |
| 5826 | rdp_speed = RDP_PS_32GB; |
| 5827 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 5828 | case LPFC_LINK_SPEED_64GHZ: |
| 5829 | rdp_speed = RDP_PS_64GB; |
| 5830 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5831 | default: |
| 5832 | rdp_speed = RDP_PS_UNKNOWN; |
| 5833 | break; |
| 5834 | } |
| 5835 | |
| 5836 | desc->info.port_speed.speed = cpu_to_be16(rdp_speed); |
| 5837 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5838 | if (phba->lmt & LMT_128Gb) |
| 5839 | rdp_cap |= RDP_PS_128GB; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 5840 | if (phba->lmt & LMT_64Gb) |
| 5841 | rdp_cap |= RDP_PS_64GB; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 5842 | if (phba->lmt & LMT_32Gb) |
| 5843 | rdp_cap |= RDP_PS_32GB; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5844 | if (phba->lmt & LMT_16Gb) |
| 5845 | rdp_cap |= RDP_PS_16GB; |
| 5846 | if (phba->lmt & LMT_10Gb) |
| 5847 | rdp_cap |= RDP_PS_10GB; |
| 5848 | if (phba->lmt & LMT_8Gb) |
| 5849 | rdp_cap |= RDP_PS_8GB; |
| 5850 | if (phba->lmt & LMT_4Gb) |
| 5851 | rdp_cap |= RDP_PS_4GB; |
| 5852 | if (phba->lmt & LMT_2Gb) |
| 5853 | rdp_cap |= RDP_PS_2GB; |
| 5854 | if (phba->lmt & LMT_1Gb) |
| 5855 | rdp_cap |= RDP_PS_1GB; |
| 5856 | |
| 5857 | if (rdp_cap == 0) |
| 5858 | rdp_cap = RDP_CAP_UNKNOWN; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5859 | if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO) |
| 5860 | rdp_cap |= RDP_CAP_USER_CONFIGURED; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5861 | |
| 5862 | desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap); |
| 5863 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5864 | return sizeof(struct fc_rdp_port_speed_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5865 | } |
| 5866 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5867 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5868 | 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] | 5869 | struct lpfc_vport *vport) |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5870 | { |
| 5871 | |
| 5872 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 5873 | |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 5874 | memcpy(desc->port_names.wwnn, &vport->fc_nodename, |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5875 | sizeof(desc->port_names.wwnn)); |
| 5876 | |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 5877 | memcpy(desc->port_names.wwpn, &vport->fc_portname, |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5878 | sizeof(desc->port_names.wwpn)); |
| 5879 | |
| 5880 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5881 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5882 | } |
| 5883 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5884 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5885 | lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc, |
| 5886 | struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 5887 | { |
| 5888 | |
| 5889 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 5890 | if (vport->fc_flag & FC_FABRIC) { |
| 5891 | memcpy(desc->port_names.wwnn, &vport->fabric_nodename, |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 5892 | sizeof(desc->port_names.wwnn)); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5893 | |
| 5894 | memcpy(desc->port_names.wwpn, &vport->fabric_portname, |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 5895 | sizeof(desc->port_names.wwpn)); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5896 | } else { /* Point to Point */ |
| 5897 | memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename, |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 5898 | sizeof(desc->port_names.wwnn)); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5899 | |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 5900 | memcpy(desc->port_names.wwpn, &ndlp->nlp_portname, |
| 5901 | sizeof(desc->port_names.wwpn)); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5905 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5906 | } |
| 5907 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5908 | static void |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5909 | lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context, |
| 5910 | int status) |
| 5911 | { |
| 5912 | struct lpfc_nodelist *ndlp = rdp_context->ndlp; |
| 5913 | struct lpfc_vport *vport = ndlp->vport; |
| 5914 | struct lpfc_iocbq *elsiocb; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5915 | struct ulp_bde64 *bpl; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5916 | IOCB_t *icmd; |
| 5917 | uint8_t *pcmd; |
| 5918 | struct ls_rjt *stat; |
| 5919 | struct fc_rdp_res_frame *rdp_res; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5920 | uint32_t cmdsize, len; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5921 | uint16_t *flag_ptr; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5922 | int rc; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5923 | |
| 5924 | if (status != SUCCESS) |
| 5925 | goto error; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5926 | |
| 5927 | /* 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] | 5928 | cmdsize = sizeof(struct fc_rdp_res_frame); |
| 5929 | |
| 5930 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, |
| 5931 | lpfc_max_els_tries, rdp_context->ndlp, |
| 5932 | rdp_context->ndlp->nlp_DID, ELS_CMD_ACC); |
| 5933 | lpfc_nlp_put(ndlp); |
| 5934 | if (!elsiocb) |
| 5935 | goto free_rdp_context; |
| 5936 | |
| 5937 | icmd = &elsiocb->iocb; |
| 5938 | icmd->ulpContext = rdp_context->rx_id; |
| 5939 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 5940 | |
| 5941 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5942 | "2171 Xmit RDP response tag x%x xri x%x, " |
| 5943 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x", |
| 5944 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5945 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5946 | ndlp->nlp_rpi); |
| 5947 | rdp_res = (struct fc_rdp_res_frame *) |
| 5948 | (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5949 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5950 | memset(pcmd, 0, sizeof(struct fc_rdp_res_frame)); |
| 5951 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5952 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5953 | /* Update Alarm and Warning */ |
| 5954 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS); |
| 5955 | phba->sfp_alarm |= *flag_ptr; |
| 5956 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS); |
| 5957 | phba->sfp_warning |= *flag_ptr; |
| 5958 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5959 | /* For RDP payload */ |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5960 | len = 8; |
| 5961 | len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *) |
| 5962 | (len + pcmd), ELS_CMD_RDP); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5963 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5964 | 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] | 5965 | rdp_context->page_a0, rdp_context->page_a2); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5966 | len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd), |
| 5967 | phba); |
| 5968 | len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *) |
| 5969 | (len + pcmd), &rdp_context->link_stat); |
| 5970 | 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] | 5971 | (len + pcmd), vport); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5972 | len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *) |
| 5973 | (len + pcmd), vport, ndlp); |
| 5974 | 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] | 5975 | &rdp_context->link_stat); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5976 | len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd), |
| 5977 | &rdp_context->link_stat, vport); |
| 5978 | len += lpfc_rdp_res_oed_temp_desc(phba, |
| 5979 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5980 | rdp_context->page_a2); |
| 5981 | len += lpfc_rdp_res_oed_voltage_desc(phba, |
| 5982 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5983 | rdp_context->page_a2); |
| 5984 | len += lpfc_rdp_res_oed_txbias_desc(phba, |
| 5985 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5986 | rdp_context->page_a2); |
| 5987 | len += lpfc_rdp_res_oed_txpower_desc(phba, |
| 5988 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5989 | rdp_context->page_a2); |
| 5990 | len += lpfc_rdp_res_oed_rxpower_desc(phba, |
| 5991 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5992 | rdp_context->page_a2); |
| 5993 | len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd), |
| 5994 | rdp_context->page_a0, vport); |
| 5995 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5996 | rdp_res->length = cpu_to_be32(len - 8); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5997 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5998 | |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5999 | /* Now that we know the true size of the payload, update the BPL */ |
| 6000 | bpl = (struct ulp_bde64 *) |
| 6001 | (((struct lpfc_dmabuf *)(elsiocb->context3))->virt); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6002 | bpl->tus.f.bdeSize = len; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 6003 | bpl->tus.f.bdeFlags = 0; |
| 6004 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 6005 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6006 | phba->fc_stat.elsXmitACC++; |
| 6007 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6008 | if (rc == IOCB_ERROR) |
| 6009 | lpfc_els_free_iocb(phba, elsiocb); |
| 6010 | |
| 6011 | kfree(rdp_context); |
| 6012 | |
| 6013 | return; |
| 6014 | error: |
| 6015 | cmdsize = 2 * sizeof(uint32_t); |
| 6016 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries, |
| 6017 | ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 6018 | lpfc_nlp_put(ndlp); |
| 6019 | if (!elsiocb) |
| 6020 | goto free_rdp_context; |
| 6021 | |
| 6022 | icmd = &elsiocb->iocb; |
| 6023 | icmd->ulpContext = rdp_context->rx_id; |
| 6024 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 6025 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6026 | |
| 6027 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
| 6028 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 6029 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6030 | |
| 6031 | phba->fc_stat.elsXmitLSRJT++; |
| 6032 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6033 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6034 | |
| 6035 | if (rc == IOCB_ERROR) |
| 6036 | lpfc_els_free_iocb(phba, elsiocb); |
| 6037 | free_rdp_context: |
| 6038 | kfree(rdp_context); |
| 6039 | } |
| 6040 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 6041 | static int |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6042 | lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) |
| 6043 | { |
| 6044 | LPFC_MBOXQ_t *mbox = NULL; |
| 6045 | int rc; |
| 6046 | |
| 6047 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6048 | if (!mbox) { |
| 6049 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, |
| 6050 | "7105 failed to allocate mailbox memory"); |
| 6051 | return 1; |
| 6052 | } |
| 6053 | |
| 6054 | if (lpfc_sli4_dump_page_a0(phba, mbox)) |
| 6055 | goto prep_mbox_fail; |
| 6056 | mbox->vport = rdp_context->ndlp->vport; |
| 6057 | mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6058 | mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6059 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6060 | if (rc == MBX_NOT_FINISHED) |
| 6061 | goto issue_mbox_fail; |
| 6062 | |
| 6063 | return 0; |
| 6064 | |
| 6065 | prep_mbox_fail: |
| 6066 | issue_mbox_fail: |
| 6067 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6068 | return 1; |
| 6069 | } |
| 6070 | |
| 6071 | /* |
| 6072 | * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS. |
| 6073 | * @vport: pointer to a host virtual N_Port data structure. |
| 6074 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6075 | * @ndlp: pointer to a node-list data structure. |
| 6076 | * |
| 6077 | * This routine processes an unsolicited RDP(Read Diagnostic Parameters) |
| 6078 | * IOCB. First, the payload of the unsolicited RDP is checked. |
| 6079 | * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3 |
| 6080 | * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2, |
| 6081 | * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl |
| 6082 | * gather all data and send RDP response. |
| 6083 | * |
| 6084 | * Return code |
| 6085 | * 0 - Sent the acc response |
| 6086 | * 1 - Sent the reject response. |
| 6087 | */ |
| 6088 | static int |
| 6089 | lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6090 | struct lpfc_nodelist *ndlp) |
| 6091 | { |
| 6092 | struct lpfc_hba *phba = vport->phba; |
| 6093 | struct lpfc_dmabuf *pcmd; |
| 6094 | uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE; |
| 6095 | struct fc_rdp_req_frame *rdp_req; |
| 6096 | struct lpfc_rdp_context *rdp_context; |
| 6097 | IOCB_t *cmd = NULL; |
| 6098 | struct ls_rjt stat; |
| 6099 | |
| 6100 | if (phba->sli_rev < LPFC_SLI_REV4 || |
James Smart | 719162b | 2018-12-10 19:37:01 -0800 | [diff] [blame] | 6101 | bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) < |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 6102 | LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6103 | rjt_err = LSRJT_UNABLE_TPC; |
| 6104 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 6105 | goto error; |
| 6106 | } |
| 6107 | |
| 6108 | if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) { |
| 6109 | rjt_err = LSRJT_UNABLE_TPC; |
| 6110 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 6111 | goto error; |
| 6112 | } |
| 6113 | |
| 6114 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6115 | rdp_req = (struct fc_rdp_req_frame *) pcmd->virt; |
| 6116 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6117 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6118 | "2422 ELS RDP Request " |
| 6119 | "dec len %d tag x%x port_id %d len %d\n", |
| 6120 | be32_to_cpu(rdp_req->rdp_des_length), |
| 6121 | be32_to_cpu(rdp_req->nport_id_desc.tag), |
| 6122 | be32_to_cpu(rdp_req->nport_id_desc.nport_id), |
| 6123 | be32_to_cpu(rdp_req->nport_id_desc.length)); |
| 6124 | |
| 6125 | if (sizeof(struct fc_rdp_nport_desc) != |
| 6126 | be32_to_cpu(rdp_req->rdp_des_length)) |
| 6127 | goto rjt_logerr; |
| 6128 | if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag)) |
| 6129 | goto rjt_logerr; |
| 6130 | if (RDP_NPORT_ID_SIZE != |
| 6131 | be32_to_cpu(rdp_req->nport_id_desc.length)) |
| 6132 | goto rjt_logerr; |
Punit Vara | 699acd6 | 2015-12-16 18:12:07 -0500 | [diff] [blame] | 6133 | rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6134 | if (!rdp_context) { |
| 6135 | rjt_err = LSRJT_UNABLE_TPC; |
| 6136 | goto error; |
| 6137 | } |
| 6138 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6139 | cmd = &cmdiocb->iocb; |
| 6140 | rdp_context->ndlp = lpfc_nlp_get(ndlp); |
| 6141 | rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id; |
| 6142 | rdp_context->rx_id = cmd->ulpContext; |
| 6143 | rdp_context->cmpl = lpfc_els_rdp_cmpl; |
| 6144 | if (lpfc_get_rdp_info(phba, rdp_context)) { |
| 6145 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS, |
| 6146 | "2423 Unable to send mailbox"); |
| 6147 | kfree(rdp_context); |
| 6148 | rjt_err = LSRJT_UNABLE_TPC; |
| 6149 | lpfc_nlp_put(ndlp); |
| 6150 | goto error; |
| 6151 | } |
| 6152 | |
| 6153 | return 0; |
| 6154 | |
| 6155 | rjt_logerr: |
| 6156 | rjt_err = LSRJT_LOGICAL_ERR; |
| 6157 | |
| 6158 | error: |
| 6159 | memset(&stat, 0, sizeof(stat)); |
| 6160 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 6161 | stat.un.b.lsRjtRsnCodeExp = rjt_expl; |
| 6162 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6163 | return 1; |
| 6164 | } |
| 6165 | |
| 6166 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6167 | static void |
| 6168 | lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6169 | { |
| 6170 | MAILBOX_t *mb; |
| 6171 | IOCB_t *icmd; |
| 6172 | uint8_t *pcmd; |
| 6173 | struct lpfc_iocbq *elsiocb; |
| 6174 | struct lpfc_nodelist *ndlp; |
| 6175 | struct ls_rjt *stat; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 6176 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6177 | struct lpfc_lcb_context *lcb_context; |
| 6178 | struct fc_lcb_res_frame *lcb_res; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 6179 | uint32_t cmdsize, shdr_status, shdr_add_status; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6180 | int rc; |
| 6181 | |
| 6182 | mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6183 | lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6184 | ndlp = lcb_context->ndlp; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6185 | pmb->ctx_ndlp = NULL; |
| 6186 | pmb->ctx_buf = NULL; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6187 | |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 6188 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6189 | &pmb->u.mqe.un.beacon_config.header.cfg_shdr; |
| 6190 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6191 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6192 | |
| 6193 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX, |
| 6194 | "0194 SET_BEACON_CONFIG mailbox " |
| 6195 | "completed with status x%x add_status x%x," |
| 6196 | " mbx status x%x\n", |
| 6197 | shdr_status, shdr_add_status, mb->mbxStatus); |
| 6198 | |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6199 | if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status || |
| 6200 | (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) || |
| 6201 | (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6202 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6203 | goto error; |
| 6204 | } |
| 6205 | |
| 6206 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6207 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 6208 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6209 | lpfc_max_els_tries, ndlp, |
| 6210 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6211 | |
| 6212 | /* Decrement the ndlp reference count from previous mbox command */ |
| 6213 | lpfc_nlp_put(ndlp); |
| 6214 | |
| 6215 | if (!elsiocb) |
| 6216 | goto free_lcb_context; |
| 6217 | |
| 6218 | lcb_res = (struct fc_lcb_res_frame *) |
| 6219 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 6220 | |
James Smart | 24bc311 | 2018-07-31 17:23:23 -0700 | [diff] [blame] | 6221 | memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame)); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6222 | icmd = &elsiocb->iocb; |
| 6223 | icmd->ulpContext = lcb_context->rx_id; |
| 6224 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 6225 | |
| 6226 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 6227 | *((uint32_t *)(pcmd)) = ELS_CMD_ACC; |
| 6228 | lcb_res->lcb_sub_command = lcb_context->sub_command; |
| 6229 | lcb_res->lcb_type = lcb_context->type; |
James Smart | 24bc311 | 2018-07-31 17:23:23 -0700 | [diff] [blame] | 6230 | lcb_res->capability = lcb_context->capability; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6231 | lcb_res->lcb_frequency = lcb_context->frequency; |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6232 | lcb_res->lcb_duration = lcb_context->duration; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6233 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6234 | phba->fc_stat.elsXmitACC++; |
| 6235 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6236 | if (rc == IOCB_ERROR) |
| 6237 | lpfc_els_free_iocb(phba, elsiocb); |
| 6238 | |
| 6239 | kfree(lcb_context); |
| 6240 | return; |
| 6241 | |
| 6242 | error: |
| 6243 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 6244 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6245 | lpfc_max_els_tries, ndlp, |
| 6246 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 6247 | lpfc_nlp_put(ndlp); |
| 6248 | if (!elsiocb) |
| 6249 | goto free_lcb_context; |
| 6250 | |
| 6251 | icmd = &elsiocb->iocb; |
| 6252 | icmd->ulpContext = lcb_context->rx_id; |
| 6253 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 6254 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 6255 | |
| 6256 | *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT; |
| 6257 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 6258 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6259 | |
James Smart | b114d90 | 2018-10-23 13:41:07 -0700 | [diff] [blame] | 6260 | if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) |
| 6261 | stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS; |
| 6262 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6263 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6264 | phba->fc_stat.elsXmitLSRJT++; |
| 6265 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6266 | if (rc == IOCB_ERROR) |
| 6267 | lpfc_els_free_iocb(phba, elsiocb); |
| 6268 | free_lcb_context: |
| 6269 | kfree(lcb_context); |
| 6270 | } |
| 6271 | |
| 6272 | static int |
| 6273 | lpfc_sli4_set_beacon(struct lpfc_vport *vport, |
| 6274 | struct lpfc_lcb_context *lcb_context, |
| 6275 | uint32_t beacon_state) |
| 6276 | { |
| 6277 | struct lpfc_hba *phba = vport->phba; |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6278 | union lpfc_sli4_cfg_shdr *cfg_shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6279 | LPFC_MBOXQ_t *mbox = NULL; |
| 6280 | uint32_t len; |
| 6281 | int rc; |
| 6282 | |
| 6283 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6284 | if (!mbox) |
| 6285 | return 1; |
| 6286 | |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6287 | cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6288 | len = sizeof(struct lpfc_mbx_set_beacon_config) - |
| 6289 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6290 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6291 | LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len, |
| 6292 | LPFC_SLI4_MBX_EMBED); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6293 | mbox->ctx_ndlp = (void *)lcb_context; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6294 | mbox->vport = phba->pport; |
| 6295 | mbox->mbox_cmpl = lpfc_els_lcb_rsp; |
| 6296 | bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config, |
| 6297 | phba->sli4_hba.physical_port); |
| 6298 | bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config, |
| 6299 | beacon_state); |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6300 | mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */ |
| 6301 | |
| 6302 | /* |
| 6303 | * Check bv1s bit before issuing the mailbox |
| 6304 | * if bv1s == 1, LCB V1 supported |
| 6305 | * else, LCB V0 supported |
| 6306 | */ |
| 6307 | |
| 6308 | if (phba->sli4_hba.pc_sli4_params.bv1s) { |
| 6309 | /* COMMON_SET_BEACON_CONFIG_V1 */ |
| 6310 | cfg_shdr->request.word9 = BEACON_VERSION_V1; |
| 6311 | lcb_context->capability |= LCB_CAPABILITY_DURATION; |
| 6312 | bf_set(lpfc_mbx_set_beacon_port_type, |
| 6313 | &mbox->u.mqe.un.beacon_config, 0); |
| 6314 | bf_set(lpfc_mbx_set_beacon_duration_v1, |
| 6315 | &mbox->u.mqe.un.beacon_config, |
| 6316 | be16_to_cpu(lcb_context->duration)); |
| 6317 | } else { |
| 6318 | /* COMMON_SET_BEACON_CONFIG_V0 */ |
| 6319 | if (be16_to_cpu(lcb_context->duration) != 0) { |
| 6320 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6321 | return 1; |
| 6322 | } |
| 6323 | cfg_shdr->request.word9 = BEACON_VERSION_V0; |
| 6324 | lcb_context->capability &= ~(LCB_CAPABILITY_DURATION); |
| 6325 | bf_set(lpfc_mbx_set_beacon_state, |
| 6326 | &mbox->u.mqe.un.beacon_config, beacon_state); |
| 6327 | bf_set(lpfc_mbx_set_beacon_port_type, |
| 6328 | &mbox->u.mqe.un.beacon_config, 1); |
| 6329 | bf_set(lpfc_mbx_set_beacon_duration, |
| 6330 | &mbox->u.mqe.un.beacon_config, |
| 6331 | be16_to_cpu(lcb_context->duration)); |
| 6332 | } |
| 6333 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6334 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6335 | if (rc == MBX_NOT_FINISHED) { |
| 6336 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6337 | return 1; |
| 6338 | } |
| 6339 | |
| 6340 | return 0; |
| 6341 | } |
| 6342 | |
| 6343 | |
| 6344 | /** |
| 6345 | * lpfc_els_rcv_lcb - Process an unsolicited LCB |
| 6346 | * @vport: pointer to a host virtual N_Port data structure. |
| 6347 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6348 | * @ndlp: pointer to a node-list data structure. |
| 6349 | * |
| 6350 | * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB. |
| 6351 | * First, the payload of the unsolicited LCB is checked. |
| 6352 | * Then based on Subcommand beacon will either turn on or off. |
| 6353 | * |
| 6354 | * Return code |
| 6355 | * 0 - Sent the acc response |
| 6356 | * 1 - Sent the reject response. |
| 6357 | **/ |
| 6358 | static int |
| 6359 | lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6360 | struct lpfc_nodelist *ndlp) |
| 6361 | { |
| 6362 | struct lpfc_hba *phba = vport->phba; |
| 6363 | struct lpfc_dmabuf *pcmd; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6364 | uint8_t *lp; |
| 6365 | struct fc_lcb_request_frame *beacon; |
| 6366 | struct lpfc_lcb_context *lcb_context; |
| 6367 | uint8_t state, rjt_err; |
| 6368 | struct ls_rjt stat; |
| 6369 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6370 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 6371 | lp = (uint8_t *)pcmd->virt; |
| 6372 | beacon = (struct fc_lcb_request_frame *)pcmd->virt; |
| 6373 | |
| 6374 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6375 | "0192 ELS LCB Data x%x x%x x%x x%x sub x%x " |
| 6376 | "type x%x frequency %x duration x%x\n", |
| 6377 | lp[0], lp[1], lp[2], |
| 6378 | beacon->lcb_command, |
| 6379 | beacon->lcb_sub_command, |
| 6380 | beacon->lcb_type, |
| 6381 | beacon->lcb_frequency, |
| 6382 | be16_to_cpu(beacon->lcb_duration)); |
| 6383 | |
James Smart | d6564e5 | 2017-06-15 22:56:50 -0700 | [diff] [blame] | 6384 | if (beacon->lcb_sub_command != LPFC_LCB_ON && |
| 6385 | beacon->lcb_sub_command != LPFC_LCB_OFF) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6386 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 6387 | goto rjt; |
| 6388 | } |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6389 | |
| 6390 | if (phba->sli_rev < LPFC_SLI_REV4 || |
| 6391 | phba->hba_flag & HBA_FCOE_MODE || |
| 6392 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) < |
| 6393 | LPFC_SLI_INTF_IF_TYPE_2)) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6394 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 6395 | goto rjt; |
| 6396 | } |
| 6397 | |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 6398 | lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL); |
| 6399 | if (!lcb_context) { |
| 6400 | rjt_err = LSRJT_UNABLE_TPC; |
| 6401 | goto rjt; |
| 6402 | } |
| 6403 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6404 | state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; |
| 6405 | lcb_context->sub_command = beacon->lcb_sub_command; |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6406 | lcb_context->capability = 0; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6407 | lcb_context->type = beacon->lcb_type; |
| 6408 | lcb_context->frequency = beacon->lcb_frequency; |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6409 | lcb_context->duration = beacon->lcb_duration; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6410 | lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
| 6411 | lcb_context->rx_id = cmdiocb->iocb.ulpContext; |
| 6412 | lcb_context->ndlp = lpfc_nlp_get(ndlp); |
| 6413 | if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { |
| 6414 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 6415 | LOG_ELS, "0193 failed to send mail box"); |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 6416 | kfree(lcb_context); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6417 | lpfc_nlp_put(ndlp); |
| 6418 | rjt_err = LSRJT_UNABLE_TPC; |
| 6419 | goto rjt; |
| 6420 | } |
| 6421 | return 0; |
| 6422 | rjt: |
| 6423 | memset(&stat, 0, sizeof(stat)); |
| 6424 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 6425 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6426 | return 1; |
| 6427 | } |
| 6428 | |
| 6429 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6430 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6431 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6432 | * @vport: pointer to a host virtual N_Port data structure. |
| 6433 | * |
| 6434 | * This routine cleans up any Registration State Change Notification |
| 6435 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 6436 | * @vport together with the host_lock is used to prevent multiple thread |
| 6437 | * trying to access the RSCN array on a same @vport at the same time. |
| 6438 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6439 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6440 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6441 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6442 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6443 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6444 | int i; |
| 6445 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6446 | spin_lock_irq(shost->host_lock); |
| 6447 | if (vport->fc_rscn_flush) { |
| 6448 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 6449 | spin_unlock_irq(shost->host_lock); |
| 6450 | return; |
| 6451 | } |
| 6452 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 6453 | vport->fc_rscn_flush = 1; |
| 6454 | spin_unlock_irq(shost->host_lock); |
| 6455 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6456 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6457 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6458 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6459 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6460 | spin_lock_irq(shost->host_lock); |
| 6461 | vport->fc_rscn_id_cnt = 0; |
| 6462 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 6463 | spin_unlock_irq(shost->host_lock); |
| 6464 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6465 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 6466 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6467 | } |
| 6468 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6469 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6470 | * 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] | 6471 | * @vport: pointer to a host virtual N_Port data structure. |
| 6472 | * @did: remote destination port identifier. |
| 6473 | * |
| 6474 | * This routine checks whether there is any pending Registration State |
| 6475 | * Configuration Notification (RSCN) to a @did on @vport. |
| 6476 | * |
| 6477 | * Return code |
| 6478 | * None zero - The @did matched with a pending rscn |
| 6479 | * 0 - not able to match @did with a pending rscn |
| 6480 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6481 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6482 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6483 | { |
| 6484 | D_ID ns_did; |
| 6485 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6486 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6487 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6488 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6489 | |
| 6490 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6491 | |
| 6492 | /* Never match fabric nodes for RSCNs */ |
| 6493 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6494 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6495 | |
| 6496 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6497 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6498 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6499 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6500 | spin_lock_irq(shost->host_lock); |
| 6501 | if (vport->fc_rscn_flush) { |
| 6502 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 6503 | spin_unlock_irq(shost->host_lock); |
| 6504 | return 0; |
| 6505 | } |
| 6506 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 6507 | vport->fc_rscn_flush = 1; |
| 6508 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6509 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6510 | lp = vport->fc_rscn_id_list[i]->virt; |
| 6511 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 6512 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6513 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6514 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 6515 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 6516 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 6517 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6518 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 6519 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 6520 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6521 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6522 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 6523 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6524 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 6525 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6526 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6527 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 6528 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6529 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6530 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6531 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 6532 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6533 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6534 | } |
| 6535 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6536 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6537 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 6538 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6539 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6540 | return_did_out: |
| 6541 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 6542 | vport->fc_rscn_flush = 0; |
| 6543 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6544 | } |
| 6545 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6546 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6547 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6548 | * @vport: pointer to a host virtual N_Port data structure. |
| 6549 | * |
| 6550 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 6551 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 6552 | * State Change Notification). |
| 6553 | * |
| 6554 | * Return code |
| 6555 | * 0 - Successful (currently alway return 0) |
| 6556 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6557 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6558 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6559 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6560 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6561 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6562 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6563 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6564 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6565 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 6566 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6567 | continue; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6568 | |
| 6569 | /* NVME Target mode does not do RSCN Recovery. */ |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 6570 | if (vport->phba->nvmet_support) |
| 6571 | continue; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6572 | |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 6573 | /* If we are in the process of doing discovery on this |
| 6574 | * NPort, let it continue on its own. |
| 6575 | */ |
| 6576 | switch (ndlp->nlp_state) { |
| 6577 | case NLP_STE_PLOGI_ISSUE: |
| 6578 | case NLP_STE_ADISC_ISSUE: |
| 6579 | case NLP_STE_REG_LOGIN_ISSUE: |
| 6580 | case NLP_STE_PRLI_ISSUE: |
| 6581 | case NLP_STE_LOGO_ISSUE: |
| 6582 | continue; |
| 6583 | } |
| 6584 | |
James Smart | a6d10f2 | 2019-08-14 16:56:50 -0700 | [diff] [blame] | 6585 | /* Check to see if we need to NVME rescan this target |
| 6586 | * remoteport. |
| 6587 | */ |
| 6588 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME && |
| 6589 | ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) |
James Smart | 6f2589f | 2019-05-14 14:58:07 -0700 | [diff] [blame] | 6590 | lpfc_nvme_rescan_port(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 6591 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6592 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6593 | NLP_EVT_DEVICE_RECOVERY); |
| 6594 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6595 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6596 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6597 | } |
| 6598 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6599 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6600 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6601 | * @vport: pointer to a host virtual N_Port data structure. |
| 6602 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6603 | * |
| 6604 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 6605 | * applications. |
| 6606 | */ |
| 6607 | static void |
| 6608 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 6609 | struct lpfc_iocbq *cmdiocb) |
| 6610 | { |
| 6611 | struct lpfc_dmabuf *pcmd; |
| 6612 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6613 | uint32_t *payload_ptr; |
| 6614 | uint32_t payload_len; |
| 6615 | struct lpfc_rscn_event_header *rscn_event_data; |
| 6616 | |
| 6617 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6618 | payload_ptr = (uint32_t *) pcmd->virt; |
| 6619 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 6620 | |
| 6621 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 6622 | payload_len, GFP_KERNEL); |
| 6623 | if (!rscn_event_data) { |
| 6624 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6625 | "0147 Failed to allocate memory for RSCN event\n"); |
| 6626 | return; |
| 6627 | } |
| 6628 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 6629 | rscn_event_data->payload_length = payload_len; |
| 6630 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 6631 | payload_len); |
| 6632 | |
| 6633 | fc_host_post_vendor_event(shost, |
| 6634 | fc_get_event_number(), |
Ales Novak | 6599eaa | 2015-08-31 16:48:16 -0400 | [diff] [blame] | 6635 | sizeof(struct lpfc_rscn_event_header) + payload_len, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6636 | (char *)rscn_event_data, |
| 6637 | LPFC_NL_VENDOR_ID); |
| 6638 | |
| 6639 | kfree(rscn_event_data); |
| 6640 | } |
| 6641 | |
| 6642 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6643 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6644 | * @vport: pointer to a host virtual N_Port data structure. |
| 6645 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6646 | * @ndlp: pointer to a node-list data structure. |
| 6647 | * |
| 6648 | * This routine processes an unsolicited RSCN (Registration State Change |
| 6649 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 6650 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 6651 | * discover state machine is about to begin discovery, it just accepts the |
| 6652 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 6653 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 6654 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 6655 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 6656 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 6657 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 6658 | * routine is invoked to handle the RSCN event. |
| 6659 | * |
| 6660 | * Return code |
| 6661 | * 0 - Just sent the acc response |
| 6662 | * 1 - Sent the acc response and waited for name server completion |
| 6663 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6664 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6665 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6666 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6667 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6668 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6669 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6670 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6671 | uint32_t *lp, *datap; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6672 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6673 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6674 | int rscn_id = 0, hba_id = 0; |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 6675 | int i, tmo; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6676 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6677 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6678 | lp = (uint32_t *) pcmd->virt; |
| 6679 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6680 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 6681 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6682 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6683 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6684 | "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] | 6685 | vport->fc_flag, payload_len, *lp, |
| 6686 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6687 | |
| 6688 | /* Send an RSCN event to the management application */ |
| 6689 | lpfc_send_rscn_event(vport, cmdiocb); |
| 6690 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 6691 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6692 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 6693 | FCH_EVT_RSCN, lp[i]); |
| 6694 | |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 6695 | /* Check if RSCN is coming from a direct-connected remote NPort */ |
| 6696 | if (vport->fc_flag & FC_PT2PT) { |
| 6697 | /* If so, just ACC it, no other action needed for now */ |
| 6698 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6699 | "2024 pt2pt RSCN %08x Data: x%x x%x\n", |
| 6700 | *lp, vport->fc_flag, payload_len); |
| 6701 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 6f2589f | 2019-05-14 14:58:07 -0700 | [diff] [blame] | 6702 | |
James Smart | a6d10f2 | 2019-08-14 16:56:50 -0700 | [diff] [blame] | 6703 | /* Check to see if we need to NVME rescan this target |
| 6704 | * remoteport. |
| 6705 | */ |
| 6706 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME && |
| 6707 | ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) |
James Smart | 6f2589f | 2019-05-14 14:58:07 -0700 | [diff] [blame] | 6708 | lpfc_nvme_rescan_port(vport, ndlp); |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 6709 | return 0; |
| 6710 | } |
| 6711 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6712 | /* If we are about to begin discovery, just ACC the RSCN. |
| 6713 | * Discovery processing will satisfy it. |
| 6714 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6715 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6716 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6717 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 6718 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6719 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6720 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6721 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6722 | } |
| 6723 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6724 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 6725 | * just ACC and ignore it. |
| 6726 | */ |
| 6727 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6728 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6729 | i = payload_len; |
| 6730 | datap = lp; |
| 6731 | while (i > 0) { |
| 6732 | nportid = *datap++; |
| 6733 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 6734 | i -= sizeof(uint32_t); |
| 6735 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6736 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 6737 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6738 | } |
| 6739 | if (rscn_id == hba_id) { |
| 6740 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6741 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6742 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6743 | "Data: x%x x%x x%x x%x\n", |
| 6744 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6745 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6746 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6747 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 6748 | ndlp->nlp_DID, vport->port_state, |
| 6749 | ndlp->nlp_flag); |
| 6750 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6751 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6752 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6753 | return 0; |
| 6754 | } |
| 6755 | } |
| 6756 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6757 | spin_lock_irq(shost->host_lock); |
| 6758 | if (vport->fc_rscn_flush) { |
| 6759 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6760 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 6761 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6762 | /* Send back ACC */ |
| 6763 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6764 | return 0; |
| 6765 | } |
| 6766 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 6767 | vport->fc_rscn_flush = 1; |
| 6768 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6769 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6770 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6771 | /* If we are already processing an RSCN, save the received |
| 6772 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 6773 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6774 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6775 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6776 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 6777 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6778 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6779 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6780 | vport->fc_flag |= FC_RSCN_DEFERRED; |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 6781 | |
| 6782 | /* Restart disctmo if its already running */ |
| 6783 | if (vport->fc_flag & FC_DISC_TMO) { |
| 6784 | tmo = ((phba->fc_ratov * 3) + 3); |
| 6785 | mod_timer(&vport->fc_disctmo, |
| 6786 | jiffies + msecs_to_jiffies(1000 * tmo)); |
| 6787 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6788 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6789 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6790 | vport->fc_flag |= FC_RSCN_MODE; |
| 6791 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6792 | if (rscn_cnt) { |
| 6793 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 6794 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 6795 | } |
| 6796 | if ((rscn_cnt) && |
| 6797 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 6798 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6799 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6800 | memcpy(((uint8_t *)cmd) + length, lp, |
| 6801 | payload_len); |
| 6802 | } else { |
| 6803 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 6804 | vport->fc_rscn_id_cnt++; |
| 6805 | /* If we zero, cmdiocb->context2, the calling |
| 6806 | * routine will not try to free it. |
| 6807 | */ |
| 6808 | cmdiocb->context2 = NULL; |
| 6809 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6810 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6811 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6812 | "0235 Deferred RSCN " |
| 6813 | "Data: x%x x%x x%x\n", |
| 6814 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 6815 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6816 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6817 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 6818 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6819 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6820 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6821 | "0234 ReDiscovery RSCN " |
| 6822 | "Data: x%x x%x x%x\n", |
| 6823 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 6824 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6825 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6826 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 6827 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6828 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6829 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6830 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6831 | lpfc_rscn_recovery_check(vport); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6832 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6833 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6834 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6835 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 6836 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6837 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6838 | spin_lock_irq(shost->host_lock); |
| 6839 | vport->fc_flag |= FC_RSCN_MODE; |
| 6840 | spin_unlock_irq(shost->host_lock); |
| 6841 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6842 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 6843 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6844 | /* |
| 6845 | * If we zero, cmdiocb->context2, the calling routine will |
| 6846 | * not try to free it. |
| 6847 | */ |
| 6848 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6849 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6850 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6851 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6852 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6853 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6854 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6855 | } |
| 6856 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6857 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6858 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6859 | * @vport: pointer to a host virtual N_Port data structure. |
| 6860 | * |
| 6861 | * This routine handles the Registration State Configuration Notification |
| 6862 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 6863 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 6864 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 6865 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 6866 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 6867 | * RSCN activities with the @vport. |
| 6868 | * |
| 6869 | * Return code |
| 6870 | * 0 - Cleaned up rscn on the @vport |
| 6871 | * 1 - Wait for plogi to name server before proceed |
| 6872 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6873 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6874 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6875 | { |
| 6876 | struct lpfc_nodelist *ndlp; |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 6877 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6878 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6879 | /* Ignore RSCN if the port is being torn down. */ |
| 6880 | if (vport->load_flag & FC_UNLOADING) { |
| 6881 | lpfc_els_flush_rscn(vport); |
| 6882 | return 0; |
| 6883 | } |
| 6884 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6885 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6886 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6887 | |
| 6888 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6889 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 6890 | "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] | 6891 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 6892 | vport->port_state, vport->num_disc_nodes, |
| 6893 | vport->gidft_inp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6894 | |
| 6895 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6896 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 6897 | vport->num_disc_nodes = 0; |
| 6898 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6899 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6900 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 6901 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6902 | /* Good ndlp, issue CT Request to NameServer. Need to |
| 6903 | * know how many gidfts were issued. If none, then just |
| 6904 | * flush the RSCN. Otherwise, the outstanding requests |
| 6905 | * need to complete. |
| 6906 | */ |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 6907 | if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) { |
| 6908 | if (lpfc_issue_gidft(vport) > 0) |
| 6909 | return 1; |
| 6910 | } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) { |
| 6911 | if (lpfc_issue_gidpt(vport) > 0) |
| 6912 | return 1; |
| 6913 | } else { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6914 | return 1; |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 6915 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6916 | } else { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6917 | /* Nameserver login in question. Revalidate. */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6918 | if (ndlp) { |
| 6919 | ndlp = lpfc_enable_node(vport, ndlp, |
| 6920 | NLP_STE_PLOGI_ISSUE); |
| 6921 | if (!ndlp) { |
| 6922 | lpfc_els_flush_rscn(vport); |
| 6923 | return 0; |
| 6924 | } |
| 6925 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6926 | } else { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6927 | ndlp = lpfc_nlp_init(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6928 | if (!ndlp) { |
| 6929 | lpfc_els_flush_rscn(vport); |
| 6930 | return 0; |
| 6931 | } |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6932 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6933 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6934 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6935 | ndlp->nlp_type |= NLP_FABRIC; |
| 6936 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 6937 | /* Wait for NameServer login cmpl before we can |
| 6938 | * continue |
| 6939 | */ |
| 6940 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6941 | } |
| 6942 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6943 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6944 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6945 | } |
| 6946 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6947 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6948 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6949 | * @vport: pointer to a host virtual N_Port data structure. |
| 6950 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6951 | * @ndlp: pointer to a node-list data structure. |
| 6952 | * |
| 6953 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 6954 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 6955 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 6956 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 6957 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 6958 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 6959 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 6960 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 6961 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 6962 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 6963 | * higher priority (as the winning port) and will initiate PLOGI and |
| 6964 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 6965 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 6966 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 6967 | * |
| 6968 | * Return code |
| 6969 | * 0 - Successfully processed the unsolicited flogi |
| 6970 | * 1 - Failed to process the unsolicited flogi |
| 6971 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6972 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6973 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6974 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6975 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6976 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6977 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6978 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6979 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 6980 | IOCB_t *icmd = &cmdiocb->iocb; |
| 6981 | struct serv_parm *sp; |
| 6982 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6983 | uint32_t cmd, did; |
| 6984 | int rc; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6985 | uint32_t fc_flag = 0; |
| 6986 | uint32_t port_state = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6987 | |
| 6988 | cmd = *lp++; |
| 6989 | sp = (struct serv_parm *) lp; |
| 6990 | |
| 6991 | /* FLOGI received */ |
| 6992 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6993 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6994 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6995 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6996 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 6997 | did = icmd->un.elsreq64.remoteID; |
| 6998 | |
| 6999 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 7000 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7001 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7002 | "0113 An FLOGI ELS command x%x was " |
| 7003 | "received from DID x%x in Loop Mode\n", |
| 7004 | cmd, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7005 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7006 | } |
| 7007 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7008 | (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7009 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7010 | /* |
| 7011 | * If our portname is greater than the remote portname, |
| 7012 | * then we initiate Nport login. |
| 7013 | */ |
| 7014 | |
| 7015 | rc = memcmp(&vport->fc_portname, &sp->portName, |
| 7016 | sizeof(struct lpfc_name)); |
| 7017 | |
| 7018 | if (!rc) { |
| 7019 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 7020 | mbox = mempool_alloc(phba->mbox_mem_pool, |
| 7021 | GFP_KERNEL); |
| 7022 | if (!mbox) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7023 | return 1; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7024 | lpfc_linkdown(phba); |
| 7025 | lpfc_init_link(phba, mbox, |
| 7026 | phba->cfg_topology, |
| 7027 | phba->cfg_link_speed); |
| 7028 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 7029 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 7030 | mbox->vport = vport; |
| 7031 | rc = lpfc_sli_issue_mbox(phba, mbox, |
| 7032 | MBX_NOWAIT); |
| 7033 | lpfc_set_loopback_flag(phba); |
| 7034 | if (rc == MBX_NOT_FINISHED) |
| 7035 | mempool_free(mbox, phba->mbox_mem_pool); |
| 7036 | return 1; |
| 7037 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7038 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7039 | /* abort the flogi coming back to ourselves |
| 7040 | * due to external loopback on the port. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7041 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7042 | lpfc_els_abort_flogi(phba); |
| 7043 | return 0; |
| 7044 | |
| 7045 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7046 | spin_lock_irq(shost->host_lock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7047 | vport->fc_flag |= FC_PT2PT_PLOGI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7048 | spin_unlock_irq(shost->host_lock); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7049 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7050 | /* If we have the high WWPN we can assign our own |
| 7051 | * myDID; otherwise, we have to WAIT for a PLOGI |
| 7052 | * from the remote NPort to find out what it |
| 7053 | * will be. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7054 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7055 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7056 | } else { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7057 | vport->fc_myDID = PT2PT_RemoteID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7058 | } |
| 7059 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7060 | /* |
| 7061 | * The vport state should go to LPFC_FLOGI only |
| 7062 | * AFTER we issue a FLOGI, not receive one. |
| 7063 | */ |
| 7064 | spin_lock_irq(shost->host_lock); |
| 7065 | fc_flag = vport->fc_flag; |
| 7066 | port_state = vport->port_state; |
| 7067 | vport->fc_flag |= FC_PT2PT; |
| 7068 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 7069 | |
| 7070 | /* Acking an unsol FLOGI. Count 1 for link bounce |
| 7071 | * work-around. |
| 7072 | */ |
| 7073 | vport->rcv_flogi_cnt++; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7074 | spin_unlock_irq(shost->host_lock); |
| 7075 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7076 | "3311 Rcv Flogi PS x%x new PS x%x " |
| 7077 | "fc_flag x%x new fc_flag x%x\n", |
| 7078 | port_state, vport->port_state, |
| 7079 | fc_flag, vport->fc_flag); |
| 7080 | |
| 7081 | /* |
| 7082 | * We temporarily set fc_myDID to make it look like we are |
| 7083 | * a Fabric. This is done just so we end up with the right |
| 7084 | * did / sid on the FLOGI ACC rsp. |
| 7085 | */ |
| 7086 | did = vport->fc_myDID; |
| 7087 | vport->fc_myDID = Fabric_DID; |
| 7088 | |
| 7089 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7090 | |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 7091 | /* Defer ACC response until AFTER we issue a FLOGI */ |
| 7092 | if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) { |
| 7093 | phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext; |
| 7094 | phba->defer_flogi_acc_ox_id = |
| 7095 | cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
| 7096 | |
| 7097 | vport->fc_myDID = did; |
| 7098 | |
| 7099 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7100 | "3344 Deferring FLOGI ACC: rx_id: x%x," |
| 7101 | " ox_id: x%x, hba_flag x%x\n", |
| 7102 | phba->defer_flogi_acc_rx_id, |
| 7103 | phba->defer_flogi_acc_ox_id, phba->hba_flag); |
| 7104 | |
| 7105 | phba->defer_flogi_acc_flag = true; |
| 7106 | |
| 7107 | return 0; |
| 7108 | } |
| 7109 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7110 | /* Send back ACC */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7111 | lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7112 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7113 | /* Now lets put fc_myDID back to what its supposed to be */ |
| 7114 | vport->fc_myDID = did; |
| 7115 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7116 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7117 | } |
| 7118 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7119 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7120 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7121 | * @vport: pointer to a host virtual N_Port data structure. |
| 7122 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7123 | * @ndlp: pointer to a node-list data structure. |
| 7124 | * |
| 7125 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 7126 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 7127 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 7128 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 7129 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 7130 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 7131 | * |
| 7132 | * Return code |
| 7133 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 7134 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7135 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7136 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7137 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7138 | { |
| 7139 | struct lpfc_dmabuf *pcmd; |
| 7140 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7141 | RNID *rn; |
| 7142 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7143 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7144 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7145 | lp = (uint32_t *) pcmd->virt; |
| 7146 | |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7147 | lp++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7148 | rn = (RNID *) lp; |
| 7149 | |
| 7150 | /* RNID received */ |
| 7151 | |
| 7152 | switch (rn->Format) { |
| 7153 | case 0: |
| 7154 | case RNID_TOPOLOGY_DISC: |
| 7155 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7156 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7157 | break; |
| 7158 | default: |
| 7159 | /* Reject this request because format not supported */ |
| 7160 | stat.un.b.lsRjtRsvd0 = 0; |
| 7161 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7162 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7163 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7164 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 7165 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7166 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7167 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7168 | } |
| 7169 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7170 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7171 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 7172 | * @vport: pointer to a host virtual N_Port data structure. |
| 7173 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7174 | * @ndlp: pointer to a node-list data structure. |
| 7175 | * |
| 7176 | * Return code |
| 7177 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 7178 | **/ |
| 7179 | static int |
| 7180 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7181 | struct lpfc_nodelist *ndlp) |
| 7182 | { |
| 7183 | uint8_t *pcmd; |
| 7184 | |
| 7185 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 7186 | |
| 7187 | /* skip over first word of echo command to find echo data */ |
| 7188 | pcmd += sizeof(uint32_t); |
| 7189 | |
| 7190 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 7191 | return 0; |
| 7192 | } |
| 7193 | |
| 7194 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7195 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7196 | * @vport: pointer to a host virtual N_Port data structure. |
| 7197 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7198 | * @ndlp: pointer to a node-list data structure. |
| 7199 | * |
| 7200 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 7201 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 7202 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 7203 | * |
| 7204 | * Return code |
| 7205 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 7206 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7207 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7208 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7209 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7210 | { |
| 7211 | struct ls_rjt stat; |
| 7212 | |
| 7213 | /* For now, unconditionally reject this command */ |
| 7214 | stat.un.b.lsRjtRsvd0 = 0; |
| 7215 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7216 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7217 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7218 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7219 | return 0; |
| 7220 | } |
| 7221 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7222 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7223 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 7224 | * @vport: pointer to a host virtual N_Port data structure. |
| 7225 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7226 | * @ndlp: pointer to a node-list data structure. |
| 7227 | * |
| 7228 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 7229 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 7230 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 7231 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 7232 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 7233 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 7234 | * command request" and reason code explanation "Invalid Originator |
| 7235 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 7236 | * RRQ from the target. |
| 7237 | **/ |
| 7238 | static void |
| 7239 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7240 | struct lpfc_nodelist *ndlp) |
| 7241 | { |
| 7242 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7243 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 7244 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7245 | } |
| 7246 | |
| 7247 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7248 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 7249 | * @phba: pointer to lpfc hba data structure. |
| 7250 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 7251 | * |
| 7252 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 7253 | * mailbox command. This callback function is to actually send the Accept |
| 7254 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 7255 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 7256 | * mailbox command, constructs the RPS response with the link statistics |
| 7257 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 7258 | * response to the RPS. |
| 7259 | * |
| 7260 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7261 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7262 | * will be stored into the context1 field of the IOCB for the completion |
| 7263 | * callback function to the RPS Accept Response ELS IOCB command. |
| 7264 | * |
| 7265 | **/ |
| 7266 | static void |
| 7267 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 7268 | { |
| 7269 | MAILBOX_t *mb; |
| 7270 | IOCB_t *icmd; |
| 7271 | struct RLS_RSP *rls_rsp; |
| 7272 | uint8_t *pcmd; |
| 7273 | struct lpfc_iocbq *elsiocb; |
| 7274 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7275 | uint16_t oxid; |
| 7276 | uint16_t rxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7277 | uint32_t cmdsize; |
| 7278 | |
| 7279 | mb = &pmb->u.mb; |
| 7280 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7281 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 7282 | rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff); |
| 7283 | oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff); |
| 7284 | pmb->ctx_buf = NULL; |
| 7285 | pmb->ctx_ndlp = NULL; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7286 | |
| 7287 | if (mb->mbxStatus) { |
| 7288 | mempool_free(pmb, phba->mbox_mem_pool); |
| 7289 | return; |
| 7290 | } |
| 7291 | |
| 7292 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7293 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 7294 | lpfc_max_els_tries, ndlp, |
| 7295 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 7296 | |
| 7297 | /* Decrement the ndlp reference count from previous mbox command */ |
| 7298 | lpfc_nlp_put(ndlp); |
| 7299 | |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 7300 | if (!elsiocb) { |
| 7301 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7302 | return; |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 7303 | } |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7304 | |
| 7305 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7306 | icmd->ulpContext = rxid; |
| 7307 | icmd->unsli3.rcvsli3.ox_id = oxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7308 | |
| 7309 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7310 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 7311 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 7312 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 7313 | |
| 7314 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 7315 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 7316 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 7317 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 7318 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 7319 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 7320 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7321 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 7322 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 7323 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 7324 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 7325 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 7326 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 7327 | ndlp->nlp_rpi); |
| 7328 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 7329 | phba->fc_stat.elsXmitACC++; |
| 7330 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 7331 | lpfc_els_free_iocb(phba, elsiocb); |
| 7332 | } |
| 7333 | |
| 7334 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7335 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 7336 | * @vport: pointer to a host virtual N_Port data structure. |
| 7337 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7338 | * @ndlp: pointer to a node-list data structure. |
| 7339 | * |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7340 | * This routine processes Read Link Status (RLS) IOCB received as an |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7341 | * ELS unsolicited event. It first checks the remote port state. If the |
| 7342 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 7343 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 7344 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 7345 | * for reading the HBA link statistics. It is for the callback function, |
| 7346 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 7347 | * to actually sending out RPL Accept (ACC) response. |
| 7348 | * |
| 7349 | * Return codes |
| 7350 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 7351 | **/ |
| 7352 | static int |
| 7353 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7354 | struct lpfc_nodelist *ndlp) |
| 7355 | { |
| 7356 | struct lpfc_hba *phba = vport->phba; |
| 7357 | LPFC_MBOXQ_t *mbox; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7358 | struct ls_rjt stat; |
| 7359 | |
| 7360 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 7361 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7362 | /* reject the unsolicited RLS request and done with it */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7363 | goto reject_out; |
| 7364 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7365 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 7366 | if (mbox) { |
| 7367 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7368 | mbox->ctx_buf = (void *)((unsigned long) |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7369 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 7370 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7371 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7372 | mbox->vport = vport; |
| 7373 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 7374 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 7375 | != MBX_NOT_FINISHED) |
| 7376 | /* Mbox completion will send ELS Response */ |
| 7377 | return 0; |
| 7378 | /* Decrement reference count used for the failed mbox |
| 7379 | * command. |
| 7380 | */ |
| 7381 | lpfc_nlp_put(ndlp); |
| 7382 | mempool_free(mbox, phba->mbox_mem_pool); |
| 7383 | } |
| 7384 | reject_out: |
| 7385 | /* issue rejection response */ |
| 7386 | stat.un.b.lsRjtRsvd0 = 0; |
| 7387 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7388 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7389 | stat.un.b.vendorUnique = 0; |
| 7390 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 7391 | return 0; |
| 7392 | } |
| 7393 | |
| 7394 | /** |
| 7395 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 7396 | * @vport: pointer to a host virtual N_Port data structure. |
| 7397 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7398 | * @ndlp: pointer to a node-list data structure. |
| 7399 | * |
| 7400 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 7401 | * ELS unsolicited event. It first checks the remote port state. If the |
| 7402 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 7403 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 7404 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 7405 | * Value (RTV) unsolicited IOCB event. |
| 7406 | * |
| 7407 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7408 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7409 | * 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] | 7410 | * callback function to the RTV Accept Response ELS IOCB command. |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7411 | * |
| 7412 | * Return codes |
| 7413 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 7414 | **/ |
| 7415 | static int |
| 7416 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7417 | struct lpfc_nodelist *ndlp) |
| 7418 | { |
| 7419 | struct lpfc_hba *phba = vport->phba; |
| 7420 | struct ls_rjt stat; |
| 7421 | struct RTV_RSP *rtv_rsp; |
| 7422 | uint8_t *pcmd; |
| 7423 | struct lpfc_iocbq *elsiocb; |
| 7424 | uint32_t cmdsize; |
| 7425 | |
| 7426 | |
| 7427 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 7428 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7429 | /* reject the unsolicited RTV request and done with it */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7430 | goto reject_out; |
| 7431 | |
| 7432 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 7433 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 7434 | lpfc_max_els_tries, ndlp, |
| 7435 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 7436 | |
| 7437 | if (!elsiocb) |
| 7438 | return 1; |
| 7439 | |
| 7440 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
Colin Ian King | 8fd03fd | 2017-12-22 00:39:36 +0000 | [diff] [blame] | 7441 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7442 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 7443 | |
| 7444 | /* use the command's xri in the response */ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7445 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 7446 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7447 | |
| 7448 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 7449 | |
| 7450 | /* populate RTV payload */ |
| 7451 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 7452 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 7453 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 7454 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 7455 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 7456 | |
| 7457 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 7458 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 7459 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 7460 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 7461 | "Data: x%x x%x x%x\n", |
| 7462 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 7463 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 7464 | ndlp->nlp_rpi, |
| 7465 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 7466 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 7467 | phba->fc_stat.elsXmitACC++; |
| 7468 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 7469 | lpfc_els_free_iocb(phba, elsiocb); |
| 7470 | return 0; |
| 7471 | |
| 7472 | reject_out: |
| 7473 | /* issue rejection response */ |
| 7474 | stat.un.b.lsRjtRsvd0 = 0; |
| 7475 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7476 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7477 | stat.un.b.vendorUnique = 0; |
| 7478 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 7479 | return 0; |
| 7480 | } |
| 7481 | |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7482 | /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7483 | * @vport: pointer to a host virtual N_Port data structure. |
| 7484 | * @ndlp: pointer to a node-list data structure. |
| 7485 | * @did: DID of the target. |
| 7486 | * @rrq: Pointer to the rrq struct. |
| 7487 | * |
| 7488 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is |
| 7489 | * Successful the the completion handler will clear the RRQ. |
| 7490 | * |
| 7491 | * Return codes |
| 7492 | * 0 - Successfully sent rrq els iocb. |
| 7493 | * 1 - Failed to send rrq els iocb. |
| 7494 | **/ |
| 7495 | static int |
| 7496 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 7497 | uint32_t did, struct lpfc_node_rrq *rrq) |
| 7498 | { |
| 7499 | struct lpfc_hba *phba = vport->phba; |
| 7500 | struct RRQ *els_rrq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7501 | struct lpfc_iocbq *elsiocb; |
| 7502 | uint8_t *pcmd; |
| 7503 | uint16_t cmdsize; |
| 7504 | int ret; |
| 7505 | |
| 7506 | |
| 7507 | if (ndlp != rrq->ndlp) |
| 7508 | ndlp = rrq->ndlp; |
| 7509 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 7510 | return 1; |
| 7511 | |
| 7512 | /* If ndlp is not NULL, we will bump the reference count on it */ |
| 7513 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); |
| 7514 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, |
| 7515 | ELS_CMD_RRQ); |
| 7516 | if (!elsiocb) |
| 7517 | return 1; |
| 7518 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7519 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7520 | |
| 7521 | /* For RRQ request, remainder of payload is Exchange IDs */ |
| 7522 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; |
| 7523 | pcmd += sizeof(uint32_t); |
| 7524 | els_rrq = (struct RRQ *) pcmd; |
| 7525 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 7526 | 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] | 7527 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
| 7528 | bf_set(rrq_did, els_rrq, vport->fc_myDID); |
| 7529 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); |
| 7530 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); |
| 7531 | |
| 7532 | |
| 7533 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7534 | "Issue RRQ: did:x%x", |
| 7535 | did, rrq->xritag, rrq->rxid); |
| 7536 | elsiocb->context_un.rrq = rrq; |
| 7537 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; |
| 7538 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 7539 | |
| 7540 | if (ret == IOCB_ERROR) { |
| 7541 | lpfc_els_free_iocb(phba, elsiocb); |
| 7542 | return 1; |
| 7543 | } |
| 7544 | return 0; |
| 7545 | } |
| 7546 | |
| 7547 | /** |
| 7548 | * lpfc_send_rrq - Sends ELS RRQ if needed. |
| 7549 | * @phba: pointer to lpfc hba data structure. |
| 7550 | * @rrq: pointer to the active rrq. |
| 7551 | * |
| 7552 | * This routine will call the lpfc_issue_els_rrq if the rrq is |
| 7553 | * still active for the xri. If this function returns a failure then |
| 7554 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. |
| 7555 | * |
| 7556 | * Returns 0 Success. |
| 7557 | * 1 Failure. |
| 7558 | **/ |
| 7559 | int |
| 7560 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) |
| 7561 | { |
| 7562 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, |
James Smart | c8cb261 | 2019-05-06 17:26:49 -0700 | [diff] [blame] | 7563 | rrq->nlp_DID); |
| 7564 | if (!ndlp) |
| 7565 | return 1; |
| 7566 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7567 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) |
| 7568 | return lpfc_issue_els_rrq(rrq->vport, ndlp, |
| 7569 | rrq->nlp_DID, rrq); |
| 7570 | else |
| 7571 | return 1; |
| 7572 | } |
| 7573 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7574 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7575 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7576 | * @vport: pointer to a host virtual N_Port data structure. |
| 7577 | * @cmdsize: size of the ELS command. |
| 7578 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 7579 | * @ndlp: pointer to a node-list data structure. |
| 7580 | * |
| 7581 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 7582 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 7583 | * |
| 7584 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7585 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7586 | * will be stored into the context1 field of the IOCB for the completion |
| 7587 | * callback function to the RPL Accept Response ELS command. |
| 7588 | * |
| 7589 | * Return code |
| 7590 | * 0 - Successfully issued ACC RPL ELS command |
| 7591 | * 1 - Failed to issue ACC RPL ELS command |
| 7592 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 7593 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7594 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 7595 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7596 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7597 | struct lpfc_hba *phba = vport->phba; |
| 7598 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7599 | RPL_RSP rpl_rsp; |
| 7600 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7601 | uint8_t *pcmd; |
| 7602 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7603 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 7604 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7605 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 7606 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7607 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 7608 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7609 | icmd = &elsiocb->iocb; |
| 7610 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7611 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 7612 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7613 | |
| 7614 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7615 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7616 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7617 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 7618 | pcmd += sizeof(uint16_t); |
| 7619 | |
| 7620 | /* Setup the RPL ACC payload */ |
| 7621 | rpl_rsp.listLen = be32_to_cpu(1); |
| 7622 | rpl_rsp.index = 0; |
| 7623 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7624 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 7625 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7626 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7627 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7628 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7629 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7630 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 7631 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 7632 | "rpi x%x\n", |
| 7633 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 7634 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 7635 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7636 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7637 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7638 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 7639 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7640 | lpfc_els_free_iocb(phba, elsiocb); |
| 7641 | return 1; |
| 7642 | } |
| 7643 | return 0; |
| 7644 | } |
| 7645 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7646 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7647 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7648 | * @vport: pointer to a host virtual N_Port data structure. |
| 7649 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7650 | * @ndlp: pointer to a node-list data structure. |
| 7651 | * |
| 7652 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 7653 | * unsolicited event. It first checks the remote port state. If the remote |
| 7654 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 7655 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 7656 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 7657 | * to accept the RPL. |
| 7658 | * |
| 7659 | * Return code |
| 7660 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 7661 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7662 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7663 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7664 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7665 | { |
| 7666 | struct lpfc_dmabuf *pcmd; |
| 7667 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7668 | uint32_t maxsize; |
| 7669 | uint16_t cmdsize; |
| 7670 | RPL *rpl; |
| 7671 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7672 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 7673 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 7674 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 7675 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7676 | stat.un.b.lsRjtRsvd0 = 0; |
| 7677 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7678 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7679 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7680 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 7681 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 7682 | /* rejected the unsolicited RPL request and done with it */ |
| 7683 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7684 | } |
| 7685 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7686 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7687 | lp = (uint32_t *) pcmd->virt; |
| 7688 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7689 | maxsize = be32_to_cpu(rpl->maxsize); |
| 7690 | |
| 7691 | /* We support only one port */ |
| 7692 | if ((rpl->index == 0) && |
| 7693 | ((maxsize == 0) || |
| 7694 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 7695 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 7696 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7697 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 7698 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7699 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7700 | |
| 7701 | return 0; |
| 7702 | } |
| 7703 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7704 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7705 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7706 | * @vport: pointer to a virtual N_Port data structure. |
| 7707 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7708 | * @ndlp: pointer to a node-list data structure. |
| 7709 | * |
| 7710 | * This routine processes Fibre Channel Address Resolution Protocol |
| 7711 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 7712 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 7713 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 7714 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 7715 | * remote PortName is compared against the FC PortName stored in the @vport |
| 7716 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 7717 | * compared against the FC NodeName stored in the @vport data structure. |
| 7718 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 7719 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 7720 | * invoked to send out FARP Response to the remote node. Before sending the |
| 7721 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 7722 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 7723 | * routine is invoked to log into the remote port first. |
| 7724 | * |
| 7725 | * Return code |
| 7726 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 7727 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7728 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7729 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7730 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7731 | { |
| 7732 | struct lpfc_dmabuf *pcmd; |
| 7733 | uint32_t *lp; |
| 7734 | IOCB_t *icmd; |
| 7735 | FARP *fp; |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7736 | uint32_t cnt, did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7737 | |
| 7738 | icmd = &cmdiocb->iocb; |
| 7739 | did = icmd->un.elsreq64.remoteID; |
| 7740 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7741 | lp = (uint32_t *) pcmd->virt; |
| 7742 | |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7743 | lp++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7744 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7745 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7746 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7747 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7748 | /* We will only support match on WWPN or WWNN */ |
| 7749 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7750 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7751 | } |
| 7752 | |
| 7753 | cnt = 0; |
| 7754 | /* If this FARP command is searching for my portname */ |
| 7755 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7756 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7757 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7758 | cnt = 1; |
| 7759 | } |
| 7760 | |
| 7761 | /* If this FARP command is searching for my nodename */ |
| 7762 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7763 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7764 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7765 | cnt = 1; |
| 7766 | } |
| 7767 | |
| 7768 | if (cnt) { |
| 7769 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 7770 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 7771 | /* Log back into the node before sending the FARP. */ |
| 7772 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7773 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7774 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 7775 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7776 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7777 | } |
| 7778 | |
| 7779 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7780 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 7781 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7782 | } |
| 7783 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7784 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7785 | } |
| 7786 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7787 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7788 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7789 | * @vport: pointer to a host virtual N_Port data structure. |
| 7790 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7791 | * @ndlp: pointer to a node-list data structure. |
| 7792 | * |
| 7793 | * This routine processes Fibre Channel Address Resolution Protocol |
| 7794 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 7795 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 7796 | * the FARP response request. |
| 7797 | * |
| 7798 | * Return code |
| 7799 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 7800 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7801 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7802 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7803 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7804 | { |
| 7805 | struct lpfc_dmabuf *pcmd; |
| 7806 | uint32_t *lp; |
| 7807 | IOCB_t *icmd; |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7808 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7809 | |
| 7810 | icmd = &cmdiocb->iocb; |
| 7811 | did = icmd->un.elsreq64.remoteID; |
| 7812 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7813 | lp = (uint32_t *) pcmd->virt; |
| 7814 | |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7815 | lp++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7816 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7817 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7818 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7819 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7820 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7821 | |
| 7822 | return 0; |
| 7823 | } |
| 7824 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7825 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7826 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7827 | * @vport: pointer to a host virtual N_Port data structure. |
| 7828 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7829 | * @fan_ndlp: pointer to a node-list data structure. |
| 7830 | * |
| 7831 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 7832 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 7833 | * only be processed on a physical port (i.e., the @vport represents the |
| 7834 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 7835 | * compared against those in the phba data structure. If any of those is |
| 7836 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 7837 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 7838 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 7839 | * is invoked to register login to the fabric. |
| 7840 | * |
| 7841 | * Return code |
| 7842 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 7843 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7844 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7845 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7846 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7847 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7848 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7849 | uint32_t *lp; |
| 7850 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7851 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7852 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 7853 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 7854 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7855 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7856 | if ((vport == phba->pport) && |
| 7857 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7858 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7859 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7860 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7861 | sizeof(struct lpfc_name)))) { |
| 7862 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7863 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7864 | } else { |
| 7865 | /* FAN verified - skip FLOGI */ |
| 7866 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7867 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 7868 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7869 | else { |
| 7870 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7871 | "3138 Need register VFI: (x%x/%x)\n", |
| 7872 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7873 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7874 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7875 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7876 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7877 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7878 | } |
| 7879 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7880 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7881 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7882 | * @ptr: holder for the timer function associated data. |
| 7883 | * |
| 7884 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 7885 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 7886 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 7887 | * up the worker thread. It is for the worker thread to invoke the routine |
| 7888 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 7889 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7890 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7891 | lpfc_els_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7892 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7893 | struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7894 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7895 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7896 | unsigned long iflag; |
| 7897 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7898 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7899 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7900 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7901 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7902 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7903 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7904 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7905 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7906 | return; |
| 7907 | } |
| 7908 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7909 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7910 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7911 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7912 | * @vport: pointer to a virtual N_Port data structure. |
| 7913 | * |
| 7914 | * This routine is the actual handler function that processes an ELS timeout |
| 7915 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 7916 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 7917 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 7918 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7919 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7920 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7921 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7922 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7923 | struct lpfc_sli_ring *pring; |
| 7924 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7925 | IOCB_t *cmd = NULL; |
| 7926 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7927 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7928 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7929 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7930 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7931 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7932 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7933 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 7934 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7935 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 7936 | if (unlikely(!pring)) |
| 7937 | return; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7938 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7939 | if ((phba->pport->load_flag & FC_UNLOADING)) |
| 7940 | return; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7941 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7942 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7943 | spin_lock(&pring->ring_lock); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7944 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7945 | if ((phba->pport->load_flag & FC_UNLOADING)) { |
| 7946 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7947 | spin_unlock(&pring->ring_lock); |
| 7948 | spin_unlock_irq(&phba->hbalock); |
| 7949 | return; |
| 7950 | } |
| 7951 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7952 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7953 | cmd = &piocb->iocb; |
| 7954 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7955 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 7956 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 7957 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7958 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7959 | |
| 7960 | if (piocb->vport != vport) |
| 7961 | continue; |
| 7962 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7963 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7964 | if (pcmd) |
| 7965 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7966 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7967 | if (els_command == ELS_CMD_FARP || |
| 7968 | els_command == ELS_CMD_FARPR || |
| 7969 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7970 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7971 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7972 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7973 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7974 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7975 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7976 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7977 | continue; |
| 7978 | } |
| 7979 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7980 | remote_ID = 0xffffffff; |
| 7981 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7982 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7983 | else { |
| 7984 | struct lpfc_nodelist *ndlp; |
| 7985 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7986 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7987 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7988 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7989 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7990 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7991 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7992 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7993 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 7994 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7995 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
James Smart | 15026c9 | 2013-12-17 20:30:09 -0500 | [diff] [blame] | 7996 | cmd = &piocb->iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7997 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7998 | "0127 ELS timeout Data: x%x x%x x%x " |
| 7999 | "x%x\n", els_command, |
| 8000 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 8001 | spin_lock_irq(&phba->hbalock); |
| 8002 | list_del_init(&piocb->dlist); |
| 8003 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 8004 | spin_unlock_irq(&phba->hbalock); |
| 8005 | } |
| 8006 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8007 | if (!list_empty(&pring->txcmplq)) |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 8008 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 8009 | mod_timer(&vport->els_tmofunc, |
| 8010 | jiffies + msecs_to_jiffies(1000 * timeout)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8011 | } |
| 8012 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8013 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8014 | * 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] | 8015 | * @vport: pointer to a host virtual N_Port data structure. |
| 8016 | * |
| 8017 | * This routine is used to clean up all the outstanding ELS commands on a |
| 8018 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 8019 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 8020 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 8021 | * the IOCBs with a non-NULL completion callback function, the callback |
| 8022 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 8023 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 8024 | * callback function, the IOCB will simply be released. Finally, it walks |
| 8025 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 8026 | * completion queue IOCB that is associated with the @vport and is not |
| 8027 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 8028 | * part of the discovery state machine) out to HBA by invoking the |
| 8029 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 8030 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 8031 | * the IOCBs are aborted when this function returns. |
| 8032 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8033 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8034 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8035 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8036 | LIST_HEAD(abort_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8037 | struct lpfc_hba *phba = vport->phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8038 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8039 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 8040 | IOCB_t *cmd = NULL; |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8041 | unsigned long iflags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8042 | |
| 8043 | lpfc_fabric_abort_vport(vport); |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8044 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8045 | /* |
| 8046 | * For SLI3, only the hbalock is required. But SLI4 needs to coordinate |
| 8047 | * with the ring insert operation. Because lpfc_sli_issue_abort_iotag |
| 8048 | * ultimately grabs the ring_lock, the driver must splice the list into |
| 8049 | * a working list and release the locks before calling the abort. |
| 8050 | */ |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8051 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8052 | pring = lpfc_phba_elsring(phba); |
Guilherme G. Piccoli | 53cf29d | 2017-05-17 19:02:17 -0300 | [diff] [blame] | 8053 | |
| 8054 | /* Bail out if we've no ELS wq, like in PCI error recovery case. */ |
| 8055 | if (unlikely(!pring)) { |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8056 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
Guilherme G. Piccoli | 53cf29d | 2017-05-17 19:02:17 -0300 | [diff] [blame] | 8057 | return; |
| 8058 | } |
| 8059 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8060 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8061 | spin_lock(&pring->ring_lock); |
| 8062 | |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8063 | /* First we need to issue aborts to outstanding cmds on txcmpl */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8064 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 8065 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 8066 | continue; |
| 8067 | |
| 8068 | if (piocb->vport != vport) |
| 8069 | continue; |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8070 | |
James Smart | 15498dc | 2019-09-21 20:58:59 -0700 | [diff] [blame] | 8071 | if (piocb->iocb_flag & LPFC_DRIVER_ABORTED) |
| 8072 | continue; |
| 8073 | |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8074 | /* On the ELS ring we can have ELS_REQUESTs or |
| 8075 | * GEN_REQUESTs waiting for a response. |
| 8076 | */ |
| 8077 | cmd = &piocb->iocb; |
| 8078 | if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| 8079 | list_add_tail(&piocb->dlist, &abort_list); |
| 8080 | |
| 8081 | /* If the link is down when flushing ELS commands |
| 8082 | * the firmware will not complete them till after |
| 8083 | * the link comes back up. This may confuse |
| 8084 | * discovery for the new link up, so we need to |
| 8085 | * change the compl routine to just clean up the iocb |
| 8086 | * and avoid any retry logic. |
| 8087 | */ |
| 8088 | if (phba->link_state == LPFC_LINK_DOWN) |
| 8089 | piocb->iocb_cmpl = lpfc_cmpl_els_link_down; |
| 8090 | } |
| 8091 | if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) |
| 8092 | list_add_tail(&piocb->dlist, &abort_list); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8093 | } |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8094 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8095 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8096 | spin_unlock(&pring->ring_lock); |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8097 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8098 | |
| 8099 | /* Abort each txcmpl iocb on aborted list and remove the dlist links. */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8100 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8101 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8102 | list_del_init(&piocb->dlist); |
| 8103 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8104 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8105 | } |
| 8106 | if (!list_empty(&abort_list)) |
| 8107 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8108 | "3387 abort list for txq not empty\n"); |
| 8109 | INIT_LIST_HEAD(&abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8110 | |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8111 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8112 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8113 | spin_lock(&pring->ring_lock); |
| 8114 | |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8115 | /* No need to abort the txq list, |
| 8116 | * just queue them up for lpfc_sli_cancel_iocbs |
| 8117 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8118 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 8119 | cmd = &piocb->iocb; |
| 8120 | |
| 8121 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 8122 | continue; |
| 8123 | } |
| 8124 | |
| 8125 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 8126 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 8127 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 8128 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 8129 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8130 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8131 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8132 | if (piocb->vport != vport) |
| 8133 | continue; |
| 8134 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8135 | list_del_init(&piocb->list); |
| 8136 | list_add_tail(&piocb->list, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8137 | } |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8138 | |
| 8139 | /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */ |
| 8140 | if (vport == phba->pport) { |
| 8141 | list_for_each_entry_safe(piocb, tmp_iocb, |
| 8142 | &phba->fabric_iocb_list, list) { |
| 8143 | cmd = &piocb->iocb; |
| 8144 | list_del_init(&piocb->list); |
| 8145 | list_add_tail(&piocb->list, &abort_list); |
| 8146 | } |
| 8147 | } |
| 8148 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8149 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8150 | spin_unlock(&pring->ring_lock); |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8151 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 8152 | |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8153 | /* Cancel all the IOCBs from the completions list */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8154 | lpfc_sli_cancel_iocbs(phba, &abort_list, |
| 8155 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 8156 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8157 | return; |
| 8158 | } |
| 8159 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8160 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8161 | * 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] | 8162 | * @phba: pointer to lpfc hba data structure. |
| 8163 | * |
| 8164 | * This routine is used to clean up all the outstanding ELS commands on a |
| 8165 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 8166 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 8167 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 8168 | * the IOCBs with the completion callback function associated, the callback |
| 8169 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 8170 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 8171 | * callback function associated, the IOCB will simply be released. Finally, |
| 8172 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 8173 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 8174 | * management plane IOCBs that are not part of the discovery state machine) |
| 8175 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 8176 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 8177 | void |
| 8178 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 8179 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8180 | struct lpfc_vport *vport; |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 8181 | |
| 8182 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8183 | list_for_each_entry(vport, &phba->port_list, listentry) |
| 8184 | lpfc_els_flush_cmd(vport); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 8185 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8186 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 8187 | return; |
| 8188 | } |
| 8189 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8190 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8191 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8192 | * @phba: Pointer to hba context object. |
| 8193 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 8194 | * @rspiocbp: Pointer to response iocb which reported error. |
| 8195 | * |
| 8196 | * This function sends an event when there is an ELS command |
| 8197 | * failure. |
| 8198 | **/ |
| 8199 | void |
| 8200 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 8201 | struct lpfc_iocbq *cmdiocbp, |
| 8202 | struct lpfc_iocbq *rspiocbp) |
| 8203 | { |
| 8204 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 8205 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8206 | struct lpfc_lsrjt_event lsrjt_event; |
| 8207 | struct lpfc_fabric_event_header fabric_event; |
| 8208 | struct ls_rjt stat; |
| 8209 | struct lpfc_nodelist *ndlp; |
| 8210 | uint32_t *pcmd; |
| 8211 | |
| 8212 | ndlp = cmdiocbp->context1; |
| 8213 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 8214 | return; |
| 8215 | |
| 8216 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 8217 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 8218 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 8219 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 8220 | sizeof(struct lpfc_name)); |
| 8221 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 8222 | sizeof(struct lpfc_name)); |
| 8223 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8224 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 8225 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8226 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 8227 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 8228 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 8229 | fc_host_post_vendor_event(shost, |
| 8230 | fc_get_event_number(), |
| 8231 | sizeof(lsrjt_event), |
| 8232 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8233 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8234 | return; |
| 8235 | } |
| 8236 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 8237 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 8238 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 8239 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 8240 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 8241 | else |
| 8242 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 8243 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 8244 | sizeof(struct lpfc_name)); |
| 8245 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 8246 | sizeof(struct lpfc_name)); |
| 8247 | fc_host_post_vendor_event(shost, |
| 8248 | fc_get_event_number(), |
| 8249 | sizeof(fabric_event), |
| 8250 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8251 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8252 | return; |
| 8253 | } |
| 8254 | |
| 8255 | } |
| 8256 | |
| 8257 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8258 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8259 | * @vport: Pointer to vport object. |
| 8260 | * @ndlp: Pointer FC node object. |
| 8261 | * @cmd: ELS command code. |
| 8262 | * |
| 8263 | * This function posts an event when there is an incoming |
| 8264 | * unsolicited ELS command. |
| 8265 | **/ |
| 8266 | static void |
| 8267 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 8268 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8269 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8270 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8271 | struct lpfc_els_event_header *els_data = NULL; |
| 8272 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8273 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8274 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8275 | if (*payload == ELS_CMD_LOGO) { |
| 8276 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 8277 | if (!logo_data) { |
| 8278 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8279 | "0148 Failed to allocate memory " |
| 8280 | "for LOGO event\n"); |
| 8281 | return; |
| 8282 | } |
| 8283 | els_data = &logo_data->header; |
| 8284 | } else { |
| 8285 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 8286 | GFP_KERNEL); |
| 8287 | if (!els_data) { |
| 8288 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8289 | "0149 Failed to allocate memory " |
| 8290 | "for ELS event\n"); |
| 8291 | return; |
| 8292 | } |
| 8293 | } |
| 8294 | els_data->event_type = FC_REG_ELS_EVENT; |
| 8295 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8296 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8297 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8298 | break; |
| 8299 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8300 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8301 | break; |
| 8302 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8303 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 8304 | break; |
| 8305 | case ELS_CMD_LOGO: |
| 8306 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 8307 | /* Copy the WWPN in the LOGO payload */ |
| 8308 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 8309 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8310 | break; |
| 8311 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 8312 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8313 | return; |
| 8314 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8315 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 8316 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 8317 | if (*payload == ELS_CMD_LOGO) { |
| 8318 | fc_host_post_vendor_event(shost, |
| 8319 | fc_get_event_number(), |
| 8320 | sizeof(struct lpfc_logo_event), |
| 8321 | (char *)logo_data, |
| 8322 | LPFC_NL_VENDOR_ID); |
| 8323 | kfree(logo_data); |
| 8324 | } else { |
| 8325 | fc_host_post_vendor_event(shost, |
| 8326 | fc_get_event_number(), |
| 8327 | sizeof(struct lpfc_els_event_header), |
| 8328 | (char *)els_data, |
| 8329 | LPFC_NL_VENDOR_ID); |
| 8330 | kfree(els_data); |
| 8331 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8332 | |
| 8333 | return; |
| 8334 | } |
| 8335 | |
| 8336 | |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8337 | DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag, |
| 8338 | FC_LS_TLV_DTAG_INIT); |
| 8339 | |
| 8340 | DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types, |
| 8341 | FC_FPIN_LI_EVT_TYPES_INIT); |
| 8342 | |
| 8343 | /** |
| 8344 | * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event. |
| 8345 | * @vport: Pointer to vport object. |
| 8346 | * @lnk_not: Pointer to the Link Integrity Notification Descriptor. |
| 8347 | * |
| 8348 | * This function processes a link integrity FPIN event by |
| 8349 | * logging a message |
| 8350 | **/ |
| 8351 | static void |
| 8352 | lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv) |
| 8353 | { |
| 8354 | struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv; |
| 8355 | const char *li_evt_str; |
| 8356 | u32 li_evt; |
| 8357 | |
| 8358 | li_evt = be16_to_cpu(li->event_type); |
| 8359 | li_evt_str = lpfc_get_fpin_li_event_nm(li_evt); |
| 8360 | |
| 8361 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8362 | "4680 FPIN Link Integrity %s (x%x) " |
| 8363 | "Detecting PN x%016llx Attached PN x%016llx " |
| 8364 | "Duration %d mSecs Count %d Port Cnt %d\n", |
| 8365 | li_evt_str, li_evt, |
| 8366 | be64_to_cpu(li->detecting_wwpn), |
| 8367 | be64_to_cpu(li->attached_wwpn), |
| 8368 | be32_to_cpu(li->event_threshold), |
| 8369 | be32_to_cpu(li->event_count), |
| 8370 | be32_to_cpu(li->pname_count)); |
| 8371 | } |
| 8372 | |
| 8373 | static void |
| 8374 | lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin, |
| 8375 | u32 fpin_length) |
| 8376 | { |
| 8377 | struct fc_tlv_desc *tlv; |
| 8378 | const char *dtag_nm; |
| 8379 | uint32_t desc_cnt = 0, bytes_remain; |
| 8380 | u32 dtag; |
| 8381 | |
| 8382 | /* FPINs handled only if we are in the right discovery state */ |
| 8383 | if (vport->port_state < LPFC_DISC_AUTH) |
| 8384 | return; |
| 8385 | |
| 8386 | /* make sure there is the full fpin header */ |
| 8387 | if (fpin_length < sizeof(struct fc_els_fpin)) |
| 8388 | return; |
| 8389 | |
| 8390 | tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0]; |
| 8391 | bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc); |
| 8392 | bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len)); |
| 8393 | |
| 8394 | /* process each descriptor */ |
| 8395 | while (bytes_remain >= FC_TLV_DESC_HDR_SZ && |
| 8396 | bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) { |
| 8397 | |
| 8398 | dtag = be32_to_cpu(tlv->desc_tag); |
| 8399 | switch (dtag) { |
| 8400 | case ELS_DTAG_LNK_INTEGRITY: |
| 8401 | lpfc_els_rcv_fpin_li(vport, tlv); |
| 8402 | break; |
| 8403 | default: |
| 8404 | dtag_nm = lpfc_get_tlv_dtag_nm(dtag); |
| 8405 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8406 | "4678 skipped FPIN descriptor[%d]: " |
| 8407 | "tag x%x (%s)\n", |
| 8408 | desc_cnt, dtag, dtag_nm); |
| 8409 | break; |
| 8410 | } |
| 8411 | |
| 8412 | desc_cnt++; |
| 8413 | bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv); |
| 8414 | tlv = fc_tlv_next_desc(tlv); |
| 8415 | } |
| 8416 | |
| 8417 | fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length, |
| 8418 | (char *)fpin); |
| 8419 | } |
| 8420 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8421 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8422 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8423 | * @phba: pointer to lpfc hba data structure. |
| 8424 | * @pring: pointer to a SLI ring. |
| 8425 | * @vport: pointer to a host virtual N_Port data structure. |
| 8426 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 8427 | * |
| 8428 | * This routine is used for processing the IOCB associated with a unsolicited |
| 8429 | * event. It first determines whether there is an existing ndlp that matches |
| 8430 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 8431 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 8432 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 8433 | * of the discovery state machine. |
| 8434 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8435 | static void |
| 8436 | 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] | 8437 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8438 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8439 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8440 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8441 | struct ls_rjt stat; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8442 | uint32_t *payload, payload_len; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8443 | uint32_t cmd, did, newnode; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 8444 | uint8_t rjt_exp, rjt_err = 0, init_link = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8445 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 8446 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8447 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8448 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8449 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8450 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8451 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8452 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8453 | payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8454 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8455 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 8456 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8457 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8458 | did = icmd->un.rcvels.remoteID; |
| 8459 | if (icmd->ulpStatus) { |
| 8460 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8461 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 8462 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8463 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8464 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8465 | |
| 8466 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8467 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8468 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8469 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8470 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8471 | if (vport->load_flag & FC_UNLOADING) |
| 8472 | goto dropit; |
| 8473 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8474 | /* If NPort discovery is delayed drop incoming ELS */ |
| 8475 | if ((vport->fc_flag & FC_DISC_DELAYED) && |
| 8476 | (cmd != ELS_CMD_PLOGI)) |
| 8477 | goto dropit; |
| 8478 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8479 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 8480 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8481 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 8482 | ndlp = lpfc_nlp_init(vport, did); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8483 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8484 | goto dropit; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8485 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8486 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8487 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8488 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8489 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 8490 | ndlp = lpfc_enable_node(vport, ndlp, |
| 8491 | NLP_STE_UNUSED_NODE); |
| 8492 | if (!ndlp) |
| 8493 | goto dropit; |
| 8494 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 8495 | newnode = 1; |
| 8496 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 8497 | ndlp->nlp_type |= NLP_FABRIC; |
| 8498 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 8499 | /* This is similar to the new node path */ |
| 8500 | ndlp = lpfc_nlp_get(ndlp); |
| 8501 | if (!ndlp) |
| 8502 | goto dropit; |
| 8503 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 8504 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8505 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8506 | |
| 8507 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8508 | |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 8509 | /* |
| 8510 | * Do not process any unsolicited ELS commands |
| 8511 | * if the ndlp is in DEV_LOSS |
| 8512 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 8513 | shost = lpfc_shost_from_vport(vport); |
| 8514 | spin_lock_irq(shost->host_lock); |
| 8515 | if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) { |
| 8516 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 8517 | goto dropit; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 8518 | } |
| 8519 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 8520 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 8521 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8522 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8523 | |
| 8524 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 8525 | cmd &= ELS_CMD_MASK; |
| 8526 | } |
| 8527 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8528 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8529 | "0112 ELS command x%x received from NPORT x%x " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 8530 | "Data: x%x x%x x%x x%x\n", |
| 8531 | cmd, did, vport->port_state, vport->fc_flag, |
| 8532 | vport->fc_myDID, vport->fc_prevDID); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8533 | |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 8534 | /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */ |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8535 | if ((vport->port_state < LPFC_FABRIC_CFG_LINK) && |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 8536 | (cmd != ELS_CMD_FLOGI) && |
| 8537 | !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) { |
James Smart | 401304c | 2016-10-13 15:06:14 -0700 | [diff] [blame] | 8538 | rjt_err = LSRJT_LOGICAL_BSY; |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8539 | rjt_exp = LSEXP_NOTHING_MORE; |
| 8540 | goto lsrjt; |
| 8541 | } |
| 8542 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8543 | switch (cmd) { |
| 8544 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8545 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8546 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 8547 | did, vport->port_state, ndlp->nlp_flag); |
| 8548 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8549 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8550 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 8551 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 8552 | (phba->pport->fc_flag & FC_PT2PT)) { |
| 8553 | vport->fc_prevDID = vport->fc_myDID; |
| 8554 | /* Our DID needs to be updated before registering |
| 8555 | * the vfi. This is done in lpfc_rcv_plogi but |
| 8556 | * that is called after the reg_vfi. |
| 8557 | */ |
| 8558 | vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo; |
| 8559 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8560 | "3312 Remote port assigned DID x%x " |
| 8561 | "%x\n", vport->fc_myDID, |
| 8562 | vport->fc_prevDID); |
| 8563 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8564 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8565 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8566 | |
| 8567 | /* If Nport discovery is delayed, reject PLOGIs */ |
| 8568 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 8569 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8570 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8571 | break; |
| 8572 | } |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 8573 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8574 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 8575 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 8576 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 8577 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8578 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 8579 | break; |
| 8580 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8581 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8582 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8583 | spin_lock_irq(shost->host_lock); |
| 8584 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 8585 | spin_unlock_irq(shost->host_lock); |
| 8586 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8587 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 8588 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8589 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8590 | break; |
| 8591 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8592 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8593 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 8594 | did, vport->port_state, ndlp->nlp_flag); |
| 8595 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8596 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 8597 | |
| 8598 | /* If the driver believes fabric discovery is done and is ready, |
| 8599 | * bounce the link. There is some descrepancy. |
| 8600 | */ |
| 8601 | if (vport->port_state >= LPFC_LOCAL_CFG_LINK && |
| 8602 | vport->fc_flag & FC_PT2PT && |
| 8603 | vport->rcv_flogi_cnt >= 1) { |
| 8604 | rjt_err = LSRJT_LOGICAL_BSY; |
| 8605 | rjt_exp = LSEXP_NOTHING_MORE; |
| 8606 | init_link++; |
| 8607 | goto lsrjt; |
| 8608 | } |
| 8609 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 8610 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8611 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8612 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8613 | break; |
| 8614 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8615 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8616 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 8617 | did, vport->port_state, ndlp->nlp_flag); |
| 8618 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8619 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8620 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8621 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8622 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8623 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8624 | break; |
| 8625 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8626 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8627 | break; |
| 8628 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8629 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8630 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 8631 | did, vport->port_state, ndlp->nlp_flag); |
| 8632 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8633 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8634 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8635 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8636 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8637 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8638 | break; |
| 8639 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8640 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8641 | break; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 8642 | case ELS_CMD_LCB: |
| 8643 | phba->fc_stat.elsRcvLCB++; |
| 8644 | lpfc_els_rcv_lcb(vport, elsiocb, ndlp); |
| 8645 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 8646 | case ELS_CMD_RDP: |
| 8647 | phba->fc_stat.elsRcvRDP++; |
| 8648 | lpfc_els_rcv_rdp(vport, elsiocb, ndlp); |
| 8649 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8650 | case ELS_CMD_RSCN: |
| 8651 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 8652 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8653 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8654 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8655 | break; |
| 8656 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8657 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8658 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 8659 | did, vport->port_state, ndlp->nlp_flag); |
| 8660 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8661 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8662 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8663 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8664 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8665 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8666 | break; |
| 8667 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8668 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 8669 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8670 | break; |
| 8671 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8672 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8673 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 8674 | did, vport->port_state, ndlp->nlp_flag); |
| 8675 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8676 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8677 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8678 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8679 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8680 | break; |
| 8681 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8682 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 8683 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8684 | break; |
| 8685 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8686 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8687 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 8688 | did, vport->port_state, ndlp->nlp_flag); |
| 8689 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8690 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8691 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8692 | break; |
| 8693 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8694 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8695 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 8696 | did, vport->port_state, ndlp->nlp_flag); |
| 8697 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8698 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8699 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8700 | break; |
| 8701 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8702 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8703 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 8704 | did, vport->port_state, ndlp->nlp_flag); |
| 8705 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8706 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8707 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8708 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8709 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 8710 | case ELS_CMD_NVMEPRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8711 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8712 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 8713 | did, vport->port_state, ndlp->nlp_flag); |
| 8714 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8715 | phba->fc_stat.elsRcvPRLI++; |
Dick Kennedy | a71e3cd | 2017-03-23 08:47:18 -0400 | [diff] [blame] | 8716 | if ((vport->port_state < LPFC_DISC_AUTH) && |
| 8717 | (vport->fc_flag & FC_FABRIC)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8718 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8719 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8720 | break; |
| 8721 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8722 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8723 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8724 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8725 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8726 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 8727 | did, vport->port_state, ndlp->nlp_flag); |
| 8728 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8729 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8730 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8731 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8732 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8733 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8734 | case ELS_CMD_RLS: |
| 8735 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8736 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 8737 | did, vport->port_state, ndlp->nlp_flag); |
| 8738 | |
| 8739 | phba->fc_stat.elsRcvRLS++; |
| 8740 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 8741 | if (newnode) |
| 8742 | lpfc_nlp_put(ndlp); |
| 8743 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8744 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8745 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8746 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 8747 | did, vport->port_state, ndlp->nlp_flag); |
| 8748 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8749 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8750 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8751 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8752 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8753 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8754 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8755 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8756 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 8757 | did, vport->port_state, ndlp->nlp_flag); |
| 8758 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8759 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8760 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8761 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8762 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8763 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8764 | case ELS_CMD_RTV: |
| 8765 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8766 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 8767 | did, vport->port_state, ndlp->nlp_flag); |
| 8768 | phba->fc_stat.elsRcvRTV++; |
| 8769 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 8770 | if (newnode) |
| 8771 | lpfc_nlp_put(ndlp); |
| 8772 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8773 | case ELS_CMD_RRQ: |
| 8774 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8775 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 8776 | did, vport->port_state, ndlp->nlp_flag); |
| 8777 | |
| 8778 | phba->fc_stat.elsRcvRRQ++; |
| 8779 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 8780 | if (newnode) |
| 8781 | lpfc_nlp_put(ndlp); |
| 8782 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8783 | case ELS_CMD_ECHO: |
| 8784 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8785 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 8786 | did, vport->port_state, ndlp->nlp_flag); |
| 8787 | |
| 8788 | phba->fc_stat.elsRcvECHO++; |
| 8789 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 8790 | if (newnode) |
| 8791 | lpfc_nlp_put(ndlp); |
| 8792 | break; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8793 | case ELS_CMD_REC: |
Colin Ian King | 8fd03fd | 2017-12-22 00:39:36 +0000 | [diff] [blame] | 8794 | /* receive this due to exchange closed */ |
| 8795 | rjt_err = LSRJT_UNABLE_TPC; |
| 8796 | rjt_exp = LSEXP_INVALID_OX_RX; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8797 | break; |
James Smart | 1a61e54 | 2019-04-05 16:04:23 -0700 | [diff] [blame] | 8798 | case ELS_CMD_FPIN: |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8799 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8800 | "RCV FPIN: did:x%x/ste:x%x flg:x%x", |
| 8801 | did, vport->port_state, ndlp->nlp_flag); |
| 8802 | |
| 8803 | lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload, |
| 8804 | payload_len); |
| 8805 | |
| 8806 | /* There are no replies, so no rjt codes */ |
James Smart | 1a61e54 | 2019-04-05 16:04:23 -0700 | [diff] [blame] | 8807 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8808 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8809 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8810 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 8811 | cmd, did, vport->port_state); |
| 8812 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8813 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8814 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8815 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8816 | |
| 8817 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8818 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8819 | "0115 Unknown ELS command x%x " |
| 8820 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8821 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8822 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8823 | break; |
| 8824 | } |
| 8825 | |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8826 | lsrjt: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8827 | /* check if need to LS_RJT received ELS cmd */ |
| 8828 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8829 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8830 | stat.un.b.lsRjtRsnCode = rjt_err; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8831 | stat.un.b.lsRjtRsnCodeExp = rjt_exp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8832 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 8833 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8834 | } |
| 8835 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8836 | lpfc_nlp_put(elsiocb->context1); |
| 8837 | elsiocb->context1 = NULL; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 8838 | |
| 8839 | /* Special case. Driver received an unsolicited command that |
| 8840 | * unsupportable given the driver's current state. Reset the |
| 8841 | * link and start over. |
| 8842 | */ |
| 8843 | if (init_link) { |
| 8844 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8845 | if (!mbox) |
| 8846 | return; |
| 8847 | lpfc_linkdown(phba); |
| 8848 | lpfc_init_link(phba, mbox, |
| 8849 | phba->cfg_topology, |
| 8850 | phba->cfg_link_speed); |
| 8851 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 8852 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 8853 | mbox->vport = vport; |
| 8854 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 8855 | MBX_NOT_FINISHED) |
| 8856 | mempool_free(mbox, phba->mbox_mem_pool); |
| 8857 | } |
| 8858 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8859 | return; |
| 8860 | |
| 8861 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8862 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8863 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8864 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8865 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8866 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8867 | phba->fc_stat.elsRcvDrop++; |
| 8868 | } |
| 8869 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8870 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8871 | * 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] | 8872 | * @phba: pointer to lpfc hba data structure. |
| 8873 | * @pring: pointer to a SLI ring. |
| 8874 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 8875 | * |
| 8876 | * This routine is used to process an unsolicited event received from a SLI |
| 8877 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 8878 | * associated with the unsolicited event is done by invoking the routine |
| 8879 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 8880 | * SLI ring on which the unsolicited event was received. |
| 8881 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8882 | void |
| 8883 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 8884 | struct lpfc_iocbq *elsiocb) |
| 8885 | { |
| 8886 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8887 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8888 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8889 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 8890 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8891 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8892 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8893 | elsiocb->context2 = NULL; |
| 8894 | elsiocb->context3 = NULL; |
| 8895 | |
| 8896 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 8897 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 8898 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 8899 | (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 8900 | IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8901 | phba->fc_stat.NoRcvBuf++; |
| 8902 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8903 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 8904 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8905 | return; |
| 8906 | } |
| 8907 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8908 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 8909 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 8910 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 8911 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 8912 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8913 | else |
| 8914 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8915 | icmd->unsli3.rcvsli3.vpi); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8916 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8917 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8918 | /* If there are no BDEs associated |
| 8919 | * with this IOCB, there is nothing to do. |
| 8920 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8921 | if (icmd->ulpBdeCount == 0) |
| 8922 | return; |
| 8923 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8924 | /* type of ELS cmd is first 32bit word |
| 8925 | * in packet |
| 8926 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8927 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8928 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8929 | } else { |
| 8930 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 8931 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8932 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 8933 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8934 | } |
| 8935 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8936 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 8937 | /* |
| 8938 | * The different unsolicited event handlers would tell us |
| 8939 | * if they are done with "mp" by setting context2 to NULL. |
| 8940 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8941 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8942 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 8943 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8944 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8945 | |
| 8946 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8947 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8948 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8949 | elsiocb->context2 = bdeBuf2; |
| 8950 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8951 | /* free mp if we are done with it */ |
| 8952 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8953 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 8954 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8955 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8956 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8957 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8958 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 8959 | static void |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8960 | lpfc_start_fdmi(struct lpfc_vport *vport) |
| 8961 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8962 | struct lpfc_nodelist *ndlp; |
| 8963 | |
| 8964 | /* If this is the first time, allocate an ndlp and initialize |
| 8965 | * it. Otherwise, make sure the node is enabled and then do the |
| 8966 | * login. |
| 8967 | */ |
| 8968 | ndlp = lpfc_findnode_did(vport, FDMI_DID); |
| 8969 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 8970 | ndlp = lpfc_nlp_init(vport, FDMI_DID); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8971 | if (ndlp) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8972 | ndlp->nlp_type |= NLP_FABRIC; |
| 8973 | } else { |
| 8974 | return; |
| 8975 | } |
| 8976 | } |
| 8977 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 8978 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 8979 | |
| 8980 | if (ndlp) { |
| 8981 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 8982 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| 8983 | } |
| 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_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] | 8988 | * @phba: pointer to lpfc hba data structure. |
| 8989 | * @vport: pointer to a virtual N_Port data structure. |
| 8990 | * |
| 8991 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 8992 | * State Change Request (SCR) for a @vport. This routine will create an |
| 8993 | * ndlp for the Name Server associated to the @vport if such node does |
| 8994 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 8995 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 8996 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 8997 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 8998 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8999 | void |
| 9000 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 9001 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9002 | struct lpfc_nodelist *ndlp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9003 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 9004 | |
| 9005 | /* |
| 9006 | * If lpfc_delay_discovery parameter is set and the clean address |
| 9007 | * bit is cleared and fc fabric parameters chenged, delay FC NPort |
| 9008 | * discovery. |
| 9009 | */ |
| 9010 | spin_lock_irq(shost->host_lock); |
| 9011 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 9012 | spin_unlock_irq(shost->host_lock); |
James Smart | 1877570 | 2013-04-17 20:19:25 -0400 | [diff] [blame] | 9013 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 9014 | "3334 Delay fc port discovery for %d seconds\n", |
| 9015 | phba->fc_ratov); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9016 | mod_timer(&vport->delayed_disc_tmo, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9017 | jiffies + msecs_to_jiffies(1000 * phba->fc_ratov)); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9018 | return; |
| 9019 | } |
| 9020 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9021 | |
| 9022 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 9023 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 9024 | ndlp = lpfc_nlp_init(vport, NameServer_DID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9025 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 9026 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9027 | lpfc_disc_start(vport); |
| 9028 | return; |
| 9029 | } |
| 9030 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9031 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 9032 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9033 | return; |
| 9034 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 9035 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 9036 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 9037 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 9038 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 9039 | lpfc_disc_start(vport); |
| 9040 | return; |
| 9041 | } |
| 9042 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 9043 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 9044 | "0348 NameServer login: node freed\n"); |
| 9045 | return; |
| 9046 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9047 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9048 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9049 | |
| 9050 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 9051 | |
| 9052 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 9053 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9054 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 9055 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9056 | return; |
| 9057 | } |
| 9058 | |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 9059 | if ((phba->cfg_enable_SmartSAN || |
| 9060 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) && |
| 9061 | (vport->load_flag & FC_ALLOW_FDMI)) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9062 | lpfc_start_fdmi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9063 | } |
| 9064 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9065 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9066 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9067 | * @phba: pointer to lpfc hba data structure. |
| 9068 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 9069 | * |
| 9070 | * This routine is the completion callback function to register new vport |
| 9071 | * mailbox command. If the new vport mailbox command completes successfully, |
| 9072 | * the fabric registration login shall be performed on physical port (the |
| 9073 | * new vport created is actually a physical port, with VPI 0) or the port |
| 9074 | * login to Name Server for State Change Request (SCR) will be performed |
| 9075 | * on virtual port (real virtual port, with VPI greater than 0). |
| 9076 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9077 | static void |
| 9078 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 9079 | { |
| 9080 | struct lpfc_vport *vport = pmb->vport; |
| 9081 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 9082 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9083 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9084 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9085 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9086 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9087 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9088 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9089 | |
| 9090 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9091 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 9092 | "0915 Register VPI failed : Status: x%x" |
| 9093 | " upd bit: x%x \n", mb->mbxStatus, |
| 9094 | mb->un.varRegVpi.upd); |
| 9095 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 9096 | mb->un.varRegVpi.upd) |
| 9097 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9098 | |
| 9099 | switch (mb->mbxStatus) { |
| 9100 | case 0x11: /* unsupported feature */ |
| 9101 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9102 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9103 | /* giving up on vport registration */ |
| 9104 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 9105 | spin_lock_irq(shost->host_lock); |
| 9106 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 9107 | spin_unlock_irq(shost->host_lock); |
| 9108 | lpfc_can_disctmo(vport); |
| 9109 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9110 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 9111 | case 0x20: |
| 9112 | spin_lock_irq(shost->host_lock); |
| 9113 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 9114 | spin_unlock_irq(shost->host_lock); |
| 9115 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 9116 | pmb->vport = vport; |
| 9117 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 9118 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 9119 | MBX_NOWAIT); |
| 9120 | if (rc == MBX_NOT_FINISHED) { |
| 9121 | lpfc_printf_vlog(vport, |
| 9122 | KERN_ERR, LOG_MBOX, |
| 9123 | "2732 Failed to issue INIT_VPI" |
| 9124 | " mailbox command\n"); |
| 9125 | } else { |
| 9126 | lpfc_nlp_put(ndlp); |
| 9127 | return; |
| 9128 | } |
Bart Van Assche | cd05c15 | 2019-03-28 11:06:18 -0700 | [diff] [blame] | 9129 | /* fall through */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9130 | default: |
| 9131 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9132 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9133 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9134 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9135 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9136 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9137 | spin_unlock_irq(shost->host_lock); |
James Smart | 5d18153 | 2017-03-04 09:30:25 -0800 | [diff] [blame] | 9138 | if (mb->mbxStatus == MBX_NOT_FINISHED) |
| 9139 | break; |
| 9140 | if ((vport->port_type == LPFC_PHYSICAL_PORT) && |
| 9141 | !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) { |
| 9142 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9143 | lpfc_issue_init_vfi(vport); |
| 9144 | else |
| 9145 | lpfc_initial_flogi(vport); |
| 9146 | } else { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9147 | lpfc_initial_fdisc(vport); |
James Smart | 5d18153 | 2017-03-04 09:30:25 -0800 | [diff] [blame] | 9148 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9149 | break; |
| 9150 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9151 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9152 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 9153 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9154 | spin_unlock_irq(shost->host_lock); |
| 9155 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9156 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 9157 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9158 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 9159 | /* |
| 9160 | * If the physical port is instantiated using |
| 9161 | * FDISC, do not start vport discovery. |
| 9162 | */ |
| 9163 | if (vport->port_state != LPFC_FDISC) |
| 9164 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9165 | lpfc_do_scr_ns_plogi(phba, vport); |
| 9166 | } |
| 9167 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9168 | lpfc_do_scr_ns_plogi(phba, vport); |
| 9169 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 9170 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9171 | /* Now, we decrement the ndlp reference count held for this |
| 9172 | * callback function |
| 9173 | */ |
| 9174 | lpfc_nlp_put(ndlp); |
| 9175 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9176 | mempool_free(pmb, phba->mbox_mem_pool); |
| 9177 | return; |
| 9178 | } |
| 9179 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9180 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9181 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9182 | * @phba: pointer to lpfc hba data structure. |
| 9183 | * @vport: pointer to a host virtual N_Port data structure. |
| 9184 | * @ndlp: pointer to a node-list data structure. |
| 9185 | * |
| 9186 | * This routine registers the @vport as a new virtual port with a HBA. |
| 9187 | * It is done through a registering vpi mailbox command. |
| 9188 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9189 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9190 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 9191 | struct lpfc_nodelist *ndlp) |
| 9192 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9193 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9194 | LPFC_MBOXQ_t *mbox; |
| 9195 | |
| 9196 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 9197 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9198 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9199 | mbox->vport = vport; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 9200 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9201 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9202 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9203 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9204 | /* mailbox command not success, decrement ndlp |
| 9205 | * reference count for this command |
| 9206 | */ |
| 9207 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9208 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9209 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9210 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 9211 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9212 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9213 | } |
| 9214 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9215 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 9216 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9217 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9218 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9219 | return; |
| 9220 | |
| 9221 | mbox_err_exit: |
| 9222 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 9223 | spin_lock_irq(shost->host_lock); |
| 9224 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 9225 | spin_unlock_irq(shost->host_lock); |
| 9226 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9227 | } |
| 9228 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9229 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9230 | * 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] | 9231 | * @phba: pointer to lpfc hba data structure. |
| 9232 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9233 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9234 | **/ |
| 9235 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9236 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9237 | { |
| 9238 | struct lpfc_vport **vports; |
| 9239 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9240 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9241 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9242 | |
| 9243 | /* Treat this failure as linkdown for all vports */ |
| 9244 | link_state = phba->link_state; |
| 9245 | lpfc_linkdown(phba); |
| 9246 | phba->link_state = link_state; |
| 9247 | |
| 9248 | vports = lpfc_create_vport_work_array(phba); |
| 9249 | |
| 9250 | if (vports) { |
| 9251 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 9252 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 9253 | if (ndlp) |
| 9254 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 9255 | lpfc_els_flush_cmd(vports[i]); |
| 9256 | } |
| 9257 | lpfc_destroy_vport_work_array(phba, vports); |
| 9258 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9259 | } |
| 9260 | |
| 9261 | /** |
| 9262 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 9263 | * @phba: pointer to lpfc hba data structure. |
| 9264 | * |
| 9265 | * This routine abort all pending discovery commands and |
| 9266 | * start a timer to retry FLOGI for the physical port |
| 9267 | * discovery. |
| 9268 | **/ |
| 9269 | void |
| 9270 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 9271 | { |
| 9272 | struct lpfc_nodelist *ndlp; |
| 9273 | struct Scsi_Host *shost; |
| 9274 | |
| 9275 | /* Cancel the all vports retry delay retry timers */ |
| 9276 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9277 | |
| 9278 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 9279 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 9280 | if (!ndlp) |
| 9281 | return; |
| 9282 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9283 | shost = lpfc_shost_from_vport(phba->pport); |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9284 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000)); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9285 | spin_lock_irq(shost->host_lock); |
| 9286 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 9287 | spin_unlock_irq(shost->host_lock); |
| 9288 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 9289 | phba->pport->port_state = LPFC_FLOGI; |
| 9290 | return; |
| 9291 | } |
| 9292 | |
| 9293 | /** |
| 9294 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 9295 | * @phba: pointer to lpfc hba data structure. |
| 9296 | * @cmdiocb: pointer to FDISC command iocb. |
| 9297 | * @rspiocb: pointer to FDISC response iocb. |
| 9298 | * |
| 9299 | * This routine checks if a FLOGI is reguired for FDISC |
| 9300 | * to succeed. |
| 9301 | **/ |
| 9302 | static int |
| 9303 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 9304 | struct lpfc_iocbq *cmdiocb, |
| 9305 | struct lpfc_iocbq *rspiocb) |
| 9306 | { |
| 9307 | |
| 9308 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 9309 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 9310 | return 0; |
| 9311 | else |
| 9312 | return 1; |
| 9313 | } |
| 9314 | |
| 9315 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9316 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9317 | * @phba: pointer to lpfc hba data structure. |
| 9318 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 9319 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 9320 | * |
| 9321 | * This routine is the completion callback function to a Fabric Discover |
| 9322 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 9323 | * single threaded, each FDISC completion callback function will reset |
| 9324 | * the discovery timer for all vports such that the timers will not get |
| 9325 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 9326 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 9327 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 9328 | * assigned to the vport has been changed with the completion of the FDISC |
| 9329 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 9330 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 9331 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 9332 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 9333 | * Server for State Change Request (SCR). |
| 9334 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9335 | static void |
| 9336 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9337 | struct lpfc_iocbq *rspiocb) |
| 9338 | { |
| 9339 | struct lpfc_vport *vport = cmdiocb->vport; |
| 9340 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 9341 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 9342 | struct lpfc_nodelist *np; |
| 9343 | struct lpfc_nodelist *next_np; |
| 9344 | IOCB_t *irsp = &rspiocb->iocb; |
| 9345 | struct lpfc_iocbq *piocb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9346 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 9347 | struct serv_parm *sp; |
| 9348 | uint8_t fabric_param_changed; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9349 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9350 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 9351 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 9352 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 9353 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9354 | /* Since all FDISCs are being single threaded, we |
| 9355 | * must reset the discovery timer for ALL vports |
| 9356 | * waiting to send FDISC when one completes. |
| 9357 | */ |
| 9358 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 9359 | lpfc_set_disctmo(piocb->vport); |
| 9360 | } |
| 9361 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9362 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 9363 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 9364 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 9365 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9366 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9367 | |
| 9368 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 9369 | lpfc_retry_pport_discovery(phba); |
| 9370 | goto out; |
| 9371 | } |
| 9372 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9373 | /* Check for retry */ |
| 9374 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 9375 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9376 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9377 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9378 | "0126 FDISC failed. (x%x/x%x)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9379 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9380 | goto fdisc_failed; |
| 9381 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9382 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9383 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 9384 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9385 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 9386 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9387 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 9388 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9389 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9390 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 9391 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9392 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 9393 | if (!prsp) |
| 9394 | goto out; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9395 | sp = prsp->virt + sizeof(uint32_t); |
| 9396 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 9397 | memcpy(&vport->fabric_portname, &sp->portName, |
| 9398 | sizeof(struct lpfc_name)); |
| 9399 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 9400 | sizeof(struct lpfc_name)); |
| 9401 | if (fabric_param_changed && |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9402 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 9403 | /* If our NportID changed, we need to ensure all |
| 9404 | * remaining NPORTs get unreg_login'ed so we can |
| 9405 | * issue unreg_vpi. |
| 9406 | */ |
| 9407 | list_for_each_entry_safe(np, next_np, |
| 9408 | &vport->fc_nodes, nlp_listp) { |
| 9409 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 9410 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 9411 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 9412 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9413 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9414 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9415 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9416 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9417 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 9418 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9419 | |
| 9420 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9421 | lpfc_sli4_unreg_all_rpis(vport); |
| 9422 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9423 | lpfc_mbx_unreg_vpi(vport); |
| 9424 | spin_lock_irq(shost->host_lock); |
| 9425 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9426 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9427 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 9428 | else |
| 9429 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9430 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 9431 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 9432 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 9433 | /* |
| 9434 | * Driver needs to re-reg VPI in order for f/w |
| 9435 | * to update the MAC address. |
| 9436 | */ |
| 9437 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 9438 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9439 | } |
| 9440 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 9441 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 9442 | lpfc_issue_init_vpi(vport); |
| 9443 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9444 | lpfc_register_new_vport(phba, vport, ndlp); |
| 9445 | else |
| 9446 | lpfc_do_scr_ns_plogi(phba, vport); |
| 9447 | goto out; |
| 9448 | fdisc_failed: |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 9449 | if (vport->fc_vport && |
| 9450 | (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)) |
James Smart | c84163d | 2015-05-21 13:55:22 -0400 | [diff] [blame] | 9451 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9452 | /* Cancel discovery timer */ |
| 9453 | lpfc_can_disctmo(vport); |
| 9454 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9455 | out: |
| 9456 | lpfc_els_free_iocb(phba, cmdiocb); |
| 9457 | } |
| 9458 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9459 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9460 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9461 | * @vport: pointer to a virtual N_Port data structure. |
| 9462 | * @ndlp: pointer to a node-list data structure. |
| 9463 | * @retry: number of retries to the command IOCB. |
| 9464 | * |
| 9465 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 9466 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 9467 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 9468 | * IOCB will be sent off HBA at any given time. |
| 9469 | * |
| 9470 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 9471 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 9472 | * will be stored into the context1 field of the IOCB for the completion |
| 9473 | * callback function to the FDISC ELS command. |
| 9474 | * |
| 9475 | * Return code |
| 9476 | * 0 - Successfully issued fdisc iocb command |
| 9477 | * 1 - Failed to issue fdisc iocb command |
| 9478 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 9479 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9480 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 9481 | uint8_t retry) |
| 9482 | { |
| 9483 | struct lpfc_hba *phba = vport->phba; |
| 9484 | IOCB_t *icmd; |
| 9485 | struct lpfc_iocbq *elsiocb; |
| 9486 | struct serv_parm *sp; |
| 9487 | uint8_t *pcmd; |
| 9488 | uint16_t cmdsize; |
| 9489 | int did = ndlp->nlp_DID; |
| 9490 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9491 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9492 | vport->port_state = LPFC_FDISC; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9493 | vport->fc_myDID = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9494 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 9495 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 9496 | ELS_CMD_FDISC); |
| 9497 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9498 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9499 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 9500 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9501 | return 1; |
| 9502 | } |
| 9503 | |
| 9504 | icmd = &elsiocb->iocb; |
| 9505 | icmd->un.elsreq64.myID = 0; |
| 9506 | icmd->un.elsreq64.fl = 1; |
| 9507 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9508 | /* |
| 9509 | * SLI3 ports require a different context type value than SLI4. |
| 9510 | * Catch SLI3 ports here and override the prep. |
| 9511 | */ |
| 9512 | if (phba->sli_rev == LPFC_SLI_REV3) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9513 | icmd->ulpCt_h = 1; |
| 9514 | icmd->ulpCt_l = 0; |
| 9515 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9516 | |
| 9517 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 9518 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 9519 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 9520 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 9521 | sp = (struct serv_parm *) pcmd; |
| 9522 | /* Setup CSPs accordingly for Fabric */ |
| 9523 | sp->cmn.e_d_tov = 0; |
| 9524 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 9525 | sp->cmn.virtual_fabric_support = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9526 | sp->cls1.classValid = 0; |
| 9527 | sp->cls2.seqDelivery = 1; |
| 9528 | sp->cls3.seqDelivery = 1; |
| 9529 | |
| 9530 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 9531 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 9532 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 9533 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 9534 | memcpy(pcmd, &vport->fc_portname, 8); |
| 9535 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 9536 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 9537 | memcpy(pcmd, &vport->fc_nodename, 8); |
Dick Kennedy | 176de5b | 2017-08-23 16:55:40 -0700 | [diff] [blame] | 9538 | sp->cmn.valid_vendor_ver_level = 0; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 9539 | memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9540 | lpfc_set_disctmo(vport); |
| 9541 | |
| 9542 | phba->fc_stat.elsXmitFDISC++; |
| 9543 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 9544 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9545 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 9546 | "Issue FDISC: did:x%x", |
| 9547 | did, 0, 0); |
| 9548 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9549 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 9550 | if (rc == IOCB_ERROR) { |
| 9551 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9552 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9553 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 9554 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9555 | return 1; |
| 9556 | } |
| 9557 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9558 | return 0; |
| 9559 | } |
| 9560 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9561 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9562 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9563 | * @phba: pointer to lpfc hba data structure. |
| 9564 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 9565 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 9566 | * |
| 9567 | * This routine is the completion callback function to the issuing of a LOGO |
| 9568 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 9569 | * reference count held on ndlp for this completion function, indicating that |
| 9570 | * the reference to the ndlp is no long needed. Note that the |
| 9571 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 9572 | * callback function and an additional explicit ndlp reference decrementation |
| 9573 | * will trigger the actual release of the ndlp. |
| 9574 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9575 | static void |
| 9576 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9577 | struct lpfc_iocbq *rspiocb) |
| 9578 | { |
| 9579 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9580 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 9581 | struct lpfc_nodelist *ndlp; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9582 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9583 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9584 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9585 | irsp = &rspiocb->iocb; |
| 9586 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 9587 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 9588 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9589 | |
| 9590 | lpfc_els_free_iocb(phba, cmdiocb); |
| 9591 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 9592 | |
| 9593 | /* Trigger the release of the ndlp after logo */ |
| 9594 | lpfc_nlp_put(ndlp); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9595 | |
| 9596 | /* NPIV LOGO completes to NPort <nlp_DID> */ |
| 9597 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 9598 | "2928 NPIV LOGO completes to NPort x%x " |
| 9599 | "Data: x%x x%x x%x x%x\n", |
| 9600 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 9601 | irsp->ulpTimeout, vport->num_disc_nodes); |
| 9602 | |
| 9603 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 9604 | spin_lock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 9605 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9606 | vport->fc_flag &= ~FC_FABRIC; |
| 9607 | spin_unlock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 9608 | lpfc_can_disctmo(vport); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9609 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9610 | } |
| 9611 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9612 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9613 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9614 | * @vport: pointer to a virtual N_Port data structure. |
| 9615 | * @ndlp: pointer to a node-list data structure. |
| 9616 | * |
| 9617 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 9618 | * |
| 9619 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 9620 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 9621 | * will be stored into the context1 field of the IOCB for the completion |
| 9622 | * callback function to the LOGO ELS command. |
| 9623 | * |
| 9624 | * Return codes |
| 9625 | * 0 - Successfully issued logo off the @vport |
| 9626 | * 1 - Failed to issue logo off the @vport |
| 9627 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9628 | int |
| 9629 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 9630 | { |
| 9631 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 9632 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9633 | struct lpfc_iocbq *elsiocb; |
| 9634 | uint8_t *pcmd; |
| 9635 | uint16_t cmdsize; |
| 9636 | |
| 9637 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 9638 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 9639 | ELS_CMD_LOGO); |
| 9640 | if (!elsiocb) |
| 9641 | return 1; |
| 9642 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9643 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 9644 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 9645 | pcmd += sizeof(uint32_t); |
| 9646 | |
| 9647 | /* Fill in LOGO payload */ |
| 9648 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 9649 | pcmd += sizeof(uint32_t); |
| 9650 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 9651 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9652 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 9653 | "Issue LOGO npiv did:x%x flg:x%x", |
| 9654 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 9655 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9656 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 9657 | spin_lock_irq(shost->host_lock); |
| 9658 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 9659 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9660 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 9661 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9662 | spin_lock_irq(shost->host_lock); |
| 9663 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 9664 | spin_unlock_irq(shost->host_lock); |
| 9665 | lpfc_els_free_iocb(phba, elsiocb); |
| 9666 | return 1; |
| 9667 | } |
| 9668 | return 0; |
| 9669 | } |
| 9670 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9671 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9672 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9673 | * @ptr: holder for the timer function associated data. |
| 9674 | * |
| 9675 | * This routine is invoked by the fabric iocb block timer after |
| 9676 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 9677 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 9678 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 9679 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 9680 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 9681 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9682 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 9683 | lpfc_fabric_block_timeout(struct timer_list *t) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9684 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 9685 | struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9686 | unsigned long iflags; |
| 9687 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9688 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9689 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 9690 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 9691 | if (!tmo_posted) |
| 9692 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 9693 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 9694 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9695 | if (!tmo_posted) |
| 9696 | lpfc_worker_wake_up(phba); |
| 9697 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9698 | } |
| 9699 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9700 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9701 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9702 | * @phba: pointer to lpfc hba data structure. |
| 9703 | * |
| 9704 | * This routine issues one fabric iocb from the driver internal list to |
| 9705 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 9706 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 9707 | * remove one pending fabric iocb from the driver internal list and invokes |
| 9708 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 9709 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9710 | static void |
| 9711 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 9712 | { |
| 9713 | struct lpfc_iocbq *iocb; |
| 9714 | unsigned long iflags; |
| 9715 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9716 | IOCB_t *cmd; |
| 9717 | |
| 9718 | repeat: |
| 9719 | iocb = NULL; |
| 9720 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9721 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9722 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 9723 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 9724 | list); |
| 9725 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9726 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9727 | atomic_inc(&phba->fabric_iocb_count); |
| 9728 | } |
| 9729 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9730 | if (iocb) { |
| 9731 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 9732 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 9733 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 9734 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9735 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 9736 | "Fabric sched1: ste:x%x", |
| 9737 | iocb->vport->port_state, 0, 0); |
| 9738 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9739 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9740 | |
| 9741 | if (ret == IOCB_ERROR) { |
| 9742 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 9743 | iocb->fabric_iocb_cmpl = NULL; |
| 9744 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 9745 | cmd = &iocb->iocb; |
| 9746 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 9747 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 9748 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 9749 | |
| 9750 | atomic_dec(&phba->fabric_iocb_count); |
| 9751 | goto repeat; |
| 9752 | } |
| 9753 | } |
| 9754 | |
| 9755 | return; |
| 9756 | } |
| 9757 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9758 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9759 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9760 | * @phba: pointer to lpfc hba data structure. |
| 9761 | * |
| 9762 | * This routine unblocks the issuing fabric iocb command. The function |
| 9763 | * will clear the fabric iocb block bit and then invoke the routine |
| 9764 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 9765 | * from the driver internal fabric iocb list. |
| 9766 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9767 | void |
| 9768 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 9769 | { |
| 9770 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 9771 | |
| 9772 | lpfc_resume_fabric_iocbs(phba); |
| 9773 | return; |
| 9774 | } |
| 9775 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9776 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9777 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9778 | * @phba: pointer to lpfc hba data structure. |
| 9779 | * |
| 9780 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 9781 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 9782 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 9783 | * fabric iocb will be issued out of the HBA. |
| 9784 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9785 | static void |
| 9786 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 9787 | { |
| 9788 | int blocked; |
| 9789 | |
| 9790 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9791 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9792 | if (!blocked) |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9793 | mod_timer(&phba->fabric_block_timer, |
| 9794 | jiffies + msecs_to_jiffies(100)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9795 | |
| 9796 | return; |
| 9797 | } |
| 9798 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9799 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9800 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9801 | * @phba: pointer to lpfc hba data structure. |
| 9802 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 9803 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 9804 | * |
| 9805 | * This routine is the callback function that is put to the fabric iocb's |
| 9806 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 9807 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 9808 | * function first restores and invokes the original iocb's callback function |
| 9809 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 9810 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 9811 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9812 | static void |
| 9813 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9814 | struct lpfc_iocbq *rspiocb) |
| 9815 | { |
| 9816 | struct ls_rjt stat; |
| 9817 | |
Shyam Saini | e01ea5e | 2016-12-24 16:21:07 +0530 | [diff] [blame] | 9818 | BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9819 | |
| 9820 | switch (rspiocb->iocb.ulpStatus) { |
| 9821 | case IOSTAT_NPORT_RJT: |
| 9822 | case IOSTAT_FABRIC_RJT: |
| 9823 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 9824 | lpfc_block_fabric_iocbs(phba); |
| 9825 | } |
| 9826 | break; |
| 9827 | |
| 9828 | case IOSTAT_NPORT_BSY: |
| 9829 | case IOSTAT_FABRIC_BSY: |
| 9830 | lpfc_block_fabric_iocbs(phba); |
| 9831 | break; |
| 9832 | |
| 9833 | case IOSTAT_LS_RJT: |
| 9834 | stat.un.lsRjtError = |
| 9835 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 9836 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 9837 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 9838 | lpfc_block_fabric_iocbs(phba); |
| 9839 | break; |
| 9840 | } |
| 9841 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 9842 | BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9843 | |
| 9844 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 9845 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 9846 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 9847 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 9848 | |
| 9849 | atomic_dec(&phba->fabric_iocb_count); |
| 9850 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9851 | /* Post any pending iocbs to HBA */ |
| 9852 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9853 | } |
| 9854 | } |
| 9855 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9856 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9857 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9858 | * @phba: pointer to lpfc hba data structure. |
| 9859 | * @iocb: pointer to lpfc command iocb data structure. |
| 9860 | * |
| 9861 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 9862 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 9863 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 9864 | * any given time. As such, this function will first check to see whether there |
| 9865 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 9866 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 9867 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 9868 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 9869 | * |
| 9870 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 9871 | * order. The problem is caused by the construction of the "ready" boolen does |
| 9872 | * not include the condition that the internal fabric IOCB list is empty. As |
| 9873 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 9874 | * ahead of the fabric IOCBs in the internal list. |
| 9875 | * |
| 9876 | * Return code |
| 9877 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 9878 | * IOCB_ERROR - failed to issue fabric iocb |
| 9879 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 9880 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9881 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 9882 | { |
| 9883 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9884 | int ready; |
| 9885 | int ret; |
| 9886 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 9887 | BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9888 | |
| 9889 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9890 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 9891 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 9892 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9893 | if (ready) |
| 9894 | /* Increment fabric iocb count to hold the position */ |
| 9895 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9896 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9897 | if (ready) { |
| 9898 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 9899 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 9900 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 9901 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9902 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 9903 | "Fabric sched2: ste:x%x", |
| 9904 | iocb->vport->port_state, 0, 0); |
| 9905 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9906 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9907 | |
| 9908 | if (ret == IOCB_ERROR) { |
| 9909 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 9910 | iocb->fabric_iocb_cmpl = NULL; |
| 9911 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 9912 | atomic_dec(&phba->fabric_iocb_count); |
| 9913 | } |
| 9914 | } else { |
| 9915 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9916 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 9917 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9918 | ret = IOCB_SUCCESS; |
| 9919 | } |
| 9920 | return ret; |
| 9921 | } |
| 9922 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9923 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9924 | * 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] | 9925 | * @vport: pointer to a virtual N_Port data structure. |
| 9926 | * |
| 9927 | * This routine aborts all the IOCBs associated with a @vport from the |
| 9928 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 9929 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 9930 | * list, removes each IOCB associated with the @vport off the list, set the |
| 9931 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 9932 | * associated with the IOCB. |
| 9933 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 9934 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9935 | { |
| 9936 | LIST_HEAD(completions); |
| 9937 | struct lpfc_hba *phba = vport->phba; |
| 9938 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9939 | |
| 9940 | spin_lock_irq(&phba->hbalock); |
| 9941 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 9942 | list) { |
| 9943 | |
| 9944 | if (piocb->vport != vport) |
| 9945 | continue; |
| 9946 | |
| 9947 | list_move_tail(&piocb->list, &completions); |
| 9948 | } |
| 9949 | spin_unlock_irq(&phba->hbalock); |
| 9950 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9951 | /* Cancel all the IOCBs from the completions list */ |
| 9952 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9953 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9954 | } |
| 9955 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9956 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9957 | * 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] | 9958 | * @ndlp: pointer to a node-list data structure. |
| 9959 | * |
| 9960 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 9961 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 9962 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 9963 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 9964 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 9965 | * associated with the IOCB. |
| 9966 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9967 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 9968 | { |
| 9969 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9970 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9971 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9972 | struct lpfc_sli_ring *pring; |
| 9973 | |
| 9974 | pring = lpfc_phba_elsring(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9975 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 9976 | if (unlikely(!pring)) |
| 9977 | return; |
| 9978 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9979 | spin_lock_irq(&phba->hbalock); |
| 9980 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 9981 | list) { |
| 9982 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 9983 | |
| 9984 | list_move_tail(&piocb->list, &completions); |
| 9985 | } |
| 9986 | } |
| 9987 | spin_unlock_irq(&phba->hbalock); |
| 9988 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9989 | /* Cancel all the IOCBs from the completions list */ |
| 9990 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9991 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9992 | } |
| 9993 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9994 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9995 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9996 | * @phba: pointer to lpfc hba data structure. |
| 9997 | * |
| 9998 | * This routine aborts all the IOCBs currently on the driver internal |
| 9999 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 10000 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 10001 | * list, removes IOCBs off the list, set the status feild to |
| 10002 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 10003 | * the IOCB. |
| 10004 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10005 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 10006 | { |
| 10007 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10008 | |
| 10009 | spin_lock_irq(&phba->hbalock); |
| 10010 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 10011 | spin_unlock_irq(&phba->hbalock); |
| 10012 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10013 | /* Cancel all the IOCBs from the completions list */ |
| 10014 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10015 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10016 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10017 | |
| 10018 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 10019 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport |
| 10020 | * @vport: pointer to lpfc vport data structure. |
| 10021 | * |
| 10022 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 10023 | * for an ndlp on removal. |
| 10024 | **/ |
| 10025 | void |
| 10026 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) |
| 10027 | { |
| 10028 | struct lpfc_hba *phba = vport->phba; |
| 10029 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 10030 | unsigned long iflag = 0; |
| 10031 | |
| 10032 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10033 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 10034 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 10035 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 10036 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) |
| 10037 | sglq_entry->ndlp = NULL; |
| 10038 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10039 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 10040 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10041 | return; |
| 10042 | } |
| 10043 | |
| 10044 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10045 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 10046 | * @phba: pointer to lpfc hba data structure. |
| 10047 | * @axri: pointer to the els xri abort wcqe structure. |
| 10048 | * |
| 10049 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 10050 | * ELS aborted xri. |
| 10051 | **/ |
| 10052 | void |
| 10053 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 10054 | struct sli4_wcqe_xri_aborted *axri) |
| 10055 | { |
| 10056 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10057 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10058 | uint16_t lxri = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10059 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10060 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 10061 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10062 | struct lpfc_nodelist *ndlp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10063 | struct lpfc_sli_ring *pring; |
| 10064 | |
| 10065 | pring = lpfc_phba_elsring(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10066 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10067 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10068 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10069 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 10070 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 10071 | if (sglq_entry->sli4_xritag == xri) { |
| 10072 | list_del(&sglq_entry->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10073 | ndlp = sglq_entry->ndlp; |
| 10074 | sglq_entry->ndlp = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10075 | list_add_tail(&sglq_entry->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10076 | &phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10077 | sglq_entry->state = SGL_FREED; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10078 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10079 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 10080 | lpfc_set_rrq_active(phba, ndlp, |
| 10081 | sglq_entry->sli4_lxritag, |
| 10082 | rxid, 1); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 10083 | |
| 10084 | /* Check if TXQ queue needs to be serviced */ |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 10085 | if (pring && !list_empty(&pring->txq)) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 10086 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10087 | return; |
| 10088 | } |
| 10089 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10090 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10091 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 10092 | if (lxri == NO_XRI) { |
| 10093 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10094 | return; |
| 10095 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10096 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10097 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10098 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10099 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10100 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10101 | return; |
| 10102 | } |
| 10103 | sglq_entry->state = SGL_XRI_ABORTED; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10104 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10105 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10106 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10107 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 10108 | |
| 10109 | /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. |
| 10110 | * @vport: pointer to virtual port object. |
| 10111 | * @ndlp: nodelist pointer for the impacted node. |
| 10112 | * |
| 10113 | * The driver calls this routine in response to an SLI4 XRI ABORT CQE |
| 10114 | * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, |
| 10115 | * the driver is required to send a LOGO to the remote node before it |
| 10116 | * attempts to recover its login to the remote node. |
| 10117 | */ |
| 10118 | void |
| 10119 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 10120 | struct lpfc_nodelist *ndlp) |
| 10121 | { |
| 10122 | struct Scsi_Host *shost; |
| 10123 | struct lpfc_hba *phba; |
| 10124 | unsigned long flags = 0; |
| 10125 | |
| 10126 | shost = lpfc_shost_from_vport(vport); |
| 10127 | phba = vport->phba; |
| 10128 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 10129 | lpfc_printf_log(phba, KERN_INFO, |
| 10130 | LOG_SLI, "3093 No rport recovery needed. " |
| 10131 | "rport in state 0x%x\n", ndlp->nlp_state); |
| 10132 | return; |
| 10133 | } |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 10134 | lpfc_printf_log(phba, KERN_ERR, |
| 10135 | LOG_ELS | LOG_FCP_ERROR | LOG_NVME_IOERR, |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 10136 | "3094 Start rport recovery on shost id 0x%x " |
| 10137 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 10138 | "flags 0x%x\n", |
| 10139 | shost->host_no, ndlp->nlp_DID, |
| 10140 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 10141 | ndlp->nlp_flag); |
| 10142 | /* |
| 10143 | * The rport is not responding. Remove the FCP-2 flag to prevent |
| 10144 | * an ADISC in the follow-up recovery code. |
| 10145 | */ |
| 10146 | spin_lock_irqsave(shost->host_lock, flags); |
| 10147 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 10148 | ndlp->nlp_flag |= NLP_ISSUE_LOGO; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 10149 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 10150 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 10151 | } |
| 10152 | |