| 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 | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017 Broadcom. All Rights Reserved. The term * |
| 5 | * “Broadcom” refers to Broadcom Limited 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> |
| 33 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 34 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 35 | #include "lpfc_hw.h" |
| 36 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 37 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 38 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 39 | #include "lpfc_disc.h" |
| 40 | #include "lpfc_scsi.h" |
| 41 | #include "lpfc.h" |
| 42 | #include "lpfc_logmsg.h" |
| 43 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 44 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 45 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | |
| 47 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, |
| 48 | struct lpfc_iocbq *); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 49 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
| 50 | struct lpfc_iocbq *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 51 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
| 52 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, |
| 53 | struct lpfc_nodelist *ndlp, uint8_t retry); |
| 54 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, |
| 55 | struct lpfc_iocbq *iocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 56 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 57 | static int lpfc_max_els_tries = 3; |
| 58 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 59 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 60 | * lpfc_els_chk_latt - Check host link attention event for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 61 | * @vport: pointer to a host virtual N_Port data structure. |
| 62 | * |
| 63 | * This routine checks whether there is an outstanding host link |
| 64 | * attention event during the discovery process with the @vport. It is done |
| 65 | * by reading the HBA's Host Attention (HA) register. If there is any host |
| 66 | * link attention events during this @vport's discovery process, the @vport |
| 67 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall |
| 68 | * be issued if the link state is not already in host link cleared state, |
| 69 | * and a return code shall indicate whether the host link attention event |
| 70 | * had happened. |
| 71 | * |
| 72 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport |
| 73 | * state in LPFC_VPORT_READY, the request for checking host link attention |
| 74 | * event will be ignored and a return code shall indicate no host link |
| 75 | * attention event had happened. |
| 76 | * |
| 77 | * Return codes |
| 78 | * 0 - no host link attention event happened |
| 79 | * 1 - host link attention event happened |
| 80 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 81 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 82 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 83 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 84 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 85 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 86 | uint32_t ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 87 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 88 | if (vport->port_state >= LPFC_VPORT_READY || |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 89 | phba->link_state == LPFC_LINK_DOWN || |
| 90 | phba->sli_rev > LPFC_SLI_REV3) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 91 | return 0; |
| 92 | |
| 93 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 94 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 95 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 96 | |
| 97 | if (!(ha_copy & HA_LATT)) |
| 98 | return 0; |
| 99 | |
| 100 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 101 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 102 | "0237 Pending Link Event during " |
| 103 | "Discovery: State x%x\n", |
| 104 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 105 | |
| 106 | /* CLEAR_LA should re-enable link attention events and |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 107 | * we should then immediately take a LATT event. The |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 108 | * LATT processing should call lpfc_linkdown() which |
| 109 | * will cleanup any left over in-progress discovery |
| 110 | * events. |
| 111 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 112 | spin_lock_irq(shost->host_lock); |
| 113 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 114 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 115 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 116 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 117 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 119 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 120 | } |
| 121 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 122 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 123 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 124 | * @vport: pointer to a host virtual N_Port data structure. |
| 125 | * @expectRsp: flag indicating whether response is expected. |
| 126 | * @cmdSize: size of the ELS command. |
| 127 | * @retry: number of retries to the command IOCB when it fails. |
| 128 | * @ndlp: pointer to a node-list data structure. |
| 129 | * @did: destination identifier. |
| 130 | * @elscmd: the ELS command code. |
| 131 | * |
| 132 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 133 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 134 | * passed into the routine for discovery state machine to issue an Extended |
| 135 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 136 | * and preparation routine that is used by all the discovery state machine |
| 137 | * routines and the ELS command-specific fields will be later set up by |
| 138 | * the individual discovery machine routines after calling this routine |
| 139 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 140 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 141 | * payload and response payload (if expected). The reference count on the |
| 142 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 143 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 144 | * reference for the command's callback function to access later. |
| 145 | * |
| 146 | * Return code |
| 147 | * Pointer to the newly allocated/prepared els iocb data structure |
| 148 | * NULL - when els iocb data structure allocation/preparation failed |
| 149 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 150 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 151 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 152 | uint16_t cmdSize, uint8_t retry, |
| 153 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 154 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 155 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 156 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 157 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 158 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 159 | struct ulp_bde64 *bpl; |
| 160 | IOCB_t *icmd; |
| 161 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 162 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 163 | if (!lpfc_is_link_up(phba)) |
| 164 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 165 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 166 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 167 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 168 | |
| 169 | if (elsiocb == NULL) |
| 170 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 171 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 172 | /* |
| 173 | * If this command is for fabric controller and HBA running |
| 174 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. |
| 175 | */ |
| 176 | if ((did == Fabric_DID) && |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 177 | (phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 178 | ((elscmd == ELS_CMD_FLOGI) || |
| 179 | (elscmd == ELS_CMD_FDISC) || |
| 180 | (elscmd == ELS_CMD_LOGO))) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 181 | switch (elscmd) { |
| 182 | case ELS_CMD_FLOGI: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 183 | elsiocb->iocb_flag |= |
| 184 | ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 185 | & LPFC_FIP_ELS_ID_MASK); |
| 186 | break; |
| 187 | case ELS_CMD_FDISC: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 188 | elsiocb->iocb_flag |= |
| 189 | ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 190 | & LPFC_FIP_ELS_ID_MASK); |
| 191 | break; |
| 192 | case ELS_CMD_LOGO: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 193 | elsiocb->iocb_flag |= |
| 194 | ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 195 | & LPFC_FIP_ELS_ID_MASK); |
| 196 | break; |
| 197 | } |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 198 | else |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 199 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 200 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 201 | icmd = &elsiocb->iocb; |
| 202 | |
| 203 | /* fill in BDEs for command */ |
| 204 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 205 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 206 | if (pcmd) |
| 207 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 208 | if (!pcmd || !pcmd->virt) |
| 209 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | |
| 211 | INIT_LIST_HEAD(&pcmd->list); |
| 212 | |
| 213 | /* Allocate buffer for response payload */ |
| 214 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 215 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 216 | if (prsp) |
| 217 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 218 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 219 | if (!prsp || !prsp->virt) |
| 220 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 221 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 222 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 223 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 224 | |
| 225 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 226 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 227 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 228 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 229 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 230 | if (!pbuflist || !pbuflist->virt) |
| 231 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 232 | |
| 233 | INIT_LIST_HEAD(&pbuflist->list); |
| 234 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 235 | if (expectRsp) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 236 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 237 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
| 238 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 239 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 240 | |
| 241 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 242 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 243 | if (elscmd == ELS_CMD_FLOGI) |
| 244 | icmd->ulpTimeout = FF_DEF_RATOV * 2; |
| 245 | else |
| 246 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 247 | } else { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 248 | icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 249 | icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
| 250 | icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 251 | icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| 252 | icmd->un.xseq64.xmit_els_remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 253 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 254 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 255 | icmd->ulpBdeCount = 1; |
| 256 | icmd->ulpLe = 1; |
| 257 | icmd->ulpClass = CLASS3; |
| 258 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 259 | /* |
| 260 | * If we have NPIV enabled, we want to send ELS traffic by VPI. |
| 261 | * For SLI4, since the driver controls VPIs we also want to include |
| 262 | * all ELS pt2pt protocol traffic as well. |
| 263 | */ |
| 264 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) || |
| 265 | ((phba->sli_rev == LPFC_SLI_REV4) && |
| 266 | (vport->fc_flag & FC_PT2PT))) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 267 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 268 | if (expectRsp) { |
| 269 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 270 | |
| 271 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
| 272 | icmd->ulpContext = phba->vpi_ids[vport->vpi]; |
| 273 | } |
| 274 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 275 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 276 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 277 | if (elscmd == ELS_CMD_ECHO) |
| 278 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 279 | else |
| 280 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 281 | } |
| 282 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 283 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 284 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 285 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 286 | bpl->tus.f.bdeSize = cmdSize; |
| 287 | bpl->tus.f.bdeFlags = 0; |
| 288 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 289 | |
| 290 | if (expectRsp) { |
| 291 | bpl++; |
| 292 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 293 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 294 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 295 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 296 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 297 | } |
| 298 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 299 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 300 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 301 | if (!elsiocb->context1) |
| 302 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 303 | elsiocb->context2 = pcmd; |
| 304 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 305 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 306 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 307 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 308 | |
| 309 | if (prsp) { |
| 310 | list_add(&prsp->list, &pcmd->list); |
| 311 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 312 | if (expectRsp) { |
| 313 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 314 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 315 | "0116 Xmit ELS command x%x to remote " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 316 | "NPORT x%x I/O tag: x%x, port state:x%x" |
| 317 | " fc_flag:x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 318 | elscmd, did, elsiocb->iotag, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 319 | vport->port_state, |
| 320 | vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 321 | } else { |
| 322 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 323 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 324 | "0117 Xmit ELS response x%x to remote " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 325 | "NPORT x%x I/O tag: x%x, size: x%x " |
| 326 | "port_state x%x fc_flag x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 327 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 328 | cmdSize, vport->port_state, |
| 329 | vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 330 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 331 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 332 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 333 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 334 | if (expectRsp) |
| 335 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 336 | kfree(pbuflist); |
| 337 | |
| 338 | els_iocb_free_prsp_exit: |
| 339 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 340 | kfree(prsp); |
| 341 | |
| 342 | els_iocb_free_pcmb_exit: |
| 343 | kfree(pcmd); |
| 344 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 345 | return NULL; |
| 346 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 347 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 348 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 349 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 350 | * @vport: pointer to a host virtual N_Port data structure. |
| 351 | * |
| 352 | * This routine issues a fabric registration login for a @vport. An |
| 353 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 354 | * The routine invokes two mailbox commands to carry out fabric registration |
| 355 | * login through the HBA firmware: the first mailbox command requests the |
| 356 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 357 | * command requests the HBA to perform the actual fabric registration login |
| 358 | * with the @vport. |
| 359 | * |
| 360 | * Return code |
| 361 | * 0 - successfully issued fabric registration login for @vport |
| 362 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 363 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 364 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 365 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 366 | { |
| 367 | struct lpfc_hba *phba = vport->phba; |
| 368 | LPFC_MBOXQ_t *mbox; |
| 369 | struct lpfc_dmabuf *mp; |
| 370 | struct lpfc_nodelist *ndlp; |
| 371 | struct serv_parm *sp; |
| 372 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 373 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 374 | |
| 375 | sp = &phba->fc_fabparam; |
| 376 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 377 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 378 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 379 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 380 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 381 | |
| 382 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 383 | if (!mbox) { |
| 384 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 385 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 386 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 387 | |
| 388 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 389 | lpfc_config_link(phba, mbox); |
| 390 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 391 | mbox->vport = vport; |
| 392 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 393 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 394 | if (rc == MBX_NOT_FINISHED) { |
| 395 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 396 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 397 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 398 | |
| 399 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 400 | if (!mbox) { |
| 401 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 402 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 403 | } |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 404 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
| 405 | ndlp->nlp_rpi); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 406 | if (rc) { |
| 407 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 408 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 409 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 410 | |
| 411 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 412 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 413 | /* increment the reference count on ndlp to hold reference |
| 414 | * for the callback routine. |
| 415 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 416 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 417 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 418 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 419 | if (rc == MBX_NOT_FINISHED) { |
| 420 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 421 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 422 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 423 | |
| 424 | return 0; |
| 425 | |
| 426 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 427 | /* decrement the reference count on ndlp just incremented |
| 428 | * for the failed mbox command. |
| 429 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 430 | lpfc_nlp_put(ndlp); |
| 431 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 432 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 433 | kfree(mp); |
| 434 | fail_free_mbox: |
| 435 | mempool_free(mbox, phba->mbox_mem_pool); |
| 436 | |
| 437 | fail: |
| 438 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 439 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 440 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 441 | return -ENXIO; |
| 442 | } |
| 443 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 444 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 445 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 446 | * @vport: pointer to a host virtual N_Port data structure. |
| 447 | * |
| 448 | * 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] | 449 | * the @vport. This mailbox command is necessary for SLI4 port only. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 450 | * |
| 451 | * Return code |
| 452 | * 0 - successfully issued REG_VFI for @vport |
| 453 | * A failure code otherwise. |
| 454 | **/ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 455 | int |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 456 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 457 | { |
| 458 | struct lpfc_hba *phba = vport->phba; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 459 | LPFC_MBOXQ_t *mboxq = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 460 | struct lpfc_nodelist *ndlp; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 461 | struct lpfc_dmabuf *dmabuf = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 462 | int rc = 0; |
| 463 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 464 | /* 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] | 465 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 466 | !(phba->link_flag & LS_LOOPBACK_MODE) && |
| 467 | !(vport->fc_flag & FC_PT2PT)) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 468 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 469 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 470 | rc = -ENODEV; |
| 471 | goto fail; |
| 472 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 473 | } |
| 474 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 475 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 476 | if (!mboxq) { |
| 477 | rc = -ENOMEM; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 478 | goto fail; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 479 | } |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 480 | |
| 481 | /* Supply CSP's only if we are fabric connect or pt-to-pt connect */ |
| 482 | if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) { |
| 483 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 484 | if (!dmabuf) { |
| 485 | rc = -ENOMEM; |
| 486 | goto fail; |
| 487 | } |
| 488 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 489 | if (!dmabuf->virt) { |
| 490 | rc = -ENOMEM; |
| 491 | goto fail; |
| 492 | } |
| 493 | memcpy(dmabuf->virt, &phba->fc_fabparam, |
| 494 | sizeof(struct serv_parm)); |
| 495 | } |
| 496 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 497 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 498 | if (dmabuf) |
| 499 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 500 | else |
| 501 | lpfc_reg_vfi(mboxq, vport, 0); |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 502 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 503 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 504 | mboxq->vport = vport; |
| 505 | mboxq->context1 = dmabuf; |
| 506 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 507 | if (rc == MBX_NOT_FINISHED) { |
| 508 | rc = -ENXIO; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 509 | goto fail; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 510 | } |
| 511 | return 0; |
| 512 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 513 | fail: |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 514 | if (mboxq) |
| 515 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 516 | if (dmabuf) { |
| 517 | if (dmabuf->virt) |
| 518 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 519 | kfree(dmabuf); |
| 520 | } |
| 521 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 522 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 523 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 524 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 525 | return rc; |
| 526 | } |
| 527 | |
| 528 | /** |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 529 | * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login |
| 530 | * @vport: pointer to a host virtual N_Port data structure. |
| 531 | * |
| 532 | * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for |
| 533 | * the @vport. This mailbox command is necessary for SLI4 port only. |
| 534 | * |
| 535 | * Return code |
| 536 | * 0 - successfully issued REG_VFI for @vport |
| 537 | * A failure code otherwise. |
| 538 | **/ |
| 539 | int |
| 540 | lpfc_issue_unreg_vfi(struct lpfc_vport *vport) |
| 541 | { |
| 542 | struct lpfc_hba *phba = vport->phba; |
| 543 | struct Scsi_Host *shost; |
| 544 | LPFC_MBOXQ_t *mboxq; |
| 545 | int rc; |
| 546 | |
| 547 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 548 | if (!mboxq) { |
| 549 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 550 | "2556 UNREG_VFI mbox allocation failed" |
| 551 | "HBA state x%x\n", phba->pport->port_state); |
| 552 | return -ENOMEM; |
| 553 | } |
| 554 | |
| 555 | lpfc_unreg_vfi(mboxq, vport); |
| 556 | mboxq->vport = vport; |
| 557 | mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl; |
| 558 | |
| 559 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 560 | if (rc == MBX_NOT_FINISHED) { |
| 561 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 562 | "2557 UNREG_VFI issue mbox failed rc x%x " |
| 563 | "HBA state x%x\n", |
| 564 | rc, phba->pport->port_state); |
| 565 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 566 | return -EIO; |
| 567 | } |
| 568 | |
| 569 | shost = lpfc_shost_from_vport(vport); |
| 570 | spin_lock_irq(shost->host_lock); |
| 571 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 572 | spin_unlock_irq(shost->host_lock); |
| 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | /** |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 577 | * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean. |
| 578 | * @vport: pointer to a host virtual N_Port data structure. |
| 579 | * @sp: pointer to service parameter data structure. |
| 580 | * |
| 581 | * This routine is called from FLOGI/FDISC completion handler functions. |
| 582 | * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric |
| 583 | * node nodename is changed in the completion service parameter else return |
| 584 | * 0. This function also set flag in the vport data structure to delay |
| 585 | * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit |
| 586 | * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric |
| 587 | * node nodename is changed in the completion service parameter. |
| 588 | * |
| 589 | * Return code |
| 590 | * 0 - FCID and Fabric Nodename and Fabric portname is not changed. |
| 591 | * 1 - FCID or Fabric Nodename or Fabric portname is changed. |
| 592 | * |
| 593 | **/ |
| 594 | static uint8_t |
| 595 | lpfc_check_clean_addr_bit(struct lpfc_vport *vport, |
| 596 | struct serv_parm *sp) |
| 597 | { |
James Smart | 8eb8b96 | 2016-07-06 12:36:08 -0700 | [diff] [blame] | 598 | struct lpfc_hba *phba = vport->phba; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 599 | uint8_t fabric_param_changed = 0; |
| 600 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 601 | |
| 602 | if ((vport->fc_prevDID != vport->fc_myDID) || |
| 603 | memcmp(&vport->fabric_portname, &sp->portName, |
| 604 | sizeof(struct lpfc_name)) || |
| 605 | memcmp(&vport->fabric_nodename, &sp->nodeName, |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 606 | sizeof(struct lpfc_name)) || |
| 607 | (vport->vport_flag & FAWWPN_PARAM_CHG)) { |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 608 | fabric_param_changed = 1; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 609 | vport->vport_flag &= ~FAWWPN_PARAM_CHG; |
| 610 | } |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 611 | /* |
| 612 | * Word 1 Bit 31 in common service parameter is overloaded. |
| 613 | * Word 1 Bit 31 in FLOGI request is multiple NPort request |
| 614 | * Word 1 Bit 31 in FLOGI response is clean address bit |
| 615 | * |
| 616 | * If fabric parameter is changed and clean address bit is |
| 617 | * cleared delay nport discovery if |
| 618 | * - vport->fc_prevDID != 0 (not initial discovery) OR |
| 619 | * - lpfc_delay_discovery module parameter is set. |
| 620 | */ |
| 621 | if (fabric_param_changed && !sp->cmn.clean_address_bit && |
James Smart | 8eb8b96 | 2016-07-06 12:36:08 -0700 | [diff] [blame] | 622 | (vport->fc_prevDID || phba->cfg_delay_discovery)) { |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 623 | spin_lock_irq(shost->host_lock); |
| 624 | vport->fc_flag |= FC_DISC_DELAYED; |
| 625 | spin_unlock_irq(shost->host_lock); |
| 626 | } |
| 627 | |
| 628 | return fabric_param_changed; |
| 629 | } |
| 630 | |
| 631 | |
| 632 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 633 | * 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] | 634 | * @vport: pointer to a host virtual N_Port data structure. |
| 635 | * @ndlp: pointer to a node-list data structure. |
| 636 | * @sp: pointer to service parameter data structure. |
| 637 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 638 | * |
| 639 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 640 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 641 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 642 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 643 | * @vport against the previously assigned N_Port ID. If it is different from |
| 644 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 645 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 646 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 647 | * is invoked to register login to the fabric. |
| 648 | * |
| 649 | * Return code |
| 650 | * 0 - Success (currently, always return 0) |
| 651 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 652 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 653 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 654 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 655 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 656 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 657 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 658 | struct lpfc_nodelist *np; |
| 659 | struct lpfc_nodelist *next_np; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 660 | uint8_t fabric_param_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 661 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 662 | spin_lock_irq(shost->host_lock); |
| 663 | vport->fc_flag |= FC_FABRIC; |
| 664 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 665 | |
| 666 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 667 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 668 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 669 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 670 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 671 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 672 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 673 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 674 | spin_lock_irq(shost->host_lock); |
| 675 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 676 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 677 | } |
| 678 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 679 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 680 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 681 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 682 | ndlp->nlp_class_sup = 0; |
| 683 | if (sp->cls1.classValid) |
| 684 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 685 | if (sp->cls2.classValid) |
| 686 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 687 | if (sp->cls3.classValid) |
| 688 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 689 | if (sp->cls4.classValid) |
| 690 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 691 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 692 | sp->cmn.bbRcvSizeLsb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 693 | |
| 694 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 695 | if (fabric_param_changed) { |
| 696 | /* Reset FDMI attribute masks based on config parameter */ |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 697 | if (phba->cfg_enable_SmartSAN || |
| 698 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 699 | /* Setup appropriate attribute masks */ |
| 700 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 701 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 702 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 703 | else |
| 704 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 705 | } else { |
| 706 | vport->fdmi_hba_mask = 0; |
| 707 | vport->fdmi_port_mask = 0; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | } |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 711 | memcpy(&vport->fabric_portname, &sp->portName, |
| 712 | sizeof(struct lpfc_name)); |
| 713 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 714 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 715 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 716 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 717 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 718 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 719 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 720 | LOG_ELS | LOG_VPORT, |
| 721 | "1816 FLOGI NPIV supported, " |
| 722 | "response data 0x%x\n", |
| 723 | sp->cmn.response_multiple_NPort); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 724 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 725 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 726 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 727 | } else { |
| 728 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 729 | to call reg_vnpid atleast for the physcial host */ |
| 730 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 731 | LOG_ELS | LOG_VPORT, |
| 732 | "1817 Fabric does not support NPIV " |
| 733 | "- configuring single port mode.\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 734 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 735 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 736 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 740 | /* |
| 741 | * For FC we need to do some special processing because of the SLI |
| 742 | * Port's default settings of the Common Service Parameters. |
| 743 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 744 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 745 | (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) { |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 746 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 747 | if (fabric_param_changed) |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 748 | lpfc_unregister_fcf_prep(phba); |
| 749 | |
| 750 | /* This should just update the VFI CSPs*/ |
| 751 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 752 | lpfc_issue_reg_vfi(vport); |
| 753 | } |
| 754 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 755 | if (fabric_param_changed && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 756 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 757 | |
| 758 | /* If our NportID changed, we need to ensure all |
| 759 | * remaining NPORTs get unreg_login'ed. |
| 760 | */ |
| 761 | list_for_each_entry_safe(np, next_np, |
| 762 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 763 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 764 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 765 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 766 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 767 | continue; |
| 768 | spin_lock_irq(shost->host_lock); |
| 769 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 770 | spin_unlock_irq(shost->host_lock); |
| 771 | lpfc_unreg_rpi(vport, np); |
| 772 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 773 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 774 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 775 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 776 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 777 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 778 | spin_lock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 779 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 780 | spin_unlock_irq(shost->host_lock); |
| 781 | } |
James Smart | 27aa1b7 | 2012-05-09 21:18:49 -0400 | [diff] [blame] | 782 | |
| 783 | /* |
| 784 | * For SLI3 and SLI4, the VPI needs to be reregistered in |
| 785 | * response to this fabric parameter change event. |
| 786 | */ |
| 787 | spin_lock_irq(shost->host_lock); |
| 788 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 789 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 790 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 791 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 792 | /* |
| 793 | * Driver needs to re-reg VPI in order for f/w |
| 794 | * to update the MAC address. |
| 795 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 796 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 797 | lpfc_register_new_vport(phba, vport, ndlp); |
| 798 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 799 | } |
| 800 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 801 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 802 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 803 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 804 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 805 | lpfc_register_new_vport(phba, vport, ndlp); |
| 806 | else |
| 807 | lpfc_issue_fabric_reglogin(vport); |
| 808 | } else { |
| 809 | ndlp->nlp_type |= NLP_FABRIC; |
| 810 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 811 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 812 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 813 | lpfc_start_fdiscs(phba); |
| 814 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 815 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 816 | lpfc_issue_init_vpi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 817 | else { |
| 818 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 819 | "3135 Need register VFI: (x%x/%x)\n", |
| 820 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 821 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 822 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 823 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 824 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 825 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 826 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 827 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 828 | * 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] | 829 | * @vport: pointer to a host virtual N_Port data structure. |
| 830 | * @ndlp: pointer to a node-list data structure. |
| 831 | * @sp: pointer to service parameter data structure. |
| 832 | * |
| 833 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 834 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 835 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 836 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 837 | * the received N_Port Name lexicographically, this node shall assign local |
| 838 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 839 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 840 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 841 | * N_Port IDs. |
| 842 | * |
| 843 | * Return code |
| 844 | * 0 - Success |
| 845 | * -ENXIO - Fail |
| 846 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 847 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 848 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 849 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 850 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 851 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 852 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 853 | LPFC_MBOXQ_t *mbox; |
| 854 | int rc; |
| 855 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 856 | spin_lock_irq(shost->host_lock); |
| 857 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 858 | vport->fc_flag |= FC_PT2PT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 859 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 860 | |
James Smart | d33d0eb | 2017-11-20 16:00:34 -0800 | [diff] [blame] | 861 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 862 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 863 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 864 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
| 865 | if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) { |
| 866 | lpfc_unregister_fcf_prep(phba); |
| 867 | |
| 868 | spin_lock_irq(shost->host_lock); |
| 869 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 870 | spin_unlock_irq(shost->host_lock); |
| 871 | phba->fc_topology_changed = 0; |
| 872 | } |
| 873 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 874 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 875 | sizeof(vport->fc_portname)); |
James Smart | 2eb6862 | 2012-09-29 11:32:27 -0400 | [diff] [blame] | 876 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 877 | if (rc >= 0) { |
| 878 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 879 | spin_lock_irq(shost->host_lock); |
| 880 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 881 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 882 | |
| 883 | /* |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 884 | * N_Port ID cannot be 0, set our Id to LocalID |
| 885 | * the other side will be RemoteID. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 886 | */ |
| 887 | |
| 888 | /* not equal */ |
| 889 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 890 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 891 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 892 | /* Decrement ndlp reference count indicating that ndlp can be |
| 893 | * safely released when other references to it are done. |
| 894 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 895 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 896 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 897 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 898 | if (!ndlp) { |
| 899 | /* |
| 900 | * Cannot find existing Fabric ndlp, so allocate a |
| 901 | * new one |
| 902 | */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 903 | ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 904 | if (!ndlp) |
| 905 | goto fail; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 906 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 907 | ndlp = lpfc_enable_node(vport, ndlp, |
| 908 | NLP_STE_UNUSED_NODE); |
| 909 | if(!ndlp) |
| 910 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 914 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 915 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 916 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 917 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 918 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 919 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 920 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 921 | spin_unlock_irq(shost->host_lock); |
James Smart | d33d0eb | 2017-11-20 16:00:34 -0800 | [diff] [blame] | 922 | |
| 923 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 924 | if (!mbox) |
| 925 | goto fail; |
| 926 | |
| 927 | lpfc_config_link(phba, mbox); |
| 928 | |
| 929 | mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
| 930 | mbox->vport = vport; |
| 931 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 932 | if (rc == MBX_NOT_FINISHED) { |
| 933 | mempool_free(mbox, phba->mbox_mem_pool); |
| 934 | goto fail; |
| 935 | } |
| 936 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 937 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 938 | * count indicating that ndlp can be released when other |
| 939 | * references to it are done. |
| 940 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 941 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 942 | |
James Smart | d33d0eb | 2017-11-20 16:00:34 -0800 | [diff] [blame] | 943 | /* Start discovery - this should just do CLEAR_LA */ |
| 944 | lpfc_disc_start(vport); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 945 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 946 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 947 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 948 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 949 | return -ENXIO; |
| 950 | } |
| 951 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 952 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 953 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 954 | * @phba: pointer to lpfc hba data structure. |
| 955 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 956 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 957 | * |
| 958 | * This routine is the top-level completion callback function for issuing |
| 959 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 960 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 961 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 962 | * returning 1), the command IOCB will be released and function returned. |
| 963 | * If the retry attempt has been given up (possibly reach the maximum |
| 964 | * number of retries), one additional decrement of ndlp reference shall be |
| 965 | * invoked before going out after releasing the command IOCB. This will |
| 966 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 967 | * invoke one decrement of ndlp reference count). If no error reported in |
| 968 | * the IOCB status, the command Port ID field is used to determine whether |
| 969 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 970 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 971 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 972 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 973 | * specific topology completion conditions. |
| 974 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 975 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 976 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 977 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 978 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 979 | struct lpfc_vport *vport = cmdiocb->vport; |
| 980 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 981 | IOCB_t *irsp = &rspiocb->iocb; |
| 982 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 983 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 984 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 985 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 986 | int rc; |
| 987 | |
| 988 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 989 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 990 | /* One additional decrement on node reference count to |
| 991 | * trigger the release of the node |
| 992 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 993 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 994 | goto out; |
| 995 | } |
| 996 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 997 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 998 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 999 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1000 | vport->port_state); |
| 1001 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1002 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1003 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1004 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1005 | * due to new FCF discovery |
| 1006 | */ |
| 1007 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1008 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 1009 | if (phba->link_state < LPFC_LINK_UP) |
| 1010 | goto stop_rr_fcf_flogi; |
| 1011 | if ((phba->fcoe_cvl_eventtag_attn == |
| 1012 | phba->fcoe_cvl_eventtag) && |
| 1013 | (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1014 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1015 | IOERR_SLI_ABORTED)) |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1016 | goto stop_rr_fcf_flogi; |
| 1017 | else |
| 1018 | phba->fcoe_cvl_eventtag_attn = |
| 1019 | phba->fcoe_cvl_eventtag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1020 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1021 | "2611 FLOGI failed on FCF (x%x), " |
| 1022 | "status:x%x/x%x, tmo:x%x, perform " |
| 1023 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1024 | phba->fcf.current_rec.fcf_indx, |
| 1025 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1026 | irsp->ulpTimeout); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1027 | lpfc_sli4_set_fcf_flogi_fail(phba, |
| 1028 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1029 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1030 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 1031 | if (rc) |
| 1032 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1033 | } |
| 1034 | |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1035 | stop_rr_fcf_flogi: |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1036 | /* FLOGI failure */ |
James Smart | c73455e | 2017-11-20 16:00:28 -0800 | [diff] [blame] | 1037 | if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 1038 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1039 | IOERR_LOOP_OPEN_FAILURE))) |
| 1040 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1041 | "2858 FLOGI failure Status:x%x/x%x " |
| 1042 | "TMO:x%x Data x%x x%x\n", |
| 1043 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1044 | irsp->ulpTimeout, phba->hba_flag, |
| 1045 | phba->fcf.fcf_flag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1046 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1047 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1048 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1049 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1050 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 1051 | /* If this is not a loop open failure, bail out */ |
| 1052 | if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 1053 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1054 | IOERR_LOOP_OPEN_FAILURE))) |
| 1055 | goto flogifail; |
| 1056 | |
James Smart | c73455e | 2017-11-20 16:00:28 -0800 | [diff] [blame] | 1057 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 1058 | "0150 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 1059 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1060 | irsp->ulpTimeout); |
| 1061 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1062 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1063 | spin_lock_irq(shost->host_lock); |
| 1064 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 1065 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1066 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1067 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1068 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 1069 | * alpa map would take too long otherwise. |
| 1070 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1071 | if (phba->alpa_map[0] == 0) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1072 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1073 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1074 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1075 | (vport->fc_prevDID != vport->fc_myDID) || |
| 1076 | phba->fc_topology_changed)) { |
| 1077 | if (vport->fc_flag & FC_VFI_REGISTERED) { |
| 1078 | if (phba->fc_topology_changed) { |
| 1079 | lpfc_unregister_fcf_prep(phba); |
| 1080 | spin_lock_irq(shost->host_lock); |
| 1081 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 1082 | spin_unlock_irq(shost->host_lock); |
| 1083 | phba->fc_topology_changed = 0; |
| 1084 | } else { |
| 1085 | lpfc_sli4_unreg_all_rpis(vport); |
| 1086 | } |
| 1087 | } |
James Smart | 342b59c | 2016-03-31 14:12:31 -0700 | [diff] [blame] | 1088 | |
| 1089 | /* Do not register VFI if the driver aborted FLOGI */ |
| 1090 | if (!lpfc_error_lost_link(irsp)) |
| 1091 | lpfc_issue_reg_vfi(vport); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1092 | lpfc_nlp_put(ndlp); |
| 1093 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1094 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1095 | goto flogifail; |
| 1096 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1097 | spin_lock_irq(shost->host_lock); |
| 1098 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 1099 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1100 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1101 | |
| 1102 | /* |
| 1103 | * The FLogI succeeded. Sync the data for the CPU before |
| 1104 | * accessing it. |
| 1105 | */ |
| 1106 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 1107 | if (!prsp) |
| 1108 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1109 | sp = prsp->virt + sizeof(uint32_t); |
| 1110 | |
| 1111 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1112 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 1113 | "0101 FLOGI completes successfully, I/O tag:x%x, " |
| 1114 | "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1115 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1116 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution, |
| 1117 | vport->port_state, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1118 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1119 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1120 | /* |
| 1121 | * If Common Service Parameters indicate Nport |
| 1122 | * we are point to point, if Fport we are Fabric. |
| 1123 | */ |
| 1124 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1125 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1126 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1127 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1128 | else { |
| 1129 | lpfc_printf_vlog(vport, KERN_ERR, |
| 1130 | LOG_FIP | LOG_ELS, |
| 1131 | "2831 FLOGI response with cleared Fabric " |
| 1132 | "bit fcf_index 0x%x " |
| 1133 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 1134 | "Fabric Name " |
| 1135 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 1136 | phba->fcf.current_rec.fcf_indx, |
| 1137 | phba->fcf.current_rec.switch_name[0], |
| 1138 | phba->fcf.current_rec.switch_name[1], |
| 1139 | phba->fcf.current_rec.switch_name[2], |
| 1140 | phba->fcf.current_rec.switch_name[3], |
| 1141 | phba->fcf.current_rec.switch_name[4], |
| 1142 | phba->fcf.current_rec.switch_name[5], |
| 1143 | phba->fcf.current_rec.switch_name[6], |
| 1144 | phba->fcf.current_rec.switch_name[7], |
| 1145 | phba->fcf.current_rec.fabric_name[0], |
| 1146 | phba->fcf.current_rec.fabric_name[1], |
| 1147 | phba->fcf.current_rec.fabric_name[2], |
| 1148 | phba->fcf.current_rec.fabric_name[3], |
| 1149 | phba->fcf.current_rec.fabric_name[4], |
| 1150 | phba->fcf.current_rec.fabric_name[5], |
| 1151 | phba->fcf.current_rec.fabric_name[6], |
| 1152 | phba->fcf.current_rec.fabric_name[7]); |
| 1153 | lpfc_nlp_put(ndlp); |
| 1154 | spin_lock_irq(&phba->hbalock); |
| 1155 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1156 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1157 | spin_unlock_irq(&phba->hbalock); |
| 1158 | goto out; |
| 1159 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1160 | if (!rc) { |
| 1161 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1162 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 1163 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 1164 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1165 | "2769 FLOGI to FCF (x%x) " |
| 1166 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1167 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1168 | spin_lock_irq(&phba->hbalock); |
| 1169 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1170 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1171 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1172 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1173 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | flogifail: |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1177 | spin_lock_irq(&phba->hbalock); |
| 1178 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 1179 | spin_unlock_irq(&phba->hbalock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1180 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1181 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1182 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1183 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1184 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1185 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1186 | |
| 1187 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1188 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1189 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1190 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1191 | IOERR_SLI_ABORTED) && |
| 1192 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1193 | IOERR_SLI_DOWN))) && |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1194 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 1195 | /* If FLOGI failed enable link interrupt. */ |
| 1196 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1197 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1198 | out: |
| 1199 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1200 | } |
| 1201 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1202 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1203 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1204 | * @vport: pointer to a host virtual N_Port data structure. |
| 1205 | * @ndlp: pointer to a node-list data structure. |
| 1206 | * @retry: number of retries to the command IOCB. |
| 1207 | * |
| 1208 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 1209 | * for a @vport. The initiator service parameters are put into the payload |
| 1210 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 1211 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 1212 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 1213 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 1214 | * |
| 1215 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1216 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1217 | * will be stored into the context1 field of the IOCB for the completion |
| 1218 | * callback function to the FLOGI ELS command. |
| 1219 | * |
| 1220 | * Return code |
| 1221 | * 0 - successfully issued flogi iocb for @vport |
| 1222 | * 1 - failed to issue flogi iocb for @vport |
| 1223 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1224 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1225 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1226 | uint8_t retry) |
| 1227 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1228 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1229 | struct serv_parm *sp; |
| 1230 | IOCB_t *icmd; |
| 1231 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | uint8_t *pcmd; |
| 1233 | uint16_t cmdsize; |
| 1234 | uint32_t tmo; |
| 1235 | int rc; |
| 1236 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1237 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1238 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1239 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1240 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1241 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1242 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | |
| 1244 | icmd = &elsiocb->iocb; |
| 1245 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1246 | |
| 1247 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1248 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1249 | pcmd += sizeof(uint32_t); |
| 1250 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1251 | sp = (struct serv_parm *) pcmd; |
| 1252 | |
| 1253 | /* Setup CSPs accordingly for Fabric */ |
| 1254 | sp->cmn.e_d_tov = 0; |
| 1255 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 1256 | sp->cmn.virtual_fabric_support = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1257 | sp->cls1.classValid = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1258 | if (sp->cmn.fcphLow < FC_PH3) |
| 1259 | sp->cmn.fcphLow = FC_PH3; |
| 1260 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1261 | sp->cmn.fcphHigh = FC_PH3; |
| 1262 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 1263 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1264 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1265 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 1266 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1267 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1268 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1269 | /* Set the fcfi to the fcfi we registered with */ |
| 1270 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1271 | } |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1272 | /* Can't do SLI4 class2 without support sequence coalescing */ |
| 1273 | sp->cls2.classValid = 0; |
| 1274 | sp->cls2.seqDelivery = 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1275 | } else { |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1276 | /* Historical, setting sequential-delivery bit for SLI3 */ |
| 1277 | sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; |
| 1278 | sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1279 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 1280 | sp->cmn.request_multiple_Nport = 1; |
| 1281 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1282 | icmd->ulpCt_h = 1; |
| 1283 | icmd->ulpCt_l = 0; |
| 1284 | } else |
| 1285 | sp->cmn.request_multiple_Nport = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1286 | } |
| 1287 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1288 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1289 | icmd->un.elsreq64.myID = 0; |
| 1290 | icmd->un.elsreq64.fl = 1; |
| 1291 | } |
| 1292 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1293 | tmo = phba->fc_ratov; |
| 1294 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1295 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1296 | phba->fc_ratov = tmo; |
| 1297 | |
| 1298 | phba->fc_stat.elsXmitFLOGI++; |
| 1299 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1300 | |
| 1301 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1302 | "Issue FLOGI: opt:x%x", |
| 1303 | phba->sli3_options, 0, 0); |
| 1304 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1305 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1306 | if (rc == IOCB_ERROR) { |
| 1307 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1308 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1309 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1310 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1311 | } |
| 1312 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1313 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1314 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1315 | * @phba: pointer to lpfc hba data structure. |
| 1316 | * |
| 1317 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1318 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1319 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1320 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1321 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1322 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1323 | * |
| 1324 | * Return code |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1325 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1326 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1327 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1328 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1329 | { |
| 1330 | struct lpfc_sli_ring *pring; |
| 1331 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1332 | struct lpfc_nodelist *ndlp; |
| 1333 | IOCB_t *icmd; |
| 1334 | |
| 1335 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1336 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1337 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1338 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1339 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1340 | pring = lpfc_phba_elsring(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1341 | |
| 1342 | /* |
| 1343 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1344 | * searching for. |
| 1345 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1346 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1347 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1348 | icmd = &iocb->iocb; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1349 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1350 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1351 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1352 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1353 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1354 | } |
| 1355 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1356 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1357 | |
| 1358 | return 0; |
| 1359 | } |
| 1360 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1361 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1362 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1363 | * @vport: pointer to a host virtual N_Port data structure. |
| 1364 | * |
| 1365 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1366 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1367 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1368 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1369 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1370 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1371 | * @vport. |
| 1372 | * |
| 1373 | * Return code |
| 1374 | * 0 - failed to issue initial flogi for @vport |
| 1375 | * 1 - successfully issued initial flogi for @vport |
| 1376 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1377 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1378 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1379 | { |
| 1380 | struct lpfc_nodelist *ndlp; |
| 1381 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1382 | vport->port_state = LPFC_FLOGI; |
| 1383 | lpfc_set_disctmo(vport); |
| 1384 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1385 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1386 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1387 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1388 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1389 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1390 | if (!ndlp) |
| 1391 | return 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1392 | /* Set the node type */ |
| 1393 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1394 | /* Put ndlp onto node list */ |
| 1395 | lpfc_enqueue_node(vport, ndlp); |
| 1396 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1397 | /* re-setup ndlp without removing from node list */ |
| 1398 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1399 | if (!ndlp) |
| 1400 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1401 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1402 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1403 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1404 | /* This decrement of reference count to node shall kick off |
| 1405 | * the release of the node. |
| 1406 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1407 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1408 | return 0; |
| 1409 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1410 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1411 | } |
| 1412 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1413 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1414 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1415 | * @vport: pointer to a host virtual N_Port data structure. |
| 1416 | * |
| 1417 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1418 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1419 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1420 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1421 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1422 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1423 | * @vport. |
| 1424 | * |
| 1425 | * Return code |
| 1426 | * 0 - failed to issue initial fdisc for @vport |
| 1427 | * 1 - successfully issued initial fdisc for @vport |
| 1428 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1429 | int |
| 1430 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1431 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1432 | struct lpfc_nodelist *ndlp; |
| 1433 | |
| 1434 | /* First look for the Fabric ndlp */ |
| 1435 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1436 | if (!ndlp) { |
| 1437 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1438 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1439 | if (!ndlp) |
| 1440 | return 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1441 | /* Put ndlp onto node list */ |
| 1442 | lpfc_enqueue_node(vport, ndlp); |
| 1443 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1444 | /* re-setup ndlp without removing from node list */ |
| 1445 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1446 | if (!ndlp) |
| 1447 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1448 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1449 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1450 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1451 | /* decrement node reference count to trigger the release of |
| 1452 | * the node. |
| 1453 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1454 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1455 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1456 | } |
| 1457 | return 1; |
| 1458 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1459 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1460 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1461 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1462 | * @vport: pointer to a host virtual N_Port data structure. |
| 1463 | * |
| 1464 | * This routine checks whether there are more remaining Port Logins |
| 1465 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1466 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1467 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1468 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1469 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1470 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1471 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1472 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1473 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1474 | if (vport->num_disc_nodes) |
| 1475 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1476 | |
| 1477 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1478 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1479 | "0232 Continue discovery with %d PLOGIs to go " |
| 1480 | "Data: x%x x%x x%x\n", |
| 1481 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1482 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1483 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1484 | if (vport->fc_flag & FC_NLP_MORE) |
| 1485 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 1486 | lpfc_els_disc_plogi(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1487 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1488 | return; |
| 1489 | } |
| 1490 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1491 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1492 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1493 | * @phba: pointer to lpfc hba data structure. |
| 1494 | * @prsp: pointer to response IOCB payload. |
| 1495 | * @ndlp: pointer to a node-list data structure. |
| 1496 | * |
| 1497 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1498 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1499 | * The following cases are considered N_Port confirmed: |
| 1500 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1501 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1502 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1503 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1504 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1505 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1506 | * on that node to release the RPI associated with the node; 2) if there is |
| 1507 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1508 | * into, a new node shall be allocated (or activated). In either case, the |
| 1509 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1510 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1511 | * its pointer returned as the confirmed node. |
| 1512 | * |
| 1513 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1514 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1515 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1516 | * into an inactive state on the vport node list and the vport node list |
| 1517 | * management algorithm does not allow two node with a same DID. |
| 1518 | * |
| 1519 | * Return code |
| 1520 | * pointer to the PLOGI N_Port @ndlp |
| 1521 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1522 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1523 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1524 | struct lpfc_nodelist *ndlp) |
| 1525 | { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1526 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1527 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1528 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1529 | struct lpfc_rport_data *rdata; |
| 1530 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1531 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1532 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1533 | uint32_t rc, keepDID = 0, keep_nlp_flag = 0; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1534 | uint16_t keep_nlp_state; |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1535 | struct lpfc_nvme_rport *keep_nrport = NULL; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1536 | int put_node; |
| 1537 | int put_rport; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1538 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1539 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1540 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1541 | * by WWPN. Just return the ndlp that was given to us. |
| 1542 | */ |
| 1543 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1544 | return ndlp; |
| 1545 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1546 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1547 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1548 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1549 | /* 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] | 1550 | * we have for that ndlp. If not, we have some work to do. |
| 1551 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1552 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1553 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1554 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1555 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1556 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1557 | active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool, |
| 1558 | GFP_KERNEL); |
| 1559 | if (active_rrqs_xri_bitmap) |
| 1560 | memset(active_rrqs_xri_bitmap, 0, |
| 1561 | phba->cfg_rrq_xri_bitmap_sz); |
| 1562 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1563 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1564 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1565 | "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n", |
| 1566 | ndlp, ndlp->nlp_DID, new_ndlp); |
| 1567 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1568 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1569 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1570 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1571 | if (!rc) { |
| 1572 | if (active_rrqs_xri_bitmap) |
| 1573 | mempool_free(active_rrqs_xri_bitmap, |
| 1574 | phba->active_rrq_pool); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1575 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1576 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1577 | new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1578 | if (!new_ndlp) { |
| 1579 | if (active_rrqs_xri_bitmap) |
| 1580 | mempool_free(active_rrqs_xri_bitmap, |
| 1581 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1582 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1583 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1584 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1585 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1586 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1587 | if (!rc) { |
| 1588 | if (active_rrqs_xri_bitmap) |
| 1589 | mempool_free(active_rrqs_xri_bitmap, |
| 1590 | phba->active_rrq_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1591 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1592 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1593 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1594 | NLP_STE_UNUSED_NODE); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1595 | if (!new_ndlp) { |
| 1596 | if (active_rrqs_xri_bitmap) |
| 1597 | mempool_free(active_rrqs_xri_bitmap, |
| 1598 | phba->active_rrq_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1599 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1600 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1601 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1602 | if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap) |
| 1603 | memcpy(active_rrqs_xri_bitmap, |
| 1604 | new_ndlp->active_rrqs_xri_bitmap, |
| 1605 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1606 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1607 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1608 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1609 | active_rrqs_xri_bitmap) |
| 1610 | memcpy(active_rrqs_xri_bitmap, |
| 1611 | new_ndlp->active_rrqs_xri_bitmap, |
| 1612 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1613 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1614 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1615 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1616 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1617 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1618 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1619 | memcpy(new_ndlp->active_rrqs_xri_bitmap, |
| 1620 | ndlp->active_rrqs_xri_bitmap, |
| 1621 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1622 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1623 | spin_lock_irq(shost->host_lock); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1624 | keep_nlp_flag = new_ndlp->nlp_flag; |
| 1625 | new_ndlp->nlp_flag = ndlp->nlp_flag; |
| 1626 | ndlp->nlp_flag = keep_nlp_flag; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1627 | spin_unlock_irq(shost->host_lock); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1628 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1629 | /* Set nlp_states accordingly */ |
| 1630 | keep_nlp_state = new_ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1631 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1632 | |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1633 | /* interchange the nvme remoteport structs */ |
| 1634 | keep_nrport = new_ndlp->nrport; |
| 1635 | new_ndlp->nrport = ndlp->nrport; |
| 1636 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1637 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1638 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1639 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1640 | * to put ndlp on UNUSED list and try to free it. |
| 1641 | */ |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1642 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1643 | "3179 PLOGI confirm NEW: %x %x\n", |
| 1644 | new_ndlp->nlp_DID, keepDID); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1645 | |
| 1646 | /* Fix up the rport accordingly */ |
| 1647 | rport = ndlp->rport; |
| 1648 | if (rport) { |
| 1649 | rdata = rport->dd_data; |
| 1650 | if (rdata->pnode == ndlp) { |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1651 | /* break the link before dropping the ref */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1652 | ndlp->rport = NULL; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1653 | lpfc_nlp_put(ndlp); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1654 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1655 | new_ndlp->rport = rport; |
| 1656 | } |
| 1657 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1658 | } |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1659 | |
| 1660 | /* Fix up the nvme rport */ |
| 1661 | if (ndlp->nrport) { |
| 1662 | ndlp->nrport = NULL; |
| 1663 | lpfc_nlp_put(ndlp); |
| 1664 | } |
| 1665 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1666 | /* We shall actually free the ndlp with both nlp_DID and |
| 1667 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1668 | * nodelist never to be used. |
| 1669 | */ |
| 1670 | if (ndlp->nlp_DID == 0) { |
| 1671 | spin_lock_irq(&phba->ndlp_lock); |
| 1672 | NLP_SET_FREE_REQ(ndlp); |
| 1673 | spin_unlock_irq(&phba->ndlp_lock); |
| 1674 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1675 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1676 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1677 | ndlp->nlp_DID = keepDID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1678 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1679 | active_rrqs_xri_bitmap) |
| 1680 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1681 | active_rrqs_xri_bitmap, |
| 1682 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1683 | |
| 1684 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 1685 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1686 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1687 | else { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1688 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1689 | "3180 PLOGI confirm SWAP: %x %x\n", |
| 1690 | new_ndlp->nlp_DID, keepDID); |
| 1691 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1692 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1693 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1694 | /* Two ndlps cannot have the same did */ |
| 1695 | ndlp->nlp_DID = keepDID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1696 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1697 | active_rrqs_xri_bitmap) |
| 1698 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1699 | active_rrqs_xri_bitmap, |
| 1700 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1701 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1702 | /* Since we are switching over to the new_ndlp, |
| 1703 | * reset the old ndlp state |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1704 | */ |
| 1705 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 1706 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1707 | keep_nlp_state = NLP_STE_NPR_NODE; |
| 1708 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1709 | |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1710 | /* Previous ndlp no longer active with nvme host transport. |
| 1711 | * Remove reference from earlier registration unless the |
| 1712 | * nvme host took care of it. |
| 1713 | */ |
| 1714 | if (ndlp->nrport) |
| 1715 | lpfc_nlp_put(ndlp); |
| 1716 | ndlp->nrport = keep_nrport; |
| 1717 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1718 | /* Fix up the rport accordingly */ |
| 1719 | rport = ndlp->rport; |
| 1720 | if (rport) { |
| 1721 | rdata = rport->dd_data; |
| 1722 | put_node = rdata->pnode != NULL; |
| 1723 | put_rport = ndlp->rport != NULL; |
| 1724 | rdata->pnode = NULL; |
| 1725 | ndlp->rport = NULL; |
| 1726 | if (put_node) |
| 1727 | lpfc_nlp_put(ndlp); |
| 1728 | if (put_rport) |
| 1729 | put_device(&rport->dev); |
| 1730 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1731 | } |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1732 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1733 | active_rrqs_xri_bitmap) |
| 1734 | mempool_free(active_rrqs_xri_bitmap, |
| 1735 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1736 | return new_ndlp; |
| 1737 | } |
| 1738 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1739 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1740 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1741 | * @vport: pointer to a host virtual N_Port data structure. |
| 1742 | * |
| 1743 | * This routine checks whether more Registration State Change |
| 1744 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1745 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1746 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1747 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1748 | * handling the RSCNs. |
| 1749 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1750 | void |
| 1751 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1752 | { |
| 1753 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1754 | |
| 1755 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1756 | /* |
| 1757 | * Check to see if more RSCNs came in while we were |
| 1758 | * processing this one. |
| 1759 | */ |
| 1760 | if (vport->fc_rscn_id_cnt || |
| 1761 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1762 | lpfc_els_handle_rscn(vport); |
| 1763 | else { |
| 1764 | spin_lock_irq(shost->host_lock); |
| 1765 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1766 | spin_unlock_irq(shost->host_lock); |
| 1767 | } |
| 1768 | } |
| 1769 | } |
| 1770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1771 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1772 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. |
| 1773 | * @phba: pointer to lpfc hba data structure. |
| 1774 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1775 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1776 | * |
| 1777 | * This routine will call the clear rrq function to free the rrq and |
| 1778 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not |
| 1779 | * exist then the clear_rrq is still called because the rrq needs to |
| 1780 | * be freed. |
| 1781 | **/ |
| 1782 | |
| 1783 | static void |
| 1784 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1785 | struct lpfc_iocbq *rspiocb) |
| 1786 | { |
| 1787 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1788 | IOCB_t *irsp; |
| 1789 | struct lpfc_nodelist *ndlp; |
| 1790 | struct lpfc_node_rrq *rrq; |
| 1791 | |
| 1792 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1793 | rrq = cmdiocb->context_un.rrq; |
| 1794 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1795 | |
| 1796 | irsp = &rspiocb->iocb; |
| 1797 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1798 | "RRQ cmpl: status:x%x/x%x did:x%x", |
| 1799 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1800 | irsp->un.elsreq64.remoteID); |
| 1801 | |
| 1802 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
| 1803 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { |
| 1804 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1805 | "2882 RRQ completes to NPort x%x " |
| 1806 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1807 | irsp->un.elsreq64.remoteID, |
| 1808 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1809 | irsp->ulpIoTag); |
| 1810 | goto out; |
| 1811 | } |
| 1812 | |
| 1813 | /* rrq completes to NPort <nlp_DID> */ |
| 1814 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1815 | "2880 RRQ completes to NPort x%x " |
| 1816 | "Data: x%x x%x x%x x%x x%x\n", |
| 1817 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1818 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); |
| 1819 | |
| 1820 | if (irsp->ulpStatus) { |
| 1821 | /* Check for retry */ |
| 1822 | /* RRQ failed Don't print the vport to vport rjts */ |
| 1823 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1824 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1825 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1826 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1827 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1828 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", |
| 1829 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1830 | irsp->un.ulpWord[4]); |
| 1831 | } |
| 1832 | out: |
| 1833 | if (rrq) |
| 1834 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1835 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1836 | return; |
| 1837 | } |
| 1838 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1839 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1840 | * @phba: pointer to lpfc hba data structure. |
| 1841 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1842 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1843 | * |
| 1844 | * This routine is the completion callback function for issuing the Port |
| 1845 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1846 | * 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] | 1847 | * 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] | 1848 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1849 | * checked for error conditons. If there is error status reported, PLOGI |
| 1850 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1851 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1852 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1853 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1854 | * there are additional N_Port nodes with the vport that need to perform |
| 1855 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1856 | * PLOGIs. |
| 1857 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1858 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1859 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1860 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1861 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1862 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1863 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1864 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1865 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1866 | struct lpfc_dmabuf *prsp; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 1867 | int disc, rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1868 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1869 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1870 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1871 | |
| 1872 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1873 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1874 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1875 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1876 | irsp->un.elsreq64.remoteID); |
| 1877 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1878 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1879 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1880 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1881 | "0136 PLOGI completes to NPort x%x " |
| 1882 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1883 | irsp->un.elsreq64.remoteID, |
| 1884 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1885 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1886 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1887 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1888 | |
| 1889 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1890 | * is being used during discovery. |
| 1891 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1892 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1893 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1894 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1895 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1896 | rc = 0; |
| 1897 | |
| 1898 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1899 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1900 | "0102 PLOGI completes to NPort x%06x " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1901 | "Data: x%x x%x x%x x%x x%x\n", |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1902 | ndlp->nlp_DID, ndlp->nlp_fc4_type, |
| 1903 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1904 | disc, vport->num_disc_nodes); |
| 1905 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1906 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1907 | if (lpfc_els_chk_latt(vport)) { |
| 1908 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1909 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1910 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1911 | goto out; |
| 1912 | } |
| 1913 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1914 | if (irsp->ulpStatus) { |
| 1915 | /* Check for retry */ |
| 1916 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1917 | /* ELS command is being retried */ |
| 1918 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1919 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1920 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1921 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1922 | } |
| 1923 | goto out; |
| 1924 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1925 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1926 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1927 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1928 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1929 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1930 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1931 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1932 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1933 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1934 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1935 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1936 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1937 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1938 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1939 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1940 | } else { |
| 1941 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1942 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1943 | cmdiocb->context2)->list.next, |
| 1944 | struct lpfc_dmabuf, list); |
| 1945 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1946 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1947 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1948 | } |
| 1949 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1950 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1951 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1952 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1953 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1954 | if (vport->num_disc_nodes == 0) { |
| 1955 | spin_lock_irq(shost->host_lock); |
| 1956 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1957 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1958 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1959 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1960 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1961 | } |
| 1962 | } |
| 1963 | |
| 1964 | out: |
| 1965 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1966 | return; |
| 1967 | } |
| 1968 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1969 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1970 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1971 | * @vport: pointer to a host virtual N_Port data structure. |
| 1972 | * @did: destination port identifier. |
| 1973 | * @retry: number of retries to the command IOCB. |
| 1974 | * |
| 1975 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1976 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1977 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1978 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1979 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1980 | * |
| 1981 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1982 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1983 | * will be stored into the context1 field of the IOCB for the completion |
| 1984 | * callback function to the PLOGI ELS command. |
| 1985 | * |
| 1986 | * Return code |
| 1987 | * 0 - Successfully issued a plogi for @vport |
| 1988 | * 1 - failed to issue a plogi for @vport |
| 1989 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1990 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1991 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1992 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1993 | struct lpfc_hba *phba = vport->phba; |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 1994 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1995 | struct serv_parm *sp; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1996 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1997 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1998 | uint8_t *pcmd; |
| 1999 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2000 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2001 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2002 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2003 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 2004 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2005 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2006 | /* 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] | 2007 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2008 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2009 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2010 | if (!elsiocb) |
| 2011 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2012 | |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 2013 | shost = lpfc_shost_from_vport(vport); |
| 2014 | spin_lock_irq(shost->host_lock); |
| 2015 | ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT; |
| 2016 | spin_unlock_irq(shost->host_lock); |
| 2017 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2018 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2019 | |
| 2020 | /* For PLOGI request, remainder of payload is service parameters */ |
| 2021 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2022 | pcmd += sizeof(uint32_t); |
| 2023 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2024 | sp = (struct serv_parm *) pcmd; |
| 2025 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2026 | /* |
| 2027 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 2028 | * to device on remote loops work. |
| 2029 | */ |
| 2030 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 2031 | sp->cmn.altBbCredit = 1; |
| 2032 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2033 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 2034 | sp->cmn.fcphLow = FC_PH_4_3; |
| 2035 | |
| 2036 | if (sp->cmn.fcphHigh < FC_PH3) |
| 2037 | sp->cmn.fcphHigh = FC_PH3; |
| 2038 | |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 2039 | sp->cmn.valid_vendor_ver_level = 0; |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2040 | memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 2041 | sp->cmn.bbRcvSizeMsb &= 0xF; |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 2042 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2043 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2044 | "Issue PLOGI: did:x%x", |
| 2045 | did, 0, 0); |
| 2046 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2047 | /* If our firmware supports this feature, convey that |
| 2048 | * information to the target using the vendor specific field. |
| 2049 | */ |
| 2050 | if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { |
| 2051 | sp->cmn.valid_vendor_ver_level = 1; |
| 2052 | sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); |
| 2053 | sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP); |
| 2054 | } |
| 2055 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2056 | phba->fc_stat.elsXmitPLOGI++; |
| 2057 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2058 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2059 | |
| 2060 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2061 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2062 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2064 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2065 | } |
| 2066 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2067 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2068 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2069 | * @phba: pointer to lpfc hba data structure. |
| 2070 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2071 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2072 | * |
| 2073 | * This routine is the completion callback function for a Process Login |
| 2074 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 2075 | * status. If there is error status reported, PRLI retry shall be attempted |
| 2076 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 2077 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 2078 | * ndlp to mark the PRLI completion. |
| 2079 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2080 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2081 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2082 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2083 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2084 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2085 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2086 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2087 | struct lpfc_nodelist *ndlp; |
| 2088 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2089 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2090 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2091 | |
| 2092 | irsp = &(rspiocb->iocb); |
| 2093 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2094 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2096 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2097 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2098 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2099 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 2100 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2101 | ndlp->nlp_DID); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2102 | |
| 2103 | /* Ddriver supports multiple FC4 types. Counters matter. */ |
| 2104 | vport->fc_prli_sent--; |
| 2105 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2107 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2108 | "0103 PRLI completes to NPort x%06x " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2109 | "Data: x%x x%x x%x x%x\n", |
| 2110 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2111 | vport->num_disc_nodes, ndlp->fc4_prli_sent); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2112 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2113 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2114 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2115 | goto out; |
| 2116 | |
| 2117 | if (irsp->ulpStatus) { |
| 2118 | /* Check for retry */ |
James Smart | 3120046 | 2017-05-15 15:20:42 -0700 | [diff] [blame] | 2119 | ndlp->fc4_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2121 | /* ELS command is being retried */ |
| 2122 | goto out; |
| 2123 | } |
James Smart | 3120046 | 2017-05-15 15:20:42 -0700 | [diff] [blame] | 2124 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2126 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 3120046 | 2017-05-15 15:20:42 -0700 | [diff] [blame] | 2127 | "2754 PRLI failure DID:%06X Status:x%x/x%x, " |
| 2128 | "data: x%x\n", |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2129 | ndlp->nlp_DID, irsp->ulpStatus, |
James Smart | 3120046 | 2017-05-15 15:20:42 -0700 | [diff] [blame] | 2130 | irsp->un.ulpWord[4], ndlp->fc4_prli_sent); |
| 2131 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2132 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2133 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2134 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2135 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2136 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2137 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2138 | } else |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2139 | /* Good status, call state machine. However, if another |
| 2140 | * PRLI is outstanding, don't call the state machine |
| 2141 | * because final disposition to Mapped or Unmapped is |
| 2142 | * completed there. |
| 2143 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2144 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2145 | NLP_EVT_CMPL_PRLI); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2146 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2147 | out: |
| 2148 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2149 | return; |
| 2150 | } |
| 2151 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2152 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2153 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2154 | * @vport: pointer to a host virtual N_Port data structure. |
| 2155 | * @ndlp: pointer to a node-list data structure. |
| 2156 | * @retry: number of retries to the command IOCB. |
| 2157 | * |
| 2158 | * This routine issues a Process Login (PRLI) ELS command for the |
| 2159 | * @vport. The PRLI service parameters are set up in the payload of the |
| 2160 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 2161 | * is put to the IOCB completion callback func field before invoking the |
| 2162 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 2163 | * |
| 2164 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2165 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2166 | * will be stored into the context1 field of the IOCB for the completion |
| 2167 | * callback function to the PRLI ELS command. |
| 2168 | * |
| 2169 | * Return code |
| 2170 | * 0 - successfully issued prli iocb command for @vport |
| 2171 | * 1 - failed to issue prli iocb command for @vport |
| 2172 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2173 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2174 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2175 | uint8_t retry) |
| 2176 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2177 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2178 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2179 | PRLI *npr; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2180 | struct lpfc_nvme_prli *npr_nvme; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2181 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2182 | uint8_t *pcmd; |
| 2183 | uint16_t cmdsize; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2184 | u32 local_nlp_type, elscmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2185 | |
Dick Kennedy | 991f0c0 | 2017-08-23 16:55:39 -0700 | [diff] [blame] | 2186 | /* |
| 2187 | * If we are in RSCN mode, the FC4 types supported from a |
| 2188 | * previous GFT_ID command may not be accurate. So, if we |
| 2189 | * are a NVME Initiator, always look for the possibility of |
| 2190 | * the remote NPort beng a NVME Target. |
| 2191 | */ |
| 2192 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2193 | vport->fc_flag & FC_RSCN_MODE && |
| 2194 | vport->nvmei_support) |
| 2195 | ndlp->nlp_fc4_type |= NLP_FC4_NVME; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2196 | local_nlp_type = ndlp->nlp_fc4_type; |
| 2197 | |
| 2198 | send_next_prli: |
| 2199 | if (local_nlp_type & NLP_FC4_FCP) { |
| 2200 | /* Payload is 4 + 16 = 20 x14 bytes. */ |
| 2201 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
| 2202 | elscmd = ELS_CMD_PRLI; |
| 2203 | } else if (local_nlp_type & NLP_FC4_NVME) { |
| 2204 | /* Payload is 4 + 20 = 24 x18 bytes. */ |
| 2205 | cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli)); |
| 2206 | elscmd = ELS_CMD_NVMEPRLI; |
| 2207 | } else { |
| 2208 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2209 | "3083 Unknown FC_TYPE x%x ndlp x%06x\n", |
| 2210 | ndlp->nlp_fc4_type, ndlp->nlp_DID); |
| 2211 | return 1; |
| 2212 | } |
James Smart | 09559e8 | 2017-06-15 22:56:46 -0700 | [diff] [blame] | 2213 | |
| 2214 | /* SLI3 ports don't support NVME. If this rport is a strict NVME |
| 2215 | * FC4 type, implicitly LOGO. |
| 2216 | */ |
| 2217 | if (phba->sli_rev == LPFC_SLI_REV3 && |
| 2218 | ndlp->nlp_fc4_type == NLP_FC4_NVME) { |
| 2219 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2220 | "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n", |
| 2221 | ndlp->nlp_type); |
| 2222 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
| 2223 | return 1; |
| 2224 | } |
| 2225 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2226 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2227 | ndlp->nlp_DID, elscmd); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2228 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2229 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2230 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2232 | |
| 2233 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2234 | memset(pcmd, 0, cmdsize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2235 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2236 | if (local_nlp_type & NLP_FC4_FCP) { |
| 2237 | /* Remainder of payload is FCP PRLI parameter page. |
| 2238 | * Note: this data structure is defined as |
| 2239 | * BE/LE in the structure definition so no |
| 2240 | * byte swap call is made. |
| 2241 | */ |
| 2242 | *((uint32_t *)(pcmd)) = ELS_CMD_PRLI; |
| 2243 | pcmd += sizeof(uint32_t); |
| 2244 | npr = (PRLI *)pcmd; |
| 2245 | |
| 2246 | /* |
| 2247 | * If our firmware version is 3.20 or later, |
| 2248 | * set the following bits for FC-TAPE support. |
| 2249 | */ |
| 2250 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 2251 | npr->ConfmComplAllowed = 1; |
| 2252 | npr->Retry = 1; |
| 2253 | npr->TaskRetryIdReq = 1; |
| 2254 | } |
| 2255 | npr->estabImagePair = 1; |
| 2256 | npr->readXferRdyDis = 1; |
| 2257 | if (vport->cfg_first_burst_size) |
| 2258 | npr->writeXferRdyDis = 1; |
| 2259 | |
| 2260 | /* For FCP support */ |
| 2261 | npr->prliType = PRLI_FCP_TYPE; |
| 2262 | npr->initiatorFunc = 1; |
| 2263 | elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ; |
| 2264 | |
| 2265 | /* Remove FCP type - processed. */ |
| 2266 | local_nlp_type &= ~NLP_FC4_FCP; |
| 2267 | } else if (local_nlp_type & NLP_FC4_NVME) { |
| 2268 | /* Remainder of payload is NVME PRLI parameter page. |
| 2269 | * This data structure is the newer definition that |
| 2270 | * uses bf macros so a byte swap is required. |
| 2271 | */ |
| 2272 | *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI; |
| 2273 | pcmd += sizeof(uint32_t); |
| 2274 | npr_nvme = (struct lpfc_nvme_prli *)pcmd; |
| 2275 | bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); |
| 2276 | bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ |
| 2277 | |
| 2278 | /* Only initiators request first burst. */ |
| 2279 | if ((phba->cfg_nvme_enable_fb) && |
| 2280 | !phba->nvmet_support) |
| 2281 | bf_set(prli_fba, npr_nvme, 1); |
| 2282 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2283 | if (phba->nvmet_support) { |
| 2284 | bf_set(prli_tgt, npr_nvme, 1); |
| 2285 | bf_set(prli_disc, npr_nvme, 1); |
| 2286 | |
| 2287 | } else { |
| 2288 | bf_set(prli_init, npr_nvme, 1); |
| 2289 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2290 | npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); |
| 2291 | npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); |
| 2292 | elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ; |
| 2293 | |
| 2294 | /* Remove NVME type - processed. */ |
| 2295 | local_nlp_type &= ~NLP_FC4_NVME; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2296 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2297 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2298 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2299 | "Issue PRLI: did:x%x", |
| 2300 | ndlp->nlp_DID, 0, 0); |
| 2301 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2302 | phba->fc_stat.elsXmitPRLI++; |
| 2303 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2304 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2305 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2306 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2307 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2308 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2309 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2311 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2312 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2313 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2314 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2315 | |
| 2316 | /* The vport counters are used for lpfc_scan_finished, but |
| 2317 | * the ndlp is used to track outstanding PRLIs for different |
| 2318 | * FC4 types. |
| 2319 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2320 | vport->fc_prli_sent++; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2321 | ndlp->fc4_prli_sent++; |
| 2322 | |
| 2323 | /* The driver supports 2 FC4 types. Make sure |
| 2324 | * a PRLI is issued for all types before exiting. |
| 2325 | */ |
James Smart | 09559e8 | 2017-06-15 22:56:46 -0700 | [diff] [blame] | 2326 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2327 | local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME)) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2328 | goto send_next_prli; |
| 2329 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2330 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2331 | } |
| 2332 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2333 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2334 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2335 | * @vport: pointer to a host virtual N_Port data structure. |
| 2336 | * |
| 2337 | * This routine performs Registration State Change Notification (RSCN) |
| 2338 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 2339 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 2340 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 2341 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 2342 | * invoked to check and handle possible more RSCN came in during the period |
| 2343 | * of processing the current ones. |
| 2344 | **/ |
| 2345 | static void |
| 2346 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 2347 | { |
| 2348 | lpfc_can_disctmo(vport); |
| 2349 | |
| 2350 | /* RSCN discovery */ |
| 2351 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 2352 | if (vport->fc_npr_cnt) |
| 2353 | if (lpfc_els_disc_plogi(vport)) |
| 2354 | return; |
| 2355 | |
| 2356 | lpfc_end_rscn(vport); |
| 2357 | } |
| 2358 | |
| 2359 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2360 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2361 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 2362 | * |
| 2363 | * This function is called when the final ADISC is completed during discovery. |
| 2364 | * This function handles clearing link attention or issuing reg_vpi depending |
| 2365 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 2366 | * discovery. |
| 2367 | * This function is called with no locks held. |
| 2368 | **/ |
| 2369 | static void |
| 2370 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 2371 | { |
| 2372 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2373 | struct lpfc_hba *phba = vport->phba; |
| 2374 | |
| 2375 | /* |
| 2376 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 2377 | * and continue discovery. |
| 2378 | */ |
| 2379 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2380 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 2381 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | d454c91 | 2014-12-30 12:08:58 -0500 | [diff] [blame] | 2382 | /* The ADISCs are complete. Doesn't matter if they |
| 2383 | * succeeded or failed because the ADISC completion |
| 2384 | * routine guarantees to call the state machine and |
| 2385 | * the RPI is either unregistered (failed ADISC response) |
| 2386 | * or the RPI is still valid and the node is marked |
| 2387 | * mapped for a target. The exchanges should be in the |
| 2388 | * correct state. This code is specific to SLI3. |
| 2389 | */ |
| 2390 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2391 | lpfc_issue_reg_vpi(phba, vport); |
| 2392 | return; |
| 2393 | } |
| 2394 | /* |
| 2395 | * For SLI2, we need to set port_state to READY |
| 2396 | * and continue discovery. |
| 2397 | */ |
| 2398 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2399 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 2400 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2401 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 2402 | vport->num_disc_nodes = 0; |
| 2403 | /* go thru NPR list, issue ELS PLOGIs */ |
| 2404 | if (vport->fc_npr_cnt) |
| 2405 | lpfc_els_disc_plogi(vport); |
| 2406 | if (!vport->num_disc_nodes) { |
| 2407 | spin_lock_irq(shost->host_lock); |
| 2408 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2409 | spin_unlock_irq(shost->host_lock); |
| 2410 | lpfc_can_disctmo(vport); |
| 2411 | lpfc_end_rscn(vport); |
| 2412 | } |
| 2413 | } |
| 2414 | vport->port_state = LPFC_VPORT_READY; |
| 2415 | } else |
| 2416 | lpfc_rscn_disc(vport); |
| 2417 | } |
| 2418 | |
| 2419 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2420 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2421 | * @vport: pointer to a host virtual N_Port data structure. |
| 2422 | * |
| 2423 | * This routine determines whether there are more ndlps on a @vport |
| 2424 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 2425 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 2426 | * remaining nodes which need to have ADISC sent. |
| 2427 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2428 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2429 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2431 | if (vport->num_disc_nodes) |
| 2432 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2433 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2434 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2435 | "0210 Continue discovery with %d ADISCs to go " |
| 2436 | "Data: x%x x%x x%x\n", |
| 2437 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 2438 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2439 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2440 | if (vport->fc_flag & FC_NLP_MORE) { |
| 2441 | lpfc_set_disctmo(vport); |
| 2442 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 2443 | lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2445 | if (!vport->num_disc_nodes) |
| 2446 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | return; |
| 2448 | } |
| 2449 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2450 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2451 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2452 | * @phba: pointer to lpfc hba data structure. |
| 2453 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2454 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2455 | * |
| 2456 | * This routine is the completion function for issuing the Address Discover |
| 2457 | * (ADISC) command. It first checks to see whether link went down during |
| 2458 | * the discovery process. If so, the node will be marked as node port |
| 2459 | * recovery for issuing discover IOCB by the link attention handler and |
| 2460 | * exit. Otherwise, the response status is checked. If error was reported |
| 2461 | * in the response status, the ADISC command shall be retried by invoking |
| 2462 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 2463 | * the response status, the state machine is invoked to set transition |
| 2464 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 2465 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2466 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2467 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2468 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2469 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2470 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2471 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2472 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2473 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2474 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2475 | |
| 2476 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2477 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2478 | |
| 2479 | irsp = &(rspiocb->iocb); |
| 2480 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2481 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2482 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2483 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 2484 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2485 | ndlp->nlp_DID); |
| 2486 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2487 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2488 | * is being used during discovery. |
| 2489 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2490 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2491 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2492 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2493 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2494 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2495 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2496 | "0104 ADISC completes to NPort x%x " |
| 2497 | "Data: x%x x%x x%x x%x x%x\n", |
| 2498 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2499 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2500 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2501 | if (lpfc_els_chk_latt(vport)) { |
| 2502 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2503 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2504 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2505 | goto out; |
| 2506 | } |
| 2507 | |
| 2508 | if (irsp->ulpStatus) { |
| 2509 | /* Check for retry */ |
| 2510 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2511 | /* ELS command is being retried */ |
| 2512 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2513 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2514 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2515 | spin_unlock_irq(shost->host_lock); |
| 2516 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2517 | } |
| 2518 | goto out; |
| 2519 | } |
| 2520 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2521 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2522 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2523 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2524 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2525 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2526 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2527 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2528 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2529 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2530 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2531 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2532 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2533 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2534 | /* Check to see if there are more ADISCs to be sent */ |
| 2535 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2536 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2537 | out: |
| 2538 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2539 | return; |
| 2540 | } |
| 2541 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2542 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2543 | * 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] | 2544 | * @vport: pointer to a virtual N_Port data structure. |
| 2545 | * @ndlp: pointer to a node-list data structure. |
| 2546 | * @retry: number of retries to the command IOCB. |
| 2547 | * |
| 2548 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2549 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2550 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2551 | * to issue the ADISC ELS command. |
| 2552 | * |
| 2553 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2554 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2555 | * will be stored into the context1 field of the IOCB for the completion |
| 2556 | * callback function to the ADISC ELS command. |
| 2557 | * |
| 2558 | * Return code |
| 2559 | * 0 - successfully issued adisc |
| 2560 | * 1 - failed to issue adisc |
| 2561 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2562 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2563 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2564 | uint8_t retry) |
| 2565 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2566 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2567 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2568 | ADISC *ap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2569 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2570 | uint8_t *pcmd; |
| 2571 | uint16_t cmdsize; |
| 2572 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2573 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2574 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2575 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2576 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2577 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2578 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2579 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2580 | |
| 2581 | /* For ADISC request, remainder of payload is service parameters */ |
| 2582 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2583 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2584 | |
| 2585 | /* Fill in ADISC payload */ |
| 2586 | ap = (ADISC *) pcmd; |
| 2587 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2588 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2589 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2590 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2591 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2592 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2593 | "Issue ADISC: did:x%x", |
| 2594 | ndlp->nlp_DID, 0, 0); |
| 2595 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2596 | phba->fc_stat.elsXmitADISC++; |
| 2597 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2598 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2599 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2600 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2601 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2602 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2603 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2604 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2605 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2606 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2607 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2608 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2609 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2610 | } |
| 2611 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2612 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2613 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2614 | * @phba: pointer to lpfc hba data structure. |
| 2615 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2616 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2617 | * |
| 2618 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2619 | * command. If no error status was reported from the LOGO response, the |
| 2620 | * state machine of the associated ndlp shall be invoked for transition with |
| 2621 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2622 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2623 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2624 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2625 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2626 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2627 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2628 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2629 | struct lpfc_vport *vport = ndlp->vport; |
| 2630 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2631 | IOCB_t *irsp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2632 | struct lpfcMboxq *mbox; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2633 | unsigned long flags; |
| 2634 | uint32_t skip_recovery = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2635 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2636 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2637 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2638 | |
| 2639 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2640 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2642 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2643 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2644 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2645 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2646 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2647 | ndlp->nlp_DID); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2648 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2650 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2651 | "0105 LOGO completes to NPort x%x " |
| 2652 | "Data: x%x x%x x%x x%x\n", |
| 2653 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2654 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2655 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2656 | if (lpfc_els_chk_latt(vport)) { |
| 2657 | skip_recovery = 1; |
| 2658 | goto out; |
| 2659 | } |
| 2660 | |
| 2661 | /* Check to see if link went down during discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2662 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2663 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2664 | * which should abort all outstanding IOs. |
| 2665 | */ |
| 2666 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2667 | NLP_EVT_DEVICE_RM); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2668 | skip_recovery = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2669 | goto out; |
| 2670 | } |
| 2671 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2672 | if (irsp->ulpStatus) { |
| 2673 | /* Check for retry */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2674 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2675 | /* ELS command is being retried */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2676 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2678 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2679 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2680 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2681 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2682 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2683 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2684 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2685 | if (lpfc_error_lost_link(irsp)) { |
| 2686 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2687 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2688 | } |
| 2689 | } |
| 2690 | |
| 2691 | /* Call state machine. This will unregister the rpi if needed. */ |
| 2692 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); |
| 2693 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2694 | out: |
| 2695 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2696 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ |
| 2697 | if ((vport->fc_flag & FC_PT2PT) && |
| 2698 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { |
| 2699 | phba->pport->fc_myDID = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2700 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 2701 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2702 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2703 | if (phba->nvmet_support) |
| 2704 | lpfc_nvmet_update_targetport(phba); |
| 2705 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2706 | lpfc_nvme_update_localport(phba->pport); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2707 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2708 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2709 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2710 | if (mbox) { |
| 2711 | lpfc_config_link(phba, mbox); |
| 2712 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2713 | mbox->vport = vport; |
| 2714 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 2715 | MBX_NOT_FINISHED) { |
| 2716 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2717 | skip_recovery = 1; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2718 | } |
| 2719 | } |
| 2720 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2721 | |
| 2722 | /* |
| 2723 | * If the node is a target, the handling attempts to recover the port. |
| 2724 | * For any other port type, the rpi is unregistered as an implicit |
| 2725 | * LOGO. |
| 2726 | */ |
| 2727 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) { |
| 2728 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 2729 | spin_lock_irqsave(shost->host_lock, flags); |
| 2730 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 2731 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2732 | |
| 2733 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2734 | "3187 LOGO completes to NPort x%x: Start " |
| 2735 | "Recovery Data: x%x x%x x%x x%x\n", |
| 2736 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2737 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 2738 | vport->num_disc_nodes); |
| 2739 | lpfc_disc_start(vport); |
| 2740 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 | return; |
| 2742 | } |
| 2743 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2744 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2745 | * 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] | 2746 | * @vport: pointer to a virtual N_Port data structure. |
| 2747 | * @ndlp: pointer to a node-list data structure. |
| 2748 | * @retry: number of retries to the command IOCB. |
| 2749 | * |
| 2750 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2751 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2752 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2753 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2754 | * |
| 2755 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2756 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2757 | * will be stored into the context1 field of the IOCB for the completion |
| 2758 | * callback function to the LOGO ELS command. |
| 2759 | * |
| 2760 | * Return code |
| 2761 | * 0 - successfully issued logo |
| 2762 | * 1 - failed to issue logo |
| 2763 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2764 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2765 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2766 | uint8_t retry) |
| 2767 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2768 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2769 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2770 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2771 | uint8_t *pcmd; |
| 2772 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2773 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2774 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2775 | spin_lock_irq(shost->host_lock); |
| 2776 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2777 | spin_unlock_irq(shost->host_lock); |
| 2778 | return 0; |
| 2779 | } |
| 2780 | spin_unlock_irq(shost->host_lock); |
| 2781 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2782 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2783 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2784 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2785 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2786 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2787 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2788 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2789 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2790 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2791 | |
| 2792 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2793 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2794 | pcmd += sizeof(uint32_t); |
| 2795 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2796 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2797 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2798 | "Issue LOGO: did:x%x", |
| 2799 | ndlp->nlp_DID, 0, 0); |
| 2800 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2801 | /* |
| 2802 | * If we are issuing a LOGO, we may try to recover the remote NPort |
| 2803 | * by issuing a PLOGI later. Even though we issue ELS cmds by the |
| 2804 | * VPI, if we have a valid RPI, and that RPI gets unreg'ed while |
| 2805 | * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI |
| 2806 | * for that ELS cmd. To avoid this situation, lets get rid of the |
| 2807 | * RPI right now, before any ELS cmds are sent. |
| 2808 | */ |
| 2809 | spin_lock_irq(shost->host_lock); |
| 2810 | ndlp->nlp_flag |= NLP_ISSUE_LOGO; |
| 2811 | spin_unlock_irq(shost->host_lock); |
| 2812 | if (lpfc_unreg_rpi(vport, ndlp)) { |
| 2813 | lpfc_els_free_iocb(phba, elsiocb); |
| 2814 | return 0; |
| 2815 | } |
| 2816 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | phba->fc_stat.elsXmitLOGO++; |
| 2818 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2819 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2820 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2821 | ndlp->nlp_flag &= ~NLP_ISSUE_LOGO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2822 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2823 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2824 | |
| 2825 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2826 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2827 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2828 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2829 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2830 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2831 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2832 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2833 | } |
| 2834 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2835 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2836 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2837 | * @phba: pointer to lpfc hba data structure. |
| 2838 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2839 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2840 | * |
| 2841 | * This routine is a generic completion callback function for ELS commands. |
| 2842 | * Specifically, it is the callback function which does not need to perform |
| 2843 | * any command specific operations. It is currently used by the ELS command |
| 2844 | * issuing routines for the ELS State Change Request (SCR), |
| 2845 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2846 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2847 | * certain debug loggings, this callback function simply invokes the |
| 2848 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2849 | * discovery process. |
| 2850 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2851 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2852 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2853 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2854 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2855 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2856 | IOCB_t *irsp; |
| 2857 | |
| 2858 | irsp = &rspiocb->iocb; |
| 2859 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2860 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2861 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2862 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2863 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2864 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2865 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2866 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2867 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2868 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2869 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2870 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2871 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2872 | return; |
| 2873 | } |
| 2874 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2875 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2876 | * 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] | 2877 | * @vport: pointer to a host virtual N_Port data structure. |
| 2878 | * @nportid: N_Port identifier to the remote node. |
| 2879 | * @retry: number of retries to the command IOCB. |
| 2880 | * |
| 2881 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2882 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2883 | * first search the @vport node list to find the matching ndlp. If no such |
| 2884 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2885 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2886 | * routine is invoked to send the SCR IOCB. |
| 2887 | * |
| 2888 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2889 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2890 | * will be stored into the context1 field of the IOCB for the completion |
| 2891 | * callback function to the SCR ELS command. |
| 2892 | * |
| 2893 | * Return code |
| 2894 | * 0 - Successfully issued scr command |
| 2895 | * 1 - Failed to issue scr command |
| 2896 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2897 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2898 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2899 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2900 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2901 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2902 | uint8_t *pcmd; |
| 2903 | uint16_t cmdsize; |
| 2904 | struct lpfc_nodelist *ndlp; |
| 2905 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2906 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2907 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2908 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2909 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 2910 | ndlp = lpfc_nlp_init(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2911 | if (!ndlp) |
| 2912 | return 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2913 | lpfc_enqueue_node(vport, ndlp); |
| 2914 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2915 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2916 | if (!ndlp) |
| 2917 | return 1; |
| 2918 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2919 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2920 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2921 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2922 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2923 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2924 | /* This will trigger the release of the node just |
| 2925 | * allocated |
| 2926 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2927 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2928 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2929 | } |
| 2930 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2931 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2932 | |
| 2933 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2934 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2935 | |
| 2936 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2937 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2938 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2939 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2940 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2941 | "Issue SCR: did:x%x", |
| 2942 | ndlp->nlp_DID, 0, 0); |
| 2943 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2944 | phba->fc_stat.elsXmitSCR++; |
| 2945 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2946 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2947 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2948 | /* The additional lpfc_nlp_put will cause the following |
| 2949 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2950 | * the node. |
| 2951 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2952 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2953 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2954 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2955 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2956 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2957 | * trigger the release of node. |
| 2958 | */ |
James Smart | b7e50c5 | 2017-11-20 16:00:37 -0800 | [diff] [blame^] | 2959 | if (!(vport->fc_flag & FC_PT2PT)) |
| 2960 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2961 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2962 | } |
| 2963 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2964 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2965 | * 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] | 2966 | * @vport: pointer to a host virtual N_Port data structure. |
| 2967 | * @nportid: N_Port identifier to the remote node. |
| 2968 | * @retry: number of retries to the command IOCB. |
| 2969 | * |
| 2970 | * This routine issues a Fibre Channel Address Resolution Response |
| 2971 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2972 | * is passed into the function. It first search the @vport node list to find |
| 2973 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2974 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2975 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2976 | * |
| 2977 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2978 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2979 | * will be stored into the context1 field of the IOCB for the completion |
| 2980 | * callback function to the PARPR ELS command. |
| 2981 | * |
| 2982 | * Return code |
| 2983 | * 0 - Successfully issued farpr command |
| 2984 | * 1 - Failed to issue farpr command |
| 2985 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2986 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2987 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2988 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2989 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2990 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2991 | FARP *fp; |
| 2992 | uint8_t *pcmd; |
| 2993 | uint32_t *lp; |
| 2994 | uint16_t cmdsize; |
| 2995 | struct lpfc_nodelist *ondlp; |
| 2996 | struct lpfc_nodelist *ndlp; |
| 2997 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2998 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2999 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3000 | ndlp = lpfc_findnode_did(vport, nportid); |
| 3001 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3002 | ndlp = lpfc_nlp_init(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3003 | if (!ndlp) |
| 3004 | return 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3005 | lpfc_enqueue_node(vport, ndlp); |
| 3006 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 3007 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 3008 | if (!ndlp) |
| 3009 | return 1; |
| 3010 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3011 | |
| 3012 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 3013 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3014 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3015 | /* This will trigger the release of the node just |
| 3016 | * allocated |
| 3017 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3018 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3019 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3020 | } |
| 3021 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3022 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3023 | |
| 3024 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3025 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3026 | |
| 3027 | /* Fill in FARPR payload */ |
| 3028 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3029 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3030 | lp = (uint32_t *) pcmd; |
| 3031 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3032 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3033 | fp->Rflags = 0; |
| 3034 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 3035 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3036 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3037 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3038 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3039 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3040 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3041 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3042 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3043 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3044 | } |
| 3045 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3046 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3047 | "Issue FARPR: did:x%x", |
| 3048 | ndlp->nlp_DID, 0, 0); |
| 3049 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3050 | phba->fc_stat.elsXmitFARPR++; |
| 3051 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3052 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 3053 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3054 | /* The additional lpfc_nlp_put will cause the following |
| 3055 | * lpfc_els_free_iocb routine to trigger the release of |
| 3056 | * the node. |
| 3057 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3058 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3059 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3060 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3061 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3062 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 3063 | * trigger the release of the node. |
| 3064 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3065 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3066 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3067 | } |
| 3068 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3069 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3070 | * 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] | 3071 | * @vport: pointer to a host virtual N_Port data structure. |
| 3072 | * @nlp: pointer to a node-list data structure. |
| 3073 | * |
| 3074 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 3075 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 3076 | * removes the ELS retry event if it presents. In addition, if the |
| 3077 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 3078 | * commands are sent for the @vport's nodes that require issuing discovery |
| 3079 | * ADISC. |
| 3080 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3081 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3082 | 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] | 3083 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3084 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3085 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3086 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3087 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 3088 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3089 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3090 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3091 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3092 | del_timer_sync(&nlp->nlp_delayfunc); |
| 3093 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3094 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3095 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3096 | /* Decrement nlp reference count held for the delayed retry */ |
| 3097 | evtp = &nlp->els_retry_evt; |
| 3098 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 3099 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3100 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3101 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3102 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3103 | spin_unlock_irq(shost->host_lock); |
| 3104 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3105 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3106 | /* Check if there are more ADISCs to be sent */ |
| 3107 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3108 | } else { |
| 3109 | /* Check if there are more PLOGIs to be sent */ |
| 3110 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 3111 | if (vport->num_disc_nodes == 0) { |
| 3112 | spin_lock_irq(shost->host_lock); |
| 3113 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3114 | spin_unlock_irq(shost->host_lock); |
| 3115 | lpfc_can_disctmo(vport); |
| 3116 | lpfc_end_rscn(vport); |
| 3117 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3118 | } |
| 3119 | } |
| 3120 | } |
| 3121 | return; |
| 3122 | } |
| 3123 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3124 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3125 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3126 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 3127 | * |
| 3128 | * This routine is invoked by the ndlp delayed-function timer to check |
| 3129 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 3130 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 3131 | * adds the delayed events to the HBA work list and invokes the |
| 3132 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 3133 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 3134 | * the work list to hold reference count of ndlp so that it guarantees the |
| 3135 | * reference to ndlp will still be available when the worker thread gets |
| 3136 | * to the event associated with the ndlp. |
| 3137 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3138 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3139 | lpfc_els_retry_delay(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3140 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3141 | struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3142 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3143 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3144 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3145 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3146 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3147 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3148 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3149 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3150 | return; |
| 3151 | } |
| 3152 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3153 | /* We need to hold the node by incrementing the reference |
| 3154 | * count until the queued work is done |
| 3155 | */ |
| 3156 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3157 | if (evtp->evt_arg1) { |
| 3158 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 3159 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3160 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3161 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3162 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3163 | return; |
| 3164 | } |
| 3165 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3166 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3167 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3168 | * @ndlp: pointer to a node-list data structure. |
| 3169 | * |
| 3170 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 3171 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 3172 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 3173 | * function according to the delayed ELS command to retry the command. |
| 3174 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3175 | void |
| 3176 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 3177 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3178 | struct lpfc_vport *vport = ndlp->vport; |
| 3179 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3180 | uint32_t cmd, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3181 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3182 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3183 | cmd = ndlp->nlp_last_elscmd; |
| 3184 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3185 | |
| 3186 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3187 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3188 | return; |
| 3189 | } |
| 3190 | |
| 3191 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3192 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 3193 | /* |
| 3194 | * If a discovery event readded nlp_delayfunc after timer |
| 3195 | * firing and before processing the timer, cancel the |
| 3196 | * nlp_delayfunc. |
| 3197 | */ |
| 3198 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3199 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3200 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3201 | |
| 3202 | switch (cmd) { |
| 3203 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3204 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3205 | break; |
| 3206 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3207 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3208 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3209 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3210 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3211 | break; |
| 3212 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3213 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3214 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3215 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3216 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3217 | break; |
| 3218 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3219 | case ELS_CMD_NVMEPRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3220 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3221 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3222 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3223 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3224 | break; |
| 3225 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3226 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3227 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3228 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3229 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3230 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3231 | case ELS_CMD_FDISC: |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3232 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
| 3233 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3234 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3235 | } |
| 3236 | return; |
| 3237 | } |
| 3238 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3239 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3240 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3241 | * @phba: pointer to lpfc hba data structure. |
| 3242 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3243 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3244 | * |
| 3245 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 3246 | * failed. The following ELS IOCBs use this function for retrying the command |
| 3247 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 3248 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 3249 | * returned error status, it makes the decision whether a retry shall be |
| 3250 | * issued for the command, and whether a retry shall be made immediately or |
| 3251 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 3252 | * is called to retry the command. In the later case, the ELS command shall |
| 3253 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 3254 | * ndlp for the delayed command issusing. |
| 3255 | * |
| 3256 | * Return code |
| 3257 | * 0 - No retry of els command is made |
| 3258 | * 1 - Immediate or delayed retry of els command is made |
| 3259 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3260 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3261 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3262 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3263 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3264 | struct lpfc_vport *vport = cmdiocb->vport; |
| 3265 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3266 | IOCB_t *irsp = &rspiocb->iocb; |
| 3267 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3268 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3269 | uint32_t *elscmd; |
| 3270 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3271 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3272 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3273 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3274 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3275 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3276 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3277 | /* Note: context2 may be 0 for internal driver abort |
| 3278 | * of delays ELS command. |
| 3279 | */ |
| 3280 | |
| 3281 | if (pcmd && pcmd->virt) { |
| 3282 | elscmd = (uint32_t *) (pcmd->virt); |
| 3283 | cmd = *elscmd++; |
| 3284 | } |
| 3285 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3286 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3287 | did = ndlp->nlp_DID; |
| 3288 | else { |
| 3289 | /* We should only hit this case for retrying PLOGI */ |
| 3290 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3291 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3292 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 3293 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3294 | return 1; |
| 3295 | } |
| 3296 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3297 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3298 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 3299 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 3300 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3301 | switch (irsp->ulpStatus) { |
| 3302 | case IOSTAT_FCP_RSP_ERROR: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3303 | break; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3304 | case IOSTAT_REMOTE_STOP: |
| 3305 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3306 | /* This IO was aborted by the target, we don't |
| 3307 | * know the rxid and because we did not send the |
| 3308 | * ABTS we cannot generate and RRQ. |
| 3309 | */ |
| 3310 | lpfc_set_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 3311 | cmdiocb->sli4_lxritag, 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3312 | } |
| 3313 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3314 | case IOSTAT_LOCAL_REJECT: |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3315 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3316 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3317 | if (cmd == ELS_CMD_FLOGI) { |
| 3318 | if (PCI_DEVICE_ID_HORNET == |
| 3319 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3320 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3321 | phba->pport->fc_myDID = 0; |
| 3322 | phba->alpa_map[0] = 0; |
| 3323 | phba->alpa_map[1] = 0; |
| 3324 | } |
| 3325 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3326 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3327 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3328 | retry = 1; |
| 3329 | break; |
| 3330 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3331 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3332 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3333 | "0124 Retry illegal cmd x%x " |
| 3334 | "retry:x%x delay:x%x\n", |
| 3335 | cmd, cmdiocb->retry, delay); |
| 3336 | retry = 1; |
| 3337 | /* All command's retry policy */ |
| 3338 | maxretry = 8; |
| 3339 | if (cmdiocb->retry > 2) |
| 3340 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3341 | break; |
| 3342 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3343 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3344 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3345 | retry = 1; |
| 3346 | if (cmdiocb->retry > 100) |
| 3347 | delay = 100; |
| 3348 | maxretry = 250; |
| 3349 | break; |
| 3350 | |
| 3351 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3352 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3353 | retry = 1; |
| 3354 | break; |
| 3355 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3356 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3357 | case IOERR_INVALID_RPI: |
James Smart | 5b5b36a | 2013-01-03 15:43:19 -0500 | [diff] [blame] | 3358 | if (cmd == ELS_CMD_PLOGI && |
| 3359 | did == NameServer_DID) { |
| 3360 | /* Continue forever if plogi to */ |
| 3361 | /* the nameserver fails */ |
| 3362 | maxretry = 0; |
| 3363 | delay = 100; |
| 3364 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3365 | retry = 1; |
| 3366 | break; |
| 3367 | } |
| 3368 | break; |
| 3369 | |
| 3370 | case IOSTAT_NPORT_RJT: |
| 3371 | case IOSTAT_FABRIC_RJT: |
| 3372 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 3373 | retry = 1; |
| 3374 | break; |
| 3375 | } |
| 3376 | break; |
| 3377 | |
| 3378 | case IOSTAT_NPORT_BSY: |
| 3379 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3380 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | retry = 1; |
| 3382 | break; |
| 3383 | |
| 3384 | case IOSTAT_LS_RJT: |
| 3385 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 3386 | /* Added for Vendor specifc support |
| 3387 | * Just keep retrying for these Rsn / Exp codes |
| 3388 | */ |
| 3389 | switch (stat.un.b.lsRjtRsnCode) { |
| 3390 | case LSRJT_UNABLE_TPC: |
James Smart | dea37e8 | 2017-06-01 21:07:07 -0700 | [diff] [blame] | 3391 | /* The driver has a VALID PLOGI but the rport has |
| 3392 | * rejected the PRLI - can't do it now. Delay |
| 3393 | * for 1 second and try again - don't care about |
| 3394 | * the explanation. |
| 3395 | */ |
| 3396 | if (cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) { |
| 3397 | delay = 1000; |
| 3398 | maxretry = lpfc_max_els_tries + 1; |
| 3399 | retry = 1; |
| 3400 | break; |
| 3401 | } |
| 3402 | |
| 3403 | /* Legacy bug fix code for targets with PLOGI delays. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3404 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3405 | LSEXP_CMD_IN_PROGRESS) { |
| 3406 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3407 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | maxretry = 48; |
| 3409 | } |
| 3410 | retry = 1; |
| 3411 | break; |
| 3412 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3413 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3414 | LSEXP_CANT_GIVE_DATA) { |
| 3415 | if (cmd == ELS_CMD_PLOGI) { |
| 3416 | delay = 1000; |
| 3417 | maxretry = 48; |
| 3418 | } |
| 3419 | retry = 1; |
| 3420 | break; |
| 3421 | } |
James Smart | dea37e8 | 2017-06-01 21:07:07 -0700 | [diff] [blame] | 3422 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3423 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | maxretry = lpfc_max_els_tries + 1; |
| 3425 | retry = 1; |
| 3426 | break; |
| 3427 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3428 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3429 | (cmd == ELS_CMD_FDISC) && |
| 3430 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3431 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3432 | "0125 FDISC Failed (x%x). " |
| 3433 | "Fabric out of resources\n", |
| 3434 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3435 | lpfc_vport_set_state(vport, |
| 3436 | FC_VPORT_NO_FABRIC_RSCS); |
| 3437 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3438 | break; |
| 3439 | |
| 3440 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3441 | if ((cmd == ELS_CMD_PLOGI) || |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3442 | (cmd == ELS_CMD_PRLI) || |
| 3443 | (cmd == ELS_CMD_NVMEPRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3444 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3445 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3446 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3447 | /* FDISC retry policy */ |
| 3448 | maxretry = 48; |
| 3449 | if (cmdiocb->retry >= 32) |
| 3450 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3451 | } |
| 3452 | retry = 1; |
| 3453 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3454 | |
| 3455 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3456 | /* There are some cases where switches return this |
| 3457 | * error when they are not ready and should be returning |
| 3458 | * Logical Busy. We should delay every time. |
| 3459 | */ |
| 3460 | if (cmd == ELS_CMD_FDISC && |
| 3461 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 3462 | maxretry = 3; |
| 3463 | delay = 1000; |
| 3464 | retry = 1; |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 3465 | } else if (cmd == ELS_CMD_FLOGI && |
| 3466 | stat.un.b.lsRjtRsnCodeExp == |
| 3467 | LSEXP_NOTHING_MORE) { |
| 3468 | vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf; |
| 3469 | retry = 1; |
| 3470 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3471 | "0820 FLOGI Failed (x%x). " |
| 3472 | "BBCredit Not Supported\n", |
| 3473 | stat.un.lsRjtError); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3474 | } |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 3475 | break; |
| 3476 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3477 | case LSRJT_PROTOCOL_ERR: |
| 3478 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3479 | (cmd == ELS_CMD_FDISC) && |
| 3480 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 3481 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 3482 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3483 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3484 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3485 | "Fabric Detected Bad WWN\n", |
| 3486 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3487 | lpfc_vport_set_state(vport, |
| 3488 | FC_VPORT_FABRIC_REJ_WWN); |
| 3489 | } |
| 3490 | break; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 3491 | case LSRJT_VENDOR_UNIQUE: |
| 3492 | if ((stat.un.b.vendorUnique == 0x45) && |
| 3493 | (cmd == ELS_CMD_FLOGI)) { |
| 3494 | goto out_retry; |
| 3495 | } |
| 3496 | break; |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 3497 | case LSRJT_CMD_UNSUPPORTED: |
| 3498 | /* lpfc nvmet returns this type of LS_RJT when it |
| 3499 | * receives an FCP PRLI because lpfc nvmet only |
| 3500 | * support NVME. ELS request is terminated for FCP4 |
| 3501 | * on this rport. |
| 3502 | */ |
| 3503 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3504 | LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) { |
| 3505 | spin_lock_irq(shost->host_lock); |
| 3506 | ndlp->nlp_flag |= NLP_FCP_PRLI_RJT; |
| 3507 | spin_unlock_irq(shost->host_lock); |
| 3508 | retry = 0; |
| 3509 | goto out_retry; |
| 3510 | } |
| 3511 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3512 | } |
| 3513 | break; |
| 3514 | |
| 3515 | case IOSTAT_INTERMED_RSP: |
| 3516 | case IOSTAT_BA_RJT: |
| 3517 | break; |
| 3518 | |
| 3519 | default: |
| 3520 | break; |
| 3521 | } |
| 3522 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3523 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3524 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3525 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3526 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3527 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 3528 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3529 | /* FLOGI retry policy */ |
| 3530 | retry = 1; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3531 | /* retry FLOGI forever */ |
James Smart | 6eae430 | 2015-04-07 15:07:23 -0400 | [diff] [blame] | 3532 | if (phba->link_flag != LS_LOOPBACK_MODE) |
| 3533 | maxretry = 0; |
| 3534 | else |
| 3535 | maxretry = 2; |
| 3536 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3537 | if (cmdiocb->retry >= 100) |
| 3538 | delay = 5000; |
| 3539 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3540 | delay = 1000; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3541 | } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) { |
| 3542 | /* retry FDISCs every second up to devloss */ |
| 3543 | retry = 1; |
| 3544 | maxretry = vport->cfg_devloss_tmo; |
| 3545 | delay = 1000; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3546 | } |
| 3547 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3548 | cmdiocb->retry++; |
| 3549 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3550 | phba->fc_stat.elsRetryExceeded++; |
| 3551 | retry = 0; |
| 3552 | } |
| 3553 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3554 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 3555 | retry = 0; |
| 3556 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 3557 | out_retry: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3558 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3559 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 3560 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 3561 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 3562 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3563 | "2849 Stop retry ELS command " |
| 3564 | "x%x to remote NPORT x%x, " |
| 3565 | "Data: x%x x%x\n", cmd, did, |
| 3566 | cmdiocb->retry, delay); |
| 3567 | return 0; |
| 3568 | } |
| 3569 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3570 | |
| 3571 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3572 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3573 | "0107 Retry ELS command x%x to remote " |
| 3574 | "NPORT x%x Data: x%x x%x\n", |
| 3575 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3576 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3577 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 3578 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3579 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 3580 | IOERR_NO_RESOURCES))) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3581 | /* Don't reset timer for no resources */ |
| 3582 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3583 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3584 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3585 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3586 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3590 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | phba->fc_stat.elsDelayRetry++; |
| 3592 | ndlp->nlp_retry = cmdiocb->retry; |
| 3593 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3594 | /* delay is specified in milliseconds */ |
| 3595 | mod_timer(&ndlp->nlp_delayfunc, |
| 3596 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3597 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3598 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3599 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3600 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3601 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3602 | if ((cmd == ELS_CMD_PRLI) || |
| 3603 | (cmd == ELS_CMD_NVMEPRLI)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3604 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 3605 | NLP_STE_PRLI_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3606 | else |
| 3607 | lpfc_nlp_set_state(vport, ndlp, |
| 3608 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3609 | ndlp->nlp_last_elscmd = cmd; |
| 3610 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3611 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3612 | } |
| 3613 | switch (cmd) { |
| 3614 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3615 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3616 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3617 | case ELS_CMD_FDISC: |
| 3618 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 3619 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3620 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3621 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3622 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3623 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3624 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3625 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3626 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3627 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3628 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3629 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3630 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3631 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3632 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3634 | case ELS_CMD_NVMEPRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3635 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3636 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 3637 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3638 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3639 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3640 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3641 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3642 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3643 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3644 | } |
| 3645 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3646 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3647 | if (logerr) { |
| 3648 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3649 | "0137 No retry ELS command x%x to remote " |
| 3650 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 3651 | cmd, did, irsp->ulpStatus, |
| 3652 | irsp->un.ulpWord[4]); |
| 3653 | } |
| 3654 | else { |
| 3655 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3656 | "0108 No retry ELS command x%x to remote " |
| 3657 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 3658 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 3659 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3660 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3661 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3662 | } |
| 3663 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3664 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3665 | * 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] | 3666 | * @phba: pointer to lpfc hba data structure. |
| 3667 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3668 | * |
| 3669 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3670 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3671 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3672 | * response of the command IOCB. If so, it will be released before releasing |
| 3673 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3674 | * |
| 3675 | * Return code |
| 3676 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3677 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3678 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3679 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3680 | { |
| 3681 | struct lpfc_dmabuf *buf_ptr; |
| 3682 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3683 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3684 | if (!list_empty(&buf_ptr1->list)) { |
| 3685 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3686 | struct lpfc_dmabuf, |
| 3687 | list); |
| 3688 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3689 | kfree(buf_ptr); |
| 3690 | } |
| 3691 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3692 | kfree(buf_ptr1); |
| 3693 | return 0; |
| 3694 | } |
| 3695 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3696 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3697 | * 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] | 3698 | * @phba: pointer to lpfc hba data structure. |
| 3699 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3700 | * |
| 3701 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3702 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3703 | * pool. |
| 3704 | * |
| 3705 | * Return code |
| 3706 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3707 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3708 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3709 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3710 | { |
| 3711 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3712 | kfree(buf_ptr); |
| 3713 | return 0; |
| 3714 | } |
| 3715 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3716 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3717 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3718 | * @phba: pointer to lpfc hba data structure. |
| 3719 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3720 | * |
| 3721 | * This routine frees a command IOCB and its associated resources. The |
| 3722 | * command IOCB data structure contains the reference to various associated |
| 3723 | * resources, these fields must be set to NULL if the associated reference |
| 3724 | * not present: |
| 3725 | * context1 - reference to ndlp |
| 3726 | * context2 - reference to cmd |
| 3727 | * context2->next - reference to rsp |
| 3728 | * context3 - reference to bpl |
| 3729 | * |
| 3730 | * It first properly decrements the reference count held on ndlp for the |
| 3731 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3732 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3733 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3734 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3735 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3736 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3737 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3738 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3739 | * |
| 3740 | * Return code |
| 3741 | * 0 - Success (currently, always return 0) |
| 3742 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3743 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3744 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3745 | { |
| 3746 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3747 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3748 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3749 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3750 | if (ndlp) { |
| 3751 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3752 | lpfc_nlp_put(ndlp); |
| 3753 | |
| 3754 | /* If the ndlp is not being used by another discovery |
| 3755 | * thread, free it. |
| 3756 | */ |
| 3757 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3758 | /* If ndlp is being used by another discovery |
| 3759 | * thread, just clear NLP_DEFER_RM |
| 3760 | */ |
| 3761 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3762 | } |
| 3763 | } |
| 3764 | else |
| 3765 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3766 | elsiocb->context1 = NULL; |
| 3767 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3768 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3769 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3770 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3771 | /* Firmware could still be in progress of DMAing |
| 3772 | * payload, so don't free data buffer till after |
| 3773 | * a hbeat. |
| 3774 | */ |
| 3775 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3776 | buf_ptr = elsiocb->context2; |
| 3777 | elsiocb->context2 = NULL; |
| 3778 | if (buf_ptr) { |
| 3779 | buf_ptr1 = NULL; |
| 3780 | spin_lock_irq(&phba->hbalock); |
| 3781 | if (!list_empty(&buf_ptr->list)) { |
| 3782 | list_remove_head(&buf_ptr->list, |
| 3783 | buf_ptr1, struct lpfc_dmabuf, |
| 3784 | list); |
| 3785 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3786 | list_add_tail(&buf_ptr1->list, |
| 3787 | &phba->elsbuf); |
| 3788 | phba->elsbuf_cnt++; |
| 3789 | } |
| 3790 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3791 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3792 | phba->elsbuf_cnt++; |
| 3793 | spin_unlock_irq(&phba->hbalock); |
| 3794 | } |
| 3795 | } else { |
| 3796 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3797 | lpfc_els_free_data(phba, buf_ptr1); |
Johannes Thumshirn | 8667f51 | 2017-01-10 12:05:54 +0100 | [diff] [blame] | 3798 | elsiocb->context2 = NULL; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3799 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | if (elsiocb->context3) { |
| 3803 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3804 | lpfc_els_free_bpl(phba, buf_ptr); |
Johannes Thumshirn | 8667f51 | 2017-01-10 12:05:54 +0100 | [diff] [blame] | 3805 | elsiocb->context3 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3806 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3807 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3808 | return 0; |
| 3809 | } |
| 3810 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3811 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3812 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3813 | * @phba: pointer to lpfc hba data structure. |
| 3814 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3815 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3816 | * |
| 3817 | * This routine is the completion callback function to the Logout (LOGO) |
| 3818 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3819 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3820 | * release the ndlp if it has the last reference remaining (reference count |
| 3821 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3822 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3823 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3824 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3825 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3826 | * IOCB data structure. |
| 3827 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3828 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3829 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3830 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3831 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3832 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3833 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3834 | IOCB_t *irsp; |
| 3835 | |
| 3836 | irsp = &rspiocb->iocb; |
| 3837 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3838 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3839 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3840 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3841 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3842 | "0109 ACC to LOGO completes to NPort x%x " |
| 3843 | "Data: x%x x%x x%x\n", |
| 3844 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3845 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3846 | |
| 3847 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3848 | /* NPort Recovery mode or node is just allocated */ |
| 3849 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3850 | /* If the ndlp is being used by another discovery |
| 3851 | * thread, just unregister the RPI. |
| 3852 | */ |
| 3853 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3854 | } else { |
| 3855 | /* Indicate the node has already released, should |
| 3856 | * not reference to it from within lpfc_els_free_iocb. |
| 3857 | */ |
| 3858 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3859 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3860 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3861 | |
| 3862 | /* |
| 3863 | * 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] | 3864 | * At this point, the driver is done so release the IOCB |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3865 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3866 | lpfc_els_free_iocb(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3867 | } |
| 3868 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3869 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3870 | * 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] | 3871 | * @phba: pointer to lpfc hba data structure. |
| 3872 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3873 | * |
| 3874 | * This routine is the completion callback function for unregister default |
| 3875 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3876 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3877 | * decrements the ndlp reference count held for this completion callback |
| 3878 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3879 | * whether there is only one reference left on the ndlp. If so, it will |
| 3880 | * perform one more decrement and trigger the release of the ndlp. |
| 3881 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3882 | void |
| 3883 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3884 | { |
| 3885 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3886 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3887 | |
| 3888 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3889 | pmb->context2 = NULL; |
| 3890 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3891 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3892 | kfree(mp); |
| 3893 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3894 | if (ndlp) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3895 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3896 | "0006 rpi%x DID:%x flg:%x %d map:%x %p\n", |
| 3897 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 3898 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3899 | ndlp->nlp_usg_map, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3900 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 3901 | lpfc_nlp_put(ndlp); |
| 3902 | /* This is the end of the default RPI cleanup logic for |
| 3903 | * this ndlp. If no other discovery threads are using |
| 3904 | * this ndlp, free all resources associated with it. |
| 3905 | */ |
| 3906 | lpfc_nlp_not_used(ndlp); |
| 3907 | } else { |
| 3908 | lpfc_drop_node(ndlp->vport, ndlp); |
| 3909 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3910 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3911 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3912 | return; |
| 3913 | } |
| 3914 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3915 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3916 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3917 | * @phba: pointer to lpfc hba data structure. |
| 3918 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3919 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3920 | * |
| 3921 | * This routine is the completion callback function for ELS Response IOCB |
| 3922 | * command. In normal case, this callback function just properly sets the |
| 3923 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3924 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3925 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3926 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3927 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3928 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3929 | * are currently referring it. |
| 3930 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3931 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3932 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3933 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3934 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3935 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3936 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3937 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3938 | IOCB_t *irsp; |
| 3939 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3940 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3941 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3942 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3943 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3944 | irsp = &rspiocb->iocb; |
| 3945 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3946 | if (cmdiocb->context_un.mbox) |
| 3947 | mbox = cmdiocb->context_un.mbox; |
| 3948 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3949 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3950 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3951 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3952 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3953 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3954 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3955 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3956 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3957 | */ |
| 3958 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3959 | ls_rjt = 1; |
| 3960 | } |
| 3961 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3962 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3963 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3964 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3965 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3966 | if (mp) { |
| 3967 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3968 | kfree(mp); |
| 3969 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3970 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3971 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3972 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3973 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3974 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3975 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3976 | /* Indicate the node has already released, |
| 3977 | * should not reference to it from within |
| 3978 | * the routine lpfc_els_free_iocb. |
| 3979 | */ |
| 3980 | cmdiocb->context1 = NULL; |
| 3981 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3982 | goto out; |
| 3983 | } |
| 3984 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3985 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3986 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3987 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3988 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3989 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3990 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3991 | "0110 ELS response tag x%x completes " |
| 3992 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3993 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3994 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3995 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3996 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3997 | if (mbox) { |
| 3998 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3999 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
Dick Kennedy | 1fe6847 | 2017-08-23 16:55:30 -0700 | [diff] [blame] | 4000 | if (!lpfc_unreg_rpi(vport, ndlp) && |
| 4001 | (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 4002 | ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) { |
| 4003 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4004 | LOG_DISCOVERY, |
| 4005 | "0314 PLOGI recov DID x%x " |
| 4006 | "Data: x%x x%x x%x\n", |
| 4007 | ndlp->nlp_DID, ndlp->nlp_state, |
| 4008 | ndlp->nlp_rpi, ndlp->nlp_flag); |
| 4009 | mp = mbox->context1; |
| 4010 | if (mp) { |
| 4011 | lpfc_mbuf_free(phba, mp->virt, |
| 4012 | mp->phys); |
| 4013 | kfree(mp); |
| 4014 | } |
| 4015 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4016 | goto out; |
| 4017 | } |
| 4018 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4019 | /* Increment reference count to ndlp to hold the |
| 4020 | * reference to ndlp for the callback function. |
| 4021 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4022 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4023 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4024 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 4025 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 4026 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 4027 | } |
| 4028 | else { |
| 4029 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 4030 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 4031 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4032 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4033 | } |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 4034 | |
| 4035 | ndlp->nlp_flag |= NLP_REG_LOGIN_SEND; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4036 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4037 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4038 | goto out; |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 4039 | |
| 4040 | /* Decrement the ndlp reference count we |
| 4041 | * set for this failed mailbox command. |
| 4042 | */ |
| 4043 | lpfc_nlp_put(ndlp); |
| 4044 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4045 | |
| 4046 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 4047 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4048 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 4049 | "Data: x%x x%x x%x\n", |
| 4050 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4051 | ndlp->nlp_rpi); |
| 4052 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4053 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4054 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4055 | /* Indicate node has already been released, |
| 4056 | * should not reference to it from within |
| 4057 | * the routine lpfc_els_free_iocb. |
| 4058 | */ |
| 4059 | cmdiocb->context1 = NULL; |
| 4060 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4061 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4062 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 4063 | if (!lpfc_error_lost_link(irsp) && |
| 4064 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4065 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4066 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4067 | /* Indicate node has already been |
| 4068 | * released, should not reference |
| 4069 | * to it from within the routine |
| 4070 | * lpfc_els_free_iocb. |
| 4071 | */ |
| 4072 | cmdiocb->context1 = NULL; |
| 4073 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | } |
| 4075 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 4076 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 4077 | if (mp) { |
| 4078 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4079 | kfree(mp); |
| 4080 | } |
| 4081 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 | } |
| 4083 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4084 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4085 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4086 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4087 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4088 | |
| 4089 | /* If the node is not being used by another discovery thread, |
| 4090 | * and we are sending a reject, we are done with it. |
| 4091 | * Release driver reference count here and free associated |
| 4092 | * resources. |
| 4093 | */ |
| 4094 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4095 | if (lpfc_nlp_not_used(ndlp)) |
| 4096 | /* Indicate node has already been released, |
| 4097 | * should not reference to it from within |
| 4098 | * the routine lpfc_els_free_iocb. |
| 4099 | */ |
| 4100 | cmdiocb->context1 = NULL; |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 4101 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4102 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4103 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | lpfc_els_free_iocb(phba, cmdiocb); |
| 4105 | return; |
| 4106 | } |
| 4107 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4108 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4109 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4110 | * @vport: pointer to a host virtual N_Port data structure. |
| 4111 | * @flag: the els command code to be accepted. |
| 4112 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4113 | * @ndlp: pointer to a node-list data structure. |
| 4114 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4115 | * |
| 4116 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 4117 | * command. It uses the @flag to properly set up the IOCB field for the |
| 4118 | * specific ACC response command to be issued and invokes the |
| 4119 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 4120 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 4121 | * field of the IOCB for the completion callback function to issue the |
| 4122 | * mailbox command to the HBA later when callback is invoked. |
| 4123 | * |
| 4124 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4125 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4126 | * will be stored into the context1 field of the IOCB for the completion |
| 4127 | * callback function to the corresponding response ELS IOCB command. |
| 4128 | * |
| 4129 | * Return code |
| 4130 | * 0 - Successfully issued acc response |
| 4131 | * 1 - Failed to issue acc response |
| 4132 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4133 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4134 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 4135 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4136 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4137 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4138 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4139 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4140 | IOCB_t *icmd; |
| 4141 | IOCB_t *oldcmd; |
| 4142 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4143 | uint8_t *pcmd; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4144 | struct serv_parm *sp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4145 | uint16_t cmdsize; |
| 4146 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4147 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4148 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4149 | oldcmd = &oldiocb->iocb; |
| 4150 | |
| 4151 | switch (flag) { |
| 4152 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4153 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4154 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 4155 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4156 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4157 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4158 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4159 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4160 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4161 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4162 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4163 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4164 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4165 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4166 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4167 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4168 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4169 | |
| 4170 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4171 | "Issue ACC: did:x%x flg:x%x", |
| 4172 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4173 | break; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4174 | case ELS_CMD_FLOGI: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4176 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4177 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 4178 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4179 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4180 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4181 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4182 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4183 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4184 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4185 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4186 | |
| 4187 | if (mbox) |
| 4188 | elsiocb->context_un.mbox = mbox; |
| 4189 | |
| 4190 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4191 | pcmd += sizeof(uint32_t); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4192 | sp = (struct serv_parm *)pcmd; |
| 4193 | |
| 4194 | if (flag == ELS_CMD_FLOGI) { |
| 4195 | /* Copy the received service parameters back */ |
| 4196 | memcpy(sp, &phba->fc_fabparam, |
| 4197 | sizeof(struct serv_parm)); |
| 4198 | |
| 4199 | /* Clear the F_Port bit */ |
| 4200 | sp->cmn.fPort = 0; |
| 4201 | |
| 4202 | /* Mark all class service parameters as invalid */ |
| 4203 | sp->cls1.classValid = 0; |
| 4204 | sp->cls2.classValid = 0; |
| 4205 | sp->cls3.classValid = 0; |
| 4206 | sp->cls4.classValid = 0; |
| 4207 | |
| 4208 | /* Copy our worldwide names */ |
| 4209 | memcpy(&sp->portName, &vport->fc_sparam.portName, |
| 4210 | sizeof(struct lpfc_name)); |
| 4211 | memcpy(&sp->nodeName, &vport->fc_sparam.nodeName, |
| 4212 | sizeof(struct lpfc_name)); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4213 | } else { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4214 | memcpy(pcmd, &vport->fc_sparam, |
| 4215 | sizeof(struct serv_parm)); |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 4216 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4217 | sp->cmn.valid_vendor_ver_level = 0; |
| 4218 | memset(sp->un.vendorVersion, 0, |
| 4219 | sizeof(sp->un.vendorVersion)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 4220 | sp->cmn.bbRcvSizeMsb &= 0xF; |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4221 | |
| 4222 | /* If our firmware supports this feature, convey that |
| 4223 | * info to the target using the vendor specific field. |
| 4224 | */ |
| 4225 | if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { |
| 4226 | sp->cmn.valid_vendor_ver_level = 1; |
| 4227 | sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); |
| 4228 | sp->un.vv.flags = |
| 4229 | cpu_to_be32(LPFC_VV_SUPPRESS_RSP); |
| 4230 | } |
| 4231 | } |
| 4232 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4233 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4234 | "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4235 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4236 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4237 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4238 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4239 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4240 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 4241 | if (!elsiocb) |
| 4242 | return 1; |
| 4243 | |
| 4244 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4245 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4246 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4247 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4248 | |
| 4249 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4250 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4251 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 4252 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 4253 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4254 | |
| 4255 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4256 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 4257 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4258 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4259 | default: |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4260 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4261 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4262 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4263 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4264 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 4265 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x " |
| 4266 | "fc_flag x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4267 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4268 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 4269 | ndlp->nlp_rpi, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4270 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4271 | spin_lock_irq(shost->host_lock); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4272 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4273 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND)) |
| 4274 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4275 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4276 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 4277 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4278 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4279 | } |
| 4280 | |
| 4281 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4282 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4283 | if (rc == IOCB_ERROR) { |
| 4284 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4285 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4286 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4287 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4288 | } |
| 4289 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4290 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4291 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4292 | * @vport: pointer to a virtual N_Port data structure. |
| 4293 | * @rejectError: |
| 4294 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4295 | * @ndlp: pointer to a node-list data structure. |
| 4296 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4297 | * |
| 4298 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 4299 | * command. If a @mbox pointer is passed in, it will be put into the |
| 4300 | * context_un.mbox field of the IOCB for the completion callback function |
| 4301 | * to issue to the HBA later. |
| 4302 | * |
| 4303 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4304 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4305 | * will be stored into the context1 field of the IOCB for the completion |
| 4306 | * callback function to the reject response ELS IOCB command. |
| 4307 | * |
| 4308 | * Return code |
| 4309 | * 0 - Successfully issued reject response |
| 4310 | * 1 - Failed to issue reject response |
| 4311 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4312 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4313 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4314 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 4315 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4316 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4317 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4318 | IOCB_t *icmd; |
| 4319 | IOCB_t *oldcmd; |
| 4320 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4321 | uint8_t *pcmd; |
| 4322 | uint16_t cmdsize; |
| 4323 | int rc; |
| 4324 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4325 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4326 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4327 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4328 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4329 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4330 | |
| 4331 | icmd = &elsiocb->iocb; |
| 4332 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4333 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4334 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4335 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4336 | |
| 4337 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4338 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4339 | *((uint32_t *) (pcmd)) = rejectError; |
| 4340 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4341 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4342 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4343 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4345 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4346 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 4347 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4348 | "rpi x%x\n", |
| 4349 | rejectError, elsiocb->iotag, |
| 4350 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 4351 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4352 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4353 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 4354 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 4355 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4356 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4357 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4358 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4359 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4360 | if (rc == IOCB_ERROR) { |
| 4361 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4362 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4363 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4364 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4365 | } |
| 4366 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4367 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4368 | * 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] | 4369 | * @vport: pointer to a virtual N_Port data structure. |
| 4370 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4371 | * @ndlp: pointer to a node-list data structure. |
| 4372 | * |
| 4373 | * This routine prepares and issues an Accept (ACC) response to Address |
| 4374 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 4375 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4376 | * |
| 4377 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4378 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4379 | * will be stored into the context1 field of the IOCB for the completion |
| 4380 | * callback function to the ADISC Accept response ELS IOCB command. |
| 4381 | * |
| 4382 | * Return code |
| 4383 | * 0 - Successfully issued acc adisc response |
| 4384 | * 1 - Failed to issue adisc acc response |
| 4385 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4386 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4387 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 4388 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4389 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4390 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4391 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4392 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4393 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4394 | uint8_t *pcmd; |
| 4395 | uint16_t cmdsize; |
| 4396 | int rc; |
| 4397 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4398 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4399 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4400 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4401 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4402 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4403 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4404 | icmd = &elsiocb->iocb; |
| 4405 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4406 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4407 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4408 | |
| 4409 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4410 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4411 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 4412 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 4413 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4414 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4415 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4416 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4417 | |
| 4418 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4419 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4420 | |
| 4421 | ap = (ADISC *) (pcmd); |
| 4422 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4423 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4424 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4425 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4426 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4427 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4428 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 4429 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4430 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4431 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4432 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4433 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4434 | if (rc == IOCB_ERROR) { |
| 4435 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4436 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4437 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4438 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4439 | } |
| 4440 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4441 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4442 | * 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] | 4443 | * @vport: pointer to a virtual N_Port data structure. |
| 4444 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4445 | * @ndlp: pointer to a node-list data structure. |
| 4446 | * |
| 4447 | * This routine prepares and issues an Accept (ACC) response to Process |
| 4448 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 4449 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4450 | * |
| 4451 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4452 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4453 | * will be stored into the context1 field of the IOCB for the completion |
| 4454 | * callback function to the PRLI Accept response ELS IOCB command. |
| 4455 | * |
| 4456 | * Return code |
| 4457 | * 0 - Successfully issued acc prli response |
| 4458 | * 1 - Failed to issue acc prli response |
| 4459 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4460 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4461 | 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] | 4462 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4463 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4464 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4465 | PRLI *npr; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4466 | struct lpfc_nvme_prli *npr_nvme; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4467 | lpfc_vpd_t *vpd; |
| 4468 | IOCB_t *icmd; |
| 4469 | IOCB_t *oldcmd; |
| 4470 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4471 | uint8_t *pcmd; |
| 4472 | uint16_t cmdsize; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4473 | uint32_t prli_fc4_req, *req_payload; |
| 4474 | struct lpfc_dmabuf *req_buf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4475 | int rc; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4476 | u32 elsrspcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4477 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4478 | /* Need the incoming PRLI payload to determine if the ACC is for an |
| 4479 | * FC4 or NVME PRLI type. The PRLI type is at word 1. |
| 4480 | */ |
| 4481 | req_buf = (struct lpfc_dmabuf *)oldiocb->context2; |
| 4482 | req_payload = (((uint32_t *)req_buf->virt) + 1); |
| 4483 | |
| 4484 | /* PRLI type payload is at byte 3 for FCP or NVME. */ |
| 4485 | prli_fc4_req = be32_to_cpu(*req_payload); |
| 4486 | prli_fc4_req = (prli_fc4_req >> 24) & 0xff; |
| 4487 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4488 | "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n", |
| 4489 | prli_fc4_req, *((uint32_t *)req_payload)); |
| 4490 | |
| 4491 | if (prli_fc4_req == PRLI_FCP_TYPE) { |
| 4492 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
| 4493 | elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
| 4494 | } else if (prli_fc4_req & PRLI_NVME_TYPE) { |
| 4495 | cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli); |
| 4496 | elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK)); |
| 4497 | } else { |
| 4498 | return 1; |
| 4499 | } |
| 4500 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4501 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4502 | ndlp->nlp_DID, elsrspcmd); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4503 | if (!elsiocb) |
| 4504 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4505 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4506 | icmd = &elsiocb->iocb; |
| 4507 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4508 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4509 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4510 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4511 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4512 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4513 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 4514 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4515 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4516 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4517 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4518 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4519 | memset(pcmd, 0, cmdsize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4520 | |
James Smart | c07f10c | 2017-04-21 16:04:54 -0700 | [diff] [blame] | 4521 | *((uint32_t *)(pcmd)) = elsrspcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4522 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4523 | |
| 4524 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4525 | vpd = &phba->vpd; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4526 | |
| 4527 | if (prli_fc4_req == PRLI_FCP_TYPE) { |
| 4528 | /* |
| 4529 | * If the remote port is a target and our firmware version |
| 4530 | * is 3.20 or later, set the following bits for FC-TAPE |
| 4531 | * support. |
| 4532 | */ |
| 4533 | npr = (PRLI *) pcmd; |
| 4534 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 4535 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| 4536 | npr->ConfmComplAllowed = 1; |
| 4537 | npr->Retry = 1; |
| 4538 | npr->TaskRetryIdReq = 1; |
| 4539 | } |
| 4540 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 4541 | npr->estabImagePair = 1; |
| 4542 | npr->readXferRdyDis = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4543 | npr->ConfmComplAllowed = 1; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4544 | npr->prliType = PRLI_FCP_TYPE; |
| 4545 | npr->initiatorFunc = 1; |
| 4546 | } else if (prli_fc4_req & PRLI_NVME_TYPE) { |
| 4547 | /* Respond with an NVME PRLI Type */ |
| 4548 | npr_nvme = (struct lpfc_nvme_prli *) pcmd; |
| 4549 | bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); |
| 4550 | bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ |
| 4551 | bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4552 | if (phba->nvmet_support) { |
| 4553 | bf_set(prli_tgt, npr_nvme, 1); |
| 4554 | bf_set(prli_disc, npr_nvme, 1); |
| 4555 | if (phba->cfg_nvme_enable_fb) { |
| 4556 | bf_set(prli_fba, npr_nvme, 1); |
| 4557 | |
| 4558 | /* TBD. Target mode needs to post buffers |
| 4559 | * that support the configured first burst |
| 4560 | * byte size. |
| 4561 | */ |
| 4562 | bf_set(prli_fb_sz, npr_nvme, |
| 4563 | phba->cfg_nvmet_fb_size); |
| 4564 | } |
| 4565 | } else { |
| 4566 | bf_set(prli_init, npr_nvme, 1); |
| 4567 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4568 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4569 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, |
| 4570 | "6015 NVME issue PRLI ACC word1 x%08x " |
| 4571 | "word4 x%08x word5 x%08x flag x%x, " |
| 4572 | "fcp_info x%x nlp_type x%x\n", |
| 4573 | npr_nvme->word1, npr_nvme->word4, |
| 4574 | npr_nvme->word5, ndlp->nlp_flag, |
| 4575 | ndlp->nlp_fcp_info, ndlp->nlp_type); |
| 4576 | npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); |
| 4577 | npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); |
| 4578 | npr_nvme->word5 = cpu_to_be32(npr_nvme->word5); |
| 4579 | } else |
| 4580 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4581 | "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n", |
| 4582 | prli_fc4_req, ndlp->nlp_fc4_type, |
| 4583 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4584 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4585 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4586 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 4587 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4588 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4589 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4590 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4591 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4592 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4593 | if (rc == IOCB_ERROR) { |
| 4594 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4595 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4596 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4597 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4598 | } |
| 4599 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4600 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4601 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4602 | * @vport: pointer to a virtual N_Port data structure. |
| 4603 | * @format: rnid command format. |
| 4604 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4605 | * @ndlp: pointer to a node-list data structure. |
| 4606 | * |
| 4607 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 4608 | * (ACC) response. It constructs the RNID ACC response command according to |
| 4609 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 4610 | * issue the response. Note that this command does not need to hold the ndlp |
| 4611 | * reference count for the callback. So, the ndlp reference count taken by |
| 4612 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 4613 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 4614 | * there is no ndlp reference available. |
| 4615 | * |
| 4616 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4617 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4618 | * will be stored into the context1 field of the IOCB for the completion |
| 4619 | * callback function. However, for the RNID Accept Response ELS command, |
| 4620 | * this is undone later by this routine after the IOCB is allocated. |
| 4621 | * |
| 4622 | * Return code |
| 4623 | * 0 - Successfully issued acc rnid response |
| 4624 | * 1 - Failed to issue acc rnid response |
| 4625 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4626 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4627 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4628 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4629 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4630 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4631 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4632 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4633 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4634 | uint8_t *pcmd; |
| 4635 | uint16_t cmdsize; |
| 4636 | int rc; |
| 4637 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4638 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 4639 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4640 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4641 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4642 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4643 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4644 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4645 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4646 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4647 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4648 | icmd = &elsiocb->iocb; |
| 4649 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4650 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4651 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4652 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4653 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4654 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4655 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 4656 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4657 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4658 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4659 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4660 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4661 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4662 | rn = (RNID *) (pcmd); |
| 4663 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4664 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 4665 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4666 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4667 | switch (format) { |
| 4668 | case 0: |
| 4669 | rn->SpecificLen = 0; |
| 4670 | break; |
| 4671 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4672 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4673 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4674 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4675 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 4676 | rn->un.topologyDisc.physPort = 0; |
| 4677 | rn->un.topologyDisc.attachedNodes = 0; |
| 4678 | break; |
| 4679 | default: |
| 4680 | rn->CommonLen = 0; |
| 4681 | rn->SpecificLen = 0; |
| 4682 | break; |
| 4683 | } |
| 4684 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4685 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4686 | "Issue ACC RNID: did:x%x flg:x%x", |
| 4687 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4688 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4689 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4690 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4691 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4692 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4693 | if (rc == IOCB_ERROR) { |
| 4694 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4695 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4696 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4697 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4698 | } |
| 4699 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4700 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4701 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. |
| 4702 | * @vport: pointer to a virtual N_Port data structure. |
| 4703 | * @iocb: pointer to the lpfc command iocb data structure. |
| 4704 | * @ndlp: pointer to a node-list data structure. |
| 4705 | * |
| 4706 | * Return |
| 4707 | **/ |
| 4708 | static void |
| 4709 | lpfc_els_clear_rrq(struct lpfc_vport *vport, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4710 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4711 | { |
| 4712 | struct lpfc_hba *phba = vport->phba; |
| 4713 | uint8_t *pcmd; |
| 4714 | struct RRQ *rrq; |
| 4715 | uint16_t rxid; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4716 | uint16_t xri; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4717 | struct lpfc_node_rrq *prrq; |
| 4718 | |
| 4719 | |
| 4720 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); |
| 4721 | pcmd += sizeof(uint32_t); |
| 4722 | rrq = (struct RRQ *)pcmd; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4723 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4724 | rxid = bf_get(rrq_rxid, rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4725 | |
| 4726 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4727 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" |
| 4728 | " x%x x%x\n", |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4729 | be32_to_cpu(bf_get(rrq_did, rrq)), |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4730 | bf_get(rrq_oxid, rrq), |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4731 | rxid, |
| 4732 | iocb->iotag, iocb->iocb.ulpContext); |
| 4733 | |
| 4734 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4735 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", |
| 4736 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4737 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4738 | xri = bf_get(rrq_oxid, rrq); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4739 | else |
| 4740 | xri = rxid; |
| 4741 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4742 | if (prrq) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4743 | lpfc_clr_rrq_active(phba, xri, prrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4744 | return; |
| 4745 | } |
| 4746 | |
| 4747 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4748 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 4749 | * @vport: pointer to a virtual N_Port data structure. |
| 4750 | * @data: pointer to echo data to return in the accept. |
| 4751 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4752 | * @ndlp: pointer to a node-list data structure. |
| 4753 | * |
| 4754 | * Return code |
| 4755 | * 0 - Successfully issued acc echo response |
| 4756 | * 1 - Failed to issue acc echo response |
| 4757 | **/ |
| 4758 | static int |
| 4759 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 4760 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 4761 | { |
| 4762 | struct lpfc_hba *phba = vport->phba; |
| 4763 | struct lpfc_iocbq *elsiocb; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4764 | uint8_t *pcmd; |
| 4765 | uint16_t cmdsize; |
| 4766 | int rc; |
| 4767 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4768 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 4769 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4770 | /* The accumulated length can exceed the BPL_SIZE. For |
| 4771 | * now, use this as the limit |
| 4772 | */ |
| 4773 | if (cmdsize > LPFC_BPL_SIZE) |
| 4774 | cmdsize = LPFC_BPL_SIZE; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4775 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4776 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4777 | if (!elsiocb) |
| 4778 | return 1; |
| 4779 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4780 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 4781 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; |
| 4782 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4783 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 4784 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4785 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 4786 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 4787 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4788 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4789 | pcmd += sizeof(uint32_t); |
| 4790 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 4791 | |
| 4792 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4793 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 4794 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4795 | |
| 4796 | phba->fc_stat.elsXmitACC++; |
| 4797 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4798 | |
| 4799 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4800 | if (rc == IOCB_ERROR) { |
| 4801 | lpfc_els_free_iocb(phba, elsiocb); |
| 4802 | return 1; |
| 4803 | } |
| 4804 | return 0; |
| 4805 | } |
| 4806 | |
| 4807 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4808 | * 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] | 4809 | * @vport: pointer to a host virtual N_Port data structure. |
| 4810 | * |
| 4811 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 4812 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 4813 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 4814 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 4815 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 4816 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 4817 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 4818 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 4819 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 4820 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 4821 | * no more ADISC need to be sent. |
| 4822 | * |
| 4823 | * Return code |
| 4824 | * The number of N_Ports with adisc issued. |
| 4825 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4826 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4827 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4828 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4829 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4830 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4831 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4832 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4833 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4834 | 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] | 4835 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4836 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4837 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4838 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4839 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4840 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4841 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4842 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4843 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4844 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4845 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4846 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4847 | vport->num_disc_nodes++; |
| 4848 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4849 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4850 | spin_lock_irq(shost->host_lock); |
| 4851 | vport->fc_flag |= FC_NLP_MORE; |
| 4852 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4853 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4854 | } |
| 4855 | } |
| 4856 | } |
| 4857 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4858 | spin_lock_irq(shost->host_lock); |
| 4859 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4860 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4861 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4862 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4863 | } |
| 4864 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4865 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4866 | * 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] | 4867 | * @vport: pointer to a host virtual N_Port data structure. |
| 4868 | * |
| 4869 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4870 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4871 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4872 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4873 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4874 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4875 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4876 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4877 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4878 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4879 | * PLOGI need to be sent. |
| 4880 | * |
| 4881 | * Return code |
| 4882 | * The number of N_Ports with plogi issued. |
| 4883 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4884 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4885 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4886 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4887 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4888 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4889 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4890 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4891 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4892 | 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] | 4893 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4894 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4895 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4896 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4897 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4898 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4899 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4900 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4901 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4902 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4903 | vport->num_disc_nodes++; |
| 4904 | if (vport->num_disc_nodes >= |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4905 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4906 | spin_lock_irq(shost->host_lock); |
| 4907 | vport->fc_flag |= FC_NLP_MORE; |
| 4908 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4909 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4910 | } |
| 4911 | } |
| 4912 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4913 | if (sentplogi) { |
| 4914 | lpfc_set_disctmo(vport); |
| 4915 | } |
| 4916 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4917 | spin_lock_irq(shost->host_lock); |
| 4918 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4919 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4920 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4921 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4922 | } |
| 4923 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4924 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4925 | lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc, |
| 4926 | uint32_t word0) |
| 4927 | { |
| 4928 | |
| 4929 | desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG); |
| 4930 | desc->payload.els_req = word0; |
| 4931 | desc->length = cpu_to_be32(sizeof(desc->payload)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4932 | |
| 4933 | return sizeof(struct fc_rdp_link_service_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4934 | } |
| 4935 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4936 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4937 | lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc, |
| 4938 | uint8_t *page_a0, uint8_t *page_a2) |
| 4939 | { |
| 4940 | uint16_t wavelength; |
| 4941 | uint16_t temperature; |
| 4942 | uint16_t rx_power; |
| 4943 | uint16_t tx_bias; |
| 4944 | uint16_t tx_power; |
| 4945 | uint16_t vcc; |
| 4946 | uint16_t flag = 0; |
| 4947 | struct sff_trasnceiver_codes_byte4 *trasn_code_byte4; |
| 4948 | struct sff_trasnceiver_codes_byte5 *trasn_code_byte5; |
| 4949 | |
| 4950 | desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG); |
| 4951 | |
| 4952 | trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *) |
| 4953 | &page_a0[SSF_TRANSCEIVER_CODE_B4]; |
| 4954 | trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *) |
| 4955 | &page_a0[SSF_TRANSCEIVER_CODE_B5]; |
| 4956 | |
| 4957 | if ((trasn_code_byte4->fc_sw_laser) || |
| 4958 | (trasn_code_byte5->fc_sw_laser_sl) || |
| 4959 | (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */ |
| 4960 | flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT); |
| 4961 | } else if (trasn_code_byte4->fc_lw_laser) { |
| 4962 | wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) | |
| 4963 | page_a0[SSF_WAVELENGTH_B0]; |
| 4964 | if (wavelength == SFP_WAVELENGTH_LC1310) |
| 4965 | flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT; |
| 4966 | if (wavelength == SFP_WAVELENGTH_LL1550) |
| 4967 | flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT; |
| 4968 | } |
| 4969 | /* check if its SFP+ */ |
| 4970 | flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ? |
| 4971 | SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN) |
| 4972 | << SFP_FLAG_CT_SHIFT; |
| 4973 | |
| 4974 | /* check if its OPTICAL */ |
| 4975 | flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ? |
| 4976 | SFP_FLAG_IS_OPTICAL_PORT : 0) |
| 4977 | << SFP_FLAG_IS_OPTICAL_SHIFT; |
| 4978 | |
| 4979 | temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 | |
| 4980 | page_a2[SFF_TEMPERATURE_B0]); |
| 4981 | vcc = (page_a2[SFF_VCC_B1] << 8 | |
| 4982 | page_a2[SFF_VCC_B0]); |
| 4983 | tx_power = (page_a2[SFF_TXPOWER_B1] << 8 | |
| 4984 | page_a2[SFF_TXPOWER_B0]); |
| 4985 | tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 | |
| 4986 | page_a2[SFF_TX_BIAS_CURRENT_B0]); |
| 4987 | rx_power = (page_a2[SFF_RXPOWER_B1] << 8 | |
| 4988 | page_a2[SFF_RXPOWER_B0]); |
| 4989 | desc->sfp_info.temperature = cpu_to_be16(temperature); |
| 4990 | desc->sfp_info.rx_power = cpu_to_be16(rx_power); |
| 4991 | desc->sfp_info.tx_bias = cpu_to_be16(tx_bias); |
| 4992 | desc->sfp_info.tx_power = cpu_to_be16(tx_power); |
| 4993 | desc->sfp_info.vcc = cpu_to_be16(vcc); |
| 4994 | |
| 4995 | desc->sfp_info.flags = cpu_to_be16(flag); |
| 4996 | desc->length = cpu_to_be32(sizeof(desc->sfp_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4997 | |
| 4998 | return sizeof(struct fc_rdp_sfp_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4999 | } |
| 5000 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5001 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5002 | lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc, |
| 5003 | READ_LNK_VAR *stat) |
| 5004 | { |
| 5005 | uint32_t type; |
| 5006 | |
| 5007 | desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG); |
| 5008 | |
| 5009 | type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT; |
| 5010 | |
| 5011 | desc->info.port_type = cpu_to_be32(type); |
| 5012 | |
| 5013 | desc->info.link_status.link_failure_cnt = |
| 5014 | cpu_to_be32(stat->linkFailureCnt); |
| 5015 | desc->info.link_status.loss_of_synch_cnt = |
| 5016 | cpu_to_be32(stat->lossSyncCnt); |
| 5017 | desc->info.link_status.loss_of_signal_cnt = |
| 5018 | cpu_to_be32(stat->lossSignalCnt); |
| 5019 | desc->info.link_status.primitive_seq_proto_err = |
| 5020 | cpu_to_be32(stat->primSeqErrCnt); |
| 5021 | desc->info.link_status.invalid_trans_word = |
| 5022 | cpu_to_be32(stat->invalidXmitWord); |
| 5023 | desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt); |
| 5024 | |
| 5025 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5026 | |
| 5027 | return sizeof(struct fc_rdp_link_error_status_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5028 | } |
| 5029 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5030 | static uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5031 | lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat, |
| 5032 | struct lpfc_vport *vport) |
| 5033 | { |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5034 | uint32_t bbCredit; |
| 5035 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5036 | desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG); |
| 5037 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5038 | bbCredit = vport->fc_sparam.cmn.bbCreditLsb | |
| 5039 | (vport->fc_sparam.cmn.bbCreditMsb << 8); |
| 5040 | desc->bbc_info.port_bbc = cpu_to_be32(bbCredit); |
| 5041 | if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
| 5042 | bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb | |
| 5043 | (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8); |
| 5044 | desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit); |
| 5045 | } else { |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5046 | desc->bbc_info.attached_port_bbc = 0; |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5047 | } |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5048 | |
| 5049 | desc->bbc_info.rtt = 0; |
| 5050 | desc->length = cpu_to_be32(sizeof(desc->bbc_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5051 | |
| 5052 | return sizeof(struct fc_rdp_bbc_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5053 | } |
| 5054 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5055 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5056 | lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba, |
| 5057 | struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2) |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5058 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5059 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5060 | |
| 5061 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5062 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5063 | desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM]; |
| 5064 | desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM]; |
| 5065 | desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING]; |
| 5066 | desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5067 | |
| 5068 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 5069 | flags |= RDP_OET_HIGH_ALARM; |
| 5070 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 5071 | flags |= RDP_OET_LOW_ALARM; |
| 5072 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 5073 | flags |= RDP_OET_HIGH_WARNING; |
| 5074 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 5075 | flags |= RDP_OET_LOW_WARNING; |
| 5076 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5077 | flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT); |
| 5078 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5079 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5080 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5081 | } |
| 5082 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5083 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5084 | lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba, |
| 5085 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5086 | uint8_t *page_a2) |
| 5087 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5088 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5089 | |
| 5090 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5091 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5092 | desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM]; |
| 5093 | desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM]; |
| 5094 | desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING]; |
| 5095 | desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5096 | |
| 5097 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 5098 | flags |= RDP_OET_HIGH_ALARM; |
| 5099 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 5100 | flags |= RDP_OET_LOW_ALARM; |
| 5101 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 5102 | flags |= RDP_OET_HIGH_WARNING; |
| 5103 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 5104 | flags |= RDP_OET_LOW_WARNING; |
| 5105 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5106 | flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT); |
| 5107 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5108 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5109 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5110 | } |
| 5111 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5112 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5113 | lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba, |
| 5114 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5115 | uint8_t *page_a2) |
| 5116 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5117 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5118 | |
| 5119 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5120 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5121 | desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM]; |
| 5122 | desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM]; |
| 5123 | desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING]; |
| 5124 | desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5125 | |
| 5126 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 5127 | flags |= RDP_OET_HIGH_ALARM; |
| 5128 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 5129 | flags |= RDP_OET_LOW_ALARM; |
| 5130 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 5131 | flags |= RDP_OET_HIGH_WARNING; |
| 5132 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 5133 | flags |= RDP_OET_LOW_WARNING; |
| 5134 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5135 | flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT); |
| 5136 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5137 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5138 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5139 | } |
| 5140 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5141 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5142 | lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba, |
| 5143 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5144 | uint8_t *page_a2) |
| 5145 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5146 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5147 | |
| 5148 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5149 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5150 | desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM]; |
| 5151 | desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM]; |
| 5152 | desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING]; |
| 5153 | desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5154 | |
| 5155 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 5156 | flags |= RDP_OET_HIGH_ALARM; |
| 5157 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 5158 | flags |= RDP_OET_LOW_ALARM; |
| 5159 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 5160 | flags |= RDP_OET_HIGH_WARNING; |
| 5161 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 5162 | flags |= RDP_OET_LOW_WARNING; |
| 5163 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5164 | flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT); |
| 5165 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5166 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5167 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5168 | } |
| 5169 | |
| 5170 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5171 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5172 | lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba, |
| 5173 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5174 | uint8_t *page_a2) |
| 5175 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5176 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5177 | |
| 5178 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5179 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5180 | desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM]; |
| 5181 | desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM]; |
| 5182 | desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING]; |
| 5183 | desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5184 | |
| 5185 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 5186 | flags |= RDP_OET_HIGH_ALARM; |
| 5187 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 5188 | flags |= RDP_OET_LOW_ALARM; |
| 5189 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 5190 | flags |= RDP_OET_HIGH_WARNING; |
| 5191 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 5192 | flags |= RDP_OET_LOW_WARNING; |
| 5193 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5194 | flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT); |
| 5195 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5196 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5197 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5198 | } |
| 5199 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5200 | static uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5201 | lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc, |
| 5202 | uint8_t *page_a0, struct lpfc_vport *vport) |
| 5203 | { |
| 5204 | desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG); |
| 5205 | memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16); |
| 5206 | memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16); |
| 5207 | memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5208 | memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5209 | memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8); |
| 5210 | desc->length = cpu_to_be32(sizeof(desc->opd_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5211 | return sizeof(struct fc_rdp_opd_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5212 | } |
| 5213 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5214 | static uint32_t |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5215 | lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat) |
| 5216 | { |
| 5217 | if (bf_get(lpfc_read_link_stat_gec2, stat) == 0) |
| 5218 | return 0; |
| 5219 | desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG); |
| 5220 | |
| 5221 | desc->info.CorrectedBlocks = |
| 5222 | cpu_to_be32(stat->fecCorrBlkCount); |
| 5223 | desc->info.UncorrectableBlocks = |
| 5224 | cpu_to_be32(stat->fecUncorrBlkCount); |
| 5225 | |
| 5226 | desc->length = cpu_to_be32(sizeof(desc->info)); |
| 5227 | |
| 5228 | return sizeof(struct fc_fec_rdp_desc); |
| 5229 | } |
| 5230 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5231 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5232 | lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba) |
| 5233 | { |
| 5234 | uint16_t rdp_cap = 0; |
| 5235 | uint16_t rdp_speed; |
| 5236 | |
| 5237 | desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG); |
| 5238 | |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5239 | switch (phba->fc_linkspeed) { |
| 5240 | case LPFC_LINK_SPEED_1GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5241 | rdp_speed = RDP_PS_1GB; |
| 5242 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5243 | case LPFC_LINK_SPEED_2GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5244 | rdp_speed = RDP_PS_2GB; |
| 5245 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5246 | case LPFC_LINK_SPEED_4GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5247 | rdp_speed = RDP_PS_4GB; |
| 5248 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5249 | case LPFC_LINK_SPEED_8GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5250 | rdp_speed = RDP_PS_8GB; |
| 5251 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5252 | case LPFC_LINK_SPEED_10GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5253 | rdp_speed = RDP_PS_10GB; |
| 5254 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5255 | case LPFC_LINK_SPEED_16GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5256 | rdp_speed = RDP_PS_16GB; |
| 5257 | break; |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 5258 | case LPFC_LINK_SPEED_32GHZ: |
| 5259 | rdp_speed = RDP_PS_32GB; |
| 5260 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5261 | default: |
| 5262 | rdp_speed = RDP_PS_UNKNOWN; |
| 5263 | break; |
| 5264 | } |
| 5265 | |
| 5266 | desc->info.port_speed.speed = cpu_to_be16(rdp_speed); |
| 5267 | |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 5268 | if (phba->lmt & LMT_32Gb) |
| 5269 | rdp_cap |= RDP_PS_32GB; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5270 | if (phba->lmt & LMT_16Gb) |
| 5271 | rdp_cap |= RDP_PS_16GB; |
| 5272 | if (phba->lmt & LMT_10Gb) |
| 5273 | rdp_cap |= RDP_PS_10GB; |
| 5274 | if (phba->lmt & LMT_8Gb) |
| 5275 | rdp_cap |= RDP_PS_8GB; |
| 5276 | if (phba->lmt & LMT_4Gb) |
| 5277 | rdp_cap |= RDP_PS_4GB; |
| 5278 | if (phba->lmt & LMT_2Gb) |
| 5279 | rdp_cap |= RDP_PS_2GB; |
| 5280 | if (phba->lmt & LMT_1Gb) |
| 5281 | rdp_cap |= RDP_PS_1GB; |
| 5282 | |
| 5283 | if (rdp_cap == 0) |
| 5284 | rdp_cap = RDP_CAP_UNKNOWN; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5285 | if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO) |
| 5286 | rdp_cap |= RDP_CAP_USER_CONFIGURED; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5287 | |
| 5288 | desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap); |
| 5289 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5290 | return sizeof(struct fc_rdp_port_speed_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5291 | } |
| 5292 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5293 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5294 | 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] | 5295 | struct lpfc_vport *vport) |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5296 | { |
| 5297 | |
| 5298 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 5299 | |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 5300 | memcpy(desc->port_names.wwnn, &vport->fc_nodename, |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5301 | sizeof(desc->port_names.wwnn)); |
| 5302 | |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 5303 | memcpy(desc->port_names.wwpn, &vport->fc_portname, |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5304 | sizeof(desc->port_names.wwpn)); |
| 5305 | |
| 5306 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5307 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5308 | } |
| 5309 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5310 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5311 | lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc, |
| 5312 | struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 5313 | { |
| 5314 | |
| 5315 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 5316 | if (vport->fc_flag & FC_FABRIC) { |
| 5317 | memcpy(desc->port_names.wwnn, &vport->fabric_nodename, |
| 5318 | sizeof(desc->port_names.wwnn)); |
| 5319 | |
| 5320 | memcpy(desc->port_names.wwpn, &vport->fabric_portname, |
| 5321 | sizeof(desc->port_names.wwpn)); |
| 5322 | } else { /* Point to Point */ |
| 5323 | memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename, |
| 5324 | sizeof(desc->port_names.wwnn)); |
| 5325 | |
| 5326 | memcpy(desc->port_names.wwnn, &ndlp->nlp_portname, |
| 5327 | sizeof(desc->port_names.wwpn)); |
| 5328 | } |
| 5329 | |
| 5330 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5331 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5332 | } |
| 5333 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5334 | static void |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5335 | lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context, |
| 5336 | int status) |
| 5337 | { |
| 5338 | struct lpfc_nodelist *ndlp = rdp_context->ndlp; |
| 5339 | struct lpfc_vport *vport = ndlp->vport; |
| 5340 | struct lpfc_iocbq *elsiocb; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5341 | struct ulp_bde64 *bpl; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5342 | IOCB_t *icmd; |
| 5343 | uint8_t *pcmd; |
| 5344 | struct ls_rjt *stat; |
| 5345 | struct fc_rdp_res_frame *rdp_res; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5346 | uint32_t cmdsize, len; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5347 | uint16_t *flag_ptr; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5348 | int rc; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5349 | |
| 5350 | if (status != SUCCESS) |
| 5351 | goto error; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5352 | |
| 5353 | /* 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] | 5354 | cmdsize = sizeof(struct fc_rdp_res_frame); |
| 5355 | |
| 5356 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, |
| 5357 | lpfc_max_els_tries, rdp_context->ndlp, |
| 5358 | rdp_context->ndlp->nlp_DID, ELS_CMD_ACC); |
| 5359 | lpfc_nlp_put(ndlp); |
| 5360 | if (!elsiocb) |
| 5361 | goto free_rdp_context; |
| 5362 | |
| 5363 | icmd = &elsiocb->iocb; |
| 5364 | icmd->ulpContext = rdp_context->rx_id; |
| 5365 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 5366 | |
| 5367 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5368 | "2171 Xmit RDP response tag x%x xri x%x, " |
| 5369 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x", |
| 5370 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5371 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5372 | ndlp->nlp_rpi); |
| 5373 | rdp_res = (struct fc_rdp_res_frame *) |
| 5374 | (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5375 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5376 | memset(pcmd, 0, sizeof(struct fc_rdp_res_frame)); |
| 5377 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5378 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5379 | /* Update Alarm and Warning */ |
| 5380 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS); |
| 5381 | phba->sfp_alarm |= *flag_ptr; |
| 5382 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS); |
| 5383 | phba->sfp_warning |= *flag_ptr; |
| 5384 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5385 | /* For RDP payload */ |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5386 | len = 8; |
| 5387 | len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *) |
| 5388 | (len + pcmd), ELS_CMD_RDP); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5389 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5390 | 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] | 5391 | rdp_context->page_a0, rdp_context->page_a2); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5392 | len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd), |
| 5393 | phba); |
| 5394 | len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *) |
| 5395 | (len + pcmd), &rdp_context->link_stat); |
| 5396 | 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] | 5397 | (len + pcmd), vport); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5398 | len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *) |
| 5399 | (len + pcmd), vport, ndlp); |
| 5400 | 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] | 5401 | &rdp_context->link_stat); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5402 | len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd), |
| 5403 | &rdp_context->link_stat, vport); |
| 5404 | len += lpfc_rdp_res_oed_temp_desc(phba, |
| 5405 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5406 | rdp_context->page_a2); |
| 5407 | len += lpfc_rdp_res_oed_voltage_desc(phba, |
| 5408 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5409 | rdp_context->page_a2); |
| 5410 | len += lpfc_rdp_res_oed_txbias_desc(phba, |
| 5411 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5412 | rdp_context->page_a2); |
| 5413 | len += lpfc_rdp_res_oed_txpower_desc(phba, |
| 5414 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5415 | rdp_context->page_a2); |
| 5416 | len += lpfc_rdp_res_oed_rxpower_desc(phba, |
| 5417 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5418 | rdp_context->page_a2); |
| 5419 | len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd), |
| 5420 | rdp_context->page_a0, vport); |
| 5421 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5422 | rdp_res->length = cpu_to_be32(len - 8); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5423 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5424 | |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5425 | /* Now that we know the true size of the payload, update the BPL */ |
| 5426 | bpl = (struct ulp_bde64 *) |
| 5427 | (((struct lpfc_dmabuf *)(elsiocb->context3))->virt); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5428 | bpl->tus.f.bdeSize = len; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5429 | bpl->tus.f.bdeFlags = 0; |
| 5430 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 5431 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5432 | phba->fc_stat.elsXmitACC++; |
| 5433 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5434 | if (rc == IOCB_ERROR) |
| 5435 | lpfc_els_free_iocb(phba, elsiocb); |
| 5436 | |
| 5437 | kfree(rdp_context); |
| 5438 | |
| 5439 | return; |
| 5440 | error: |
| 5441 | cmdsize = 2 * sizeof(uint32_t); |
| 5442 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries, |
| 5443 | ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 5444 | lpfc_nlp_put(ndlp); |
| 5445 | if (!elsiocb) |
| 5446 | goto free_rdp_context; |
| 5447 | |
| 5448 | icmd = &elsiocb->iocb; |
| 5449 | icmd->ulpContext = rdp_context->rx_id; |
| 5450 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 5451 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5452 | |
| 5453 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
| 5454 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 5455 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5456 | |
| 5457 | phba->fc_stat.elsXmitLSRJT++; |
| 5458 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5459 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5460 | |
| 5461 | if (rc == IOCB_ERROR) |
| 5462 | lpfc_els_free_iocb(phba, elsiocb); |
| 5463 | free_rdp_context: |
| 5464 | kfree(rdp_context); |
| 5465 | } |
| 5466 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5467 | static int |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5468 | lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) |
| 5469 | { |
| 5470 | LPFC_MBOXQ_t *mbox = NULL; |
| 5471 | int rc; |
| 5472 | |
| 5473 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5474 | if (!mbox) { |
| 5475 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, |
| 5476 | "7105 failed to allocate mailbox memory"); |
| 5477 | return 1; |
| 5478 | } |
| 5479 | |
| 5480 | if (lpfc_sli4_dump_page_a0(phba, mbox)) |
| 5481 | goto prep_mbox_fail; |
| 5482 | mbox->vport = rdp_context->ndlp->vport; |
| 5483 | mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; |
| 5484 | mbox->context2 = (struct lpfc_rdp_context *) rdp_context; |
| 5485 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5486 | if (rc == MBX_NOT_FINISHED) |
| 5487 | goto issue_mbox_fail; |
| 5488 | |
| 5489 | return 0; |
| 5490 | |
| 5491 | prep_mbox_fail: |
| 5492 | issue_mbox_fail: |
| 5493 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5494 | return 1; |
| 5495 | } |
| 5496 | |
| 5497 | /* |
| 5498 | * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS. |
| 5499 | * @vport: pointer to a host virtual N_Port data structure. |
| 5500 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5501 | * @ndlp: pointer to a node-list data structure. |
| 5502 | * |
| 5503 | * This routine processes an unsolicited RDP(Read Diagnostic Parameters) |
| 5504 | * IOCB. First, the payload of the unsolicited RDP is checked. |
| 5505 | * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3 |
| 5506 | * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2, |
| 5507 | * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl |
| 5508 | * gather all data and send RDP response. |
| 5509 | * |
| 5510 | * Return code |
| 5511 | * 0 - Sent the acc response |
| 5512 | * 1 - Sent the reject response. |
| 5513 | */ |
| 5514 | static int |
| 5515 | lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5516 | struct lpfc_nodelist *ndlp) |
| 5517 | { |
| 5518 | struct lpfc_hba *phba = vport->phba; |
| 5519 | struct lpfc_dmabuf *pcmd; |
| 5520 | uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE; |
| 5521 | struct fc_rdp_req_frame *rdp_req; |
| 5522 | struct lpfc_rdp_context *rdp_context; |
| 5523 | IOCB_t *cmd = NULL; |
| 5524 | struct ls_rjt stat; |
| 5525 | |
| 5526 | if (phba->sli_rev < LPFC_SLI_REV4 || |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5527 | bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 5528 | LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5529 | rjt_err = LSRJT_UNABLE_TPC; |
| 5530 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 5531 | goto error; |
| 5532 | } |
| 5533 | |
| 5534 | if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) { |
| 5535 | rjt_err = LSRJT_UNABLE_TPC; |
| 5536 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 5537 | goto error; |
| 5538 | } |
| 5539 | |
| 5540 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5541 | rdp_req = (struct fc_rdp_req_frame *) pcmd->virt; |
| 5542 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5543 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5544 | "2422 ELS RDP Request " |
| 5545 | "dec len %d tag x%x port_id %d len %d\n", |
| 5546 | be32_to_cpu(rdp_req->rdp_des_length), |
| 5547 | be32_to_cpu(rdp_req->nport_id_desc.tag), |
| 5548 | be32_to_cpu(rdp_req->nport_id_desc.nport_id), |
| 5549 | be32_to_cpu(rdp_req->nport_id_desc.length)); |
| 5550 | |
| 5551 | if (sizeof(struct fc_rdp_nport_desc) != |
| 5552 | be32_to_cpu(rdp_req->rdp_des_length)) |
| 5553 | goto rjt_logerr; |
| 5554 | if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag)) |
| 5555 | goto rjt_logerr; |
| 5556 | if (RDP_NPORT_ID_SIZE != |
| 5557 | be32_to_cpu(rdp_req->nport_id_desc.length)) |
| 5558 | goto rjt_logerr; |
Punit Vara | 699acd6 | 2015-12-16 18:12:07 -0500 | [diff] [blame] | 5559 | rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5560 | if (!rdp_context) { |
| 5561 | rjt_err = LSRJT_UNABLE_TPC; |
| 5562 | goto error; |
| 5563 | } |
| 5564 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5565 | cmd = &cmdiocb->iocb; |
| 5566 | rdp_context->ndlp = lpfc_nlp_get(ndlp); |
| 5567 | rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id; |
| 5568 | rdp_context->rx_id = cmd->ulpContext; |
| 5569 | rdp_context->cmpl = lpfc_els_rdp_cmpl; |
| 5570 | if (lpfc_get_rdp_info(phba, rdp_context)) { |
| 5571 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS, |
| 5572 | "2423 Unable to send mailbox"); |
| 5573 | kfree(rdp_context); |
| 5574 | rjt_err = LSRJT_UNABLE_TPC; |
| 5575 | lpfc_nlp_put(ndlp); |
| 5576 | goto error; |
| 5577 | } |
| 5578 | |
| 5579 | return 0; |
| 5580 | |
| 5581 | rjt_logerr: |
| 5582 | rjt_err = LSRJT_LOGICAL_ERR; |
| 5583 | |
| 5584 | error: |
| 5585 | memset(&stat, 0, sizeof(stat)); |
| 5586 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 5587 | stat.un.b.lsRjtRsnCodeExp = rjt_expl; |
| 5588 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5589 | return 1; |
| 5590 | } |
| 5591 | |
| 5592 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5593 | static void |
| 5594 | lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5595 | { |
| 5596 | MAILBOX_t *mb; |
| 5597 | IOCB_t *icmd; |
| 5598 | uint8_t *pcmd; |
| 5599 | struct lpfc_iocbq *elsiocb; |
| 5600 | struct lpfc_nodelist *ndlp; |
| 5601 | struct ls_rjt *stat; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5602 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5603 | struct lpfc_lcb_context *lcb_context; |
| 5604 | struct fc_lcb_res_frame *lcb_res; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5605 | uint32_t cmdsize, shdr_status, shdr_add_status; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5606 | int rc; |
| 5607 | |
| 5608 | mb = &pmb->u.mb; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5609 | lcb_context = (struct lpfc_lcb_context *)pmb->context1; |
| 5610 | ndlp = lcb_context->ndlp; |
| 5611 | pmb->context1 = NULL; |
| 5612 | pmb->context2 = NULL; |
| 5613 | |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5614 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 5615 | &pmb->u.mqe.un.beacon_config.header.cfg_shdr; |
| 5616 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5617 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5618 | |
| 5619 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX, |
| 5620 | "0194 SET_BEACON_CONFIG mailbox " |
| 5621 | "completed with status x%x add_status x%x," |
| 5622 | " mbx status x%x\n", |
| 5623 | shdr_status, shdr_add_status, mb->mbxStatus); |
| 5624 | |
| 5625 | if (mb->mbxStatus && !(shdr_status && |
| 5626 | shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5627 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5628 | goto error; |
| 5629 | } |
| 5630 | |
| 5631 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5632 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 5633 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5634 | lpfc_max_els_tries, ndlp, |
| 5635 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5636 | |
| 5637 | /* Decrement the ndlp reference count from previous mbox command */ |
| 5638 | lpfc_nlp_put(ndlp); |
| 5639 | |
| 5640 | if (!elsiocb) |
| 5641 | goto free_lcb_context; |
| 5642 | |
| 5643 | lcb_res = (struct fc_lcb_res_frame *) |
| 5644 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5645 | |
| 5646 | icmd = &elsiocb->iocb; |
| 5647 | icmd->ulpContext = lcb_context->rx_id; |
| 5648 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 5649 | |
| 5650 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5651 | *((uint32_t *)(pcmd)) = ELS_CMD_ACC; |
| 5652 | lcb_res->lcb_sub_command = lcb_context->sub_command; |
| 5653 | lcb_res->lcb_type = lcb_context->type; |
| 5654 | lcb_res->lcb_frequency = lcb_context->frequency; |
| 5655 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5656 | phba->fc_stat.elsXmitACC++; |
| 5657 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5658 | if (rc == IOCB_ERROR) |
| 5659 | lpfc_els_free_iocb(phba, elsiocb); |
| 5660 | |
| 5661 | kfree(lcb_context); |
| 5662 | return; |
| 5663 | |
| 5664 | error: |
| 5665 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 5666 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5667 | lpfc_max_els_tries, ndlp, |
| 5668 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 5669 | lpfc_nlp_put(ndlp); |
| 5670 | if (!elsiocb) |
| 5671 | goto free_lcb_context; |
| 5672 | |
| 5673 | icmd = &elsiocb->iocb; |
| 5674 | icmd->ulpContext = lcb_context->rx_id; |
| 5675 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 5676 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5677 | |
| 5678 | *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT; |
| 5679 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 5680 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5681 | |
| 5682 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5683 | phba->fc_stat.elsXmitLSRJT++; |
| 5684 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5685 | if (rc == IOCB_ERROR) |
| 5686 | lpfc_els_free_iocb(phba, elsiocb); |
| 5687 | free_lcb_context: |
| 5688 | kfree(lcb_context); |
| 5689 | } |
| 5690 | |
| 5691 | static int |
| 5692 | lpfc_sli4_set_beacon(struct lpfc_vport *vport, |
| 5693 | struct lpfc_lcb_context *lcb_context, |
| 5694 | uint32_t beacon_state) |
| 5695 | { |
| 5696 | struct lpfc_hba *phba = vport->phba; |
| 5697 | LPFC_MBOXQ_t *mbox = NULL; |
| 5698 | uint32_t len; |
| 5699 | int rc; |
| 5700 | |
| 5701 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5702 | if (!mbox) |
| 5703 | return 1; |
| 5704 | |
| 5705 | len = sizeof(struct lpfc_mbx_set_beacon_config) - |
| 5706 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 5707 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5708 | LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len, |
| 5709 | LPFC_SLI4_MBX_EMBED); |
| 5710 | mbox->context1 = (void *)lcb_context; |
| 5711 | mbox->vport = phba->pport; |
| 5712 | mbox->mbox_cmpl = lpfc_els_lcb_rsp; |
| 5713 | bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config, |
| 5714 | phba->sli4_hba.physical_port); |
| 5715 | bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config, |
| 5716 | beacon_state); |
| 5717 | bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1); |
| 5718 | bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0); |
| 5719 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5720 | if (rc == MBX_NOT_FINISHED) { |
| 5721 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5722 | return 1; |
| 5723 | } |
| 5724 | |
| 5725 | return 0; |
| 5726 | } |
| 5727 | |
| 5728 | |
| 5729 | /** |
| 5730 | * lpfc_els_rcv_lcb - Process an unsolicited LCB |
| 5731 | * @vport: pointer to a host virtual N_Port data structure. |
| 5732 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5733 | * @ndlp: pointer to a node-list data structure. |
| 5734 | * |
| 5735 | * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB. |
| 5736 | * First, the payload of the unsolicited LCB is checked. |
| 5737 | * Then based on Subcommand beacon will either turn on or off. |
| 5738 | * |
| 5739 | * Return code |
| 5740 | * 0 - Sent the acc response |
| 5741 | * 1 - Sent the reject response. |
| 5742 | **/ |
| 5743 | static int |
| 5744 | lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5745 | struct lpfc_nodelist *ndlp) |
| 5746 | { |
| 5747 | struct lpfc_hba *phba = vport->phba; |
| 5748 | struct lpfc_dmabuf *pcmd; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5749 | uint8_t *lp; |
| 5750 | struct fc_lcb_request_frame *beacon; |
| 5751 | struct lpfc_lcb_context *lcb_context; |
| 5752 | uint8_t state, rjt_err; |
| 5753 | struct ls_rjt stat; |
| 5754 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5755 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 5756 | lp = (uint8_t *)pcmd->virt; |
| 5757 | beacon = (struct fc_lcb_request_frame *)pcmd->virt; |
| 5758 | |
| 5759 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5760 | "0192 ELS LCB Data x%x x%x x%x x%x sub x%x " |
| 5761 | "type x%x frequency %x duration x%x\n", |
| 5762 | lp[0], lp[1], lp[2], |
| 5763 | beacon->lcb_command, |
| 5764 | beacon->lcb_sub_command, |
| 5765 | beacon->lcb_type, |
| 5766 | beacon->lcb_frequency, |
| 5767 | be16_to_cpu(beacon->lcb_duration)); |
| 5768 | |
| 5769 | if (phba->sli_rev < LPFC_SLI_REV4 || |
| 5770 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 5771 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 5772 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5773 | goto rjt; |
| 5774 | } |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5775 | |
| 5776 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 5777 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5778 | goto rjt; |
| 5779 | } |
James Smart | d6564e5 | 2017-06-15 22:56:50 -0700 | [diff] [blame] | 5780 | if (beacon->lcb_sub_command != LPFC_LCB_ON && |
| 5781 | beacon->lcb_sub_command != LPFC_LCB_OFF) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5782 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5783 | goto rjt; |
| 5784 | } |
James Smart | d6564e5 | 2017-06-15 22:56:50 -0700 | [diff] [blame] | 5785 | if (beacon->lcb_sub_command == LPFC_LCB_ON && |
| 5786 | be16_to_cpu(beacon->lcb_duration) != 0) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5787 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5788 | goto rjt; |
| 5789 | } |
| 5790 | |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 5791 | lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL); |
| 5792 | if (!lcb_context) { |
| 5793 | rjt_err = LSRJT_UNABLE_TPC; |
| 5794 | goto rjt; |
| 5795 | } |
| 5796 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5797 | state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; |
| 5798 | lcb_context->sub_command = beacon->lcb_sub_command; |
| 5799 | lcb_context->type = beacon->lcb_type; |
| 5800 | lcb_context->frequency = beacon->lcb_frequency; |
| 5801 | lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
| 5802 | lcb_context->rx_id = cmdiocb->iocb.ulpContext; |
| 5803 | lcb_context->ndlp = lpfc_nlp_get(ndlp); |
| 5804 | if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { |
| 5805 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 5806 | LOG_ELS, "0193 failed to send mail box"); |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 5807 | kfree(lcb_context); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5808 | lpfc_nlp_put(ndlp); |
| 5809 | rjt_err = LSRJT_UNABLE_TPC; |
| 5810 | goto rjt; |
| 5811 | } |
| 5812 | return 0; |
| 5813 | rjt: |
| 5814 | memset(&stat, 0, sizeof(stat)); |
| 5815 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 5816 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5817 | return 1; |
| 5818 | } |
| 5819 | |
| 5820 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5821 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5822 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5823 | * @vport: pointer to a host virtual N_Port data structure. |
| 5824 | * |
| 5825 | * This routine cleans up any Registration State Change Notification |
| 5826 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 5827 | * @vport together with the host_lock is used to prevent multiple thread |
| 5828 | * trying to access the RSCN array on a same @vport at the same time. |
| 5829 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5830 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5831 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5832 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5833 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5834 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5835 | int i; |
| 5836 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5837 | spin_lock_irq(shost->host_lock); |
| 5838 | if (vport->fc_rscn_flush) { |
| 5839 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 5840 | spin_unlock_irq(shost->host_lock); |
| 5841 | return; |
| 5842 | } |
| 5843 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 5844 | vport->fc_rscn_flush = 1; |
| 5845 | spin_unlock_irq(shost->host_lock); |
| 5846 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5847 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5848 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5849 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5850 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5851 | spin_lock_irq(shost->host_lock); |
| 5852 | vport->fc_rscn_id_cnt = 0; |
| 5853 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 5854 | spin_unlock_irq(shost->host_lock); |
| 5855 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5856 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 5857 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5858 | } |
| 5859 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5860 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5861 | * 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] | 5862 | * @vport: pointer to a host virtual N_Port data structure. |
| 5863 | * @did: remote destination port identifier. |
| 5864 | * |
| 5865 | * This routine checks whether there is any pending Registration State |
| 5866 | * Configuration Notification (RSCN) to a @did on @vport. |
| 5867 | * |
| 5868 | * Return code |
| 5869 | * None zero - The @did matched with a pending rscn |
| 5870 | * 0 - not able to match @did with a pending rscn |
| 5871 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5872 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5873 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5874 | { |
| 5875 | D_ID ns_did; |
| 5876 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5877 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5878 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5879 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5880 | |
| 5881 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5882 | |
| 5883 | /* Never match fabric nodes for RSCNs */ |
| 5884 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5885 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5886 | |
| 5887 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5888 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5889 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5890 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5891 | spin_lock_irq(shost->host_lock); |
| 5892 | if (vport->fc_rscn_flush) { |
| 5893 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 5894 | spin_unlock_irq(shost->host_lock); |
| 5895 | return 0; |
| 5896 | } |
| 5897 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 5898 | vport->fc_rscn_flush = 1; |
| 5899 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5900 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5901 | lp = vport->fc_rscn_id_list[i]->virt; |
| 5902 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 5903 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5904 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5905 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 5906 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5907 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 5908 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5909 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 5910 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 5911 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5912 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5913 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5914 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5915 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 5916 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5917 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5918 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5919 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5920 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5921 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5922 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5923 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5924 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5925 | } |
| 5926 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5927 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5928 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 5929 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5930 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5931 | return_did_out: |
| 5932 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 5933 | vport->fc_rscn_flush = 0; |
| 5934 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5935 | } |
| 5936 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5937 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5938 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5939 | * @vport: pointer to a host virtual N_Port data structure. |
| 5940 | * |
| 5941 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 5942 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 5943 | * State Change Notification). |
| 5944 | * |
| 5945 | * Return code |
| 5946 | * 0 - Successful (currently alway return 0) |
| 5947 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5948 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5949 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5950 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5951 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5952 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5953 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5954 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5955 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5956 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 5957 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5958 | continue; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5959 | |
| 5960 | /* NVME Target mode does not do RSCN Recovery. */ |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5961 | if (vport->phba->nvmet_support) |
| 5962 | continue; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5963 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5964 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5965 | NLP_EVT_DEVICE_RECOVERY); |
| 5966 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5967 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5968 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5969 | } |
| 5970 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5971 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5972 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5973 | * @vport: pointer to a host virtual N_Port data structure. |
| 5974 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5975 | * |
| 5976 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 5977 | * applications. |
| 5978 | */ |
| 5979 | static void |
| 5980 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 5981 | struct lpfc_iocbq *cmdiocb) |
| 5982 | { |
| 5983 | struct lpfc_dmabuf *pcmd; |
| 5984 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5985 | uint32_t *payload_ptr; |
| 5986 | uint32_t payload_len; |
| 5987 | struct lpfc_rscn_event_header *rscn_event_data; |
| 5988 | |
| 5989 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5990 | payload_ptr = (uint32_t *) pcmd->virt; |
| 5991 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 5992 | |
| 5993 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 5994 | payload_len, GFP_KERNEL); |
| 5995 | if (!rscn_event_data) { |
| 5996 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5997 | "0147 Failed to allocate memory for RSCN event\n"); |
| 5998 | return; |
| 5999 | } |
| 6000 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 6001 | rscn_event_data->payload_length = payload_len; |
| 6002 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 6003 | payload_len); |
| 6004 | |
| 6005 | fc_host_post_vendor_event(shost, |
| 6006 | fc_get_event_number(), |
Ales Novak | 6599eaa | 2015-08-31 16:48:16 -0400 | [diff] [blame] | 6007 | sizeof(struct lpfc_rscn_event_header) + payload_len, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6008 | (char *)rscn_event_data, |
| 6009 | LPFC_NL_VENDOR_ID); |
| 6010 | |
| 6011 | kfree(rscn_event_data); |
| 6012 | } |
| 6013 | |
| 6014 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6015 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6016 | * @vport: pointer to a host virtual N_Port data structure. |
| 6017 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6018 | * @ndlp: pointer to a node-list data structure. |
| 6019 | * |
| 6020 | * This routine processes an unsolicited RSCN (Registration State Change |
| 6021 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 6022 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 6023 | * discover state machine is about to begin discovery, it just accepts the |
| 6024 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 6025 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 6026 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 6027 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 6028 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 6029 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 6030 | * routine is invoked to handle the RSCN event. |
| 6031 | * |
| 6032 | * Return code |
| 6033 | * 0 - Just sent the acc response |
| 6034 | * 1 - Sent the acc response and waited for name server completion |
| 6035 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6036 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6037 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6038 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6039 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6040 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6041 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6042 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6043 | uint32_t *lp, *datap; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6044 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6045 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6046 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 6047 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6048 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6049 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6050 | lp = (uint32_t *) pcmd->virt; |
| 6051 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6052 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 6053 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6054 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6055 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6056 | "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] | 6057 | vport->fc_flag, payload_len, *lp, |
| 6058 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6059 | |
| 6060 | /* Send an RSCN event to the management application */ |
| 6061 | lpfc_send_rscn_event(vport, cmdiocb); |
| 6062 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 6063 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6064 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 6065 | FCH_EVT_RSCN, lp[i]); |
| 6066 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6067 | /* If we are about to begin discovery, just ACC the RSCN. |
| 6068 | * Discovery processing will satisfy it. |
| 6069 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6070 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6071 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6072 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 6073 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6074 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6075 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6076 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6077 | } |
| 6078 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6079 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 6080 | * just ACC and ignore it. |
| 6081 | */ |
| 6082 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6083 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6084 | i = payload_len; |
| 6085 | datap = lp; |
| 6086 | while (i > 0) { |
| 6087 | nportid = *datap++; |
| 6088 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 6089 | i -= sizeof(uint32_t); |
| 6090 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6091 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 6092 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6093 | } |
| 6094 | if (rscn_id == hba_id) { |
| 6095 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6096 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6097 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6098 | "Data: x%x x%x x%x x%x\n", |
| 6099 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6100 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6101 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6102 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 6103 | ndlp->nlp_DID, vport->port_state, |
| 6104 | ndlp->nlp_flag); |
| 6105 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6106 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6107 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6108 | return 0; |
| 6109 | } |
| 6110 | } |
| 6111 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6112 | spin_lock_irq(shost->host_lock); |
| 6113 | if (vport->fc_rscn_flush) { |
| 6114 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6115 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 6116 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6117 | /* Send back ACC */ |
| 6118 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6119 | return 0; |
| 6120 | } |
| 6121 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 6122 | vport->fc_rscn_flush = 1; |
| 6123 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6124 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6125 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6126 | /* If we are already processing an RSCN, save the received |
| 6127 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 6128 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6129 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6130 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6131 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 6132 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6133 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6134 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6135 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 6136 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6137 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6138 | vport->fc_flag |= FC_RSCN_MODE; |
| 6139 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6140 | if (rscn_cnt) { |
| 6141 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 6142 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 6143 | } |
| 6144 | if ((rscn_cnt) && |
| 6145 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 6146 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6147 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6148 | memcpy(((uint8_t *)cmd) + length, lp, |
| 6149 | payload_len); |
| 6150 | } else { |
| 6151 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 6152 | vport->fc_rscn_id_cnt++; |
| 6153 | /* If we zero, cmdiocb->context2, the calling |
| 6154 | * routine will not try to free it. |
| 6155 | */ |
| 6156 | cmdiocb->context2 = NULL; |
| 6157 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6158 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6159 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6160 | "0235 Deferred RSCN " |
| 6161 | "Data: x%x x%x x%x\n", |
| 6162 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 6163 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6164 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6165 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 6166 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6167 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6168 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6169 | "0234 ReDiscovery RSCN " |
| 6170 | "Data: x%x x%x x%x\n", |
| 6171 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 6172 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6173 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6174 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 6175 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6176 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6177 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6178 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6179 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6180 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6181 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6182 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6183 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6184 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6185 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6186 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 6187 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6188 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6189 | spin_lock_irq(shost->host_lock); |
| 6190 | vport->fc_flag |= FC_RSCN_MODE; |
| 6191 | spin_unlock_irq(shost->host_lock); |
| 6192 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6193 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 6194 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6195 | /* |
| 6196 | * If we zero, cmdiocb->context2, the calling routine will |
| 6197 | * not try to free it. |
| 6198 | */ |
| 6199 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6200 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6201 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6202 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6203 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6204 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6205 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6206 | } |
| 6207 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6208 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6209 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6210 | * @vport: pointer to a host virtual N_Port data structure. |
| 6211 | * |
| 6212 | * This routine handles the Registration State Configuration Notification |
| 6213 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 6214 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 6215 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 6216 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 6217 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 6218 | * RSCN activities with the @vport. |
| 6219 | * |
| 6220 | * Return code |
| 6221 | * 0 - Cleaned up rscn on the @vport |
| 6222 | * 1 - Wait for plogi to name server before proceed |
| 6223 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6224 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6225 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6226 | { |
| 6227 | struct lpfc_nodelist *ndlp; |
| 6228 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6229 | /* Ignore RSCN if the port is being torn down. */ |
| 6230 | if (vport->load_flag & FC_UNLOADING) { |
| 6231 | lpfc_els_flush_rscn(vport); |
| 6232 | return 0; |
| 6233 | } |
| 6234 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6235 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6236 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6237 | |
| 6238 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6239 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6240 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 6241 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 6242 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6243 | |
| 6244 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6245 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 6246 | vport->num_disc_nodes = 0; |
| 6247 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6248 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6249 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 6250 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6251 | /* Good ndlp, issue CT Request to NameServer. Need to |
| 6252 | * know how many gidfts were issued. If none, then just |
| 6253 | * flush the RSCN. Otherwise, the outstanding requests |
| 6254 | * need to complete. |
| 6255 | */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 6256 | vport->gidft_inp = 0; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6257 | if (lpfc_issue_gidft(vport) > 0) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6258 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6259 | } else { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6260 | /* Nameserver login in question. Revalidate. */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6261 | if (ndlp) { |
| 6262 | ndlp = lpfc_enable_node(vport, ndlp, |
| 6263 | NLP_STE_PLOGI_ISSUE); |
| 6264 | if (!ndlp) { |
| 6265 | lpfc_els_flush_rscn(vport); |
| 6266 | return 0; |
| 6267 | } |
| 6268 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6269 | } else { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6270 | ndlp = lpfc_nlp_init(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6271 | if (!ndlp) { |
| 6272 | lpfc_els_flush_rscn(vport); |
| 6273 | return 0; |
| 6274 | } |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6275 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6276 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6277 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6278 | ndlp->nlp_type |= NLP_FABRIC; |
| 6279 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 6280 | /* Wait for NameServer login cmpl before we can |
| 6281 | * continue |
| 6282 | */ |
| 6283 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6284 | } |
| 6285 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6286 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6287 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6288 | } |
| 6289 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6290 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6291 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6292 | * @vport: pointer to a host virtual N_Port data structure. |
| 6293 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6294 | * @ndlp: pointer to a node-list data structure. |
| 6295 | * |
| 6296 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 6297 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 6298 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 6299 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 6300 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 6301 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 6302 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 6303 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 6304 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 6305 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 6306 | * higher priority (as the winning port) and will initiate PLOGI and |
| 6307 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 6308 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 6309 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 6310 | * |
| 6311 | * Return code |
| 6312 | * 0 - Successfully processed the unsolicited flogi |
| 6313 | * 1 - Failed to process the unsolicited flogi |
| 6314 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6315 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6316 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6317 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6318 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6319 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6320 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6321 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6322 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 6323 | IOCB_t *icmd = &cmdiocb->iocb; |
| 6324 | struct serv_parm *sp; |
| 6325 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6326 | uint32_t cmd, did; |
| 6327 | int rc; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6328 | uint32_t fc_flag = 0; |
| 6329 | uint32_t port_state = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6330 | |
| 6331 | cmd = *lp++; |
| 6332 | sp = (struct serv_parm *) lp; |
| 6333 | |
| 6334 | /* FLOGI received */ |
| 6335 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6336 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6337 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6338 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6339 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 6340 | did = icmd->un.elsreq64.remoteID; |
| 6341 | |
| 6342 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 6343 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6344 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6345 | "0113 An FLOGI ELS command x%x was " |
| 6346 | "received from DID x%x in Loop Mode\n", |
| 6347 | cmd, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6348 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6349 | } |
| 6350 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6351 | (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6352 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6353 | /* |
| 6354 | * If our portname is greater than the remote portname, |
| 6355 | * then we initiate Nport login. |
| 6356 | */ |
| 6357 | |
| 6358 | rc = memcmp(&vport->fc_portname, &sp->portName, |
| 6359 | sizeof(struct lpfc_name)); |
| 6360 | |
| 6361 | if (!rc) { |
| 6362 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 6363 | mbox = mempool_alloc(phba->mbox_mem_pool, |
| 6364 | GFP_KERNEL); |
| 6365 | if (!mbox) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6366 | return 1; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6367 | lpfc_linkdown(phba); |
| 6368 | lpfc_init_link(phba, mbox, |
| 6369 | phba->cfg_topology, |
| 6370 | phba->cfg_link_speed); |
| 6371 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 6372 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 6373 | mbox->vport = vport; |
| 6374 | rc = lpfc_sli_issue_mbox(phba, mbox, |
| 6375 | MBX_NOWAIT); |
| 6376 | lpfc_set_loopback_flag(phba); |
| 6377 | if (rc == MBX_NOT_FINISHED) |
| 6378 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6379 | return 1; |
| 6380 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6381 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6382 | /* abort the flogi coming back to ourselves |
| 6383 | * due to external loopback on the port. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6384 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6385 | lpfc_els_abort_flogi(phba); |
| 6386 | return 0; |
| 6387 | |
| 6388 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6389 | spin_lock_irq(shost->host_lock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6390 | vport->fc_flag |= FC_PT2PT_PLOGI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6391 | spin_unlock_irq(shost->host_lock); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6392 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6393 | /* If we have the high WWPN we can assign our own |
| 6394 | * myDID; otherwise, we have to WAIT for a PLOGI |
| 6395 | * from the remote NPort to find out what it |
| 6396 | * will be. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6397 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6398 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6399 | } else { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6400 | vport->fc_myDID = PT2PT_RemoteID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6401 | } |
| 6402 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6403 | /* |
| 6404 | * The vport state should go to LPFC_FLOGI only |
| 6405 | * AFTER we issue a FLOGI, not receive one. |
| 6406 | */ |
| 6407 | spin_lock_irq(shost->host_lock); |
| 6408 | fc_flag = vport->fc_flag; |
| 6409 | port_state = vport->port_state; |
| 6410 | vport->fc_flag |= FC_PT2PT; |
| 6411 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6412 | spin_unlock_irq(shost->host_lock); |
| 6413 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6414 | "3311 Rcv Flogi PS x%x new PS x%x " |
| 6415 | "fc_flag x%x new fc_flag x%x\n", |
| 6416 | port_state, vport->port_state, |
| 6417 | fc_flag, vport->fc_flag); |
| 6418 | |
| 6419 | /* |
| 6420 | * We temporarily set fc_myDID to make it look like we are |
| 6421 | * a Fabric. This is done just so we end up with the right |
| 6422 | * did / sid on the FLOGI ACC rsp. |
| 6423 | */ |
| 6424 | did = vport->fc_myDID; |
| 6425 | vport->fc_myDID = Fabric_DID; |
| 6426 | |
| 6427 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 6428 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6429 | /* Send back ACC */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6430 | lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6431 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6432 | /* Now lets put fc_myDID back to what its supposed to be */ |
| 6433 | vport->fc_myDID = did; |
| 6434 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6435 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6436 | } |
| 6437 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6438 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6439 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6440 | * @vport: pointer to a host virtual N_Port data structure. |
| 6441 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6442 | * @ndlp: pointer to a node-list data structure. |
| 6443 | * |
| 6444 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 6445 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 6446 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 6447 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 6448 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 6449 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 6450 | * |
| 6451 | * Return code |
| 6452 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 6453 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6454 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6455 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6456 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6457 | { |
| 6458 | struct lpfc_dmabuf *pcmd; |
| 6459 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6460 | RNID *rn; |
| 6461 | struct ls_rjt stat; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6462 | uint32_t cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6463 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6464 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6465 | lp = (uint32_t *) pcmd->virt; |
| 6466 | |
| 6467 | cmd = *lp++; |
| 6468 | rn = (RNID *) lp; |
| 6469 | |
| 6470 | /* RNID received */ |
| 6471 | |
| 6472 | switch (rn->Format) { |
| 6473 | case 0: |
| 6474 | case RNID_TOPOLOGY_DISC: |
| 6475 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6476 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6477 | break; |
| 6478 | default: |
| 6479 | /* Reject this request because format not supported */ |
| 6480 | stat.un.b.lsRjtRsvd0 = 0; |
| 6481 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6482 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6483 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6484 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 6485 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6486 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6487 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6488 | } |
| 6489 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6490 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6491 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 6492 | * @vport: pointer to a host virtual N_Port data structure. |
| 6493 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6494 | * @ndlp: pointer to a node-list data structure. |
| 6495 | * |
| 6496 | * Return code |
| 6497 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 6498 | **/ |
| 6499 | static int |
| 6500 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6501 | struct lpfc_nodelist *ndlp) |
| 6502 | { |
| 6503 | uint8_t *pcmd; |
| 6504 | |
| 6505 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 6506 | |
| 6507 | /* skip over first word of echo command to find echo data */ |
| 6508 | pcmd += sizeof(uint32_t); |
| 6509 | |
| 6510 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 6511 | return 0; |
| 6512 | } |
| 6513 | |
| 6514 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6515 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6516 | * @vport: pointer to a host virtual N_Port data structure. |
| 6517 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6518 | * @ndlp: pointer to a node-list data structure. |
| 6519 | * |
| 6520 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 6521 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 6522 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 6523 | * |
| 6524 | * Return code |
| 6525 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 6526 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6527 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6528 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6529 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6530 | { |
| 6531 | struct ls_rjt stat; |
| 6532 | |
| 6533 | /* For now, unconditionally reject this command */ |
| 6534 | stat.un.b.lsRjtRsvd0 = 0; |
| 6535 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6536 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6537 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6538 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6539 | return 0; |
| 6540 | } |
| 6541 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6542 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6543 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 6544 | * @vport: pointer to a host virtual N_Port data structure. |
| 6545 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6546 | * @ndlp: pointer to a node-list data structure. |
| 6547 | * |
| 6548 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 6549 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 6550 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 6551 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 6552 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 6553 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 6554 | * command request" and reason code explanation "Invalid Originator |
| 6555 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 6556 | * RRQ from the target. |
| 6557 | **/ |
| 6558 | static void |
| 6559 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6560 | struct lpfc_nodelist *ndlp) |
| 6561 | { |
| 6562 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6563 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 6564 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6565 | } |
| 6566 | |
| 6567 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6568 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 6569 | * @phba: pointer to lpfc hba data structure. |
| 6570 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6571 | * |
| 6572 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 6573 | * mailbox command. This callback function is to actually send the Accept |
| 6574 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 6575 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 6576 | * mailbox command, constructs the RPS response with the link statistics |
| 6577 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 6578 | * response to the RPS. |
| 6579 | * |
| 6580 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6581 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6582 | * will be stored into the context1 field of the IOCB for the completion |
| 6583 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6584 | * |
| 6585 | **/ |
| 6586 | static void |
| 6587 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6588 | { |
| 6589 | MAILBOX_t *mb; |
| 6590 | IOCB_t *icmd; |
| 6591 | struct RLS_RSP *rls_rsp; |
| 6592 | uint8_t *pcmd; |
| 6593 | struct lpfc_iocbq *elsiocb; |
| 6594 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6595 | uint16_t oxid; |
| 6596 | uint16_t rxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6597 | uint32_t cmdsize; |
| 6598 | |
| 6599 | mb = &pmb->u.mb; |
| 6600 | |
| 6601 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6602 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 6603 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6604 | pmb->context1 = NULL; |
| 6605 | pmb->context2 = NULL; |
| 6606 | |
| 6607 | if (mb->mbxStatus) { |
| 6608 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6609 | return; |
| 6610 | } |
| 6611 | |
| 6612 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6613 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6614 | lpfc_max_els_tries, ndlp, |
| 6615 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6616 | |
| 6617 | /* Decrement the ndlp reference count from previous mbox command */ |
| 6618 | lpfc_nlp_put(ndlp); |
| 6619 | |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6620 | if (!elsiocb) { |
| 6621 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6622 | return; |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6623 | } |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6624 | |
| 6625 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6626 | icmd->ulpContext = rxid; |
| 6627 | icmd->unsli3.rcvsli3.ox_id = oxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6628 | |
| 6629 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6630 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6631 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 6632 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 6633 | |
| 6634 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 6635 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 6636 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 6637 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 6638 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 6639 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6640 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6641 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 6642 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6643 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 6644 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 6645 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6646 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6647 | ndlp->nlp_rpi); |
| 6648 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6649 | phba->fc_stat.elsXmitACC++; |
| 6650 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 6651 | lpfc_els_free_iocb(phba, elsiocb); |
| 6652 | } |
| 6653 | |
| 6654 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6655 | * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6656 | * @phba: pointer to lpfc hba data structure. |
| 6657 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6658 | * |
| 6659 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 6660 | * mailbox command. This callback function is to actually send the Accept |
| 6661 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 6662 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 6663 | * mailbox command, constructs the RPS response with the link statistics |
| 6664 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 6665 | * response to the RPS. |
| 6666 | * |
| 6667 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6668 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6669 | * will be stored into the context1 field of the IOCB for the completion |
| 6670 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6671 | * |
| 6672 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 6673 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6674 | lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6675 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6676 | MAILBOX_t *mb; |
| 6677 | IOCB_t *icmd; |
| 6678 | RPS_RSP *rps_rsp; |
| 6679 | uint8_t *pcmd; |
| 6680 | struct lpfc_iocbq *elsiocb; |
| 6681 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6682 | uint16_t status; |
| 6683 | uint16_t oxid; |
| 6684 | uint16_t rxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6685 | uint32_t cmdsize; |
| 6686 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6687 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6688 | |
| 6689 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6690 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 6691 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 6692 | pmb->context1 = NULL; |
| 6693 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6694 | |
| 6695 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6696 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6697 | return; |
| 6698 | } |
| 6699 | |
| 6700 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6701 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6702 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6703 | lpfc_max_els_tries, ndlp, |
| 6704 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6705 | |
| 6706 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6707 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6708 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6709 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6710 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6711 | |
| 6712 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6713 | icmd->ulpContext = rxid; |
| 6714 | icmd->unsli3.rcvsli3.ox_id = oxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6715 | |
| 6716 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6717 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6718 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6719 | rps_rsp = (RPS_RSP *)pcmd; |
| 6720 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6721 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6722 | status = 0x10; |
| 6723 | else |
| 6724 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6725 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6726 | status |= 0x4; |
| 6727 | |
| 6728 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6729 | rps_rsp->portStatus = cpu_to_be16(status); |
| 6730 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 6731 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 6732 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 6733 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 6734 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 6735 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6736 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6737 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6738 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 6739 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 6740 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6741 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6742 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6743 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6744 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6745 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6746 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6747 | return; |
| 6748 | } |
| 6749 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6750 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6751 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 6752 | * @vport: pointer to a host virtual N_Port data structure. |
| 6753 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6754 | * @ndlp: pointer to a node-list data structure. |
| 6755 | * |
| 6756 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 6757 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6758 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6759 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 6760 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 6761 | * for reading the HBA link statistics. It is for the callback function, |
| 6762 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 6763 | * to actually sending out RPL Accept (ACC) response. |
| 6764 | * |
| 6765 | * Return codes |
| 6766 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 6767 | **/ |
| 6768 | static int |
| 6769 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6770 | struct lpfc_nodelist *ndlp) |
| 6771 | { |
| 6772 | struct lpfc_hba *phba = vport->phba; |
| 6773 | LPFC_MBOXQ_t *mbox; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6774 | struct ls_rjt stat; |
| 6775 | |
| 6776 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6777 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6778 | /* reject the unsolicited RPS request and done with it */ |
| 6779 | goto reject_out; |
| 6780 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6781 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 6782 | if (mbox) { |
| 6783 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6784 | mbox->context1 = (void *)((unsigned long) |
| 6785 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 6786 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6787 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6788 | mbox->vport = vport; |
| 6789 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 6790 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 6791 | != MBX_NOT_FINISHED) |
| 6792 | /* Mbox completion will send ELS Response */ |
| 6793 | return 0; |
| 6794 | /* Decrement reference count used for the failed mbox |
| 6795 | * command. |
| 6796 | */ |
| 6797 | lpfc_nlp_put(ndlp); |
| 6798 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6799 | } |
| 6800 | reject_out: |
| 6801 | /* issue rejection response */ |
| 6802 | stat.un.b.lsRjtRsvd0 = 0; |
| 6803 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6804 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6805 | stat.un.b.vendorUnique = 0; |
| 6806 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6807 | return 0; |
| 6808 | } |
| 6809 | |
| 6810 | /** |
| 6811 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 6812 | * @vport: pointer to a host virtual N_Port data structure. |
| 6813 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6814 | * @ndlp: pointer to a node-list data structure. |
| 6815 | * |
| 6816 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 6817 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6818 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6819 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 6820 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 6821 | * Value (RTV) unsolicited IOCB event. |
| 6822 | * |
| 6823 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6824 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6825 | * will be stored into the context1 field of the IOCB for the completion |
| 6826 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6827 | * |
| 6828 | * Return codes |
| 6829 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 6830 | **/ |
| 6831 | static int |
| 6832 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6833 | struct lpfc_nodelist *ndlp) |
| 6834 | { |
| 6835 | struct lpfc_hba *phba = vport->phba; |
| 6836 | struct ls_rjt stat; |
| 6837 | struct RTV_RSP *rtv_rsp; |
| 6838 | uint8_t *pcmd; |
| 6839 | struct lpfc_iocbq *elsiocb; |
| 6840 | uint32_t cmdsize; |
| 6841 | |
| 6842 | |
| 6843 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6844 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6845 | /* reject the unsolicited RPS request and done with it */ |
| 6846 | goto reject_out; |
| 6847 | |
| 6848 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 6849 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6850 | lpfc_max_els_tries, ndlp, |
| 6851 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6852 | |
| 6853 | if (!elsiocb) |
| 6854 | return 1; |
| 6855 | |
| 6856 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6857 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6858 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 6859 | |
| 6860 | /* use the command's xri in the response */ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6861 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 6862 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6863 | |
| 6864 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 6865 | |
| 6866 | /* populate RTV payload */ |
| 6867 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 6868 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 6869 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 6870 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 6871 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 6872 | |
| 6873 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 6874 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6875 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 6876 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 6877 | "Data: x%x x%x x%x\n", |
| 6878 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6879 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6880 | ndlp->nlp_rpi, |
| 6881 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 6882 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6883 | phba->fc_stat.elsXmitACC++; |
| 6884 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 6885 | lpfc_els_free_iocb(phba, elsiocb); |
| 6886 | return 0; |
| 6887 | |
| 6888 | reject_out: |
| 6889 | /* issue rejection response */ |
| 6890 | stat.un.b.lsRjtRsvd0 = 0; |
| 6891 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6892 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6893 | stat.un.b.vendorUnique = 0; |
| 6894 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6895 | return 0; |
| 6896 | } |
| 6897 | |
| 6898 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6899 | * @vport: pointer to a host virtual N_Port data structure. |
| 6900 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6901 | * @ndlp: pointer to a node-list data structure. |
| 6902 | * |
| 6903 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 6904 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6905 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6906 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 6907 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 6908 | * for reading the HBA link statistics. It is for the callback function, |
| 6909 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 6910 | * to actually sending out RPS Accept (ACC) response. |
| 6911 | * |
| 6912 | * Return codes |
| 6913 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 6914 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6915 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6916 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6917 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6918 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6919 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6920 | uint32_t *lp; |
| 6921 | uint8_t flag; |
| 6922 | LPFC_MBOXQ_t *mbox; |
| 6923 | struct lpfc_dmabuf *pcmd; |
| 6924 | RPS *rps; |
| 6925 | struct ls_rjt stat; |
| 6926 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6927 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6928 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6929 | /* reject the unsolicited RPS request and done with it */ |
| 6930 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6931 | |
| 6932 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6933 | lp = (uint32_t *) pcmd->virt; |
| 6934 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 6935 | rps = (RPS *) lp; |
| 6936 | |
| 6937 | if ((flag == 0) || |
| 6938 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6939 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6940 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6941 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6942 | printk("Fix me....\n"); |
| 6943 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6944 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 6945 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6946 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6947 | mbox->context1 = (void *)((unsigned long) |
| 6948 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 6949 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6950 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6951 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6952 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6953 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6954 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6955 | /* Mbox completion will send ELS Response */ |
| 6956 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6957 | /* Decrement reference count used for the failed mbox |
| 6958 | * command. |
| 6959 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6960 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6961 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6962 | } |
| 6963 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6964 | |
| 6965 | reject_out: |
| 6966 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6967 | stat.un.b.lsRjtRsvd0 = 0; |
| 6968 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6969 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6970 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6971 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6972 | return 0; |
| 6973 | } |
| 6974 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6975 | /* lpfc_issue_els_rrq - Process an unsolicited rps iocb |
| 6976 | * @vport: pointer to a host virtual N_Port data structure. |
| 6977 | * @ndlp: pointer to a node-list data structure. |
| 6978 | * @did: DID of the target. |
| 6979 | * @rrq: Pointer to the rrq struct. |
| 6980 | * |
| 6981 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is |
| 6982 | * Successful the the completion handler will clear the RRQ. |
| 6983 | * |
| 6984 | * Return codes |
| 6985 | * 0 - Successfully sent rrq els iocb. |
| 6986 | * 1 - Failed to send rrq els iocb. |
| 6987 | **/ |
| 6988 | static int |
| 6989 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6990 | uint32_t did, struct lpfc_node_rrq *rrq) |
| 6991 | { |
| 6992 | struct lpfc_hba *phba = vport->phba; |
| 6993 | struct RRQ *els_rrq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6994 | struct lpfc_iocbq *elsiocb; |
| 6995 | uint8_t *pcmd; |
| 6996 | uint16_t cmdsize; |
| 6997 | int ret; |
| 6998 | |
| 6999 | |
| 7000 | if (ndlp != rrq->ndlp) |
| 7001 | ndlp = rrq->ndlp; |
| 7002 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 7003 | return 1; |
| 7004 | |
| 7005 | /* If ndlp is not NULL, we will bump the reference count on it */ |
| 7006 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); |
| 7007 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, |
| 7008 | ELS_CMD_RRQ); |
| 7009 | if (!elsiocb) |
| 7010 | return 1; |
| 7011 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7012 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7013 | |
| 7014 | /* For RRQ request, remainder of payload is Exchange IDs */ |
| 7015 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; |
| 7016 | pcmd += sizeof(uint32_t); |
| 7017 | els_rrq = (struct RRQ *) pcmd; |
| 7018 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 7019 | 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] | 7020 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
| 7021 | bf_set(rrq_did, els_rrq, vport->fc_myDID); |
| 7022 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); |
| 7023 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); |
| 7024 | |
| 7025 | |
| 7026 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7027 | "Issue RRQ: did:x%x", |
| 7028 | did, rrq->xritag, rrq->rxid); |
| 7029 | elsiocb->context_un.rrq = rrq; |
| 7030 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; |
| 7031 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 7032 | |
| 7033 | if (ret == IOCB_ERROR) { |
| 7034 | lpfc_els_free_iocb(phba, elsiocb); |
| 7035 | return 1; |
| 7036 | } |
| 7037 | return 0; |
| 7038 | } |
| 7039 | |
| 7040 | /** |
| 7041 | * lpfc_send_rrq - Sends ELS RRQ if needed. |
| 7042 | * @phba: pointer to lpfc hba data structure. |
| 7043 | * @rrq: pointer to the active rrq. |
| 7044 | * |
| 7045 | * This routine will call the lpfc_issue_els_rrq if the rrq is |
| 7046 | * still active for the xri. If this function returns a failure then |
| 7047 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. |
| 7048 | * |
| 7049 | * Returns 0 Success. |
| 7050 | * 1 Failure. |
| 7051 | **/ |
| 7052 | int |
| 7053 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) |
| 7054 | { |
| 7055 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, |
| 7056 | rrq->nlp_DID); |
| 7057 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) |
| 7058 | return lpfc_issue_els_rrq(rrq->vport, ndlp, |
| 7059 | rrq->nlp_DID, rrq); |
| 7060 | else |
| 7061 | return 1; |
| 7062 | } |
| 7063 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7064 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7065 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7066 | * @vport: pointer to a host virtual N_Port data structure. |
| 7067 | * @cmdsize: size of the ELS command. |
| 7068 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 7069 | * @ndlp: pointer to a node-list data structure. |
| 7070 | * |
| 7071 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 7072 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 7073 | * |
| 7074 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7075 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7076 | * will be stored into the context1 field of the IOCB for the completion |
| 7077 | * callback function to the RPL Accept Response ELS command. |
| 7078 | * |
| 7079 | * Return code |
| 7080 | * 0 - Successfully issued ACC RPL ELS command |
| 7081 | * 1 - Failed to issue ACC RPL ELS command |
| 7082 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 7083 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7084 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 7085 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7086 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7087 | struct lpfc_hba *phba = vport->phba; |
| 7088 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7089 | RPL_RSP rpl_rsp; |
| 7090 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7091 | uint8_t *pcmd; |
| 7092 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7093 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 7094 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7095 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 7096 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7097 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 7098 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7099 | icmd = &elsiocb->iocb; |
| 7100 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7101 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 7102 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7103 | |
| 7104 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7105 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7106 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7107 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 7108 | pcmd += sizeof(uint16_t); |
| 7109 | |
| 7110 | /* Setup the RPL ACC payload */ |
| 7111 | rpl_rsp.listLen = be32_to_cpu(1); |
| 7112 | rpl_rsp.index = 0; |
| 7113 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7114 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 7115 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7116 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7117 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7118 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7119 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7120 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 7121 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 7122 | "rpi x%x\n", |
| 7123 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 7124 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 7125 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7126 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7127 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7128 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 7129 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7130 | lpfc_els_free_iocb(phba, elsiocb); |
| 7131 | return 1; |
| 7132 | } |
| 7133 | return 0; |
| 7134 | } |
| 7135 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7136 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7137 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7138 | * @vport: pointer to a host virtual N_Port data structure. |
| 7139 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7140 | * @ndlp: pointer to a node-list data structure. |
| 7141 | * |
| 7142 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 7143 | * unsolicited event. It first checks the remote port state. If the remote |
| 7144 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 7145 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 7146 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 7147 | * to accept the RPL. |
| 7148 | * |
| 7149 | * Return code |
| 7150 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 7151 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7152 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7153 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7154 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7155 | { |
| 7156 | struct lpfc_dmabuf *pcmd; |
| 7157 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7158 | uint32_t maxsize; |
| 7159 | uint16_t cmdsize; |
| 7160 | RPL *rpl; |
| 7161 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7162 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 7163 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 7164 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 7165 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7166 | stat.un.b.lsRjtRsvd0 = 0; |
| 7167 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7168 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7169 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7170 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 7171 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 7172 | /* rejected the unsolicited RPL request and done with it */ |
| 7173 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7174 | } |
| 7175 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7176 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7177 | lp = (uint32_t *) pcmd->virt; |
| 7178 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7179 | maxsize = be32_to_cpu(rpl->maxsize); |
| 7180 | |
| 7181 | /* We support only one port */ |
| 7182 | if ((rpl->index == 0) && |
| 7183 | ((maxsize == 0) || |
| 7184 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 7185 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 7186 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7187 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 7188 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7189 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7190 | |
| 7191 | return 0; |
| 7192 | } |
| 7193 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7194 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7195 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7196 | * @vport: pointer to a 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 Fibre Channel Address Resolution Protocol |
| 7201 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 7202 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 7203 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 7204 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 7205 | * remote PortName is compared against the FC PortName stored in the @vport |
| 7206 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 7207 | * compared against the FC NodeName stored in the @vport data structure. |
| 7208 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 7209 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 7210 | * invoked to send out FARP Response to the remote node. Before sending the |
| 7211 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 7212 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 7213 | * routine is invoked to log into the remote port first. |
| 7214 | * |
| 7215 | * Return code |
| 7216 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 7217 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7218 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7219 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7220 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7221 | { |
| 7222 | struct lpfc_dmabuf *pcmd; |
| 7223 | uint32_t *lp; |
| 7224 | IOCB_t *icmd; |
| 7225 | FARP *fp; |
| 7226 | uint32_t cmd, cnt, did; |
| 7227 | |
| 7228 | icmd = &cmdiocb->iocb; |
| 7229 | did = icmd->un.elsreq64.remoteID; |
| 7230 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7231 | lp = (uint32_t *) pcmd->virt; |
| 7232 | |
| 7233 | cmd = *lp++; |
| 7234 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7235 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7236 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7237 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7238 | /* We will only support match on WWPN or WWNN */ |
| 7239 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7240 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7241 | } |
| 7242 | |
| 7243 | cnt = 0; |
| 7244 | /* If this FARP command is searching for my portname */ |
| 7245 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7246 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7247 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7248 | cnt = 1; |
| 7249 | } |
| 7250 | |
| 7251 | /* If this FARP command is searching for my nodename */ |
| 7252 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7253 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7254 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7255 | cnt = 1; |
| 7256 | } |
| 7257 | |
| 7258 | if (cnt) { |
| 7259 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 7260 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 7261 | /* Log back into the node before sending the FARP. */ |
| 7262 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7263 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7264 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 7265 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7266 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7267 | } |
| 7268 | |
| 7269 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7270 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 7271 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7272 | } |
| 7273 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7274 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7275 | } |
| 7276 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7277 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7278 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7279 | * @vport: pointer to a host virtual N_Port data structure. |
| 7280 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7281 | * @ndlp: pointer to a node-list data structure. |
| 7282 | * |
| 7283 | * This routine processes Fibre Channel Address Resolution Protocol |
| 7284 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 7285 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 7286 | * the FARP response request. |
| 7287 | * |
| 7288 | * Return code |
| 7289 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 7290 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7291 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7292 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7293 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7294 | { |
| 7295 | struct lpfc_dmabuf *pcmd; |
| 7296 | uint32_t *lp; |
| 7297 | IOCB_t *icmd; |
| 7298 | uint32_t cmd, did; |
| 7299 | |
| 7300 | icmd = &cmdiocb->iocb; |
| 7301 | did = icmd->un.elsreq64.remoteID; |
| 7302 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7303 | lp = (uint32_t *) pcmd->virt; |
| 7304 | |
| 7305 | cmd = *lp++; |
| 7306 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7307 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7308 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7309 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7310 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7311 | |
| 7312 | return 0; |
| 7313 | } |
| 7314 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7315 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7316 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7317 | * @vport: pointer to a host virtual N_Port data structure. |
| 7318 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7319 | * @fan_ndlp: pointer to a node-list data structure. |
| 7320 | * |
| 7321 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 7322 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 7323 | * only be processed on a physical port (i.e., the @vport represents the |
| 7324 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 7325 | * compared against those in the phba data structure. If any of those is |
| 7326 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 7327 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 7328 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 7329 | * is invoked to register login to the fabric. |
| 7330 | * |
| 7331 | * Return code |
| 7332 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 7333 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7334 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7335 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7336 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7337 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7338 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7339 | uint32_t *lp; |
| 7340 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7341 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7342 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 7343 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 7344 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7345 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7346 | if ((vport == phba->pport) && |
| 7347 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7348 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7349 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7350 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7351 | sizeof(struct lpfc_name)))) { |
| 7352 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7353 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7354 | } else { |
| 7355 | /* FAN verified - skip FLOGI */ |
| 7356 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7357 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 7358 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7359 | else { |
| 7360 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7361 | "3138 Need register VFI: (x%x/%x)\n", |
| 7362 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7363 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7364 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7365 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7366 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7367 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7368 | } |
| 7369 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7370 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7371 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7372 | * @ptr: holder for the timer function associated data. |
| 7373 | * |
| 7374 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 7375 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 7376 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 7377 | * up the worker thread. It is for the worker thread to invoke the routine |
| 7378 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 7379 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7380 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7381 | lpfc_els_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7382 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7383 | struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7384 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7385 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7386 | unsigned long iflag; |
| 7387 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7388 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7389 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7390 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7391 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7392 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7393 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7394 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7395 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7396 | return; |
| 7397 | } |
| 7398 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7399 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7400 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7401 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7402 | * @vport: pointer to a virtual N_Port data structure. |
| 7403 | * |
| 7404 | * This routine is the actual handler function that processes an ELS timeout |
| 7405 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 7406 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 7407 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 7408 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7409 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7410 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7411 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7412 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7413 | struct lpfc_sli_ring *pring; |
| 7414 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7415 | IOCB_t *cmd = NULL; |
| 7416 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7417 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7418 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7419 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7420 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7421 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7422 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7423 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 7424 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7425 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 7426 | if (unlikely(!pring)) |
| 7427 | return; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7428 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7429 | if ((phba->pport->load_flag & FC_UNLOADING)) |
| 7430 | return; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7431 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7432 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7433 | spin_lock(&pring->ring_lock); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7434 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7435 | if ((phba->pport->load_flag & FC_UNLOADING)) { |
| 7436 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7437 | spin_unlock(&pring->ring_lock); |
| 7438 | spin_unlock_irq(&phba->hbalock); |
| 7439 | return; |
| 7440 | } |
| 7441 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7442 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7443 | cmd = &piocb->iocb; |
| 7444 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7445 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 7446 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 7447 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7448 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7449 | |
| 7450 | if (piocb->vport != vport) |
| 7451 | continue; |
| 7452 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7453 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7454 | if (pcmd) |
| 7455 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7456 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7457 | if (els_command == ELS_CMD_FARP || |
| 7458 | els_command == ELS_CMD_FARPR || |
| 7459 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7460 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7461 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7462 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7463 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7464 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7465 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7466 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7467 | continue; |
| 7468 | } |
| 7469 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7470 | remote_ID = 0xffffffff; |
| 7471 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7472 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7473 | else { |
| 7474 | struct lpfc_nodelist *ndlp; |
| 7475 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7476 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7477 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7478 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7479 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7480 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7481 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7482 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7483 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 7484 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7485 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
James Smart | 15026c9 | 2013-12-17 20:30:09 -0500 | [diff] [blame] | 7486 | cmd = &piocb->iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7487 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7488 | "0127 ELS timeout Data: x%x x%x x%x " |
| 7489 | "x%x\n", els_command, |
| 7490 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 7491 | spin_lock_irq(&phba->hbalock); |
| 7492 | list_del_init(&piocb->dlist); |
| 7493 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 7494 | spin_unlock_irq(&phba->hbalock); |
| 7495 | } |
| 7496 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7497 | if (!list_empty(&pring->txcmplq)) |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7498 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 7499 | mod_timer(&vport->els_tmofunc, |
| 7500 | jiffies + msecs_to_jiffies(1000 * timeout)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7501 | } |
| 7502 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7503 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7504 | * 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] | 7505 | * @vport: pointer to a host virtual N_Port data structure. |
| 7506 | * |
| 7507 | * This routine is used to clean up all the outstanding ELS commands on a |
| 7508 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 7509 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 7510 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 7511 | * the IOCBs with a non-NULL completion callback function, the callback |
| 7512 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 7513 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 7514 | * callback function, the IOCB will simply be released. Finally, it walks |
| 7515 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 7516 | * completion queue IOCB that is associated with the @vport and is not |
| 7517 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 7518 | * part of the discovery state machine) out to HBA by invoking the |
| 7519 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 7520 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 7521 | * the IOCBs are aborted when this function returns. |
| 7522 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7523 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7524 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7525 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7526 | LIST_HEAD(abort_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7527 | struct lpfc_hba *phba = vport->phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7528 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7529 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7530 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7531 | |
| 7532 | lpfc_fabric_abort_vport(vport); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7533 | /* |
| 7534 | * For SLI3, only the hbalock is required. But SLI4 needs to coordinate |
| 7535 | * with the ring insert operation. Because lpfc_sli_issue_abort_iotag |
| 7536 | * ultimately grabs the ring_lock, the driver must splice the list into |
| 7537 | * a working list and release the locks before calling the abort. |
| 7538 | */ |
| 7539 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7540 | pring = lpfc_phba_elsring(phba); |
Guilherme G. Piccoli | 53cf29d | 2017-05-17 19:02:17 -0300 | [diff] [blame] | 7541 | |
| 7542 | /* Bail out if we've no ELS wq, like in PCI error recovery case. */ |
| 7543 | if (unlikely(!pring)) { |
| 7544 | spin_unlock_irq(&phba->hbalock); |
| 7545 | return; |
| 7546 | } |
| 7547 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7548 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7549 | spin_lock(&pring->ring_lock); |
| 7550 | |
| 7551 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 7552 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 7553 | continue; |
| 7554 | |
| 7555 | if (piocb->vport != vport) |
| 7556 | continue; |
| 7557 | list_add_tail(&piocb->dlist, &abort_list); |
| 7558 | } |
| 7559 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7560 | spin_unlock(&pring->ring_lock); |
| 7561 | spin_unlock_irq(&phba->hbalock); |
| 7562 | /* Abort each iocb on the aborted list and remove the dlist links. */ |
| 7563 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 7564 | spin_lock_irq(&phba->hbalock); |
| 7565 | list_del_init(&piocb->dlist); |
| 7566 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 7567 | spin_unlock_irq(&phba->hbalock); |
| 7568 | } |
| 7569 | if (!list_empty(&abort_list)) |
| 7570 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7571 | "3387 abort list for txq not empty\n"); |
| 7572 | INIT_LIST_HEAD(&abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7573 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7574 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7575 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7576 | spin_lock(&pring->ring_lock); |
| 7577 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7578 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 7579 | cmd = &piocb->iocb; |
| 7580 | |
| 7581 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 7582 | continue; |
| 7583 | } |
| 7584 | |
| 7585 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7586 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 7587 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 7588 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 7589 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7590 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7591 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7592 | if (piocb->vport != vport) |
| 7593 | continue; |
| 7594 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7595 | list_del_init(&piocb->list); |
| 7596 | list_add_tail(&piocb->list, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7597 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7598 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7599 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7600 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 7601 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7602 | /* Cancell all the IOCBs from the completions list */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7603 | lpfc_sli_cancel_iocbs(phba, &abort_list, |
| 7604 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 7605 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7606 | return; |
| 7607 | } |
| 7608 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7609 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7610 | * 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] | 7611 | * @phba: pointer to lpfc hba data structure. |
| 7612 | * |
| 7613 | * This routine is used to clean up all the outstanding ELS commands on a |
| 7614 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 7615 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 7616 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 7617 | * the IOCBs with the completion callback function associated, the callback |
| 7618 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 7619 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 7620 | * callback function associated, the IOCB will simply be released. Finally, |
| 7621 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 7622 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 7623 | * management plane IOCBs that are not part of the discovery state machine) |
| 7624 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 7625 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 7626 | void |
| 7627 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 7628 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7629 | struct lpfc_vport *vport; |
| 7630 | list_for_each_entry(vport, &phba->port_list, listentry) |
| 7631 | lpfc_els_flush_cmd(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7632 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 7633 | return; |
| 7634 | } |
| 7635 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7636 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7637 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7638 | * @phba: Pointer to hba context object. |
| 7639 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 7640 | * @rspiocbp: Pointer to response iocb which reported error. |
| 7641 | * |
| 7642 | * This function sends an event when there is an ELS command |
| 7643 | * failure. |
| 7644 | **/ |
| 7645 | void |
| 7646 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 7647 | struct lpfc_iocbq *cmdiocbp, |
| 7648 | struct lpfc_iocbq *rspiocbp) |
| 7649 | { |
| 7650 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 7651 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7652 | struct lpfc_lsrjt_event lsrjt_event; |
| 7653 | struct lpfc_fabric_event_header fabric_event; |
| 7654 | struct ls_rjt stat; |
| 7655 | struct lpfc_nodelist *ndlp; |
| 7656 | uint32_t *pcmd; |
| 7657 | |
| 7658 | ndlp = cmdiocbp->context1; |
| 7659 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 7660 | return; |
| 7661 | |
| 7662 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 7663 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 7664 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 7665 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 7666 | sizeof(struct lpfc_name)); |
| 7667 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 7668 | sizeof(struct lpfc_name)); |
| 7669 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 7670 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7671 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7672 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 7673 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 7674 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 7675 | fc_host_post_vendor_event(shost, |
| 7676 | fc_get_event_number(), |
| 7677 | sizeof(lsrjt_event), |
| 7678 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7679 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7680 | return; |
| 7681 | } |
| 7682 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 7683 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 7684 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 7685 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 7686 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 7687 | else |
| 7688 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 7689 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 7690 | sizeof(struct lpfc_name)); |
| 7691 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 7692 | sizeof(struct lpfc_name)); |
| 7693 | fc_host_post_vendor_event(shost, |
| 7694 | fc_get_event_number(), |
| 7695 | sizeof(fabric_event), |
| 7696 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7697 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7698 | return; |
| 7699 | } |
| 7700 | |
| 7701 | } |
| 7702 | |
| 7703 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7704 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7705 | * @vport: Pointer to vport object. |
| 7706 | * @ndlp: Pointer FC node object. |
| 7707 | * @cmd: ELS command code. |
| 7708 | * |
| 7709 | * This function posts an event when there is an incoming |
| 7710 | * unsolicited ELS command. |
| 7711 | **/ |
| 7712 | static void |
| 7713 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 7714 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7715 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7716 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7717 | struct lpfc_els_event_header *els_data = NULL; |
| 7718 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7719 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7720 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7721 | if (*payload == ELS_CMD_LOGO) { |
| 7722 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 7723 | if (!logo_data) { |
| 7724 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7725 | "0148 Failed to allocate memory " |
| 7726 | "for LOGO event\n"); |
| 7727 | return; |
| 7728 | } |
| 7729 | els_data = &logo_data->header; |
| 7730 | } else { |
| 7731 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 7732 | GFP_KERNEL); |
| 7733 | if (!els_data) { |
| 7734 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7735 | "0149 Failed to allocate memory " |
| 7736 | "for ELS event\n"); |
| 7737 | return; |
| 7738 | } |
| 7739 | } |
| 7740 | els_data->event_type = FC_REG_ELS_EVENT; |
| 7741 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7742 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7743 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7744 | break; |
| 7745 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7746 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7747 | break; |
| 7748 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7749 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 7750 | break; |
| 7751 | case ELS_CMD_LOGO: |
| 7752 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 7753 | /* Copy the WWPN in the LOGO payload */ |
| 7754 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 7755 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7756 | break; |
| 7757 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 7758 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7759 | return; |
| 7760 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7761 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 7762 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 7763 | if (*payload == ELS_CMD_LOGO) { |
| 7764 | fc_host_post_vendor_event(shost, |
| 7765 | fc_get_event_number(), |
| 7766 | sizeof(struct lpfc_logo_event), |
| 7767 | (char *)logo_data, |
| 7768 | LPFC_NL_VENDOR_ID); |
| 7769 | kfree(logo_data); |
| 7770 | } else { |
| 7771 | fc_host_post_vendor_event(shost, |
| 7772 | fc_get_event_number(), |
| 7773 | sizeof(struct lpfc_els_event_header), |
| 7774 | (char *)els_data, |
| 7775 | LPFC_NL_VENDOR_ID); |
| 7776 | kfree(els_data); |
| 7777 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7778 | |
| 7779 | return; |
| 7780 | } |
| 7781 | |
| 7782 | |
| 7783 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7784 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7785 | * @phba: pointer to lpfc hba data structure. |
| 7786 | * @pring: pointer to a SLI ring. |
| 7787 | * @vport: pointer to a host virtual N_Port data structure. |
| 7788 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 7789 | * |
| 7790 | * This routine is used for processing the IOCB associated with a unsolicited |
| 7791 | * event. It first determines whether there is an existing ndlp that matches |
| 7792 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 7793 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 7794 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 7795 | * of the discovery state machine. |
| 7796 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7797 | static void |
| 7798 | 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] | 7799 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7800 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7801 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7802 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7803 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7804 | uint32_t *payload; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7805 | uint32_t cmd, did, newnode; |
| 7806 | uint8_t rjt_exp, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7807 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7808 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7809 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7810 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7811 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7812 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7813 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 7814 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7815 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 7816 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7817 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7818 | did = icmd->un.rcvels.remoteID; |
| 7819 | if (icmd->ulpStatus) { |
| 7820 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7821 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 7822 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7823 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7824 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7825 | |
| 7826 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7827 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7828 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7829 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7830 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7831 | if (vport->load_flag & FC_UNLOADING) |
| 7832 | goto dropit; |
| 7833 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7834 | /* If NPort discovery is delayed drop incoming ELS */ |
| 7835 | if ((vport->fc_flag & FC_DISC_DELAYED) && |
| 7836 | (cmd != ELS_CMD_PLOGI)) |
| 7837 | goto dropit; |
| 7838 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7839 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7840 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7841 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 7842 | ndlp = lpfc_nlp_init(vport, did); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7843 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7844 | goto dropit; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7845 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7846 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7847 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7848 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7849 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 7850 | ndlp = lpfc_enable_node(vport, ndlp, |
| 7851 | NLP_STE_UNUSED_NODE); |
| 7852 | if (!ndlp) |
| 7853 | goto dropit; |
| 7854 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 7855 | newnode = 1; |
| 7856 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 7857 | ndlp->nlp_type |= NLP_FABRIC; |
| 7858 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 7859 | /* This is similar to the new node path */ |
| 7860 | ndlp = lpfc_nlp_get(ndlp); |
| 7861 | if (!ndlp) |
| 7862 | goto dropit; |
| 7863 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 7864 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7865 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7866 | |
| 7867 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7868 | |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7869 | /* |
| 7870 | * Do not process any unsolicited ELS commands |
| 7871 | * if the ndlp is in DEV_LOSS |
| 7872 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 7873 | shost = lpfc_shost_from_vport(vport); |
| 7874 | spin_lock_irq(shost->host_lock); |
| 7875 | if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) { |
| 7876 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7877 | goto dropit; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 7878 | } |
| 7879 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7880 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7881 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7882 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7883 | |
| 7884 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 7885 | cmd &= ELS_CMD_MASK; |
| 7886 | } |
| 7887 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7888 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7889 | "0112 ELS command x%x received from NPORT x%x " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7890 | "Data: x%x x%x x%x x%x\n", |
| 7891 | cmd, did, vport->port_state, vport->fc_flag, |
| 7892 | vport->fc_myDID, vport->fc_prevDID); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7893 | |
| 7894 | /* reject till our FLOGI completes */ |
| 7895 | if ((vport->port_state < LPFC_FABRIC_CFG_LINK) && |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7896 | (cmd != ELS_CMD_FLOGI)) { |
James Smart | 401304c | 2016-10-13 15:06:14 -0700 | [diff] [blame] | 7897 | rjt_err = LSRJT_LOGICAL_BSY; |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7898 | rjt_exp = LSEXP_NOTHING_MORE; |
| 7899 | goto lsrjt; |
| 7900 | } |
| 7901 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7902 | switch (cmd) { |
| 7903 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7904 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7905 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 7906 | did, vport->port_state, ndlp->nlp_flag); |
| 7907 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7908 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7909 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7910 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 7911 | (phba->pport->fc_flag & FC_PT2PT)) { |
| 7912 | vport->fc_prevDID = vport->fc_myDID; |
| 7913 | /* Our DID needs to be updated before registering |
| 7914 | * the vfi. This is done in lpfc_rcv_plogi but |
| 7915 | * that is called after the reg_vfi. |
| 7916 | */ |
| 7917 | vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo; |
| 7918 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7919 | "3312 Remote port assigned DID x%x " |
| 7920 | "%x\n", vport->fc_myDID, |
| 7921 | vport->fc_prevDID); |
| 7922 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7923 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7924 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7925 | |
| 7926 | /* If Nport discovery is delayed, reject PLOGIs */ |
| 7927 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 7928 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7929 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7930 | break; |
| 7931 | } |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7932 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7933 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 7934 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 7935 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 7936 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7937 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 7938 | break; |
| 7939 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7940 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7941 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7942 | spin_lock_irq(shost->host_lock); |
| 7943 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 7944 | spin_unlock_irq(shost->host_lock); |
| 7945 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7946 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7947 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7948 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7949 | break; |
| 7950 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7951 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7952 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 7953 | did, vport->port_state, ndlp->nlp_flag); |
| 7954 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7955 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7956 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7957 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7958 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7959 | break; |
| 7960 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7961 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7962 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 7963 | did, vport->port_state, ndlp->nlp_flag); |
| 7964 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7965 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7966 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7967 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7968 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7969 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7970 | break; |
| 7971 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7972 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7973 | break; |
| 7974 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7975 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7976 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 7977 | did, vport->port_state, ndlp->nlp_flag); |
| 7978 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7979 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7980 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7981 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7982 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7983 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7984 | break; |
| 7985 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7986 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7987 | break; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 7988 | case ELS_CMD_LCB: |
| 7989 | phba->fc_stat.elsRcvLCB++; |
| 7990 | lpfc_els_rcv_lcb(vport, elsiocb, ndlp); |
| 7991 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 7992 | case ELS_CMD_RDP: |
| 7993 | phba->fc_stat.elsRcvRDP++; |
| 7994 | lpfc_els_rcv_rdp(vport, elsiocb, ndlp); |
| 7995 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7996 | case ELS_CMD_RSCN: |
| 7997 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7998 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7999 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8000 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8001 | break; |
| 8002 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8003 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8004 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 8005 | did, vport->port_state, ndlp->nlp_flag); |
| 8006 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8007 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8008 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8009 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8010 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8011 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8012 | break; |
| 8013 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8014 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 8015 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8016 | break; |
| 8017 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8018 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8019 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 8020 | did, vport->port_state, ndlp->nlp_flag); |
| 8021 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8022 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8023 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8024 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8025 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8026 | break; |
| 8027 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8028 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 8029 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8030 | break; |
| 8031 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8032 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8033 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 8034 | did, vport->port_state, ndlp->nlp_flag); |
| 8035 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8036 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8037 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8038 | break; |
| 8039 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8040 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8041 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 8042 | did, vport->port_state, ndlp->nlp_flag); |
| 8043 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8044 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8045 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8046 | break; |
| 8047 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8048 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8049 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 8050 | did, vport->port_state, ndlp->nlp_flag); |
| 8051 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8052 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8053 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8054 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8055 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 8056 | case ELS_CMD_NVMEPRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8057 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8058 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 8059 | did, vport->port_state, ndlp->nlp_flag); |
| 8060 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8061 | phba->fc_stat.elsRcvPRLI++; |
Dick Kennedy | a71e3cd | 2017-03-23 08:47:18 -0400 | [diff] [blame] | 8062 | if ((vport->port_state < LPFC_DISC_AUTH) && |
| 8063 | (vport->fc_flag & FC_FABRIC)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8064 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8065 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8066 | break; |
| 8067 | } |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 8068 | |
| 8069 | /* NVMET accepts NVME PRLI only. Reject FCP PRLI */ |
| 8070 | if (cmd == ELS_CMD_PRLI && phba->nvmet_support) { |
| 8071 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 8072 | rjt_exp = LSEXP_REQ_UNSUPPORTED; |
| 8073 | break; |
| 8074 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8075 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8076 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8077 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8078 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8079 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 8080 | did, vport->port_state, ndlp->nlp_flag); |
| 8081 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8082 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8083 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8084 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8085 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8086 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8087 | case ELS_CMD_RLS: |
| 8088 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8089 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 8090 | did, vport->port_state, ndlp->nlp_flag); |
| 8091 | |
| 8092 | phba->fc_stat.elsRcvRLS++; |
| 8093 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 8094 | if (newnode) |
| 8095 | lpfc_nlp_put(ndlp); |
| 8096 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8097 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8098 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8099 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 8100 | did, vport->port_state, ndlp->nlp_flag); |
| 8101 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8102 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8103 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8104 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8105 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8106 | break; |
| 8107 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8108 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8109 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 8110 | did, vport->port_state, ndlp->nlp_flag); |
| 8111 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8112 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8113 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8114 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8115 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8116 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8117 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8118 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8119 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 8120 | did, vport->port_state, ndlp->nlp_flag); |
| 8121 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8122 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8123 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8124 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8125 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8126 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8127 | case ELS_CMD_RTV: |
| 8128 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8129 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 8130 | did, vport->port_state, ndlp->nlp_flag); |
| 8131 | phba->fc_stat.elsRcvRTV++; |
| 8132 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 8133 | if (newnode) |
| 8134 | lpfc_nlp_put(ndlp); |
| 8135 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8136 | case ELS_CMD_RRQ: |
| 8137 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8138 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 8139 | did, vport->port_state, ndlp->nlp_flag); |
| 8140 | |
| 8141 | phba->fc_stat.elsRcvRRQ++; |
| 8142 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 8143 | if (newnode) |
| 8144 | lpfc_nlp_put(ndlp); |
| 8145 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8146 | case ELS_CMD_ECHO: |
| 8147 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8148 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 8149 | did, vport->port_state, ndlp->nlp_flag); |
| 8150 | |
| 8151 | phba->fc_stat.elsRcvECHO++; |
| 8152 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 8153 | if (newnode) |
| 8154 | lpfc_nlp_put(ndlp); |
| 8155 | break; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8156 | case ELS_CMD_REC: |
| 8157 | /* receive this due to exchange closed */ |
| 8158 | rjt_err = LSRJT_UNABLE_TPC; |
| 8159 | rjt_exp = LSEXP_INVALID_OX_RX; |
| 8160 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8161 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8162 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8163 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 8164 | cmd, did, vport->port_state); |
| 8165 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8166 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8167 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8168 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8169 | |
| 8170 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8171 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8172 | "0115 Unknown ELS command x%x " |
| 8173 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8174 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8175 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8176 | break; |
| 8177 | } |
| 8178 | |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8179 | lsrjt: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8180 | /* check if need to LS_RJT received ELS cmd */ |
| 8181 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8182 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8183 | stat.un.b.lsRjtRsnCode = rjt_err; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8184 | stat.un.b.lsRjtRsnCodeExp = rjt_exp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8185 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 8186 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8187 | } |
| 8188 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8189 | lpfc_nlp_put(elsiocb->context1); |
| 8190 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8191 | return; |
| 8192 | |
| 8193 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8194 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8195 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8196 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8197 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8198 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8199 | phba->fc_stat.elsRcvDrop++; |
| 8200 | } |
| 8201 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8202 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8203 | * 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] | 8204 | * @phba: pointer to lpfc hba data structure. |
| 8205 | * @pring: pointer to a SLI ring. |
| 8206 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 8207 | * |
| 8208 | * This routine is used to process an unsolicited event received from a SLI |
| 8209 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 8210 | * associated with the unsolicited event is done by invoking the routine |
| 8211 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 8212 | * SLI ring on which the unsolicited event was received. |
| 8213 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8214 | void |
| 8215 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 8216 | struct lpfc_iocbq *elsiocb) |
| 8217 | { |
| 8218 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8219 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8220 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8221 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 8222 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8223 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8224 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8225 | elsiocb->context2 = NULL; |
| 8226 | elsiocb->context3 = NULL; |
| 8227 | |
| 8228 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 8229 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 8230 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 8231 | (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 8232 | IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8233 | phba->fc_stat.NoRcvBuf++; |
| 8234 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8235 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 8236 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8237 | return; |
| 8238 | } |
| 8239 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8240 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 8241 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 8242 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 8243 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 8244 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8245 | else |
| 8246 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8247 | icmd->unsli3.rcvsli3.vpi); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8248 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8249 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8250 | /* If there are no BDEs associated |
| 8251 | * with this IOCB, there is nothing to do. |
| 8252 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8253 | if (icmd->ulpBdeCount == 0) |
| 8254 | return; |
| 8255 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8256 | /* type of ELS cmd is first 32bit word |
| 8257 | * in packet |
| 8258 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8259 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8260 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8261 | } else { |
| 8262 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 8263 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8264 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 8265 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8266 | } |
| 8267 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8268 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 8269 | /* |
| 8270 | * The different unsolicited event handlers would tell us |
| 8271 | * if they are done with "mp" by setting context2 to NULL. |
| 8272 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8273 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8274 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 8275 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8276 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8277 | |
| 8278 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8279 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8280 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8281 | elsiocb->context2 = bdeBuf2; |
| 8282 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8283 | /* free mp if we are done with it */ |
| 8284 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8285 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 8286 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8287 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8288 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8289 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8290 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 8291 | static void |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8292 | lpfc_start_fdmi(struct lpfc_vport *vport) |
| 8293 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8294 | struct lpfc_nodelist *ndlp; |
| 8295 | |
| 8296 | /* If this is the first time, allocate an ndlp and initialize |
| 8297 | * it. Otherwise, make sure the node is enabled and then do the |
| 8298 | * login. |
| 8299 | */ |
| 8300 | ndlp = lpfc_findnode_did(vport, FDMI_DID); |
| 8301 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 8302 | ndlp = lpfc_nlp_init(vport, FDMI_DID); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8303 | if (ndlp) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8304 | ndlp->nlp_type |= NLP_FABRIC; |
| 8305 | } else { |
| 8306 | return; |
| 8307 | } |
| 8308 | } |
| 8309 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 8310 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 8311 | |
| 8312 | if (ndlp) { |
| 8313 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 8314 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| 8315 | } |
| 8316 | } |
| 8317 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8318 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8319 | * 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] | 8320 | * @phba: pointer to lpfc hba data structure. |
| 8321 | * @vport: pointer to a virtual N_Port data structure. |
| 8322 | * |
| 8323 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 8324 | * State Change Request (SCR) for a @vport. This routine will create an |
| 8325 | * ndlp for the Name Server associated to the @vport if such node does |
| 8326 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 8327 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 8328 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 8329 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 8330 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8331 | void |
| 8332 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 8333 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8334 | struct lpfc_nodelist *ndlp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8335 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8336 | |
| 8337 | /* |
| 8338 | * If lpfc_delay_discovery parameter is set and the clean address |
| 8339 | * bit is cleared and fc fabric parameters chenged, delay FC NPort |
| 8340 | * discovery. |
| 8341 | */ |
| 8342 | spin_lock_irq(shost->host_lock); |
| 8343 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 8344 | spin_unlock_irq(shost->host_lock); |
James Smart | 1877570 | 2013-04-17 20:19:25 -0400 | [diff] [blame] | 8345 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 8346 | "3334 Delay fc port discovery for %d seconds\n", |
| 8347 | phba->fc_ratov); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8348 | mod_timer(&vport->delayed_disc_tmo, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8349 | jiffies + msecs_to_jiffies(1000 * phba->fc_ratov)); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8350 | return; |
| 8351 | } |
| 8352 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8353 | |
| 8354 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 8355 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 8356 | ndlp = lpfc_nlp_init(vport, NameServer_DID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8357 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8358 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8359 | lpfc_disc_start(vport); |
| 8360 | return; |
| 8361 | } |
| 8362 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8363 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8364 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8365 | return; |
| 8366 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8367 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 8368 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 8369 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8370 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8371 | lpfc_disc_start(vport); |
| 8372 | return; |
| 8373 | } |
| 8374 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 8375 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8376 | "0348 NameServer login: node freed\n"); |
| 8377 | return; |
| 8378 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8379 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8380 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8381 | |
| 8382 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 8383 | |
| 8384 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 8385 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8386 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8387 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8388 | return; |
| 8389 | } |
| 8390 | |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 8391 | if ((phba->cfg_enable_SmartSAN || |
| 8392 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) && |
| 8393 | (vport->load_flag & FC_ALLOW_FDMI)) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8394 | lpfc_start_fdmi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8395 | } |
| 8396 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8397 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8398 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8399 | * @phba: pointer to lpfc hba data structure. |
| 8400 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 8401 | * |
| 8402 | * This routine is the completion callback function to register new vport |
| 8403 | * mailbox command. If the new vport mailbox command completes successfully, |
| 8404 | * the fabric registration login shall be performed on physical port (the |
| 8405 | * new vport created is actually a physical port, with VPI 0) or the port |
| 8406 | * login to Name Server for State Change Request (SCR) will be performed |
| 8407 | * on virtual port (real virtual port, with VPI greater than 0). |
| 8408 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8409 | static void |
| 8410 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 8411 | { |
| 8412 | struct lpfc_vport *vport = pmb->vport; |
| 8413 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8414 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 8415 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8416 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8417 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8418 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8419 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8420 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8421 | |
| 8422 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8423 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8424 | "0915 Register VPI failed : Status: x%x" |
| 8425 | " upd bit: x%x \n", mb->mbxStatus, |
| 8426 | mb->un.varRegVpi.upd); |
| 8427 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 8428 | mb->un.varRegVpi.upd) |
| 8429 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8430 | |
| 8431 | switch (mb->mbxStatus) { |
| 8432 | case 0x11: /* unsupported feature */ |
| 8433 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8434 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8435 | /* giving up on vport registration */ |
| 8436 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 8437 | spin_lock_irq(shost->host_lock); |
| 8438 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 8439 | spin_unlock_irq(shost->host_lock); |
| 8440 | lpfc_can_disctmo(vport); |
| 8441 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8442 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 8443 | case 0x20: |
| 8444 | spin_lock_irq(shost->host_lock); |
| 8445 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 8446 | spin_unlock_irq(shost->host_lock); |
| 8447 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 8448 | pmb->vport = vport; |
| 8449 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 8450 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 8451 | MBX_NOWAIT); |
| 8452 | if (rc == MBX_NOT_FINISHED) { |
| 8453 | lpfc_printf_vlog(vport, |
| 8454 | KERN_ERR, LOG_MBOX, |
| 8455 | "2732 Failed to issue INIT_VPI" |
| 8456 | " mailbox command\n"); |
| 8457 | } else { |
| 8458 | lpfc_nlp_put(ndlp); |
| 8459 | return; |
| 8460 | } |
| 8461 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8462 | default: |
| 8463 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8464 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8465 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8466 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8467 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8468 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8469 | spin_unlock_irq(shost->host_lock); |
James Smart | 5d18153 | 2017-03-04 09:30:25 -0800 | [diff] [blame] | 8470 | if (mb->mbxStatus == MBX_NOT_FINISHED) |
| 8471 | break; |
| 8472 | if ((vport->port_type == LPFC_PHYSICAL_PORT) && |
| 8473 | !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) { |
| 8474 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8475 | lpfc_issue_init_vfi(vport); |
| 8476 | else |
| 8477 | lpfc_initial_flogi(vport); |
| 8478 | } else { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8479 | lpfc_initial_fdisc(vport); |
James Smart | 5d18153 | 2017-03-04 09:30:25 -0800 | [diff] [blame] | 8480 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8481 | break; |
| 8482 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8483 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8484 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 8485 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8486 | spin_unlock_irq(shost->host_lock); |
| 8487 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8488 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 8489 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8490 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 8491 | /* |
| 8492 | * If the physical port is instantiated using |
| 8493 | * FDISC, do not start vport discovery. |
| 8494 | */ |
| 8495 | if (vport->port_state != LPFC_FDISC) |
| 8496 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8497 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8498 | } |
| 8499 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8500 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8501 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8502 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8503 | /* Now, we decrement the ndlp reference count held for this |
| 8504 | * callback function |
| 8505 | */ |
| 8506 | lpfc_nlp_put(ndlp); |
| 8507 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8508 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8509 | return; |
| 8510 | } |
| 8511 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8512 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8513 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8514 | * @phba: pointer to lpfc hba data structure. |
| 8515 | * @vport: pointer to a host virtual N_Port data structure. |
| 8516 | * @ndlp: pointer to a node-list data structure. |
| 8517 | * |
| 8518 | * This routine registers the @vport as a new virtual port with a HBA. |
| 8519 | * It is done through a registering vpi mailbox command. |
| 8520 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8521 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8522 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 8523 | struct lpfc_nodelist *ndlp) |
| 8524 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8525 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8526 | LPFC_MBOXQ_t *mbox; |
| 8527 | |
| 8528 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8529 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8530 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8531 | mbox->vport = vport; |
| 8532 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 8533 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8534 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8535 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8536 | /* mailbox command not success, decrement ndlp |
| 8537 | * reference count for this command |
| 8538 | */ |
| 8539 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8540 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8541 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8542 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 8543 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8544 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8545 | } |
| 8546 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8547 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 8548 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8549 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8550 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8551 | return; |
| 8552 | |
| 8553 | mbox_err_exit: |
| 8554 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 8555 | spin_lock_irq(shost->host_lock); |
| 8556 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 8557 | spin_unlock_irq(shost->host_lock); |
| 8558 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8559 | } |
| 8560 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8561 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8562 | * 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] | 8563 | * @phba: pointer to lpfc hba data structure. |
| 8564 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8565 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8566 | **/ |
| 8567 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8568 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8569 | { |
| 8570 | struct lpfc_vport **vports; |
| 8571 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8572 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8573 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8574 | |
| 8575 | /* Treat this failure as linkdown for all vports */ |
| 8576 | link_state = phba->link_state; |
| 8577 | lpfc_linkdown(phba); |
| 8578 | phba->link_state = link_state; |
| 8579 | |
| 8580 | vports = lpfc_create_vport_work_array(phba); |
| 8581 | |
| 8582 | if (vports) { |
| 8583 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 8584 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 8585 | if (ndlp) |
| 8586 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 8587 | lpfc_els_flush_cmd(vports[i]); |
| 8588 | } |
| 8589 | lpfc_destroy_vport_work_array(phba, vports); |
| 8590 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8591 | } |
| 8592 | |
| 8593 | /** |
| 8594 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 8595 | * @phba: pointer to lpfc hba data structure. |
| 8596 | * |
| 8597 | * This routine abort all pending discovery commands and |
| 8598 | * start a timer to retry FLOGI for the physical port |
| 8599 | * discovery. |
| 8600 | **/ |
| 8601 | void |
| 8602 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 8603 | { |
| 8604 | struct lpfc_nodelist *ndlp; |
| 8605 | struct Scsi_Host *shost; |
| 8606 | |
| 8607 | /* Cancel the all vports retry delay retry timers */ |
| 8608 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8609 | |
| 8610 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 8611 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 8612 | if (!ndlp) |
| 8613 | return; |
| 8614 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8615 | shost = lpfc_shost_from_vport(phba->pport); |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8616 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000)); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8617 | spin_lock_irq(shost->host_lock); |
| 8618 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 8619 | spin_unlock_irq(shost->host_lock); |
| 8620 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 8621 | phba->pport->port_state = LPFC_FLOGI; |
| 8622 | return; |
| 8623 | } |
| 8624 | |
| 8625 | /** |
| 8626 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 8627 | * @phba: pointer to lpfc hba data structure. |
| 8628 | * @cmdiocb: pointer to FDISC command iocb. |
| 8629 | * @rspiocb: pointer to FDISC response iocb. |
| 8630 | * |
| 8631 | * This routine checks if a FLOGI is reguired for FDISC |
| 8632 | * to succeed. |
| 8633 | **/ |
| 8634 | static int |
| 8635 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 8636 | struct lpfc_iocbq *cmdiocb, |
| 8637 | struct lpfc_iocbq *rspiocb) |
| 8638 | { |
| 8639 | |
| 8640 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 8641 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 8642 | return 0; |
| 8643 | else |
| 8644 | return 1; |
| 8645 | } |
| 8646 | |
| 8647 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8648 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8649 | * @phba: pointer to lpfc hba data structure. |
| 8650 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8651 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8652 | * |
| 8653 | * This routine is the completion callback function to a Fabric Discover |
| 8654 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 8655 | * single threaded, each FDISC completion callback function will reset |
| 8656 | * the discovery timer for all vports such that the timers will not get |
| 8657 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 8658 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 8659 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 8660 | * assigned to the vport has been changed with the completion of the FDISC |
| 8661 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 8662 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 8663 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 8664 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 8665 | * Server for State Change Request (SCR). |
| 8666 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8667 | static void |
| 8668 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8669 | struct lpfc_iocbq *rspiocb) |
| 8670 | { |
| 8671 | struct lpfc_vport *vport = cmdiocb->vport; |
| 8672 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8673 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 8674 | struct lpfc_nodelist *np; |
| 8675 | struct lpfc_nodelist *next_np; |
| 8676 | IOCB_t *irsp = &rspiocb->iocb; |
| 8677 | struct lpfc_iocbq *piocb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8678 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 8679 | struct serv_parm *sp; |
| 8680 | uint8_t fabric_param_changed; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8681 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8682 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8683 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 8684 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 8685 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8686 | /* Since all FDISCs are being single threaded, we |
| 8687 | * must reset the discovery timer for ALL vports |
| 8688 | * waiting to send FDISC when one completes. |
| 8689 | */ |
| 8690 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 8691 | lpfc_set_disctmo(piocb->vport); |
| 8692 | } |
| 8693 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8694 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8695 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 8696 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 8697 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8698 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8699 | |
| 8700 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 8701 | lpfc_retry_pport_discovery(phba); |
| 8702 | goto out; |
| 8703 | } |
| 8704 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8705 | /* Check for retry */ |
| 8706 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 8707 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8708 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8709 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8710 | "0126 FDISC failed. (x%x/x%x)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8711 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8712 | goto fdisc_failed; |
| 8713 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8714 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8715 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8716 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8717 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8718 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8719 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 8720 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8721 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8722 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 8723 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8724 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 8725 | if (!prsp) |
| 8726 | goto out; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8727 | sp = prsp->virt + sizeof(uint32_t); |
| 8728 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 8729 | memcpy(&vport->fabric_portname, &sp->portName, |
| 8730 | sizeof(struct lpfc_name)); |
| 8731 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 8732 | sizeof(struct lpfc_name)); |
| 8733 | if (fabric_param_changed && |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8734 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 8735 | /* If our NportID changed, we need to ensure all |
| 8736 | * remaining NPORTs get unreg_login'ed so we can |
| 8737 | * issue unreg_vpi. |
| 8738 | */ |
| 8739 | list_for_each_entry_safe(np, next_np, |
| 8740 | &vport->fc_nodes, nlp_listp) { |
| 8741 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 8742 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 8743 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 8744 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8745 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8746 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8747 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8748 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8749 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 8750 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8751 | |
| 8752 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8753 | lpfc_sli4_unreg_all_rpis(vport); |
| 8754 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8755 | lpfc_mbx_unreg_vpi(vport); |
| 8756 | spin_lock_irq(shost->host_lock); |
| 8757 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8758 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8759 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8760 | else |
| 8761 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8762 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8763 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 8764 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 8765 | /* |
| 8766 | * Driver needs to re-reg VPI in order for f/w |
| 8767 | * to update the MAC address. |
| 8768 | */ |
| 8769 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 8770 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8771 | } |
| 8772 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 8773 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 8774 | lpfc_issue_init_vpi(vport); |
| 8775 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8776 | lpfc_register_new_vport(phba, vport, ndlp); |
| 8777 | else |
| 8778 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8779 | goto out; |
| 8780 | fdisc_failed: |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 8781 | if (vport->fc_vport && |
| 8782 | (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)) |
James Smart | c84163d | 2015-05-21 13:55:22 -0400 | [diff] [blame] | 8783 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8784 | /* Cancel discovery timer */ |
| 8785 | lpfc_can_disctmo(vport); |
| 8786 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8787 | out: |
| 8788 | lpfc_els_free_iocb(phba, cmdiocb); |
| 8789 | } |
| 8790 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8791 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8792 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8793 | * @vport: pointer to a virtual N_Port data structure. |
| 8794 | * @ndlp: pointer to a node-list data structure. |
| 8795 | * @retry: number of retries to the command IOCB. |
| 8796 | * |
| 8797 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 8798 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 8799 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 8800 | * IOCB will be sent off HBA at any given time. |
| 8801 | * |
| 8802 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 8803 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 8804 | * will be stored into the context1 field of the IOCB for the completion |
| 8805 | * callback function to the FDISC ELS command. |
| 8806 | * |
| 8807 | * Return code |
| 8808 | * 0 - Successfully issued fdisc iocb command |
| 8809 | * 1 - Failed to issue fdisc iocb command |
| 8810 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8811 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8812 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 8813 | uint8_t retry) |
| 8814 | { |
| 8815 | struct lpfc_hba *phba = vport->phba; |
| 8816 | IOCB_t *icmd; |
| 8817 | struct lpfc_iocbq *elsiocb; |
| 8818 | struct serv_parm *sp; |
| 8819 | uint8_t *pcmd; |
| 8820 | uint16_t cmdsize; |
| 8821 | int did = ndlp->nlp_DID; |
| 8822 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8823 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8824 | vport->port_state = LPFC_FDISC; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8825 | vport->fc_myDID = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8826 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 8827 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 8828 | ELS_CMD_FDISC); |
| 8829 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8830 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8831 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8832 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8833 | return 1; |
| 8834 | } |
| 8835 | |
| 8836 | icmd = &elsiocb->iocb; |
| 8837 | icmd->un.elsreq64.myID = 0; |
| 8838 | icmd->un.elsreq64.fl = 1; |
| 8839 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 8840 | /* |
| 8841 | * SLI3 ports require a different context type value than SLI4. |
| 8842 | * Catch SLI3 ports here and override the prep. |
| 8843 | */ |
| 8844 | if (phba->sli_rev == LPFC_SLI_REV3) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8845 | icmd->ulpCt_h = 1; |
| 8846 | icmd->ulpCt_l = 0; |
| 8847 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8848 | |
| 8849 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 8850 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 8851 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 8852 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 8853 | sp = (struct serv_parm *) pcmd; |
| 8854 | /* Setup CSPs accordingly for Fabric */ |
| 8855 | sp->cmn.e_d_tov = 0; |
| 8856 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 8857 | sp->cmn.virtual_fabric_support = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8858 | sp->cls1.classValid = 0; |
| 8859 | sp->cls2.seqDelivery = 1; |
| 8860 | sp->cls3.seqDelivery = 1; |
| 8861 | |
| 8862 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 8863 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 8864 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 8865 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 8866 | memcpy(pcmd, &vport->fc_portname, 8); |
| 8867 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 8868 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 8869 | memcpy(pcmd, &vport->fc_nodename, 8); |
Dick Kennedy | 176de5b | 2017-08-23 16:55:40 -0700 | [diff] [blame] | 8870 | sp->cmn.valid_vendor_ver_level = 0; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 8871 | memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8872 | lpfc_set_disctmo(vport); |
| 8873 | |
| 8874 | phba->fc_stat.elsXmitFDISC++; |
| 8875 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 8876 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8877 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8878 | "Issue FDISC: did:x%x", |
| 8879 | did, 0, 0); |
| 8880 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8881 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 8882 | if (rc == IOCB_ERROR) { |
| 8883 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8884 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8885 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8886 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8887 | return 1; |
| 8888 | } |
| 8889 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8890 | return 0; |
| 8891 | } |
| 8892 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8893 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8894 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8895 | * @phba: pointer to lpfc hba data structure. |
| 8896 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8897 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8898 | * |
| 8899 | * This routine is the completion callback function to the issuing of a LOGO |
| 8900 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 8901 | * reference count held on ndlp for this completion function, indicating that |
| 8902 | * the reference to the ndlp is no long needed. Note that the |
| 8903 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 8904 | * callback function and an additional explicit ndlp reference decrementation |
| 8905 | * will trigger the actual release of the ndlp. |
| 8906 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8907 | static void |
| 8908 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8909 | struct lpfc_iocbq *rspiocb) |
| 8910 | { |
| 8911 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8912 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8913 | struct lpfc_nodelist *ndlp; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8914 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8915 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8916 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8917 | irsp = &rspiocb->iocb; |
| 8918 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8919 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 8920 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8921 | |
| 8922 | lpfc_els_free_iocb(phba, cmdiocb); |
| 8923 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8924 | |
| 8925 | /* Trigger the release of the ndlp after logo */ |
| 8926 | lpfc_nlp_put(ndlp); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8927 | |
| 8928 | /* NPIV LOGO completes to NPort <nlp_DID> */ |
| 8929 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8930 | "2928 NPIV LOGO completes to NPort x%x " |
| 8931 | "Data: x%x x%x x%x x%x\n", |
| 8932 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 8933 | irsp->ulpTimeout, vport->num_disc_nodes); |
| 8934 | |
| 8935 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 8936 | spin_lock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 8937 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8938 | vport->fc_flag &= ~FC_FABRIC; |
| 8939 | spin_unlock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 8940 | lpfc_can_disctmo(vport); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8941 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8942 | } |
| 8943 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8944 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8945 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8946 | * @vport: pointer to a virtual N_Port data structure. |
| 8947 | * @ndlp: pointer to a node-list data structure. |
| 8948 | * |
| 8949 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 8950 | * |
| 8951 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 8952 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 8953 | * will be stored into the context1 field of the IOCB for the completion |
| 8954 | * callback function to the LOGO ELS command. |
| 8955 | * |
| 8956 | * Return codes |
| 8957 | * 0 - Successfully issued logo off the @vport |
| 8958 | * 1 - Failed to issue logo off the @vport |
| 8959 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8960 | int |
| 8961 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 8962 | { |
| 8963 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8964 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8965 | struct lpfc_iocbq *elsiocb; |
| 8966 | uint8_t *pcmd; |
| 8967 | uint16_t cmdsize; |
| 8968 | |
| 8969 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 8970 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 8971 | ELS_CMD_LOGO); |
| 8972 | if (!elsiocb) |
| 8973 | return 1; |
| 8974 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8975 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 8976 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 8977 | pcmd += sizeof(uint32_t); |
| 8978 | |
| 8979 | /* Fill in LOGO payload */ |
| 8980 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 8981 | pcmd += sizeof(uint32_t); |
| 8982 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 8983 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8984 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8985 | "Issue LOGO npiv did:x%x flg:x%x", |
| 8986 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 8987 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8988 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 8989 | spin_lock_irq(shost->host_lock); |
| 8990 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 8991 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8992 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 8993 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8994 | spin_lock_irq(shost->host_lock); |
| 8995 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 8996 | spin_unlock_irq(shost->host_lock); |
| 8997 | lpfc_els_free_iocb(phba, elsiocb); |
| 8998 | return 1; |
| 8999 | } |
| 9000 | return 0; |
| 9001 | } |
| 9002 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9003 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9004 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9005 | * @ptr: holder for the timer function associated data. |
| 9006 | * |
| 9007 | * This routine is invoked by the fabric iocb block timer after |
| 9008 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 9009 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 9010 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 9011 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 9012 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 9013 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9014 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 9015 | lpfc_fabric_block_timeout(struct timer_list *t) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9016 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 9017 | struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9018 | unsigned long iflags; |
| 9019 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9020 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9021 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 9022 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 9023 | if (!tmo_posted) |
| 9024 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 9025 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 9026 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9027 | if (!tmo_posted) |
| 9028 | lpfc_worker_wake_up(phba); |
| 9029 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9030 | } |
| 9031 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9032 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9033 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9034 | * @phba: pointer to lpfc hba data structure. |
| 9035 | * |
| 9036 | * This routine issues one fabric iocb from the driver internal list to |
| 9037 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 9038 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 9039 | * remove one pending fabric iocb from the driver internal list and invokes |
| 9040 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 9041 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9042 | static void |
| 9043 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 9044 | { |
| 9045 | struct lpfc_iocbq *iocb; |
| 9046 | unsigned long iflags; |
| 9047 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9048 | IOCB_t *cmd; |
| 9049 | |
| 9050 | repeat: |
| 9051 | iocb = NULL; |
| 9052 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9053 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9054 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 9055 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 9056 | list); |
| 9057 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9058 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9059 | atomic_inc(&phba->fabric_iocb_count); |
| 9060 | } |
| 9061 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9062 | if (iocb) { |
| 9063 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 9064 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 9065 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 9066 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9067 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 9068 | "Fabric sched1: ste:x%x", |
| 9069 | iocb->vport->port_state, 0, 0); |
| 9070 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9071 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9072 | |
| 9073 | if (ret == IOCB_ERROR) { |
| 9074 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 9075 | iocb->fabric_iocb_cmpl = NULL; |
| 9076 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 9077 | cmd = &iocb->iocb; |
| 9078 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 9079 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 9080 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 9081 | |
| 9082 | atomic_dec(&phba->fabric_iocb_count); |
| 9083 | goto repeat; |
| 9084 | } |
| 9085 | } |
| 9086 | |
| 9087 | return; |
| 9088 | } |
| 9089 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9090 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9091 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9092 | * @phba: pointer to lpfc hba data structure. |
| 9093 | * |
| 9094 | * This routine unblocks the issuing fabric iocb command. The function |
| 9095 | * will clear the fabric iocb block bit and then invoke the routine |
| 9096 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 9097 | * from the driver internal fabric iocb list. |
| 9098 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9099 | void |
| 9100 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 9101 | { |
| 9102 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 9103 | |
| 9104 | lpfc_resume_fabric_iocbs(phba); |
| 9105 | return; |
| 9106 | } |
| 9107 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9108 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9109 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9110 | * @phba: pointer to lpfc hba data structure. |
| 9111 | * |
| 9112 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 9113 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 9114 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 9115 | * fabric iocb will be issued out of the HBA. |
| 9116 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9117 | static void |
| 9118 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 9119 | { |
| 9120 | int blocked; |
| 9121 | |
| 9122 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9123 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9124 | if (!blocked) |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9125 | mod_timer(&phba->fabric_block_timer, |
| 9126 | jiffies + msecs_to_jiffies(100)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9127 | |
| 9128 | return; |
| 9129 | } |
| 9130 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9131 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9132 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9133 | * @phba: pointer to lpfc hba data structure. |
| 9134 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 9135 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 9136 | * |
| 9137 | * This routine is the callback function that is put to the fabric iocb's |
| 9138 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 9139 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 9140 | * function first restores and invokes the original iocb's callback function |
| 9141 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 9142 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 9143 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9144 | static void |
| 9145 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9146 | struct lpfc_iocbq *rspiocb) |
| 9147 | { |
| 9148 | struct ls_rjt stat; |
| 9149 | |
Shyam Saini | e01ea5e | 2016-12-24 16:21:07 +0530 | [diff] [blame] | 9150 | BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9151 | |
| 9152 | switch (rspiocb->iocb.ulpStatus) { |
| 9153 | case IOSTAT_NPORT_RJT: |
| 9154 | case IOSTAT_FABRIC_RJT: |
| 9155 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 9156 | lpfc_block_fabric_iocbs(phba); |
| 9157 | } |
| 9158 | break; |
| 9159 | |
| 9160 | case IOSTAT_NPORT_BSY: |
| 9161 | case IOSTAT_FABRIC_BSY: |
| 9162 | lpfc_block_fabric_iocbs(phba); |
| 9163 | break; |
| 9164 | |
| 9165 | case IOSTAT_LS_RJT: |
| 9166 | stat.un.lsRjtError = |
| 9167 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 9168 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 9169 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 9170 | lpfc_block_fabric_iocbs(phba); |
| 9171 | break; |
| 9172 | } |
| 9173 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 9174 | BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9175 | |
| 9176 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 9177 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 9178 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 9179 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 9180 | |
| 9181 | atomic_dec(&phba->fabric_iocb_count); |
| 9182 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9183 | /* Post any pending iocbs to HBA */ |
| 9184 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9185 | } |
| 9186 | } |
| 9187 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9188 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9189 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9190 | * @phba: pointer to lpfc hba data structure. |
| 9191 | * @iocb: pointer to lpfc command iocb data structure. |
| 9192 | * |
| 9193 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 9194 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 9195 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 9196 | * any given time. As such, this function will first check to see whether there |
| 9197 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 9198 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 9199 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 9200 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 9201 | * |
| 9202 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 9203 | * order. The problem is caused by the construction of the "ready" boolen does |
| 9204 | * not include the condition that the internal fabric IOCB list is empty. As |
| 9205 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 9206 | * ahead of the fabric IOCBs in the internal list. |
| 9207 | * |
| 9208 | * Return code |
| 9209 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 9210 | * IOCB_ERROR - failed to issue fabric iocb |
| 9211 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 9212 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9213 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 9214 | { |
| 9215 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9216 | int ready; |
| 9217 | int ret; |
| 9218 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 9219 | BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9220 | |
| 9221 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9222 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 9223 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 9224 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9225 | if (ready) |
| 9226 | /* Increment fabric iocb count to hold the position */ |
| 9227 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9228 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9229 | if (ready) { |
| 9230 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 9231 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 9232 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 9233 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9234 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 9235 | "Fabric sched2: ste:x%x", |
| 9236 | iocb->vport->port_state, 0, 0); |
| 9237 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9238 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9239 | |
| 9240 | if (ret == IOCB_ERROR) { |
| 9241 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 9242 | iocb->fabric_iocb_cmpl = NULL; |
| 9243 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 9244 | atomic_dec(&phba->fabric_iocb_count); |
| 9245 | } |
| 9246 | } else { |
| 9247 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9248 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 9249 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9250 | ret = IOCB_SUCCESS; |
| 9251 | } |
| 9252 | return ret; |
| 9253 | } |
| 9254 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9255 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9256 | * 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] | 9257 | * @vport: pointer to a virtual N_Port data structure. |
| 9258 | * |
| 9259 | * This routine aborts all the IOCBs associated with a @vport from the |
| 9260 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 9261 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 9262 | * list, removes each IOCB associated with the @vport off the list, set the |
| 9263 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 9264 | * associated with the IOCB. |
| 9265 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 9266 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9267 | { |
| 9268 | LIST_HEAD(completions); |
| 9269 | struct lpfc_hba *phba = vport->phba; |
| 9270 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9271 | |
| 9272 | spin_lock_irq(&phba->hbalock); |
| 9273 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 9274 | list) { |
| 9275 | |
| 9276 | if (piocb->vport != vport) |
| 9277 | continue; |
| 9278 | |
| 9279 | list_move_tail(&piocb->list, &completions); |
| 9280 | } |
| 9281 | spin_unlock_irq(&phba->hbalock); |
| 9282 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9283 | /* Cancel all the IOCBs from the completions list */ |
| 9284 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9285 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9286 | } |
| 9287 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9288 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9289 | * 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] | 9290 | * @ndlp: pointer to a node-list data structure. |
| 9291 | * |
| 9292 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 9293 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 9294 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 9295 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 9296 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 9297 | * associated with the IOCB. |
| 9298 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9299 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 9300 | { |
| 9301 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9302 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9303 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9304 | struct lpfc_sli_ring *pring; |
| 9305 | |
| 9306 | pring = lpfc_phba_elsring(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9307 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 9308 | if (unlikely(!pring)) |
| 9309 | return; |
| 9310 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9311 | spin_lock_irq(&phba->hbalock); |
| 9312 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 9313 | list) { |
| 9314 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 9315 | |
| 9316 | list_move_tail(&piocb->list, &completions); |
| 9317 | } |
| 9318 | } |
| 9319 | spin_unlock_irq(&phba->hbalock); |
| 9320 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9321 | /* Cancel all the IOCBs from the completions list */ |
| 9322 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9323 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9324 | } |
| 9325 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9326 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9327 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9328 | * @phba: pointer to lpfc hba data structure. |
| 9329 | * |
| 9330 | * This routine aborts all the IOCBs currently on the driver internal |
| 9331 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 9332 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 9333 | * list, removes IOCBs off the list, set the status feild to |
| 9334 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 9335 | * the IOCB. |
| 9336 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9337 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 9338 | { |
| 9339 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9340 | |
| 9341 | spin_lock_irq(&phba->hbalock); |
| 9342 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 9343 | spin_unlock_irq(&phba->hbalock); |
| 9344 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9345 | /* Cancel all the IOCBs from the completions list */ |
| 9346 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9347 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9348 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9349 | |
| 9350 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 9351 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport |
| 9352 | * @vport: pointer to lpfc vport data structure. |
| 9353 | * |
| 9354 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 9355 | * for an ndlp on removal. |
| 9356 | **/ |
| 9357 | void |
| 9358 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) |
| 9359 | { |
| 9360 | struct lpfc_hba *phba = vport->phba; |
| 9361 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 9362 | unsigned long iflag = 0; |
| 9363 | |
| 9364 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9365 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 9366 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 9367 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 9368 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) |
| 9369 | sglq_entry->ndlp = NULL; |
| 9370 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9371 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 9372 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9373 | return; |
| 9374 | } |
| 9375 | |
| 9376 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9377 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 9378 | * @phba: pointer to lpfc hba data structure. |
| 9379 | * @axri: pointer to the els xri abort wcqe structure. |
| 9380 | * |
| 9381 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 9382 | * ELS aborted xri. |
| 9383 | **/ |
| 9384 | void |
| 9385 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 9386 | struct sli4_wcqe_xri_aborted *axri) |
| 9387 | { |
| 9388 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9389 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9390 | uint16_t lxri = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9391 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9392 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 9393 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9394 | struct lpfc_nodelist *ndlp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9395 | struct lpfc_sli_ring *pring; |
| 9396 | |
| 9397 | pring = lpfc_phba_elsring(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9398 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9399 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9400 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9401 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 9402 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 9403 | if (sglq_entry->sli4_xritag == xri) { |
| 9404 | list_del(&sglq_entry->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9405 | ndlp = sglq_entry->ndlp; |
| 9406 | sglq_entry->ndlp = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9407 | list_add_tail(&sglq_entry->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9408 | &phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9409 | sglq_entry->state = SGL_FREED; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9410 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9411 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 9412 | lpfc_set_rrq_active(phba, ndlp, |
| 9413 | sglq_entry->sli4_lxritag, |
| 9414 | rxid, 1); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 9415 | |
| 9416 | /* Check if TXQ queue needs to be serviced */ |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 9417 | if (pring && !list_empty(&pring->txq)) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 9418 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9419 | return; |
| 9420 | } |
| 9421 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9422 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9423 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 9424 | if (lxri == NO_XRI) { |
| 9425 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9426 | return; |
| 9427 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9428 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9429 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9430 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9431 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9432 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9433 | return; |
| 9434 | } |
| 9435 | sglq_entry->state = SGL_XRI_ABORTED; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9436 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9437 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9438 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9439 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 9440 | |
| 9441 | /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. |
| 9442 | * @vport: pointer to virtual port object. |
| 9443 | * @ndlp: nodelist pointer for the impacted node. |
| 9444 | * |
| 9445 | * The driver calls this routine in response to an SLI4 XRI ABORT CQE |
| 9446 | * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, |
| 9447 | * the driver is required to send a LOGO to the remote node before it |
| 9448 | * attempts to recover its login to the remote node. |
| 9449 | */ |
| 9450 | void |
| 9451 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 9452 | struct lpfc_nodelist *ndlp) |
| 9453 | { |
| 9454 | struct Scsi_Host *shost; |
| 9455 | struct lpfc_hba *phba; |
| 9456 | unsigned long flags = 0; |
| 9457 | |
| 9458 | shost = lpfc_shost_from_vport(vport); |
| 9459 | phba = vport->phba; |
| 9460 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 9461 | lpfc_printf_log(phba, KERN_INFO, |
| 9462 | LOG_SLI, "3093 No rport recovery needed. " |
| 9463 | "rport in state 0x%x\n", ndlp->nlp_state); |
| 9464 | return; |
| 9465 | } |
| 9466 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9467 | "3094 Start rport recovery on shost id 0x%x " |
| 9468 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 9469 | "flags 0x%x\n", |
| 9470 | shost->host_no, ndlp->nlp_DID, |
| 9471 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 9472 | ndlp->nlp_flag); |
| 9473 | /* |
| 9474 | * The rport is not responding. Remove the FCP-2 flag to prevent |
| 9475 | * an ADISC in the follow-up recovery code. |
| 9476 | */ |
| 9477 | spin_lock_irqsave(shost->host_lock, flags); |
| 9478 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 9479 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 9480 | lpfc_issue_els_logo(vport, ndlp, 0); |
| 9481 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
| 9482 | } |
| 9483 | |