| 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 | c9f8735 | 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 | c9f8735 | 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 | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 861 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
| 862 | if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) { |
| 863 | lpfc_unregister_fcf_prep(phba); |
| 864 | |
| 865 | spin_lock_irq(shost->host_lock); |
| 866 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 867 | spin_unlock_irq(shost->host_lock); |
| 868 | phba->fc_topology_changed = 0; |
| 869 | } |
| 870 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 871 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 872 | sizeof(vport->fc_portname)); |
James Smart | 2eb6862 | 2012-09-29 11:32:27 -0400 | [diff] [blame] | 873 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 874 | if (rc >= 0) { |
| 875 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 876 | spin_lock_irq(shost->host_lock); |
| 877 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 878 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 879 | |
| 880 | /* |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 881 | * N_Port ID cannot be 0, set our Id to LocalID |
| 882 | * the other side will be RemoteID. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 883 | */ |
| 884 | |
| 885 | /* not equal */ |
| 886 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 887 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 888 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 889 | /* Decrement ndlp reference count indicating that ndlp can be |
| 890 | * safely released when other references to it are done. |
| 891 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 892 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 893 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 894 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 895 | if (!ndlp) { |
| 896 | /* |
| 897 | * Cannot find existing Fabric ndlp, so allocate a |
| 898 | * new one |
| 899 | */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 900 | ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 901 | if (!ndlp) |
| 902 | goto fail; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 903 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 904 | ndlp = lpfc_enable_node(vport, ndlp, |
| 905 | NLP_STE_UNUSED_NODE); |
| 906 | if(!ndlp) |
| 907 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 911 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 912 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 913 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 914 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 915 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 916 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 917 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 918 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 919 | } else |
| 920 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 921 | * count indicating that ndlp can be released when other |
| 922 | * references to it are done. |
| 923 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 924 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 925 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 926 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 927 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 928 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 929 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 930 | if (!mbox) |
| 931 | goto fail; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 932 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 933 | lpfc_config_link(phba, mbox); |
| 934 | |
| 935 | mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
| 936 | mbox->vport = vport; |
| 937 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 938 | if (rc == MBX_NOT_FINISHED) { |
| 939 | mempool_free(mbox, phba->mbox_mem_pool); |
| 940 | goto fail; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 941 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 942 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 943 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 944 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 945 | return -ENXIO; |
| 946 | } |
| 947 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 948 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 949 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 950 | * @phba: pointer to lpfc hba data structure. |
| 951 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 952 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 953 | * |
| 954 | * This routine is the top-level completion callback function for issuing |
| 955 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 956 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 957 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 958 | * returning 1), the command IOCB will be released and function returned. |
| 959 | * If the retry attempt has been given up (possibly reach the maximum |
| 960 | * number of retries), one additional decrement of ndlp reference shall be |
| 961 | * invoked before going out after releasing the command IOCB. This will |
| 962 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 963 | * invoke one decrement of ndlp reference count). If no error reported in |
| 964 | * the IOCB status, the command Port ID field is used to determine whether |
| 965 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 966 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 967 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 968 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 969 | * specific topology completion conditions. |
| 970 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 971 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 972 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 973 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 974 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 975 | struct lpfc_vport *vport = cmdiocb->vport; |
| 976 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 977 | IOCB_t *irsp = &rspiocb->iocb; |
| 978 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 979 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 980 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 981 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 982 | int rc; |
| 983 | |
| 984 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 985 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 986 | /* One additional decrement on node reference count to |
| 987 | * trigger the release of the node |
| 988 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 989 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 990 | goto out; |
| 991 | } |
| 992 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 993 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 994 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 995 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 996 | vport->port_state); |
| 997 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 998 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 999 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1000 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1001 | * due to new FCF discovery |
| 1002 | */ |
| 1003 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1004 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 1005 | if (phba->link_state < LPFC_LINK_UP) |
| 1006 | goto stop_rr_fcf_flogi; |
| 1007 | if ((phba->fcoe_cvl_eventtag_attn == |
| 1008 | phba->fcoe_cvl_eventtag) && |
| 1009 | (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1010 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1011 | IOERR_SLI_ABORTED)) |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1012 | goto stop_rr_fcf_flogi; |
| 1013 | else |
| 1014 | phba->fcoe_cvl_eventtag_attn = |
| 1015 | phba->fcoe_cvl_eventtag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1016 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1017 | "2611 FLOGI failed on FCF (x%x), " |
| 1018 | "status:x%x/x%x, tmo:x%x, perform " |
| 1019 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1020 | phba->fcf.current_rec.fcf_indx, |
| 1021 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1022 | irsp->ulpTimeout); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1023 | lpfc_sli4_set_fcf_flogi_fail(phba, |
| 1024 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1025 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1026 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 1027 | if (rc) |
| 1028 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1029 | } |
| 1030 | |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1031 | stop_rr_fcf_flogi: |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1032 | /* FLOGI failure */ |
| 1033 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1034 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x " |
| 1035 | "Data x%x x%x\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1036 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1037 | irsp->ulpTimeout, phba->hba_flag, |
| 1038 | phba->fcf.fcf_flag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1039 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1040 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1041 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1042 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1043 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1044 | /* FLOGI failure */ |
| 1045 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1046 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 1047 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1048 | irsp->ulpTimeout); |
| 1049 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1050 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1051 | spin_lock_irq(shost->host_lock); |
| 1052 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 1053 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1054 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1055 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1056 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 1057 | * alpa map would take too long otherwise. |
| 1058 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1059 | if (phba->alpa_map[0] == 0) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1060 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1061 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1062 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1063 | (vport->fc_prevDID != vport->fc_myDID) || |
| 1064 | phba->fc_topology_changed)) { |
| 1065 | if (vport->fc_flag & FC_VFI_REGISTERED) { |
| 1066 | if (phba->fc_topology_changed) { |
| 1067 | lpfc_unregister_fcf_prep(phba); |
| 1068 | spin_lock_irq(shost->host_lock); |
| 1069 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 1070 | spin_unlock_irq(shost->host_lock); |
| 1071 | phba->fc_topology_changed = 0; |
| 1072 | } else { |
| 1073 | lpfc_sli4_unreg_all_rpis(vport); |
| 1074 | } |
| 1075 | } |
James Smart | 342b59c | 2016-03-31 14:12:31 -0700 | [diff] [blame] | 1076 | |
| 1077 | /* Do not register VFI if the driver aborted FLOGI */ |
| 1078 | if (!lpfc_error_lost_link(irsp)) |
| 1079 | lpfc_issue_reg_vfi(vport); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1080 | lpfc_nlp_put(ndlp); |
| 1081 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1082 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1083 | goto flogifail; |
| 1084 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1085 | spin_lock_irq(shost->host_lock); |
| 1086 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 1087 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1088 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1089 | |
| 1090 | /* |
| 1091 | * The FLogI succeeded. Sync the data for the CPU before |
| 1092 | * accessing it. |
| 1093 | */ |
| 1094 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 1095 | if (!prsp) |
| 1096 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1097 | sp = prsp->virt + sizeof(uint32_t); |
| 1098 | |
| 1099 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1100 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 1101 | "0101 FLOGI completes successfully, I/O tag:x%x, " |
| 1102 | "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] | 1103 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1104 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution, |
| 1105 | vport->port_state, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1106 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1107 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1108 | /* |
| 1109 | * If Common Service Parameters indicate Nport |
| 1110 | * we are point to point, if Fport we are Fabric. |
| 1111 | */ |
| 1112 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1113 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1114 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1115 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1116 | else { |
| 1117 | lpfc_printf_vlog(vport, KERN_ERR, |
| 1118 | LOG_FIP | LOG_ELS, |
| 1119 | "2831 FLOGI response with cleared Fabric " |
| 1120 | "bit fcf_index 0x%x " |
| 1121 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 1122 | "Fabric Name " |
| 1123 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 1124 | phba->fcf.current_rec.fcf_indx, |
| 1125 | phba->fcf.current_rec.switch_name[0], |
| 1126 | phba->fcf.current_rec.switch_name[1], |
| 1127 | phba->fcf.current_rec.switch_name[2], |
| 1128 | phba->fcf.current_rec.switch_name[3], |
| 1129 | phba->fcf.current_rec.switch_name[4], |
| 1130 | phba->fcf.current_rec.switch_name[5], |
| 1131 | phba->fcf.current_rec.switch_name[6], |
| 1132 | phba->fcf.current_rec.switch_name[7], |
| 1133 | phba->fcf.current_rec.fabric_name[0], |
| 1134 | phba->fcf.current_rec.fabric_name[1], |
| 1135 | phba->fcf.current_rec.fabric_name[2], |
| 1136 | phba->fcf.current_rec.fabric_name[3], |
| 1137 | phba->fcf.current_rec.fabric_name[4], |
| 1138 | phba->fcf.current_rec.fabric_name[5], |
| 1139 | phba->fcf.current_rec.fabric_name[6], |
| 1140 | phba->fcf.current_rec.fabric_name[7]); |
| 1141 | lpfc_nlp_put(ndlp); |
| 1142 | spin_lock_irq(&phba->hbalock); |
| 1143 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1144 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1145 | spin_unlock_irq(&phba->hbalock); |
| 1146 | goto out; |
| 1147 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1148 | if (!rc) { |
| 1149 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1150 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 1151 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 1152 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1153 | "2769 FLOGI to FCF (x%x) " |
| 1154 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1155 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1156 | spin_lock_irq(&phba->hbalock); |
| 1157 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1158 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1159 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1160 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1161 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | flogifail: |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1165 | spin_lock_irq(&phba->hbalock); |
| 1166 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 1167 | spin_unlock_irq(&phba->hbalock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1168 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1169 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1170 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1171 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1172 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1173 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1174 | |
| 1175 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1176 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1177 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1178 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1179 | IOERR_SLI_ABORTED) && |
| 1180 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1181 | IOERR_SLI_DOWN))) && |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1182 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 1183 | /* If FLOGI failed enable link interrupt. */ |
| 1184 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1185 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1186 | out: |
| 1187 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1188 | } |
| 1189 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1190 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1191 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1192 | * @vport: pointer to a host virtual N_Port data structure. |
| 1193 | * @ndlp: pointer to a node-list data structure. |
| 1194 | * @retry: number of retries to the command IOCB. |
| 1195 | * |
| 1196 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 1197 | * for a @vport. The initiator service parameters are put into the payload |
| 1198 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 1199 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 1200 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 1201 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 1202 | * |
| 1203 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1204 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1205 | * will be stored into the context1 field of the IOCB for the completion |
| 1206 | * callback function to the FLOGI ELS command. |
| 1207 | * |
| 1208 | * Return code |
| 1209 | * 0 - successfully issued flogi iocb for @vport |
| 1210 | * 1 - failed to issue flogi iocb for @vport |
| 1211 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1212 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1213 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1214 | uint8_t retry) |
| 1215 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1216 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1217 | struct serv_parm *sp; |
| 1218 | IOCB_t *icmd; |
| 1219 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1220 | uint8_t *pcmd; |
| 1221 | uint16_t cmdsize; |
| 1222 | uint32_t tmo; |
| 1223 | int rc; |
| 1224 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1225 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1226 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1227 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1228 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1229 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1230 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1231 | |
| 1232 | icmd = &elsiocb->iocb; |
| 1233 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1234 | |
| 1235 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1236 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1237 | pcmd += sizeof(uint32_t); |
| 1238 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1239 | sp = (struct serv_parm *) pcmd; |
| 1240 | |
| 1241 | /* Setup CSPs accordingly for Fabric */ |
| 1242 | sp->cmn.e_d_tov = 0; |
| 1243 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 1244 | sp->cmn.virtual_fabric_support = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1245 | sp->cls1.classValid = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1246 | if (sp->cmn.fcphLow < FC_PH3) |
| 1247 | sp->cmn.fcphLow = FC_PH3; |
| 1248 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1249 | sp->cmn.fcphHigh = FC_PH3; |
| 1250 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 1251 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1252 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1253 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 1254 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1255 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1256 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1257 | /* Set the fcfi to the fcfi we registered with */ |
| 1258 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1259 | } |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1260 | /* Can't do SLI4 class2 without support sequence coalescing */ |
| 1261 | sp->cls2.classValid = 0; |
| 1262 | sp->cls2.seqDelivery = 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1263 | } else { |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1264 | /* Historical, setting sequential-delivery bit for SLI3 */ |
| 1265 | sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; |
| 1266 | sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1267 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 1268 | sp->cmn.request_multiple_Nport = 1; |
| 1269 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1270 | icmd->ulpCt_h = 1; |
| 1271 | icmd->ulpCt_l = 0; |
| 1272 | } else |
| 1273 | sp->cmn.request_multiple_Nport = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1274 | } |
| 1275 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1276 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1277 | icmd->un.elsreq64.myID = 0; |
| 1278 | icmd->un.elsreq64.fl = 1; |
| 1279 | } |
| 1280 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1281 | tmo = phba->fc_ratov; |
| 1282 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1283 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1284 | phba->fc_ratov = tmo; |
| 1285 | |
| 1286 | phba->fc_stat.elsXmitFLOGI++; |
| 1287 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1288 | |
| 1289 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1290 | "Issue FLOGI: opt:x%x", |
| 1291 | phba->sli3_options, 0, 0); |
| 1292 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1293 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1294 | if (rc == IOCB_ERROR) { |
| 1295 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1296 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1297 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1298 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1299 | } |
| 1300 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1301 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1302 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1303 | * @phba: pointer to lpfc hba data structure. |
| 1304 | * |
| 1305 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1306 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1307 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1308 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1309 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1310 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1311 | * |
| 1312 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1313 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1314 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1315 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1316 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1317 | { |
| 1318 | struct lpfc_sli_ring *pring; |
| 1319 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1320 | struct lpfc_nodelist *ndlp; |
| 1321 | IOCB_t *icmd; |
| 1322 | |
| 1323 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1324 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1325 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1326 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1327 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1328 | pring = lpfc_phba_elsring(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1329 | |
| 1330 | /* |
| 1331 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1332 | * searching for. |
| 1333 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1334 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1336 | icmd = &iocb->iocb; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1337 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1338 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1339 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1340 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1341 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1342 | } |
| 1343 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1344 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1345 | |
| 1346 | return 0; |
| 1347 | } |
| 1348 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1349 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1350 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1351 | * @vport: pointer to a host virtual N_Port data structure. |
| 1352 | * |
| 1353 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1354 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1355 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1356 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1357 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1358 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1359 | * @vport. |
| 1360 | * |
| 1361 | * Return code |
| 1362 | * 0 - failed to issue initial flogi for @vport |
| 1363 | * 1 - successfully issued initial flogi for @vport |
| 1364 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1365 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1366 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1367 | { |
| 1368 | struct lpfc_nodelist *ndlp; |
| 1369 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1370 | vport->port_state = LPFC_FLOGI; |
| 1371 | lpfc_set_disctmo(vport); |
| 1372 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1373 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1374 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1375 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1376 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1377 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1378 | if (!ndlp) |
| 1379 | return 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1380 | /* Set the node type */ |
| 1381 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1382 | /* Put ndlp onto node list */ |
| 1383 | lpfc_enqueue_node(vport, ndlp); |
| 1384 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1385 | /* re-setup ndlp without removing from node list */ |
| 1386 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1387 | if (!ndlp) |
| 1388 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1389 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1390 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1391 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1392 | /* This decrement of reference count to node shall kick off |
| 1393 | * the release of the node. |
| 1394 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1395 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1396 | return 0; |
| 1397 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1398 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1399 | } |
| 1400 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1401 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1402 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1403 | * @vport: pointer to a host virtual N_Port data structure. |
| 1404 | * |
| 1405 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1406 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1407 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1408 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1409 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1410 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1411 | * @vport. |
| 1412 | * |
| 1413 | * Return code |
| 1414 | * 0 - failed to issue initial fdisc for @vport |
| 1415 | * 1 - successfully issued initial fdisc for @vport |
| 1416 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1417 | int |
| 1418 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1419 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1420 | struct lpfc_nodelist *ndlp; |
| 1421 | |
| 1422 | /* First look for the Fabric ndlp */ |
| 1423 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1424 | if (!ndlp) { |
| 1425 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1426 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1427 | if (!ndlp) |
| 1428 | return 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1429 | /* Put ndlp onto node list */ |
| 1430 | lpfc_enqueue_node(vport, ndlp); |
| 1431 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1432 | /* re-setup ndlp without removing from node list */ |
| 1433 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1434 | if (!ndlp) |
| 1435 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1436 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1437 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1438 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1439 | /* decrement node reference count to trigger the release of |
| 1440 | * the node. |
| 1441 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1442 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1443 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1444 | } |
| 1445 | return 1; |
| 1446 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1447 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1448 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1449 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1450 | * @vport: pointer to a host virtual N_Port data structure. |
| 1451 | * |
| 1452 | * This routine checks whether there are more remaining Port Logins |
| 1453 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1454 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1455 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1456 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1457 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1458 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1459 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1460 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1462 | if (vport->num_disc_nodes) |
| 1463 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1464 | |
| 1465 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1466 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1467 | "0232 Continue discovery with %d PLOGIs to go " |
| 1468 | "Data: x%x x%x x%x\n", |
| 1469 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1470 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1471 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1472 | if (vport->fc_flag & FC_NLP_MORE) |
| 1473 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 1474 | lpfc_els_disc_plogi(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1475 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1476 | return; |
| 1477 | } |
| 1478 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1479 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1480 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1481 | * @phba: pointer to lpfc hba data structure. |
| 1482 | * @prsp: pointer to response IOCB payload. |
| 1483 | * @ndlp: pointer to a node-list data structure. |
| 1484 | * |
| 1485 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1486 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1487 | * The following cases are considered N_Port confirmed: |
| 1488 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1489 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1490 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1491 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1492 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1493 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1494 | * on that node to release the RPI associated with the node; 2) if there is |
| 1495 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1496 | * into, a new node shall be allocated (or activated). In either case, the |
| 1497 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1498 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1499 | * its pointer returned as the confirmed node. |
| 1500 | * |
| 1501 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1502 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1503 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1504 | * into an inactive state on the vport node list and the vport node list |
| 1505 | * management algorithm does not allow two node with a same DID. |
| 1506 | * |
| 1507 | * Return code |
| 1508 | * pointer to the PLOGI N_Port @ndlp |
| 1509 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1510 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1511 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1512 | struct lpfc_nodelist *ndlp) |
| 1513 | { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1514 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1515 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1516 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1517 | struct lpfc_rport_data *rdata; |
| 1518 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1519 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1520 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1521 | uint32_t rc, keepDID = 0, keep_nlp_flag = 0; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1522 | uint16_t keep_nlp_state; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1523 | int put_node; |
| 1524 | int put_rport; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1525 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1526 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1527 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1528 | * by WWPN. Just return the ndlp that was given to us. |
| 1529 | */ |
| 1530 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1531 | return ndlp; |
| 1532 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1533 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1534 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1535 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1536 | /* 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] | 1537 | * we have for that ndlp. If not, we have some work to do. |
| 1538 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1539 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1540 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1541 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1542 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1543 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1544 | active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool, |
| 1545 | GFP_KERNEL); |
| 1546 | if (active_rrqs_xri_bitmap) |
| 1547 | memset(active_rrqs_xri_bitmap, 0, |
| 1548 | phba->cfg_rrq_xri_bitmap_sz); |
| 1549 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1550 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1551 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1552 | "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n", |
| 1553 | ndlp, ndlp->nlp_DID, new_ndlp); |
| 1554 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1555 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1556 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1557 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1558 | if (!rc) { |
| 1559 | if (active_rrqs_xri_bitmap) |
| 1560 | mempool_free(active_rrqs_xri_bitmap, |
| 1561 | phba->active_rrq_pool); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1562 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1563 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1564 | new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1565 | if (!new_ndlp) { |
| 1566 | if (active_rrqs_xri_bitmap) |
| 1567 | mempool_free(active_rrqs_xri_bitmap, |
| 1568 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1569 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1570 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1571 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1572 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1573 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1574 | if (!rc) { |
| 1575 | if (active_rrqs_xri_bitmap) |
| 1576 | mempool_free(active_rrqs_xri_bitmap, |
| 1577 | phba->active_rrq_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1578 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1579 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1580 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1581 | NLP_STE_UNUSED_NODE); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1582 | if (!new_ndlp) { |
| 1583 | if (active_rrqs_xri_bitmap) |
| 1584 | mempool_free(active_rrqs_xri_bitmap, |
| 1585 | phba->active_rrq_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1586 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1587 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1588 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1589 | if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap) |
| 1590 | memcpy(active_rrqs_xri_bitmap, |
| 1591 | new_ndlp->active_rrqs_xri_bitmap, |
| 1592 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1593 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1594 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1595 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1596 | active_rrqs_xri_bitmap) |
| 1597 | memcpy(active_rrqs_xri_bitmap, |
| 1598 | new_ndlp->active_rrqs_xri_bitmap, |
| 1599 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1600 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1601 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1602 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1603 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1604 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1605 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1606 | memcpy(new_ndlp->active_rrqs_xri_bitmap, |
| 1607 | ndlp->active_rrqs_xri_bitmap, |
| 1608 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1609 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1610 | spin_lock_irq(shost->host_lock); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1611 | keep_nlp_flag = new_ndlp->nlp_flag; |
| 1612 | new_ndlp->nlp_flag = ndlp->nlp_flag; |
| 1613 | ndlp->nlp_flag = keep_nlp_flag; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1614 | spin_unlock_irq(shost->host_lock); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1615 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1616 | /* Set nlp_states accordingly */ |
| 1617 | keep_nlp_state = new_ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1618 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1619 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1620 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1621 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1622 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1623 | * to put ndlp on UNUSED list and try to free it. |
| 1624 | */ |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1625 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1626 | "3179 PLOGI confirm NEW: %x %x\n", |
| 1627 | new_ndlp->nlp_DID, keepDID); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1628 | |
| 1629 | /* Fix up the rport accordingly */ |
| 1630 | rport = ndlp->rport; |
| 1631 | if (rport) { |
| 1632 | rdata = rport->dd_data; |
| 1633 | if (rdata->pnode == ndlp) { |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1634 | /* break the link before dropping the ref */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1635 | ndlp->rport = NULL; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1636 | lpfc_nlp_put(ndlp); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1637 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1638 | new_ndlp->rport = rport; |
| 1639 | } |
| 1640 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1641 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1642 | /* We shall actually free the ndlp with both nlp_DID and |
| 1643 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1644 | * nodelist never to be used. |
| 1645 | */ |
| 1646 | if (ndlp->nlp_DID == 0) { |
| 1647 | spin_lock_irq(&phba->ndlp_lock); |
| 1648 | NLP_SET_FREE_REQ(ndlp); |
| 1649 | spin_unlock_irq(&phba->ndlp_lock); |
| 1650 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1651 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1652 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1653 | ndlp->nlp_DID = keepDID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1654 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1655 | active_rrqs_xri_bitmap) |
| 1656 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1657 | active_rrqs_xri_bitmap, |
| 1658 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1659 | |
| 1660 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 1661 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1662 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1663 | else { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1664 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1665 | "3180 PLOGI confirm SWAP: %x %x\n", |
| 1666 | new_ndlp->nlp_DID, keepDID); |
| 1667 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1668 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1669 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1670 | /* Two ndlps cannot have the same did */ |
| 1671 | ndlp->nlp_DID = keepDID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1672 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1673 | active_rrqs_xri_bitmap) |
| 1674 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1675 | active_rrqs_xri_bitmap, |
| 1676 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1677 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1678 | /* Since we are switching over to the new_ndlp, |
| 1679 | * reset the old ndlp state |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1680 | */ |
| 1681 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 1682 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1683 | keep_nlp_state = NLP_STE_NPR_NODE; |
| 1684 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1685 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1686 | /* Fix up the rport accordingly */ |
| 1687 | rport = ndlp->rport; |
| 1688 | if (rport) { |
| 1689 | rdata = rport->dd_data; |
| 1690 | put_node = rdata->pnode != NULL; |
| 1691 | put_rport = ndlp->rport != NULL; |
| 1692 | rdata->pnode = NULL; |
| 1693 | ndlp->rport = NULL; |
| 1694 | if (put_node) |
| 1695 | lpfc_nlp_put(ndlp); |
| 1696 | if (put_rport) |
| 1697 | put_device(&rport->dev); |
| 1698 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1699 | } |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1700 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1701 | active_rrqs_xri_bitmap) |
| 1702 | mempool_free(active_rrqs_xri_bitmap, |
| 1703 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1704 | return new_ndlp; |
| 1705 | } |
| 1706 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1707 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1708 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1709 | * @vport: pointer to a host virtual N_Port data structure. |
| 1710 | * |
| 1711 | * This routine checks whether more Registration State Change |
| 1712 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1713 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1714 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1715 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1716 | * handling the RSCNs. |
| 1717 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1718 | void |
| 1719 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1720 | { |
| 1721 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1722 | |
| 1723 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1724 | /* |
| 1725 | * Check to see if more RSCNs came in while we were |
| 1726 | * processing this one. |
| 1727 | */ |
| 1728 | if (vport->fc_rscn_id_cnt || |
| 1729 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1730 | lpfc_els_handle_rscn(vport); |
| 1731 | else { |
| 1732 | spin_lock_irq(shost->host_lock); |
| 1733 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1734 | spin_unlock_irq(shost->host_lock); |
| 1735 | } |
| 1736 | } |
| 1737 | } |
| 1738 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1739 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1740 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. |
| 1741 | * @phba: pointer to lpfc hba data structure. |
| 1742 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1743 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1744 | * |
| 1745 | * This routine will call the clear rrq function to free the rrq and |
| 1746 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not |
| 1747 | * exist then the clear_rrq is still called because the rrq needs to |
| 1748 | * be freed. |
| 1749 | **/ |
| 1750 | |
| 1751 | static void |
| 1752 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1753 | struct lpfc_iocbq *rspiocb) |
| 1754 | { |
| 1755 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1756 | IOCB_t *irsp; |
| 1757 | struct lpfc_nodelist *ndlp; |
| 1758 | struct lpfc_node_rrq *rrq; |
| 1759 | |
| 1760 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1761 | rrq = cmdiocb->context_un.rrq; |
| 1762 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1763 | |
| 1764 | irsp = &rspiocb->iocb; |
| 1765 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1766 | "RRQ cmpl: status:x%x/x%x did:x%x", |
| 1767 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1768 | irsp->un.elsreq64.remoteID); |
| 1769 | |
| 1770 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
| 1771 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { |
| 1772 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1773 | "2882 RRQ completes to NPort x%x " |
| 1774 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1775 | irsp->un.elsreq64.remoteID, |
| 1776 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1777 | irsp->ulpIoTag); |
| 1778 | goto out; |
| 1779 | } |
| 1780 | |
| 1781 | /* rrq completes to NPort <nlp_DID> */ |
| 1782 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1783 | "2880 RRQ completes to NPort x%x " |
| 1784 | "Data: x%x x%x x%x x%x x%x\n", |
| 1785 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1786 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); |
| 1787 | |
| 1788 | if (irsp->ulpStatus) { |
| 1789 | /* Check for retry */ |
| 1790 | /* RRQ failed Don't print the vport to vport rjts */ |
| 1791 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1792 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1793 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1794 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1795 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1796 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", |
| 1797 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1798 | irsp->un.ulpWord[4]); |
| 1799 | } |
| 1800 | out: |
| 1801 | if (rrq) |
| 1802 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1803 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1804 | return; |
| 1805 | } |
| 1806 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1807 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1808 | * @phba: pointer to lpfc hba data structure. |
| 1809 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1810 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1811 | * |
| 1812 | * This routine is the completion callback function for issuing the Port |
| 1813 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1814 | * 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] | 1815 | * 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] | 1816 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1817 | * checked for error conditons. If there is error status reported, PLOGI |
| 1818 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1819 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1820 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1821 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1822 | * there are additional N_Port nodes with the vport that need to perform |
| 1823 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1824 | * PLOGIs. |
| 1825 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1826 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1827 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1828 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1829 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1830 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1831 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1832 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1833 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1834 | struct lpfc_dmabuf *prsp; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 1835 | int disc, rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1836 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1837 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1838 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1839 | |
| 1840 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1841 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1842 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1843 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1844 | irsp->un.elsreq64.remoteID); |
| 1845 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1846 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1847 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1848 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1849 | "0136 PLOGI completes to NPort x%x " |
| 1850 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1851 | irsp->un.elsreq64.remoteID, |
| 1852 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1853 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1854 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1855 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1856 | |
| 1857 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1858 | * is being used during discovery. |
| 1859 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1860 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1861 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1862 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1863 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1864 | rc = 0; |
| 1865 | |
| 1866 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1867 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1868 | "0102 PLOGI completes to NPort x%06x " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1869 | "Data: x%x x%x x%x x%x x%x\n", |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1870 | ndlp->nlp_DID, ndlp->nlp_fc4_type, |
| 1871 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1872 | disc, vport->num_disc_nodes); |
| 1873 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1874 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1875 | if (lpfc_els_chk_latt(vport)) { |
| 1876 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1877 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1878 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1879 | goto out; |
| 1880 | } |
| 1881 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1882 | if (irsp->ulpStatus) { |
| 1883 | /* Check for retry */ |
| 1884 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1885 | /* ELS command is being retried */ |
| 1886 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1887 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1888 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1889 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1890 | } |
| 1891 | goto out; |
| 1892 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1893 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1894 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1895 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1896 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1897 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1898 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1899 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1900 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1901 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1902 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1903 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1904 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1905 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1906 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1907 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | } else { |
| 1909 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1910 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1911 | cmdiocb->context2)->list.next, |
| 1912 | struct lpfc_dmabuf, list); |
| 1913 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1914 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1915 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1916 | } |
| 1917 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1918 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1919 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1920 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1921 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1922 | if (vport->num_disc_nodes == 0) { |
| 1923 | spin_lock_irq(shost->host_lock); |
| 1924 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1925 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1926 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1927 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1928 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | out: |
| 1933 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1934 | return; |
| 1935 | } |
| 1936 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1937 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1938 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1939 | * @vport: pointer to a host virtual N_Port data structure. |
| 1940 | * @did: destination port identifier. |
| 1941 | * @retry: number of retries to the command IOCB. |
| 1942 | * |
| 1943 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1944 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1945 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1946 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1947 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1948 | * |
| 1949 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1950 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1951 | * will be stored into the context1 field of the IOCB for the completion |
| 1952 | * callback function to the PLOGI ELS command. |
| 1953 | * |
| 1954 | * Return code |
| 1955 | * 0 - Successfully issued a plogi for @vport |
| 1956 | * 1 - failed to issue a plogi for @vport |
| 1957 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1958 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1959 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1961 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1962 | struct serv_parm *sp; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1963 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1964 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1965 | uint8_t *pcmd; |
| 1966 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1967 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1968 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1969 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1970 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1971 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1972 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1973 | /* 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] | 1974 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1975 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1976 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1977 | if (!elsiocb) |
| 1978 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1979 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1980 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1981 | |
| 1982 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1983 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1984 | pcmd += sizeof(uint32_t); |
| 1985 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | sp = (struct serv_parm *) pcmd; |
| 1987 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1988 | /* |
| 1989 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 1990 | * to device on remote loops work. |
| 1991 | */ |
| 1992 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 1993 | sp->cmn.altBbCredit = 1; |
| 1994 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1995 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1996 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1997 | |
| 1998 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1999 | sp->cmn.fcphHigh = FC_PH3; |
| 2000 | |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 2001 | sp->cmn.valid_vendor_ver_level = 0; |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2002 | memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 2003 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2004 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2005 | "Issue PLOGI: did:x%x", |
| 2006 | did, 0, 0); |
| 2007 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2008 | /* If our firmware supports this feature, convey that |
| 2009 | * information to the target using the vendor specific field. |
| 2010 | */ |
| 2011 | if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { |
| 2012 | sp->cmn.valid_vendor_ver_level = 1; |
| 2013 | sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); |
| 2014 | sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP); |
| 2015 | } |
| 2016 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2017 | phba->fc_stat.elsXmitPLOGI++; |
| 2018 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2019 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2020 | |
| 2021 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2022 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2023 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2024 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2025 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2026 | } |
| 2027 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2028 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2029 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2030 | * @phba: pointer to lpfc hba data structure. |
| 2031 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2032 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2033 | * |
| 2034 | * This routine is the completion callback function for a Process Login |
| 2035 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 2036 | * status. If there is error status reported, PRLI retry shall be attempted |
| 2037 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 2038 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 2039 | * ndlp to mark the PRLI completion. |
| 2040 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2041 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2042 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2043 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2044 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2045 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2046 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2048 | struct lpfc_nodelist *ndlp; |
| 2049 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2050 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2051 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2052 | |
| 2053 | irsp = &(rspiocb->iocb); |
| 2054 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2055 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2056 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2057 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2058 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2059 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2060 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 2061 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2062 | ndlp->nlp_DID); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2063 | |
| 2064 | /* Ddriver supports multiple FC4 types. Counters matter. */ |
| 2065 | vport->fc_prli_sent--; |
| 2066 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2067 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2068 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2069 | "0103 PRLI completes to NPort x%06x " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2070 | "Data: x%x x%x x%x x%x\n", |
| 2071 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2072 | vport->num_disc_nodes, ndlp->fc4_prli_sent); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2073 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2074 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2075 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | goto out; |
| 2077 | |
| 2078 | if (irsp->ulpStatus) { |
| 2079 | /* Check for retry */ |
| 2080 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2081 | /* ELS command is being retried */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2082 | ndlp->fc4_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2083 | goto out; |
| 2084 | } |
| 2085 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2086 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2087 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 2088 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2089 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2090 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2091 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2093 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2094 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2095 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2096 | } else |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2097 | /* Good status, call state machine. However, if another |
| 2098 | * PRLI is outstanding, don't call the state machine |
| 2099 | * because final disposition to Mapped or Unmapped is |
| 2100 | * completed there. |
| 2101 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2102 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2103 | NLP_EVT_CMPL_PRLI); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2104 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2105 | out: |
| 2106 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2107 | return; |
| 2108 | } |
| 2109 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2110 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2111 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2112 | * @vport: pointer to a host virtual N_Port data structure. |
| 2113 | * @ndlp: pointer to a node-list data structure. |
| 2114 | * @retry: number of retries to the command IOCB. |
| 2115 | * |
| 2116 | * This routine issues a Process Login (PRLI) ELS command for the |
| 2117 | * @vport. The PRLI service parameters are set up in the payload of the |
| 2118 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 2119 | * is put to the IOCB completion callback func field before invoking the |
| 2120 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 2121 | * |
| 2122 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2123 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2124 | * will be stored into the context1 field of the IOCB for the completion |
| 2125 | * callback function to the PRLI ELS command. |
| 2126 | * |
| 2127 | * Return code |
| 2128 | * 0 - successfully issued prli iocb command for @vport |
| 2129 | * 1 - failed to issue prli iocb command for @vport |
| 2130 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2131 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2132 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | uint8_t retry) |
| 2134 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2135 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2136 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | PRLI *npr; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2138 | struct lpfc_nvme_prli *npr_nvme; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2140 | uint8_t *pcmd; |
| 2141 | uint16_t cmdsize; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2142 | u32 local_nlp_type, elscmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2143 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2144 | local_nlp_type = ndlp->nlp_fc4_type; |
| 2145 | |
| 2146 | send_next_prli: |
| 2147 | if (local_nlp_type & NLP_FC4_FCP) { |
| 2148 | /* Payload is 4 + 16 = 20 x14 bytes. */ |
| 2149 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
| 2150 | elscmd = ELS_CMD_PRLI; |
| 2151 | } else if (local_nlp_type & NLP_FC4_NVME) { |
| 2152 | /* Payload is 4 + 20 = 24 x18 bytes. */ |
| 2153 | cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli)); |
| 2154 | elscmd = ELS_CMD_NVMEPRLI; |
| 2155 | } else { |
| 2156 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2157 | "3083 Unknown FC_TYPE x%x ndlp x%06x\n", |
| 2158 | ndlp->nlp_fc4_type, ndlp->nlp_DID); |
| 2159 | return 1; |
| 2160 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2161 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2162 | ndlp->nlp_DID, elscmd); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2163 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2164 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2165 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2167 | |
| 2168 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2169 | memset(pcmd, 0, cmdsize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2170 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2171 | if (local_nlp_type & NLP_FC4_FCP) { |
| 2172 | /* Remainder of payload is FCP PRLI parameter page. |
| 2173 | * Note: this data structure is defined as |
| 2174 | * BE/LE in the structure definition so no |
| 2175 | * byte swap call is made. |
| 2176 | */ |
| 2177 | *((uint32_t *)(pcmd)) = ELS_CMD_PRLI; |
| 2178 | pcmd += sizeof(uint32_t); |
| 2179 | npr = (PRLI *)pcmd; |
| 2180 | |
| 2181 | /* |
| 2182 | * If our firmware version is 3.20 or later, |
| 2183 | * set the following bits for FC-TAPE support. |
| 2184 | */ |
| 2185 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 2186 | npr->ConfmComplAllowed = 1; |
| 2187 | npr->Retry = 1; |
| 2188 | npr->TaskRetryIdReq = 1; |
| 2189 | } |
| 2190 | npr->estabImagePair = 1; |
| 2191 | npr->readXferRdyDis = 1; |
| 2192 | if (vport->cfg_first_burst_size) |
| 2193 | npr->writeXferRdyDis = 1; |
| 2194 | |
| 2195 | /* For FCP support */ |
| 2196 | npr->prliType = PRLI_FCP_TYPE; |
| 2197 | npr->initiatorFunc = 1; |
| 2198 | elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ; |
| 2199 | |
| 2200 | /* Remove FCP type - processed. */ |
| 2201 | local_nlp_type &= ~NLP_FC4_FCP; |
| 2202 | } else if (local_nlp_type & NLP_FC4_NVME) { |
| 2203 | /* Remainder of payload is NVME PRLI parameter page. |
| 2204 | * This data structure is the newer definition that |
| 2205 | * uses bf macros so a byte swap is required. |
| 2206 | */ |
| 2207 | *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI; |
| 2208 | pcmd += sizeof(uint32_t); |
| 2209 | npr_nvme = (struct lpfc_nvme_prli *)pcmd; |
| 2210 | bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); |
| 2211 | bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ |
| 2212 | |
| 2213 | /* Only initiators request first burst. */ |
| 2214 | if ((phba->cfg_nvme_enable_fb) && |
| 2215 | !phba->nvmet_support) |
| 2216 | bf_set(prli_fba, npr_nvme, 1); |
| 2217 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2218 | if (phba->nvmet_support) { |
| 2219 | bf_set(prli_tgt, npr_nvme, 1); |
| 2220 | bf_set(prli_disc, npr_nvme, 1); |
| 2221 | |
| 2222 | } else { |
| 2223 | bf_set(prli_init, npr_nvme, 1); |
| 2224 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2225 | npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); |
| 2226 | npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); |
| 2227 | elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ; |
| 2228 | |
| 2229 | /* Remove NVME type - processed. */ |
| 2230 | local_nlp_type &= ~NLP_FC4_NVME; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2232 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2233 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2234 | "Issue PRLI: did:x%x", |
| 2235 | ndlp->nlp_DID, 0, 0); |
| 2236 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2237 | phba->fc_stat.elsXmitPRLI++; |
| 2238 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2239 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2240 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2241 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2242 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2243 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2244 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2245 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2246 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2247 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2248 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2249 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2250 | |
| 2251 | /* The vport counters are used for lpfc_scan_finished, but |
| 2252 | * the ndlp is used to track outstanding PRLIs for different |
| 2253 | * FC4 types. |
| 2254 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2255 | vport->fc_prli_sent++; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2256 | ndlp->fc4_prli_sent++; |
| 2257 | |
| 2258 | /* The driver supports 2 FC4 types. Make sure |
| 2259 | * a PRLI is issued for all types before exiting. |
| 2260 | */ |
| 2261 | if (local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME)) |
| 2262 | goto send_next_prli; |
| 2263 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2264 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2265 | } |
| 2266 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2267 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2268 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2269 | * @vport: pointer to a host virtual N_Port data structure. |
| 2270 | * |
| 2271 | * This routine performs Registration State Change Notification (RSCN) |
| 2272 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 2273 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 2274 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 2275 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 2276 | * invoked to check and handle possible more RSCN came in during the period |
| 2277 | * of processing the current ones. |
| 2278 | **/ |
| 2279 | static void |
| 2280 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 2281 | { |
| 2282 | lpfc_can_disctmo(vport); |
| 2283 | |
| 2284 | /* RSCN discovery */ |
| 2285 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 2286 | if (vport->fc_npr_cnt) |
| 2287 | if (lpfc_els_disc_plogi(vport)) |
| 2288 | return; |
| 2289 | |
| 2290 | lpfc_end_rscn(vport); |
| 2291 | } |
| 2292 | |
| 2293 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2294 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2295 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 2296 | * |
| 2297 | * This function is called when the final ADISC is completed during discovery. |
| 2298 | * This function handles clearing link attention or issuing reg_vpi depending |
| 2299 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 2300 | * discovery. |
| 2301 | * This function is called with no locks held. |
| 2302 | **/ |
| 2303 | static void |
| 2304 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 2305 | { |
| 2306 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2307 | struct lpfc_hba *phba = vport->phba; |
| 2308 | |
| 2309 | /* |
| 2310 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 2311 | * and continue discovery. |
| 2312 | */ |
| 2313 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2314 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 2315 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | d454c91 | 2014-12-30 12:08:58 -0500 | [diff] [blame] | 2316 | /* The ADISCs are complete. Doesn't matter if they |
| 2317 | * succeeded or failed because the ADISC completion |
| 2318 | * routine guarantees to call the state machine and |
| 2319 | * the RPI is either unregistered (failed ADISC response) |
| 2320 | * or the RPI is still valid and the node is marked |
| 2321 | * mapped for a target. The exchanges should be in the |
| 2322 | * correct state. This code is specific to SLI3. |
| 2323 | */ |
| 2324 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2325 | lpfc_issue_reg_vpi(phba, vport); |
| 2326 | return; |
| 2327 | } |
| 2328 | /* |
| 2329 | * For SLI2, we need to set port_state to READY |
| 2330 | * and continue discovery. |
| 2331 | */ |
| 2332 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2333 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 2334 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2335 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 2336 | vport->num_disc_nodes = 0; |
| 2337 | /* go thru NPR list, issue ELS PLOGIs */ |
| 2338 | if (vport->fc_npr_cnt) |
| 2339 | lpfc_els_disc_plogi(vport); |
| 2340 | if (!vport->num_disc_nodes) { |
| 2341 | spin_lock_irq(shost->host_lock); |
| 2342 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2343 | spin_unlock_irq(shost->host_lock); |
| 2344 | lpfc_can_disctmo(vport); |
| 2345 | lpfc_end_rscn(vport); |
| 2346 | } |
| 2347 | } |
| 2348 | vport->port_state = LPFC_VPORT_READY; |
| 2349 | } else |
| 2350 | lpfc_rscn_disc(vport); |
| 2351 | } |
| 2352 | |
| 2353 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2354 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2355 | * @vport: pointer to a host virtual N_Port data structure. |
| 2356 | * |
| 2357 | * This routine determines whether there are more ndlps on a @vport |
| 2358 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 2359 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 2360 | * remaining nodes which need to have ADISC sent. |
| 2361 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2362 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2363 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2364 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2365 | if (vport->num_disc_nodes) |
| 2366 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2367 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2368 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2369 | "0210 Continue discovery with %d ADISCs to go " |
| 2370 | "Data: x%x x%x x%x\n", |
| 2371 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 2372 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2373 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2374 | if (vport->fc_flag & FC_NLP_MORE) { |
| 2375 | lpfc_set_disctmo(vport); |
| 2376 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 2377 | lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2378 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2379 | if (!vport->num_disc_nodes) |
| 2380 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | return; |
| 2382 | } |
| 2383 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2384 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2385 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2386 | * @phba: pointer to lpfc hba data structure. |
| 2387 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2388 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2389 | * |
| 2390 | * This routine is the completion function for issuing the Address Discover |
| 2391 | * (ADISC) command. It first checks to see whether link went down during |
| 2392 | * the discovery process. If so, the node will be marked as node port |
| 2393 | * recovery for issuing discover IOCB by the link attention handler and |
| 2394 | * exit. Otherwise, the response status is checked. If error was reported |
| 2395 | * in the response status, the ADISC command shall be retried by invoking |
| 2396 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 2397 | * the response status, the state machine is invoked to set transition |
| 2398 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 2399 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2400 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2401 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2402 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2403 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2404 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2405 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2408 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2409 | |
| 2410 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2411 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2412 | |
| 2413 | irsp = &(rspiocb->iocb); |
| 2414 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2415 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2416 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2417 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 2418 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2419 | ndlp->nlp_DID); |
| 2420 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2421 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2422 | * is being used during discovery. |
| 2423 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2424 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2426 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2427 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2428 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2429 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2430 | "0104 ADISC completes to NPort x%x " |
| 2431 | "Data: x%x x%x x%x x%x x%x\n", |
| 2432 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2433 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2434 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2435 | if (lpfc_els_chk_latt(vport)) { |
| 2436 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2438 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2439 | goto out; |
| 2440 | } |
| 2441 | |
| 2442 | if (irsp->ulpStatus) { |
| 2443 | /* Check for retry */ |
| 2444 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2445 | /* ELS command is being retried */ |
| 2446 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2447 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2448 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2449 | spin_unlock_irq(shost->host_lock); |
| 2450 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2451 | } |
| 2452 | goto out; |
| 2453 | } |
| 2454 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2455 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2456 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2457 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2458 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2459 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2460 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2461 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2462 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2463 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2464 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2465 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2466 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2467 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2468 | /* Check to see if there are more ADISCs to be sent */ |
| 2469 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2470 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2471 | out: |
| 2472 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2473 | return; |
| 2474 | } |
| 2475 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2476 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2477 | * 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] | 2478 | * @vport: pointer to a virtual N_Port data structure. |
| 2479 | * @ndlp: pointer to a node-list data structure. |
| 2480 | * @retry: number of retries to the command IOCB. |
| 2481 | * |
| 2482 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2483 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2484 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2485 | * to issue the ADISC ELS command. |
| 2486 | * |
| 2487 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2488 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2489 | * will be stored into the context1 field of the IOCB for the completion |
| 2490 | * callback function to the ADISC ELS command. |
| 2491 | * |
| 2492 | * Return code |
| 2493 | * 0 - successfully issued adisc |
| 2494 | * 1 - failed to issue adisc |
| 2495 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2496 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2497 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2498 | uint8_t retry) |
| 2499 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2500 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2501 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2502 | ADISC *ap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2503 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2504 | uint8_t *pcmd; |
| 2505 | uint16_t cmdsize; |
| 2506 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2507 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2508 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2509 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2510 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2511 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2512 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2513 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2514 | |
| 2515 | /* For ADISC request, remainder of payload is service parameters */ |
| 2516 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2517 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2518 | |
| 2519 | /* Fill in ADISC payload */ |
| 2520 | ap = (ADISC *) pcmd; |
| 2521 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2522 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2523 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2524 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2525 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2526 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2527 | "Issue ADISC: did:x%x", |
| 2528 | ndlp->nlp_DID, 0, 0); |
| 2529 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2530 | phba->fc_stat.elsXmitADISC++; |
| 2531 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2532 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2533 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2534 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2535 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2536 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2537 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2538 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2539 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2540 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2541 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2542 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2543 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2544 | } |
| 2545 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2546 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2547 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2548 | * @phba: pointer to lpfc hba data structure. |
| 2549 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2550 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2551 | * |
| 2552 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2553 | * command. If no error status was reported from the LOGO response, the |
| 2554 | * state machine of the associated ndlp shall be invoked for transition with |
| 2555 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2556 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2557 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2558 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2559 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2560 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2561 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2562 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2563 | struct lpfc_vport *vport = ndlp->vport; |
| 2564 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2565 | IOCB_t *irsp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2566 | struct lpfcMboxq *mbox; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2567 | unsigned long flags; |
| 2568 | uint32_t skip_recovery = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2569 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2570 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2571 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2572 | |
| 2573 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2574 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2575 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2576 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2577 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2578 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2579 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2580 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2581 | ndlp->nlp_DID); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2582 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2583 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2584 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2585 | "0105 LOGO completes to NPort x%x " |
| 2586 | "Data: x%x x%x x%x x%x\n", |
| 2587 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2588 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2589 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2590 | if (lpfc_els_chk_latt(vport)) { |
| 2591 | skip_recovery = 1; |
| 2592 | goto out; |
| 2593 | } |
| 2594 | |
| 2595 | /* Check to see if link went down during discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2596 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2597 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2598 | * which should abort all outstanding IOs. |
| 2599 | */ |
| 2600 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2601 | NLP_EVT_DEVICE_RM); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2602 | skip_recovery = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2603 | goto out; |
| 2604 | } |
| 2605 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2606 | if (irsp->ulpStatus) { |
| 2607 | /* Check for retry */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2608 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | /* ELS command is being retried */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2610 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2611 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2612 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2613 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2614 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2615 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2616 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2617 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2618 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2619 | if (lpfc_error_lost_link(irsp)) { |
| 2620 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | /* Call state machine. This will unregister the rpi if needed. */ |
| 2626 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); |
| 2627 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2628 | out: |
| 2629 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2630 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ |
| 2631 | if ((vport->fc_flag & FC_PT2PT) && |
| 2632 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { |
| 2633 | phba->pport->fc_myDID = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2634 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 2635 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2636 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2637 | if (phba->nvmet_support) |
| 2638 | lpfc_nvmet_update_targetport(phba); |
| 2639 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2640 | lpfc_nvme_update_localport(phba->pport); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2641 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2642 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2643 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2644 | if (mbox) { |
| 2645 | lpfc_config_link(phba, mbox); |
| 2646 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2647 | mbox->vport = vport; |
| 2648 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 2649 | MBX_NOT_FINISHED) { |
| 2650 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2651 | skip_recovery = 1; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2652 | } |
| 2653 | } |
| 2654 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2655 | |
| 2656 | /* |
| 2657 | * If the node is a target, the handling attempts to recover the port. |
| 2658 | * For any other port type, the rpi is unregistered as an implicit |
| 2659 | * LOGO. |
| 2660 | */ |
| 2661 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) { |
| 2662 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 2663 | spin_lock_irqsave(shost->host_lock, flags); |
| 2664 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 2665 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2666 | |
| 2667 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2668 | "3187 LOGO completes to NPort x%x: Start " |
| 2669 | "Recovery Data: x%x x%x x%x x%x\n", |
| 2670 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2671 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 2672 | vport->num_disc_nodes); |
| 2673 | lpfc_disc_start(vport); |
| 2674 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2675 | return; |
| 2676 | } |
| 2677 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2678 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2679 | * 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] | 2680 | * @vport: pointer to a virtual N_Port data structure. |
| 2681 | * @ndlp: pointer to a node-list data structure. |
| 2682 | * @retry: number of retries to the command IOCB. |
| 2683 | * |
| 2684 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2685 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2686 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2687 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2688 | * |
| 2689 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2690 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2691 | * will be stored into the context1 field of the IOCB for the completion |
| 2692 | * callback function to the LOGO ELS command. |
| 2693 | * |
| 2694 | * Return code |
| 2695 | * 0 - successfully issued logo |
| 2696 | * 1 - failed to issue logo |
| 2697 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2698 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2699 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2700 | uint8_t retry) |
| 2701 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2702 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2703 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2704 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2705 | uint8_t *pcmd; |
| 2706 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2707 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2708 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2709 | spin_lock_irq(shost->host_lock); |
| 2710 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2711 | spin_unlock_irq(shost->host_lock); |
| 2712 | return 0; |
| 2713 | } |
| 2714 | spin_unlock_irq(shost->host_lock); |
| 2715 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2716 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2717 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2718 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2719 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2720 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2721 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2722 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2723 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2724 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2725 | |
| 2726 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2727 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2728 | pcmd += sizeof(uint32_t); |
| 2729 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2730 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2731 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2732 | "Issue LOGO: did:x%x", |
| 2733 | ndlp->nlp_DID, 0, 0); |
| 2734 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2735 | /* |
| 2736 | * If we are issuing a LOGO, we may try to recover the remote NPort |
| 2737 | * by issuing a PLOGI later. Even though we issue ELS cmds by the |
| 2738 | * VPI, if we have a valid RPI, and that RPI gets unreg'ed while |
| 2739 | * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI |
| 2740 | * for that ELS cmd. To avoid this situation, lets get rid of the |
| 2741 | * RPI right now, before any ELS cmds are sent. |
| 2742 | */ |
| 2743 | spin_lock_irq(shost->host_lock); |
| 2744 | ndlp->nlp_flag |= NLP_ISSUE_LOGO; |
| 2745 | spin_unlock_irq(shost->host_lock); |
| 2746 | if (lpfc_unreg_rpi(vport, ndlp)) { |
| 2747 | lpfc_els_free_iocb(phba, elsiocb); |
| 2748 | return 0; |
| 2749 | } |
| 2750 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2751 | phba->fc_stat.elsXmitLOGO++; |
| 2752 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2753 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2754 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2755 | ndlp->nlp_flag &= ~NLP_ISSUE_LOGO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2756 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2757 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2758 | |
| 2759 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2760 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2761 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2762 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2763 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2764 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2765 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2766 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2767 | } |
| 2768 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2769 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2770 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2771 | * @phba: pointer to lpfc hba data structure. |
| 2772 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2773 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2774 | * |
| 2775 | * This routine is a generic completion callback function for ELS commands. |
| 2776 | * Specifically, it is the callback function which does not need to perform |
| 2777 | * any command specific operations. It is currently used by the ELS command |
| 2778 | * issuing routines for the ELS State Change Request (SCR), |
| 2779 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2780 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2781 | * certain debug loggings, this callback function simply invokes the |
| 2782 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2783 | * discovery process. |
| 2784 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2785 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2786 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2787 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2788 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2789 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2790 | IOCB_t *irsp; |
| 2791 | |
| 2792 | irsp = &rspiocb->iocb; |
| 2793 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2794 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2795 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2796 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2797 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2798 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2799 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2800 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2801 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2802 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2803 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2804 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2805 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2806 | return; |
| 2807 | } |
| 2808 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2809 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2810 | * 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] | 2811 | * @vport: pointer to a host virtual N_Port data structure. |
| 2812 | * @nportid: N_Port identifier to the remote node. |
| 2813 | * @retry: number of retries to the command IOCB. |
| 2814 | * |
| 2815 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2816 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2817 | * first search the @vport node list to find the matching ndlp. If no such |
| 2818 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2819 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2820 | * routine is invoked to send the SCR IOCB. |
| 2821 | * |
| 2822 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2823 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2824 | * will be stored into the context1 field of the IOCB for the completion |
| 2825 | * callback function to the SCR ELS command. |
| 2826 | * |
| 2827 | * Return code |
| 2828 | * 0 - Successfully issued scr command |
| 2829 | * 1 - Failed to issue scr command |
| 2830 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2831 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2832 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2833 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2834 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2835 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2836 | uint8_t *pcmd; |
| 2837 | uint16_t cmdsize; |
| 2838 | struct lpfc_nodelist *ndlp; |
| 2839 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2840 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2841 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2842 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2843 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 2844 | ndlp = lpfc_nlp_init(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2845 | if (!ndlp) |
| 2846 | return 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2847 | lpfc_enqueue_node(vport, ndlp); |
| 2848 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2849 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2850 | if (!ndlp) |
| 2851 | return 1; |
| 2852 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2853 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2854 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2855 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2856 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2857 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2858 | /* This will trigger the release of the node just |
| 2859 | * allocated |
| 2860 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2861 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2862 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2863 | } |
| 2864 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2865 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2866 | |
| 2867 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2868 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2869 | |
| 2870 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2871 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2872 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2873 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2874 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2875 | "Issue SCR: did:x%x", |
| 2876 | ndlp->nlp_DID, 0, 0); |
| 2877 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2878 | phba->fc_stat.elsXmitSCR++; |
| 2879 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2880 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2881 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2882 | /* The additional lpfc_nlp_put will cause the following |
| 2883 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2884 | * the node. |
| 2885 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2886 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2887 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2888 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2889 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2890 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2891 | * trigger the release of node. |
| 2892 | */ |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 2893 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2894 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2895 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2896 | } |
| 2897 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2898 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2899 | * 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] | 2900 | * @vport: pointer to a host virtual N_Port data structure. |
| 2901 | * @nportid: N_Port identifier to the remote node. |
| 2902 | * @retry: number of retries to the command IOCB. |
| 2903 | * |
| 2904 | * This routine issues a Fibre Channel Address Resolution Response |
| 2905 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2906 | * is passed into the function. It first search the @vport node list to find |
| 2907 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2908 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2909 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2910 | * |
| 2911 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2912 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2913 | * will be stored into the context1 field of the IOCB for the completion |
| 2914 | * callback function to the PARPR ELS command. |
| 2915 | * |
| 2916 | * Return code |
| 2917 | * 0 - Successfully issued farpr command |
| 2918 | * 1 - Failed to issue farpr command |
| 2919 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2920 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2921 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2922 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2923 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2924 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2925 | FARP *fp; |
| 2926 | uint8_t *pcmd; |
| 2927 | uint32_t *lp; |
| 2928 | uint16_t cmdsize; |
| 2929 | struct lpfc_nodelist *ondlp; |
| 2930 | struct lpfc_nodelist *ndlp; |
| 2931 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2932 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2933 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2934 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2935 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 2936 | ndlp = lpfc_nlp_init(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2937 | if (!ndlp) |
| 2938 | return 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2939 | lpfc_enqueue_node(vport, ndlp); |
| 2940 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2941 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2942 | if (!ndlp) |
| 2943 | return 1; |
| 2944 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2945 | |
| 2946 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2947 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2948 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2949 | /* This will trigger the release of the node just |
| 2950 | * allocated |
| 2951 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2952 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2953 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2954 | } |
| 2955 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2956 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2957 | |
| 2958 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2959 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2960 | |
| 2961 | /* Fill in FARPR payload */ |
| 2962 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2963 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2964 | lp = (uint32_t *) pcmd; |
| 2965 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2966 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2967 | fp->Rflags = 0; |
| 2968 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2969 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2970 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2971 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2972 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2973 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2974 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2975 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2976 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2977 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2978 | } |
| 2979 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2980 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2981 | "Issue FARPR: did:x%x", |
| 2982 | ndlp->nlp_DID, 0, 0); |
| 2983 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2984 | phba->fc_stat.elsXmitFARPR++; |
| 2985 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2986 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2987 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2988 | /* The additional lpfc_nlp_put will cause the following |
| 2989 | * lpfc_els_free_iocb routine to trigger the release of |
| 2990 | * the node. |
| 2991 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2992 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2993 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2994 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2995 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2996 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2997 | * trigger the release of the node. |
| 2998 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2999 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3000 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3001 | } |
| 3002 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3003 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3004 | * 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] | 3005 | * @vport: pointer to a host virtual N_Port data structure. |
| 3006 | * @nlp: pointer to a node-list data structure. |
| 3007 | * |
| 3008 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 3009 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 3010 | * removes the ELS retry event if it presents. In addition, if the |
| 3011 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 3012 | * commands are sent for the @vport's nodes that require issuing discovery |
| 3013 | * ADISC. |
| 3014 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3015 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3016 | 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] | 3017 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3018 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3019 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3020 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3021 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 3022 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3023 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3024 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3025 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3026 | del_timer_sync(&nlp->nlp_delayfunc); |
| 3027 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3028 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3029 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3030 | /* Decrement nlp reference count held for the delayed retry */ |
| 3031 | evtp = &nlp->els_retry_evt; |
| 3032 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 3033 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3034 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3035 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3036 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3037 | spin_unlock_irq(shost->host_lock); |
| 3038 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3039 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3040 | /* Check if there are more ADISCs to be sent */ |
| 3041 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3042 | } else { |
| 3043 | /* Check if there are more PLOGIs to be sent */ |
| 3044 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 3045 | if (vport->num_disc_nodes == 0) { |
| 3046 | spin_lock_irq(shost->host_lock); |
| 3047 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3048 | spin_unlock_irq(shost->host_lock); |
| 3049 | lpfc_can_disctmo(vport); |
| 3050 | lpfc_end_rscn(vport); |
| 3051 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3052 | } |
| 3053 | } |
| 3054 | } |
| 3055 | return; |
| 3056 | } |
| 3057 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3058 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3059 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3060 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 3061 | * |
| 3062 | * This routine is invoked by the ndlp delayed-function timer to check |
| 3063 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 3064 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 3065 | * adds the delayed events to the HBA work list and invokes the |
| 3066 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 3067 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 3068 | * the work list to hold reference count of ndlp so that it guarantees the |
| 3069 | * reference to ndlp will still be available when the worker thread gets |
| 3070 | * to the event associated with the ndlp. |
| 3071 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3072 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3073 | lpfc_els_retry_delay(unsigned long ptr) |
| 3074 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3075 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 3076 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3077 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3078 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3079 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3080 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3081 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3083 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3084 | return; |
| 3085 | } |
| 3086 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3087 | /* We need to hold the node by incrementing the reference |
| 3088 | * count until the queued work is done |
| 3089 | */ |
| 3090 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3091 | if (evtp->evt_arg1) { |
| 3092 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 3093 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3094 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3095 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3096 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | return; |
| 3098 | } |
| 3099 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3100 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3101 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3102 | * @ndlp: pointer to a node-list data structure. |
| 3103 | * |
| 3104 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 3105 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 3106 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 3107 | * function according to the delayed ELS command to retry the command. |
| 3108 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3109 | void |
| 3110 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 3111 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3112 | struct lpfc_vport *vport = ndlp->vport; |
| 3113 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3114 | uint32_t cmd, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3115 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3116 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3117 | cmd = ndlp->nlp_last_elscmd; |
| 3118 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3119 | |
| 3120 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3121 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3122 | return; |
| 3123 | } |
| 3124 | |
| 3125 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3126 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 3127 | /* |
| 3128 | * If a discovery event readded nlp_delayfunc after timer |
| 3129 | * firing and before processing the timer, cancel the |
| 3130 | * nlp_delayfunc. |
| 3131 | */ |
| 3132 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3133 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3134 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3135 | |
| 3136 | switch (cmd) { |
| 3137 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3138 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3139 | break; |
| 3140 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3141 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3142 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3143 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3144 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3145 | break; |
| 3146 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3147 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3148 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3149 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3150 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3151 | break; |
| 3152 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3153 | case ELS_CMD_NVMEPRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3154 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3155 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3156 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3157 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3158 | break; |
| 3159 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3160 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3161 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3162 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3163 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3164 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3165 | case ELS_CMD_FDISC: |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3166 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
| 3167 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3168 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3169 | } |
| 3170 | return; |
| 3171 | } |
| 3172 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3173 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3174 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3175 | * @phba: pointer to lpfc hba data structure. |
| 3176 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3177 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3178 | * |
| 3179 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 3180 | * failed. The following ELS IOCBs use this function for retrying the command |
| 3181 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 3182 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 3183 | * returned error status, it makes the decision whether a retry shall be |
| 3184 | * issued for the command, and whether a retry shall be made immediately or |
| 3185 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 3186 | * is called to retry the command. In the later case, the ELS command shall |
| 3187 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 3188 | * ndlp for the delayed command issusing. |
| 3189 | * |
| 3190 | * Return code |
| 3191 | * 0 - No retry of els command is made |
| 3192 | * 1 - Immediate or delayed retry of els command is made |
| 3193 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3194 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3195 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3196 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3197 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3198 | struct lpfc_vport *vport = cmdiocb->vport; |
| 3199 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3200 | IOCB_t *irsp = &rspiocb->iocb; |
| 3201 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3202 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3203 | uint32_t *elscmd; |
| 3204 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3205 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3206 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3207 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3208 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3209 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3210 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3211 | /* Note: context2 may be 0 for internal driver abort |
| 3212 | * of delays ELS command. |
| 3213 | */ |
| 3214 | |
| 3215 | if (pcmd && pcmd->virt) { |
| 3216 | elscmd = (uint32_t *) (pcmd->virt); |
| 3217 | cmd = *elscmd++; |
| 3218 | } |
| 3219 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3220 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3221 | did = ndlp->nlp_DID; |
| 3222 | else { |
| 3223 | /* We should only hit this case for retrying PLOGI */ |
| 3224 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3225 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3226 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 3227 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3228 | return 1; |
| 3229 | } |
| 3230 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3231 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3232 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 3233 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 3234 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3235 | switch (irsp->ulpStatus) { |
| 3236 | case IOSTAT_FCP_RSP_ERROR: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 | break; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3238 | case IOSTAT_REMOTE_STOP: |
| 3239 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3240 | /* This IO was aborted by the target, we don't |
| 3241 | * know the rxid and because we did not send the |
| 3242 | * ABTS we cannot generate and RRQ. |
| 3243 | */ |
| 3244 | lpfc_set_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 3245 | cmdiocb->sli4_lxritag, 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3246 | } |
| 3247 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3248 | case IOSTAT_LOCAL_REJECT: |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3249 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3250 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3251 | if (cmd == ELS_CMD_FLOGI) { |
| 3252 | if (PCI_DEVICE_ID_HORNET == |
| 3253 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3254 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3255 | phba->pport->fc_myDID = 0; |
| 3256 | phba->alpa_map[0] = 0; |
| 3257 | phba->alpa_map[1] = 0; |
| 3258 | } |
| 3259 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3260 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3261 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3262 | retry = 1; |
| 3263 | break; |
| 3264 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3265 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3266 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3267 | "0124 Retry illegal cmd x%x " |
| 3268 | "retry:x%x delay:x%x\n", |
| 3269 | cmd, cmdiocb->retry, delay); |
| 3270 | retry = 1; |
| 3271 | /* All command's retry policy */ |
| 3272 | maxretry = 8; |
| 3273 | if (cmdiocb->retry > 2) |
| 3274 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3275 | break; |
| 3276 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3277 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3278 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3279 | retry = 1; |
| 3280 | if (cmdiocb->retry > 100) |
| 3281 | delay = 100; |
| 3282 | maxretry = 250; |
| 3283 | break; |
| 3284 | |
| 3285 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3286 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3287 | retry = 1; |
| 3288 | break; |
| 3289 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3290 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3291 | case IOERR_INVALID_RPI: |
James Smart | 5b5b36a | 2013-01-03 15:43:19 -0500 | [diff] [blame] | 3292 | if (cmd == ELS_CMD_PLOGI && |
| 3293 | did == NameServer_DID) { |
| 3294 | /* Continue forever if plogi to */ |
| 3295 | /* the nameserver fails */ |
| 3296 | maxretry = 0; |
| 3297 | delay = 100; |
| 3298 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3299 | retry = 1; |
| 3300 | break; |
| 3301 | } |
| 3302 | break; |
| 3303 | |
| 3304 | case IOSTAT_NPORT_RJT: |
| 3305 | case IOSTAT_FABRIC_RJT: |
| 3306 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 3307 | retry = 1; |
| 3308 | break; |
| 3309 | } |
| 3310 | break; |
| 3311 | |
| 3312 | case IOSTAT_NPORT_BSY: |
| 3313 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3314 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3315 | retry = 1; |
| 3316 | break; |
| 3317 | |
| 3318 | case IOSTAT_LS_RJT: |
| 3319 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 3320 | /* Added for Vendor specifc support |
| 3321 | * Just keep retrying for these Rsn / Exp codes |
| 3322 | */ |
| 3323 | switch (stat.un.b.lsRjtRsnCode) { |
| 3324 | case LSRJT_UNABLE_TPC: |
| 3325 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3326 | LSEXP_CMD_IN_PROGRESS) { |
| 3327 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3328 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3329 | maxretry = 48; |
| 3330 | } |
| 3331 | retry = 1; |
| 3332 | break; |
| 3333 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3334 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3335 | LSEXP_CANT_GIVE_DATA) { |
| 3336 | if (cmd == ELS_CMD_PLOGI) { |
| 3337 | delay = 1000; |
| 3338 | maxretry = 48; |
| 3339 | } |
| 3340 | retry = 1; |
| 3341 | break; |
| 3342 | } |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 3343 | if ((cmd == ELS_CMD_PLOGI) || |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3344 | (cmd == ELS_CMD_PRLI) || |
| 3345 | (cmd == ELS_CMD_NVMEPRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3346 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3347 | maxretry = lpfc_max_els_tries + 1; |
| 3348 | retry = 1; |
| 3349 | break; |
| 3350 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3351 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3352 | (cmd == ELS_CMD_FDISC) && |
| 3353 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3354 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3355 | "0125 FDISC Failed (x%x). " |
| 3356 | "Fabric out of resources\n", |
| 3357 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3358 | lpfc_vport_set_state(vport, |
| 3359 | FC_VPORT_NO_FABRIC_RSCS); |
| 3360 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3361 | break; |
| 3362 | |
| 3363 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3364 | if ((cmd == ELS_CMD_PLOGI) || |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3365 | (cmd == ELS_CMD_PRLI) || |
| 3366 | (cmd == ELS_CMD_NVMEPRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3367 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3368 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3369 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3370 | /* FDISC retry policy */ |
| 3371 | maxretry = 48; |
| 3372 | if (cmdiocb->retry >= 32) |
| 3373 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3374 | } |
| 3375 | retry = 1; |
| 3376 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3377 | |
| 3378 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3379 | /* There are some cases where switches return this |
| 3380 | * error when they are not ready and should be returning |
| 3381 | * Logical Busy. We should delay every time. |
| 3382 | */ |
| 3383 | if (cmd == ELS_CMD_FDISC && |
| 3384 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 3385 | maxretry = 3; |
| 3386 | delay = 1000; |
| 3387 | retry = 1; |
| 3388 | break; |
| 3389 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3390 | case LSRJT_PROTOCOL_ERR: |
| 3391 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3392 | (cmd == ELS_CMD_FDISC) && |
| 3393 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 3394 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 3395 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3396 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3397 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3398 | "Fabric Detected Bad WWN\n", |
| 3399 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3400 | lpfc_vport_set_state(vport, |
| 3401 | FC_VPORT_FABRIC_REJ_WWN); |
| 3402 | } |
| 3403 | break; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 3404 | case LSRJT_VENDOR_UNIQUE: |
| 3405 | if ((stat.un.b.vendorUnique == 0x45) && |
| 3406 | (cmd == ELS_CMD_FLOGI)) { |
| 3407 | goto out_retry; |
| 3408 | } |
| 3409 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | } |
| 3411 | break; |
| 3412 | |
| 3413 | case IOSTAT_INTERMED_RSP: |
| 3414 | case IOSTAT_BA_RJT: |
| 3415 | break; |
| 3416 | |
| 3417 | default: |
| 3418 | break; |
| 3419 | } |
| 3420 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3421 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3422 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3423 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3424 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3425 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 3426 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3427 | /* FLOGI retry policy */ |
| 3428 | retry = 1; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3429 | /* retry FLOGI forever */ |
James Smart | 6eae430 | 2015-04-07 15:07:23 -0400 | [diff] [blame] | 3430 | if (phba->link_flag != LS_LOOPBACK_MODE) |
| 3431 | maxretry = 0; |
| 3432 | else |
| 3433 | maxretry = 2; |
| 3434 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3435 | if (cmdiocb->retry >= 100) |
| 3436 | delay = 5000; |
| 3437 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3438 | delay = 1000; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3439 | } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) { |
| 3440 | /* retry FDISCs every second up to devloss */ |
| 3441 | retry = 1; |
| 3442 | maxretry = vport->cfg_devloss_tmo; |
| 3443 | delay = 1000; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3444 | } |
| 3445 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3446 | cmdiocb->retry++; |
| 3447 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3448 | phba->fc_stat.elsRetryExceeded++; |
| 3449 | retry = 0; |
| 3450 | } |
| 3451 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3452 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 3453 | retry = 0; |
| 3454 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 3455 | out_retry: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3456 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3457 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 3458 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 3459 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 3460 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3461 | "2849 Stop retry ELS command " |
| 3462 | "x%x to remote NPORT x%x, " |
| 3463 | "Data: x%x x%x\n", cmd, did, |
| 3464 | cmdiocb->retry, delay); |
| 3465 | return 0; |
| 3466 | } |
| 3467 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3468 | |
| 3469 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3470 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3471 | "0107 Retry ELS command x%x to remote " |
| 3472 | "NPORT x%x Data: x%x x%x\n", |
| 3473 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3474 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3475 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 3476 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3477 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 3478 | IOERR_NO_RESOURCES))) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3479 | /* Don't reset timer for no resources */ |
| 3480 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3481 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3482 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3483 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3484 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3488 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3489 | phba->fc_stat.elsDelayRetry++; |
| 3490 | ndlp->nlp_retry = cmdiocb->retry; |
| 3491 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3492 | /* delay is specified in milliseconds */ |
| 3493 | mod_timer(&ndlp->nlp_delayfunc, |
| 3494 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3495 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3496 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3497 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3498 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3499 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3500 | if ((cmd == ELS_CMD_PRLI) || |
| 3501 | (cmd == ELS_CMD_NVMEPRLI)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3502 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 3503 | NLP_STE_PRLI_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3504 | else |
| 3505 | lpfc_nlp_set_state(vport, ndlp, |
| 3506 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3507 | ndlp->nlp_last_elscmd = cmd; |
| 3508 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3509 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3510 | } |
| 3511 | switch (cmd) { |
| 3512 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3513 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3514 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3515 | case ELS_CMD_FDISC: |
| 3516 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 3517 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3518 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3519 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3520 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3521 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3522 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3523 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3524 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3525 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3526 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3527 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3528 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3529 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3530 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3531 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3532 | case ELS_CMD_NVMEPRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3533 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3534 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 3535 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3536 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3537 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3538 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3539 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3540 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3541 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | } |
| 3543 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3544 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3545 | if (logerr) { |
| 3546 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3547 | "0137 No retry ELS command x%x to remote " |
| 3548 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 3549 | cmd, did, irsp->ulpStatus, |
| 3550 | irsp->un.ulpWord[4]); |
| 3551 | } |
| 3552 | else { |
| 3553 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3554 | "0108 No retry ELS command x%x to remote " |
| 3555 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 3556 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 3557 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3558 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3559 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3560 | } |
| 3561 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3562 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3563 | * 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] | 3564 | * @phba: pointer to lpfc hba data structure. |
| 3565 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3566 | * |
| 3567 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3568 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3569 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3570 | * response of the command IOCB. If so, it will be released before releasing |
| 3571 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3572 | * |
| 3573 | * Return code |
| 3574 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3575 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3576 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3577 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3578 | { |
| 3579 | struct lpfc_dmabuf *buf_ptr; |
| 3580 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3581 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3582 | if (!list_empty(&buf_ptr1->list)) { |
| 3583 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3584 | struct lpfc_dmabuf, |
| 3585 | list); |
| 3586 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3587 | kfree(buf_ptr); |
| 3588 | } |
| 3589 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3590 | kfree(buf_ptr1); |
| 3591 | return 0; |
| 3592 | } |
| 3593 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3594 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3595 | * 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] | 3596 | * @phba: pointer to lpfc hba data structure. |
| 3597 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3598 | * |
| 3599 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3600 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3601 | * pool. |
| 3602 | * |
| 3603 | * Return code |
| 3604 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3605 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3606 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3607 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3608 | { |
| 3609 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3610 | kfree(buf_ptr); |
| 3611 | return 0; |
| 3612 | } |
| 3613 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3614 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3615 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3616 | * @phba: pointer to lpfc hba data structure. |
| 3617 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3618 | * |
| 3619 | * This routine frees a command IOCB and its associated resources. The |
| 3620 | * command IOCB data structure contains the reference to various associated |
| 3621 | * resources, these fields must be set to NULL if the associated reference |
| 3622 | * not present: |
| 3623 | * context1 - reference to ndlp |
| 3624 | * context2 - reference to cmd |
| 3625 | * context2->next - reference to rsp |
| 3626 | * context3 - reference to bpl |
| 3627 | * |
| 3628 | * It first properly decrements the reference count held on ndlp for the |
| 3629 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3630 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3631 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3632 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3633 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3634 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3635 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3636 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3637 | * |
| 3638 | * Return code |
| 3639 | * 0 - Success (currently, always return 0) |
| 3640 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3641 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3642 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3643 | { |
| 3644 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3645 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3646 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3647 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3648 | if (ndlp) { |
| 3649 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3650 | lpfc_nlp_put(ndlp); |
| 3651 | |
| 3652 | /* If the ndlp is not being used by another discovery |
| 3653 | * thread, free it. |
| 3654 | */ |
| 3655 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3656 | /* If ndlp is being used by another discovery |
| 3657 | * thread, just clear NLP_DEFER_RM |
| 3658 | */ |
| 3659 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3660 | } |
| 3661 | } |
| 3662 | else |
| 3663 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3664 | elsiocb->context1 = NULL; |
| 3665 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3666 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3667 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3668 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3669 | /* Firmware could still be in progress of DMAing |
| 3670 | * payload, so don't free data buffer till after |
| 3671 | * a hbeat. |
| 3672 | */ |
| 3673 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3674 | buf_ptr = elsiocb->context2; |
| 3675 | elsiocb->context2 = NULL; |
| 3676 | if (buf_ptr) { |
| 3677 | buf_ptr1 = NULL; |
| 3678 | spin_lock_irq(&phba->hbalock); |
| 3679 | if (!list_empty(&buf_ptr->list)) { |
| 3680 | list_remove_head(&buf_ptr->list, |
| 3681 | buf_ptr1, struct lpfc_dmabuf, |
| 3682 | list); |
| 3683 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3684 | list_add_tail(&buf_ptr1->list, |
| 3685 | &phba->elsbuf); |
| 3686 | phba->elsbuf_cnt++; |
| 3687 | } |
| 3688 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3689 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3690 | phba->elsbuf_cnt++; |
| 3691 | spin_unlock_irq(&phba->hbalock); |
| 3692 | } |
| 3693 | } else { |
| 3694 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3695 | lpfc_els_free_data(phba, buf_ptr1); |
Johannes Thumshirn | 8667f51 | 2017-01-10 12:05:54 +0100 | [diff] [blame] | 3696 | elsiocb->context2 = NULL; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3697 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3698 | } |
| 3699 | |
| 3700 | if (elsiocb->context3) { |
| 3701 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3702 | lpfc_els_free_bpl(phba, buf_ptr); |
Johannes Thumshirn | 8667f51 | 2017-01-10 12:05:54 +0100 | [diff] [blame] | 3703 | elsiocb->context3 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3704 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3705 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3706 | return 0; |
| 3707 | } |
| 3708 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3709 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3710 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3711 | * @phba: pointer to lpfc hba data structure. |
| 3712 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3713 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3714 | * |
| 3715 | * This routine is the completion callback function to the Logout (LOGO) |
| 3716 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3717 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3718 | * release the ndlp if it has the last reference remaining (reference count |
| 3719 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3720 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3721 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3722 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3723 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3724 | * IOCB data structure. |
| 3725 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3726 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3727 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3728 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3729 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3730 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3731 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3732 | IOCB_t *irsp; |
| 3733 | |
| 3734 | irsp = &rspiocb->iocb; |
| 3735 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3736 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3737 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3738 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3739 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3740 | "0109 ACC to LOGO completes to NPort x%x " |
| 3741 | "Data: x%x x%x x%x\n", |
| 3742 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3743 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3744 | |
| 3745 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3746 | /* NPort Recovery mode or node is just allocated */ |
| 3747 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3748 | /* If the ndlp is being used by another discovery |
| 3749 | * thread, just unregister the RPI. |
| 3750 | */ |
| 3751 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3752 | } else { |
| 3753 | /* Indicate the node has already released, should |
| 3754 | * not reference to it from within lpfc_els_free_iocb. |
| 3755 | */ |
| 3756 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3757 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3758 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3759 | |
| 3760 | /* |
| 3761 | * 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] | 3762 | * At this point, the driver is done so release the IOCB |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3763 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3764 | lpfc_els_free_iocb(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3765 | } |
| 3766 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3767 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3768 | * 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] | 3769 | * @phba: pointer to lpfc hba data structure. |
| 3770 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3771 | * |
| 3772 | * This routine is the completion callback function for unregister default |
| 3773 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3774 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3775 | * decrements the ndlp reference count held for this completion callback |
| 3776 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3777 | * whether there is only one reference left on the ndlp. If so, it will |
| 3778 | * perform one more decrement and trigger the release of the ndlp. |
| 3779 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3780 | void |
| 3781 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3782 | { |
| 3783 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3784 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3785 | |
| 3786 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3787 | pmb->context2 = NULL; |
| 3788 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3789 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3790 | kfree(mp); |
| 3791 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3792 | if (ndlp) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3793 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3794 | "0006 rpi%x DID:%x flg:%x %d map:%x %p\n", |
| 3795 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 3796 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3797 | ndlp->nlp_usg_map, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3798 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 3799 | lpfc_nlp_put(ndlp); |
| 3800 | /* This is the end of the default RPI cleanup logic for |
| 3801 | * this ndlp. If no other discovery threads are using |
| 3802 | * this ndlp, free all resources associated with it. |
| 3803 | */ |
| 3804 | lpfc_nlp_not_used(ndlp); |
| 3805 | } else { |
| 3806 | lpfc_drop_node(ndlp->vport, ndlp); |
| 3807 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3808 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3809 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3810 | return; |
| 3811 | } |
| 3812 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3813 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3814 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3815 | * @phba: pointer to lpfc hba data structure. |
| 3816 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3817 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3818 | * |
| 3819 | * This routine is the completion callback function for ELS Response IOCB |
| 3820 | * command. In normal case, this callback function just properly sets the |
| 3821 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3822 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3823 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3824 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3825 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3826 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3827 | * are currently referring it. |
| 3828 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3829 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3830 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3831 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3832 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3833 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3834 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3835 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3836 | IOCB_t *irsp; |
| 3837 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3838 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3839 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3840 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3841 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3842 | irsp = &rspiocb->iocb; |
| 3843 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3844 | if (cmdiocb->context_un.mbox) |
| 3845 | mbox = cmdiocb->context_un.mbox; |
| 3846 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3847 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3848 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3849 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3850 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3851 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3852 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3853 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3854 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3855 | */ |
| 3856 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3857 | ls_rjt = 1; |
| 3858 | } |
| 3859 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3860 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3861 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3862 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3863 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3864 | if (mp) { |
| 3865 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3866 | kfree(mp); |
| 3867 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3868 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3869 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3870 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3871 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3872 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3873 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3874 | /* Indicate the node has already released, |
| 3875 | * should not reference to it from within |
| 3876 | * the routine lpfc_els_free_iocb. |
| 3877 | */ |
| 3878 | cmdiocb->context1 = NULL; |
| 3879 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3880 | goto out; |
| 3881 | } |
| 3882 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3883 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3884 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3885 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3886 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3887 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3888 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3889 | "0110 ELS response tag x%x completes " |
| 3890 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3891 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3892 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3893 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3894 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3895 | if (mbox) { |
| 3896 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3897 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3898 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3899 | /* Increment reference count to ndlp to hold the |
| 3900 | * reference to ndlp for the callback function. |
| 3901 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3902 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3903 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3904 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3905 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3906 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3907 | } |
| 3908 | else { |
| 3909 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3910 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3911 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3912 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3913 | } |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3914 | |
| 3915 | ndlp->nlp_flag |= NLP_REG_LOGIN_SEND; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3916 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3917 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3918 | goto out; |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3919 | |
| 3920 | /* Decrement the ndlp reference count we |
| 3921 | * set for this failed mailbox command. |
| 3922 | */ |
| 3923 | lpfc_nlp_put(ndlp); |
| 3924 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3925 | |
| 3926 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3927 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3928 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3929 | "Data: x%x x%x x%x\n", |
| 3930 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3931 | ndlp->nlp_rpi); |
| 3932 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3933 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3934 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3935 | /* Indicate node has already been released, |
| 3936 | * should not reference to it from within |
| 3937 | * the routine lpfc_els_free_iocb. |
| 3938 | */ |
| 3939 | cmdiocb->context1 = NULL; |
| 3940 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3941 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3942 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3943 | if (!lpfc_error_lost_link(irsp) && |
| 3944 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3945 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3946 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3947 | /* Indicate node has already been |
| 3948 | * released, should not reference |
| 3949 | * to it from within the routine |
| 3950 | * lpfc_els_free_iocb. |
| 3951 | */ |
| 3952 | cmdiocb->context1 = NULL; |
| 3953 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3954 | } |
| 3955 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3956 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3957 | if (mp) { |
| 3958 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3959 | kfree(mp); |
| 3960 | } |
| 3961 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3962 | } |
| 3963 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3964 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3965 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3966 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3967 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3968 | |
| 3969 | /* If the node is not being used by another discovery thread, |
| 3970 | * and we are sending a reject, we are done with it. |
| 3971 | * Release driver reference count here and free associated |
| 3972 | * resources. |
| 3973 | */ |
| 3974 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3975 | if (lpfc_nlp_not_used(ndlp)) |
| 3976 | /* Indicate node has already been released, |
| 3977 | * should not reference to it from within |
| 3978 | * the routine lpfc_els_free_iocb. |
| 3979 | */ |
| 3980 | cmdiocb->context1 = NULL; |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3981 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3982 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3983 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3984 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3985 | return; |
| 3986 | } |
| 3987 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3988 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3989 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3990 | * @vport: pointer to a host virtual N_Port data structure. |
| 3991 | * @flag: the els command code to be accepted. |
| 3992 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3993 | * @ndlp: pointer to a node-list data structure. |
| 3994 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3995 | * |
| 3996 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3997 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3998 | * specific ACC response command to be issued and invokes the |
| 3999 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 4000 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 4001 | * field of the IOCB for the completion callback function to issue the |
| 4002 | * mailbox command to the HBA later when callback is invoked. |
| 4003 | * |
| 4004 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4005 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4006 | * will be stored into the context1 field of the IOCB for the completion |
| 4007 | * callback function to the corresponding response ELS IOCB command. |
| 4008 | * |
| 4009 | * Return code |
| 4010 | * 0 - Successfully issued acc response |
| 4011 | * 1 - Failed to issue acc response |
| 4012 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4013 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4014 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 4015 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4016 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4017 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4018 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4019 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4020 | IOCB_t *icmd; |
| 4021 | IOCB_t *oldcmd; |
| 4022 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4023 | uint8_t *pcmd; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4024 | struct serv_parm *sp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4025 | uint16_t cmdsize; |
| 4026 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4027 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4028 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4029 | oldcmd = &oldiocb->iocb; |
| 4030 | |
| 4031 | switch (flag) { |
| 4032 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4033 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4034 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 4035 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4036 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4037 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4038 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4039 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4040 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4041 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4042 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4043 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4044 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4045 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4046 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4047 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4048 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4049 | |
| 4050 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4051 | "Issue ACC: did:x%x flg:x%x", |
| 4052 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4053 | break; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4054 | case ELS_CMD_FLOGI: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4055 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4056 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4057 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 4058 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4059 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4060 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4061 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4062 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4063 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4064 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4065 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4066 | |
| 4067 | if (mbox) |
| 4068 | elsiocb->context_un.mbox = mbox; |
| 4069 | |
| 4070 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4071 | pcmd += sizeof(uint32_t); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4072 | sp = (struct serv_parm *)pcmd; |
| 4073 | |
| 4074 | if (flag == ELS_CMD_FLOGI) { |
| 4075 | /* Copy the received service parameters back */ |
| 4076 | memcpy(sp, &phba->fc_fabparam, |
| 4077 | sizeof(struct serv_parm)); |
| 4078 | |
| 4079 | /* Clear the F_Port bit */ |
| 4080 | sp->cmn.fPort = 0; |
| 4081 | |
| 4082 | /* Mark all class service parameters as invalid */ |
| 4083 | sp->cls1.classValid = 0; |
| 4084 | sp->cls2.classValid = 0; |
| 4085 | sp->cls3.classValid = 0; |
| 4086 | sp->cls4.classValid = 0; |
| 4087 | |
| 4088 | /* Copy our worldwide names */ |
| 4089 | memcpy(&sp->portName, &vport->fc_sparam.portName, |
| 4090 | sizeof(struct lpfc_name)); |
| 4091 | memcpy(&sp->nodeName, &vport->fc_sparam.nodeName, |
| 4092 | sizeof(struct lpfc_name)); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4093 | } else { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4094 | memcpy(pcmd, &vport->fc_sparam, |
| 4095 | sizeof(struct serv_parm)); |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 4096 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4097 | sp->cmn.valid_vendor_ver_level = 0; |
| 4098 | memset(sp->un.vendorVersion, 0, |
| 4099 | sizeof(sp->un.vendorVersion)); |
| 4100 | |
| 4101 | /* If our firmware supports this feature, convey that |
| 4102 | * info to the target using the vendor specific field. |
| 4103 | */ |
| 4104 | if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { |
| 4105 | sp->cmn.valid_vendor_ver_level = 1; |
| 4106 | sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); |
| 4107 | sp->un.vv.flags = |
| 4108 | cpu_to_be32(LPFC_VV_SUPPRESS_RSP); |
| 4109 | } |
| 4110 | } |
| 4111 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4112 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4113 | "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4114 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4115 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4116 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4117 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4118 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4119 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 4120 | if (!elsiocb) |
| 4121 | return 1; |
| 4122 | |
| 4123 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4124 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4125 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4126 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4127 | |
| 4128 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4129 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4130 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 4131 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 4132 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4133 | |
| 4134 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4135 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 4136 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4137 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4138 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4139 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4140 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4141 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4142 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4143 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 4144 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x " |
| 4145 | "fc_flag x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4146 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4147 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 4148 | ndlp->nlp_rpi, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4149 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4150 | spin_lock_irq(shost->host_lock); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4151 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4152 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND)) |
| 4153 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4154 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4155 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 4156 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4157 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4158 | } |
| 4159 | |
| 4160 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4161 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4162 | if (rc == IOCB_ERROR) { |
| 4163 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4164 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4165 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4166 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4167 | } |
| 4168 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4169 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4170 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4171 | * @vport: pointer to a virtual N_Port data structure. |
| 4172 | * @rejectError: |
| 4173 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4174 | * @ndlp: pointer to a node-list data structure. |
| 4175 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4176 | * |
| 4177 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 4178 | * command. If a @mbox pointer is passed in, it will be put into the |
| 4179 | * context_un.mbox field of the IOCB for the completion callback function |
| 4180 | * to issue to the HBA later. |
| 4181 | * |
| 4182 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4183 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4184 | * will be stored into the context1 field of the IOCB for the completion |
| 4185 | * callback function to the reject response ELS IOCB command. |
| 4186 | * |
| 4187 | * Return code |
| 4188 | * 0 - Successfully issued reject response |
| 4189 | * 1 - Failed to issue reject response |
| 4190 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4191 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4192 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4193 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 4194 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4195 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4196 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4197 | IOCB_t *icmd; |
| 4198 | IOCB_t *oldcmd; |
| 4199 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4200 | uint8_t *pcmd; |
| 4201 | uint16_t cmdsize; |
| 4202 | int rc; |
| 4203 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4204 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4205 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4206 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4207 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4208 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4209 | |
| 4210 | icmd = &elsiocb->iocb; |
| 4211 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4212 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4213 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4215 | |
| 4216 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4217 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4218 | *((uint32_t *) (pcmd)) = rejectError; |
| 4219 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4220 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4221 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4222 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4223 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4224 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4225 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 4226 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4227 | "rpi x%x\n", |
| 4228 | rejectError, elsiocb->iotag, |
| 4229 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 4230 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4231 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4232 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 4233 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 4234 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4235 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4236 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4237 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4238 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4239 | if (rc == IOCB_ERROR) { |
| 4240 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4241 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4242 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4243 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4244 | } |
| 4245 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4246 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4247 | * 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] | 4248 | * @vport: pointer to a virtual N_Port data structure. |
| 4249 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4250 | * @ndlp: pointer to a node-list data structure. |
| 4251 | * |
| 4252 | * This routine prepares and issues an Accept (ACC) response to Address |
| 4253 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 4254 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4255 | * |
| 4256 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4257 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4258 | * will be stored into the context1 field of the IOCB for the completion |
| 4259 | * callback function to the ADISC Accept response ELS IOCB command. |
| 4260 | * |
| 4261 | * Return code |
| 4262 | * 0 - Successfully issued acc adisc response |
| 4263 | * 1 - Failed to issue adisc acc response |
| 4264 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4265 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4266 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 4267 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4268 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4269 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4270 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4271 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4272 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4273 | uint8_t *pcmd; |
| 4274 | uint16_t cmdsize; |
| 4275 | int rc; |
| 4276 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4277 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4278 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4279 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4280 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4281 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4283 | icmd = &elsiocb->iocb; |
| 4284 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4285 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4286 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4287 | |
| 4288 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4289 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4290 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 4291 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 4292 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4293 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4294 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4295 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4296 | |
| 4297 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4298 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4299 | |
| 4300 | ap = (ADISC *) (pcmd); |
| 4301 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4302 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4303 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4304 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4305 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4306 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4307 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 4308 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4309 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4310 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4311 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4312 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4313 | if (rc == IOCB_ERROR) { |
| 4314 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4315 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4316 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4317 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4318 | } |
| 4319 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4320 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4321 | * 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] | 4322 | * @vport: pointer to a virtual N_Port data structure. |
| 4323 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4324 | * @ndlp: pointer to a node-list data structure. |
| 4325 | * |
| 4326 | * This routine prepares and issues an Accept (ACC) response to Process |
| 4327 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 4328 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4329 | * |
| 4330 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4331 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4332 | * will be stored into the context1 field of the IOCB for the completion |
| 4333 | * callback function to the PRLI Accept response ELS IOCB command. |
| 4334 | * |
| 4335 | * Return code |
| 4336 | * 0 - Successfully issued acc prli response |
| 4337 | * 1 - Failed to issue acc prli response |
| 4338 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4339 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4340 | 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] | 4341 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4342 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4343 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | PRLI *npr; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4345 | struct lpfc_nvme_prli *npr_nvme; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4346 | lpfc_vpd_t *vpd; |
| 4347 | IOCB_t *icmd; |
| 4348 | IOCB_t *oldcmd; |
| 4349 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4350 | uint8_t *pcmd; |
| 4351 | uint16_t cmdsize; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4352 | uint32_t prli_fc4_req, *req_payload; |
| 4353 | struct lpfc_dmabuf *req_buf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4354 | int rc; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4355 | u32 elsrspcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4356 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4357 | /* Need the incoming PRLI payload to determine if the ACC is for an |
| 4358 | * FC4 or NVME PRLI type. The PRLI type is at word 1. |
| 4359 | */ |
| 4360 | req_buf = (struct lpfc_dmabuf *)oldiocb->context2; |
| 4361 | req_payload = (((uint32_t *)req_buf->virt) + 1); |
| 4362 | |
| 4363 | /* PRLI type payload is at byte 3 for FCP or NVME. */ |
| 4364 | prli_fc4_req = be32_to_cpu(*req_payload); |
| 4365 | prli_fc4_req = (prli_fc4_req >> 24) & 0xff; |
| 4366 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4367 | "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n", |
| 4368 | prli_fc4_req, *((uint32_t *)req_payload)); |
| 4369 | |
| 4370 | if (prli_fc4_req == PRLI_FCP_TYPE) { |
| 4371 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
| 4372 | elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
| 4373 | } else if (prli_fc4_req & PRLI_NVME_TYPE) { |
| 4374 | cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli); |
| 4375 | elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK)); |
| 4376 | } else { |
| 4377 | return 1; |
| 4378 | } |
| 4379 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4380 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4381 | ndlp->nlp_DID, elsrspcmd); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4382 | if (!elsiocb) |
| 4383 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4384 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4385 | icmd = &elsiocb->iocb; |
| 4386 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4387 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4388 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4389 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4390 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4391 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4392 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 4393 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4394 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4395 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4396 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4397 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4398 | memset(pcmd, 0, cmdsize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4399 | |
James Smart | c07f10c | 2017-04-21 16:04:54 -0700 | [diff] [blame] | 4400 | *((uint32_t *)(pcmd)) = elsrspcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4401 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4402 | |
| 4403 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4404 | vpd = &phba->vpd; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4405 | |
| 4406 | if (prli_fc4_req == PRLI_FCP_TYPE) { |
| 4407 | /* |
| 4408 | * If the remote port is a target and our firmware version |
| 4409 | * is 3.20 or later, set the following bits for FC-TAPE |
| 4410 | * support. |
| 4411 | */ |
| 4412 | npr = (PRLI *) pcmd; |
| 4413 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 4414 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| 4415 | npr->ConfmComplAllowed = 1; |
| 4416 | npr->Retry = 1; |
| 4417 | npr->TaskRetryIdReq = 1; |
| 4418 | } |
| 4419 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 4420 | npr->estabImagePair = 1; |
| 4421 | npr->readXferRdyDis = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4422 | npr->ConfmComplAllowed = 1; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4423 | npr->prliType = PRLI_FCP_TYPE; |
| 4424 | npr->initiatorFunc = 1; |
| 4425 | } else if (prli_fc4_req & PRLI_NVME_TYPE) { |
| 4426 | /* Respond with an NVME PRLI Type */ |
| 4427 | npr_nvme = (struct lpfc_nvme_prli *) pcmd; |
| 4428 | bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); |
| 4429 | bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ |
| 4430 | bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4431 | if (phba->nvmet_support) { |
| 4432 | bf_set(prli_tgt, npr_nvme, 1); |
| 4433 | bf_set(prli_disc, npr_nvme, 1); |
| 4434 | if (phba->cfg_nvme_enable_fb) { |
| 4435 | bf_set(prli_fba, npr_nvme, 1); |
| 4436 | |
| 4437 | /* TBD. Target mode needs to post buffers |
| 4438 | * that support the configured first burst |
| 4439 | * byte size. |
| 4440 | */ |
| 4441 | bf_set(prli_fb_sz, npr_nvme, |
| 4442 | phba->cfg_nvmet_fb_size); |
| 4443 | } |
| 4444 | } else { |
| 4445 | bf_set(prli_init, npr_nvme, 1); |
| 4446 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4447 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4448 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, |
| 4449 | "6015 NVME issue PRLI ACC word1 x%08x " |
| 4450 | "word4 x%08x word5 x%08x flag x%x, " |
| 4451 | "fcp_info x%x nlp_type x%x\n", |
| 4452 | npr_nvme->word1, npr_nvme->word4, |
| 4453 | npr_nvme->word5, ndlp->nlp_flag, |
| 4454 | ndlp->nlp_fcp_info, ndlp->nlp_type); |
| 4455 | npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); |
| 4456 | npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); |
| 4457 | npr_nvme->word5 = cpu_to_be32(npr_nvme->word5); |
| 4458 | } else |
| 4459 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4460 | "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n", |
| 4461 | prli_fc4_req, ndlp->nlp_fc4_type, |
| 4462 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4463 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4464 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4465 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 4466 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4467 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4468 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4469 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4470 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4471 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4472 | if (rc == IOCB_ERROR) { |
| 4473 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4474 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4475 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4476 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4477 | } |
| 4478 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4479 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4480 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4481 | * @vport: pointer to a virtual N_Port data structure. |
| 4482 | * @format: rnid command format. |
| 4483 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4484 | * @ndlp: pointer to a node-list data structure. |
| 4485 | * |
| 4486 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 4487 | * (ACC) response. It constructs the RNID ACC response command according to |
| 4488 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 4489 | * issue the response. Note that this command does not need to hold the ndlp |
| 4490 | * reference count for the callback. So, the ndlp reference count taken by |
| 4491 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 4492 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 4493 | * there is no ndlp reference available. |
| 4494 | * |
| 4495 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4496 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4497 | * will be stored into the context1 field of the IOCB for the completion |
| 4498 | * callback function. However, for the RNID Accept Response ELS command, |
| 4499 | * this is undone later by this routine after the IOCB is allocated. |
| 4500 | * |
| 4501 | * Return code |
| 4502 | * 0 - Successfully issued acc rnid response |
| 4503 | * 1 - Failed to issue acc rnid response |
| 4504 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4505 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4506 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4507 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4508 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4509 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4510 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4511 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4512 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4513 | uint8_t *pcmd; |
| 4514 | uint16_t cmdsize; |
| 4515 | int rc; |
| 4516 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4517 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 4518 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4519 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4520 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4521 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4522 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4523 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4524 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4525 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4526 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4527 | icmd = &elsiocb->iocb; |
| 4528 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4529 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4530 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4531 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4532 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4533 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4534 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 4535 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4536 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4537 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4538 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4539 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4540 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4541 | rn = (RNID *) (pcmd); |
| 4542 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4543 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 4544 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4545 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4546 | switch (format) { |
| 4547 | case 0: |
| 4548 | rn->SpecificLen = 0; |
| 4549 | break; |
| 4550 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4551 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4552 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4553 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4554 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 4555 | rn->un.topologyDisc.physPort = 0; |
| 4556 | rn->un.topologyDisc.attachedNodes = 0; |
| 4557 | break; |
| 4558 | default: |
| 4559 | rn->CommonLen = 0; |
| 4560 | rn->SpecificLen = 0; |
| 4561 | break; |
| 4562 | } |
| 4563 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4564 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4565 | "Issue ACC RNID: did:x%x flg:x%x", |
| 4566 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4567 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4568 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4569 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4570 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4571 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4572 | if (rc == IOCB_ERROR) { |
| 4573 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4574 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4575 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4576 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4577 | } |
| 4578 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4579 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4580 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. |
| 4581 | * @vport: pointer to a virtual N_Port data structure. |
| 4582 | * @iocb: pointer to the lpfc command iocb data structure. |
| 4583 | * @ndlp: pointer to a node-list data structure. |
| 4584 | * |
| 4585 | * Return |
| 4586 | **/ |
| 4587 | static void |
| 4588 | lpfc_els_clear_rrq(struct lpfc_vport *vport, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4589 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4590 | { |
| 4591 | struct lpfc_hba *phba = vport->phba; |
| 4592 | uint8_t *pcmd; |
| 4593 | struct RRQ *rrq; |
| 4594 | uint16_t rxid; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4595 | uint16_t xri; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4596 | struct lpfc_node_rrq *prrq; |
| 4597 | |
| 4598 | |
| 4599 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); |
| 4600 | pcmd += sizeof(uint32_t); |
| 4601 | rrq = (struct RRQ *)pcmd; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4602 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4603 | rxid = bf_get(rrq_rxid, rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4604 | |
| 4605 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4606 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" |
| 4607 | " x%x x%x\n", |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4608 | be32_to_cpu(bf_get(rrq_did, rrq)), |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4609 | bf_get(rrq_oxid, rrq), |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4610 | rxid, |
| 4611 | iocb->iotag, iocb->iocb.ulpContext); |
| 4612 | |
| 4613 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4614 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", |
| 4615 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4616 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4617 | xri = bf_get(rrq_oxid, rrq); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4618 | else |
| 4619 | xri = rxid; |
| 4620 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4621 | if (prrq) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4622 | lpfc_clr_rrq_active(phba, xri, prrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4623 | return; |
| 4624 | } |
| 4625 | |
| 4626 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4627 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 4628 | * @vport: pointer to a virtual N_Port data structure. |
| 4629 | * @data: pointer to echo data to return in the accept. |
| 4630 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4631 | * @ndlp: pointer to a node-list data structure. |
| 4632 | * |
| 4633 | * Return code |
| 4634 | * 0 - Successfully issued acc echo response |
| 4635 | * 1 - Failed to issue acc echo response |
| 4636 | **/ |
| 4637 | static int |
| 4638 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 4639 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 4640 | { |
| 4641 | struct lpfc_hba *phba = vport->phba; |
| 4642 | struct lpfc_iocbq *elsiocb; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4643 | uint8_t *pcmd; |
| 4644 | uint16_t cmdsize; |
| 4645 | int rc; |
| 4646 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4647 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 4648 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4649 | /* The accumulated length can exceed the BPL_SIZE. For |
| 4650 | * now, use this as the limit |
| 4651 | */ |
| 4652 | if (cmdsize > LPFC_BPL_SIZE) |
| 4653 | cmdsize = LPFC_BPL_SIZE; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4654 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4655 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4656 | if (!elsiocb) |
| 4657 | return 1; |
| 4658 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4659 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 4660 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; |
| 4661 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4662 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 4663 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4664 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 4665 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 4666 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4667 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4668 | pcmd += sizeof(uint32_t); |
| 4669 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 4670 | |
| 4671 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4672 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 4673 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4674 | |
| 4675 | phba->fc_stat.elsXmitACC++; |
| 4676 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4677 | |
| 4678 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4679 | if (rc == IOCB_ERROR) { |
| 4680 | lpfc_els_free_iocb(phba, elsiocb); |
| 4681 | return 1; |
| 4682 | } |
| 4683 | return 0; |
| 4684 | } |
| 4685 | |
| 4686 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4687 | * 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] | 4688 | * @vport: pointer to a host virtual N_Port data structure. |
| 4689 | * |
| 4690 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 4691 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 4692 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 4693 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 4694 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 4695 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 4696 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 4697 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 4698 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 4699 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 4700 | * no more ADISC need to be sent. |
| 4701 | * |
| 4702 | * Return code |
| 4703 | * The number of N_Ports with adisc issued. |
| 4704 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4705 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4706 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4707 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4708 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4709 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4710 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4711 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4712 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4713 | 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] | 4714 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4715 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4716 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4717 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4718 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4719 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4720 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4721 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4722 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4723 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4724 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4725 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4726 | vport->num_disc_nodes++; |
| 4727 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4728 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4729 | spin_lock_irq(shost->host_lock); |
| 4730 | vport->fc_flag |= FC_NLP_MORE; |
| 4731 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4732 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4733 | } |
| 4734 | } |
| 4735 | } |
| 4736 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4737 | spin_lock_irq(shost->host_lock); |
| 4738 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4739 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4740 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4741 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4742 | } |
| 4743 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4744 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4745 | * 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] | 4746 | * @vport: pointer to a host virtual N_Port data structure. |
| 4747 | * |
| 4748 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4749 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4750 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4751 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4752 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4753 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4754 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4755 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4756 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4757 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4758 | * PLOGI need to be sent. |
| 4759 | * |
| 4760 | * Return code |
| 4761 | * The number of N_Ports with plogi issued. |
| 4762 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4763 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4764 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4765 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4766 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4767 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4768 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4769 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4770 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4771 | 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] | 4772 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4773 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4774 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4775 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4776 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4777 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4778 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4779 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4780 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4781 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4782 | vport->num_disc_nodes++; |
| 4783 | if (vport->num_disc_nodes >= |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4784 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4785 | spin_lock_irq(shost->host_lock); |
| 4786 | vport->fc_flag |= FC_NLP_MORE; |
| 4787 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4788 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4789 | } |
| 4790 | } |
| 4791 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4792 | if (sentplogi) { |
| 4793 | lpfc_set_disctmo(vport); |
| 4794 | } |
| 4795 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4796 | spin_lock_irq(shost->host_lock); |
| 4797 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4798 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4799 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4800 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4801 | } |
| 4802 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4803 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4804 | lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc, |
| 4805 | uint32_t word0) |
| 4806 | { |
| 4807 | |
| 4808 | desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG); |
| 4809 | desc->payload.els_req = word0; |
| 4810 | desc->length = cpu_to_be32(sizeof(desc->payload)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4811 | |
| 4812 | return sizeof(struct fc_rdp_link_service_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4813 | } |
| 4814 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4815 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4816 | lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc, |
| 4817 | uint8_t *page_a0, uint8_t *page_a2) |
| 4818 | { |
| 4819 | uint16_t wavelength; |
| 4820 | uint16_t temperature; |
| 4821 | uint16_t rx_power; |
| 4822 | uint16_t tx_bias; |
| 4823 | uint16_t tx_power; |
| 4824 | uint16_t vcc; |
| 4825 | uint16_t flag = 0; |
| 4826 | struct sff_trasnceiver_codes_byte4 *trasn_code_byte4; |
| 4827 | struct sff_trasnceiver_codes_byte5 *trasn_code_byte5; |
| 4828 | |
| 4829 | desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG); |
| 4830 | |
| 4831 | trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *) |
| 4832 | &page_a0[SSF_TRANSCEIVER_CODE_B4]; |
| 4833 | trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *) |
| 4834 | &page_a0[SSF_TRANSCEIVER_CODE_B5]; |
| 4835 | |
| 4836 | if ((trasn_code_byte4->fc_sw_laser) || |
| 4837 | (trasn_code_byte5->fc_sw_laser_sl) || |
| 4838 | (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */ |
| 4839 | flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT); |
| 4840 | } else if (trasn_code_byte4->fc_lw_laser) { |
| 4841 | wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) | |
| 4842 | page_a0[SSF_WAVELENGTH_B0]; |
| 4843 | if (wavelength == SFP_WAVELENGTH_LC1310) |
| 4844 | flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT; |
| 4845 | if (wavelength == SFP_WAVELENGTH_LL1550) |
| 4846 | flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT; |
| 4847 | } |
| 4848 | /* check if its SFP+ */ |
| 4849 | flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ? |
| 4850 | SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN) |
| 4851 | << SFP_FLAG_CT_SHIFT; |
| 4852 | |
| 4853 | /* check if its OPTICAL */ |
| 4854 | flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ? |
| 4855 | SFP_FLAG_IS_OPTICAL_PORT : 0) |
| 4856 | << SFP_FLAG_IS_OPTICAL_SHIFT; |
| 4857 | |
| 4858 | temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 | |
| 4859 | page_a2[SFF_TEMPERATURE_B0]); |
| 4860 | vcc = (page_a2[SFF_VCC_B1] << 8 | |
| 4861 | page_a2[SFF_VCC_B0]); |
| 4862 | tx_power = (page_a2[SFF_TXPOWER_B1] << 8 | |
| 4863 | page_a2[SFF_TXPOWER_B0]); |
| 4864 | tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 | |
| 4865 | page_a2[SFF_TX_BIAS_CURRENT_B0]); |
| 4866 | rx_power = (page_a2[SFF_RXPOWER_B1] << 8 | |
| 4867 | page_a2[SFF_RXPOWER_B0]); |
| 4868 | desc->sfp_info.temperature = cpu_to_be16(temperature); |
| 4869 | desc->sfp_info.rx_power = cpu_to_be16(rx_power); |
| 4870 | desc->sfp_info.tx_bias = cpu_to_be16(tx_bias); |
| 4871 | desc->sfp_info.tx_power = cpu_to_be16(tx_power); |
| 4872 | desc->sfp_info.vcc = cpu_to_be16(vcc); |
| 4873 | |
| 4874 | desc->sfp_info.flags = cpu_to_be16(flag); |
| 4875 | desc->length = cpu_to_be32(sizeof(desc->sfp_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4876 | |
| 4877 | return sizeof(struct fc_rdp_sfp_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4878 | } |
| 4879 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4880 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4881 | lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc, |
| 4882 | READ_LNK_VAR *stat) |
| 4883 | { |
| 4884 | uint32_t type; |
| 4885 | |
| 4886 | desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG); |
| 4887 | |
| 4888 | type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT; |
| 4889 | |
| 4890 | desc->info.port_type = cpu_to_be32(type); |
| 4891 | |
| 4892 | desc->info.link_status.link_failure_cnt = |
| 4893 | cpu_to_be32(stat->linkFailureCnt); |
| 4894 | desc->info.link_status.loss_of_synch_cnt = |
| 4895 | cpu_to_be32(stat->lossSyncCnt); |
| 4896 | desc->info.link_status.loss_of_signal_cnt = |
| 4897 | cpu_to_be32(stat->lossSignalCnt); |
| 4898 | desc->info.link_status.primitive_seq_proto_err = |
| 4899 | cpu_to_be32(stat->primSeqErrCnt); |
| 4900 | desc->info.link_status.invalid_trans_word = |
| 4901 | cpu_to_be32(stat->invalidXmitWord); |
| 4902 | desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt); |
| 4903 | |
| 4904 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4905 | |
| 4906 | return sizeof(struct fc_rdp_link_error_status_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4907 | } |
| 4908 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4909 | static uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4910 | lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat, |
| 4911 | struct lpfc_vport *vport) |
| 4912 | { |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4913 | uint32_t bbCredit; |
| 4914 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4915 | desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG); |
| 4916 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4917 | bbCredit = vport->fc_sparam.cmn.bbCreditLsb | |
| 4918 | (vport->fc_sparam.cmn.bbCreditMsb << 8); |
| 4919 | desc->bbc_info.port_bbc = cpu_to_be32(bbCredit); |
| 4920 | if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
| 4921 | bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb | |
| 4922 | (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8); |
| 4923 | desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit); |
| 4924 | } else { |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4925 | desc->bbc_info.attached_port_bbc = 0; |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4926 | } |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4927 | |
| 4928 | desc->bbc_info.rtt = 0; |
| 4929 | desc->length = cpu_to_be32(sizeof(desc->bbc_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4930 | |
| 4931 | return sizeof(struct fc_rdp_bbc_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4932 | } |
| 4933 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4934 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4935 | lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba, |
| 4936 | struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2) |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4937 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4938 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4939 | |
| 4940 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 4941 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4942 | desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM]; |
| 4943 | desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM]; |
| 4944 | desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING]; |
| 4945 | desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4946 | |
| 4947 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 4948 | flags |= RDP_OET_HIGH_ALARM; |
| 4949 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 4950 | flags |= RDP_OET_LOW_ALARM; |
| 4951 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 4952 | flags |= RDP_OET_HIGH_WARNING; |
| 4953 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 4954 | flags |= RDP_OET_LOW_WARNING; |
| 4955 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4956 | flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT); |
| 4957 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 4958 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4959 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4960 | } |
| 4961 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4962 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4963 | lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba, |
| 4964 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4965 | uint8_t *page_a2) |
| 4966 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4967 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4968 | |
| 4969 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 4970 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4971 | desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM]; |
| 4972 | desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM]; |
| 4973 | desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING]; |
| 4974 | desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4975 | |
| 4976 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 4977 | flags |= RDP_OET_HIGH_ALARM; |
| 4978 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 4979 | flags |= RDP_OET_LOW_ALARM; |
| 4980 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 4981 | flags |= RDP_OET_HIGH_WARNING; |
| 4982 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 4983 | flags |= RDP_OET_LOW_WARNING; |
| 4984 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4985 | flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT); |
| 4986 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 4987 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4988 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4989 | } |
| 4990 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4991 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4992 | lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba, |
| 4993 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4994 | uint8_t *page_a2) |
| 4995 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4996 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4997 | |
| 4998 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 4999 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5000 | desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM]; |
| 5001 | desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM]; |
| 5002 | desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING]; |
| 5003 | desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5004 | |
| 5005 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 5006 | flags |= RDP_OET_HIGH_ALARM; |
| 5007 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 5008 | flags |= RDP_OET_LOW_ALARM; |
| 5009 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 5010 | flags |= RDP_OET_HIGH_WARNING; |
| 5011 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 5012 | flags |= RDP_OET_LOW_WARNING; |
| 5013 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5014 | flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT); |
| 5015 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5016 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5017 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5018 | } |
| 5019 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5020 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5021 | lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba, |
| 5022 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5023 | uint8_t *page_a2) |
| 5024 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5025 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5026 | |
| 5027 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5028 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5029 | desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM]; |
| 5030 | desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM]; |
| 5031 | desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING]; |
| 5032 | desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5033 | |
| 5034 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 5035 | flags |= RDP_OET_HIGH_ALARM; |
| 5036 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 5037 | flags |= RDP_OET_LOW_ALARM; |
| 5038 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 5039 | flags |= RDP_OET_HIGH_WARNING; |
| 5040 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 5041 | flags |= RDP_OET_LOW_WARNING; |
| 5042 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5043 | flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT); |
| 5044 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5045 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5046 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5047 | } |
| 5048 | |
| 5049 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5050 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5051 | lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba, |
| 5052 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5053 | uint8_t *page_a2) |
| 5054 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5055 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5056 | |
| 5057 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5058 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5059 | desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM]; |
| 5060 | desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM]; |
| 5061 | desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING]; |
| 5062 | desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5063 | |
| 5064 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 5065 | flags |= RDP_OET_HIGH_ALARM; |
| 5066 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 5067 | flags |= RDP_OET_LOW_ALARM; |
| 5068 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 5069 | flags |= RDP_OET_HIGH_WARNING; |
| 5070 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 5071 | flags |= RDP_OET_LOW_WARNING; |
| 5072 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5073 | flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT); |
| 5074 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5075 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5076 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5077 | } |
| 5078 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5079 | static uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5080 | lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc, |
| 5081 | uint8_t *page_a0, struct lpfc_vport *vport) |
| 5082 | { |
| 5083 | desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG); |
| 5084 | memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16); |
| 5085 | memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16); |
| 5086 | memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5087 | memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5088 | memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8); |
| 5089 | desc->length = cpu_to_be32(sizeof(desc->opd_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5090 | return sizeof(struct fc_rdp_opd_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5091 | } |
| 5092 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5093 | static uint32_t |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5094 | lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat) |
| 5095 | { |
| 5096 | if (bf_get(lpfc_read_link_stat_gec2, stat) == 0) |
| 5097 | return 0; |
| 5098 | desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG); |
| 5099 | |
| 5100 | desc->info.CorrectedBlocks = |
| 5101 | cpu_to_be32(stat->fecCorrBlkCount); |
| 5102 | desc->info.UncorrectableBlocks = |
| 5103 | cpu_to_be32(stat->fecUncorrBlkCount); |
| 5104 | |
| 5105 | desc->length = cpu_to_be32(sizeof(desc->info)); |
| 5106 | |
| 5107 | return sizeof(struct fc_fec_rdp_desc); |
| 5108 | } |
| 5109 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5110 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5111 | lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba) |
| 5112 | { |
| 5113 | uint16_t rdp_cap = 0; |
| 5114 | uint16_t rdp_speed; |
| 5115 | |
| 5116 | desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG); |
| 5117 | |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5118 | switch (phba->fc_linkspeed) { |
| 5119 | case LPFC_LINK_SPEED_1GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5120 | rdp_speed = RDP_PS_1GB; |
| 5121 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5122 | case LPFC_LINK_SPEED_2GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5123 | rdp_speed = RDP_PS_2GB; |
| 5124 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5125 | case LPFC_LINK_SPEED_4GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5126 | rdp_speed = RDP_PS_4GB; |
| 5127 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5128 | case LPFC_LINK_SPEED_8GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5129 | rdp_speed = RDP_PS_8GB; |
| 5130 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5131 | case LPFC_LINK_SPEED_10GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5132 | rdp_speed = RDP_PS_10GB; |
| 5133 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5134 | case LPFC_LINK_SPEED_16GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5135 | rdp_speed = RDP_PS_16GB; |
| 5136 | break; |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 5137 | case LPFC_LINK_SPEED_32GHZ: |
| 5138 | rdp_speed = RDP_PS_32GB; |
| 5139 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5140 | default: |
| 5141 | rdp_speed = RDP_PS_UNKNOWN; |
| 5142 | break; |
| 5143 | } |
| 5144 | |
| 5145 | desc->info.port_speed.speed = cpu_to_be16(rdp_speed); |
| 5146 | |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 5147 | if (phba->lmt & LMT_32Gb) |
| 5148 | rdp_cap |= RDP_PS_32GB; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5149 | if (phba->lmt & LMT_16Gb) |
| 5150 | rdp_cap |= RDP_PS_16GB; |
| 5151 | if (phba->lmt & LMT_10Gb) |
| 5152 | rdp_cap |= RDP_PS_10GB; |
| 5153 | if (phba->lmt & LMT_8Gb) |
| 5154 | rdp_cap |= RDP_PS_8GB; |
| 5155 | if (phba->lmt & LMT_4Gb) |
| 5156 | rdp_cap |= RDP_PS_4GB; |
| 5157 | if (phba->lmt & LMT_2Gb) |
| 5158 | rdp_cap |= RDP_PS_2GB; |
| 5159 | if (phba->lmt & LMT_1Gb) |
| 5160 | rdp_cap |= RDP_PS_1GB; |
| 5161 | |
| 5162 | if (rdp_cap == 0) |
| 5163 | rdp_cap = RDP_CAP_UNKNOWN; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5164 | if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO) |
| 5165 | rdp_cap |= RDP_CAP_USER_CONFIGURED; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5166 | |
| 5167 | desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap); |
| 5168 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5169 | return sizeof(struct fc_rdp_port_speed_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5170 | } |
| 5171 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5172 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5173 | 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] | 5174 | struct lpfc_vport *vport) |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5175 | { |
| 5176 | |
| 5177 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 5178 | |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 5179 | memcpy(desc->port_names.wwnn, &vport->fc_nodename, |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5180 | sizeof(desc->port_names.wwnn)); |
| 5181 | |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 5182 | memcpy(desc->port_names.wwpn, &vport->fc_portname, |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5183 | sizeof(desc->port_names.wwpn)); |
| 5184 | |
| 5185 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5186 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5187 | } |
| 5188 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5189 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5190 | lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc, |
| 5191 | struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 5192 | { |
| 5193 | |
| 5194 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 5195 | if (vport->fc_flag & FC_FABRIC) { |
| 5196 | memcpy(desc->port_names.wwnn, &vport->fabric_nodename, |
| 5197 | sizeof(desc->port_names.wwnn)); |
| 5198 | |
| 5199 | memcpy(desc->port_names.wwpn, &vport->fabric_portname, |
| 5200 | sizeof(desc->port_names.wwpn)); |
| 5201 | } else { /* Point to Point */ |
| 5202 | memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename, |
| 5203 | sizeof(desc->port_names.wwnn)); |
| 5204 | |
| 5205 | memcpy(desc->port_names.wwnn, &ndlp->nlp_portname, |
| 5206 | sizeof(desc->port_names.wwpn)); |
| 5207 | } |
| 5208 | |
| 5209 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5210 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5211 | } |
| 5212 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5213 | static void |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5214 | lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context, |
| 5215 | int status) |
| 5216 | { |
| 5217 | struct lpfc_nodelist *ndlp = rdp_context->ndlp; |
| 5218 | struct lpfc_vport *vport = ndlp->vport; |
| 5219 | struct lpfc_iocbq *elsiocb; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5220 | struct ulp_bde64 *bpl; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5221 | IOCB_t *icmd; |
| 5222 | uint8_t *pcmd; |
| 5223 | struct ls_rjt *stat; |
| 5224 | struct fc_rdp_res_frame *rdp_res; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5225 | uint32_t cmdsize, len; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5226 | uint16_t *flag_ptr; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5227 | int rc; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5228 | |
| 5229 | if (status != SUCCESS) |
| 5230 | goto error; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5231 | |
| 5232 | /* 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] | 5233 | cmdsize = sizeof(struct fc_rdp_res_frame); |
| 5234 | |
| 5235 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, |
| 5236 | lpfc_max_els_tries, rdp_context->ndlp, |
| 5237 | rdp_context->ndlp->nlp_DID, ELS_CMD_ACC); |
| 5238 | lpfc_nlp_put(ndlp); |
| 5239 | if (!elsiocb) |
| 5240 | goto free_rdp_context; |
| 5241 | |
| 5242 | icmd = &elsiocb->iocb; |
| 5243 | icmd->ulpContext = rdp_context->rx_id; |
| 5244 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 5245 | |
| 5246 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5247 | "2171 Xmit RDP response tag x%x xri x%x, " |
| 5248 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x", |
| 5249 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5250 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5251 | ndlp->nlp_rpi); |
| 5252 | rdp_res = (struct fc_rdp_res_frame *) |
| 5253 | (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5254 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5255 | memset(pcmd, 0, sizeof(struct fc_rdp_res_frame)); |
| 5256 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5257 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5258 | /* Update Alarm and Warning */ |
| 5259 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS); |
| 5260 | phba->sfp_alarm |= *flag_ptr; |
| 5261 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS); |
| 5262 | phba->sfp_warning |= *flag_ptr; |
| 5263 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5264 | /* For RDP payload */ |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5265 | len = 8; |
| 5266 | len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *) |
| 5267 | (len + pcmd), ELS_CMD_RDP); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5268 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5269 | 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] | 5270 | rdp_context->page_a0, rdp_context->page_a2); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5271 | len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd), |
| 5272 | phba); |
| 5273 | len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *) |
| 5274 | (len + pcmd), &rdp_context->link_stat); |
| 5275 | 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] | 5276 | (len + pcmd), vport); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5277 | len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *) |
| 5278 | (len + pcmd), vport, ndlp); |
| 5279 | 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] | 5280 | &rdp_context->link_stat); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5281 | /* Check if nport is logged, BZ190632 */ |
| 5282 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) |
| 5283 | goto lpfc_skip_descriptor; |
| 5284 | |
| 5285 | len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd), |
| 5286 | &rdp_context->link_stat, vport); |
| 5287 | len += lpfc_rdp_res_oed_temp_desc(phba, |
| 5288 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5289 | rdp_context->page_a2); |
| 5290 | len += lpfc_rdp_res_oed_voltage_desc(phba, |
| 5291 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5292 | rdp_context->page_a2); |
| 5293 | len += lpfc_rdp_res_oed_txbias_desc(phba, |
| 5294 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5295 | rdp_context->page_a2); |
| 5296 | len += lpfc_rdp_res_oed_txpower_desc(phba, |
| 5297 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5298 | rdp_context->page_a2); |
| 5299 | len += lpfc_rdp_res_oed_rxpower_desc(phba, |
| 5300 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5301 | rdp_context->page_a2); |
| 5302 | len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd), |
| 5303 | rdp_context->page_a0, vport); |
| 5304 | |
| 5305 | lpfc_skip_descriptor: |
| 5306 | rdp_res->length = cpu_to_be32(len - 8); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5307 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5308 | |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5309 | /* Now that we know the true size of the payload, update the BPL */ |
| 5310 | bpl = (struct ulp_bde64 *) |
| 5311 | (((struct lpfc_dmabuf *)(elsiocb->context3))->virt); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5312 | bpl->tus.f.bdeSize = len; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5313 | bpl->tus.f.bdeFlags = 0; |
| 5314 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 5315 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5316 | phba->fc_stat.elsXmitACC++; |
| 5317 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5318 | if (rc == IOCB_ERROR) |
| 5319 | lpfc_els_free_iocb(phba, elsiocb); |
| 5320 | |
| 5321 | kfree(rdp_context); |
| 5322 | |
| 5323 | return; |
| 5324 | error: |
| 5325 | cmdsize = 2 * sizeof(uint32_t); |
| 5326 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries, |
| 5327 | ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 5328 | lpfc_nlp_put(ndlp); |
| 5329 | if (!elsiocb) |
| 5330 | goto free_rdp_context; |
| 5331 | |
| 5332 | icmd = &elsiocb->iocb; |
| 5333 | icmd->ulpContext = rdp_context->rx_id; |
| 5334 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 5335 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5336 | |
| 5337 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
| 5338 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 5339 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5340 | |
| 5341 | phba->fc_stat.elsXmitLSRJT++; |
| 5342 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5343 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5344 | |
| 5345 | if (rc == IOCB_ERROR) |
| 5346 | lpfc_els_free_iocb(phba, elsiocb); |
| 5347 | free_rdp_context: |
| 5348 | kfree(rdp_context); |
| 5349 | } |
| 5350 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5351 | static int |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5352 | lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) |
| 5353 | { |
| 5354 | LPFC_MBOXQ_t *mbox = NULL; |
| 5355 | int rc; |
| 5356 | |
| 5357 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5358 | if (!mbox) { |
| 5359 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, |
| 5360 | "7105 failed to allocate mailbox memory"); |
| 5361 | return 1; |
| 5362 | } |
| 5363 | |
| 5364 | if (lpfc_sli4_dump_page_a0(phba, mbox)) |
| 5365 | goto prep_mbox_fail; |
| 5366 | mbox->vport = rdp_context->ndlp->vport; |
| 5367 | mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; |
| 5368 | mbox->context2 = (struct lpfc_rdp_context *) rdp_context; |
| 5369 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5370 | if (rc == MBX_NOT_FINISHED) |
| 5371 | goto issue_mbox_fail; |
| 5372 | |
| 5373 | return 0; |
| 5374 | |
| 5375 | prep_mbox_fail: |
| 5376 | issue_mbox_fail: |
| 5377 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5378 | return 1; |
| 5379 | } |
| 5380 | |
| 5381 | /* |
| 5382 | * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS. |
| 5383 | * @vport: pointer to a host virtual N_Port data structure. |
| 5384 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5385 | * @ndlp: pointer to a node-list data structure. |
| 5386 | * |
| 5387 | * This routine processes an unsolicited RDP(Read Diagnostic Parameters) |
| 5388 | * IOCB. First, the payload of the unsolicited RDP is checked. |
| 5389 | * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3 |
| 5390 | * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2, |
| 5391 | * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl |
| 5392 | * gather all data and send RDP response. |
| 5393 | * |
| 5394 | * Return code |
| 5395 | * 0 - Sent the acc response |
| 5396 | * 1 - Sent the reject response. |
| 5397 | */ |
| 5398 | static int |
| 5399 | lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5400 | struct lpfc_nodelist *ndlp) |
| 5401 | { |
| 5402 | struct lpfc_hba *phba = vport->phba; |
| 5403 | struct lpfc_dmabuf *pcmd; |
| 5404 | uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE; |
| 5405 | struct fc_rdp_req_frame *rdp_req; |
| 5406 | struct lpfc_rdp_context *rdp_context; |
| 5407 | IOCB_t *cmd = NULL; |
| 5408 | struct ls_rjt stat; |
| 5409 | |
| 5410 | if (phba->sli_rev < LPFC_SLI_REV4 || |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5411 | bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 5412 | LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5413 | rjt_err = LSRJT_UNABLE_TPC; |
| 5414 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 5415 | goto error; |
| 5416 | } |
| 5417 | |
| 5418 | if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) { |
| 5419 | rjt_err = LSRJT_UNABLE_TPC; |
| 5420 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 5421 | goto error; |
| 5422 | } |
| 5423 | |
| 5424 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5425 | rdp_req = (struct fc_rdp_req_frame *) pcmd->virt; |
| 5426 | |
| 5427 | |
| 5428 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5429 | "2422 ELS RDP Request " |
| 5430 | "dec len %d tag x%x port_id %d len %d\n", |
| 5431 | be32_to_cpu(rdp_req->rdp_des_length), |
| 5432 | be32_to_cpu(rdp_req->nport_id_desc.tag), |
| 5433 | be32_to_cpu(rdp_req->nport_id_desc.nport_id), |
| 5434 | be32_to_cpu(rdp_req->nport_id_desc.length)); |
| 5435 | |
James Smart | 7d93331 | 2016-07-06 12:35:58 -0700 | [diff] [blame] | 5436 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) && |
| 5437 | !phba->cfg_enable_SmartSAN) { |
| 5438 | rjt_err = LSRJT_UNABLE_TPC; |
| 5439 | rjt_expl = LSEXP_PORT_LOGIN_REQ; |
| 5440 | goto error; |
| 5441 | } |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5442 | if (sizeof(struct fc_rdp_nport_desc) != |
| 5443 | be32_to_cpu(rdp_req->rdp_des_length)) |
| 5444 | goto rjt_logerr; |
| 5445 | if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag)) |
| 5446 | goto rjt_logerr; |
| 5447 | if (RDP_NPORT_ID_SIZE != |
| 5448 | be32_to_cpu(rdp_req->nport_id_desc.length)) |
| 5449 | goto rjt_logerr; |
Punit Vara | 699acd6 | 2015-12-16 18:12:07 -0500 | [diff] [blame] | 5450 | rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5451 | if (!rdp_context) { |
| 5452 | rjt_err = LSRJT_UNABLE_TPC; |
| 5453 | goto error; |
| 5454 | } |
| 5455 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5456 | cmd = &cmdiocb->iocb; |
| 5457 | rdp_context->ndlp = lpfc_nlp_get(ndlp); |
| 5458 | rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id; |
| 5459 | rdp_context->rx_id = cmd->ulpContext; |
| 5460 | rdp_context->cmpl = lpfc_els_rdp_cmpl; |
| 5461 | if (lpfc_get_rdp_info(phba, rdp_context)) { |
| 5462 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS, |
| 5463 | "2423 Unable to send mailbox"); |
| 5464 | kfree(rdp_context); |
| 5465 | rjt_err = LSRJT_UNABLE_TPC; |
| 5466 | lpfc_nlp_put(ndlp); |
| 5467 | goto error; |
| 5468 | } |
| 5469 | |
| 5470 | return 0; |
| 5471 | |
| 5472 | rjt_logerr: |
| 5473 | rjt_err = LSRJT_LOGICAL_ERR; |
| 5474 | |
| 5475 | error: |
| 5476 | memset(&stat, 0, sizeof(stat)); |
| 5477 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 5478 | stat.un.b.lsRjtRsnCodeExp = rjt_expl; |
| 5479 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5480 | return 1; |
| 5481 | } |
| 5482 | |
| 5483 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5484 | static void |
| 5485 | lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5486 | { |
| 5487 | MAILBOX_t *mb; |
| 5488 | IOCB_t *icmd; |
| 5489 | uint8_t *pcmd; |
| 5490 | struct lpfc_iocbq *elsiocb; |
| 5491 | struct lpfc_nodelist *ndlp; |
| 5492 | struct ls_rjt *stat; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5493 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5494 | struct lpfc_lcb_context *lcb_context; |
| 5495 | struct fc_lcb_res_frame *lcb_res; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5496 | uint32_t cmdsize, shdr_status, shdr_add_status; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5497 | int rc; |
| 5498 | |
| 5499 | mb = &pmb->u.mb; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5500 | lcb_context = (struct lpfc_lcb_context *)pmb->context1; |
| 5501 | ndlp = lcb_context->ndlp; |
| 5502 | pmb->context1 = NULL; |
| 5503 | pmb->context2 = NULL; |
| 5504 | |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5505 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 5506 | &pmb->u.mqe.un.beacon_config.header.cfg_shdr; |
| 5507 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5508 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5509 | |
| 5510 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX, |
| 5511 | "0194 SET_BEACON_CONFIG mailbox " |
| 5512 | "completed with status x%x add_status x%x," |
| 5513 | " mbx status x%x\n", |
| 5514 | shdr_status, shdr_add_status, mb->mbxStatus); |
| 5515 | |
| 5516 | if (mb->mbxStatus && !(shdr_status && |
| 5517 | shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5518 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5519 | goto error; |
| 5520 | } |
| 5521 | |
| 5522 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5523 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 5524 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5525 | lpfc_max_els_tries, ndlp, |
| 5526 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5527 | |
| 5528 | /* Decrement the ndlp reference count from previous mbox command */ |
| 5529 | lpfc_nlp_put(ndlp); |
| 5530 | |
| 5531 | if (!elsiocb) |
| 5532 | goto free_lcb_context; |
| 5533 | |
| 5534 | lcb_res = (struct fc_lcb_res_frame *) |
| 5535 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5536 | |
| 5537 | icmd = &elsiocb->iocb; |
| 5538 | icmd->ulpContext = lcb_context->rx_id; |
| 5539 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 5540 | |
| 5541 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5542 | *((uint32_t *)(pcmd)) = ELS_CMD_ACC; |
| 5543 | lcb_res->lcb_sub_command = lcb_context->sub_command; |
| 5544 | lcb_res->lcb_type = lcb_context->type; |
| 5545 | lcb_res->lcb_frequency = lcb_context->frequency; |
| 5546 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5547 | phba->fc_stat.elsXmitACC++; |
| 5548 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5549 | if (rc == IOCB_ERROR) |
| 5550 | lpfc_els_free_iocb(phba, elsiocb); |
| 5551 | |
| 5552 | kfree(lcb_context); |
| 5553 | return; |
| 5554 | |
| 5555 | error: |
| 5556 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 5557 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5558 | lpfc_max_els_tries, ndlp, |
| 5559 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 5560 | lpfc_nlp_put(ndlp); |
| 5561 | if (!elsiocb) |
| 5562 | goto free_lcb_context; |
| 5563 | |
| 5564 | icmd = &elsiocb->iocb; |
| 5565 | icmd->ulpContext = lcb_context->rx_id; |
| 5566 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 5567 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5568 | |
| 5569 | *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT; |
| 5570 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 5571 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5572 | |
| 5573 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5574 | phba->fc_stat.elsXmitLSRJT++; |
| 5575 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5576 | if (rc == IOCB_ERROR) |
| 5577 | lpfc_els_free_iocb(phba, elsiocb); |
| 5578 | free_lcb_context: |
| 5579 | kfree(lcb_context); |
| 5580 | } |
| 5581 | |
| 5582 | static int |
| 5583 | lpfc_sli4_set_beacon(struct lpfc_vport *vport, |
| 5584 | struct lpfc_lcb_context *lcb_context, |
| 5585 | uint32_t beacon_state) |
| 5586 | { |
| 5587 | struct lpfc_hba *phba = vport->phba; |
| 5588 | LPFC_MBOXQ_t *mbox = NULL; |
| 5589 | uint32_t len; |
| 5590 | int rc; |
| 5591 | |
| 5592 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5593 | if (!mbox) |
| 5594 | return 1; |
| 5595 | |
| 5596 | len = sizeof(struct lpfc_mbx_set_beacon_config) - |
| 5597 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 5598 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5599 | LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len, |
| 5600 | LPFC_SLI4_MBX_EMBED); |
| 5601 | mbox->context1 = (void *)lcb_context; |
| 5602 | mbox->vport = phba->pport; |
| 5603 | mbox->mbox_cmpl = lpfc_els_lcb_rsp; |
| 5604 | bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config, |
| 5605 | phba->sli4_hba.physical_port); |
| 5606 | bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config, |
| 5607 | beacon_state); |
| 5608 | bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1); |
| 5609 | bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0); |
| 5610 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5611 | if (rc == MBX_NOT_FINISHED) { |
| 5612 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5613 | return 1; |
| 5614 | } |
| 5615 | |
| 5616 | return 0; |
| 5617 | } |
| 5618 | |
| 5619 | |
| 5620 | /** |
| 5621 | * lpfc_els_rcv_lcb - Process an unsolicited LCB |
| 5622 | * @vport: pointer to a host virtual N_Port data structure. |
| 5623 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5624 | * @ndlp: pointer to a node-list data structure. |
| 5625 | * |
| 5626 | * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB. |
| 5627 | * First, the payload of the unsolicited LCB is checked. |
| 5628 | * Then based on Subcommand beacon will either turn on or off. |
| 5629 | * |
| 5630 | * Return code |
| 5631 | * 0 - Sent the acc response |
| 5632 | * 1 - Sent the reject response. |
| 5633 | **/ |
| 5634 | static int |
| 5635 | lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5636 | struct lpfc_nodelist *ndlp) |
| 5637 | { |
| 5638 | struct lpfc_hba *phba = vport->phba; |
| 5639 | struct lpfc_dmabuf *pcmd; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5640 | uint8_t *lp; |
| 5641 | struct fc_lcb_request_frame *beacon; |
| 5642 | struct lpfc_lcb_context *lcb_context; |
| 5643 | uint8_t state, rjt_err; |
| 5644 | struct ls_rjt stat; |
| 5645 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5646 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 5647 | lp = (uint8_t *)pcmd->virt; |
| 5648 | beacon = (struct fc_lcb_request_frame *)pcmd->virt; |
| 5649 | |
| 5650 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5651 | "0192 ELS LCB Data x%x x%x x%x x%x sub x%x " |
| 5652 | "type x%x frequency %x duration x%x\n", |
| 5653 | lp[0], lp[1], lp[2], |
| 5654 | beacon->lcb_command, |
| 5655 | beacon->lcb_sub_command, |
| 5656 | beacon->lcb_type, |
| 5657 | beacon->lcb_frequency, |
| 5658 | be16_to_cpu(beacon->lcb_duration)); |
| 5659 | |
| 5660 | if (phba->sli_rev < LPFC_SLI_REV4 || |
| 5661 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 5662 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 5663 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5664 | goto rjt; |
| 5665 | } |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5666 | |
| 5667 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 5668 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5669 | goto rjt; |
| 5670 | } |
| 5671 | if (beacon->lcb_frequency == 0) { |
| 5672 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5673 | goto rjt; |
| 5674 | } |
| 5675 | if ((beacon->lcb_type != LPFC_LCB_GREEN) && |
| 5676 | (beacon->lcb_type != LPFC_LCB_AMBER)) { |
| 5677 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5678 | goto rjt; |
| 5679 | } |
| 5680 | if ((beacon->lcb_sub_command != LPFC_LCB_ON) && |
| 5681 | (beacon->lcb_sub_command != LPFC_LCB_OFF)) { |
| 5682 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5683 | goto rjt; |
| 5684 | } |
| 5685 | if ((beacon->lcb_sub_command == LPFC_LCB_ON) && |
| 5686 | (beacon->lcb_type != LPFC_LCB_GREEN) && |
| 5687 | (beacon->lcb_type != LPFC_LCB_AMBER)) { |
| 5688 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5689 | goto rjt; |
| 5690 | } |
| 5691 | if (be16_to_cpu(beacon->lcb_duration) != 0) { |
| 5692 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5693 | goto rjt; |
| 5694 | } |
| 5695 | |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 5696 | lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL); |
| 5697 | if (!lcb_context) { |
| 5698 | rjt_err = LSRJT_UNABLE_TPC; |
| 5699 | goto rjt; |
| 5700 | } |
| 5701 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5702 | state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; |
| 5703 | lcb_context->sub_command = beacon->lcb_sub_command; |
| 5704 | lcb_context->type = beacon->lcb_type; |
| 5705 | lcb_context->frequency = beacon->lcb_frequency; |
| 5706 | lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
| 5707 | lcb_context->rx_id = cmdiocb->iocb.ulpContext; |
| 5708 | lcb_context->ndlp = lpfc_nlp_get(ndlp); |
| 5709 | if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { |
| 5710 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 5711 | LOG_ELS, "0193 failed to send mail box"); |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 5712 | kfree(lcb_context); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5713 | lpfc_nlp_put(ndlp); |
| 5714 | rjt_err = LSRJT_UNABLE_TPC; |
| 5715 | goto rjt; |
| 5716 | } |
| 5717 | return 0; |
| 5718 | rjt: |
| 5719 | memset(&stat, 0, sizeof(stat)); |
| 5720 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 5721 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5722 | return 1; |
| 5723 | } |
| 5724 | |
| 5725 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5726 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5727 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5728 | * @vport: pointer to a host virtual N_Port data structure. |
| 5729 | * |
| 5730 | * This routine cleans up any Registration State Change Notification |
| 5731 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 5732 | * @vport together with the host_lock is used to prevent multiple thread |
| 5733 | * trying to access the RSCN array on a same @vport at the same time. |
| 5734 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5735 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5736 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5737 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5738 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5739 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5740 | int i; |
| 5741 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5742 | spin_lock_irq(shost->host_lock); |
| 5743 | if (vport->fc_rscn_flush) { |
| 5744 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 5745 | spin_unlock_irq(shost->host_lock); |
| 5746 | return; |
| 5747 | } |
| 5748 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 5749 | vport->fc_rscn_flush = 1; |
| 5750 | spin_unlock_irq(shost->host_lock); |
| 5751 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5752 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5753 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5754 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5755 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5756 | spin_lock_irq(shost->host_lock); |
| 5757 | vport->fc_rscn_id_cnt = 0; |
| 5758 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 5759 | spin_unlock_irq(shost->host_lock); |
| 5760 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5761 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 5762 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5763 | } |
| 5764 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5765 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5766 | * 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] | 5767 | * @vport: pointer to a host virtual N_Port data structure. |
| 5768 | * @did: remote destination port identifier. |
| 5769 | * |
| 5770 | * This routine checks whether there is any pending Registration State |
| 5771 | * Configuration Notification (RSCN) to a @did on @vport. |
| 5772 | * |
| 5773 | * Return code |
| 5774 | * None zero - The @did matched with a pending rscn |
| 5775 | * 0 - not able to match @did with a pending rscn |
| 5776 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5777 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5778 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5779 | { |
| 5780 | D_ID ns_did; |
| 5781 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5782 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5783 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5784 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5785 | |
| 5786 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5787 | |
| 5788 | /* Never match fabric nodes for RSCNs */ |
| 5789 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5790 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5791 | |
| 5792 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5793 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5794 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5795 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5796 | spin_lock_irq(shost->host_lock); |
| 5797 | if (vport->fc_rscn_flush) { |
| 5798 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 5799 | spin_unlock_irq(shost->host_lock); |
| 5800 | return 0; |
| 5801 | } |
| 5802 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 5803 | vport->fc_rscn_flush = 1; |
| 5804 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5805 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5806 | lp = vport->fc_rscn_id_list[i]->virt; |
| 5807 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 5808 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5809 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5810 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 5811 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5812 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 5813 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5814 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 5815 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 5816 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5817 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5818 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5819 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5820 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 5821 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5822 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5823 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5824 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5825 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5826 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5827 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5828 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5829 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5830 | } |
| 5831 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5832 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5833 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 5834 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5835 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5836 | return_did_out: |
| 5837 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 5838 | vport->fc_rscn_flush = 0; |
| 5839 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5840 | } |
| 5841 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5842 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5843 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5844 | * @vport: pointer to a host virtual N_Port data structure. |
| 5845 | * |
| 5846 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 5847 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 5848 | * State Change Notification). |
| 5849 | * |
| 5850 | * Return code |
| 5851 | * 0 - Successful (currently alway return 0) |
| 5852 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5853 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5854 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5855 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5856 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5857 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5858 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5859 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5860 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5861 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 5862 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5863 | continue; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5864 | |
| 5865 | /* NVME Target mode does not do RSCN Recovery. */ |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5866 | if (vport->phba->nvmet_support) |
| 5867 | continue; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5868 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5869 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5870 | NLP_EVT_DEVICE_RECOVERY); |
| 5871 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5872 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5873 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5874 | } |
| 5875 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5876 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5877 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5878 | * @vport: pointer to a host virtual N_Port data structure. |
| 5879 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5880 | * |
| 5881 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 5882 | * applications. |
| 5883 | */ |
| 5884 | static void |
| 5885 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 5886 | struct lpfc_iocbq *cmdiocb) |
| 5887 | { |
| 5888 | struct lpfc_dmabuf *pcmd; |
| 5889 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5890 | uint32_t *payload_ptr; |
| 5891 | uint32_t payload_len; |
| 5892 | struct lpfc_rscn_event_header *rscn_event_data; |
| 5893 | |
| 5894 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5895 | payload_ptr = (uint32_t *) pcmd->virt; |
| 5896 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 5897 | |
| 5898 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 5899 | payload_len, GFP_KERNEL); |
| 5900 | if (!rscn_event_data) { |
| 5901 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5902 | "0147 Failed to allocate memory for RSCN event\n"); |
| 5903 | return; |
| 5904 | } |
| 5905 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 5906 | rscn_event_data->payload_length = payload_len; |
| 5907 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 5908 | payload_len); |
| 5909 | |
| 5910 | fc_host_post_vendor_event(shost, |
| 5911 | fc_get_event_number(), |
Ales Novak | 6599eaa | 2015-08-31 16:48:16 -0400 | [diff] [blame] | 5912 | sizeof(struct lpfc_rscn_event_header) + payload_len, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5913 | (char *)rscn_event_data, |
| 5914 | LPFC_NL_VENDOR_ID); |
| 5915 | |
| 5916 | kfree(rscn_event_data); |
| 5917 | } |
| 5918 | |
| 5919 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5920 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5921 | * @vport: pointer to a host virtual N_Port data structure. |
| 5922 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5923 | * @ndlp: pointer to a node-list data structure. |
| 5924 | * |
| 5925 | * This routine processes an unsolicited RSCN (Registration State Change |
| 5926 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 5927 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 5928 | * discover state machine is about to begin discovery, it just accepts the |
| 5929 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 5930 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 5931 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 5932 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 5933 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 5934 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 5935 | * routine is invoked to handle the RSCN event. |
| 5936 | * |
| 5937 | * Return code |
| 5938 | * 0 - Just sent the acc response |
| 5939 | * 1 - Sent the acc response and waited for name server completion |
| 5940 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5941 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5942 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5943 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5944 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5945 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5946 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5947 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5948 | uint32_t *lp, *datap; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5949 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5950 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5951 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5952 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5953 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5954 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5955 | lp = (uint32_t *) pcmd->virt; |
| 5956 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5957 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 5958 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5959 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5960 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5961 | "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] | 5962 | vport->fc_flag, payload_len, *lp, |
| 5963 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5964 | |
| 5965 | /* Send an RSCN event to the management application */ |
| 5966 | lpfc_send_rscn_event(vport, cmdiocb); |
| 5967 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5968 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5969 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5970 | FCH_EVT_RSCN, lp[i]); |
| 5971 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5972 | /* If we are about to begin discovery, just ACC the RSCN. |
| 5973 | * Discovery processing will satisfy it. |
| 5974 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5975 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5976 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5977 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 5978 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 5979 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5980 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5981 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5982 | } |
| 5983 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5984 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 5985 | * just ACC and ignore it. |
| 5986 | */ |
| 5987 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5988 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5989 | i = payload_len; |
| 5990 | datap = lp; |
| 5991 | while (i > 0) { |
| 5992 | nportid = *datap++; |
| 5993 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 5994 | i -= sizeof(uint32_t); |
| 5995 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5996 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 5997 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5998 | } |
| 5999 | if (rscn_id == hba_id) { |
| 6000 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6001 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6002 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6003 | "Data: x%x x%x x%x x%x\n", |
| 6004 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6005 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6006 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6007 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 6008 | ndlp->nlp_DID, vport->port_state, |
| 6009 | ndlp->nlp_flag); |
| 6010 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6011 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6012 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6013 | return 0; |
| 6014 | } |
| 6015 | } |
| 6016 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6017 | spin_lock_irq(shost->host_lock); |
| 6018 | if (vport->fc_rscn_flush) { |
| 6019 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6020 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 6021 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6022 | /* Send back ACC */ |
| 6023 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6024 | return 0; |
| 6025 | } |
| 6026 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 6027 | vport->fc_rscn_flush = 1; |
| 6028 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6029 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6030 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6031 | /* If we are already processing an RSCN, save the received |
| 6032 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 6033 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6034 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6035 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6036 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 6037 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6038 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6039 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6040 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 6041 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6042 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6043 | vport->fc_flag |= FC_RSCN_MODE; |
| 6044 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6045 | if (rscn_cnt) { |
| 6046 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 6047 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 6048 | } |
| 6049 | if ((rscn_cnt) && |
| 6050 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 6051 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6052 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6053 | memcpy(((uint8_t *)cmd) + length, lp, |
| 6054 | payload_len); |
| 6055 | } else { |
| 6056 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 6057 | vport->fc_rscn_id_cnt++; |
| 6058 | /* If we zero, cmdiocb->context2, the calling |
| 6059 | * routine will not try to free it. |
| 6060 | */ |
| 6061 | cmdiocb->context2 = NULL; |
| 6062 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6063 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6064 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6065 | "0235 Deferred RSCN " |
| 6066 | "Data: x%x x%x x%x\n", |
| 6067 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 6068 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6069 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6070 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 6071 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6072 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6073 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6074 | "0234 ReDiscovery RSCN " |
| 6075 | "Data: x%x x%x x%x\n", |
| 6076 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 6077 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6078 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6079 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 6080 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6081 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6082 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6083 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6084 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6085 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6086 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6087 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6088 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6089 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6090 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6091 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 6092 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6093 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6094 | spin_lock_irq(shost->host_lock); |
| 6095 | vport->fc_flag |= FC_RSCN_MODE; |
| 6096 | spin_unlock_irq(shost->host_lock); |
| 6097 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6098 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 6099 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6100 | /* |
| 6101 | * If we zero, cmdiocb->context2, the calling routine will |
| 6102 | * not try to free it. |
| 6103 | */ |
| 6104 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6105 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6106 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6107 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6108 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6109 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6110 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6111 | } |
| 6112 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6113 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6114 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6115 | * @vport: pointer to a host virtual N_Port data structure. |
| 6116 | * |
| 6117 | * This routine handles the Registration State Configuration Notification |
| 6118 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 6119 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 6120 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 6121 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 6122 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 6123 | * RSCN activities with the @vport. |
| 6124 | * |
| 6125 | * Return code |
| 6126 | * 0 - Cleaned up rscn on the @vport |
| 6127 | * 1 - Wait for plogi to name server before proceed |
| 6128 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6129 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6130 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6131 | { |
| 6132 | struct lpfc_nodelist *ndlp; |
| 6133 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6134 | /* Ignore RSCN if the port is being torn down. */ |
| 6135 | if (vport->load_flag & FC_UNLOADING) { |
| 6136 | lpfc_els_flush_rscn(vport); |
| 6137 | return 0; |
| 6138 | } |
| 6139 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6140 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6141 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6142 | |
| 6143 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6144 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6145 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 6146 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 6147 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6148 | |
| 6149 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6150 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 6151 | vport->num_disc_nodes = 0; |
| 6152 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6153 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6154 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 6155 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6156 | /* Good ndlp, issue CT Request to NameServer. Need to |
| 6157 | * know how many gidfts were issued. If none, then just |
| 6158 | * flush the RSCN. Otherwise, the outstanding requests |
| 6159 | * need to complete. |
| 6160 | */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 6161 | vport->gidft_inp = 0; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6162 | if (lpfc_issue_gidft(vport) > 0) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6163 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6164 | } else { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6165 | /* Nameserver login in question. Revalidate. */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6166 | if (ndlp) { |
| 6167 | ndlp = lpfc_enable_node(vport, ndlp, |
| 6168 | NLP_STE_PLOGI_ISSUE); |
| 6169 | if (!ndlp) { |
| 6170 | lpfc_els_flush_rscn(vport); |
| 6171 | return 0; |
| 6172 | } |
| 6173 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6174 | } else { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6175 | ndlp = lpfc_nlp_init(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6176 | if (!ndlp) { |
| 6177 | lpfc_els_flush_rscn(vport); |
| 6178 | return 0; |
| 6179 | } |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6180 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6181 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6182 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6183 | ndlp->nlp_type |= NLP_FABRIC; |
| 6184 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 6185 | /* Wait for NameServer login cmpl before we can |
| 6186 | * continue |
| 6187 | */ |
| 6188 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6189 | } |
| 6190 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6191 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6192 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6193 | } |
| 6194 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6195 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6196 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6197 | * @vport: pointer to a host virtual N_Port data structure. |
| 6198 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6199 | * @ndlp: pointer to a node-list data structure. |
| 6200 | * |
| 6201 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 6202 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 6203 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 6204 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 6205 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 6206 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 6207 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 6208 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 6209 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 6210 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 6211 | * higher priority (as the winning port) and will initiate PLOGI and |
| 6212 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 6213 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 6214 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 6215 | * |
| 6216 | * Return code |
| 6217 | * 0 - Successfully processed the unsolicited flogi |
| 6218 | * 1 - Failed to process the unsolicited flogi |
| 6219 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6220 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6221 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6222 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6223 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6224 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6225 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6226 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6227 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 6228 | IOCB_t *icmd = &cmdiocb->iocb; |
| 6229 | struct serv_parm *sp; |
| 6230 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6231 | uint32_t cmd, did; |
| 6232 | int rc; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6233 | uint32_t fc_flag = 0; |
| 6234 | uint32_t port_state = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6235 | |
| 6236 | cmd = *lp++; |
| 6237 | sp = (struct serv_parm *) lp; |
| 6238 | |
| 6239 | /* FLOGI received */ |
| 6240 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6241 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6242 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6243 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6244 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 6245 | did = icmd->un.elsreq64.remoteID; |
| 6246 | |
| 6247 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 6248 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6249 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6250 | "0113 An FLOGI ELS command x%x was " |
| 6251 | "received from DID x%x in Loop Mode\n", |
| 6252 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6253 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6254 | } |
| 6255 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6256 | (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6257 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6258 | /* |
| 6259 | * If our portname is greater than the remote portname, |
| 6260 | * then we initiate Nport login. |
| 6261 | */ |
| 6262 | |
| 6263 | rc = memcmp(&vport->fc_portname, &sp->portName, |
| 6264 | sizeof(struct lpfc_name)); |
| 6265 | |
| 6266 | if (!rc) { |
| 6267 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 6268 | mbox = mempool_alloc(phba->mbox_mem_pool, |
| 6269 | GFP_KERNEL); |
| 6270 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6271 | return 1; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6272 | lpfc_linkdown(phba); |
| 6273 | lpfc_init_link(phba, mbox, |
| 6274 | phba->cfg_topology, |
| 6275 | phba->cfg_link_speed); |
| 6276 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 6277 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 6278 | mbox->vport = vport; |
| 6279 | rc = lpfc_sli_issue_mbox(phba, mbox, |
| 6280 | MBX_NOWAIT); |
| 6281 | lpfc_set_loopback_flag(phba); |
| 6282 | if (rc == MBX_NOT_FINISHED) |
| 6283 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6284 | return 1; |
| 6285 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6286 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6287 | /* abort the flogi coming back to ourselves |
| 6288 | * due to external loopback on the port. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6289 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6290 | lpfc_els_abort_flogi(phba); |
| 6291 | return 0; |
| 6292 | |
| 6293 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6294 | spin_lock_irq(shost->host_lock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6295 | vport->fc_flag |= FC_PT2PT_PLOGI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6296 | spin_unlock_irq(shost->host_lock); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6297 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6298 | /* If we have the high WWPN we can assign our own |
| 6299 | * myDID; otherwise, we have to WAIT for a PLOGI |
| 6300 | * from the remote NPort to find out what it |
| 6301 | * will be. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6302 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6303 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6304 | } else { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6305 | vport->fc_myDID = PT2PT_RemoteID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6306 | } |
| 6307 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6308 | /* |
| 6309 | * The vport state should go to LPFC_FLOGI only |
| 6310 | * AFTER we issue a FLOGI, not receive one. |
| 6311 | */ |
| 6312 | spin_lock_irq(shost->host_lock); |
| 6313 | fc_flag = vport->fc_flag; |
| 6314 | port_state = vport->port_state; |
| 6315 | vport->fc_flag |= FC_PT2PT; |
| 6316 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6317 | spin_unlock_irq(shost->host_lock); |
| 6318 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6319 | "3311 Rcv Flogi PS x%x new PS x%x " |
| 6320 | "fc_flag x%x new fc_flag x%x\n", |
| 6321 | port_state, vport->port_state, |
| 6322 | fc_flag, vport->fc_flag); |
| 6323 | |
| 6324 | /* |
| 6325 | * We temporarily set fc_myDID to make it look like we are |
| 6326 | * a Fabric. This is done just so we end up with the right |
| 6327 | * did / sid on the FLOGI ACC rsp. |
| 6328 | */ |
| 6329 | did = vport->fc_myDID; |
| 6330 | vport->fc_myDID = Fabric_DID; |
| 6331 | |
| 6332 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 6333 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6334 | /* Send back ACC */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6335 | lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6336 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6337 | /* Now lets put fc_myDID back to what its supposed to be */ |
| 6338 | vport->fc_myDID = did; |
| 6339 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6340 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6341 | } |
| 6342 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6343 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6344 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6345 | * @vport: pointer to a host virtual N_Port data structure. |
| 6346 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6347 | * @ndlp: pointer to a node-list data structure. |
| 6348 | * |
| 6349 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 6350 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 6351 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 6352 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 6353 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 6354 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 6355 | * |
| 6356 | * Return code |
| 6357 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 6358 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6359 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6360 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6361 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6362 | { |
| 6363 | struct lpfc_dmabuf *pcmd; |
| 6364 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6365 | RNID *rn; |
| 6366 | struct ls_rjt stat; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6367 | uint32_t cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6368 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6369 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6370 | lp = (uint32_t *) pcmd->virt; |
| 6371 | |
| 6372 | cmd = *lp++; |
| 6373 | rn = (RNID *) lp; |
| 6374 | |
| 6375 | /* RNID received */ |
| 6376 | |
| 6377 | switch (rn->Format) { |
| 6378 | case 0: |
| 6379 | case RNID_TOPOLOGY_DISC: |
| 6380 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6381 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6382 | break; |
| 6383 | default: |
| 6384 | /* Reject this request because format not supported */ |
| 6385 | stat.un.b.lsRjtRsvd0 = 0; |
| 6386 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6387 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6388 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6389 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 6390 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6391 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6392 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6393 | } |
| 6394 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6395 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6396 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 6397 | * @vport: pointer to a host virtual N_Port data structure. |
| 6398 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6399 | * @ndlp: pointer to a node-list data structure. |
| 6400 | * |
| 6401 | * Return code |
| 6402 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 6403 | **/ |
| 6404 | static int |
| 6405 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6406 | struct lpfc_nodelist *ndlp) |
| 6407 | { |
| 6408 | uint8_t *pcmd; |
| 6409 | |
| 6410 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 6411 | |
| 6412 | /* skip over first word of echo command to find echo data */ |
| 6413 | pcmd += sizeof(uint32_t); |
| 6414 | |
| 6415 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 6416 | return 0; |
| 6417 | } |
| 6418 | |
| 6419 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6420 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6421 | * @vport: pointer to a host virtual N_Port data structure. |
| 6422 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6423 | * @ndlp: pointer to a node-list data structure. |
| 6424 | * |
| 6425 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 6426 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 6427 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 6428 | * |
| 6429 | * Return code |
| 6430 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 6431 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6432 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6433 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6434 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6435 | { |
| 6436 | struct ls_rjt stat; |
| 6437 | |
| 6438 | /* For now, unconditionally reject this command */ |
| 6439 | stat.un.b.lsRjtRsvd0 = 0; |
| 6440 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6441 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6442 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6443 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6444 | return 0; |
| 6445 | } |
| 6446 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6447 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6448 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 6449 | * @vport: pointer to a host virtual N_Port data structure. |
| 6450 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6451 | * @ndlp: pointer to a node-list data structure. |
| 6452 | * |
| 6453 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 6454 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 6455 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 6456 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 6457 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 6458 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 6459 | * command request" and reason code explanation "Invalid Originator |
| 6460 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 6461 | * RRQ from the target. |
| 6462 | **/ |
| 6463 | static void |
| 6464 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6465 | struct lpfc_nodelist *ndlp) |
| 6466 | { |
| 6467 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6468 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 6469 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6470 | } |
| 6471 | |
| 6472 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6473 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 6474 | * @phba: pointer to lpfc hba data structure. |
| 6475 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6476 | * |
| 6477 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 6478 | * mailbox command. This callback function is to actually send the Accept |
| 6479 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 6480 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 6481 | * mailbox command, constructs the RPS response with the link statistics |
| 6482 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 6483 | * response to the RPS. |
| 6484 | * |
| 6485 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6486 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6487 | * will be stored into the context1 field of the IOCB for the completion |
| 6488 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6489 | * |
| 6490 | **/ |
| 6491 | static void |
| 6492 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6493 | { |
| 6494 | MAILBOX_t *mb; |
| 6495 | IOCB_t *icmd; |
| 6496 | struct RLS_RSP *rls_rsp; |
| 6497 | uint8_t *pcmd; |
| 6498 | struct lpfc_iocbq *elsiocb; |
| 6499 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6500 | uint16_t oxid; |
| 6501 | uint16_t rxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6502 | uint32_t cmdsize; |
| 6503 | |
| 6504 | mb = &pmb->u.mb; |
| 6505 | |
| 6506 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6507 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 6508 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6509 | pmb->context1 = NULL; |
| 6510 | pmb->context2 = NULL; |
| 6511 | |
| 6512 | if (mb->mbxStatus) { |
| 6513 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6514 | return; |
| 6515 | } |
| 6516 | |
| 6517 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6518 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6519 | lpfc_max_els_tries, ndlp, |
| 6520 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6521 | |
| 6522 | /* Decrement the ndlp reference count from previous mbox command */ |
| 6523 | lpfc_nlp_put(ndlp); |
| 6524 | |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6525 | if (!elsiocb) { |
| 6526 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6527 | return; |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6528 | } |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6529 | |
| 6530 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6531 | icmd->ulpContext = rxid; |
| 6532 | icmd->unsli3.rcvsli3.ox_id = oxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6533 | |
| 6534 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6535 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6536 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 6537 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 6538 | |
| 6539 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 6540 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 6541 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 6542 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 6543 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 6544 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6545 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6546 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 6547 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6548 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 6549 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 6550 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6551 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6552 | ndlp->nlp_rpi); |
| 6553 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6554 | phba->fc_stat.elsXmitACC++; |
| 6555 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 6556 | lpfc_els_free_iocb(phba, elsiocb); |
| 6557 | } |
| 6558 | |
| 6559 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6560 | * 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] | 6561 | * @phba: pointer to lpfc hba data structure. |
| 6562 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6563 | * |
| 6564 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 6565 | * mailbox command. This callback function is to actually send the Accept |
| 6566 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 6567 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 6568 | * mailbox command, constructs the RPS response with the link statistics |
| 6569 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 6570 | * response to the RPS. |
| 6571 | * |
| 6572 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6573 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6574 | * will be stored into the context1 field of the IOCB for the completion |
| 6575 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6576 | * |
| 6577 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 6578 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6579 | 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] | 6580 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6581 | MAILBOX_t *mb; |
| 6582 | IOCB_t *icmd; |
| 6583 | RPS_RSP *rps_rsp; |
| 6584 | uint8_t *pcmd; |
| 6585 | struct lpfc_iocbq *elsiocb; |
| 6586 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6587 | uint16_t status; |
| 6588 | uint16_t oxid; |
| 6589 | uint16_t rxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6590 | uint32_t cmdsize; |
| 6591 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6592 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6593 | |
| 6594 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6595 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 6596 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 6597 | pmb->context1 = NULL; |
| 6598 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6599 | |
| 6600 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6601 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6602 | return; |
| 6603 | } |
| 6604 | |
| 6605 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6606 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6607 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6608 | lpfc_max_els_tries, ndlp, |
| 6609 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6610 | |
| 6611 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6612 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6613 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6614 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6615 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6616 | |
| 6617 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6618 | icmd->ulpContext = rxid; |
| 6619 | icmd->unsli3.rcvsli3.ox_id = oxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6620 | |
| 6621 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6622 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6623 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6624 | rps_rsp = (RPS_RSP *)pcmd; |
| 6625 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6626 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6627 | status = 0x10; |
| 6628 | else |
| 6629 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6630 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6631 | status |= 0x4; |
| 6632 | |
| 6633 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6634 | rps_rsp->portStatus = cpu_to_be16(status); |
| 6635 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 6636 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 6637 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 6638 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 6639 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 6640 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6641 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6642 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6643 | "0118 Xmit ELS RPS 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); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6648 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6649 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6650 | 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] | 6651 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6652 | return; |
| 6653 | } |
| 6654 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6655 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6656 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 6657 | * @vport: pointer to a host virtual N_Port data structure. |
| 6658 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6659 | * @ndlp: pointer to a node-list data structure. |
| 6660 | * |
| 6661 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 6662 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6663 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6664 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 6665 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 6666 | * for reading the HBA link statistics. It is for the callback function, |
| 6667 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 6668 | * to actually sending out RPL Accept (ACC) response. |
| 6669 | * |
| 6670 | * Return codes |
| 6671 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 6672 | **/ |
| 6673 | static int |
| 6674 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6675 | struct lpfc_nodelist *ndlp) |
| 6676 | { |
| 6677 | struct lpfc_hba *phba = vport->phba; |
| 6678 | LPFC_MBOXQ_t *mbox; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6679 | struct ls_rjt stat; |
| 6680 | |
| 6681 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6682 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6683 | /* reject the unsolicited RPS request and done with it */ |
| 6684 | goto reject_out; |
| 6685 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6686 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 6687 | if (mbox) { |
| 6688 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6689 | mbox->context1 = (void *)((unsigned long) |
| 6690 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 6691 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6692 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6693 | mbox->vport = vport; |
| 6694 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 6695 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 6696 | != MBX_NOT_FINISHED) |
| 6697 | /* Mbox completion will send ELS Response */ |
| 6698 | return 0; |
| 6699 | /* Decrement reference count used for the failed mbox |
| 6700 | * command. |
| 6701 | */ |
| 6702 | lpfc_nlp_put(ndlp); |
| 6703 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6704 | } |
| 6705 | reject_out: |
| 6706 | /* issue rejection response */ |
| 6707 | stat.un.b.lsRjtRsvd0 = 0; |
| 6708 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6709 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6710 | stat.un.b.vendorUnique = 0; |
| 6711 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6712 | return 0; |
| 6713 | } |
| 6714 | |
| 6715 | /** |
| 6716 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 6717 | * @vport: pointer to a host virtual N_Port data structure. |
| 6718 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6719 | * @ndlp: pointer to a node-list data structure. |
| 6720 | * |
| 6721 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 6722 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6723 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6724 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 6725 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 6726 | * Value (RTV) unsolicited IOCB event. |
| 6727 | * |
| 6728 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6729 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6730 | * will be stored into the context1 field of the IOCB for the completion |
| 6731 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6732 | * |
| 6733 | * Return codes |
| 6734 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 6735 | **/ |
| 6736 | static int |
| 6737 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6738 | struct lpfc_nodelist *ndlp) |
| 6739 | { |
| 6740 | struct lpfc_hba *phba = vport->phba; |
| 6741 | struct ls_rjt stat; |
| 6742 | struct RTV_RSP *rtv_rsp; |
| 6743 | uint8_t *pcmd; |
| 6744 | struct lpfc_iocbq *elsiocb; |
| 6745 | uint32_t cmdsize; |
| 6746 | |
| 6747 | |
| 6748 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6749 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6750 | /* reject the unsolicited RPS request and done with it */ |
| 6751 | goto reject_out; |
| 6752 | |
| 6753 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 6754 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6755 | lpfc_max_els_tries, ndlp, |
| 6756 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6757 | |
| 6758 | if (!elsiocb) |
| 6759 | return 1; |
| 6760 | |
| 6761 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6762 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6763 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 6764 | |
| 6765 | /* use the command's xri in the response */ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6766 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 6767 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6768 | |
| 6769 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 6770 | |
| 6771 | /* populate RTV payload */ |
| 6772 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 6773 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 6774 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 6775 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 6776 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 6777 | |
| 6778 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 6779 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6780 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 6781 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 6782 | "Data: x%x x%x x%x\n", |
| 6783 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6784 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6785 | ndlp->nlp_rpi, |
| 6786 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 6787 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6788 | phba->fc_stat.elsXmitACC++; |
| 6789 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 6790 | lpfc_els_free_iocb(phba, elsiocb); |
| 6791 | return 0; |
| 6792 | |
| 6793 | reject_out: |
| 6794 | /* issue rejection response */ |
| 6795 | stat.un.b.lsRjtRsvd0 = 0; |
| 6796 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6797 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6798 | stat.un.b.vendorUnique = 0; |
| 6799 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6800 | return 0; |
| 6801 | } |
| 6802 | |
| 6803 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6804 | * @vport: pointer to a host virtual N_Port data structure. |
| 6805 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6806 | * @ndlp: pointer to a node-list data structure. |
| 6807 | * |
| 6808 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 6809 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6810 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6811 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 6812 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 6813 | * for reading the HBA link statistics. It is for the callback function, |
| 6814 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 6815 | * to actually sending out RPS Accept (ACC) response. |
| 6816 | * |
| 6817 | * Return codes |
| 6818 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 6819 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6820 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6821 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6822 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6823 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6824 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6825 | uint32_t *lp; |
| 6826 | uint8_t flag; |
| 6827 | LPFC_MBOXQ_t *mbox; |
| 6828 | struct lpfc_dmabuf *pcmd; |
| 6829 | RPS *rps; |
| 6830 | struct ls_rjt stat; |
| 6831 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6832 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6833 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6834 | /* reject the unsolicited RPS request and done with it */ |
| 6835 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6836 | |
| 6837 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6838 | lp = (uint32_t *) pcmd->virt; |
| 6839 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 6840 | rps = (RPS *) lp; |
| 6841 | |
| 6842 | if ((flag == 0) || |
| 6843 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6844 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6845 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6846 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6847 | printk("Fix me....\n"); |
| 6848 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6849 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 6850 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6851 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6852 | mbox->context1 = (void *)((unsigned long) |
| 6853 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 6854 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6855 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6856 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6857 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6858 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6859 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6860 | /* Mbox completion will send ELS Response */ |
| 6861 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6862 | /* Decrement reference count used for the failed mbox |
| 6863 | * command. |
| 6864 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6865 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6866 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6867 | } |
| 6868 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6869 | |
| 6870 | reject_out: |
| 6871 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6872 | stat.un.b.lsRjtRsvd0 = 0; |
| 6873 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6874 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6875 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6876 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6877 | return 0; |
| 6878 | } |
| 6879 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6880 | /* lpfc_issue_els_rrq - Process an unsolicited rps iocb |
| 6881 | * @vport: pointer to a host virtual N_Port data structure. |
| 6882 | * @ndlp: pointer to a node-list data structure. |
| 6883 | * @did: DID of the target. |
| 6884 | * @rrq: Pointer to the rrq struct. |
| 6885 | * |
| 6886 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is |
| 6887 | * Successful the the completion handler will clear the RRQ. |
| 6888 | * |
| 6889 | * Return codes |
| 6890 | * 0 - Successfully sent rrq els iocb. |
| 6891 | * 1 - Failed to send rrq els iocb. |
| 6892 | **/ |
| 6893 | static int |
| 6894 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6895 | uint32_t did, struct lpfc_node_rrq *rrq) |
| 6896 | { |
| 6897 | struct lpfc_hba *phba = vport->phba; |
| 6898 | struct RRQ *els_rrq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6899 | struct lpfc_iocbq *elsiocb; |
| 6900 | uint8_t *pcmd; |
| 6901 | uint16_t cmdsize; |
| 6902 | int ret; |
| 6903 | |
| 6904 | |
| 6905 | if (ndlp != rrq->ndlp) |
| 6906 | ndlp = rrq->ndlp; |
| 6907 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 6908 | return 1; |
| 6909 | |
| 6910 | /* If ndlp is not NULL, we will bump the reference count on it */ |
| 6911 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); |
| 6912 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, |
| 6913 | ELS_CMD_RRQ); |
| 6914 | if (!elsiocb) |
| 6915 | return 1; |
| 6916 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6917 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6918 | |
| 6919 | /* For RRQ request, remainder of payload is Exchange IDs */ |
| 6920 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; |
| 6921 | pcmd += sizeof(uint32_t); |
| 6922 | els_rrq = (struct RRQ *) pcmd; |
| 6923 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 6924 | 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] | 6925 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
| 6926 | bf_set(rrq_did, els_rrq, vport->fc_myDID); |
| 6927 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); |
| 6928 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); |
| 6929 | |
| 6930 | |
| 6931 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6932 | "Issue RRQ: did:x%x", |
| 6933 | did, rrq->xritag, rrq->rxid); |
| 6934 | elsiocb->context_un.rrq = rrq; |
| 6935 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; |
| 6936 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6937 | |
| 6938 | if (ret == IOCB_ERROR) { |
| 6939 | lpfc_els_free_iocb(phba, elsiocb); |
| 6940 | return 1; |
| 6941 | } |
| 6942 | return 0; |
| 6943 | } |
| 6944 | |
| 6945 | /** |
| 6946 | * lpfc_send_rrq - Sends ELS RRQ if needed. |
| 6947 | * @phba: pointer to lpfc hba data structure. |
| 6948 | * @rrq: pointer to the active rrq. |
| 6949 | * |
| 6950 | * This routine will call the lpfc_issue_els_rrq if the rrq is |
| 6951 | * still active for the xri. If this function returns a failure then |
| 6952 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. |
| 6953 | * |
| 6954 | * Returns 0 Success. |
| 6955 | * 1 Failure. |
| 6956 | **/ |
| 6957 | int |
| 6958 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) |
| 6959 | { |
| 6960 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, |
| 6961 | rrq->nlp_DID); |
| 6962 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) |
| 6963 | return lpfc_issue_els_rrq(rrq->vport, ndlp, |
| 6964 | rrq->nlp_DID, rrq); |
| 6965 | else |
| 6966 | return 1; |
| 6967 | } |
| 6968 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6969 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6970 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6971 | * @vport: pointer to a host virtual N_Port data structure. |
| 6972 | * @cmdsize: size of the ELS command. |
| 6973 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 6974 | * @ndlp: pointer to a node-list data structure. |
| 6975 | * |
| 6976 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 6977 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 6978 | * |
| 6979 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6980 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6981 | * will be stored into the context1 field of the IOCB for the completion |
| 6982 | * callback function to the RPL Accept Response ELS command. |
| 6983 | * |
| 6984 | * Return code |
| 6985 | * 0 - Successfully issued ACC RPL ELS command |
| 6986 | * 1 - Failed to issue ACC RPL ELS command |
| 6987 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 6988 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6989 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 6990 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6991 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6992 | struct lpfc_hba *phba = vport->phba; |
| 6993 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6994 | RPL_RSP rpl_rsp; |
| 6995 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6996 | uint8_t *pcmd; |
| 6997 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6998 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 6999 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7000 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 7001 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7002 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 7003 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7004 | icmd = &elsiocb->iocb; |
| 7005 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7006 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 7007 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7008 | |
| 7009 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7010 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7011 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7012 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 7013 | pcmd += sizeof(uint16_t); |
| 7014 | |
| 7015 | /* Setup the RPL ACC payload */ |
| 7016 | rpl_rsp.listLen = be32_to_cpu(1); |
| 7017 | rpl_rsp.index = 0; |
| 7018 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7019 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 7020 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7021 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7022 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7023 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7024 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7025 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 7026 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 7027 | "rpi x%x\n", |
| 7028 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 7029 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 7030 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7031 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7032 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7033 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 7034 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7035 | lpfc_els_free_iocb(phba, elsiocb); |
| 7036 | return 1; |
| 7037 | } |
| 7038 | return 0; |
| 7039 | } |
| 7040 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7041 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7042 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7043 | * @vport: pointer to a host virtual N_Port data structure. |
| 7044 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7045 | * @ndlp: pointer to a node-list data structure. |
| 7046 | * |
| 7047 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 7048 | * unsolicited event. It first checks the remote port state. If the remote |
| 7049 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 7050 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 7051 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 7052 | * to accept the RPL. |
| 7053 | * |
| 7054 | * Return code |
| 7055 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 7056 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7057 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7058 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7059 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7060 | { |
| 7061 | struct lpfc_dmabuf *pcmd; |
| 7062 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7063 | uint32_t maxsize; |
| 7064 | uint16_t cmdsize; |
| 7065 | RPL *rpl; |
| 7066 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7067 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 7068 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 7069 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 7070 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7071 | stat.un.b.lsRjtRsvd0 = 0; |
| 7072 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7073 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7074 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7075 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 7076 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 7077 | /* rejected the unsolicited RPL request and done with it */ |
| 7078 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7079 | } |
| 7080 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7081 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7082 | lp = (uint32_t *) pcmd->virt; |
| 7083 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7084 | maxsize = be32_to_cpu(rpl->maxsize); |
| 7085 | |
| 7086 | /* We support only one port */ |
| 7087 | if ((rpl->index == 0) && |
| 7088 | ((maxsize == 0) || |
| 7089 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 7090 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 7091 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7092 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 7093 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7094 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7095 | |
| 7096 | return 0; |
| 7097 | } |
| 7098 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7099 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7100 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7101 | * @vport: pointer to a virtual N_Port data structure. |
| 7102 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7103 | * @ndlp: pointer to a node-list data structure. |
| 7104 | * |
| 7105 | * This routine processes Fibre Channel Address Resolution Protocol |
| 7106 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 7107 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 7108 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 7109 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 7110 | * remote PortName is compared against the FC PortName stored in the @vport |
| 7111 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 7112 | * compared against the FC NodeName stored in the @vport data structure. |
| 7113 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 7114 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 7115 | * invoked to send out FARP Response to the remote node. Before sending the |
| 7116 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 7117 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 7118 | * routine is invoked to log into the remote port first. |
| 7119 | * |
| 7120 | * Return code |
| 7121 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 7122 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7123 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7124 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7125 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7126 | { |
| 7127 | struct lpfc_dmabuf *pcmd; |
| 7128 | uint32_t *lp; |
| 7129 | IOCB_t *icmd; |
| 7130 | FARP *fp; |
| 7131 | uint32_t cmd, cnt, did; |
| 7132 | |
| 7133 | icmd = &cmdiocb->iocb; |
| 7134 | did = icmd->un.elsreq64.remoteID; |
| 7135 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7136 | lp = (uint32_t *) pcmd->virt; |
| 7137 | |
| 7138 | cmd = *lp++; |
| 7139 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7140 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7141 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7142 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7143 | /* We will only support match on WWPN or WWNN */ |
| 7144 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7145 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7146 | } |
| 7147 | |
| 7148 | cnt = 0; |
| 7149 | /* If this FARP command is searching for my portname */ |
| 7150 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7151 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7152 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7153 | cnt = 1; |
| 7154 | } |
| 7155 | |
| 7156 | /* If this FARP command is searching for my nodename */ |
| 7157 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7158 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7159 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7160 | cnt = 1; |
| 7161 | } |
| 7162 | |
| 7163 | if (cnt) { |
| 7164 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 7165 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 7166 | /* Log back into the node before sending the FARP. */ |
| 7167 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7168 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7169 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 7170 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7171 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7172 | } |
| 7173 | |
| 7174 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7175 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 7176 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7177 | } |
| 7178 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7179 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7180 | } |
| 7181 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7182 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7183 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7184 | * @vport: pointer to a host virtual N_Port data structure. |
| 7185 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7186 | * @ndlp: pointer to a node-list data structure. |
| 7187 | * |
| 7188 | * This routine processes Fibre Channel Address Resolution Protocol |
| 7189 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 7190 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 7191 | * the FARP response request. |
| 7192 | * |
| 7193 | * Return code |
| 7194 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 7195 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7196 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7197 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7198 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7199 | { |
| 7200 | struct lpfc_dmabuf *pcmd; |
| 7201 | uint32_t *lp; |
| 7202 | IOCB_t *icmd; |
| 7203 | uint32_t cmd, did; |
| 7204 | |
| 7205 | icmd = &cmdiocb->iocb; |
| 7206 | did = icmd->un.elsreq64.remoteID; |
| 7207 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7208 | lp = (uint32_t *) pcmd->virt; |
| 7209 | |
| 7210 | cmd = *lp++; |
| 7211 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7212 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7213 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7214 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7215 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7216 | |
| 7217 | return 0; |
| 7218 | } |
| 7219 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7220 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7221 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7222 | * @vport: pointer to a host virtual N_Port data structure. |
| 7223 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7224 | * @fan_ndlp: pointer to a node-list data structure. |
| 7225 | * |
| 7226 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 7227 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 7228 | * only be processed on a physical port (i.e., the @vport represents the |
| 7229 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 7230 | * compared against those in the phba data structure. If any of those is |
| 7231 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 7232 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 7233 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 7234 | * is invoked to register login to the fabric. |
| 7235 | * |
| 7236 | * Return code |
| 7237 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 7238 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7239 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7240 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7241 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7242 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7243 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7244 | uint32_t *lp; |
| 7245 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7246 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7247 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 7248 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 7249 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7250 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7251 | if ((vport == phba->pport) && |
| 7252 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7253 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7254 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7255 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7256 | sizeof(struct lpfc_name)))) { |
| 7257 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7258 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7259 | } else { |
| 7260 | /* FAN verified - skip FLOGI */ |
| 7261 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7262 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 7263 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7264 | else { |
| 7265 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7266 | "3138 Need register VFI: (x%x/%x)\n", |
| 7267 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7268 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7269 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7270 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7271 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7272 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7273 | } |
| 7274 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7275 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7276 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7277 | * @ptr: holder for the timer function associated data. |
| 7278 | * |
| 7279 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 7280 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 7281 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 7282 | * up the worker thread. It is for the worker thread to invoke the routine |
| 7283 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 7284 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7285 | void |
| 7286 | lpfc_els_timeout(unsigned long ptr) |
| 7287 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7288 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 7289 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7290 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7291 | unsigned long iflag; |
| 7292 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7293 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7294 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7295 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7296 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7297 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7298 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7299 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7300 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7301 | return; |
| 7302 | } |
| 7303 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7304 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7305 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7306 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7307 | * @vport: pointer to a virtual N_Port data structure. |
| 7308 | * |
| 7309 | * This routine is the actual handler function that processes an ELS timeout |
| 7310 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 7311 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 7312 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 7313 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7314 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7315 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7316 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7317 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7318 | struct lpfc_sli_ring *pring; |
| 7319 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7320 | IOCB_t *cmd = NULL; |
| 7321 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7322 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7323 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7324 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7325 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7326 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7327 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7328 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 7329 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7330 | pring = lpfc_phba_elsring(phba); |
| 7331 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7332 | if ((phba->pport->load_flag & FC_UNLOADING)) |
| 7333 | return; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7334 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7335 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7336 | spin_lock(&pring->ring_lock); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7337 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7338 | if ((phba->pport->load_flag & FC_UNLOADING)) { |
| 7339 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7340 | spin_unlock(&pring->ring_lock); |
| 7341 | spin_unlock_irq(&phba->hbalock); |
| 7342 | return; |
| 7343 | } |
| 7344 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7345 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7346 | cmd = &piocb->iocb; |
| 7347 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7348 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 7349 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 7350 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7351 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7352 | |
| 7353 | if (piocb->vport != vport) |
| 7354 | continue; |
| 7355 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7356 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7357 | if (pcmd) |
| 7358 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7359 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7360 | if (els_command == ELS_CMD_FARP || |
| 7361 | els_command == ELS_CMD_FARPR || |
| 7362 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7363 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7364 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7365 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7366 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7367 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7368 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7369 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7370 | continue; |
| 7371 | } |
| 7372 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7373 | remote_ID = 0xffffffff; |
| 7374 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7375 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7376 | else { |
| 7377 | struct lpfc_nodelist *ndlp; |
| 7378 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7379 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7380 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7381 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7382 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7383 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7384 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7385 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7386 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 7387 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7388 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
James Smart | 15026c9 | 2013-12-17 20:30:09 -0500 | [diff] [blame] | 7389 | cmd = &piocb->iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7390 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7391 | "0127 ELS timeout Data: x%x x%x x%x " |
| 7392 | "x%x\n", els_command, |
| 7393 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 7394 | spin_lock_irq(&phba->hbalock); |
| 7395 | list_del_init(&piocb->dlist); |
| 7396 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 7397 | spin_unlock_irq(&phba->hbalock); |
| 7398 | } |
| 7399 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7400 | if (!list_empty(&pring->txcmplq)) |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7401 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 7402 | mod_timer(&vport->els_tmofunc, |
| 7403 | jiffies + msecs_to_jiffies(1000 * timeout)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7404 | } |
| 7405 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7406 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7407 | * 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] | 7408 | * @vport: pointer to a host virtual N_Port data structure. |
| 7409 | * |
| 7410 | * This routine is used to clean up all the outstanding ELS commands on a |
| 7411 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 7412 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 7413 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 7414 | * the IOCBs with a non-NULL completion callback function, the callback |
| 7415 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 7416 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 7417 | * callback function, the IOCB will simply be released. Finally, it walks |
| 7418 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 7419 | * completion queue IOCB that is associated with the @vport and is not |
| 7420 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 7421 | * part of the discovery state machine) out to HBA by invoking the |
| 7422 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 7423 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 7424 | * the IOCBs are aborted when this function returns. |
| 7425 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7426 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7427 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7428 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7429 | LIST_HEAD(abort_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7430 | struct lpfc_hba *phba = vport->phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7431 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7432 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7433 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7434 | |
| 7435 | lpfc_fabric_abort_vport(vport); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7436 | /* |
| 7437 | * For SLI3, only the hbalock is required. But SLI4 needs to coordinate |
| 7438 | * with the ring insert operation. Because lpfc_sli_issue_abort_iotag |
| 7439 | * ultimately grabs the ring_lock, the driver must splice the list into |
| 7440 | * a working list and release the locks before calling the abort. |
| 7441 | */ |
| 7442 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7443 | pring = lpfc_phba_elsring(phba); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7444 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7445 | spin_lock(&pring->ring_lock); |
| 7446 | |
| 7447 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 7448 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 7449 | continue; |
| 7450 | |
| 7451 | if (piocb->vport != vport) |
| 7452 | continue; |
| 7453 | list_add_tail(&piocb->dlist, &abort_list); |
| 7454 | } |
| 7455 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7456 | spin_unlock(&pring->ring_lock); |
| 7457 | spin_unlock_irq(&phba->hbalock); |
| 7458 | /* Abort each iocb on the aborted list and remove the dlist links. */ |
| 7459 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 7460 | spin_lock_irq(&phba->hbalock); |
| 7461 | list_del_init(&piocb->dlist); |
| 7462 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 7463 | spin_unlock_irq(&phba->hbalock); |
| 7464 | } |
| 7465 | if (!list_empty(&abort_list)) |
| 7466 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7467 | "3387 abort list for txq not empty\n"); |
| 7468 | INIT_LIST_HEAD(&abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7469 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7470 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7471 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7472 | spin_lock(&pring->ring_lock); |
| 7473 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7474 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 7475 | cmd = &piocb->iocb; |
| 7476 | |
| 7477 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 7478 | continue; |
| 7479 | } |
| 7480 | |
| 7481 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7482 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 7483 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 7484 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 7485 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7486 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7487 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7488 | if (piocb->vport != vport) |
| 7489 | continue; |
| 7490 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7491 | list_del_init(&piocb->list); |
| 7492 | list_add_tail(&piocb->list, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7493 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7494 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7495 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7496 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 7497 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7498 | /* Cancell all the IOCBs from the completions list */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7499 | lpfc_sli_cancel_iocbs(phba, &abort_list, |
| 7500 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 7501 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7502 | return; |
| 7503 | } |
| 7504 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7505 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7506 | * 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] | 7507 | * @phba: pointer to lpfc hba data structure. |
| 7508 | * |
| 7509 | * This routine is used to clean up all the outstanding ELS commands on a |
| 7510 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 7511 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 7512 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 7513 | * the IOCBs with the completion callback function associated, the callback |
| 7514 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 7515 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 7516 | * callback function associated, the IOCB will simply be released. Finally, |
| 7517 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 7518 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 7519 | * management plane IOCBs that are not part of the discovery state machine) |
| 7520 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 7521 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 7522 | void |
| 7523 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 7524 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7525 | struct lpfc_vport *vport; |
| 7526 | list_for_each_entry(vport, &phba->port_list, listentry) |
| 7527 | lpfc_els_flush_cmd(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7528 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 7529 | return; |
| 7530 | } |
| 7531 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7532 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7533 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7534 | * @phba: Pointer to hba context object. |
| 7535 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 7536 | * @rspiocbp: Pointer to response iocb which reported error. |
| 7537 | * |
| 7538 | * This function sends an event when there is an ELS command |
| 7539 | * failure. |
| 7540 | **/ |
| 7541 | void |
| 7542 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 7543 | struct lpfc_iocbq *cmdiocbp, |
| 7544 | struct lpfc_iocbq *rspiocbp) |
| 7545 | { |
| 7546 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 7547 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7548 | struct lpfc_lsrjt_event lsrjt_event; |
| 7549 | struct lpfc_fabric_event_header fabric_event; |
| 7550 | struct ls_rjt stat; |
| 7551 | struct lpfc_nodelist *ndlp; |
| 7552 | uint32_t *pcmd; |
| 7553 | |
| 7554 | ndlp = cmdiocbp->context1; |
| 7555 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 7556 | return; |
| 7557 | |
| 7558 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 7559 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 7560 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 7561 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 7562 | sizeof(struct lpfc_name)); |
| 7563 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 7564 | sizeof(struct lpfc_name)); |
| 7565 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 7566 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7567 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7568 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 7569 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 7570 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 7571 | fc_host_post_vendor_event(shost, |
| 7572 | fc_get_event_number(), |
| 7573 | sizeof(lsrjt_event), |
| 7574 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7575 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7576 | return; |
| 7577 | } |
| 7578 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 7579 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 7580 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 7581 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 7582 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 7583 | else |
| 7584 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 7585 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 7586 | sizeof(struct lpfc_name)); |
| 7587 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 7588 | sizeof(struct lpfc_name)); |
| 7589 | fc_host_post_vendor_event(shost, |
| 7590 | fc_get_event_number(), |
| 7591 | sizeof(fabric_event), |
| 7592 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7593 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7594 | return; |
| 7595 | } |
| 7596 | |
| 7597 | } |
| 7598 | |
| 7599 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7600 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7601 | * @vport: Pointer to vport object. |
| 7602 | * @ndlp: Pointer FC node object. |
| 7603 | * @cmd: ELS command code. |
| 7604 | * |
| 7605 | * This function posts an event when there is an incoming |
| 7606 | * unsolicited ELS command. |
| 7607 | **/ |
| 7608 | static void |
| 7609 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 7610 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7611 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7612 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7613 | struct lpfc_els_event_header *els_data = NULL; |
| 7614 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7615 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7616 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7617 | if (*payload == ELS_CMD_LOGO) { |
| 7618 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 7619 | if (!logo_data) { |
| 7620 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7621 | "0148 Failed to allocate memory " |
| 7622 | "for LOGO event\n"); |
| 7623 | return; |
| 7624 | } |
| 7625 | els_data = &logo_data->header; |
| 7626 | } else { |
| 7627 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 7628 | GFP_KERNEL); |
| 7629 | if (!els_data) { |
| 7630 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7631 | "0149 Failed to allocate memory " |
| 7632 | "for ELS event\n"); |
| 7633 | return; |
| 7634 | } |
| 7635 | } |
| 7636 | els_data->event_type = FC_REG_ELS_EVENT; |
| 7637 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7638 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7639 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7640 | break; |
| 7641 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7642 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7643 | break; |
| 7644 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7645 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 7646 | break; |
| 7647 | case ELS_CMD_LOGO: |
| 7648 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 7649 | /* Copy the WWPN in the LOGO payload */ |
| 7650 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 7651 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7652 | break; |
| 7653 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 7654 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7655 | return; |
| 7656 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7657 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 7658 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 7659 | if (*payload == ELS_CMD_LOGO) { |
| 7660 | fc_host_post_vendor_event(shost, |
| 7661 | fc_get_event_number(), |
| 7662 | sizeof(struct lpfc_logo_event), |
| 7663 | (char *)logo_data, |
| 7664 | LPFC_NL_VENDOR_ID); |
| 7665 | kfree(logo_data); |
| 7666 | } else { |
| 7667 | fc_host_post_vendor_event(shost, |
| 7668 | fc_get_event_number(), |
| 7669 | sizeof(struct lpfc_els_event_header), |
| 7670 | (char *)els_data, |
| 7671 | LPFC_NL_VENDOR_ID); |
| 7672 | kfree(els_data); |
| 7673 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7674 | |
| 7675 | return; |
| 7676 | } |
| 7677 | |
| 7678 | |
| 7679 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7680 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7681 | * @phba: pointer to lpfc hba data structure. |
| 7682 | * @pring: pointer to a SLI ring. |
| 7683 | * @vport: pointer to a host virtual N_Port data structure. |
| 7684 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 7685 | * |
| 7686 | * This routine is used for processing the IOCB associated with a unsolicited |
| 7687 | * event. It first determines whether there is an existing ndlp that matches |
| 7688 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 7689 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 7690 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 7691 | * of the discovery state machine. |
| 7692 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7693 | static void |
| 7694 | 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] | 7695 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7696 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7697 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7698 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7699 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7700 | uint32_t *payload; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7701 | uint32_t cmd, did, newnode; |
| 7702 | uint8_t rjt_exp, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7703 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7704 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7705 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7706 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7707 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7708 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7709 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 7710 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7711 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 7712 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7713 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7714 | did = icmd->un.rcvels.remoteID; |
| 7715 | if (icmd->ulpStatus) { |
| 7716 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7717 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 7718 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7719 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7720 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7721 | |
| 7722 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7723 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7724 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7725 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7726 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7727 | if (vport->load_flag & FC_UNLOADING) |
| 7728 | goto dropit; |
| 7729 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7730 | /* If NPort discovery is delayed drop incoming ELS */ |
| 7731 | if ((vport->fc_flag & FC_DISC_DELAYED) && |
| 7732 | (cmd != ELS_CMD_PLOGI)) |
| 7733 | goto dropit; |
| 7734 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7735 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7736 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7737 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 7738 | ndlp = lpfc_nlp_init(vport, did); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7739 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7740 | goto dropit; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7741 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7742 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7743 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7744 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7745 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 7746 | ndlp = lpfc_enable_node(vport, ndlp, |
| 7747 | NLP_STE_UNUSED_NODE); |
| 7748 | if (!ndlp) |
| 7749 | goto dropit; |
| 7750 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 7751 | newnode = 1; |
| 7752 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 7753 | ndlp->nlp_type |= NLP_FABRIC; |
| 7754 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 7755 | /* This is similar to the new node path */ |
| 7756 | ndlp = lpfc_nlp_get(ndlp); |
| 7757 | if (!ndlp) |
| 7758 | goto dropit; |
| 7759 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 7760 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7761 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7762 | |
| 7763 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7764 | |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7765 | /* |
| 7766 | * Do not process any unsolicited ELS commands |
| 7767 | * if the ndlp is in DEV_LOSS |
| 7768 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 7769 | shost = lpfc_shost_from_vport(vport); |
| 7770 | spin_lock_irq(shost->host_lock); |
| 7771 | if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) { |
| 7772 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7773 | goto dropit; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 7774 | } |
| 7775 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7776 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7777 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7778 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7779 | |
| 7780 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 7781 | cmd &= ELS_CMD_MASK; |
| 7782 | } |
| 7783 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7784 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7785 | "0112 ELS command x%x received from NPORT x%x " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7786 | "Data: x%x x%x x%x x%x\n", |
| 7787 | cmd, did, vport->port_state, vport->fc_flag, |
| 7788 | vport->fc_myDID, vport->fc_prevDID); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7789 | |
| 7790 | /* reject till our FLOGI completes */ |
| 7791 | if ((vport->port_state < LPFC_FABRIC_CFG_LINK) && |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7792 | (cmd != ELS_CMD_FLOGI)) { |
James Smart | 401304c | 2016-10-13 15:06:14 -0700 | [diff] [blame] | 7793 | rjt_err = LSRJT_LOGICAL_BSY; |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7794 | rjt_exp = LSEXP_NOTHING_MORE; |
| 7795 | goto lsrjt; |
| 7796 | } |
| 7797 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7798 | switch (cmd) { |
| 7799 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7800 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7801 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 7802 | did, vport->port_state, ndlp->nlp_flag); |
| 7803 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7804 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7805 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7806 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 7807 | (phba->pport->fc_flag & FC_PT2PT)) { |
| 7808 | vport->fc_prevDID = vport->fc_myDID; |
| 7809 | /* Our DID needs to be updated before registering |
| 7810 | * the vfi. This is done in lpfc_rcv_plogi but |
| 7811 | * that is called after the reg_vfi. |
| 7812 | */ |
| 7813 | vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo; |
| 7814 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7815 | "3312 Remote port assigned DID x%x " |
| 7816 | "%x\n", vport->fc_myDID, |
| 7817 | vport->fc_prevDID); |
| 7818 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7819 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7820 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7821 | |
| 7822 | /* If Nport discovery is delayed, reject PLOGIs */ |
| 7823 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 7824 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7825 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7826 | break; |
| 7827 | } |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7828 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7829 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 7830 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 7831 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 7832 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7833 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 7834 | break; |
| 7835 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7836 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7837 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7838 | spin_lock_irq(shost->host_lock); |
| 7839 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 7840 | spin_unlock_irq(shost->host_lock); |
| 7841 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7842 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7843 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7844 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7845 | break; |
| 7846 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7847 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7848 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 7849 | did, vport->port_state, ndlp->nlp_flag); |
| 7850 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7851 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7852 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7853 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7854 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7855 | break; |
| 7856 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7857 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7858 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 7859 | did, vport->port_state, ndlp->nlp_flag); |
| 7860 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7861 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7862 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7863 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7864 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7865 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7866 | break; |
| 7867 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7868 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7869 | break; |
| 7870 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7871 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7872 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 7873 | did, vport->port_state, ndlp->nlp_flag); |
| 7874 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7875 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7876 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7877 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7878 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7879 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7880 | break; |
| 7881 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7882 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7883 | break; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 7884 | case ELS_CMD_LCB: |
| 7885 | phba->fc_stat.elsRcvLCB++; |
| 7886 | lpfc_els_rcv_lcb(vport, elsiocb, ndlp); |
| 7887 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 7888 | case ELS_CMD_RDP: |
| 7889 | phba->fc_stat.elsRcvRDP++; |
| 7890 | lpfc_els_rcv_rdp(vport, elsiocb, ndlp); |
| 7891 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7892 | case ELS_CMD_RSCN: |
| 7893 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7894 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7895 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7896 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7897 | break; |
| 7898 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7899 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7900 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 7901 | did, vport->port_state, ndlp->nlp_flag); |
| 7902 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7903 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7904 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7905 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7906 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7907 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7908 | break; |
| 7909 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7910 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7911 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7912 | break; |
| 7913 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7914 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7915 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 7916 | did, vport->port_state, ndlp->nlp_flag); |
| 7917 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7918 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7919 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7920 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7921 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7922 | break; |
| 7923 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7924 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7925 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7926 | break; |
| 7927 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7928 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7929 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 7930 | did, vport->port_state, ndlp->nlp_flag); |
| 7931 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7932 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7933 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7934 | break; |
| 7935 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7936 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7937 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 7938 | did, vport->port_state, ndlp->nlp_flag); |
| 7939 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7940 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7941 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7942 | break; |
| 7943 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7944 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7945 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 7946 | did, vport->port_state, ndlp->nlp_flag); |
| 7947 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7948 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7949 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7950 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7951 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 7952 | case ELS_CMD_NVMEPRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7953 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7954 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 7955 | did, vport->port_state, ndlp->nlp_flag); |
| 7956 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7957 | phba->fc_stat.elsRcvPRLI++; |
Dick Kennedy | a71e3cd | 2017-03-23 08:47:18 -0400 | [diff] [blame] | 7958 | if ((vport->port_state < LPFC_DISC_AUTH) && |
| 7959 | (vport->fc_flag & FC_FABRIC)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7960 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7961 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7962 | break; |
| 7963 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7964 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7965 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7966 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7967 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7968 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 7969 | did, vport->port_state, ndlp->nlp_flag); |
| 7970 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7971 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7972 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7973 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7974 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7975 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7976 | case ELS_CMD_RLS: |
| 7977 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7978 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 7979 | did, vport->port_state, ndlp->nlp_flag); |
| 7980 | |
| 7981 | phba->fc_stat.elsRcvRLS++; |
| 7982 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 7983 | if (newnode) |
| 7984 | lpfc_nlp_put(ndlp); |
| 7985 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7986 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7987 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7988 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 7989 | did, vport->port_state, ndlp->nlp_flag); |
| 7990 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7991 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7992 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7993 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7994 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7995 | break; |
| 7996 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7997 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7998 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 7999 | did, vport->port_state, ndlp->nlp_flag); |
| 8000 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8001 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8002 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8003 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8004 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8005 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8006 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8007 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8008 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 8009 | did, vport->port_state, ndlp->nlp_flag); |
| 8010 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8011 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8012 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8013 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8014 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8015 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8016 | case ELS_CMD_RTV: |
| 8017 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8018 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 8019 | did, vport->port_state, ndlp->nlp_flag); |
| 8020 | phba->fc_stat.elsRcvRTV++; |
| 8021 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 8022 | if (newnode) |
| 8023 | lpfc_nlp_put(ndlp); |
| 8024 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8025 | case ELS_CMD_RRQ: |
| 8026 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8027 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 8028 | did, vport->port_state, ndlp->nlp_flag); |
| 8029 | |
| 8030 | phba->fc_stat.elsRcvRRQ++; |
| 8031 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 8032 | if (newnode) |
| 8033 | lpfc_nlp_put(ndlp); |
| 8034 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8035 | case ELS_CMD_ECHO: |
| 8036 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8037 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 8038 | did, vport->port_state, ndlp->nlp_flag); |
| 8039 | |
| 8040 | phba->fc_stat.elsRcvECHO++; |
| 8041 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 8042 | if (newnode) |
| 8043 | lpfc_nlp_put(ndlp); |
| 8044 | break; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8045 | case ELS_CMD_REC: |
| 8046 | /* receive this due to exchange closed */ |
| 8047 | rjt_err = LSRJT_UNABLE_TPC; |
| 8048 | rjt_exp = LSEXP_INVALID_OX_RX; |
| 8049 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8050 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8051 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8052 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 8053 | cmd, did, vport->port_state); |
| 8054 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8055 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8056 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8057 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8058 | |
| 8059 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8060 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8061 | "0115 Unknown ELS command x%x " |
| 8062 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8063 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8064 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8065 | break; |
| 8066 | } |
| 8067 | |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8068 | lsrjt: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8069 | /* check if need to LS_RJT received ELS cmd */ |
| 8070 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8071 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8072 | stat.un.b.lsRjtRsnCode = rjt_err; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8073 | stat.un.b.lsRjtRsnCodeExp = rjt_exp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8074 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 8075 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8076 | } |
| 8077 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8078 | lpfc_nlp_put(elsiocb->context1); |
| 8079 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8080 | return; |
| 8081 | |
| 8082 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8083 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8084 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8085 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8086 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8087 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8088 | phba->fc_stat.elsRcvDrop++; |
| 8089 | } |
| 8090 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8091 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8092 | * 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] | 8093 | * @phba: pointer to lpfc hba data structure. |
| 8094 | * @pring: pointer to a SLI ring. |
| 8095 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 8096 | * |
| 8097 | * This routine is used to process an unsolicited event received from a SLI |
| 8098 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 8099 | * associated with the unsolicited event is done by invoking the routine |
| 8100 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 8101 | * SLI ring on which the unsolicited event was received. |
| 8102 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8103 | void |
| 8104 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 8105 | struct lpfc_iocbq *elsiocb) |
| 8106 | { |
| 8107 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8108 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8109 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8110 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 8111 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8112 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8113 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8114 | elsiocb->context2 = NULL; |
| 8115 | elsiocb->context3 = NULL; |
| 8116 | |
| 8117 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 8118 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 8119 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 8120 | (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 8121 | IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8122 | phba->fc_stat.NoRcvBuf++; |
| 8123 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8124 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 8125 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8126 | return; |
| 8127 | } |
| 8128 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8129 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 8130 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 8131 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 8132 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 8133 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8134 | else |
| 8135 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8136 | icmd->unsli3.rcvsli3.vpi); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8137 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8138 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8139 | /* If there are no BDEs associated |
| 8140 | * with this IOCB, there is nothing to do. |
| 8141 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8142 | if (icmd->ulpBdeCount == 0) |
| 8143 | return; |
| 8144 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8145 | /* type of ELS cmd is first 32bit word |
| 8146 | * in packet |
| 8147 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8148 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8149 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8150 | } else { |
| 8151 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 8152 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8153 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 8154 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8155 | } |
| 8156 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8157 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 8158 | /* |
| 8159 | * The different unsolicited event handlers would tell us |
| 8160 | * if they are done with "mp" by setting context2 to NULL. |
| 8161 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8162 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8163 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 8164 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8165 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8166 | |
| 8167 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8168 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8169 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8170 | elsiocb->context2 = bdeBuf2; |
| 8171 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8172 | /* free mp if we are done with it */ |
| 8173 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8174 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 8175 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8176 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8177 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8178 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8179 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 8180 | static void |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8181 | lpfc_start_fdmi(struct lpfc_vport *vport) |
| 8182 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8183 | struct lpfc_nodelist *ndlp; |
| 8184 | |
| 8185 | /* If this is the first time, allocate an ndlp and initialize |
| 8186 | * it. Otherwise, make sure the node is enabled and then do the |
| 8187 | * login. |
| 8188 | */ |
| 8189 | ndlp = lpfc_findnode_did(vport, FDMI_DID); |
| 8190 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 8191 | ndlp = lpfc_nlp_init(vport, FDMI_DID); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8192 | if (ndlp) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8193 | ndlp->nlp_type |= NLP_FABRIC; |
| 8194 | } else { |
| 8195 | return; |
| 8196 | } |
| 8197 | } |
| 8198 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 8199 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 8200 | |
| 8201 | if (ndlp) { |
| 8202 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 8203 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| 8204 | } |
| 8205 | } |
| 8206 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8207 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8208 | * 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] | 8209 | * @phba: pointer to lpfc hba data structure. |
| 8210 | * @vport: pointer to a virtual N_Port data structure. |
| 8211 | * |
| 8212 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 8213 | * State Change Request (SCR) for a @vport. This routine will create an |
| 8214 | * ndlp for the Name Server associated to the @vport if such node does |
| 8215 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 8216 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 8217 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 8218 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 8219 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8220 | void |
| 8221 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 8222 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8223 | struct lpfc_nodelist *ndlp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8224 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8225 | |
| 8226 | /* |
| 8227 | * If lpfc_delay_discovery parameter is set and the clean address |
| 8228 | * bit is cleared and fc fabric parameters chenged, delay FC NPort |
| 8229 | * discovery. |
| 8230 | */ |
| 8231 | spin_lock_irq(shost->host_lock); |
| 8232 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 8233 | spin_unlock_irq(shost->host_lock); |
James Smart | 1877570 | 2013-04-17 20:19:25 -0400 | [diff] [blame] | 8234 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 8235 | "3334 Delay fc port discovery for %d seconds\n", |
| 8236 | phba->fc_ratov); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8237 | mod_timer(&vport->delayed_disc_tmo, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8238 | jiffies + msecs_to_jiffies(1000 * phba->fc_ratov)); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8239 | return; |
| 8240 | } |
| 8241 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8242 | |
| 8243 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 8244 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 8245 | ndlp = lpfc_nlp_init(vport, NameServer_DID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8246 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8247 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8248 | lpfc_disc_start(vport); |
| 8249 | return; |
| 8250 | } |
| 8251 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8252 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8253 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8254 | return; |
| 8255 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8256 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 8257 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 8258 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8259 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8260 | lpfc_disc_start(vport); |
| 8261 | return; |
| 8262 | } |
| 8263 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 8264 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8265 | "0348 NameServer login: node freed\n"); |
| 8266 | return; |
| 8267 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8268 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8269 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8270 | |
| 8271 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 8272 | |
| 8273 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 8274 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8275 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8276 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8277 | return; |
| 8278 | } |
| 8279 | |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 8280 | if ((phba->cfg_enable_SmartSAN || |
| 8281 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) && |
| 8282 | (vport->load_flag & FC_ALLOW_FDMI)) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8283 | lpfc_start_fdmi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8284 | } |
| 8285 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8286 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8287 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8288 | * @phba: pointer to lpfc hba data structure. |
| 8289 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 8290 | * |
| 8291 | * This routine is the completion callback function to register new vport |
| 8292 | * mailbox command. If the new vport mailbox command completes successfully, |
| 8293 | * the fabric registration login shall be performed on physical port (the |
| 8294 | * new vport created is actually a physical port, with VPI 0) or the port |
| 8295 | * login to Name Server for State Change Request (SCR) will be performed |
| 8296 | * on virtual port (real virtual port, with VPI greater than 0). |
| 8297 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8298 | static void |
| 8299 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 8300 | { |
| 8301 | struct lpfc_vport *vport = pmb->vport; |
| 8302 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8303 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 8304 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8305 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8306 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8307 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8308 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8309 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8310 | |
| 8311 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8312 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8313 | "0915 Register VPI failed : Status: x%x" |
| 8314 | " upd bit: x%x \n", mb->mbxStatus, |
| 8315 | mb->un.varRegVpi.upd); |
| 8316 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 8317 | mb->un.varRegVpi.upd) |
| 8318 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8319 | |
| 8320 | switch (mb->mbxStatus) { |
| 8321 | case 0x11: /* unsupported feature */ |
| 8322 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8323 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8324 | /* giving up on vport registration */ |
| 8325 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 8326 | spin_lock_irq(shost->host_lock); |
| 8327 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 8328 | spin_unlock_irq(shost->host_lock); |
| 8329 | lpfc_can_disctmo(vport); |
| 8330 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8331 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 8332 | case 0x20: |
| 8333 | spin_lock_irq(shost->host_lock); |
| 8334 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 8335 | spin_unlock_irq(shost->host_lock); |
| 8336 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 8337 | pmb->vport = vport; |
| 8338 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 8339 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 8340 | MBX_NOWAIT); |
| 8341 | if (rc == MBX_NOT_FINISHED) { |
| 8342 | lpfc_printf_vlog(vport, |
| 8343 | KERN_ERR, LOG_MBOX, |
| 8344 | "2732 Failed to issue INIT_VPI" |
| 8345 | " mailbox command\n"); |
| 8346 | } else { |
| 8347 | lpfc_nlp_put(ndlp); |
| 8348 | return; |
| 8349 | } |
| 8350 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8351 | default: |
| 8352 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8353 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8354 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8355 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8356 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8357 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8358 | spin_unlock_irq(shost->host_lock); |
James Smart | 5d18153 | 2017-03-04 09:30:25 -0800 | [diff] [blame] | 8359 | if (mb->mbxStatus == MBX_NOT_FINISHED) |
| 8360 | break; |
| 8361 | if ((vport->port_type == LPFC_PHYSICAL_PORT) && |
| 8362 | !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) { |
| 8363 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8364 | lpfc_issue_init_vfi(vport); |
| 8365 | else |
| 8366 | lpfc_initial_flogi(vport); |
| 8367 | } else { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8368 | lpfc_initial_fdisc(vport); |
James Smart | 5d18153 | 2017-03-04 09:30:25 -0800 | [diff] [blame] | 8369 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8370 | break; |
| 8371 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8372 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8373 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 8374 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8375 | spin_unlock_irq(shost->host_lock); |
| 8376 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8377 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 8378 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8379 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 8380 | /* |
| 8381 | * If the physical port is instantiated using |
| 8382 | * FDISC, do not start vport discovery. |
| 8383 | */ |
| 8384 | if (vport->port_state != LPFC_FDISC) |
| 8385 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8386 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8387 | } |
| 8388 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8389 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8390 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8391 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8392 | /* Now, we decrement the ndlp reference count held for this |
| 8393 | * callback function |
| 8394 | */ |
| 8395 | lpfc_nlp_put(ndlp); |
| 8396 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8397 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8398 | return; |
| 8399 | } |
| 8400 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8401 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8402 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8403 | * @phba: pointer to lpfc hba data structure. |
| 8404 | * @vport: pointer to a host virtual N_Port data structure. |
| 8405 | * @ndlp: pointer to a node-list data structure. |
| 8406 | * |
| 8407 | * This routine registers the @vport as a new virtual port with a HBA. |
| 8408 | * It is done through a registering vpi mailbox command. |
| 8409 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8410 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8411 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 8412 | struct lpfc_nodelist *ndlp) |
| 8413 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8414 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8415 | LPFC_MBOXQ_t *mbox; |
| 8416 | |
| 8417 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8418 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8419 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8420 | mbox->vport = vport; |
| 8421 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 8422 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8423 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8424 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8425 | /* mailbox command not success, decrement ndlp |
| 8426 | * reference count for this command |
| 8427 | */ |
| 8428 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8429 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8430 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8431 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 8432 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8433 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8434 | } |
| 8435 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8436 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 8437 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8438 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8439 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8440 | return; |
| 8441 | |
| 8442 | mbox_err_exit: |
| 8443 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 8444 | spin_lock_irq(shost->host_lock); |
| 8445 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 8446 | spin_unlock_irq(shost->host_lock); |
| 8447 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8448 | } |
| 8449 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8450 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8451 | * 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] | 8452 | * @phba: pointer to lpfc hba data structure. |
| 8453 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8454 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8455 | **/ |
| 8456 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8457 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8458 | { |
| 8459 | struct lpfc_vport **vports; |
| 8460 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8461 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8462 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8463 | |
| 8464 | /* Treat this failure as linkdown for all vports */ |
| 8465 | link_state = phba->link_state; |
| 8466 | lpfc_linkdown(phba); |
| 8467 | phba->link_state = link_state; |
| 8468 | |
| 8469 | vports = lpfc_create_vport_work_array(phba); |
| 8470 | |
| 8471 | if (vports) { |
| 8472 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 8473 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 8474 | if (ndlp) |
| 8475 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 8476 | lpfc_els_flush_cmd(vports[i]); |
| 8477 | } |
| 8478 | lpfc_destroy_vport_work_array(phba, vports); |
| 8479 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8480 | } |
| 8481 | |
| 8482 | /** |
| 8483 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 8484 | * @phba: pointer to lpfc hba data structure. |
| 8485 | * |
| 8486 | * This routine abort all pending discovery commands and |
| 8487 | * start a timer to retry FLOGI for the physical port |
| 8488 | * discovery. |
| 8489 | **/ |
| 8490 | void |
| 8491 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 8492 | { |
| 8493 | struct lpfc_nodelist *ndlp; |
| 8494 | struct Scsi_Host *shost; |
| 8495 | |
| 8496 | /* Cancel the all vports retry delay retry timers */ |
| 8497 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8498 | |
| 8499 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 8500 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 8501 | if (!ndlp) |
| 8502 | return; |
| 8503 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8504 | shost = lpfc_shost_from_vport(phba->pport); |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8505 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000)); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8506 | spin_lock_irq(shost->host_lock); |
| 8507 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 8508 | spin_unlock_irq(shost->host_lock); |
| 8509 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 8510 | phba->pport->port_state = LPFC_FLOGI; |
| 8511 | return; |
| 8512 | } |
| 8513 | |
| 8514 | /** |
| 8515 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 8516 | * @phba: pointer to lpfc hba data structure. |
| 8517 | * @cmdiocb: pointer to FDISC command iocb. |
| 8518 | * @rspiocb: pointer to FDISC response iocb. |
| 8519 | * |
| 8520 | * This routine checks if a FLOGI is reguired for FDISC |
| 8521 | * to succeed. |
| 8522 | **/ |
| 8523 | static int |
| 8524 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 8525 | struct lpfc_iocbq *cmdiocb, |
| 8526 | struct lpfc_iocbq *rspiocb) |
| 8527 | { |
| 8528 | |
| 8529 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 8530 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 8531 | return 0; |
| 8532 | else |
| 8533 | return 1; |
| 8534 | } |
| 8535 | |
| 8536 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8537 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8538 | * @phba: pointer to lpfc hba data structure. |
| 8539 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8540 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8541 | * |
| 8542 | * This routine is the completion callback function to a Fabric Discover |
| 8543 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 8544 | * single threaded, each FDISC completion callback function will reset |
| 8545 | * the discovery timer for all vports such that the timers will not get |
| 8546 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 8547 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 8548 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 8549 | * assigned to the vport has been changed with the completion of the FDISC |
| 8550 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 8551 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 8552 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 8553 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 8554 | * Server for State Change Request (SCR). |
| 8555 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8556 | static void |
| 8557 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8558 | struct lpfc_iocbq *rspiocb) |
| 8559 | { |
| 8560 | struct lpfc_vport *vport = cmdiocb->vport; |
| 8561 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8562 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 8563 | struct lpfc_nodelist *np; |
| 8564 | struct lpfc_nodelist *next_np; |
| 8565 | IOCB_t *irsp = &rspiocb->iocb; |
| 8566 | struct lpfc_iocbq *piocb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8567 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 8568 | struct serv_parm *sp; |
| 8569 | uint8_t fabric_param_changed; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8570 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8571 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8572 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 8573 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 8574 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8575 | /* Since all FDISCs are being single threaded, we |
| 8576 | * must reset the discovery timer for ALL vports |
| 8577 | * waiting to send FDISC when one completes. |
| 8578 | */ |
| 8579 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 8580 | lpfc_set_disctmo(piocb->vport); |
| 8581 | } |
| 8582 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8583 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8584 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 8585 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 8586 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8587 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8588 | |
| 8589 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 8590 | lpfc_retry_pport_discovery(phba); |
| 8591 | goto out; |
| 8592 | } |
| 8593 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8594 | /* Check for retry */ |
| 8595 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 8596 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8597 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8598 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8599 | "0126 FDISC failed. (x%x/x%x)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8600 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8601 | goto fdisc_failed; |
| 8602 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8603 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8604 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8605 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8606 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8607 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8608 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 8609 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8610 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8611 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 8612 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8613 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 8614 | if (!prsp) |
| 8615 | goto out; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8616 | sp = prsp->virt + sizeof(uint32_t); |
| 8617 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 8618 | memcpy(&vport->fabric_portname, &sp->portName, |
| 8619 | sizeof(struct lpfc_name)); |
| 8620 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 8621 | sizeof(struct lpfc_name)); |
| 8622 | if (fabric_param_changed && |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8623 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 8624 | /* If our NportID changed, we need to ensure all |
| 8625 | * remaining NPORTs get unreg_login'ed so we can |
| 8626 | * issue unreg_vpi. |
| 8627 | */ |
| 8628 | list_for_each_entry_safe(np, next_np, |
| 8629 | &vport->fc_nodes, nlp_listp) { |
| 8630 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 8631 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 8632 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 8633 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8634 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8635 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8636 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8637 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8638 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 8639 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8640 | |
| 8641 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8642 | lpfc_sli4_unreg_all_rpis(vport); |
| 8643 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8644 | lpfc_mbx_unreg_vpi(vport); |
| 8645 | spin_lock_irq(shost->host_lock); |
| 8646 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8647 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8648 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8649 | else |
| 8650 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8651 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8652 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 8653 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 8654 | /* |
| 8655 | * Driver needs to re-reg VPI in order for f/w |
| 8656 | * to update the MAC address. |
| 8657 | */ |
| 8658 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 8659 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8660 | } |
| 8661 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 8662 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 8663 | lpfc_issue_init_vpi(vport); |
| 8664 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8665 | lpfc_register_new_vport(phba, vport, ndlp); |
| 8666 | else |
| 8667 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8668 | goto out; |
| 8669 | fdisc_failed: |
James Smart | c84163d | 2015-05-21 13:55:22 -0400 | [diff] [blame] | 8670 | if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS) |
| 8671 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8672 | /* Cancel discovery timer */ |
| 8673 | lpfc_can_disctmo(vport); |
| 8674 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8675 | out: |
| 8676 | lpfc_els_free_iocb(phba, cmdiocb); |
| 8677 | } |
| 8678 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8679 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8680 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8681 | * @vport: pointer to a virtual N_Port data structure. |
| 8682 | * @ndlp: pointer to a node-list data structure. |
| 8683 | * @retry: number of retries to the command IOCB. |
| 8684 | * |
| 8685 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 8686 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 8687 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 8688 | * IOCB will be sent off HBA at any given time. |
| 8689 | * |
| 8690 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 8691 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 8692 | * will be stored into the context1 field of the IOCB for the completion |
| 8693 | * callback function to the FDISC ELS command. |
| 8694 | * |
| 8695 | * Return code |
| 8696 | * 0 - Successfully issued fdisc iocb command |
| 8697 | * 1 - Failed to issue fdisc iocb command |
| 8698 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8699 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8700 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 8701 | uint8_t retry) |
| 8702 | { |
| 8703 | struct lpfc_hba *phba = vport->phba; |
| 8704 | IOCB_t *icmd; |
| 8705 | struct lpfc_iocbq *elsiocb; |
| 8706 | struct serv_parm *sp; |
| 8707 | uint8_t *pcmd; |
| 8708 | uint16_t cmdsize; |
| 8709 | int did = ndlp->nlp_DID; |
| 8710 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8711 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8712 | vport->port_state = LPFC_FDISC; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8713 | vport->fc_myDID = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8714 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 8715 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 8716 | ELS_CMD_FDISC); |
| 8717 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8718 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8719 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8720 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8721 | return 1; |
| 8722 | } |
| 8723 | |
| 8724 | icmd = &elsiocb->iocb; |
| 8725 | icmd->un.elsreq64.myID = 0; |
| 8726 | icmd->un.elsreq64.fl = 1; |
| 8727 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 8728 | /* |
| 8729 | * SLI3 ports require a different context type value than SLI4. |
| 8730 | * Catch SLI3 ports here and override the prep. |
| 8731 | */ |
| 8732 | if (phba->sli_rev == LPFC_SLI_REV3) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8733 | icmd->ulpCt_h = 1; |
| 8734 | icmd->ulpCt_l = 0; |
| 8735 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8736 | |
| 8737 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 8738 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 8739 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 8740 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 8741 | sp = (struct serv_parm *) pcmd; |
| 8742 | /* Setup CSPs accordingly for Fabric */ |
| 8743 | sp->cmn.e_d_tov = 0; |
| 8744 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 8745 | sp->cmn.virtual_fabric_support = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8746 | sp->cls1.classValid = 0; |
| 8747 | sp->cls2.seqDelivery = 1; |
| 8748 | sp->cls3.seqDelivery = 1; |
| 8749 | |
| 8750 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 8751 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 8752 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 8753 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 8754 | memcpy(pcmd, &vport->fc_portname, 8); |
| 8755 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 8756 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 8757 | memcpy(pcmd, &vport->fc_nodename, 8); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 8758 | memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8759 | lpfc_set_disctmo(vport); |
| 8760 | |
| 8761 | phba->fc_stat.elsXmitFDISC++; |
| 8762 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 8763 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8764 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8765 | "Issue FDISC: did:x%x", |
| 8766 | did, 0, 0); |
| 8767 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8768 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 8769 | if (rc == IOCB_ERROR) { |
| 8770 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8771 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8772 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8773 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8774 | return 1; |
| 8775 | } |
| 8776 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8777 | return 0; |
| 8778 | } |
| 8779 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8780 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8781 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8782 | * @phba: pointer to lpfc hba data structure. |
| 8783 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8784 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8785 | * |
| 8786 | * This routine is the completion callback function to the issuing of a LOGO |
| 8787 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 8788 | * reference count held on ndlp for this completion function, indicating that |
| 8789 | * the reference to the ndlp is no long needed. Note that the |
| 8790 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 8791 | * callback function and an additional explicit ndlp reference decrementation |
| 8792 | * will trigger the actual release of the ndlp. |
| 8793 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8794 | static void |
| 8795 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8796 | struct lpfc_iocbq *rspiocb) |
| 8797 | { |
| 8798 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8799 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8800 | struct lpfc_nodelist *ndlp; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8801 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8802 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8803 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8804 | irsp = &rspiocb->iocb; |
| 8805 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8806 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 8807 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8808 | |
| 8809 | lpfc_els_free_iocb(phba, cmdiocb); |
| 8810 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8811 | |
| 8812 | /* Trigger the release of the ndlp after logo */ |
| 8813 | lpfc_nlp_put(ndlp); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8814 | |
| 8815 | /* NPIV LOGO completes to NPort <nlp_DID> */ |
| 8816 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8817 | "2928 NPIV LOGO completes to NPort x%x " |
| 8818 | "Data: x%x x%x x%x x%x\n", |
| 8819 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 8820 | irsp->ulpTimeout, vport->num_disc_nodes); |
| 8821 | |
| 8822 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 8823 | spin_lock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 8824 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8825 | vport->fc_flag &= ~FC_FABRIC; |
| 8826 | spin_unlock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 8827 | lpfc_can_disctmo(vport); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8828 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8829 | } |
| 8830 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8831 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8832 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8833 | * @vport: pointer to a virtual N_Port data structure. |
| 8834 | * @ndlp: pointer to a node-list data structure. |
| 8835 | * |
| 8836 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 8837 | * |
| 8838 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 8839 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 8840 | * will be stored into the context1 field of the IOCB for the completion |
| 8841 | * callback function to the LOGO ELS command. |
| 8842 | * |
| 8843 | * Return codes |
| 8844 | * 0 - Successfully issued logo off the @vport |
| 8845 | * 1 - Failed to issue logo off the @vport |
| 8846 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8847 | int |
| 8848 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 8849 | { |
| 8850 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8851 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8852 | struct lpfc_iocbq *elsiocb; |
| 8853 | uint8_t *pcmd; |
| 8854 | uint16_t cmdsize; |
| 8855 | |
| 8856 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 8857 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 8858 | ELS_CMD_LOGO); |
| 8859 | if (!elsiocb) |
| 8860 | return 1; |
| 8861 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8862 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 8863 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 8864 | pcmd += sizeof(uint32_t); |
| 8865 | |
| 8866 | /* Fill in LOGO payload */ |
| 8867 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 8868 | pcmd += sizeof(uint32_t); |
| 8869 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 8870 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8871 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8872 | "Issue LOGO npiv did:x%x flg:x%x", |
| 8873 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 8874 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8875 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 8876 | spin_lock_irq(shost->host_lock); |
| 8877 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 8878 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8879 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 8880 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8881 | spin_lock_irq(shost->host_lock); |
| 8882 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 8883 | spin_unlock_irq(shost->host_lock); |
| 8884 | lpfc_els_free_iocb(phba, elsiocb); |
| 8885 | return 1; |
| 8886 | } |
| 8887 | return 0; |
| 8888 | } |
| 8889 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8890 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8891 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8892 | * @ptr: holder for the timer function associated data. |
| 8893 | * |
| 8894 | * This routine is invoked by the fabric iocb block timer after |
| 8895 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 8896 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 8897 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 8898 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 8899 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 8900 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8901 | void |
| 8902 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 8903 | { |
| 8904 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 8905 | unsigned long iflags; |
| 8906 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8907 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8908 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 8909 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 8910 | if (!tmo_posted) |
| 8911 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 8912 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 8913 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8914 | if (!tmo_posted) |
| 8915 | lpfc_worker_wake_up(phba); |
| 8916 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8917 | } |
| 8918 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8919 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8920 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8921 | * @phba: pointer to lpfc hba data structure. |
| 8922 | * |
| 8923 | * This routine issues one fabric iocb from the driver internal list to |
| 8924 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 8925 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 8926 | * remove one pending fabric iocb from the driver internal list and invokes |
| 8927 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 8928 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8929 | static void |
| 8930 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 8931 | { |
| 8932 | struct lpfc_iocbq *iocb; |
| 8933 | unsigned long iflags; |
| 8934 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8935 | IOCB_t *cmd; |
| 8936 | |
| 8937 | repeat: |
| 8938 | iocb = NULL; |
| 8939 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8940 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8941 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 8942 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 8943 | list); |
| 8944 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8945 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8946 | atomic_inc(&phba->fabric_iocb_count); |
| 8947 | } |
| 8948 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8949 | if (iocb) { |
| 8950 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 8951 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 8952 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 8953 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8954 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 8955 | "Fabric sched1: ste:x%x", |
| 8956 | iocb->vport->port_state, 0, 0); |
| 8957 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8958 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8959 | |
| 8960 | if (ret == IOCB_ERROR) { |
| 8961 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 8962 | iocb->fabric_iocb_cmpl = NULL; |
| 8963 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 8964 | cmd = &iocb->iocb; |
| 8965 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 8966 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 8967 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 8968 | |
| 8969 | atomic_dec(&phba->fabric_iocb_count); |
| 8970 | goto repeat; |
| 8971 | } |
| 8972 | } |
| 8973 | |
| 8974 | return; |
| 8975 | } |
| 8976 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8977 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8978 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8979 | * @phba: pointer to lpfc hba data structure. |
| 8980 | * |
| 8981 | * This routine unblocks the issuing fabric iocb command. The function |
| 8982 | * will clear the fabric iocb block bit and then invoke the routine |
| 8983 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 8984 | * from the driver internal fabric iocb list. |
| 8985 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8986 | void |
| 8987 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 8988 | { |
| 8989 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 8990 | |
| 8991 | lpfc_resume_fabric_iocbs(phba); |
| 8992 | return; |
| 8993 | } |
| 8994 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8995 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8996 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8997 | * @phba: pointer to lpfc hba data structure. |
| 8998 | * |
| 8999 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 9000 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 9001 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 9002 | * fabric iocb will be issued out of the HBA. |
| 9003 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9004 | static void |
| 9005 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 9006 | { |
| 9007 | int blocked; |
| 9008 | |
| 9009 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9010 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9011 | if (!blocked) |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9012 | mod_timer(&phba->fabric_block_timer, |
| 9013 | jiffies + msecs_to_jiffies(100)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9014 | |
| 9015 | return; |
| 9016 | } |
| 9017 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9018 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9019 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9020 | * @phba: pointer to lpfc hba data structure. |
| 9021 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 9022 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 9023 | * |
| 9024 | * This routine is the callback function that is put to the fabric iocb's |
| 9025 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 9026 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 9027 | * function first restores and invokes the original iocb's callback function |
| 9028 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 9029 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 9030 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9031 | static void |
| 9032 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9033 | struct lpfc_iocbq *rspiocb) |
| 9034 | { |
| 9035 | struct ls_rjt stat; |
| 9036 | |
Shyam Saini | e01ea5e | 2016-12-24 16:21:07 +0530 | [diff] [blame] | 9037 | BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9038 | |
| 9039 | switch (rspiocb->iocb.ulpStatus) { |
| 9040 | case IOSTAT_NPORT_RJT: |
| 9041 | case IOSTAT_FABRIC_RJT: |
| 9042 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 9043 | lpfc_block_fabric_iocbs(phba); |
| 9044 | } |
| 9045 | break; |
| 9046 | |
| 9047 | case IOSTAT_NPORT_BSY: |
| 9048 | case IOSTAT_FABRIC_BSY: |
| 9049 | lpfc_block_fabric_iocbs(phba); |
| 9050 | break; |
| 9051 | |
| 9052 | case IOSTAT_LS_RJT: |
| 9053 | stat.un.lsRjtError = |
| 9054 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 9055 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 9056 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 9057 | lpfc_block_fabric_iocbs(phba); |
| 9058 | break; |
| 9059 | } |
| 9060 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 9061 | BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9062 | |
| 9063 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 9064 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 9065 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 9066 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 9067 | |
| 9068 | atomic_dec(&phba->fabric_iocb_count); |
| 9069 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9070 | /* Post any pending iocbs to HBA */ |
| 9071 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9072 | } |
| 9073 | } |
| 9074 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9075 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9076 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9077 | * @phba: pointer to lpfc hba data structure. |
| 9078 | * @iocb: pointer to lpfc command iocb data structure. |
| 9079 | * |
| 9080 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 9081 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 9082 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 9083 | * any given time. As such, this function will first check to see whether there |
| 9084 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 9085 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 9086 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 9087 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 9088 | * |
| 9089 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 9090 | * order. The problem is caused by the construction of the "ready" boolen does |
| 9091 | * not include the condition that the internal fabric IOCB list is empty. As |
| 9092 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 9093 | * ahead of the fabric IOCBs in the internal list. |
| 9094 | * |
| 9095 | * Return code |
| 9096 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 9097 | * IOCB_ERROR - failed to issue fabric iocb |
| 9098 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 9099 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9100 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 9101 | { |
| 9102 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9103 | int ready; |
| 9104 | int ret; |
| 9105 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 9106 | BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9107 | |
| 9108 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9109 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 9110 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 9111 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9112 | if (ready) |
| 9113 | /* Increment fabric iocb count to hold the position */ |
| 9114 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9115 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9116 | if (ready) { |
| 9117 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 9118 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 9119 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 9120 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9121 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 9122 | "Fabric sched2: ste:x%x", |
| 9123 | iocb->vport->port_state, 0, 0); |
| 9124 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9125 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9126 | |
| 9127 | if (ret == IOCB_ERROR) { |
| 9128 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 9129 | iocb->fabric_iocb_cmpl = NULL; |
| 9130 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 9131 | atomic_dec(&phba->fabric_iocb_count); |
| 9132 | } |
| 9133 | } else { |
| 9134 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9135 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 9136 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9137 | ret = IOCB_SUCCESS; |
| 9138 | } |
| 9139 | return ret; |
| 9140 | } |
| 9141 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9142 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9143 | * 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] | 9144 | * @vport: pointer to a virtual N_Port data structure. |
| 9145 | * |
| 9146 | * This routine aborts all the IOCBs associated with a @vport from the |
| 9147 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 9148 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 9149 | * list, removes each IOCB associated with the @vport off the list, set the |
| 9150 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 9151 | * associated with the IOCB. |
| 9152 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 9153 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9154 | { |
| 9155 | LIST_HEAD(completions); |
| 9156 | struct lpfc_hba *phba = vport->phba; |
| 9157 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9158 | |
| 9159 | spin_lock_irq(&phba->hbalock); |
| 9160 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 9161 | list) { |
| 9162 | |
| 9163 | if (piocb->vport != vport) |
| 9164 | continue; |
| 9165 | |
| 9166 | list_move_tail(&piocb->list, &completions); |
| 9167 | } |
| 9168 | spin_unlock_irq(&phba->hbalock); |
| 9169 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9170 | /* Cancel all the IOCBs from the completions list */ |
| 9171 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9172 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9173 | } |
| 9174 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9175 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9176 | * 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] | 9177 | * @ndlp: pointer to a node-list data structure. |
| 9178 | * |
| 9179 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 9180 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 9181 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 9182 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 9183 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 9184 | * associated with the IOCB. |
| 9185 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9186 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 9187 | { |
| 9188 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9189 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9190 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9191 | struct lpfc_sli_ring *pring; |
| 9192 | |
| 9193 | pring = lpfc_phba_elsring(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9194 | |
| 9195 | spin_lock_irq(&phba->hbalock); |
| 9196 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 9197 | list) { |
| 9198 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 9199 | |
| 9200 | list_move_tail(&piocb->list, &completions); |
| 9201 | } |
| 9202 | } |
| 9203 | spin_unlock_irq(&phba->hbalock); |
| 9204 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9205 | /* Cancel all the IOCBs from the completions list */ |
| 9206 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9207 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9208 | } |
| 9209 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9210 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9211 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9212 | * @phba: pointer to lpfc hba data structure. |
| 9213 | * |
| 9214 | * This routine aborts all the IOCBs currently on the driver internal |
| 9215 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 9216 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 9217 | * list, removes IOCBs off the list, set the status feild to |
| 9218 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 9219 | * the IOCB. |
| 9220 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9221 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 9222 | { |
| 9223 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9224 | |
| 9225 | spin_lock_irq(&phba->hbalock); |
| 9226 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 9227 | spin_unlock_irq(&phba->hbalock); |
| 9228 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9229 | /* Cancel all the IOCBs from the completions list */ |
| 9230 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9231 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9232 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9233 | |
| 9234 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 9235 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport |
| 9236 | * @vport: pointer to lpfc vport data structure. |
| 9237 | * |
| 9238 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 9239 | * for an ndlp on removal. |
| 9240 | **/ |
| 9241 | void |
| 9242 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) |
| 9243 | { |
| 9244 | struct lpfc_hba *phba = vport->phba; |
| 9245 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 9246 | unsigned long iflag = 0; |
| 9247 | |
| 9248 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9249 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 9250 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 9251 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 9252 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) |
| 9253 | sglq_entry->ndlp = NULL; |
| 9254 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9255 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 9256 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9257 | return; |
| 9258 | } |
| 9259 | |
| 9260 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9261 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 9262 | * @phba: pointer to lpfc hba data structure. |
| 9263 | * @axri: pointer to the els xri abort wcqe structure. |
| 9264 | * |
| 9265 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 9266 | * ELS aborted xri. |
| 9267 | **/ |
| 9268 | void |
| 9269 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 9270 | struct sli4_wcqe_xri_aborted *axri) |
| 9271 | { |
| 9272 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9273 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9274 | uint16_t lxri = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9275 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9276 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 9277 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9278 | struct lpfc_nodelist *ndlp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9279 | struct lpfc_sli_ring *pring; |
| 9280 | |
| 9281 | pring = lpfc_phba_elsring(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9282 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9283 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9284 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9285 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 9286 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 9287 | if (sglq_entry->sli4_xritag == xri) { |
| 9288 | list_del(&sglq_entry->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9289 | ndlp = sglq_entry->ndlp; |
| 9290 | sglq_entry->ndlp = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9291 | list_add_tail(&sglq_entry->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9292 | &phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9293 | sglq_entry->state = SGL_FREED; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9294 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9295 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 9296 | lpfc_set_rrq_active(phba, ndlp, |
| 9297 | sglq_entry->sli4_lxritag, |
| 9298 | rxid, 1); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 9299 | |
| 9300 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9301 | if (!(list_empty(&pring->txq))) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 9302 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9303 | return; |
| 9304 | } |
| 9305 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9306 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9307 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 9308 | if (lxri == NO_XRI) { |
| 9309 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9310 | return; |
| 9311 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9312 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9313 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9314 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9315 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9316 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9317 | return; |
| 9318 | } |
| 9319 | sglq_entry->state = SGL_XRI_ABORTED; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9320 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9321 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9322 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9323 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 9324 | |
| 9325 | /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. |
| 9326 | * @vport: pointer to virtual port object. |
| 9327 | * @ndlp: nodelist pointer for the impacted node. |
| 9328 | * |
| 9329 | * The driver calls this routine in response to an SLI4 XRI ABORT CQE |
| 9330 | * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, |
| 9331 | * the driver is required to send a LOGO to the remote node before it |
| 9332 | * attempts to recover its login to the remote node. |
| 9333 | */ |
| 9334 | void |
| 9335 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 9336 | struct lpfc_nodelist *ndlp) |
| 9337 | { |
| 9338 | struct Scsi_Host *shost; |
| 9339 | struct lpfc_hba *phba; |
| 9340 | unsigned long flags = 0; |
| 9341 | |
| 9342 | shost = lpfc_shost_from_vport(vport); |
| 9343 | phba = vport->phba; |
| 9344 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 9345 | lpfc_printf_log(phba, KERN_INFO, |
| 9346 | LOG_SLI, "3093 No rport recovery needed. " |
| 9347 | "rport in state 0x%x\n", ndlp->nlp_state); |
| 9348 | return; |
| 9349 | } |
| 9350 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9351 | "3094 Start rport recovery on shost id 0x%x " |
| 9352 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 9353 | "flags 0x%x\n", |
| 9354 | shost->host_no, ndlp->nlp_DID, |
| 9355 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 9356 | ndlp->nlp_flag); |
| 9357 | /* |
| 9358 | * The rport is not responding. Remove the FCP-2 flag to prevent |
| 9359 | * an ADISC in the follow-up recovery code. |
| 9360 | */ |
| 9361 | spin_lock_irqsave(shost->host_lock, flags); |
| 9362 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 9363 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 9364 | lpfc_issue_els_logo(vport, ndlp, 0); |
| 9365 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
| 9366 | } |
| 9367 | |