| 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 | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 4 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * 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] | 10 | * modify it under the terms of version 2 of the GNU General * |
| 11 | * Public License as published by the Free Software Foundation. * |
| 12 | * This program is distributed in the hope that it will be useful. * |
| 13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 18 | * more details, a copy of which can be found in the file COPYING * |
| 19 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 21 | /* See Fibre Channel protocol T11 FC-LS for details */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
| 26 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 27 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 28 | #include <scsi/scsi_device.h> |
| 29 | #include <scsi/scsi_host.h> |
| 30 | #include <scsi/scsi_transport_fc.h> |
| 31 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 32 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 33 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 34 | #include "lpfc_hw.h" |
| 35 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 36 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 37 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 38 | #include "lpfc_disc.h" |
| 39 | #include "lpfc_scsi.h" |
| 40 | #include "lpfc.h" |
| 41 | #include "lpfc_logmsg.h" |
| 42 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 43 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 44 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | |
| 46 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, |
| 47 | struct lpfc_iocbq *); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 48 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
| 49 | struct lpfc_iocbq *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 50 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
| 51 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, |
| 52 | struct lpfc_nodelist *ndlp, uint8_t retry); |
| 53 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, |
| 54 | struct lpfc_iocbq *iocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 55 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 56 | static int lpfc_max_els_tries = 3; |
| 57 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 58 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 59 | * lpfc_els_chk_latt - Check host link attention event for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 60 | * @vport: pointer to a host virtual N_Port data structure. |
| 61 | * |
| 62 | * This routine checks whether there is an outstanding host link |
| 63 | * attention event during the discovery process with the @vport. It is done |
| 64 | * by reading the HBA's Host Attention (HA) register. If there is any host |
| 65 | * link attention events during this @vport's discovery process, the @vport |
| 66 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall |
| 67 | * be issued if the link state is not already in host link cleared state, |
| 68 | * and a return code shall indicate whether the host link attention event |
| 69 | * had happened. |
| 70 | * |
| 71 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport |
| 72 | * state in LPFC_VPORT_READY, the request for checking host link attention |
| 73 | * event will be ignored and a return code shall indicate no host link |
| 74 | * attention event had happened. |
| 75 | * |
| 76 | * Return codes |
| 77 | * 0 - no host link attention event happened |
| 78 | * 1 - host link attention event happened |
| 79 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 80 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 81 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 82 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 83 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 84 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 85 | uint32_t ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 86 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 87 | if (vport->port_state >= LPFC_VPORT_READY || |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 88 | phba->link_state == LPFC_LINK_DOWN || |
| 89 | phba->sli_rev > LPFC_SLI_REV3) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 90 | return 0; |
| 91 | |
| 92 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 93 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 94 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 95 | |
| 96 | if (!(ha_copy & HA_LATT)) |
| 97 | return 0; |
| 98 | |
| 99 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 100 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 101 | "0237 Pending Link Event during " |
| 102 | "Discovery: State x%x\n", |
| 103 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 104 | |
| 105 | /* CLEAR_LA should re-enable link attention events and |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 106 | * we should then immediately take a LATT event. The |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 107 | * LATT processing should call lpfc_linkdown() which |
| 108 | * will cleanup any left over in-progress discovery |
| 109 | * events. |
| 110 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 111 | spin_lock_irq(shost->host_lock); |
| 112 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 113 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 114 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 115 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 116 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 117 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 118 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 119 | } |
| 120 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 121 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 122 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 123 | * @vport: pointer to a host virtual N_Port data structure. |
| 124 | * @expectRsp: flag indicating whether response is expected. |
| 125 | * @cmdSize: size of the ELS command. |
| 126 | * @retry: number of retries to the command IOCB when it fails. |
| 127 | * @ndlp: pointer to a node-list data structure. |
| 128 | * @did: destination identifier. |
| 129 | * @elscmd: the ELS command code. |
| 130 | * |
| 131 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 132 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 133 | * passed into the routine for discovery state machine to issue an Extended |
| 134 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 135 | * and preparation routine that is used by all the discovery state machine |
| 136 | * routines and the ELS command-specific fields will be later set up by |
| 137 | * the individual discovery machine routines after calling this routine |
| 138 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 139 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 140 | * payload and response payload (if expected). The reference count on the |
| 141 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 142 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 143 | * reference for the command's callback function to access later. |
| 144 | * |
| 145 | * Return code |
| 146 | * Pointer to the newly allocated/prepared els iocb data structure |
| 147 | * NULL - when els iocb data structure allocation/preparation failed |
| 148 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 149 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 150 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 151 | uint16_t cmdSize, uint8_t retry, |
| 152 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 153 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 154 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 155 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 156 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 157 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 158 | struct ulp_bde64 *bpl; |
| 159 | IOCB_t *icmd; |
| 160 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 161 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 162 | if (!lpfc_is_link_up(phba)) |
| 163 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 164 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 165 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 166 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 167 | |
| 168 | if (elsiocb == NULL) |
| 169 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 170 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 171 | /* |
| 172 | * If this command is for fabric controller and HBA running |
| 173 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. |
| 174 | */ |
| 175 | if ((did == Fabric_DID) && |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 176 | (phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 177 | ((elscmd == ELS_CMD_FLOGI) || |
| 178 | (elscmd == ELS_CMD_FDISC) || |
| 179 | (elscmd == ELS_CMD_LOGO))) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 180 | switch (elscmd) { |
| 181 | case ELS_CMD_FLOGI: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 182 | elsiocb->iocb_flag |= |
| 183 | ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 184 | & LPFC_FIP_ELS_ID_MASK); |
| 185 | break; |
| 186 | case ELS_CMD_FDISC: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 187 | elsiocb->iocb_flag |= |
| 188 | ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 189 | & LPFC_FIP_ELS_ID_MASK); |
| 190 | break; |
| 191 | case ELS_CMD_LOGO: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 192 | elsiocb->iocb_flag |= |
| 193 | ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 194 | & LPFC_FIP_ELS_ID_MASK); |
| 195 | break; |
| 196 | } |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 197 | else |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 198 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 199 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 200 | icmd = &elsiocb->iocb; |
| 201 | |
| 202 | /* fill in BDEs for command */ |
| 203 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 204 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 205 | if (pcmd) |
| 206 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 207 | if (!pcmd || !pcmd->virt) |
| 208 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 209 | |
| 210 | INIT_LIST_HEAD(&pcmd->list); |
| 211 | |
| 212 | /* Allocate buffer for response payload */ |
| 213 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 214 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | if (prsp) |
| 216 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 217 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 218 | if (!prsp || !prsp->virt) |
| 219 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 220 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 221 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 222 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 223 | |
| 224 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 225 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 226 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 227 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 228 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 229 | if (!pbuflist || !pbuflist->virt) |
| 230 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 231 | |
| 232 | INIT_LIST_HEAD(&pbuflist->list); |
| 233 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 234 | if (expectRsp) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 235 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 236 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
| 237 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 238 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 239 | |
| 240 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 242 | if (elscmd == ELS_CMD_FLOGI) |
| 243 | icmd->ulpTimeout = FF_DEF_RATOV * 2; |
| 244 | else |
| 245 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 246 | } else { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 247 | icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 248 | icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
| 249 | icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 250 | icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| 251 | icmd->un.xseq64.xmit_els_remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 252 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 253 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 254 | icmd->ulpBdeCount = 1; |
| 255 | icmd->ulpLe = 1; |
| 256 | icmd->ulpClass = CLASS3; |
| 257 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 258 | /* |
| 259 | * If we have NPIV enabled, we want to send ELS traffic by VPI. |
| 260 | * For SLI4, since the driver controls VPIs we also want to include |
| 261 | * all ELS pt2pt protocol traffic as well. |
| 262 | */ |
| 263 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) || |
| 264 | ((phba->sli_rev == LPFC_SLI_REV4) && |
| 265 | (vport->fc_flag & FC_PT2PT))) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 266 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 267 | if (expectRsp) { |
| 268 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 269 | |
| 270 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
| 271 | icmd->ulpContext = phba->vpi_ids[vport->vpi]; |
| 272 | } |
| 273 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 274 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 275 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 276 | if (elscmd == ELS_CMD_ECHO) |
| 277 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 278 | else |
| 279 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 280 | } |
| 281 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 282 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 283 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 284 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 285 | bpl->tus.f.bdeSize = cmdSize; |
| 286 | bpl->tus.f.bdeFlags = 0; |
| 287 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 288 | |
| 289 | if (expectRsp) { |
| 290 | bpl++; |
| 291 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 292 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 293 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 294 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 295 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 296 | } |
| 297 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 298 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 299 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 300 | if (!elsiocb->context1) |
| 301 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 302 | elsiocb->context2 = pcmd; |
| 303 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 304 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 305 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 306 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 307 | |
| 308 | if (prsp) { |
| 309 | list_add(&prsp->list, &pcmd->list); |
| 310 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 311 | if (expectRsp) { |
| 312 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 313 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 314 | "0116 Xmit ELS command x%x to remote " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 315 | "NPORT x%x I/O tag: x%x, port state:x%x" |
| 316 | " fc_flag:x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 317 | elscmd, did, elsiocb->iotag, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 318 | vport->port_state, |
| 319 | vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 320 | } else { |
| 321 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 322 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 323 | "0117 Xmit ELS response x%x to remote " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 324 | "NPORT x%x I/O tag: x%x, size: x%x " |
| 325 | "port_state x%x fc_flag x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 326 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 327 | cmdSize, vport->port_state, |
| 328 | vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 329 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 330 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 331 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 332 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 333 | if (expectRsp) |
| 334 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 335 | kfree(pbuflist); |
| 336 | |
| 337 | els_iocb_free_prsp_exit: |
| 338 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 339 | kfree(prsp); |
| 340 | |
| 341 | els_iocb_free_pcmb_exit: |
| 342 | kfree(pcmd); |
| 343 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 344 | return NULL; |
| 345 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 346 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 347 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 348 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 349 | * @vport: pointer to a host virtual N_Port data structure. |
| 350 | * |
| 351 | * This routine issues a fabric registration login for a @vport. An |
| 352 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 353 | * The routine invokes two mailbox commands to carry out fabric registration |
| 354 | * login through the HBA firmware: the first mailbox command requests the |
| 355 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 356 | * command requests the HBA to perform the actual fabric registration login |
| 357 | * with the @vport. |
| 358 | * |
| 359 | * Return code |
| 360 | * 0 - successfully issued fabric registration login for @vport |
| 361 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 362 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 363 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 364 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 365 | { |
| 366 | struct lpfc_hba *phba = vport->phba; |
| 367 | LPFC_MBOXQ_t *mbox; |
| 368 | struct lpfc_dmabuf *mp; |
| 369 | struct lpfc_nodelist *ndlp; |
| 370 | struct serv_parm *sp; |
| 371 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 372 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 373 | |
| 374 | sp = &phba->fc_fabparam; |
| 375 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 376 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 377 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 378 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 379 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 380 | |
| 381 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 382 | if (!mbox) { |
| 383 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 384 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 385 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 386 | |
| 387 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 388 | lpfc_config_link(phba, mbox); |
| 389 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 390 | mbox->vport = vport; |
| 391 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 392 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 393 | if (rc == MBX_NOT_FINISHED) { |
| 394 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 395 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 396 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 397 | |
| 398 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 399 | if (!mbox) { |
| 400 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 401 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 402 | } |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 403 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
| 404 | ndlp->nlp_rpi); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 405 | if (rc) { |
| 406 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 407 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 408 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 409 | |
| 410 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 411 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 412 | /* increment the reference count on ndlp to hold reference |
| 413 | * for the callback routine. |
| 414 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 415 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 416 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 417 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 418 | if (rc == MBX_NOT_FINISHED) { |
| 419 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 420 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 421 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 422 | |
| 423 | return 0; |
| 424 | |
| 425 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 426 | /* decrement the reference count on ndlp just incremented |
| 427 | * for the failed mbox command. |
| 428 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 429 | lpfc_nlp_put(ndlp); |
| 430 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 431 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 432 | kfree(mp); |
| 433 | fail_free_mbox: |
| 434 | mempool_free(mbox, phba->mbox_mem_pool); |
| 435 | |
| 436 | fail: |
| 437 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 438 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 439 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 440 | return -ENXIO; |
| 441 | } |
| 442 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 443 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 444 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 445 | * @vport: pointer to a host virtual N_Port data structure. |
| 446 | * |
| 447 | * 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] | 448 | * the @vport. This mailbox command is necessary for SLI4 port only. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 449 | * |
| 450 | * Return code |
| 451 | * 0 - successfully issued REG_VFI for @vport |
| 452 | * A failure code otherwise. |
| 453 | **/ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 454 | int |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 455 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 456 | { |
| 457 | struct lpfc_hba *phba = vport->phba; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 458 | LPFC_MBOXQ_t *mboxq = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 459 | struct lpfc_nodelist *ndlp; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 460 | struct lpfc_dmabuf *dmabuf = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 461 | int rc = 0; |
| 462 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 463 | /* 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] | 464 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 465 | !(phba->link_flag & LS_LOOPBACK_MODE) && |
| 466 | !(vport->fc_flag & FC_PT2PT)) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 467 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 468 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 469 | rc = -ENODEV; |
| 470 | goto fail; |
| 471 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 472 | } |
| 473 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 474 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 475 | if (!mboxq) { |
| 476 | rc = -ENOMEM; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 477 | goto fail; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 478 | } |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 479 | |
| 480 | /* Supply CSP's only if we are fabric connect or pt-to-pt connect */ |
| 481 | if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) { |
| 482 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 483 | if (!dmabuf) { |
| 484 | rc = -ENOMEM; |
| 485 | goto fail; |
| 486 | } |
| 487 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 488 | if (!dmabuf->virt) { |
| 489 | rc = -ENOMEM; |
| 490 | goto fail; |
| 491 | } |
| 492 | memcpy(dmabuf->virt, &phba->fc_fabparam, |
| 493 | sizeof(struct serv_parm)); |
| 494 | } |
| 495 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 496 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 497 | if (dmabuf) |
| 498 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 499 | else |
| 500 | lpfc_reg_vfi(mboxq, vport, 0); |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 501 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 502 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 503 | mboxq->vport = vport; |
| 504 | mboxq->context1 = dmabuf; |
| 505 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 506 | if (rc == MBX_NOT_FINISHED) { |
| 507 | rc = -ENXIO; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 508 | goto fail; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 509 | } |
| 510 | return 0; |
| 511 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 512 | fail: |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 513 | if (mboxq) |
| 514 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 515 | if (dmabuf) { |
| 516 | if (dmabuf->virt) |
| 517 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 518 | kfree(dmabuf); |
| 519 | } |
| 520 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 521 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 522 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 523 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 524 | return rc; |
| 525 | } |
| 526 | |
| 527 | /** |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 528 | * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login |
| 529 | * @vport: pointer to a host virtual N_Port data structure. |
| 530 | * |
| 531 | * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for |
| 532 | * the @vport. This mailbox command is necessary for SLI4 port only. |
| 533 | * |
| 534 | * Return code |
| 535 | * 0 - successfully issued REG_VFI for @vport |
| 536 | * A failure code otherwise. |
| 537 | **/ |
| 538 | int |
| 539 | lpfc_issue_unreg_vfi(struct lpfc_vport *vport) |
| 540 | { |
| 541 | struct lpfc_hba *phba = vport->phba; |
| 542 | struct Scsi_Host *shost; |
| 543 | LPFC_MBOXQ_t *mboxq; |
| 544 | int rc; |
| 545 | |
| 546 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 547 | if (!mboxq) { |
| 548 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 549 | "2556 UNREG_VFI mbox allocation failed" |
| 550 | "HBA state x%x\n", phba->pport->port_state); |
| 551 | return -ENOMEM; |
| 552 | } |
| 553 | |
| 554 | lpfc_unreg_vfi(mboxq, vport); |
| 555 | mboxq->vport = vport; |
| 556 | mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl; |
| 557 | |
| 558 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 559 | if (rc == MBX_NOT_FINISHED) { |
| 560 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 561 | "2557 UNREG_VFI issue mbox failed rc x%x " |
| 562 | "HBA state x%x\n", |
| 563 | rc, phba->pport->port_state); |
| 564 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 565 | return -EIO; |
| 566 | } |
| 567 | |
| 568 | shost = lpfc_shost_from_vport(vport); |
| 569 | spin_lock_irq(shost->host_lock); |
| 570 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 571 | spin_unlock_irq(shost->host_lock); |
| 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | /** |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 576 | * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean. |
| 577 | * @vport: pointer to a host virtual N_Port data structure. |
| 578 | * @sp: pointer to service parameter data structure. |
| 579 | * |
| 580 | * This routine is called from FLOGI/FDISC completion handler functions. |
| 581 | * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric |
| 582 | * node nodename is changed in the completion service parameter else return |
| 583 | * 0. This function also set flag in the vport data structure to delay |
| 584 | * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit |
| 585 | * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric |
| 586 | * node nodename is changed in the completion service parameter. |
| 587 | * |
| 588 | * Return code |
| 589 | * 0 - FCID and Fabric Nodename and Fabric portname is not changed. |
| 590 | * 1 - FCID or Fabric Nodename or Fabric portname is changed. |
| 591 | * |
| 592 | **/ |
| 593 | static uint8_t |
| 594 | lpfc_check_clean_addr_bit(struct lpfc_vport *vport, |
| 595 | struct serv_parm *sp) |
| 596 | { |
James Smart | 8eb8b96 | 2016-07-06 12:36:08 -0700 | [diff] [blame] | 597 | struct lpfc_hba *phba = vport->phba; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 598 | uint8_t fabric_param_changed = 0; |
| 599 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 600 | |
| 601 | if ((vport->fc_prevDID != vport->fc_myDID) || |
| 602 | memcmp(&vport->fabric_portname, &sp->portName, |
| 603 | sizeof(struct lpfc_name)) || |
| 604 | memcmp(&vport->fabric_nodename, &sp->nodeName, |
| 605 | sizeof(struct lpfc_name))) |
| 606 | fabric_param_changed = 1; |
| 607 | |
| 608 | /* |
| 609 | * Word 1 Bit 31 in common service parameter is overloaded. |
| 610 | * Word 1 Bit 31 in FLOGI request is multiple NPort request |
| 611 | * Word 1 Bit 31 in FLOGI response is clean address bit |
| 612 | * |
| 613 | * If fabric parameter is changed and clean address bit is |
| 614 | * cleared delay nport discovery if |
| 615 | * - vport->fc_prevDID != 0 (not initial discovery) OR |
| 616 | * - lpfc_delay_discovery module parameter is set. |
| 617 | */ |
| 618 | if (fabric_param_changed && !sp->cmn.clean_address_bit && |
James Smart | 8eb8b96 | 2016-07-06 12:36:08 -0700 | [diff] [blame] | 619 | (vport->fc_prevDID || phba->cfg_delay_discovery)) { |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 620 | spin_lock_irq(shost->host_lock); |
| 621 | vport->fc_flag |= FC_DISC_DELAYED; |
| 622 | spin_unlock_irq(shost->host_lock); |
| 623 | } |
| 624 | |
| 625 | return fabric_param_changed; |
| 626 | } |
| 627 | |
| 628 | |
| 629 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 630 | * 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] | 631 | * @vport: pointer to a host virtual N_Port data structure. |
| 632 | * @ndlp: pointer to a node-list data structure. |
| 633 | * @sp: pointer to service parameter data structure. |
| 634 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 635 | * |
| 636 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 637 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 638 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 639 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 640 | * @vport against the previously assigned N_Port ID. If it is different from |
| 641 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 642 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 643 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 644 | * is invoked to register login to the fabric. |
| 645 | * |
| 646 | * Return code |
| 647 | * 0 - Success (currently, always return 0) |
| 648 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 649 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 650 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 651 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 652 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 653 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 654 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 655 | struct lpfc_nodelist *np; |
| 656 | struct lpfc_nodelist *next_np; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 657 | uint8_t fabric_param_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 658 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 659 | spin_lock_irq(shost->host_lock); |
| 660 | vport->fc_flag |= FC_FABRIC; |
| 661 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 662 | |
| 663 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 664 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 665 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 666 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 667 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 668 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 669 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 670 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 671 | spin_lock_irq(shost->host_lock); |
| 672 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 673 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 674 | } |
| 675 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 676 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 677 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 678 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 679 | ndlp->nlp_class_sup = 0; |
| 680 | if (sp->cls1.classValid) |
| 681 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 682 | if (sp->cls2.classValid) |
| 683 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 684 | if (sp->cls3.classValid) |
| 685 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 686 | if (sp->cls4.classValid) |
| 687 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 688 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 689 | sp->cmn.bbRcvSizeLsb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 690 | |
| 691 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 692 | if (fabric_param_changed) { |
| 693 | /* Reset FDMI attribute masks based on config parameter */ |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 694 | if (phba->cfg_enable_SmartSAN || |
| 695 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 696 | /* Setup appropriate attribute masks */ |
| 697 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 698 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 699 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 700 | else |
| 701 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 702 | } else { |
| 703 | vport->fdmi_hba_mask = 0; |
| 704 | vport->fdmi_port_mask = 0; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | } |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 708 | memcpy(&vport->fabric_portname, &sp->portName, |
| 709 | sizeof(struct lpfc_name)); |
| 710 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 711 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 712 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 713 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 714 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 715 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 716 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 717 | LOG_ELS | LOG_VPORT, |
| 718 | "1816 FLOGI NPIV supported, " |
| 719 | "response data 0x%x\n", |
| 720 | sp->cmn.response_multiple_NPort); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 721 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 722 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 723 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 724 | } else { |
| 725 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 726 | to call reg_vnpid atleast for the physcial host */ |
| 727 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 728 | LOG_ELS | LOG_VPORT, |
| 729 | "1817 Fabric does not support NPIV " |
| 730 | "- configuring single port mode.\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 731 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 732 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 733 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 737 | /* |
| 738 | * For FC we need to do some special processing because of the SLI |
| 739 | * Port's default settings of the Common Service Parameters. |
| 740 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 741 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 742 | (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) { |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 743 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 744 | if (fabric_param_changed) |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 745 | lpfc_unregister_fcf_prep(phba); |
| 746 | |
| 747 | /* This should just update the VFI CSPs*/ |
| 748 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 749 | lpfc_issue_reg_vfi(vport); |
| 750 | } |
| 751 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 752 | if (fabric_param_changed && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 753 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 754 | |
| 755 | /* If our NportID changed, we need to ensure all |
| 756 | * remaining NPORTs get unreg_login'ed. |
| 757 | */ |
| 758 | list_for_each_entry_safe(np, next_np, |
| 759 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 760 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 761 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 762 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 763 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 764 | continue; |
| 765 | spin_lock_irq(shost->host_lock); |
| 766 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 767 | spin_unlock_irq(shost->host_lock); |
| 768 | lpfc_unreg_rpi(vport, np); |
| 769 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 770 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 771 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 772 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 773 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 774 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 775 | spin_lock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 776 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 777 | spin_unlock_irq(shost->host_lock); |
| 778 | } |
James Smart | 27aa1b7 | 2012-05-09 21:18:49 -0400 | [diff] [blame] | 779 | |
| 780 | /* |
| 781 | * For SLI3 and SLI4, the VPI needs to be reregistered in |
| 782 | * response to this fabric parameter change event. |
| 783 | */ |
| 784 | spin_lock_irq(shost->host_lock); |
| 785 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 786 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 787 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 788 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 789 | /* |
| 790 | * Driver needs to re-reg VPI in order for f/w |
| 791 | * to update the MAC address. |
| 792 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 793 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 794 | lpfc_register_new_vport(phba, vport, ndlp); |
| 795 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 796 | } |
| 797 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 798 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 799 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 800 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 801 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 802 | lpfc_register_new_vport(phba, vport, ndlp); |
| 803 | else |
| 804 | lpfc_issue_fabric_reglogin(vport); |
| 805 | } else { |
| 806 | ndlp->nlp_type |= NLP_FABRIC; |
| 807 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 808 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 809 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 810 | lpfc_start_fdiscs(phba); |
| 811 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 812 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 813 | lpfc_issue_init_vpi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 814 | else { |
| 815 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 816 | "3135 Need register VFI: (x%x/%x)\n", |
| 817 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 818 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 819 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 820 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 821 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 822 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 823 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 824 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 825 | * 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] | 826 | * @vport: pointer to a host virtual N_Port data structure. |
| 827 | * @ndlp: pointer to a node-list data structure. |
| 828 | * @sp: pointer to service parameter data structure. |
| 829 | * |
| 830 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 831 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 832 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 833 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 834 | * the received N_Port Name lexicographically, this node shall assign local |
| 835 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 836 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 837 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 838 | * N_Port IDs. |
| 839 | * |
| 840 | * Return code |
| 841 | * 0 - Success |
| 842 | * -ENXIO - Fail |
| 843 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 845 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 846 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 847 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 848 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 849 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 850 | LPFC_MBOXQ_t *mbox; |
| 851 | int rc; |
| 852 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 853 | spin_lock_irq(shost->host_lock); |
| 854 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 855 | vport->fc_flag |= FC_PT2PT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 856 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 857 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 858 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
| 859 | if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) { |
| 860 | lpfc_unregister_fcf_prep(phba); |
| 861 | |
| 862 | spin_lock_irq(shost->host_lock); |
| 863 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 864 | spin_unlock_irq(shost->host_lock); |
| 865 | phba->fc_topology_changed = 0; |
| 866 | } |
| 867 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 868 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 869 | sizeof(vport->fc_portname)); |
James Smart | 2eb6862 | 2012-09-29 11:32:27 -0400 | [diff] [blame] | 870 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 871 | if (rc >= 0) { |
| 872 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 873 | spin_lock_irq(shost->host_lock); |
| 874 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 875 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 876 | |
| 877 | /* |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 878 | * N_Port ID cannot be 0, set our Id to LocalID |
| 879 | * the other side will be RemoteID. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 880 | */ |
| 881 | |
| 882 | /* not equal */ |
| 883 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 884 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 885 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 886 | /* Decrement ndlp reference count indicating that ndlp can be |
| 887 | * safely released when other references to it are done. |
| 888 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 889 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 890 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 891 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 892 | if (!ndlp) { |
| 893 | /* |
| 894 | * Cannot find existing Fabric ndlp, so allocate a |
| 895 | * new one |
| 896 | */ |
| 897 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 898 | if (!ndlp) |
| 899 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 900 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 901 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 902 | ndlp = lpfc_enable_node(vport, ndlp, |
| 903 | NLP_STE_UNUSED_NODE); |
| 904 | if(!ndlp) |
| 905 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 909 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 910 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 911 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 912 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 913 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 914 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 915 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 916 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 917 | } else |
| 918 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 919 | * count indicating that ndlp can be released when other |
| 920 | * references to it are done. |
| 921 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 922 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 923 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 924 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 925 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 926 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 927 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 928 | if (!mbox) |
| 929 | goto fail; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 930 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 931 | lpfc_config_link(phba, mbox); |
| 932 | |
| 933 | mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
| 934 | mbox->vport = vport; |
| 935 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 936 | if (rc == MBX_NOT_FINISHED) { |
| 937 | mempool_free(mbox, phba->mbox_mem_pool); |
| 938 | goto fail; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 939 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 940 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 941 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 942 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 943 | return -ENXIO; |
| 944 | } |
| 945 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 946 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 947 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 948 | * @phba: pointer to lpfc hba data structure. |
| 949 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 950 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 951 | * |
| 952 | * This routine is the top-level completion callback function for issuing |
| 953 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 954 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 955 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 956 | * returning 1), the command IOCB will be released and function returned. |
| 957 | * If the retry attempt has been given up (possibly reach the maximum |
| 958 | * number of retries), one additional decrement of ndlp reference shall be |
| 959 | * invoked before going out after releasing the command IOCB. This will |
| 960 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 961 | * invoke one decrement of ndlp reference count). If no error reported in |
| 962 | * the IOCB status, the command Port ID field is used to determine whether |
| 963 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 964 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 965 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 966 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 967 | * specific topology completion conditions. |
| 968 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 969 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 970 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 971 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 972 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 973 | struct lpfc_vport *vport = cmdiocb->vport; |
| 974 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 975 | IOCB_t *irsp = &rspiocb->iocb; |
| 976 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 977 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 978 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 979 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 980 | int rc; |
| 981 | |
| 982 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 983 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 984 | /* One additional decrement on node reference count to |
| 985 | * trigger the release of the node |
| 986 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 987 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 988 | goto out; |
| 989 | } |
| 990 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 991 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 992 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 993 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 994 | vport->port_state); |
| 995 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 996 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 997 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 998 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 999 | * due to new FCF discovery |
| 1000 | */ |
| 1001 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1002 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 1003 | if (phba->link_state < LPFC_LINK_UP) |
| 1004 | goto stop_rr_fcf_flogi; |
| 1005 | if ((phba->fcoe_cvl_eventtag_attn == |
| 1006 | phba->fcoe_cvl_eventtag) && |
| 1007 | (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1008 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1009 | IOERR_SLI_ABORTED)) |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1010 | goto stop_rr_fcf_flogi; |
| 1011 | else |
| 1012 | phba->fcoe_cvl_eventtag_attn = |
| 1013 | phba->fcoe_cvl_eventtag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1014 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1015 | "2611 FLOGI failed on FCF (x%x), " |
| 1016 | "status:x%x/x%x, tmo:x%x, perform " |
| 1017 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1018 | phba->fcf.current_rec.fcf_indx, |
| 1019 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1020 | irsp->ulpTimeout); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1021 | lpfc_sli4_set_fcf_flogi_fail(phba, |
| 1022 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1023 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1024 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 1025 | if (rc) |
| 1026 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1027 | } |
| 1028 | |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1029 | stop_rr_fcf_flogi: |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1030 | /* FLOGI failure */ |
| 1031 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1032 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x " |
| 1033 | "Data x%x x%x\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1034 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1035 | irsp->ulpTimeout, phba->hba_flag, |
| 1036 | phba->fcf.fcf_flag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1037 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1038 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1039 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1040 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1041 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1042 | /* FLOGI failure */ |
| 1043 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1044 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 1045 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1046 | irsp->ulpTimeout); |
| 1047 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1048 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1049 | spin_lock_irq(shost->host_lock); |
| 1050 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 1051 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1052 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1053 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1054 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 1055 | * alpa map would take too long otherwise. |
| 1056 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1057 | if (phba->alpa_map[0] == 0) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1058 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1059 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1060 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1061 | (vport->fc_prevDID != vport->fc_myDID) || |
| 1062 | phba->fc_topology_changed)) { |
| 1063 | if (vport->fc_flag & FC_VFI_REGISTERED) { |
| 1064 | if (phba->fc_topology_changed) { |
| 1065 | lpfc_unregister_fcf_prep(phba); |
| 1066 | spin_lock_irq(shost->host_lock); |
| 1067 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 1068 | spin_unlock_irq(shost->host_lock); |
| 1069 | phba->fc_topology_changed = 0; |
| 1070 | } else { |
| 1071 | lpfc_sli4_unreg_all_rpis(vport); |
| 1072 | } |
| 1073 | } |
James Smart | 342b59c | 2016-03-31 14:12:31 -0700 | [diff] [blame] | 1074 | |
| 1075 | /* Do not register VFI if the driver aborted FLOGI */ |
| 1076 | if (!lpfc_error_lost_link(irsp)) |
| 1077 | lpfc_issue_reg_vfi(vport); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1078 | lpfc_nlp_put(ndlp); |
| 1079 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1080 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1081 | goto flogifail; |
| 1082 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1083 | spin_lock_irq(shost->host_lock); |
| 1084 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 1085 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1086 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1087 | |
| 1088 | /* |
| 1089 | * The FLogI succeeded. Sync the data for the CPU before |
| 1090 | * accessing it. |
| 1091 | */ |
| 1092 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 1093 | if (!prsp) |
| 1094 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1095 | sp = prsp->virt + sizeof(uint32_t); |
| 1096 | |
| 1097 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1098 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 1099 | "0101 FLOGI completes successfully, I/O tag:x%x, " |
| 1100 | "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] | 1101 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1102 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution, |
| 1103 | vport->port_state, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1104 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1105 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1106 | /* |
| 1107 | * If Common Service Parameters indicate Nport |
| 1108 | * we are point to point, if Fport we are Fabric. |
| 1109 | */ |
| 1110 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1111 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1112 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1113 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1114 | else { |
| 1115 | lpfc_printf_vlog(vport, KERN_ERR, |
| 1116 | LOG_FIP | LOG_ELS, |
| 1117 | "2831 FLOGI response with cleared Fabric " |
| 1118 | "bit fcf_index 0x%x " |
| 1119 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 1120 | "Fabric Name " |
| 1121 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 1122 | phba->fcf.current_rec.fcf_indx, |
| 1123 | phba->fcf.current_rec.switch_name[0], |
| 1124 | phba->fcf.current_rec.switch_name[1], |
| 1125 | phba->fcf.current_rec.switch_name[2], |
| 1126 | phba->fcf.current_rec.switch_name[3], |
| 1127 | phba->fcf.current_rec.switch_name[4], |
| 1128 | phba->fcf.current_rec.switch_name[5], |
| 1129 | phba->fcf.current_rec.switch_name[6], |
| 1130 | phba->fcf.current_rec.switch_name[7], |
| 1131 | phba->fcf.current_rec.fabric_name[0], |
| 1132 | phba->fcf.current_rec.fabric_name[1], |
| 1133 | phba->fcf.current_rec.fabric_name[2], |
| 1134 | phba->fcf.current_rec.fabric_name[3], |
| 1135 | phba->fcf.current_rec.fabric_name[4], |
| 1136 | phba->fcf.current_rec.fabric_name[5], |
| 1137 | phba->fcf.current_rec.fabric_name[6], |
| 1138 | phba->fcf.current_rec.fabric_name[7]); |
| 1139 | lpfc_nlp_put(ndlp); |
| 1140 | spin_lock_irq(&phba->hbalock); |
| 1141 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1142 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1143 | spin_unlock_irq(&phba->hbalock); |
| 1144 | goto out; |
| 1145 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1146 | if (!rc) { |
| 1147 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1148 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 1149 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 1150 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1151 | "2769 FLOGI to FCF (x%x) " |
| 1152 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1153 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1154 | spin_lock_irq(&phba->hbalock); |
| 1155 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1156 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1157 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1158 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1159 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | flogifail: |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1163 | spin_lock_irq(&phba->hbalock); |
| 1164 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 1165 | spin_unlock_irq(&phba->hbalock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1166 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1167 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1168 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1169 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1170 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1171 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1172 | |
| 1173 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1174 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1175 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1176 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1177 | IOERR_SLI_ABORTED) && |
| 1178 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1179 | IOERR_SLI_DOWN))) && |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1180 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 1181 | /* If FLOGI failed enable link interrupt. */ |
| 1182 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1183 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1184 | out: |
| 1185 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1186 | } |
| 1187 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1188 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1189 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1190 | * @vport: pointer to a host virtual N_Port data structure. |
| 1191 | * @ndlp: pointer to a node-list data structure. |
| 1192 | * @retry: number of retries to the command IOCB. |
| 1193 | * |
| 1194 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 1195 | * for a @vport. The initiator service parameters are put into the payload |
| 1196 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 1197 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 1198 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 1199 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 1200 | * |
| 1201 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1202 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1203 | * will be stored into the context1 field of the IOCB for the completion |
| 1204 | * callback function to the FLOGI ELS command. |
| 1205 | * |
| 1206 | * Return code |
| 1207 | * 0 - successfully issued flogi iocb for @vport |
| 1208 | * 1 - failed to issue flogi iocb for @vport |
| 1209 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1210 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1211 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1212 | uint8_t retry) |
| 1213 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1214 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1215 | struct serv_parm *sp; |
| 1216 | IOCB_t *icmd; |
| 1217 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1218 | uint8_t *pcmd; |
| 1219 | uint16_t cmdsize; |
| 1220 | uint32_t tmo; |
| 1221 | int rc; |
| 1222 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1223 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1224 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1225 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1226 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1227 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1228 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1229 | |
| 1230 | icmd = &elsiocb->iocb; |
| 1231 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1232 | |
| 1233 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1234 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1235 | pcmd += sizeof(uint32_t); |
| 1236 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1237 | sp = (struct serv_parm *) pcmd; |
| 1238 | |
| 1239 | /* Setup CSPs accordingly for Fabric */ |
| 1240 | sp->cmn.e_d_tov = 0; |
| 1241 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 1242 | sp->cmn.virtual_fabric_support = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | sp->cls1.classValid = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1244 | if (sp->cmn.fcphLow < FC_PH3) |
| 1245 | sp->cmn.fcphLow = FC_PH3; |
| 1246 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1247 | sp->cmn.fcphHigh = FC_PH3; |
| 1248 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 1249 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1250 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1251 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 1252 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1253 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1254 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1255 | /* Set the fcfi to the fcfi we registered with */ |
| 1256 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1257 | } |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1258 | /* Can't do SLI4 class2 without support sequence coalescing */ |
| 1259 | sp->cls2.classValid = 0; |
| 1260 | sp->cls2.seqDelivery = 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1261 | } else { |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1262 | /* Historical, setting sequential-delivery bit for SLI3 */ |
| 1263 | sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; |
| 1264 | sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1265 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 1266 | sp->cmn.request_multiple_Nport = 1; |
| 1267 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1268 | icmd->ulpCt_h = 1; |
| 1269 | icmd->ulpCt_l = 0; |
| 1270 | } else |
| 1271 | sp->cmn.request_multiple_Nport = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1272 | } |
| 1273 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1274 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1275 | icmd->un.elsreq64.myID = 0; |
| 1276 | icmd->un.elsreq64.fl = 1; |
| 1277 | } |
| 1278 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1279 | tmo = phba->fc_ratov; |
| 1280 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1281 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1282 | phba->fc_ratov = tmo; |
| 1283 | |
| 1284 | phba->fc_stat.elsXmitFLOGI++; |
| 1285 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1286 | |
| 1287 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1288 | "Issue FLOGI: opt:x%x", |
| 1289 | phba->sli3_options, 0, 0); |
| 1290 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1291 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1292 | if (rc == IOCB_ERROR) { |
| 1293 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1294 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1295 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1296 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1297 | } |
| 1298 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1299 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1300 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1301 | * @phba: pointer to lpfc hba data structure. |
| 1302 | * |
| 1303 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1304 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1305 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1306 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1307 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1308 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1309 | * |
| 1310 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1311 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1312 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1313 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1314 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1315 | { |
| 1316 | struct lpfc_sli_ring *pring; |
| 1317 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1318 | struct lpfc_nodelist *ndlp; |
| 1319 | IOCB_t *icmd; |
| 1320 | |
| 1321 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1322 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1323 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1324 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1325 | |
| 1326 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1327 | |
| 1328 | /* |
| 1329 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1330 | * searching for. |
| 1331 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1332 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1333 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1334 | icmd = &iocb->iocb; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1335 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1336 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1337 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1338 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1339 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1340 | } |
| 1341 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1342 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1343 | |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1347 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1348 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1349 | * @vport: pointer to a host virtual N_Port data structure. |
| 1350 | * |
| 1351 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1352 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1353 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1354 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1355 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1356 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1357 | * @vport. |
| 1358 | * |
| 1359 | * Return code |
| 1360 | * 0 - failed to issue initial flogi for @vport |
| 1361 | * 1 - successfully issued initial flogi for @vport |
| 1362 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1363 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1364 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1365 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1366 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1367 | struct lpfc_nodelist *ndlp; |
| 1368 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1369 | vport->port_state = LPFC_FLOGI; |
| 1370 | lpfc_set_disctmo(vport); |
| 1371 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1372 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1373 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1374 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1375 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1376 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1377 | if (!ndlp) |
| 1378 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1379 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
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 | { |
| 1420 | struct lpfc_hba *phba = vport->phba; |
| 1421 | struct lpfc_nodelist *ndlp; |
| 1422 | |
| 1423 | /* First look for the Fabric ndlp */ |
| 1424 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1425 | if (!ndlp) { |
| 1426 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1427 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1428 | if (!ndlp) |
| 1429 | return 0; |
| 1430 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1431 | /* Put ndlp onto node list */ |
| 1432 | lpfc_enqueue_node(vport, ndlp); |
| 1433 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1434 | /* re-setup ndlp without removing from node list */ |
| 1435 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1436 | if (!ndlp) |
| 1437 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1438 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1439 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1440 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1441 | /* decrement node reference count to trigger the release of |
| 1442 | * the node. |
| 1443 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1444 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1445 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1446 | } |
| 1447 | return 1; |
| 1448 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1449 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1450 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1451 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1452 | * @vport: pointer to a host virtual N_Port data structure. |
| 1453 | * |
| 1454 | * This routine checks whether there are more remaining Port Logins |
| 1455 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1456 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1457 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1458 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1459 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1460 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1461 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1462 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1463 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1464 | if (vport->num_disc_nodes) |
| 1465 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1466 | |
| 1467 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1468 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1469 | "0232 Continue discovery with %d PLOGIs to go " |
| 1470 | "Data: x%x x%x x%x\n", |
| 1471 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1472 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1473 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1474 | if (vport->fc_flag & FC_NLP_MORE) |
| 1475 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 1476 | lpfc_els_disc_plogi(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1477 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1478 | return; |
| 1479 | } |
| 1480 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1481 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1482 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1483 | * @phba: pointer to lpfc hba data structure. |
| 1484 | * @prsp: pointer to response IOCB payload. |
| 1485 | * @ndlp: pointer to a node-list data structure. |
| 1486 | * |
| 1487 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1488 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1489 | * The following cases are considered N_Port confirmed: |
| 1490 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1491 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1492 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1493 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1494 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1495 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1496 | * on that node to release the RPI associated with the node; 2) if there is |
| 1497 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1498 | * into, a new node shall be allocated (or activated). In either case, the |
| 1499 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1500 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1501 | * its pointer returned as the confirmed node. |
| 1502 | * |
| 1503 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1504 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1505 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1506 | * into an inactive state on the vport node list and the vport node list |
| 1507 | * management algorithm does not allow two node with a same DID. |
| 1508 | * |
| 1509 | * Return code |
| 1510 | * pointer to the PLOGI N_Port @ndlp |
| 1511 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1512 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1513 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1514 | struct lpfc_nodelist *ndlp) |
| 1515 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1516 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1517 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1518 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1519 | struct lpfc_rport_data *rdata; |
| 1520 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1521 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1522 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1523 | uint32_t rc, keepDID = 0, keep_nlp_flag = 0; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1524 | uint16_t keep_nlp_state; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1525 | int put_node; |
| 1526 | int put_rport; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1527 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1528 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1529 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1530 | * by WWPN. Just return the ndlp that was given to us. |
| 1531 | */ |
| 1532 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1533 | return ndlp; |
| 1534 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1535 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1536 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1537 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1538 | /* 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] | 1539 | * we have for that ndlp. If not, we have some work to do. |
| 1540 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1541 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1542 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1543 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1544 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1545 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1546 | active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool, |
| 1547 | GFP_KERNEL); |
| 1548 | if (active_rrqs_xri_bitmap) |
| 1549 | memset(active_rrqs_xri_bitmap, 0, |
| 1550 | phba->cfg_rrq_xri_bitmap_sz); |
| 1551 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1552 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1553 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1554 | "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n", |
| 1555 | ndlp, ndlp->nlp_DID, new_ndlp); |
| 1556 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1557 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1558 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1559 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1560 | if (!rc) { |
| 1561 | if (active_rrqs_xri_bitmap) |
| 1562 | mempool_free(active_rrqs_xri_bitmap, |
| 1563 | phba->active_rrq_pool); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1564 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1565 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1566 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1567 | if (!new_ndlp) { |
| 1568 | if (active_rrqs_xri_bitmap) |
| 1569 | mempool_free(active_rrqs_xri_bitmap, |
| 1570 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1571 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1572 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1573 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1574 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1575 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1576 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1577 | if (!rc) { |
| 1578 | if (active_rrqs_xri_bitmap) |
| 1579 | mempool_free(active_rrqs_xri_bitmap, |
| 1580 | phba->active_rrq_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1581 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1582 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1583 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1584 | NLP_STE_UNUSED_NODE); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1585 | if (!new_ndlp) { |
| 1586 | if (active_rrqs_xri_bitmap) |
| 1587 | mempool_free(active_rrqs_xri_bitmap, |
| 1588 | phba->active_rrq_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1589 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1590 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1591 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1592 | if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap) |
| 1593 | memcpy(active_rrqs_xri_bitmap, |
| 1594 | new_ndlp->active_rrqs_xri_bitmap, |
| 1595 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1596 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1597 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1598 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1599 | active_rrqs_xri_bitmap) |
| 1600 | memcpy(active_rrqs_xri_bitmap, |
| 1601 | new_ndlp->active_rrqs_xri_bitmap, |
| 1602 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1603 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1604 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1605 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1606 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1607 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1608 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1609 | memcpy(new_ndlp->active_rrqs_xri_bitmap, |
| 1610 | ndlp->active_rrqs_xri_bitmap, |
| 1611 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1612 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1613 | spin_lock_irq(shost->host_lock); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1614 | keep_nlp_flag = new_ndlp->nlp_flag; |
| 1615 | new_ndlp->nlp_flag = ndlp->nlp_flag; |
| 1616 | ndlp->nlp_flag = keep_nlp_flag; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1617 | spin_unlock_irq(shost->host_lock); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1618 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1619 | /* Set nlp_states accordingly */ |
| 1620 | keep_nlp_state = new_ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1621 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1622 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1623 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1624 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1625 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1626 | * to put ndlp on UNUSED list and try to free it. |
| 1627 | */ |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1628 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1629 | "3179 PLOGI confirm NEW: %x %x\n", |
| 1630 | new_ndlp->nlp_DID, keepDID); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1631 | |
| 1632 | /* Fix up the rport accordingly */ |
| 1633 | rport = ndlp->rport; |
| 1634 | if (rport) { |
| 1635 | rdata = rport->dd_data; |
| 1636 | if (rdata->pnode == ndlp) { |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1637 | /* break the link before dropping the ref */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1638 | ndlp->rport = NULL; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1639 | lpfc_nlp_put(ndlp); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1640 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1641 | new_ndlp->rport = rport; |
| 1642 | } |
| 1643 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1644 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1645 | /* We shall actually free the ndlp with both nlp_DID and |
| 1646 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1647 | * nodelist never to be used. |
| 1648 | */ |
| 1649 | if (ndlp->nlp_DID == 0) { |
| 1650 | spin_lock_irq(&phba->ndlp_lock); |
| 1651 | NLP_SET_FREE_REQ(ndlp); |
| 1652 | spin_unlock_irq(&phba->ndlp_lock); |
| 1653 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1654 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1655 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1656 | ndlp->nlp_DID = keepDID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1657 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1658 | active_rrqs_xri_bitmap) |
| 1659 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1660 | active_rrqs_xri_bitmap, |
| 1661 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1662 | |
| 1663 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 1664 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1665 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1666 | else { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1667 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1668 | "3180 PLOGI confirm SWAP: %x %x\n", |
| 1669 | new_ndlp->nlp_DID, keepDID); |
| 1670 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1671 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1672 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1673 | /* Two ndlps cannot have the same did */ |
| 1674 | ndlp->nlp_DID = keepDID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1675 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1676 | active_rrqs_xri_bitmap) |
| 1677 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1678 | active_rrqs_xri_bitmap, |
| 1679 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1680 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1681 | /* Since we are switching over to the new_ndlp, |
| 1682 | * reset the old ndlp state |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1683 | */ |
| 1684 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 1685 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1686 | keep_nlp_state = NLP_STE_NPR_NODE; |
| 1687 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1688 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1689 | /* Fix up the rport accordingly */ |
| 1690 | rport = ndlp->rport; |
| 1691 | if (rport) { |
| 1692 | rdata = rport->dd_data; |
| 1693 | put_node = rdata->pnode != NULL; |
| 1694 | put_rport = ndlp->rport != NULL; |
| 1695 | rdata->pnode = NULL; |
| 1696 | ndlp->rport = NULL; |
| 1697 | if (put_node) |
| 1698 | lpfc_nlp_put(ndlp); |
| 1699 | if (put_rport) |
| 1700 | put_device(&rport->dev); |
| 1701 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1702 | } |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1703 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1704 | active_rrqs_xri_bitmap) |
| 1705 | mempool_free(active_rrqs_xri_bitmap, |
| 1706 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1707 | return new_ndlp; |
| 1708 | } |
| 1709 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1710 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1711 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1712 | * @vport: pointer to a host virtual N_Port data structure. |
| 1713 | * |
| 1714 | * This routine checks whether more Registration State Change |
| 1715 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1716 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1717 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1718 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1719 | * handling the RSCNs. |
| 1720 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1721 | void |
| 1722 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1723 | { |
| 1724 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1725 | |
| 1726 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1727 | /* |
| 1728 | * Check to see if more RSCNs came in while we were |
| 1729 | * processing this one. |
| 1730 | */ |
| 1731 | if (vport->fc_rscn_id_cnt || |
| 1732 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1733 | lpfc_els_handle_rscn(vport); |
| 1734 | else { |
| 1735 | spin_lock_irq(shost->host_lock); |
| 1736 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1737 | spin_unlock_irq(shost->host_lock); |
| 1738 | } |
| 1739 | } |
| 1740 | } |
| 1741 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1742 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1743 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. |
| 1744 | * @phba: pointer to lpfc hba data structure. |
| 1745 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1746 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1747 | * |
| 1748 | * This routine will call the clear rrq function to free the rrq and |
| 1749 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not |
| 1750 | * exist then the clear_rrq is still called because the rrq needs to |
| 1751 | * be freed. |
| 1752 | **/ |
| 1753 | |
| 1754 | static void |
| 1755 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1756 | struct lpfc_iocbq *rspiocb) |
| 1757 | { |
| 1758 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1759 | IOCB_t *irsp; |
| 1760 | struct lpfc_nodelist *ndlp; |
| 1761 | struct lpfc_node_rrq *rrq; |
| 1762 | |
| 1763 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1764 | rrq = cmdiocb->context_un.rrq; |
| 1765 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1766 | |
| 1767 | irsp = &rspiocb->iocb; |
| 1768 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1769 | "RRQ cmpl: status:x%x/x%x did:x%x", |
| 1770 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1771 | irsp->un.elsreq64.remoteID); |
| 1772 | |
| 1773 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
| 1774 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { |
| 1775 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1776 | "2882 RRQ completes to NPort x%x " |
| 1777 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1778 | irsp->un.elsreq64.remoteID, |
| 1779 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1780 | irsp->ulpIoTag); |
| 1781 | goto out; |
| 1782 | } |
| 1783 | |
| 1784 | /* rrq completes to NPort <nlp_DID> */ |
| 1785 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1786 | "2880 RRQ completes to NPort x%x " |
| 1787 | "Data: x%x x%x x%x x%x x%x\n", |
| 1788 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1789 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); |
| 1790 | |
| 1791 | if (irsp->ulpStatus) { |
| 1792 | /* Check for retry */ |
| 1793 | /* RRQ failed Don't print the vport to vport rjts */ |
| 1794 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1795 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1796 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1797 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1798 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1799 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", |
| 1800 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1801 | irsp->un.ulpWord[4]); |
| 1802 | } |
| 1803 | out: |
| 1804 | if (rrq) |
| 1805 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1806 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1807 | return; |
| 1808 | } |
| 1809 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1810 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1811 | * @phba: pointer to lpfc hba data structure. |
| 1812 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1813 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1814 | * |
| 1815 | * This routine is the completion callback function for issuing the Port |
| 1816 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1817 | * 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] | 1818 | * 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] | 1819 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1820 | * checked for error conditons. If there is error status reported, PLOGI |
| 1821 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1822 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1823 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1824 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1825 | * there are additional N_Port nodes with the vport that need to perform |
| 1826 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1827 | * PLOGIs. |
| 1828 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1829 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1830 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1831 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1832 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1833 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1834 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1835 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1836 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1837 | struct lpfc_dmabuf *prsp; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 1838 | int disc, rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1839 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1840 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1841 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1842 | |
| 1843 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1844 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1845 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1846 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1847 | irsp->un.elsreq64.remoteID); |
| 1848 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1849 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1850 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1851 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1852 | "0136 PLOGI completes to NPort x%x " |
| 1853 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1854 | irsp->un.elsreq64.remoteID, |
| 1855 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1856 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1857 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1858 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1859 | |
| 1860 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1861 | * is being used during discovery. |
| 1862 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1863 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1864 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1865 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1866 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1867 | rc = 0; |
| 1868 | |
| 1869 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1870 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1871 | "0102 PLOGI completes to NPort x%x " |
| 1872 | "Data: x%x x%x x%x x%x x%x\n", |
| 1873 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1874 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1875 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1876 | if (lpfc_els_chk_latt(vport)) { |
| 1877 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1878 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1879 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1880 | goto out; |
| 1881 | } |
| 1882 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1883 | if (irsp->ulpStatus) { |
| 1884 | /* Check for retry */ |
| 1885 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1886 | /* ELS command is being retried */ |
| 1887 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1888 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1889 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1890 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1891 | } |
| 1892 | goto out; |
| 1893 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1894 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1895 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1896 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1897 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1898 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1899 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1900 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1901 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1902 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1903 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1904 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1905 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1906 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1907 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1908 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1909 | } else { |
| 1910 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1911 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1912 | cmdiocb->context2)->list.next, |
| 1913 | struct lpfc_dmabuf, list); |
| 1914 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1915 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1916 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1917 | } |
| 1918 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1919 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1920 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1921 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1922 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1923 | if (vport->num_disc_nodes == 0) { |
| 1924 | spin_lock_irq(shost->host_lock); |
| 1925 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1926 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1927 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1928 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1929 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | out: |
| 1934 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1935 | return; |
| 1936 | } |
| 1937 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1938 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1939 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1940 | * @vport: pointer to a host virtual N_Port data structure. |
| 1941 | * @did: destination port identifier. |
| 1942 | * @retry: number of retries to the command IOCB. |
| 1943 | * |
| 1944 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1945 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1946 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1947 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1948 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1949 | * |
| 1950 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1951 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1952 | * will be stored into the context1 field of the IOCB for the completion |
| 1953 | * callback function to the PLOGI ELS command. |
| 1954 | * |
| 1955 | * Return code |
| 1956 | * 0 - Successfully issued a plogi for @vport |
| 1957 | * 1 - failed to issue a plogi for @vport |
| 1958 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1959 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1960 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1961 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1962 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1963 | struct serv_parm *sp; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1964 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1965 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1966 | uint8_t *pcmd; |
| 1967 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1968 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1969 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1970 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1971 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1972 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1973 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1974 | /* 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] | 1975 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1976 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1977 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1978 | if (!elsiocb) |
| 1979 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1980 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1981 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1982 | |
| 1983 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1984 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1985 | pcmd += sizeof(uint32_t); |
| 1986 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1987 | sp = (struct serv_parm *) pcmd; |
| 1988 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1989 | /* |
| 1990 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 1991 | * to device on remote loops work. |
| 1992 | */ |
| 1993 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 1994 | sp->cmn.altBbCredit = 1; |
| 1995 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1996 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1997 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1998 | |
| 1999 | if (sp->cmn.fcphHigh < FC_PH3) |
| 2000 | sp->cmn.fcphHigh = FC_PH3; |
| 2001 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2002 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2003 | "Issue PLOGI: did:x%x", |
| 2004 | did, 0, 0); |
| 2005 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | phba->fc_stat.elsXmitPLOGI++; |
| 2007 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2008 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2009 | |
| 2010 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2011 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2012 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2013 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2014 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2015 | } |
| 2016 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2017 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2018 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2019 | * @phba: pointer to lpfc hba data structure. |
| 2020 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2021 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2022 | * |
| 2023 | * This routine is the completion callback function for a Process Login |
| 2024 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 2025 | * status. If there is error status reported, PRLI retry shall be attempted |
| 2026 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 2027 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 2028 | * ndlp to mark the PRLI completion. |
| 2029 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2030 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2031 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2032 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2033 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2034 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2035 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2036 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | struct lpfc_nodelist *ndlp; |
| 2038 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2039 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2040 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2041 | |
| 2042 | irsp = &(rspiocb->iocb); |
| 2043 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2044 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2045 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2046 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2048 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2049 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 2050 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2051 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2052 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2053 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2054 | "0103 PRLI completes to NPort x%x " |
| 2055 | "Data: x%x x%x x%x x%x\n", |
| 2056 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2057 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2058 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2059 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2060 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2061 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2062 | goto out; |
| 2063 | |
| 2064 | if (irsp->ulpStatus) { |
| 2065 | /* Check for retry */ |
| 2066 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2067 | /* ELS command is being retried */ |
| 2068 | goto out; |
| 2069 | } |
| 2070 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2071 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2072 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 2073 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2074 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2075 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2076 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2077 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2078 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2079 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2080 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2081 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2082 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2083 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2084 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2085 | out: |
| 2086 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2087 | return; |
| 2088 | } |
| 2089 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2090 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2091 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2092 | * @vport: pointer to a host virtual N_Port data structure. |
| 2093 | * @ndlp: pointer to a node-list data structure. |
| 2094 | * @retry: number of retries to the command IOCB. |
| 2095 | * |
| 2096 | * This routine issues a Process Login (PRLI) ELS command for the |
| 2097 | * @vport. The PRLI service parameters are set up in the payload of the |
| 2098 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 2099 | * is put to the IOCB completion callback func field before invoking the |
| 2100 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 2101 | * |
| 2102 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2103 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2104 | * will be stored into the context1 field of the IOCB for the completion |
| 2105 | * callback function to the PRLI ELS command. |
| 2106 | * |
| 2107 | * Return code |
| 2108 | * 0 - successfully issued prli iocb command for @vport |
| 2109 | * 1 - failed to issue prli iocb command for @vport |
| 2110 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2111 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2112 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2113 | uint8_t retry) |
| 2114 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2115 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2116 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2117 | PRLI *npr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2118 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | uint8_t *pcmd; |
| 2120 | uint16_t cmdsize; |
| 2121 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2122 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2123 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2124 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2125 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2126 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2127 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2128 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2129 | |
| 2130 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2131 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2132 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2133 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2134 | |
| 2135 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 2136 | npr = (PRLI *) pcmd; |
| 2137 | /* |
| 2138 | * If our firmware version is 3.20 or later, |
| 2139 | * set the following bits for FC-TAPE support. |
| 2140 | */ |
| 2141 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 2142 | npr->ConfmComplAllowed = 1; |
| 2143 | npr->Retry = 1; |
| 2144 | npr->TaskRetryIdReq = 1; |
| 2145 | } |
| 2146 | npr->estabImagePair = 1; |
| 2147 | npr->readXferRdyDis = 1; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 2148 | if (vport->cfg_first_burst_size) |
| 2149 | npr->writeXferRdyDis = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | |
| 2151 | /* For FCP support */ |
| 2152 | npr->prliType = PRLI_FCP_TYPE; |
| 2153 | npr->initiatorFunc = 1; |
| 2154 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2155 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2156 | "Issue PRLI: did:x%x", |
| 2157 | ndlp->nlp_DID, 0, 0); |
| 2158 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2159 | phba->fc_stat.elsXmitPRLI++; |
| 2160 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2161 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2163 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2164 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2165 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2166 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2167 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2168 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2170 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2171 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2172 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2173 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2174 | } |
| 2175 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2176 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2177 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2178 | * @vport: pointer to a host virtual N_Port data structure. |
| 2179 | * |
| 2180 | * This routine performs Registration State Change Notification (RSCN) |
| 2181 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 2182 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 2183 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 2184 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 2185 | * invoked to check and handle possible more RSCN came in during the period |
| 2186 | * of processing the current ones. |
| 2187 | **/ |
| 2188 | static void |
| 2189 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 2190 | { |
| 2191 | lpfc_can_disctmo(vport); |
| 2192 | |
| 2193 | /* RSCN discovery */ |
| 2194 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 2195 | if (vport->fc_npr_cnt) |
| 2196 | if (lpfc_els_disc_plogi(vport)) |
| 2197 | return; |
| 2198 | |
| 2199 | lpfc_end_rscn(vport); |
| 2200 | } |
| 2201 | |
| 2202 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2203 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2204 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 2205 | * |
| 2206 | * This function is called when the final ADISC is completed during discovery. |
| 2207 | * This function handles clearing link attention or issuing reg_vpi depending |
| 2208 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 2209 | * discovery. |
| 2210 | * This function is called with no locks held. |
| 2211 | **/ |
| 2212 | static void |
| 2213 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 2214 | { |
| 2215 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2216 | struct lpfc_hba *phba = vport->phba; |
| 2217 | |
| 2218 | /* |
| 2219 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 2220 | * and continue discovery. |
| 2221 | */ |
| 2222 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2223 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 2224 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | d454c91 | 2014-12-30 12:08:58 -0500 | [diff] [blame] | 2225 | /* The ADISCs are complete. Doesn't matter if they |
| 2226 | * succeeded or failed because the ADISC completion |
| 2227 | * routine guarantees to call the state machine and |
| 2228 | * the RPI is either unregistered (failed ADISC response) |
| 2229 | * or the RPI is still valid and the node is marked |
| 2230 | * mapped for a target. The exchanges should be in the |
| 2231 | * correct state. This code is specific to SLI3. |
| 2232 | */ |
| 2233 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2234 | lpfc_issue_reg_vpi(phba, vport); |
| 2235 | return; |
| 2236 | } |
| 2237 | /* |
| 2238 | * For SLI2, we need to set port_state to READY |
| 2239 | * and continue discovery. |
| 2240 | */ |
| 2241 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2242 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 2243 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2244 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 2245 | vport->num_disc_nodes = 0; |
| 2246 | /* go thru NPR list, issue ELS PLOGIs */ |
| 2247 | if (vport->fc_npr_cnt) |
| 2248 | lpfc_els_disc_plogi(vport); |
| 2249 | if (!vport->num_disc_nodes) { |
| 2250 | spin_lock_irq(shost->host_lock); |
| 2251 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2252 | spin_unlock_irq(shost->host_lock); |
| 2253 | lpfc_can_disctmo(vport); |
| 2254 | lpfc_end_rscn(vport); |
| 2255 | } |
| 2256 | } |
| 2257 | vport->port_state = LPFC_VPORT_READY; |
| 2258 | } else |
| 2259 | lpfc_rscn_disc(vport); |
| 2260 | } |
| 2261 | |
| 2262 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2263 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2264 | * @vport: pointer to a host virtual N_Port data structure. |
| 2265 | * |
| 2266 | * This routine determines whether there are more ndlps on a @vport |
| 2267 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 2268 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 2269 | * remaining nodes which need to have ADISC sent. |
| 2270 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2271 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2272 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2274 | if (vport->num_disc_nodes) |
| 2275 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2276 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2277 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2278 | "0210 Continue discovery with %d ADISCs to go " |
| 2279 | "Data: x%x x%x x%x\n", |
| 2280 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 2281 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2282 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2283 | if (vport->fc_flag & FC_NLP_MORE) { |
| 2284 | lpfc_set_disctmo(vport); |
| 2285 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 2286 | lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2287 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2288 | if (!vport->num_disc_nodes) |
| 2289 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2290 | return; |
| 2291 | } |
| 2292 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2293 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2294 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2295 | * @phba: pointer to lpfc hba data structure. |
| 2296 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2297 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2298 | * |
| 2299 | * This routine is the completion function for issuing the Address Discover |
| 2300 | * (ADISC) command. It first checks to see whether link went down during |
| 2301 | * the discovery process. If so, the node will be marked as node port |
| 2302 | * recovery for issuing discover IOCB by the link attention handler and |
| 2303 | * exit. Otherwise, the response status is checked. If error was reported |
| 2304 | * in the response status, the ADISC command shall be retried by invoking |
| 2305 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 2306 | * the response status, the state machine is invoked to set transition |
| 2307 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 2308 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2310 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2311 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2312 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2313 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2314 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2316 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2317 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2318 | |
| 2319 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2320 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2321 | |
| 2322 | irsp = &(rspiocb->iocb); |
| 2323 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2324 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2325 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2326 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 2327 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2328 | ndlp->nlp_DID); |
| 2329 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2330 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2331 | * is being used during discovery. |
| 2332 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2333 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2334 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2335 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2336 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2337 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2338 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2339 | "0104 ADISC completes to NPort x%x " |
| 2340 | "Data: x%x x%x x%x x%x x%x\n", |
| 2341 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2342 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2343 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2344 | if (lpfc_els_chk_latt(vport)) { |
| 2345 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2346 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2347 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | goto out; |
| 2349 | } |
| 2350 | |
| 2351 | if (irsp->ulpStatus) { |
| 2352 | /* Check for retry */ |
| 2353 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2354 | /* ELS command is being retried */ |
| 2355 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2356 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2357 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2358 | spin_unlock_irq(shost->host_lock); |
| 2359 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2360 | } |
| 2361 | goto out; |
| 2362 | } |
| 2363 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2364 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2365 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2366 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2367 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2368 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2369 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2370 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2371 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2372 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2373 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2374 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2375 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2376 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2377 | /* Check to see if there are more ADISCs to be sent */ |
| 2378 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2379 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2380 | out: |
| 2381 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2382 | return; |
| 2383 | } |
| 2384 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2385 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2386 | * 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] | 2387 | * @vport: pointer to a virtual N_Port data structure. |
| 2388 | * @ndlp: pointer to a node-list data structure. |
| 2389 | * @retry: number of retries to the command IOCB. |
| 2390 | * |
| 2391 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2392 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2393 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2394 | * to issue the ADISC ELS command. |
| 2395 | * |
| 2396 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2397 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2398 | * will be stored into the context1 field of the IOCB for the completion |
| 2399 | * callback function to the ADISC ELS command. |
| 2400 | * |
| 2401 | * Return code |
| 2402 | * 0 - successfully issued adisc |
| 2403 | * 1 - failed to issue adisc |
| 2404 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2405 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2406 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | uint8_t retry) |
| 2408 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2409 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2410 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2411 | ADISC *ap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2412 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2413 | uint8_t *pcmd; |
| 2414 | uint16_t cmdsize; |
| 2415 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2416 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2417 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2418 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2419 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2420 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2421 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2423 | |
| 2424 | /* For ADISC request, remainder of payload is service parameters */ |
| 2425 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2426 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2427 | |
| 2428 | /* Fill in ADISC payload */ |
| 2429 | ap = (ADISC *) pcmd; |
| 2430 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2431 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2432 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2433 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2434 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2435 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2436 | "Issue ADISC: did:x%x", |
| 2437 | ndlp->nlp_DID, 0, 0); |
| 2438 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2439 | phba->fc_stat.elsXmitADISC++; |
| 2440 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2441 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2442 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2443 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2444 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2445 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2446 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2448 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2449 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2450 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2451 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2452 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2453 | } |
| 2454 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2455 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2456 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2457 | * @phba: pointer to lpfc hba data structure. |
| 2458 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2459 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2460 | * |
| 2461 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2462 | * command. If no error status was reported from the LOGO response, the |
| 2463 | * state machine of the associated ndlp shall be invoked for transition with |
| 2464 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2465 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2466 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2467 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2468 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2469 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2470 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2471 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2472 | struct lpfc_vport *vport = ndlp->vport; |
| 2473 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2474 | IOCB_t *irsp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2475 | struct lpfcMboxq *mbox; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2476 | unsigned long flags; |
| 2477 | uint32_t skip_recovery = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2478 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2479 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2480 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2481 | |
| 2482 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2483 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2484 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2485 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2486 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2487 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2488 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2489 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2490 | ndlp->nlp_DID); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2491 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2492 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2493 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2494 | "0105 LOGO completes to NPort x%x " |
| 2495 | "Data: x%x x%x x%x x%x\n", |
| 2496 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2497 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2498 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2499 | if (lpfc_els_chk_latt(vport)) { |
| 2500 | skip_recovery = 1; |
| 2501 | goto out; |
| 2502 | } |
| 2503 | |
| 2504 | /* Check to see if link went down during discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2505 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2506 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2507 | * which should abort all outstanding IOs. |
| 2508 | */ |
| 2509 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2510 | NLP_EVT_DEVICE_RM); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2511 | skip_recovery = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2512 | goto out; |
| 2513 | } |
| 2514 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2515 | if (irsp->ulpStatus) { |
| 2516 | /* Check for retry */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2517 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2518 | /* ELS command is being retried */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2519 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2520 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2521 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2522 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2523 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2524 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2525 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2526 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2527 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2528 | if (lpfc_error_lost_link(irsp)) { |
| 2529 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2530 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2531 | } |
| 2532 | } |
| 2533 | |
| 2534 | /* Call state machine. This will unregister the rpi if needed. */ |
| 2535 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); |
| 2536 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2537 | out: |
| 2538 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2539 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ |
| 2540 | if ((vport->fc_flag & FC_PT2PT) && |
| 2541 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { |
| 2542 | phba->pport->fc_myDID = 0; |
| 2543 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2544 | if (mbox) { |
| 2545 | lpfc_config_link(phba, mbox); |
| 2546 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2547 | mbox->vport = vport; |
| 2548 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 2549 | MBX_NOT_FINISHED) { |
| 2550 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2551 | skip_recovery = 1; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2552 | } |
| 2553 | } |
| 2554 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2555 | |
| 2556 | /* |
| 2557 | * If the node is a target, the handling attempts to recover the port. |
| 2558 | * For any other port type, the rpi is unregistered as an implicit |
| 2559 | * LOGO. |
| 2560 | */ |
| 2561 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) { |
| 2562 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 2563 | spin_lock_irqsave(shost->host_lock, flags); |
| 2564 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 2565 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2566 | |
| 2567 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2568 | "3187 LOGO completes to NPort x%x: Start " |
| 2569 | "Recovery Data: x%x x%x x%x x%x\n", |
| 2570 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2571 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 2572 | vport->num_disc_nodes); |
| 2573 | lpfc_disc_start(vport); |
| 2574 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2575 | return; |
| 2576 | } |
| 2577 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2578 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2579 | * 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] | 2580 | * @vport: pointer to a virtual N_Port data structure. |
| 2581 | * @ndlp: pointer to a node-list data structure. |
| 2582 | * @retry: number of retries to the command IOCB. |
| 2583 | * |
| 2584 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2585 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2586 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2587 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2588 | * |
| 2589 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2590 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2591 | * will be stored into the context1 field of the IOCB for the completion |
| 2592 | * callback function to the LOGO ELS command. |
| 2593 | * |
| 2594 | * Return code |
| 2595 | * 0 - successfully issued logo |
| 2596 | * 1 - failed to issue logo |
| 2597 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2598 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2599 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2600 | uint8_t retry) |
| 2601 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2602 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2603 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2604 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2605 | uint8_t *pcmd; |
| 2606 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2607 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2608 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2609 | spin_lock_irq(shost->host_lock); |
| 2610 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2611 | spin_unlock_irq(shost->host_lock); |
| 2612 | return 0; |
| 2613 | } |
| 2614 | spin_unlock_irq(shost->host_lock); |
| 2615 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2616 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2617 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2618 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2619 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2620 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2622 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2623 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2624 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | |
| 2626 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2627 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2628 | pcmd += sizeof(uint32_t); |
| 2629 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2630 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2631 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2632 | "Issue LOGO: did:x%x", |
| 2633 | ndlp->nlp_DID, 0, 0); |
| 2634 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2635 | /* |
| 2636 | * If we are issuing a LOGO, we may try to recover the remote NPort |
| 2637 | * by issuing a PLOGI later. Even though we issue ELS cmds by the |
| 2638 | * VPI, if we have a valid RPI, and that RPI gets unreg'ed while |
| 2639 | * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI |
| 2640 | * for that ELS cmd. To avoid this situation, lets get rid of the |
| 2641 | * RPI right now, before any ELS cmds are sent. |
| 2642 | */ |
| 2643 | spin_lock_irq(shost->host_lock); |
| 2644 | ndlp->nlp_flag |= NLP_ISSUE_LOGO; |
| 2645 | spin_unlock_irq(shost->host_lock); |
| 2646 | if (lpfc_unreg_rpi(vport, ndlp)) { |
| 2647 | lpfc_els_free_iocb(phba, elsiocb); |
| 2648 | return 0; |
| 2649 | } |
| 2650 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2651 | phba->fc_stat.elsXmitLOGO++; |
| 2652 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2653 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2654 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2655 | ndlp->nlp_flag &= ~NLP_ISSUE_LOGO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2656 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2657 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2658 | |
| 2659 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2660 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2661 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2662 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2663 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2664 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2665 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2666 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2667 | } |
| 2668 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2669 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2670 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2671 | * @phba: pointer to lpfc hba data structure. |
| 2672 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2673 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2674 | * |
| 2675 | * This routine is a generic completion callback function for ELS commands. |
| 2676 | * Specifically, it is the callback function which does not need to perform |
| 2677 | * any command specific operations. It is currently used by the ELS command |
| 2678 | * issuing routines for the ELS State Change Request (SCR), |
| 2679 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2680 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2681 | * certain debug loggings, this callback function simply invokes the |
| 2682 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2683 | * discovery process. |
| 2684 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2685 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2686 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2687 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2688 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2689 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2690 | IOCB_t *irsp; |
| 2691 | |
| 2692 | irsp = &rspiocb->iocb; |
| 2693 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2694 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2695 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2696 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2697 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2698 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2699 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2700 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2701 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2702 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2703 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2704 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2705 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2706 | return; |
| 2707 | } |
| 2708 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2709 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2710 | * 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] | 2711 | * @vport: pointer to a host virtual N_Port data structure. |
| 2712 | * @nportid: N_Port identifier to the remote node. |
| 2713 | * @retry: number of retries to the command IOCB. |
| 2714 | * |
| 2715 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2716 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2717 | * first search the @vport node list to find the matching ndlp. If no such |
| 2718 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2719 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2720 | * routine is invoked to send the SCR IOCB. |
| 2721 | * |
| 2722 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2723 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2724 | * will be stored into the context1 field of the IOCB for the completion |
| 2725 | * callback function to the SCR ELS command. |
| 2726 | * |
| 2727 | * Return code |
| 2728 | * 0 - Successfully issued scr command |
| 2729 | * 1 - Failed to issue scr command |
| 2730 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2731 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2732 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2733 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2734 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2735 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2736 | uint8_t *pcmd; |
| 2737 | uint16_t cmdsize; |
| 2738 | struct lpfc_nodelist *ndlp; |
| 2739 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2740 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2742 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2743 | if (!ndlp) { |
| 2744 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2745 | if (!ndlp) |
| 2746 | return 1; |
| 2747 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2748 | lpfc_enqueue_node(vport, ndlp); |
| 2749 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2750 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2751 | if (!ndlp) |
| 2752 | return 1; |
| 2753 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2754 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2755 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2756 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2757 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2758 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2759 | /* This will trigger the release of the node just |
| 2760 | * allocated |
| 2761 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2762 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2763 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2764 | } |
| 2765 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2766 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2767 | |
| 2768 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2769 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2770 | |
| 2771 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2772 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2773 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2774 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2775 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2776 | "Issue SCR: did:x%x", |
| 2777 | ndlp->nlp_DID, 0, 0); |
| 2778 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2779 | phba->fc_stat.elsXmitSCR++; |
| 2780 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2781 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2782 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2783 | /* The additional lpfc_nlp_put will cause the following |
| 2784 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2785 | * the node. |
| 2786 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2787 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2788 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2789 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2790 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2791 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2792 | * trigger the release of node. |
| 2793 | */ |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 2794 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2795 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2796 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2797 | } |
| 2798 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2799 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2800 | * 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] | 2801 | * @vport: pointer to a host virtual N_Port data structure. |
| 2802 | * @nportid: N_Port identifier to the remote node. |
| 2803 | * @retry: number of retries to the command IOCB. |
| 2804 | * |
| 2805 | * This routine issues a Fibre Channel Address Resolution Response |
| 2806 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2807 | * is passed into the function. It first search the @vport node list to find |
| 2808 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2809 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2810 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2811 | * |
| 2812 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2813 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2814 | * will be stored into the context1 field of the IOCB for the completion |
| 2815 | * callback function to the PARPR ELS command. |
| 2816 | * |
| 2817 | * Return code |
| 2818 | * 0 - Successfully issued farpr command |
| 2819 | * 1 - Failed to issue farpr command |
| 2820 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2821 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2822 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2823 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2824 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2825 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2826 | FARP *fp; |
| 2827 | uint8_t *pcmd; |
| 2828 | uint32_t *lp; |
| 2829 | uint16_t cmdsize; |
| 2830 | struct lpfc_nodelist *ondlp; |
| 2831 | struct lpfc_nodelist *ndlp; |
| 2832 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2833 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2834 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2835 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2836 | if (!ndlp) { |
| 2837 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2838 | if (!ndlp) |
| 2839 | return 1; |
| 2840 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2841 | lpfc_enqueue_node(vport, ndlp); |
| 2842 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2843 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2844 | if (!ndlp) |
| 2845 | return 1; |
| 2846 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2847 | |
| 2848 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2849 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2850 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2851 | /* This will trigger the release of the node just |
| 2852 | * allocated |
| 2853 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2854 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2855 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2856 | } |
| 2857 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2858 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2859 | |
| 2860 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2861 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2862 | |
| 2863 | /* Fill in FARPR payload */ |
| 2864 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2865 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2866 | lp = (uint32_t *) pcmd; |
| 2867 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2868 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2869 | fp->Rflags = 0; |
| 2870 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2871 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2872 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2873 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2874 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2875 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2876 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2877 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2878 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2879 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2880 | } |
| 2881 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2882 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2883 | "Issue FARPR: did:x%x", |
| 2884 | ndlp->nlp_DID, 0, 0); |
| 2885 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2886 | phba->fc_stat.elsXmitFARPR++; |
| 2887 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2888 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2889 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2890 | /* The additional lpfc_nlp_put will cause the following |
| 2891 | * lpfc_els_free_iocb routine to trigger the release of |
| 2892 | * the node. |
| 2893 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2894 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2895 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2896 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2897 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2898 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2899 | * trigger the release of the node. |
| 2900 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2901 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2902 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2903 | } |
| 2904 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2905 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2906 | * 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] | 2907 | * @vport: pointer to a host virtual N_Port data structure. |
| 2908 | * @nlp: pointer to a node-list data structure. |
| 2909 | * |
| 2910 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2911 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2912 | * removes the ELS retry event if it presents. In addition, if the |
| 2913 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2914 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2915 | * ADISC. |
| 2916 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2917 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2918 | 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] | 2919 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2920 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2921 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2922 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2923 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2924 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2925 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2926 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2927 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2928 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2929 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2930 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2931 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2932 | /* Decrement nlp reference count held for the delayed retry */ |
| 2933 | evtp = &nlp->els_retry_evt; |
| 2934 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2935 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2936 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2937 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2938 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2939 | spin_unlock_irq(shost->host_lock); |
| 2940 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2941 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2942 | /* Check if there are more ADISCs to be sent */ |
| 2943 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2944 | } else { |
| 2945 | /* Check if there are more PLOGIs to be sent */ |
| 2946 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2947 | if (vport->num_disc_nodes == 0) { |
| 2948 | spin_lock_irq(shost->host_lock); |
| 2949 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2950 | spin_unlock_irq(shost->host_lock); |
| 2951 | lpfc_can_disctmo(vport); |
| 2952 | lpfc_end_rscn(vport); |
| 2953 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2954 | } |
| 2955 | } |
| 2956 | } |
| 2957 | return; |
| 2958 | } |
| 2959 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2960 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2961 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2962 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2963 | * |
| 2964 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2965 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2966 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2967 | * adds the delayed events to the HBA work list and invokes the |
| 2968 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2969 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2970 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2971 | * reference to ndlp will still be available when the worker thread gets |
| 2972 | * to the event associated with the ndlp. |
| 2973 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2974 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2975 | lpfc_els_retry_delay(unsigned long ptr) |
| 2976 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2977 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2978 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2979 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2980 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2981 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2982 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2983 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2984 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2985 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2986 | return; |
| 2987 | } |
| 2988 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2989 | /* We need to hold the node by incrementing the reference |
| 2990 | * count until the queued work is done |
| 2991 | */ |
| 2992 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2993 | if (evtp->evt_arg1) { |
| 2994 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2995 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2996 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2997 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2998 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2999 | return; |
| 3000 | } |
| 3001 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3002 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3003 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3004 | * @ndlp: pointer to a node-list data structure. |
| 3005 | * |
| 3006 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 3007 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 3008 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 3009 | * function according to the delayed ELS command to retry the command. |
| 3010 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3011 | void |
| 3012 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 3013 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3014 | struct lpfc_vport *vport = ndlp->vport; |
| 3015 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3016 | uint32_t cmd, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3017 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3018 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3019 | cmd = ndlp->nlp_last_elscmd; |
| 3020 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3021 | |
| 3022 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3023 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3024 | return; |
| 3025 | } |
| 3026 | |
| 3027 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3028 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 3029 | /* |
| 3030 | * If a discovery event readded nlp_delayfunc after timer |
| 3031 | * firing and before processing the timer, cancel the |
| 3032 | * nlp_delayfunc. |
| 3033 | */ |
| 3034 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3035 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3036 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3037 | |
| 3038 | switch (cmd) { |
| 3039 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3040 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3041 | break; |
| 3042 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3043 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3044 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3045 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3046 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3047 | break; |
| 3048 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3049 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3050 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3051 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3052 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3053 | break; |
| 3054 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3055 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3056 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3057 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3058 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3059 | break; |
| 3060 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3061 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3062 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3063 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3064 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3065 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3066 | case ELS_CMD_FDISC: |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3067 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
| 3068 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3069 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3070 | } |
| 3071 | return; |
| 3072 | } |
| 3073 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3074 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3075 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3076 | * @phba: pointer to lpfc hba data structure. |
| 3077 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3078 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3079 | * |
| 3080 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 3081 | * failed. The following ELS IOCBs use this function for retrying the command |
| 3082 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 3083 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 3084 | * returned error status, it makes the decision whether a retry shall be |
| 3085 | * issued for the command, and whether a retry shall be made immediately or |
| 3086 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 3087 | * is called to retry the command. In the later case, the ELS command shall |
| 3088 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 3089 | * ndlp for the delayed command issusing. |
| 3090 | * |
| 3091 | * Return code |
| 3092 | * 0 - No retry of els command is made |
| 3093 | * 1 - Immediate or delayed retry of els command is made |
| 3094 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3095 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3096 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3097 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3098 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3099 | struct lpfc_vport *vport = cmdiocb->vport; |
| 3100 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3101 | IOCB_t *irsp = &rspiocb->iocb; |
| 3102 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3103 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3104 | uint32_t *elscmd; |
| 3105 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3106 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3107 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3108 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3109 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3110 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3111 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3112 | /* Note: context2 may be 0 for internal driver abort |
| 3113 | * of delays ELS command. |
| 3114 | */ |
| 3115 | |
| 3116 | if (pcmd && pcmd->virt) { |
| 3117 | elscmd = (uint32_t *) (pcmd->virt); |
| 3118 | cmd = *elscmd++; |
| 3119 | } |
| 3120 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3121 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3122 | did = ndlp->nlp_DID; |
| 3123 | else { |
| 3124 | /* We should only hit this case for retrying PLOGI */ |
| 3125 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3126 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3127 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 3128 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3129 | return 1; |
| 3130 | } |
| 3131 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3132 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3133 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 3134 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 3135 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3136 | switch (irsp->ulpStatus) { |
| 3137 | case IOSTAT_FCP_RSP_ERROR: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3138 | break; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3139 | case IOSTAT_REMOTE_STOP: |
| 3140 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3141 | /* This IO was aborted by the target, we don't |
| 3142 | * know the rxid and because we did not send the |
| 3143 | * ABTS we cannot generate and RRQ. |
| 3144 | */ |
| 3145 | lpfc_set_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 3146 | cmdiocb->sli4_lxritag, 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3147 | } |
| 3148 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3149 | case IOSTAT_LOCAL_REJECT: |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3150 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3151 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3152 | if (cmd == ELS_CMD_FLOGI) { |
| 3153 | if (PCI_DEVICE_ID_HORNET == |
| 3154 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3155 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3156 | phba->pport->fc_myDID = 0; |
| 3157 | phba->alpa_map[0] = 0; |
| 3158 | phba->alpa_map[1] = 0; |
| 3159 | } |
| 3160 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3161 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3162 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3163 | retry = 1; |
| 3164 | break; |
| 3165 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3166 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3167 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3168 | "0124 Retry illegal cmd x%x " |
| 3169 | "retry:x%x delay:x%x\n", |
| 3170 | cmd, cmdiocb->retry, delay); |
| 3171 | retry = 1; |
| 3172 | /* All command's retry policy */ |
| 3173 | maxretry = 8; |
| 3174 | if (cmdiocb->retry > 2) |
| 3175 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3176 | break; |
| 3177 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3178 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3179 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3180 | retry = 1; |
| 3181 | if (cmdiocb->retry > 100) |
| 3182 | delay = 100; |
| 3183 | maxretry = 250; |
| 3184 | break; |
| 3185 | |
| 3186 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3187 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3188 | retry = 1; |
| 3189 | break; |
| 3190 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3191 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3192 | case IOERR_INVALID_RPI: |
James Smart | 5b5b36a | 2013-01-03 15:43:19 -0500 | [diff] [blame] | 3193 | if (cmd == ELS_CMD_PLOGI && |
| 3194 | did == NameServer_DID) { |
| 3195 | /* Continue forever if plogi to */ |
| 3196 | /* the nameserver fails */ |
| 3197 | maxretry = 0; |
| 3198 | delay = 100; |
| 3199 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3200 | retry = 1; |
| 3201 | break; |
| 3202 | } |
| 3203 | break; |
| 3204 | |
| 3205 | case IOSTAT_NPORT_RJT: |
| 3206 | case IOSTAT_FABRIC_RJT: |
| 3207 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 3208 | retry = 1; |
| 3209 | break; |
| 3210 | } |
| 3211 | break; |
| 3212 | |
| 3213 | case IOSTAT_NPORT_BSY: |
| 3214 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3215 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3216 | retry = 1; |
| 3217 | break; |
| 3218 | |
| 3219 | case IOSTAT_LS_RJT: |
| 3220 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 3221 | /* Added for Vendor specifc support |
| 3222 | * Just keep retrying for these Rsn / Exp codes |
| 3223 | */ |
| 3224 | switch (stat.un.b.lsRjtRsnCode) { |
| 3225 | case LSRJT_UNABLE_TPC: |
| 3226 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3227 | LSEXP_CMD_IN_PROGRESS) { |
| 3228 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3229 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3230 | maxretry = 48; |
| 3231 | } |
| 3232 | retry = 1; |
| 3233 | break; |
| 3234 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3235 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3236 | LSEXP_CANT_GIVE_DATA) { |
| 3237 | if (cmd == ELS_CMD_PLOGI) { |
| 3238 | delay = 1000; |
| 3239 | maxretry = 48; |
| 3240 | } |
| 3241 | retry = 1; |
| 3242 | break; |
| 3243 | } |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 3244 | if ((cmd == ELS_CMD_PLOGI) || |
| 3245 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3246 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3247 | maxretry = lpfc_max_els_tries + 1; |
| 3248 | retry = 1; |
| 3249 | break; |
| 3250 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3251 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3252 | (cmd == ELS_CMD_FDISC) && |
| 3253 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3254 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3255 | "0125 FDISC Failed (x%x). " |
| 3256 | "Fabric out of resources\n", |
| 3257 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3258 | lpfc_vport_set_state(vport, |
| 3259 | FC_VPORT_NO_FABRIC_RSCS); |
| 3260 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | break; |
| 3262 | |
| 3263 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3264 | if ((cmd == ELS_CMD_PLOGI) || |
| 3265 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3266 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3267 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3268 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3269 | /* FDISC retry policy */ |
| 3270 | maxretry = 48; |
| 3271 | if (cmdiocb->retry >= 32) |
| 3272 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3273 | } |
| 3274 | retry = 1; |
| 3275 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3276 | |
| 3277 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3278 | /* There are some cases where switches return this |
| 3279 | * error when they are not ready and should be returning |
| 3280 | * Logical Busy. We should delay every time. |
| 3281 | */ |
| 3282 | if (cmd == ELS_CMD_FDISC && |
| 3283 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 3284 | maxretry = 3; |
| 3285 | delay = 1000; |
| 3286 | retry = 1; |
| 3287 | break; |
| 3288 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3289 | case LSRJT_PROTOCOL_ERR: |
| 3290 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3291 | (cmd == ELS_CMD_FDISC) && |
| 3292 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 3293 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 3294 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3295 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3296 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3297 | "Fabric Detected Bad WWN\n", |
| 3298 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3299 | lpfc_vport_set_state(vport, |
| 3300 | FC_VPORT_FABRIC_REJ_WWN); |
| 3301 | } |
| 3302 | break; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 3303 | case LSRJT_VENDOR_UNIQUE: |
| 3304 | if ((stat.un.b.vendorUnique == 0x45) && |
| 3305 | (cmd == ELS_CMD_FLOGI)) { |
| 3306 | goto out_retry; |
| 3307 | } |
| 3308 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3309 | } |
| 3310 | break; |
| 3311 | |
| 3312 | case IOSTAT_INTERMED_RSP: |
| 3313 | case IOSTAT_BA_RJT: |
| 3314 | break; |
| 3315 | |
| 3316 | default: |
| 3317 | break; |
| 3318 | } |
| 3319 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3320 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3321 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3322 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3323 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3324 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 3325 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3326 | /* FLOGI retry policy */ |
| 3327 | retry = 1; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3328 | /* retry FLOGI forever */ |
James Smart | 6eae430 | 2015-04-07 15:07:23 -0400 | [diff] [blame] | 3329 | if (phba->link_flag != LS_LOOPBACK_MODE) |
| 3330 | maxretry = 0; |
| 3331 | else |
| 3332 | maxretry = 2; |
| 3333 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3334 | if (cmdiocb->retry >= 100) |
| 3335 | delay = 5000; |
| 3336 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3337 | delay = 1000; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3338 | } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) { |
| 3339 | /* retry FDISCs every second up to devloss */ |
| 3340 | retry = 1; |
| 3341 | maxretry = vport->cfg_devloss_tmo; |
| 3342 | delay = 1000; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3343 | } |
| 3344 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3345 | cmdiocb->retry++; |
| 3346 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3347 | phba->fc_stat.elsRetryExceeded++; |
| 3348 | retry = 0; |
| 3349 | } |
| 3350 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3351 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 3352 | retry = 0; |
| 3353 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 3354 | out_retry: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3355 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3356 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 3357 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 3358 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 3359 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3360 | "2849 Stop retry ELS command " |
| 3361 | "x%x to remote NPORT x%x, " |
| 3362 | "Data: x%x x%x\n", cmd, did, |
| 3363 | cmdiocb->retry, delay); |
| 3364 | return 0; |
| 3365 | } |
| 3366 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3367 | |
| 3368 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3369 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3370 | "0107 Retry ELS command x%x to remote " |
| 3371 | "NPORT x%x Data: x%x x%x\n", |
| 3372 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3373 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3374 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 3375 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3376 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 3377 | IOERR_NO_RESOURCES))) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3378 | /* Don't reset timer for no resources */ |
| 3379 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3380 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3381 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3382 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3383 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3387 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3388 | phba->fc_stat.elsDelayRetry++; |
| 3389 | ndlp->nlp_retry = cmdiocb->retry; |
| 3390 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3391 | /* delay is specified in milliseconds */ |
| 3392 | mod_timer(&ndlp->nlp_delayfunc, |
| 3393 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3394 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3395 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3396 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3398 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3399 | if (cmd == ELS_CMD_PRLI) |
| 3400 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 3401 | NLP_STE_PRLI_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3402 | else |
| 3403 | lpfc_nlp_set_state(vport, ndlp, |
| 3404 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | ndlp->nlp_last_elscmd = cmd; |
| 3406 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3407 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | } |
| 3409 | switch (cmd) { |
| 3410 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3411 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3412 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3413 | case ELS_CMD_FDISC: |
| 3414 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 3415 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3416 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3417 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3418 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3419 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3420 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3421 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3422 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3423 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3425 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3426 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3427 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3428 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3429 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3430 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3431 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 3432 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3433 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3434 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3435 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3436 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3437 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3438 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3439 | } |
| 3440 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3441 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3442 | if (logerr) { |
| 3443 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3444 | "0137 No retry ELS command x%x to remote " |
| 3445 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 3446 | cmd, did, irsp->ulpStatus, |
| 3447 | irsp->un.ulpWord[4]); |
| 3448 | } |
| 3449 | else { |
| 3450 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3451 | "0108 No retry ELS command x%x to remote " |
| 3452 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 3453 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 3454 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3455 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3456 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3457 | } |
| 3458 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3459 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3460 | * 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] | 3461 | * @phba: pointer to lpfc hba data structure. |
| 3462 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3463 | * |
| 3464 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3465 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3466 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3467 | * response of the command IOCB. If so, it will be released before releasing |
| 3468 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3469 | * |
| 3470 | * Return code |
| 3471 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3472 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3473 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3474 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3475 | { |
| 3476 | struct lpfc_dmabuf *buf_ptr; |
| 3477 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3478 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3479 | if (!list_empty(&buf_ptr1->list)) { |
| 3480 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3481 | struct lpfc_dmabuf, |
| 3482 | list); |
| 3483 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3484 | kfree(buf_ptr); |
| 3485 | } |
| 3486 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3487 | kfree(buf_ptr1); |
| 3488 | return 0; |
| 3489 | } |
| 3490 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3491 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3492 | * 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] | 3493 | * @phba: pointer to lpfc hba data structure. |
| 3494 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3495 | * |
| 3496 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3497 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3498 | * pool. |
| 3499 | * |
| 3500 | * Return code |
| 3501 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3502 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3503 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3504 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3505 | { |
| 3506 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3507 | kfree(buf_ptr); |
| 3508 | return 0; |
| 3509 | } |
| 3510 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3511 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3512 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3513 | * @phba: pointer to lpfc hba data structure. |
| 3514 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3515 | * |
| 3516 | * This routine frees a command IOCB and its associated resources. The |
| 3517 | * command IOCB data structure contains the reference to various associated |
| 3518 | * resources, these fields must be set to NULL if the associated reference |
| 3519 | * not present: |
| 3520 | * context1 - reference to ndlp |
| 3521 | * context2 - reference to cmd |
| 3522 | * context2->next - reference to rsp |
| 3523 | * context3 - reference to bpl |
| 3524 | * |
| 3525 | * It first properly decrements the reference count held on ndlp for the |
| 3526 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3527 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3528 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3529 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3530 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3531 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3532 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3533 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3534 | * |
| 3535 | * Return code |
| 3536 | * 0 - Success (currently, always return 0) |
| 3537 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3538 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3539 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | { |
| 3541 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3542 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3543 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3544 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3545 | if (ndlp) { |
| 3546 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3547 | lpfc_nlp_put(ndlp); |
| 3548 | |
| 3549 | /* If the ndlp is not being used by another discovery |
| 3550 | * thread, free it. |
| 3551 | */ |
| 3552 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3553 | /* If ndlp is being used by another discovery |
| 3554 | * thread, just clear NLP_DEFER_RM |
| 3555 | */ |
| 3556 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3557 | } |
| 3558 | } |
| 3559 | else |
| 3560 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3561 | elsiocb->context1 = NULL; |
| 3562 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3563 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3564 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3565 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3566 | /* Firmware could still be in progress of DMAing |
| 3567 | * payload, so don't free data buffer till after |
| 3568 | * a hbeat. |
| 3569 | */ |
| 3570 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3571 | buf_ptr = elsiocb->context2; |
| 3572 | elsiocb->context2 = NULL; |
| 3573 | if (buf_ptr) { |
| 3574 | buf_ptr1 = NULL; |
| 3575 | spin_lock_irq(&phba->hbalock); |
| 3576 | if (!list_empty(&buf_ptr->list)) { |
| 3577 | list_remove_head(&buf_ptr->list, |
| 3578 | buf_ptr1, struct lpfc_dmabuf, |
| 3579 | list); |
| 3580 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3581 | list_add_tail(&buf_ptr1->list, |
| 3582 | &phba->elsbuf); |
| 3583 | phba->elsbuf_cnt++; |
| 3584 | } |
| 3585 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3586 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3587 | phba->elsbuf_cnt++; |
| 3588 | spin_unlock_irq(&phba->hbalock); |
| 3589 | } |
| 3590 | } else { |
| 3591 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3592 | lpfc_els_free_data(phba, buf_ptr1); |
| 3593 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | if (elsiocb->context3) { |
| 3597 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3598 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3599 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3600 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3601 | return 0; |
| 3602 | } |
| 3603 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3604 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3605 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3606 | * @phba: pointer to lpfc hba data structure. |
| 3607 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3608 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3609 | * |
| 3610 | * This routine is the completion callback function to the Logout (LOGO) |
| 3611 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3612 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3613 | * release the ndlp if it has the last reference remaining (reference count |
| 3614 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3615 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3616 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3617 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3618 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3619 | * IOCB data structure. |
| 3620 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3621 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3622 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3623 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3624 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3625 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3626 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3627 | IOCB_t *irsp; |
| 3628 | |
| 3629 | irsp = &rspiocb->iocb; |
| 3630 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3631 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3632 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3634 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3635 | "0109 ACC to LOGO completes to NPort x%x " |
| 3636 | "Data: x%x x%x x%x\n", |
| 3637 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3638 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3639 | |
| 3640 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3641 | /* NPort Recovery mode or node is just allocated */ |
| 3642 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3643 | /* If the ndlp is being used by another discovery |
| 3644 | * thread, just unregister the RPI. |
| 3645 | */ |
| 3646 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3647 | } else { |
| 3648 | /* Indicate the node has already released, should |
| 3649 | * not reference to it from within lpfc_els_free_iocb. |
| 3650 | */ |
| 3651 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3652 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3653 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3654 | |
| 3655 | /* |
| 3656 | * 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] | 3657 | * At this point, the driver is done so release the IOCB |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3658 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3659 | lpfc_els_free_iocb(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3660 | } |
| 3661 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3662 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3663 | * 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] | 3664 | * @phba: pointer to lpfc hba data structure. |
| 3665 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3666 | * |
| 3667 | * This routine is the completion callback function for unregister default |
| 3668 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3669 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3670 | * decrements the ndlp reference count held for this completion callback |
| 3671 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3672 | * whether there is only one reference left on the ndlp. If so, it will |
| 3673 | * perform one more decrement and trigger the release of the ndlp. |
| 3674 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3675 | void |
| 3676 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3677 | { |
| 3678 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3679 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3680 | |
| 3681 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3682 | pmb->context2 = NULL; |
| 3683 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3684 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3685 | kfree(mp); |
| 3686 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3687 | if (ndlp) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3688 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3689 | "0006 rpi%x DID:%x flg:%x %d map:%x %p\n", |
| 3690 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 3691 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3692 | ndlp->nlp_usg_map, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3693 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 3694 | lpfc_nlp_put(ndlp); |
| 3695 | /* This is the end of the default RPI cleanup logic for |
| 3696 | * this ndlp. If no other discovery threads are using |
| 3697 | * this ndlp, free all resources associated with it. |
| 3698 | */ |
| 3699 | lpfc_nlp_not_used(ndlp); |
| 3700 | } else { |
| 3701 | lpfc_drop_node(ndlp->vport, ndlp); |
| 3702 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3703 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3704 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3705 | return; |
| 3706 | } |
| 3707 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3708 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3709 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3710 | * @phba: pointer to lpfc hba data structure. |
| 3711 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3712 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3713 | * |
| 3714 | * This routine is the completion callback function for ELS Response IOCB |
| 3715 | * command. In normal case, this callback function just properly sets the |
| 3716 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3717 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3718 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3719 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3720 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3721 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3722 | * are currently referring it. |
| 3723 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3724 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3725 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3726 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3727 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3728 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3729 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3730 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3731 | IOCB_t *irsp; |
| 3732 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3733 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3734 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3735 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3736 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3737 | irsp = &rspiocb->iocb; |
| 3738 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3739 | if (cmdiocb->context_un.mbox) |
| 3740 | mbox = cmdiocb->context_un.mbox; |
| 3741 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3742 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3743 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3744 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3745 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3746 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3747 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3748 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3749 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3750 | */ |
| 3751 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3752 | ls_rjt = 1; |
| 3753 | } |
| 3754 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3755 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3756 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3757 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3758 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3759 | if (mp) { |
| 3760 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3761 | kfree(mp); |
| 3762 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3763 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3764 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3765 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3766 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3767 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3768 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3769 | /* Indicate the node has already released, |
| 3770 | * should not reference to it from within |
| 3771 | * the routine lpfc_els_free_iocb. |
| 3772 | */ |
| 3773 | cmdiocb->context1 = NULL; |
| 3774 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3775 | goto out; |
| 3776 | } |
| 3777 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3778 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3779 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3780 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3781 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3782 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3783 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3784 | "0110 ELS response tag x%x completes " |
| 3785 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3786 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3787 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3788 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3789 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3790 | if (mbox) { |
| 3791 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3792 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3793 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3794 | /* Increment reference count to ndlp to hold the |
| 3795 | * reference to ndlp for the callback function. |
| 3796 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3797 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3798 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3799 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3800 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3801 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3802 | } |
| 3803 | else { |
| 3804 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3805 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3806 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3807 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3808 | } |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3809 | |
| 3810 | ndlp->nlp_flag |= NLP_REG_LOGIN_SEND; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3811 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3812 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3813 | goto out; |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3814 | |
| 3815 | /* Decrement the ndlp reference count we |
| 3816 | * set for this failed mailbox command. |
| 3817 | */ |
| 3818 | lpfc_nlp_put(ndlp); |
| 3819 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3820 | |
| 3821 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3822 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3823 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3824 | "Data: x%x x%x x%x\n", |
| 3825 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3826 | ndlp->nlp_rpi); |
| 3827 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3828 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3829 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3830 | /* Indicate node has already been released, |
| 3831 | * should not reference to it from within |
| 3832 | * the routine lpfc_els_free_iocb. |
| 3833 | */ |
| 3834 | cmdiocb->context1 = NULL; |
| 3835 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3836 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3837 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3838 | if (!lpfc_error_lost_link(irsp) && |
| 3839 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3840 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3841 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3842 | /* Indicate node has already been |
| 3843 | * released, should not reference |
| 3844 | * to it from within the routine |
| 3845 | * lpfc_els_free_iocb. |
| 3846 | */ |
| 3847 | cmdiocb->context1 = NULL; |
| 3848 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | } |
| 3850 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3851 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3852 | if (mp) { |
| 3853 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3854 | kfree(mp); |
| 3855 | } |
| 3856 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3857 | } |
| 3858 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3859 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3860 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3861 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3862 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3863 | |
| 3864 | /* If the node is not being used by another discovery thread, |
| 3865 | * and we are sending a reject, we are done with it. |
| 3866 | * Release driver reference count here and free associated |
| 3867 | * resources. |
| 3868 | */ |
| 3869 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3870 | if (lpfc_nlp_not_used(ndlp)) |
| 3871 | /* Indicate node has already been released, |
| 3872 | * should not reference to it from within |
| 3873 | * the routine lpfc_els_free_iocb. |
| 3874 | */ |
| 3875 | cmdiocb->context1 = NULL; |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3876 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3877 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3878 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3879 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3880 | return; |
| 3881 | } |
| 3882 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3883 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3884 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3885 | * @vport: pointer to a host virtual N_Port data structure. |
| 3886 | * @flag: the els command code to be accepted. |
| 3887 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3888 | * @ndlp: pointer to a node-list data structure. |
| 3889 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3890 | * |
| 3891 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3892 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3893 | * specific ACC response command to be issued and invokes the |
| 3894 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3895 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3896 | * field of the IOCB for the completion callback function to issue the |
| 3897 | * mailbox command to the HBA later when callback is invoked. |
| 3898 | * |
| 3899 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3900 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3901 | * will be stored into the context1 field of the IOCB for the completion |
| 3902 | * callback function to the corresponding response ELS IOCB command. |
| 3903 | * |
| 3904 | * Return code |
| 3905 | * 0 - Successfully issued acc response |
| 3906 | * 1 - Failed to issue acc response |
| 3907 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3908 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3909 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3910 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3911 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3912 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3913 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3914 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3915 | IOCB_t *icmd; |
| 3916 | IOCB_t *oldcmd; |
| 3917 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3918 | uint8_t *pcmd; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3919 | struct serv_parm *sp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3920 | uint16_t cmdsize; |
| 3921 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3922 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3923 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3924 | oldcmd = &oldiocb->iocb; |
| 3925 | |
| 3926 | switch (flag) { |
| 3927 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3928 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3929 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3930 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3931 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3932 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3933 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3934 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3935 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3936 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3937 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3938 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3939 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3940 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3941 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3942 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3943 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3944 | |
| 3945 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3946 | "Issue ACC: did:x%x flg:x%x", |
| 3947 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3948 | break; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3949 | case ELS_CMD_FLOGI: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3950 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3951 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3952 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3953 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3954 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3955 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3956 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3957 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3958 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3959 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3960 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3961 | |
| 3962 | if (mbox) |
| 3963 | elsiocb->context_un.mbox = mbox; |
| 3964 | |
| 3965 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3966 | pcmd += sizeof(uint32_t); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3967 | sp = (struct serv_parm *)pcmd; |
| 3968 | |
| 3969 | if (flag == ELS_CMD_FLOGI) { |
| 3970 | /* Copy the received service parameters back */ |
| 3971 | memcpy(sp, &phba->fc_fabparam, |
| 3972 | sizeof(struct serv_parm)); |
| 3973 | |
| 3974 | /* Clear the F_Port bit */ |
| 3975 | sp->cmn.fPort = 0; |
| 3976 | |
| 3977 | /* Mark all class service parameters as invalid */ |
| 3978 | sp->cls1.classValid = 0; |
| 3979 | sp->cls2.classValid = 0; |
| 3980 | sp->cls3.classValid = 0; |
| 3981 | sp->cls4.classValid = 0; |
| 3982 | |
| 3983 | /* Copy our worldwide names */ |
| 3984 | memcpy(&sp->portName, &vport->fc_sparam.portName, |
| 3985 | sizeof(struct lpfc_name)); |
| 3986 | memcpy(&sp->nodeName, &vport->fc_sparam.nodeName, |
| 3987 | sizeof(struct lpfc_name)); |
| 3988 | } else { |
| 3989 | memcpy(pcmd, &vport->fc_sparam, |
| 3990 | sizeof(struct serv_parm)); |
| 3991 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3992 | |
| 3993 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3994 | "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3995 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3996 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3997 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3998 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3999 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4000 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 4001 | if (!elsiocb) |
| 4002 | return 1; |
| 4003 | |
| 4004 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4005 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4006 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4007 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4008 | |
| 4009 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4010 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4011 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 4012 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 4013 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4014 | |
| 4015 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4016 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 4017 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4018 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4019 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4020 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4021 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4022 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4023 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4024 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 4025 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x " |
| 4026 | "fc_flag x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4027 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4028 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 4029 | ndlp->nlp_rpi, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4030 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4031 | spin_lock_irq(shost->host_lock); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4032 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4033 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND)) |
| 4034 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4035 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4036 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 4037 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4038 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4039 | } |
| 4040 | |
| 4041 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4042 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4043 | if (rc == IOCB_ERROR) { |
| 4044 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4045 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4046 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4047 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4048 | } |
| 4049 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4050 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4051 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4052 | * @vport: pointer to a virtual N_Port data structure. |
| 4053 | * @rejectError: |
| 4054 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4055 | * @ndlp: pointer to a node-list data structure. |
| 4056 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4057 | * |
| 4058 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 4059 | * command. If a @mbox pointer is passed in, it will be put into the |
| 4060 | * context_un.mbox field of the IOCB for the completion callback function |
| 4061 | * to issue to the HBA later. |
| 4062 | * |
| 4063 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4064 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4065 | * will be stored into the context1 field of the IOCB for the completion |
| 4066 | * callback function to the reject response ELS IOCB command. |
| 4067 | * |
| 4068 | * Return code |
| 4069 | * 0 - Successfully issued reject response |
| 4070 | * 1 - Failed to issue reject response |
| 4071 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4072 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4073 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4074 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 4075 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4077 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4078 | IOCB_t *icmd; |
| 4079 | IOCB_t *oldcmd; |
| 4080 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4081 | uint8_t *pcmd; |
| 4082 | uint16_t cmdsize; |
| 4083 | int rc; |
| 4084 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4085 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4086 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4087 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4088 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4089 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4090 | |
| 4091 | icmd = &elsiocb->iocb; |
| 4092 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4093 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4094 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4095 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4096 | |
| 4097 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4098 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4099 | *((uint32_t *) (pcmd)) = rejectError; |
| 4100 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4101 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4102 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4103 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4105 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4106 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 4107 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4108 | "rpi x%x\n", |
| 4109 | rejectError, elsiocb->iotag, |
| 4110 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 4111 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4112 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4113 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 4114 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 4115 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4116 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4117 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4118 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4119 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4120 | if (rc == IOCB_ERROR) { |
| 4121 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4122 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4123 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4124 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4125 | } |
| 4126 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4127 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4128 | * 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] | 4129 | * @vport: pointer to a virtual N_Port data structure. |
| 4130 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4131 | * @ndlp: pointer to a node-list data structure. |
| 4132 | * |
| 4133 | * This routine prepares and issues an Accept (ACC) response to Address |
| 4134 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 4135 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4136 | * |
| 4137 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4138 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4139 | * will be stored into the context1 field of the IOCB for the completion |
| 4140 | * callback function to the ADISC Accept response ELS IOCB command. |
| 4141 | * |
| 4142 | * Return code |
| 4143 | * 0 - Successfully issued acc adisc response |
| 4144 | * 1 - Failed to issue adisc acc response |
| 4145 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4146 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4147 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 4148 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4149 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4150 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4151 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4152 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4153 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4154 | uint8_t *pcmd; |
| 4155 | uint16_t cmdsize; |
| 4156 | int rc; |
| 4157 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4158 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4159 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4160 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4161 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4162 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4163 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4164 | icmd = &elsiocb->iocb; |
| 4165 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4166 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4167 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4168 | |
| 4169 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4170 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4171 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 4172 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 4173 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4174 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4175 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4176 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4177 | |
| 4178 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4179 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4180 | |
| 4181 | ap = (ADISC *) (pcmd); |
| 4182 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4183 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4184 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4185 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4186 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4187 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4188 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 4189 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4190 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4191 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4192 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4193 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4194 | if (rc == IOCB_ERROR) { |
| 4195 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4196 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4197 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4198 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4199 | } |
| 4200 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4201 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4202 | * 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] | 4203 | * @vport: pointer to a virtual N_Port data structure. |
| 4204 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4205 | * @ndlp: pointer to a node-list data structure. |
| 4206 | * |
| 4207 | * This routine prepares and issues an Accept (ACC) response to Process |
| 4208 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 4209 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4210 | * |
| 4211 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4212 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4213 | * will be stored into the context1 field of the IOCB for the completion |
| 4214 | * callback function to the PRLI Accept response ELS IOCB command. |
| 4215 | * |
| 4216 | * Return code |
| 4217 | * 0 - Successfully issued acc prli response |
| 4218 | * 1 - Failed to issue acc prli response |
| 4219 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4220 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4221 | 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] | 4222 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4223 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4224 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4225 | PRLI *npr; |
| 4226 | lpfc_vpd_t *vpd; |
| 4227 | IOCB_t *icmd; |
| 4228 | IOCB_t *oldcmd; |
| 4229 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4230 | uint8_t *pcmd; |
| 4231 | uint16_t cmdsize; |
| 4232 | int rc; |
| 4233 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4234 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4235 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4236 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4237 | if (!elsiocb) |
| 4238 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4239 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4240 | icmd = &elsiocb->iocb; |
| 4241 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4242 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4243 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4244 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4245 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4246 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4247 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 4248 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4249 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4250 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4251 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4252 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4253 | |
| 4254 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4255 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4256 | |
| 4257 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4258 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4259 | |
| 4260 | npr = (PRLI *) pcmd; |
| 4261 | vpd = &phba->vpd; |
| 4262 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4263 | * If the remote port is a target and our firmware version is 3.20 or |
| 4264 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4265 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4266 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 4267 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4268 | npr->ConfmComplAllowed = 1; |
| 4269 | npr->Retry = 1; |
| 4270 | npr->TaskRetryIdReq = 1; |
| 4271 | } |
| 4272 | |
| 4273 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 4274 | npr->estabImagePair = 1; |
| 4275 | npr->readXferRdyDis = 1; |
| 4276 | npr->ConfmComplAllowed = 1; |
| 4277 | |
| 4278 | npr->prliType = PRLI_FCP_TYPE; |
| 4279 | npr->initiatorFunc = 1; |
| 4280 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4281 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4282 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 4283 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4284 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4285 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4286 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4287 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4288 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4289 | if (rc == IOCB_ERROR) { |
| 4290 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4291 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4292 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4293 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4294 | } |
| 4295 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4296 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4297 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4298 | * @vport: pointer to a virtual N_Port data structure. |
| 4299 | * @format: rnid command format. |
| 4300 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4301 | * @ndlp: pointer to a node-list data structure. |
| 4302 | * |
| 4303 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 4304 | * (ACC) response. It constructs the RNID ACC response command according to |
| 4305 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 4306 | * issue the response. Note that this command does not need to hold the ndlp |
| 4307 | * reference count for the callback. So, the ndlp reference count taken by |
| 4308 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 4309 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 4310 | * there is no ndlp reference available. |
| 4311 | * |
| 4312 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4313 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4314 | * will be stored into the context1 field of the IOCB for the completion |
| 4315 | * callback function. However, for the RNID Accept Response ELS command, |
| 4316 | * this is undone later by this routine after the IOCB is allocated. |
| 4317 | * |
| 4318 | * Return code |
| 4319 | * 0 - Successfully issued acc rnid response |
| 4320 | * 1 - Failed to issue acc rnid response |
| 4321 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4322 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4323 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4324 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4325 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4326 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4327 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4328 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4329 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4330 | uint8_t *pcmd; |
| 4331 | uint16_t cmdsize; |
| 4332 | int rc; |
| 4333 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4334 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 4335 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4336 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4337 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4338 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4339 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4340 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4341 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4342 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4343 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | icmd = &elsiocb->iocb; |
| 4345 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4346 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4347 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4348 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4349 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4350 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4351 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 4352 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4353 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4354 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4355 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4356 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4357 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4358 | rn = (RNID *) (pcmd); |
| 4359 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4360 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 4361 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4362 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4363 | switch (format) { |
| 4364 | case 0: |
| 4365 | rn->SpecificLen = 0; |
| 4366 | break; |
| 4367 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4368 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4369 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4370 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4371 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 4372 | rn->un.topologyDisc.physPort = 0; |
| 4373 | rn->un.topologyDisc.attachedNodes = 0; |
| 4374 | break; |
| 4375 | default: |
| 4376 | rn->CommonLen = 0; |
| 4377 | rn->SpecificLen = 0; |
| 4378 | break; |
| 4379 | } |
| 4380 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4381 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4382 | "Issue ACC RNID: did:x%x flg:x%x", |
| 4383 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4384 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4385 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4386 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4387 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4388 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4389 | if (rc == IOCB_ERROR) { |
| 4390 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4391 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4392 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4393 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4394 | } |
| 4395 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4396 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4397 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. |
| 4398 | * @vport: pointer to a virtual N_Port data structure. |
| 4399 | * @iocb: pointer to the lpfc command iocb data structure. |
| 4400 | * @ndlp: pointer to a node-list data structure. |
| 4401 | * |
| 4402 | * Return |
| 4403 | **/ |
| 4404 | static void |
| 4405 | lpfc_els_clear_rrq(struct lpfc_vport *vport, |
| 4406 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
| 4407 | { |
| 4408 | struct lpfc_hba *phba = vport->phba; |
| 4409 | uint8_t *pcmd; |
| 4410 | struct RRQ *rrq; |
| 4411 | uint16_t rxid; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4412 | uint16_t xri; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4413 | struct lpfc_node_rrq *prrq; |
| 4414 | |
| 4415 | |
| 4416 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); |
| 4417 | pcmd += sizeof(uint32_t); |
| 4418 | rrq = (struct RRQ *)pcmd; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4419 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4420 | rxid = bf_get(rrq_rxid, rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4421 | |
| 4422 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4423 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" |
| 4424 | " x%x x%x\n", |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4425 | be32_to_cpu(bf_get(rrq_did, rrq)), |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4426 | bf_get(rrq_oxid, rrq), |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4427 | rxid, |
| 4428 | iocb->iotag, iocb->iocb.ulpContext); |
| 4429 | |
| 4430 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4431 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", |
| 4432 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4433 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4434 | xri = bf_get(rrq_oxid, rrq); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4435 | else |
| 4436 | xri = rxid; |
| 4437 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4438 | if (prrq) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4439 | lpfc_clr_rrq_active(phba, xri, prrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4440 | return; |
| 4441 | } |
| 4442 | |
| 4443 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4444 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 4445 | * @vport: pointer to a virtual N_Port data structure. |
| 4446 | * @data: pointer to echo data to return in the accept. |
| 4447 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4448 | * @ndlp: pointer to a node-list data structure. |
| 4449 | * |
| 4450 | * Return code |
| 4451 | * 0 - Successfully issued acc echo response |
| 4452 | * 1 - Failed to issue acc echo response |
| 4453 | **/ |
| 4454 | static int |
| 4455 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 4456 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 4457 | { |
| 4458 | struct lpfc_hba *phba = vport->phba; |
| 4459 | struct lpfc_iocbq *elsiocb; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4460 | uint8_t *pcmd; |
| 4461 | uint16_t cmdsize; |
| 4462 | int rc; |
| 4463 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4464 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 4465 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4466 | /* The accumulated length can exceed the BPL_SIZE. For |
| 4467 | * now, use this as the limit |
| 4468 | */ |
| 4469 | if (cmdsize > LPFC_BPL_SIZE) |
| 4470 | cmdsize = LPFC_BPL_SIZE; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4471 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4472 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4473 | if (!elsiocb) |
| 4474 | return 1; |
| 4475 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4476 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 4477 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; |
| 4478 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4479 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 4480 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4481 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 4482 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 4483 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4484 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4485 | pcmd += sizeof(uint32_t); |
| 4486 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 4487 | |
| 4488 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4489 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 4490 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4491 | |
| 4492 | phba->fc_stat.elsXmitACC++; |
| 4493 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4494 | |
| 4495 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4496 | if (rc == IOCB_ERROR) { |
| 4497 | lpfc_els_free_iocb(phba, elsiocb); |
| 4498 | return 1; |
| 4499 | } |
| 4500 | return 0; |
| 4501 | } |
| 4502 | |
| 4503 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4504 | * 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] | 4505 | * @vport: pointer to a host virtual N_Port data structure. |
| 4506 | * |
| 4507 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 4508 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 4509 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 4510 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 4511 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 4512 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 4513 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 4514 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 4515 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 4516 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 4517 | * no more ADISC need to be sent. |
| 4518 | * |
| 4519 | * Return code |
| 4520 | * The number of N_Ports with adisc issued. |
| 4521 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4523 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4524 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4525 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4526 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4527 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4528 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4529 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4530 | 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] | 4531 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4532 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4533 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4534 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4535 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4536 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4537 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4538 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4539 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4540 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4541 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4542 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4543 | vport->num_disc_nodes++; |
| 4544 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4545 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4546 | spin_lock_irq(shost->host_lock); |
| 4547 | vport->fc_flag |= FC_NLP_MORE; |
| 4548 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4549 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4550 | } |
| 4551 | } |
| 4552 | } |
| 4553 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4554 | spin_lock_irq(shost->host_lock); |
| 4555 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4556 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4557 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4558 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4559 | } |
| 4560 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4561 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4562 | * 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] | 4563 | * @vport: pointer to a host virtual N_Port data structure. |
| 4564 | * |
| 4565 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4566 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4567 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4568 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4569 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4570 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4571 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4572 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4573 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4574 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4575 | * PLOGI need to be sent. |
| 4576 | * |
| 4577 | * Return code |
| 4578 | * The number of N_Ports with plogi issued. |
| 4579 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4580 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4581 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4582 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4583 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4584 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4585 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4586 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4587 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4588 | 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] | 4589 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4590 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4591 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4592 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4593 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4594 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4595 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4596 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4597 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4598 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4599 | vport->num_disc_nodes++; |
| 4600 | if (vport->num_disc_nodes >= |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4601 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4602 | spin_lock_irq(shost->host_lock); |
| 4603 | vport->fc_flag |= FC_NLP_MORE; |
| 4604 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4605 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4606 | } |
| 4607 | } |
| 4608 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4609 | if (sentplogi) { |
| 4610 | lpfc_set_disctmo(vport); |
| 4611 | } |
| 4612 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4613 | spin_lock_irq(shost->host_lock); |
| 4614 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4615 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4616 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4617 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4618 | } |
| 4619 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4620 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4621 | lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc, |
| 4622 | uint32_t word0) |
| 4623 | { |
| 4624 | |
| 4625 | desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG); |
| 4626 | desc->payload.els_req = word0; |
| 4627 | desc->length = cpu_to_be32(sizeof(desc->payload)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4628 | |
| 4629 | return sizeof(struct fc_rdp_link_service_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4630 | } |
| 4631 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4632 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4633 | lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc, |
| 4634 | uint8_t *page_a0, uint8_t *page_a2) |
| 4635 | { |
| 4636 | uint16_t wavelength; |
| 4637 | uint16_t temperature; |
| 4638 | uint16_t rx_power; |
| 4639 | uint16_t tx_bias; |
| 4640 | uint16_t tx_power; |
| 4641 | uint16_t vcc; |
| 4642 | uint16_t flag = 0; |
| 4643 | struct sff_trasnceiver_codes_byte4 *trasn_code_byte4; |
| 4644 | struct sff_trasnceiver_codes_byte5 *trasn_code_byte5; |
| 4645 | |
| 4646 | desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG); |
| 4647 | |
| 4648 | trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *) |
| 4649 | &page_a0[SSF_TRANSCEIVER_CODE_B4]; |
| 4650 | trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *) |
| 4651 | &page_a0[SSF_TRANSCEIVER_CODE_B5]; |
| 4652 | |
| 4653 | if ((trasn_code_byte4->fc_sw_laser) || |
| 4654 | (trasn_code_byte5->fc_sw_laser_sl) || |
| 4655 | (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */ |
| 4656 | flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT); |
| 4657 | } else if (trasn_code_byte4->fc_lw_laser) { |
| 4658 | wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) | |
| 4659 | page_a0[SSF_WAVELENGTH_B0]; |
| 4660 | if (wavelength == SFP_WAVELENGTH_LC1310) |
| 4661 | flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT; |
| 4662 | if (wavelength == SFP_WAVELENGTH_LL1550) |
| 4663 | flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT; |
| 4664 | } |
| 4665 | /* check if its SFP+ */ |
| 4666 | flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ? |
| 4667 | SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN) |
| 4668 | << SFP_FLAG_CT_SHIFT; |
| 4669 | |
| 4670 | /* check if its OPTICAL */ |
| 4671 | flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ? |
| 4672 | SFP_FLAG_IS_OPTICAL_PORT : 0) |
| 4673 | << SFP_FLAG_IS_OPTICAL_SHIFT; |
| 4674 | |
| 4675 | temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 | |
| 4676 | page_a2[SFF_TEMPERATURE_B0]); |
| 4677 | vcc = (page_a2[SFF_VCC_B1] << 8 | |
| 4678 | page_a2[SFF_VCC_B0]); |
| 4679 | tx_power = (page_a2[SFF_TXPOWER_B1] << 8 | |
| 4680 | page_a2[SFF_TXPOWER_B0]); |
| 4681 | tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 | |
| 4682 | page_a2[SFF_TX_BIAS_CURRENT_B0]); |
| 4683 | rx_power = (page_a2[SFF_RXPOWER_B1] << 8 | |
| 4684 | page_a2[SFF_RXPOWER_B0]); |
| 4685 | desc->sfp_info.temperature = cpu_to_be16(temperature); |
| 4686 | desc->sfp_info.rx_power = cpu_to_be16(rx_power); |
| 4687 | desc->sfp_info.tx_bias = cpu_to_be16(tx_bias); |
| 4688 | desc->sfp_info.tx_power = cpu_to_be16(tx_power); |
| 4689 | desc->sfp_info.vcc = cpu_to_be16(vcc); |
| 4690 | |
| 4691 | desc->sfp_info.flags = cpu_to_be16(flag); |
| 4692 | desc->length = cpu_to_be32(sizeof(desc->sfp_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4693 | |
| 4694 | return sizeof(struct fc_rdp_sfp_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4695 | } |
| 4696 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4697 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4698 | lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc, |
| 4699 | READ_LNK_VAR *stat) |
| 4700 | { |
| 4701 | uint32_t type; |
| 4702 | |
| 4703 | desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG); |
| 4704 | |
| 4705 | type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT; |
| 4706 | |
| 4707 | desc->info.port_type = cpu_to_be32(type); |
| 4708 | |
| 4709 | desc->info.link_status.link_failure_cnt = |
| 4710 | cpu_to_be32(stat->linkFailureCnt); |
| 4711 | desc->info.link_status.loss_of_synch_cnt = |
| 4712 | cpu_to_be32(stat->lossSyncCnt); |
| 4713 | desc->info.link_status.loss_of_signal_cnt = |
| 4714 | cpu_to_be32(stat->lossSignalCnt); |
| 4715 | desc->info.link_status.primitive_seq_proto_err = |
| 4716 | cpu_to_be32(stat->primSeqErrCnt); |
| 4717 | desc->info.link_status.invalid_trans_word = |
| 4718 | cpu_to_be32(stat->invalidXmitWord); |
| 4719 | desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt); |
| 4720 | |
| 4721 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4722 | |
| 4723 | return sizeof(struct fc_rdp_link_error_status_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4724 | } |
| 4725 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4726 | static uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4727 | lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat, |
| 4728 | struct lpfc_vport *vport) |
| 4729 | { |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4730 | uint32_t bbCredit; |
| 4731 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4732 | desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG); |
| 4733 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4734 | bbCredit = vport->fc_sparam.cmn.bbCreditLsb | |
| 4735 | (vport->fc_sparam.cmn.bbCreditMsb << 8); |
| 4736 | desc->bbc_info.port_bbc = cpu_to_be32(bbCredit); |
| 4737 | if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
| 4738 | bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb | |
| 4739 | (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8); |
| 4740 | desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit); |
| 4741 | } else { |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4742 | desc->bbc_info.attached_port_bbc = 0; |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4743 | } |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4744 | |
| 4745 | desc->bbc_info.rtt = 0; |
| 4746 | desc->length = cpu_to_be32(sizeof(desc->bbc_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4747 | |
| 4748 | return sizeof(struct fc_rdp_bbc_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4749 | } |
| 4750 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4751 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4752 | lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba, |
| 4753 | struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2) |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4754 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4755 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4756 | |
| 4757 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 4758 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4759 | desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM]; |
| 4760 | desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM]; |
| 4761 | desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING]; |
| 4762 | desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4763 | |
| 4764 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 4765 | flags |= RDP_OET_HIGH_ALARM; |
| 4766 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 4767 | flags |= RDP_OET_LOW_ALARM; |
| 4768 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 4769 | flags |= RDP_OET_HIGH_WARNING; |
| 4770 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 4771 | flags |= RDP_OET_LOW_WARNING; |
| 4772 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4773 | flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT); |
| 4774 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 4775 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4776 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4777 | } |
| 4778 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4779 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4780 | lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba, |
| 4781 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4782 | uint8_t *page_a2) |
| 4783 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4784 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4785 | |
| 4786 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 4787 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4788 | desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM]; |
| 4789 | desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM]; |
| 4790 | desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING]; |
| 4791 | desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4792 | |
| 4793 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 4794 | flags |= RDP_OET_HIGH_ALARM; |
| 4795 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 4796 | flags |= RDP_OET_LOW_ALARM; |
| 4797 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 4798 | flags |= RDP_OET_HIGH_WARNING; |
| 4799 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 4800 | flags |= RDP_OET_LOW_WARNING; |
| 4801 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4802 | flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT); |
| 4803 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 4804 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4805 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4806 | } |
| 4807 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4808 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4809 | lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba, |
| 4810 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4811 | uint8_t *page_a2) |
| 4812 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4813 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4814 | |
| 4815 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 4816 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4817 | desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM]; |
| 4818 | desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM]; |
| 4819 | desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING]; |
| 4820 | desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4821 | |
| 4822 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 4823 | flags |= RDP_OET_HIGH_ALARM; |
| 4824 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 4825 | flags |= RDP_OET_LOW_ALARM; |
| 4826 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 4827 | flags |= RDP_OET_HIGH_WARNING; |
| 4828 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 4829 | flags |= RDP_OET_LOW_WARNING; |
| 4830 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4831 | flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT); |
| 4832 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 4833 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4834 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4835 | } |
| 4836 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4837 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4838 | lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba, |
| 4839 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4840 | uint8_t *page_a2) |
| 4841 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4842 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4843 | |
| 4844 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 4845 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4846 | desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM]; |
| 4847 | desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM]; |
| 4848 | desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING]; |
| 4849 | desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4850 | |
| 4851 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 4852 | flags |= RDP_OET_HIGH_ALARM; |
| 4853 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 4854 | flags |= RDP_OET_LOW_ALARM; |
| 4855 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 4856 | flags |= RDP_OET_HIGH_WARNING; |
| 4857 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 4858 | flags |= RDP_OET_LOW_WARNING; |
| 4859 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4860 | flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT); |
| 4861 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 4862 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4863 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4867 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4868 | lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba, |
| 4869 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4870 | uint8_t *page_a2) |
| 4871 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4872 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4873 | |
| 4874 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 4875 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4876 | desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM]; |
| 4877 | desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM]; |
| 4878 | desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING]; |
| 4879 | desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4880 | |
| 4881 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 4882 | flags |= RDP_OET_HIGH_ALARM; |
| 4883 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 4884 | flags |= RDP_OET_LOW_ALARM; |
| 4885 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 4886 | flags |= RDP_OET_HIGH_WARNING; |
| 4887 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 4888 | flags |= RDP_OET_LOW_WARNING; |
| 4889 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4890 | flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT); |
| 4891 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 4892 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4893 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4894 | } |
| 4895 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4896 | static uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4897 | lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc, |
| 4898 | uint8_t *page_a0, struct lpfc_vport *vport) |
| 4899 | { |
| 4900 | desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG); |
| 4901 | memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16); |
| 4902 | memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16); |
| 4903 | memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16); |
| 4904 | memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 2); |
| 4905 | memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8); |
| 4906 | desc->length = cpu_to_be32(sizeof(desc->opd_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4907 | return sizeof(struct fc_rdp_opd_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4908 | } |
| 4909 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4910 | static uint32_t |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 4911 | lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat) |
| 4912 | { |
| 4913 | if (bf_get(lpfc_read_link_stat_gec2, stat) == 0) |
| 4914 | return 0; |
| 4915 | desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG); |
| 4916 | |
| 4917 | desc->info.CorrectedBlocks = |
| 4918 | cpu_to_be32(stat->fecCorrBlkCount); |
| 4919 | desc->info.UncorrectableBlocks = |
| 4920 | cpu_to_be32(stat->fecUncorrBlkCount); |
| 4921 | |
| 4922 | desc->length = cpu_to_be32(sizeof(desc->info)); |
| 4923 | |
| 4924 | return sizeof(struct fc_fec_rdp_desc); |
| 4925 | } |
| 4926 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4927 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4928 | lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba) |
| 4929 | { |
| 4930 | uint16_t rdp_cap = 0; |
| 4931 | uint16_t rdp_speed; |
| 4932 | |
| 4933 | desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG); |
| 4934 | |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4935 | switch (phba->fc_linkspeed) { |
| 4936 | case LPFC_LINK_SPEED_1GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4937 | rdp_speed = RDP_PS_1GB; |
| 4938 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4939 | case LPFC_LINK_SPEED_2GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4940 | rdp_speed = RDP_PS_2GB; |
| 4941 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4942 | case LPFC_LINK_SPEED_4GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4943 | rdp_speed = RDP_PS_4GB; |
| 4944 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4945 | case LPFC_LINK_SPEED_8GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4946 | rdp_speed = RDP_PS_8GB; |
| 4947 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4948 | case LPFC_LINK_SPEED_10GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4949 | rdp_speed = RDP_PS_10GB; |
| 4950 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4951 | case LPFC_LINK_SPEED_16GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4952 | rdp_speed = RDP_PS_16GB; |
| 4953 | break; |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4954 | case LPFC_LINK_SPEED_32GHZ: |
| 4955 | rdp_speed = RDP_PS_32GB; |
| 4956 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4957 | default: |
| 4958 | rdp_speed = RDP_PS_UNKNOWN; |
| 4959 | break; |
| 4960 | } |
| 4961 | |
| 4962 | desc->info.port_speed.speed = cpu_to_be16(rdp_speed); |
| 4963 | |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4964 | if (phba->lmt & LMT_32Gb) |
| 4965 | rdp_cap |= RDP_PS_32GB; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4966 | if (phba->lmt & LMT_16Gb) |
| 4967 | rdp_cap |= RDP_PS_16GB; |
| 4968 | if (phba->lmt & LMT_10Gb) |
| 4969 | rdp_cap |= RDP_PS_10GB; |
| 4970 | if (phba->lmt & LMT_8Gb) |
| 4971 | rdp_cap |= RDP_PS_8GB; |
| 4972 | if (phba->lmt & LMT_4Gb) |
| 4973 | rdp_cap |= RDP_PS_4GB; |
| 4974 | if (phba->lmt & LMT_2Gb) |
| 4975 | rdp_cap |= RDP_PS_2GB; |
| 4976 | if (phba->lmt & LMT_1Gb) |
| 4977 | rdp_cap |= RDP_PS_1GB; |
| 4978 | |
| 4979 | if (rdp_cap == 0) |
| 4980 | rdp_cap = RDP_CAP_UNKNOWN; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4981 | if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO) |
| 4982 | rdp_cap |= RDP_CAP_USER_CONFIGURED; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4983 | |
| 4984 | desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap); |
| 4985 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4986 | return sizeof(struct fc_rdp_port_speed_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4987 | } |
| 4988 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 4989 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4990 | lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc, |
| 4991 | struct lpfc_hba *phba) |
| 4992 | { |
| 4993 | |
| 4994 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 4995 | |
| 4996 | memcpy(desc->port_names.wwnn, phba->wwnn, |
| 4997 | sizeof(desc->port_names.wwnn)); |
| 4998 | |
| 4999 | memcpy(desc->port_names.wwpn, &phba->wwpn, |
| 5000 | sizeof(desc->port_names.wwpn)); |
| 5001 | |
| 5002 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5003 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5004 | } |
| 5005 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5006 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5007 | lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc, |
| 5008 | struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 5009 | { |
| 5010 | |
| 5011 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 5012 | if (vport->fc_flag & FC_FABRIC) { |
| 5013 | memcpy(desc->port_names.wwnn, &vport->fabric_nodename, |
| 5014 | sizeof(desc->port_names.wwnn)); |
| 5015 | |
| 5016 | memcpy(desc->port_names.wwpn, &vport->fabric_portname, |
| 5017 | sizeof(desc->port_names.wwpn)); |
| 5018 | } else { /* Point to Point */ |
| 5019 | memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename, |
| 5020 | sizeof(desc->port_names.wwnn)); |
| 5021 | |
| 5022 | memcpy(desc->port_names.wwnn, &ndlp->nlp_portname, |
| 5023 | sizeof(desc->port_names.wwpn)); |
| 5024 | } |
| 5025 | |
| 5026 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5027 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5028 | } |
| 5029 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5030 | static void |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5031 | lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context, |
| 5032 | int status) |
| 5033 | { |
| 5034 | struct lpfc_nodelist *ndlp = rdp_context->ndlp; |
| 5035 | struct lpfc_vport *vport = ndlp->vport; |
| 5036 | struct lpfc_iocbq *elsiocb; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5037 | struct ulp_bde64 *bpl; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5038 | IOCB_t *icmd; |
| 5039 | uint8_t *pcmd; |
| 5040 | struct ls_rjt *stat; |
| 5041 | struct fc_rdp_res_frame *rdp_res; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5042 | uint32_t cmdsize, len; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5043 | uint16_t *flag_ptr; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5044 | int rc; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5045 | |
| 5046 | if (status != SUCCESS) |
| 5047 | goto error; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5048 | |
| 5049 | /* 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] | 5050 | cmdsize = sizeof(struct fc_rdp_res_frame); |
| 5051 | |
| 5052 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, |
| 5053 | lpfc_max_els_tries, rdp_context->ndlp, |
| 5054 | rdp_context->ndlp->nlp_DID, ELS_CMD_ACC); |
| 5055 | lpfc_nlp_put(ndlp); |
| 5056 | if (!elsiocb) |
| 5057 | goto free_rdp_context; |
| 5058 | |
| 5059 | icmd = &elsiocb->iocb; |
| 5060 | icmd->ulpContext = rdp_context->rx_id; |
| 5061 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 5062 | |
| 5063 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5064 | "2171 Xmit RDP response tag x%x xri x%x, " |
| 5065 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x", |
| 5066 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5067 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5068 | ndlp->nlp_rpi); |
| 5069 | rdp_res = (struct fc_rdp_res_frame *) |
| 5070 | (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5071 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5072 | memset(pcmd, 0, sizeof(struct fc_rdp_res_frame)); |
| 5073 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5074 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5075 | /* Update Alarm and Warning */ |
| 5076 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS); |
| 5077 | phba->sfp_alarm |= *flag_ptr; |
| 5078 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS); |
| 5079 | phba->sfp_warning |= *flag_ptr; |
| 5080 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5081 | /* For RDP payload */ |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5082 | len = 8; |
| 5083 | len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *) |
| 5084 | (len + pcmd), ELS_CMD_RDP); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5085 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5086 | 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] | 5087 | rdp_context->page_a0, rdp_context->page_a2); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5088 | len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd), |
| 5089 | phba); |
| 5090 | len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *) |
| 5091 | (len + pcmd), &rdp_context->link_stat); |
| 5092 | len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *) |
| 5093 | (len + pcmd), phba); |
| 5094 | len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *) |
| 5095 | (len + pcmd), vport, ndlp); |
| 5096 | 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] | 5097 | &rdp_context->link_stat); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5098 | /* Check if nport is logged, BZ190632 */ |
| 5099 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) |
| 5100 | goto lpfc_skip_descriptor; |
| 5101 | |
| 5102 | len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd), |
| 5103 | &rdp_context->link_stat, vport); |
| 5104 | len += lpfc_rdp_res_oed_temp_desc(phba, |
| 5105 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5106 | rdp_context->page_a2); |
| 5107 | len += lpfc_rdp_res_oed_voltage_desc(phba, |
| 5108 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5109 | rdp_context->page_a2); |
| 5110 | len += lpfc_rdp_res_oed_txbias_desc(phba, |
| 5111 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5112 | rdp_context->page_a2); |
| 5113 | len += lpfc_rdp_res_oed_txpower_desc(phba, |
| 5114 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5115 | rdp_context->page_a2); |
| 5116 | len += lpfc_rdp_res_oed_rxpower_desc(phba, |
| 5117 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5118 | rdp_context->page_a2); |
| 5119 | len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd), |
| 5120 | rdp_context->page_a0, vport); |
| 5121 | |
| 5122 | lpfc_skip_descriptor: |
| 5123 | rdp_res->length = cpu_to_be32(len - 8); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5124 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5125 | |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5126 | /* Now that we know the true size of the payload, update the BPL */ |
| 5127 | bpl = (struct ulp_bde64 *) |
| 5128 | (((struct lpfc_dmabuf *)(elsiocb->context3))->virt); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5129 | bpl->tus.f.bdeSize = len; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5130 | bpl->tus.f.bdeFlags = 0; |
| 5131 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 5132 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5133 | phba->fc_stat.elsXmitACC++; |
| 5134 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5135 | if (rc == IOCB_ERROR) |
| 5136 | lpfc_els_free_iocb(phba, elsiocb); |
| 5137 | |
| 5138 | kfree(rdp_context); |
| 5139 | |
| 5140 | return; |
| 5141 | error: |
| 5142 | cmdsize = 2 * sizeof(uint32_t); |
| 5143 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries, |
| 5144 | ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 5145 | lpfc_nlp_put(ndlp); |
| 5146 | if (!elsiocb) |
| 5147 | goto free_rdp_context; |
| 5148 | |
| 5149 | icmd = &elsiocb->iocb; |
| 5150 | icmd->ulpContext = rdp_context->rx_id; |
| 5151 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 5152 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5153 | |
| 5154 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
| 5155 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 5156 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5157 | |
| 5158 | phba->fc_stat.elsXmitLSRJT++; |
| 5159 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5160 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5161 | |
| 5162 | if (rc == IOCB_ERROR) |
| 5163 | lpfc_els_free_iocb(phba, elsiocb); |
| 5164 | free_rdp_context: |
| 5165 | kfree(rdp_context); |
| 5166 | } |
| 5167 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5168 | static int |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5169 | lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) |
| 5170 | { |
| 5171 | LPFC_MBOXQ_t *mbox = NULL; |
| 5172 | int rc; |
| 5173 | |
| 5174 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5175 | if (!mbox) { |
| 5176 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, |
| 5177 | "7105 failed to allocate mailbox memory"); |
| 5178 | return 1; |
| 5179 | } |
| 5180 | |
| 5181 | if (lpfc_sli4_dump_page_a0(phba, mbox)) |
| 5182 | goto prep_mbox_fail; |
| 5183 | mbox->vport = rdp_context->ndlp->vport; |
| 5184 | mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; |
| 5185 | mbox->context2 = (struct lpfc_rdp_context *) rdp_context; |
| 5186 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5187 | if (rc == MBX_NOT_FINISHED) |
| 5188 | goto issue_mbox_fail; |
| 5189 | |
| 5190 | return 0; |
| 5191 | |
| 5192 | prep_mbox_fail: |
| 5193 | issue_mbox_fail: |
| 5194 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5195 | return 1; |
| 5196 | } |
| 5197 | |
| 5198 | /* |
| 5199 | * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS. |
| 5200 | * @vport: pointer to a host virtual N_Port data structure. |
| 5201 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5202 | * @ndlp: pointer to a node-list data structure. |
| 5203 | * |
| 5204 | * This routine processes an unsolicited RDP(Read Diagnostic Parameters) |
| 5205 | * IOCB. First, the payload of the unsolicited RDP is checked. |
| 5206 | * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3 |
| 5207 | * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2, |
| 5208 | * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl |
| 5209 | * gather all data and send RDP response. |
| 5210 | * |
| 5211 | * Return code |
| 5212 | * 0 - Sent the acc response |
| 5213 | * 1 - Sent the reject response. |
| 5214 | */ |
| 5215 | static int |
| 5216 | lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5217 | struct lpfc_nodelist *ndlp) |
| 5218 | { |
| 5219 | struct lpfc_hba *phba = vport->phba; |
| 5220 | struct lpfc_dmabuf *pcmd; |
| 5221 | uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE; |
| 5222 | struct fc_rdp_req_frame *rdp_req; |
| 5223 | struct lpfc_rdp_context *rdp_context; |
| 5224 | IOCB_t *cmd = NULL; |
| 5225 | struct ls_rjt stat; |
| 5226 | |
| 5227 | if (phba->sli_rev < LPFC_SLI_REV4 || |
| 5228 | (bf_get(lpfc_sli_intf_if_type, |
| 5229 | &phba->sli4_hba.sli_intf) != |
| 5230 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 5231 | rjt_err = LSRJT_UNABLE_TPC; |
| 5232 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 5233 | goto error; |
| 5234 | } |
| 5235 | |
| 5236 | if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) { |
| 5237 | rjt_err = LSRJT_UNABLE_TPC; |
| 5238 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 5239 | goto error; |
| 5240 | } |
| 5241 | |
| 5242 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5243 | rdp_req = (struct fc_rdp_req_frame *) pcmd->virt; |
| 5244 | |
| 5245 | |
| 5246 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5247 | "2422 ELS RDP Request " |
| 5248 | "dec len %d tag x%x port_id %d len %d\n", |
| 5249 | be32_to_cpu(rdp_req->rdp_des_length), |
| 5250 | be32_to_cpu(rdp_req->nport_id_desc.tag), |
| 5251 | be32_to_cpu(rdp_req->nport_id_desc.nport_id), |
| 5252 | be32_to_cpu(rdp_req->nport_id_desc.length)); |
| 5253 | |
James Smart | 7d93331 | 2016-07-06 12:35:58 -0700 | [diff] [blame] | 5254 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) && |
| 5255 | !phba->cfg_enable_SmartSAN) { |
| 5256 | rjt_err = LSRJT_UNABLE_TPC; |
| 5257 | rjt_expl = LSEXP_PORT_LOGIN_REQ; |
| 5258 | goto error; |
| 5259 | } |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5260 | if (sizeof(struct fc_rdp_nport_desc) != |
| 5261 | be32_to_cpu(rdp_req->rdp_des_length)) |
| 5262 | goto rjt_logerr; |
| 5263 | if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag)) |
| 5264 | goto rjt_logerr; |
| 5265 | if (RDP_NPORT_ID_SIZE != |
| 5266 | be32_to_cpu(rdp_req->nport_id_desc.length)) |
| 5267 | goto rjt_logerr; |
Punit Vara | 699acd6 | 2015-12-16 18:12:07 -0500 | [diff] [blame] | 5268 | rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5269 | if (!rdp_context) { |
| 5270 | rjt_err = LSRJT_UNABLE_TPC; |
| 5271 | goto error; |
| 5272 | } |
| 5273 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5274 | cmd = &cmdiocb->iocb; |
| 5275 | rdp_context->ndlp = lpfc_nlp_get(ndlp); |
| 5276 | rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id; |
| 5277 | rdp_context->rx_id = cmd->ulpContext; |
| 5278 | rdp_context->cmpl = lpfc_els_rdp_cmpl; |
| 5279 | if (lpfc_get_rdp_info(phba, rdp_context)) { |
| 5280 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS, |
| 5281 | "2423 Unable to send mailbox"); |
| 5282 | kfree(rdp_context); |
| 5283 | rjt_err = LSRJT_UNABLE_TPC; |
| 5284 | lpfc_nlp_put(ndlp); |
| 5285 | goto error; |
| 5286 | } |
| 5287 | |
| 5288 | return 0; |
| 5289 | |
| 5290 | rjt_logerr: |
| 5291 | rjt_err = LSRJT_LOGICAL_ERR; |
| 5292 | |
| 5293 | error: |
| 5294 | memset(&stat, 0, sizeof(stat)); |
| 5295 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 5296 | stat.un.b.lsRjtRsnCodeExp = rjt_expl; |
| 5297 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5298 | return 1; |
| 5299 | } |
| 5300 | |
| 5301 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5302 | static void |
| 5303 | lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5304 | { |
| 5305 | MAILBOX_t *mb; |
| 5306 | IOCB_t *icmd; |
| 5307 | uint8_t *pcmd; |
| 5308 | struct lpfc_iocbq *elsiocb; |
| 5309 | struct lpfc_nodelist *ndlp; |
| 5310 | struct ls_rjt *stat; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5311 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5312 | struct lpfc_lcb_context *lcb_context; |
| 5313 | struct fc_lcb_res_frame *lcb_res; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5314 | uint32_t cmdsize, shdr_status, shdr_add_status; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5315 | int rc; |
| 5316 | |
| 5317 | mb = &pmb->u.mb; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5318 | lcb_context = (struct lpfc_lcb_context *)pmb->context1; |
| 5319 | ndlp = lcb_context->ndlp; |
| 5320 | pmb->context1 = NULL; |
| 5321 | pmb->context2 = NULL; |
| 5322 | |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5323 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 5324 | &pmb->u.mqe.un.beacon_config.header.cfg_shdr; |
| 5325 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5326 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5327 | |
| 5328 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX, |
| 5329 | "0194 SET_BEACON_CONFIG mailbox " |
| 5330 | "completed with status x%x add_status x%x," |
| 5331 | " mbx status x%x\n", |
| 5332 | shdr_status, shdr_add_status, mb->mbxStatus); |
| 5333 | |
| 5334 | if (mb->mbxStatus && !(shdr_status && |
| 5335 | shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5336 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5337 | goto error; |
| 5338 | } |
| 5339 | |
| 5340 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5341 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 5342 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5343 | lpfc_max_els_tries, ndlp, |
| 5344 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5345 | |
| 5346 | /* Decrement the ndlp reference count from previous mbox command */ |
| 5347 | lpfc_nlp_put(ndlp); |
| 5348 | |
| 5349 | if (!elsiocb) |
| 5350 | goto free_lcb_context; |
| 5351 | |
| 5352 | lcb_res = (struct fc_lcb_res_frame *) |
| 5353 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5354 | |
| 5355 | icmd = &elsiocb->iocb; |
| 5356 | icmd->ulpContext = lcb_context->rx_id; |
| 5357 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 5358 | |
| 5359 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5360 | *((uint32_t *)(pcmd)) = ELS_CMD_ACC; |
| 5361 | lcb_res->lcb_sub_command = lcb_context->sub_command; |
| 5362 | lcb_res->lcb_type = lcb_context->type; |
| 5363 | lcb_res->lcb_frequency = lcb_context->frequency; |
| 5364 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5365 | phba->fc_stat.elsXmitACC++; |
| 5366 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5367 | if (rc == IOCB_ERROR) |
| 5368 | lpfc_els_free_iocb(phba, elsiocb); |
| 5369 | |
| 5370 | kfree(lcb_context); |
| 5371 | return; |
| 5372 | |
| 5373 | error: |
| 5374 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 5375 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5376 | lpfc_max_els_tries, ndlp, |
| 5377 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 5378 | lpfc_nlp_put(ndlp); |
| 5379 | if (!elsiocb) |
| 5380 | goto free_lcb_context; |
| 5381 | |
| 5382 | icmd = &elsiocb->iocb; |
| 5383 | icmd->ulpContext = lcb_context->rx_id; |
| 5384 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 5385 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5386 | |
| 5387 | *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT; |
| 5388 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 5389 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5390 | |
| 5391 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5392 | phba->fc_stat.elsXmitLSRJT++; |
| 5393 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5394 | if (rc == IOCB_ERROR) |
| 5395 | lpfc_els_free_iocb(phba, elsiocb); |
| 5396 | free_lcb_context: |
| 5397 | kfree(lcb_context); |
| 5398 | } |
| 5399 | |
| 5400 | static int |
| 5401 | lpfc_sli4_set_beacon(struct lpfc_vport *vport, |
| 5402 | struct lpfc_lcb_context *lcb_context, |
| 5403 | uint32_t beacon_state) |
| 5404 | { |
| 5405 | struct lpfc_hba *phba = vport->phba; |
| 5406 | LPFC_MBOXQ_t *mbox = NULL; |
| 5407 | uint32_t len; |
| 5408 | int rc; |
| 5409 | |
| 5410 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5411 | if (!mbox) |
| 5412 | return 1; |
| 5413 | |
| 5414 | len = sizeof(struct lpfc_mbx_set_beacon_config) - |
| 5415 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 5416 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5417 | LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len, |
| 5418 | LPFC_SLI4_MBX_EMBED); |
| 5419 | mbox->context1 = (void *)lcb_context; |
| 5420 | mbox->vport = phba->pport; |
| 5421 | mbox->mbox_cmpl = lpfc_els_lcb_rsp; |
| 5422 | bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config, |
| 5423 | phba->sli4_hba.physical_port); |
| 5424 | bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config, |
| 5425 | beacon_state); |
| 5426 | bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1); |
| 5427 | bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0); |
| 5428 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5429 | if (rc == MBX_NOT_FINISHED) { |
| 5430 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5431 | return 1; |
| 5432 | } |
| 5433 | |
| 5434 | return 0; |
| 5435 | } |
| 5436 | |
| 5437 | |
| 5438 | /** |
| 5439 | * lpfc_els_rcv_lcb - Process an unsolicited LCB |
| 5440 | * @vport: pointer to a host virtual N_Port data structure. |
| 5441 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5442 | * @ndlp: pointer to a node-list data structure. |
| 5443 | * |
| 5444 | * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB. |
| 5445 | * First, the payload of the unsolicited LCB is checked. |
| 5446 | * Then based on Subcommand beacon will either turn on or off. |
| 5447 | * |
| 5448 | * Return code |
| 5449 | * 0 - Sent the acc response |
| 5450 | * 1 - Sent the reject response. |
| 5451 | **/ |
| 5452 | static int |
| 5453 | lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5454 | struct lpfc_nodelist *ndlp) |
| 5455 | { |
| 5456 | struct lpfc_hba *phba = vport->phba; |
| 5457 | struct lpfc_dmabuf *pcmd; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5458 | uint8_t *lp; |
| 5459 | struct fc_lcb_request_frame *beacon; |
| 5460 | struct lpfc_lcb_context *lcb_context; |
| 5461 | uint8_t state, rjt_err; |
| 5462 | struct ls_rjt stat; |
| 5463 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5464 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 5465 | lp = (uint8_t *)pcmd->virt; |
| 5466 | beacon = (struct fc_lcb_request_frame *)pcmd->virt; |
| 5467 | |
| 5468 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5469 | "0192 ELS LCB Data x%x x%x x%x x%x sub x%x " |
| 5470 | "type x%x frequency %x duration x%x\n", |
| 5471 | lp[0], lp[1], lp[2], |
| 5472 | beacon->lcb_command, |
| 5473 | beacon->lcb_sub_command, |
| 5474 | beacon->lcb_type, |
| 5475 | beacon->lcb_frequency, |
| 5476 | be16_to_cpu(beacon->lcb_duration)); |
| 5477 | |
| 5478 | if (phba->sli_rev < LPFC_SLI_REV4 || |
| 5479 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 5480 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 5481 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5482 | goto rjt; |
| 5483 | } |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5484 | |
| 5485 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 5486 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5487 | goto rjt; |
| 5488 | } |
| 5489 | if (beacon->lcb_frequency == 0) { |
| 5490 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5491 | goto rjt; |
| 5492 | } |
| 5493 | if ((beacon->lcb_type != LPFC_LCB_GREEN) && |
| 5494 | (beacon->lcb_type != LPFC_LCB_AMBER)) { |
| 5495 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5496 | goto rjt; |
| 5497 | } |
| 5498 | if ((beacon->lcb_sub_command != LPFC_LCB_ON) && |
| 5499 | (beacon->lcb_sub_command != LPFC_LCB_OFF)) { |
| 5500 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5501 | goto rjt; |
| 5502 | } |
| 5503 | if ((beacon->lcb_sub_command == LPFC_LCB_ON) && |
| 5504 | (beacon->lcb_type != LPFC_LCB_GREEN) && |
| 5505 | (beacon->lcb_type != LPFC_LCB_AMBER)) { |
| 5506 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5507 | goto rjt; |
| 5508 | } |
| 5509 | if (be16_to_cpu(beacon->lcb_duration) != 0) { |
| 5510 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5511 | goto rjt; |
| 5512 | } |
| 5513 | |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 5514 | lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL); |
| 5515 | if (!lcb_context) { |
| 5516 | rjt_err = LSRJT_UNABLE_TPC; |
| 5517 | goto rjt; |
| 5518 | } |
| 5519 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5520 | state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; |
| 5521 | lcb_context->sub_command = beacon->lcb_sub_command; |
| 5522 | lcb_context->type = beacon->lcb_type; |
| 5523 | lcb_context->frequency = beacon->lcb_frequency; |
| 5524 | lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
| 5525 | lcb_context->rx_id = cmdiocb->iocb.ulpContext; |
| 5526 | lcb_context->ndlp = lpfc_nlp_get(ndlp); |
| 5527 | if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { |
| 5528 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 5529 | LOG_ELS, "0193 failed to send mail box"); |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 5530 | kfree(lcb_context); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5531 | lpfc_nlp_put(ndlp); |
| 5532 | rjt_err = LSRJT_UNABLE_TPC; |
| 5533 | goto rjt; |
| 5534 | } |
| 5535 | return 0; |
| 5536 | rjt: |
| 5537 | memset(&stat, 0, sizeof(stat)); |
| 5538 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 5539 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5540 | return 1; |
| 5541 | } |
| 5542 | |
| 5543 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5544 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5545 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5546 | * @vport: pointer to a host virtual N_Port data structure. |
| 5547 | * |
| 5548 | * This routine cleans up any Registration State Change Notification |
| 5549 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 5550 | * @vport together with the host_lock is used to prevent multiple thread |
| 5551 | * trying to access the RSCN array on a same @vport at the same time. |
| 5552 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5553 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5554 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5555 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5556 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5557 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5558 | int i; |
| 5559 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5560 | spin_lock_irq(shost->host_lock); |
| 5561 | if (vport->fc_rscn_flush) { |
| 5562 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 5563 | spin_unlock_irq(shost->host_lock); |
| 5564 | return; |
| 5565 | } |
| 5566 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 5567 | vport->fc_rscn_flush = 1; |
| 5568 | spin_unlock_irq(shost->host_lock); |
| 5569 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5570 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5571 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5572 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5573 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5574 | spin_lock_irq(shost->host_lock); |
| 5575 | vport->fc_rscn_id_cnt = 0; |
| 5576 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 5577 | spin_unlock_irq(shost->host_lock); |
| 5578 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5579 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 5580 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5581 | } |
| 5582 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5583 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5584 | * 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] | 5585 | * @vport: pointer to a host virtual N_Port data structure. |
| 5586 | * @did: remote destination port identifier. |
| 5587 | * |
| 5588 | * This routine checks whether there is any pending Registration State |
| 5589 | * Configuration Notification (RSCN) to a @did on @vport. |
| 5590 | * |
| 5591 | * Return code |
| 5592 | * None zero - The @did matched with a pending rscn |
| 5593 | * 0 - not able to match @did with a pending rscn |
| 5594 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5595 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5596 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5597 | { |
| 5598 | D_ID ns_did; |
| 5599 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5600 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5601 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5602 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5603 | |
| 5604 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5605 | |
| 5606 | /* Never match fabric nodes for RSCNs */ |
| 5607 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5608 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5609 | |
| 5610 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5611 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5612 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5613 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5614 | spin_lock_irq(shost->host_lock); |
| 5615 | if (vport->fc_rscn_flush) { |
| 5616 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 5617 | spin_unlock_irq(shost->host_lock); |
| 5618 | return 0; |
| 5619 | } |
| 5620 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 5621 | vport->fc_rscn_flush = 1; |
| 5622 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5623 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5624 | lp = vport->fc_rscn_id_list[i]->virt; |
| 5625 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 5626 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5627 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5628 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 5629 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5630 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 5631 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5632 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 5633 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 5634 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5635 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5636 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5637 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5638 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 5639 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5640 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5641 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5642 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5643 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5644 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5645 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5646 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5647 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5648 | } |
| 5649 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5650 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5651 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 5652 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5653 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5654 | return_did_out: |
| 5655 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 5656 | vport->fc_rscn_flush = 0; |
| 5657 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5658 | } |
| 5659 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5660 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5661 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5662 | * @vport: pointer to a host virtual N_Port data structure. |
| 5663 | * |
| 5664 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 5665 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 5666 | * State Change Notification). |
| 5667 | * |
| 5668 | * Return code |
| 5669 | * 0 - Successful (currently alway return 0) |
| 5670 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5671 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5672 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5673 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5674 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5675 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5676 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5677 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5678 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5679 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 5680 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5681 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5682 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5683 | NLP_EVT_DEVICE_RECOVERY); |
| 5684 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5685 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5686 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5687 | } |
| 5688 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5689 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5690 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5691 | * @vport: pointer to a host virtual N_Port data structure. |
| 5692 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5693 | * |
| 5694 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 5695 | * applications. |
| 5696 | */ |
| 5697 | static void |
| 5698 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 5699 | struct lpfc_iocbq *cmdiocb) |
| 5700 | { |
| 5701 | struct lpfc_dmabuf *pcmd; |
| 5702 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5703 | uint32_t *payload_ptr; |
| 5704 | uint32_t payload_len; |
| 5705 | struct lpfc_rscn_event_header *rscn_event_data; |
| 5706 | |
| 5707 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5708 | payload_ptr = (uint32_t *) pcmd->virt; |
| 5709 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 5710 | |
| 5711 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 5712 | payload_len, GFP_KERNEL); |
| 5713 | if (!rscn_event_data) { |
| 5714 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5715 | "0147 Failed to allocate memory for RSCN event\n"); |
| 5716 | return; |
| 5717 | } |
| 5718 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 5719 | rscn_event_data->payload_length = payload_len; |
| 5720 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 5721 | payload_len); |
| 5722 | |
| 5723 | fc_host_post_vendor_event(shost, |
| 5724 | fc_get_event_number(), |
Ales Novak | 6599eaa | 2015-08-31 16:48:16 -0400 | [diff] [blame] | 5725 | sizeof(struct lpfc_rscn_event_header) + payload_len, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5726 | (char *)rscn_event_data, |
| 5727 | LPFC_NL_VENDOR_ID); |
| 5728 | |
| 5729 | kfree(rscn_event_data); |
| 5730 | } |
| 5731 | |
| 5732 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5733 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5734 | * @vport: pointer to a host virtual N_Port data structure. |
| 5735 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5736 | * @ndlp: pointer to a node-list data structure. |
| 5737 | * |
| 5738 | * This routine processes an unsolicited RSCN (Registration State Change |
| 5739 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 5740 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 5741 | * discover state machine is about to begin discovery, it just accepts the |
| 5742 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 5743 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 5744 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 5745 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 5746 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 5747 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 5748 | * routine is invoked to handle the RSCN event. |
| 5749 | * |
| 5750 | * Return code |
| 5751 | * 0 - Just sent the acc response |
| 5752 | * 1 - Sent the acc response and waited for name server completion |
| 5753 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5754 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5755 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5756 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5757 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5758 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5759 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5760 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5761 | uint32_t *lp, *datap; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5762 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5763 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5764 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5765 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5766 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5767 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5768 | lp = (uint32_t *) pcmd->virt; |
| 5769 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5770 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 5771 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5772 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5773 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5774 | "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] | 5775 | vport->fc_flag, payload_len, *lp, |
| 5776 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5777 | |
| 5778 | /* Send an RSCN event to the management application */ |
| 5779 | lpfc_send_rscn_event(vport, cmdiocb); |
| 5780 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5781 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5782 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5783 | FCH_EVT_RSCN, lp[i]); |
| 5784 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5785 | /* If we are about to begin discovery, just ACC the RSCN. |
| 5786 | * Discovery processing will satisfy it. |
| 5787 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5788 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5789 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5790 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 5791 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 5792 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5793 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5794 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5795 | } |
| 5796 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5797 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 5798 | * just ACC and ignore it. |
| 5799 | */ |
| 5800 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5801 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5802 | i = payload_len; |
| 5803 | datap = lp; |
| 5804 | while (i > 0) { |
| 5805 | nportid = *datap++; |
| 5806 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 5807 | i -= sizeof(uint32_t); |
| 5808 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5809 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 5810 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5811 | } |
| 5812 | if (rscn_id == hba_id) { |
| 5813 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5814 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5815 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5816 | "Data: x%x x%x x%x x%x\n", |
| 5817 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5818 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5819 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5820 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 5821 | ndlp->nlp_DID, vport->port_state, |
| 5822 | ndlp->nlp_flag); |
| 5823 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5824 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5825 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5826 | return 0; |
| 5827 | } |
| 5828 | } |
| 5829 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5830 | spin_lock_irq(shost->host_lock); |
| 5831 | if (vport->fc_rscn_flush) { |
| 5832 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5833 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 5834 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5835 | /* Send back ACC */ |
| 5836 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5837 | return 0; |
| 5838 | } |
| 5839 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 5840 | vport->fc_rscn_flush = 1; |
| 5841 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5842 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5843 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5844 | /* If we are already processing an RSCN, save the received |
| 5845 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 5846 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5847 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5848 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5849 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 5850 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 5851 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5852 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5853 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 5854 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5855 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5856 | vport->fc_flag |= FC_RSCN_MODE; |
| 5857 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5858 | if (rscn_cnt) { |
| 5859 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 5860 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 5861 | } |
| 5862 | if ((rscn_cnt) && |
| 5863 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 5864 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5865 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5866 | memcpy(((uint8_t *)cmd) + length, lp, |
| 5867 | payload_len); |
| 5868 | } else { |
| 5869 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 5870 | vport->fc_rscn_id_cnt++; |
| 5871 | /* If we zero, cmdiocb->context2, the calling |
| 5872 | * routine will not try to free it. |
| 5873 | */ |
| 5874 | cmdiocb->context2 = NULL; |
| 5875 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5876 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5877 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5878 | "0235 Deferred RSCN " |
| 5879 | "Data: x%x x%x x%x\n", |
| 5880 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 5881 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5882 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5883 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 5884 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5885 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5886 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5887 | "0234 ReDiscovery RSCN " |
| 5888 | "Data: x%x x%x x%x\n", |
| 5889 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 5890 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5891 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5892 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 5893 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5894 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5895 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5896 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5897 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5898 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5899 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5900 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5901 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5902 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5903 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5904 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 5905 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 5906 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5907 | spin_lock_irq(shost->host_lock); |
| 5908 | vport->fc_flag |= FC_RSCN_MODE; |
| 5909 | spin_unlock_irq(shost->host_lock); |
| 5910 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5911 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 5912 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5913 | /* |
| 5914 | * If we zero, cmdiocb->context2, the calling routine will |
| 5915 | * not try to free it. |
| 5916 | */ |
| 5917 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5918 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5919 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5920 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5921 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5922 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5923 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5924 | } |
| 5925 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5926 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5927 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5928 | * @vport: pointer to a host virtual N_Port data structure. |
| 5929 | * |
| 5930 | * This routine handles the Registration State Configuration Notification |
| 5931 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 5932 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 5933 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 5934 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 5935 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 5936 | * RSCN activities with the @vport. |
| 5937 | * |
| 5938 | * Return code |
| 5939 | * 0 - Cleaned up rscn on the @vport |
| 5940 | * 1 - Wait for plogi to name server before proceed |
| 5941 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5942 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5943 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5944 | { |
| 5945 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5946 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5947 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5948 | /* Ignore RSCN if the port is being torn down. */ |
| 5949 | if (vport->load_flag & FC_UNLOADING) { |
| 5950 | lpfc_els_flush_rscn(vport); |
| 5951 | return 0; |
| 5952 | } |
| 5953 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5954 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5955 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5956 | |
| 5957 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5958 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5959 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 5960 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 5961 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5962 | |
| 5963 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5964 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5965 | vport->num_disc_nodes = 0; |
| 5966 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5967 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5968 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 5969 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5970 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5971 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5972 | /* Wait for NameServer query cmpl before we can |
| 5973 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5974 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5975 | } else { |
| 5976 | /* If login to NameServer does not exist, issue one */ |
| 5977 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5978 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5979 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5980 | /* Wait for NameServer login cmpl before we can |
| 5981 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5982 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5983 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5984 | if (ndlp) { |
| 5985 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5986 | NLP_STE_PLOGI_ISSUE); |
| 5987 | if (!ndlp) { |
| 5988 | lpfc_els_flush_rscn(vport); |
| 5989 | return 0; |
| 5990 | } |
| 5991 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5992 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5993 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5994 | if (!ndlp) { |
| 5995 | lpfc_els_flush_rscn(vport); |
| 5996 | return 0; |
| 5997 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5998 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5999 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6000 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6001 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6002 | ndlp->nlp_type |= NLP_FABRIC; |
| 6003 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 6004 | /* Wait for NameServer login cmpl before we can |
| 6005 | * continue |
| 6006 | */ |
| 6007 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6008 | } |
| 6009 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6010 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6011 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6012 | } |
| 6013 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6014 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6015 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6016 | * @vport: pointer to a host virtual N_Port data structure. |
| 6017 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6018 | * @ndlp: pointer to a node-list data structure. |
| 6019 | * |
| 6020 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 6021 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 6022 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 6023 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 6024 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 6025 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 6026 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 6027 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 6028 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 6029 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 6030 | * higher priority (as the winning port) and will initiate PLOGI and |
| 6031 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 6032 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 6033 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 6034 | * |
| 6035 | * Return code |
| 6036 | * 0 - Successfully processed the unsolicited flogi |
| 6037 | * 1 - Failed to process the unsolicited flogi |
| 6038 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6039 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6040 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6041 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6042 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6043 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6044 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6045 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6046 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 6047 | IOCB_t *icmd = &cmdiocb->iocb; |
| 6048 | struct serv_parm *sp; |
| 6049 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6050 | uint32_t cmd, did; |
| 6051 | int rc; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6052 | uint32_t fc_flag = 0; |
| 6053 | uint32_t port_state = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6054 | |
| 6055 | cmd = *lp++; |
| 6056 | sp = (struct serv_parm *) lp; |
| 6057 | |
| 6058 | /* FLOGI received */ |
| 6059 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6060 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6061 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6062 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6063 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 6064 | did = icmd->un.elsreq64.remoteID; |
| 6065 | |
| 6066 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 6067 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6068 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6069 | "0113 An FLOGI ELS command x%x was " |
| 6070 | "received from DID x%x in Loop Mode\n", |
| 6071 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6072 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6073 | } |
| 6074 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6075 | (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6076 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6077 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6078 | /* |
| 6079 | * If our portname is greater than the remote portname, |
| 6080 | * then we initiate Nport login. |
| 6081 | */ |
| 6082 | |
| 6083 | rc = memcmp(&vport->fc_portname, &sp->portName, |
| 6084 | sizeof(struct lpfc_name)); |
| 6085 | |
| 6086 | if (!rc) { |
| 6087 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 6088 | mbox = mempool_alloc(phba->mbox_mem_pool, |
| 6089 | GFP_KERNEL); |
| 6090 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6091 | return 1; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6092 | lpfc_linkdown(phba); |
| 6093 | lpfc_init_link(phba, mbox, |
| 6094 | phba->cfg_topology, |
| 6095 | phba->cfg_link_speed); |
| 6096 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 6097 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 6098 | mbox->vport = vport; |
| 6099 | rc = lpfc_sli_issue_mbox(phba, mbox, |
| 6100 | MBX_NOWAIT); |
| 6101 | lpfc_set_loopback_flag(phba); |
| 6102 | if (rc == MBX_NOT_FINISHED) |
| 6103 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6104 | return 1; |
| 6105 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6106 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6107 | /* abort the flogi coming back to ourselves |
| 6108 | * due to external loopback on the port. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6109 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6110 | lpfc_els_abort_flogi(phba); |
| 6111 | return 0; |
| 6112 | |
| 6113 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6114 | spin_lock_irq(shost->host_lock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6115 | vport->fc_flag |= FC_PT2PT_PLOGI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6116 | spin_unlock_irq(shost->host_lock); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6117 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6118 | /* If we have the high WWPN we can assign our own |
| 6119 | * myDID; otherwise, we have to WAIT for a PLOGI |
| 6120 | * from the remote NPort to find out what it |
| 6121 | * will be. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6122 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6123 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6124 | } else { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6125 | vport->fc_myDID = PT2PT_RemoteID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6126 | } |
| 6127 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6128 | /* |
| 6129 | * The vport state should go to LPFC_FLOGI only |
| 6130 | * AFTER we issue a FLOGI, not receive one. |
| 6131 | */ |
| 6132 | spin_lock_irq(shost->host_lock); |
| 6133 | fc_flag = vport->fc_flag; |
| 6134 | port_state = vport->port_state; |
| 6135 | vport->fc_flag |= FC_PT2PT; |
| 6136 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6137 | spin_unlock_irq(shost->host_lock); |
| 6138 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6139 | "3311 Rcv Flogi PS x%x new PS x%x " |
| 6140 | "fc_flag x%x new fc_flag x%x\n", |
| 6141 | port_state, vport->port_state, |
| 6142 | fc_flag, vport->fc_flag); |
| 6143 | |
| 6144 | /* |
| 6145 | * We temporarily set fc_myDID to make it look like we are |
| 6146 | * a Fabric. This is done just so we end up with the right |
| 6147 | * did / sid on the FLOGI ACC rsp. |
| 6148 | */ |
| 6149 | did = vport->fc_myDID; |
| 6150 | vport->fc_myDID = Fabric_DID; |
| 6151 | |
| 6152 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 6153 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6154 | /* Send back ACC */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6155 | lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6156 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6157 | /* Now lets put fc_myDID back to what its supposed to be */ |
| 6158 | vport->fc_myDID = did; |
| 6159 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6160 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6161 | } |
| 6162 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6163 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6164 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6165 | * @vport: pointer to a host virtual N_Port data structure. |
| 6166 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6167 | * @ndlp: pointer to a node-list data structure. |
| 6168 | * |
| 6169 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 6170 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 6171 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 6172 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 6173 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 6174 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 6175 | * |
| 6176 | * Return code |
| 6177 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 6178 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6179 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6180 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6181 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6182 | { |
| 6183 | struct lpfc_dmabuf *pcmd; |
| 6184 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6185 | RNID *rn; |
| 6186 | struct ls_rjt stat; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6187 | uint32_t cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6188 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6189 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6190 | lp = (uint32_t *) pcmd->virt; |
| 6191 | |
| 6192 | cmd = *lp++; |
| 6193 | rn = (RNID *) lp; |
| 6194 | |
| 6195 | /* RNID received */ |
| 6196 | |
| 6197 | switch (rn->Format) { |
| 6198 | case 0: |
| 6199 | case RNID_TOPOLOGY_DISC: |
| 6200 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6201 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6202 | break; |
| 6203 | default: |
| 6204 | /* Reject this request because format not supported */ |
| 6205 | stat.un.b.lsRjtRsvd0 = 0; |
| 6206 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6207 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6208 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6209 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 6210 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6211 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6212 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6213 | } |
| 6214 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6215 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6216 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 6217 | * @vport: pointer to a host virtual N_Port data structure. |
| 6218 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6219 | * @ndlp: pointer to a node-list data structure. |
| 6220 | * |
| 6221 | * Return code |
| 6222 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 6223 | **/ |
| 6224 | static int |
| 6225 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6226 | struct lpfc_nodelist *ndlp) |
| 6227 | { |
| 6228 | uint8_t *pcmd; |
| 6229 | |
| 6230 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 6231 | |
| 6232 | /* skip over first word of echo command to find echo data */ |
| 6233 | pcmd += sizeof(uint32_t); |
| 6234 | |
| 6235 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 6236 | return 0; |
| 6237 | } |
| 6238 | |
| 6239 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6240 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6241 | * @vport: pointer to a host virtual N_Port data structure. |
| 6242 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6243 | * @ndlp: pointer to a node-list data structure. |
| 6244 | * |
| 6245 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 6246 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 6247 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 6248 | * |
| 6249 | * Return code |
| 6250 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 6251 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6252 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6253 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6254 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6255 | { |
| 6256 | struct ls_rjt stat; |
| 6257 | |
| 6258 | /* For now, unconditionally reject this command */ |
| 6259 | stat.un.b.lsRjtRsvd0 = 0; |
| 6260 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6261 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6262 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6263 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6264 | return 0; |
| 6265 | } |
| 6266 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6267 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6268 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 6269 | * @vport: pointer to a host virtual N_Port data structure. |
| 6270 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6271 | * @ndlp: pointer to a node-list data structure. |
| 6272 | * |
| 6273 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 6274 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 6275 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 6276 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 6277 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 6278 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 6279 | * command request" and reason code explanation "Invalid Originator |
| 6280 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 6281 | * RRQ from the target. |
| 6282 | **/ |
| 6283 | static void |
| 6284 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6285 | struct lpfc_nodelist *ndlp) |
| 6286 | { |
| 6287 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6288 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 6289 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6290 | } |
| 6291 | |
| 6292 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6293 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 6294 | * @phba: pointer to lpfc hba data structure. |
| 6295 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6296 | * |
| 6297 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 6298 | * mailbox command. This callback function is to actually send the Accept |
| 6299 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 6300 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 6301 | * mailbox command, constructs the RPS response with the link statistics |
| 6302 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 6303 | * response to the RPS. |
| 6304 | * |
| 6305 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6306 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6307 | * will be stored into the context1 field of the IOCB for the completion |
| 6308 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6309 | * |
| 6310 | **/ |
| 6311 | static void |
| 6312 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6313 | { |
| 6314 | MAILBOX_t *mb; |
| 6315 | IOCB_t *icmd; |
| 6316 | struct RLS_RSP *rls_rsp; |
| 6317 | uint8_t *pcmd; |
| 6318 | struct lpfc_iocbq *elsiocb; |
| 6319 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6320 | uint16_t oxid; |
| 6321 | uint16_t rxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6322 | uint32_t cmdsize; |
| 6323 | |
| 6324 | mb = &pmb->u.mb; |
| 6325 | |
| 6326 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6327 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 6328 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6329 | pmb->context1 = NULL; |
| 6330 | pmb->context2 = NULL; |
| 6331 | |
| 6332 | if (mb->mbxStatus) { |
| 6333 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6334 | return; |
| 6335 | } |
| 6336 | |
| 6337 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6338 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6339 | lpfc_max_els_tries, ndlp, |
| 6340 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6341 | |
| 6342 | /* Decrement the ndlp reference count from previous mbox command */ |
| 6343 | lpfc_nlp_put(ndlp); |
| 6344 | |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6345 | if (!elsiocb) { |
| 6346 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6347 | return; |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6348 | } |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6349 | |
| 6350 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6351 | icmd->ulpContext = rxid; |
| 6352 | icmd->unsli3.rcvsli3.ox_id = oxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6353 | |
| 6354 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6355 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6356 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 6357 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 6358 | |
| 6359 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 6360 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 6361 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 6362 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 6363 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 6364 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6365 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6366 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 6367 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6368 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 6369 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 6370 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6371 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6372 | ndlp->nlp_rpi); |
| 6373 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6374 | phba->fc_stat.elsXmitACC++; |
| 6375 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 6376 | lpfc_els_free_iocb(phba, elsiocb); |
| 6377 | } |
| 6378 | |
| 6379 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6380 | * 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] | 6381 | * @phba: pointer to lpfc hba data structure. |
| 6382 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6383 | * |
| 6384 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 6385 | * mailbox command. This callback function is to actually send the Accept |
| 6386 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 6387 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 6388 | * mailbox command, constructs the RPS response with the link statistics |
| 6389 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 6390 | * response to the RPS. |
| 6391 | * |
| 6392 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6393 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6394 | * will be stored into the context1 field of the IOCB for the completion |
| 6395 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6396 | * |
| 6397 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 6398 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6399 | 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] | 6400 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6401 | MAILBOX_t *mb; |
| 6402 | IOCB_t *icmd; |
| 6403 | RPS_RSP *rps_rsp; |
| 6404 | uint8_t *pcmd; |
| 6405 | struct lpfc_iocbq *elsiocb; |
| 6406 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6407 | uint16_t status; |
| 6408 | uint16_t oxid; |
| 6409 | uint16_t rxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6410 | uint32_t cmdsize; |
| 6411 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6412 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6413 | |
| 6414 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6415 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 6416 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 6417 | pmb->context1 = NULL; |
| 6418 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6419 | |
| 6420 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6421 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6422 | return; |
| 6423 | } |
| 6424 | |
| 6425 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6426 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6427 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6428 | lpfc_max_els_tries, ndlp, |
| 6429 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6430 | |
| 6431 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6432 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6433 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6434 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6435 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6436 | |
| 6437 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6438 | icmd->ulpContext = rxid; |
| 6439 | icmd->unsli3.rcvsli3.ox_id = oxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6440 | |
| 6441 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6442 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6443 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6444 | rps_rsp = (RPS_RSP *)pcmd; |
| 6445 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6446 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6447 | status = 0x10; |
| 6448 | else |
| 6449 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6450 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6451 | status |= 0x4; |
| 6452 | |
| 6453 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6454 | rps_rsp->portStatus = cpu_to_be16(status); |
| 6455 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 6456 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 6457 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 6458 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 6459 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 6460 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6461 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6462 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6463 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 6464 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 6465 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6466 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6467 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6468 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6469 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6470 | 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] | 6471 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6472 | return; |
| 6473 | } |
| 6474 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6475 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6476 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 6477 | * @vport: pointer to a host virtual N_Port data structure. |
| 6478 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6479 | * @ndlp: pointer to a node-list data structure. |
| 6480 | * |
| 6481 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 6482 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6483 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6484 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 6485 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 6486 | * for reading the HBA link statistics. It is for the callback function, |
| 6487 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 6488 | * to actually sending out RPL Accept (ACC) response. |
| 6489 | * |
| 6490 | * Return codes |
| 6491 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 6492 | **/ |
| 6493 | static int |
| 6494 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6495 | struct lpfc_nodelist *ndlp) |
| 6496 | { |
| 6497 | struct lpfc_hba *phba = vport->phba; |
| 6498 | LPFC_MBOXQ_t *mbox; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6499 | struct ls_rjt stat; |
| 6500 | |
| 6501 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6502 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6503 | /* reject the unsolicited RPS request and done with it */ |
| 6504 | goto reject_out; |
| 6505 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6506 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 6507 | if (mbox) { |
| 6508 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6509 | mbox->context1 = (void *)((unsigned long) |
| 6510 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 6511 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6512 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6513 | mbox->vport = vport; |
| 6514 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 6515 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 6516 | != MBX_NOT_FINISHED) |
| 6517 | /* Mbox completion will send ELS Response */ |
| 6518 | return 0; |
| 6519 | /* Decrement reference count used for the failed mbox |
| 6520 | * command. |
| 6521 | */ |
| 6522 | lpfc_nlp_put(ndlp); |
| 6523 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6524 | } |
| 6525 | reject_out: |
| 6526 | /* issue rejection response */ |
| 6527 | stat.un.b.lsRjtRsvd0 = 0; |
| 6528 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6529 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6530 | stat.un.b.vendorUnique = 0; |
| 6531 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6532 | return 0; |
| 6533 | } |
| 6534 | |
| 6535 | /** |
| 6536 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 6537 | * @vport: pointer to a host virtual N_Port data structure. |
| 6538 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6539 | * @ndlp: pointer to a node-list data structure. |
| 6540 | * |
| 6541 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 6542 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6543 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6544 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 6545 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 6546 | * Value (RTV) unsolicited IOCB event. |
| 6547 | * |
| 6548 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6549 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6550 | * will be stored into the context1 field of the IOCB for the completion |
| 6551 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6552 | * |
| 6553 | * Return codes |
| 6554 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 6555 | **/ |
| 6556 | static int |
| 6557 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6558 | struct lpfc_nodelist *ndlp) |
| 6559 | { |
| 6560 | struct lpfc_hba *phba = vport->phba; |
| 6561 | struct ls_rjt stat; |
| 6562 | struct RTV_RSP *rtv_rsp; |
| 6563 | uint8_t *pcmd; |
| 6564 | struct lpfc_iocbq *elsiocb; |
| 6565 | uint32_t cmdsize; |
| 6566 | |
| 6567 | |
| 6568 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6569 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6570 | /* reject the unsolicited RPS request and done with it */ |
| 6571 | goto reject_out; |
| 6572 | |
| 6573 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 6574 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6575 | lpfc_max_els_tries, ndlp, |
| 6576 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6577 | |
| 6578 | if (!elsiocb) |
| 6579 | return 1; |
| 6580 | |
| 6581 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6582 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6583 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 6584 | |
| 6585 | /* use the command's xri in the response */ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6586 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 6587 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6588 | |
| 6589 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 6590 | |
| 6591 | /* populate RTV payload */ |
| 6592 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 6593 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 6594 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 6595 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 6596 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 6597 | |
| 6598 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 6599 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6600 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 6601 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 6602 | "Data: x%x x%x x%x\n", |
| 6603 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6604 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6605 | ndlp->nlp_rpi, |
| 6606 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 6607 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6608 | phba->fc_stat.elsXmitACC++; |
| 6609 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 6610 | lpfc_els_free_iocb(phba, elsiocb); |
| 6611 | return 0; |
| 6612 | |
| 6613 | reject_out: |
| 6614 | /* issue rejection response */ |
| 6615 | stat.un.b.lsRjtRsvd0 = 0; |
| 6616 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6617 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6618 | stat.un.b.vendorUnique = 0; |
| 6619 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6620 | return 0; |
| 6621 | } |
| 6622 | |
| 6623 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6624 | * @vport: pointer to a host virtual N_Port data structure. |
| 6625 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6626 | * @ndlp: pointer to a node-list data structure. |
| 6627 | * |
| 6628 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 6629 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6630 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6631 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 6632 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 6633 | * for reading the HBA link statistics. It is for the callback function, |
| 6634 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 6635 | * to actually sending out RPS Accept (ACC) response. |
| 6636 | * |
| 6637 | * Return codes |
| 6638 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 6639 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6640 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6641 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6642 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6643 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6644 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6645 | uint32_t *lp; |
| 6646 | uint8_t flag; |
| 6647 | LPFC_MBOXQ_t *mbox; |
| 6648 | struct lpfc_dmabuf *pcmd; |
| 6649 | RPS *rps; |
| 6650 | struct ls_rjt stat; |
| 6651 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6652 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6653 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6654 | /* reject the unsolicited RPS request and done with it */ |
| 6655 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6656 | |
| 6657 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6658 | lp = (uint32_t *) pcmd->virt; |
| 6659 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 6660 | rps = (RPS *) lp; |
| 6661 | |
| 6662 | if ((flag == 0) || |
| 6663 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6664 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6665 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6666 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6667 | printk("Fix me....\n"); |
| 6668 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6669 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 6670 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6671 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6672 | mbox->context1 = (void *)((unsigned long) |
| 6673 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 6674 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6675 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6676 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6677 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6678 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6679 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6680 | /* Mbox completion will send ELS Response */ |
| 6681 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6682 | /* Decrement reference count used for the failed mbox |
| 6683 | * command. |
| 6684 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6685 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6686 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6687 | } |
| 6688 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6689 | |
| 6690 | reject_out: |
| 6691 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6692 | stat.un.b.lsRjtRsvd0 = 0; |
| 6693 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6694 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6695 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6696 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6697 | return 0; |
| 6698 | } |
| 6699 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6700 | /* lpfc_issue_els_rrq - Process an unsolicited rps iocb |
| 6701 | * @vport: pointer to a host virtual N_Port data structure. |
| 6702 | * @ndlp: pointer to a node-list data structure. |
| 6703 | * @did: DID of the target. |
| 6704 | * @rrq: Pointer to the rrq struct. |
| 6705 | * |
| 6706 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is |
| 6707 | * Successful the the completion handler will clear the RRQ. |
| 6708 | * |
| 6709 | * Return codes |
| 6710 | * 0 - Successfully sent rrq els iocb. |
| 6711 | * 1 - Failed to send rrq els iocb. |
| 6712 | **/ |
| 6713 | static int |
| 6714 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6715 | uint32_t did, struct lpfc_node_rrq *rrq) |
| 6716 | { |
| 6717 | struct lpfc_hba *phba = vport->phba; |
| 6718 | struct RRQ *els_rrq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6719 | struct lpfc_iocbq *elsiocb; |
| 6720 | uint8_t *pcmd; |
| 6721 | uint16_t cmdsize; |
| 6722 | int ret; |
| 6723 | |
| 6724 | |
| 6725 | if (ndlp != rrq->ndlp) |
| 6726 | ndlp = rrq->ndlp; |
| 6727 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 6728 | return 1; |
| 6729 | |
| 6730 | /* If ndlp is not NULL, we will bump the reference count on it */ |
| 6731 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); |
| 6732 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, |
| 6733 | ELS_CMD_RRQ); |
| 6734 | if (!elsiocb) |
| 6735 | return 1; |
| 6736 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6737 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6738 | |
| 6739 | /* For RRQ request, remainder of payload is Exchange IDs */ |
| 6740 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; |
| 6741 | pcmd += sizeof(uint32_t); |
| 6742 | els_rrq = (struct RRQ *) pcmd; |
| 6743 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 6744 | 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] | 6745 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
| 6746 | bf_set(rrq_did, els_rrq, vport->fc_myDID); |
| 6747 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); |
| 6748 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); |
| 6749 | |
| 6750 | |
| 6751 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6752 | "Issue RRQ: did:x%x", |
| 6753 | did, rrq->xritag, rrq->rxid); |
| 6754 | elsiocb->context_un.rrq = rrq; |
| 6755 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; |
| 6756 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6757 | |
| 6758 | if (ret == IOCB_ERROR) { |
| 6759 | lpfc_els_free_iocb(phba, elsiocb); |
| 6760 | return 1; |
| 6761 | } |
| 6762 | return 0; |
| 6763 | } |
| 6764 | |
| 6765 | /** |
| 6766 | * lpfc_send_rrq - Sends ELS RRQ if needed. |
| 6767 | * @phba: pointer to lpfc hba data structure. |
| 6768 | * @rrq: pointer to the active rrq. |
| 6769 | * |
| 6770 | * This routine will call the lpfc_issue_els_rrq if the rrq is |
| 6771 | * still active for the xri. If this function returns a failure then |
| 6772 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. |
| 6773 | * |
| 6774 | * Returns 0 Success. |
| 6775 | * 1 Failure. |
| 6776 | **/ |
| 6777 | int |
| 6778 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) |
| 6779 | { |
| 6780 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, |
| 6781 | rrq->nlp_DID); |
| 6782 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) |
| 6783 | return lpfc_issue_els_rrq(rrq->vport, ndlp, |
| 6784 | rrq->nlp_DID, rrq); |
| 6785 | else |
| 6786 | return 1; |
| 6787 | } |
| 6788 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6789 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6790 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6791 | * @vport: pointer to a host virtual N_Port data structure. |
| 6792 | * @cmdsize: size of the ELS command. |
| 6793 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 6794 | * @ndlp: pointer to a node-list data structure. |
| 6795 | * |
| 6796 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 6797 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 6798 | * |
| 6799 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6800 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6801 | * will be stored into the context1 field of the IOCB for the completion |
| 6802 | * callback function to the RPL Accept Response ELS command. |
| 6803 | * |
| 6804 | * Return code |
| 6805 | * 0 - Successfully issued ACC RPL ELS command |
| 6806 | * 1 - Failed to issue ACC RPL ELS command |
| 6807 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 6808 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6809 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 6810 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6811 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6812 | struct lpfc_hba *phba = vport->phba; |
| 6813 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6814 | RPL_RSP rpl_rsp; |
| 6815 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6816 | uint8_t *pcmd; |
| 6817 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6818 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 6819 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6820 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6821 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6822 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6823 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6824 | icmd = &elsiocb->iocb; |
| 6825 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6826 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 6827 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6828 | |
| 6829 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6830 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6831 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6832 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 6833 | pcmd += sizeof(uint16_t); |
| 6834 | |
| 6835 | /* Setup the RPL ACC payload */ |
| 6836 | rpl_rsp.listLen = be32_to_cpu(1); |
| 6837 | rpl_rsp.index = 0; |
| 6838 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6839 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 6840 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6841 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6842 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6843 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6844 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6845 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 6846 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 6847 | "rpi x%x\n", |
| 6848 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6849 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6850 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6851 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6852 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6853 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6854 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6855 | lpfc_els_free_iocb(phba, elsiocb); |
| 6856 | return 1; |
| 6857 | } |
| 6858 | return 0; |
| 6859 | } |
| 6860 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6861 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6862 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6863 | * @vport: pointer to a host virtual N_Port data structure. |
| 6864 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6865 | * @ndlp: pointer to a node-list data structure. |
| 6866 | * |
| 6867 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 6868 | * unsolicited event. It first checks the remote port state. If the remote |
| 6869 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 6870 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 6871 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 6872 | * to accept the RPL. |
| 6873 | * |
| 6874 | * Return code |
| 6875 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 6876 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6877 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6878 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6879 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6880 | { |
| 6881 | struct lpfc_dmabuf *pcmd; |
| 6882 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6883 | uint32_t maxsize; |
| 6884 | uint16_t cmdsize; |
| 6885 | RPL *rpl; |
| 6886 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6887 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6888 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6889 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6890 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6891 | stat.un.b.lsRjtRsvd0 = 0; |
| 6892 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6893 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6894 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6895 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 6896 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6897 | /* rejected the unsolicited RPL request and done with it */ |
| 6898 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6899 | } |
| 6900 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6901 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6902 | lp = (uint32_t *) pcmd->virt; |
| 6903 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6904 | maxsize = be32_to_cpu(rpl->maxsize); |
| 6905 | |
| 6906 | /* We support only one port */ |
| 6907 | if ((rpl->index == 0) && |
| 6908 | ((maxsize == 0) || |
| 6909 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 6910 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6911 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6912 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 6913 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6914 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6915 | |
| 6916 | return 0; |
| 6917 | } |
| 6918 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6919 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6920 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6921 | * @vport: pointer to a virtual N_Port data structure. |
| 6922 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6923 | * @ndlp: pointer to a node-list data structure. |
| 6924 | * |
| 6925 | * This routine processes Fibre Channel Address Resolution Protocol |
| 6926 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 6927 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 6928 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 6929 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 6930 | * remote PortName is compared against the FC PortName stored in the @vport |
| 6931 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 6932 | * compared against the FC NodeName stored in the @vport data structure. |
| 6933 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 6934 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 6935 | * invoked to send out FARP Response to the remote node. Before sending the |
| 6936 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 6937 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 6938 | * routine is invoked to log into the remote port first. |
| 6939 | * |
| 6940 | * Return code |
| 6941 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 6942 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6943 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6944 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6945 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6946 | { |
| 6947 | struct lpfc_dmabuf *pcmd; |
| 6948 | uint32_t *lp; |
| 6949 | IOCB_t *icmd; |
| 6950 | FARP *fp; |
| 6951 | uint32_t cmd, cnt, did; |
| 6952 | |
| 6953 | icmd = &cmdiocb->iocb; |
| 6954 | did = icmd->un.elsreq64.remoteID; |
| 6955 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6956 | lp = (uint32_t *) pcmd->virt; |
| 6957 | |
| 6958 | cmd = *lp++; |
| 6959 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6960 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6961 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6962 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6963 | /* We will only support match on WWPN or WWNN */ |
| 6964 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6965 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6966 | } |
| 6967 | |
| 6968 | cnt = 0; |
| 6969 | /* If this FARP command is searching for my portname */ |
| 6970 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6971 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6972 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6973 | cnt = 1; |
| 6974 | } |
| 6975 | |
| 6976 | /* If this FARP command is searching for my nodename */ |
| 6977 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6978 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6979 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6980 | cnt = 1; |
| 6981 | } |
| 6982 | |
| 6983 | if (cnt) { |
| 6984 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 6985 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 6986 | /* Log back into the node before sending the FARP. */ |
| 6987 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6988 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6989 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 6990 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6991 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6992 | } |
| 6993 | |
| 6994 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6995 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 6996 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6997 | } |
| 6998 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6999 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7000 | } |
| 7001 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7002 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7003 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7004 | * @vport: pointer to a host virtual N_Port data structure. |
| 7005 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7006 | * @ndlp: pointer to a node-list data structure. |
| 7007 | * |
| 7008 | * This routine processes Fibre Channel Address Resolution Protocol |
| 7009 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 7010 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 7011 | * the FARP response request. |
| 7012 | * |
| 7013 | * Return code |
| 7014 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 7015 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7016 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7017 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7018 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7019 | { |
| 7020 | struct lpfc_dmabuf *pcmd; |
| 7021 | uint32_t *lp; |
| 7022 | IOCB_t *icmd; |
| 7023 | uint32_t cmd, did; |
| 7024 | |
| 7025 | icmd = &cmdiocb->iocb; |
| 7026 | did = icmd->un.elsreq64.remoteID; |
| 7027 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7028 | lp = (uint32_t *) pcmd->virt; |
| 7029 | |
| 7030 | cmd = *lp++; |
| 7031 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7032 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7033 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7034 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7035 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7036 | |
| 7037 | return 0; |
| 7038 | } |
| 7039 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7040 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7041 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7042 | * @vport: pointer to a host virtual N_Port data structure. |
| 7043 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7044 | * @fan_ndlp: pointer to a node-list data structure. |
| 7045 | * |
| 7046 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 7047 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 7048 | * only be processed on a physical port (i.e., the @vport represents the |
| 7049 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 7050 | * compared against those in the phba data structure. If any of those is |
| 7051 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 7052 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 7053 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 7054 | * is invoked to register login to the fabric. |
| 7055 | * |
| 7056 | * Return code |
| 7057 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 7058 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7059 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7060 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7061 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7062 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7063 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7064 | uint32_t *lp; |
| 7065 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7066 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7067 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 7068 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 7069 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7070 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7071 | if ((vport == phba->pport) && |
| 7072 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7073 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7074 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7075 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7076 | sizeof(struct lpfc_name)))) { |
| 7077 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7078 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7079 | } else { |
| 7080 | /* FAN verified - skip FLOGI */ |
| 7081 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7082 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 7083 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7084 | else { |
| 7085 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7086 | "3138 Need register VFI: (x%x/%x)\n", |
| 7087 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7088 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7089 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7090 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7091 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7092 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7093 | } |
| 7094 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7095 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7096 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7097 | * @ptr: holder for the timer function associated data. |
| 7098 | * |
| 7099 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 7100 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 7101 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 7102 | * up the worker thread. It is for the worker thread to invoke the routine |
| 7103 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 7104 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7105 | void |
| 7106 | lpfc_els_timeout(unsigned long ptr) |
| 7107 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7108 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 7109 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7110 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7111 | unsigned long iflag; |
| 7112 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7113 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7114 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7115 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7116 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7117 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7118 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7119 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7120 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7121 | return; |
| 7122 | } |
| 7123 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7124 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7125 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7126 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7127 | * @vport: pointer to a virtual N_Port data structure. |
| 7128 | * |
| 7129 | * This routine is the actual handler function that processes an ELS timeout |
| 7130 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 7131 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 7132 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 7133 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7134 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7135 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7136 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7137 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7138 | struct lpfc_sli_ring *pring; |
| 7139 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7140 | IOCB_t *cmd = NULL; |
| 7141 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7142 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7143 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7144 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7145 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7146 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7147 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7148 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 7149 | |
| 7150 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7151 | if ((phba->pport->load_flag & FC_UNLOADING)) |
| 7152 | return; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7153 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7154 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7155 | spin_lock(&pring->ring_lock); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7156 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7157 | if ((phba->pport->load_flag & FC_UNLOADING)) { |
| 7158 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7159 | spin_unlock(&pring->ring_lock); |
| 7160 | spin_unlock_irq(&phba->hbalock); |
| 7161 | return; |
| 7162 | } |
| 7163 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7164 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7165 | cmd = &piocb->iocb; |
| 7166 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7167 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 7168 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 7169 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7170 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7171 | |
| 7172 | if (piocb->vport != vport) |
| 7173 | continue; |
| 7174 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7175 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7176 | if (pcmd) |
| 7177 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7178 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7179 | if (els_command == ELS_CMD_FARP || |
| 7180 | els_command == ELS_CMD_FARPR || |
| 7181 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7182 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7183 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7184 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7185 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7186 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7187 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7188 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7189 | continue; |
| 7190 | } |
| 7191 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7192 | remote_ID = 0xffffffff; |
| 7193 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7194 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7195 | else { |
| 7196 | struct lpfc_nodelist *ndlp; |
| 7197 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7198 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7199 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7200 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7201 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7202 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7203 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7204 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7205 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 7206 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7207 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
James Smart | 15026c9 | 2013-12-17 20:30:09 -0500 | [diff] [blame] | 7208 | cmd = &piocb->iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7209 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7210 | "0127 ELS timeout Data: x%x x%x x%x " |
| 7211 | "x%x\n", els_command, |
| 7212 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 7213 | spin_lock_irq(&phba->hbalock); |
| 7214 | list_del_init(&piocb->dlist); |
| 7215 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 7216 | spin_unlock_irq(&phba->hbalock); |
| 7217 | } |
| 7218 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 7219 | if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq)) |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7220 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 7221 | mod_timer(&vport->els_tmofunc, |
| 7222 | jiffies + msecs_to_jiffies(1000 * timeout)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7223 | } |
| 7224 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7225 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7226 | * 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] | 7227 | * @vport: pointer to a host virtual N_Port data structure. |
| 7228 | * |
| 7229 | * This routine is used to clean up all the outstanding ELS commands on a |
| 7230 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 7231 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 7232 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 7233 | * the IOCBs with a non-NULL completion callback function, the callback |
| 7234 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 7235 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 7236 | * callback function, the IOCB will simply be released. Finally, it walks |
| 7237 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 7238 | * completion queue IOCB that is associated with the @vport and is not |
| 7239 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 7240 | * part of the discovery state machine) out to HBA by invoking the |
| 7241 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 7242 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 7243 | * the IOCBs are aborted when this function returns. |
| 7244 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7245 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7246 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7247 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7248 | LIST_HEAD(abort_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7249 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7250 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7251 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7252 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7253 | |
| 7254 | lpfc_fabric_abort_vport(vport); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7255 | /* |
| 7256 | * For SLI3, only the hbalock is required. But SLI4 needs to coordinate |
| 7257 | * with the ring insert operation. Because lpfc_sli_issue_abort_iotag |
| 7258 | * ultimately grabs the ring_lock, the driver must splice the list into |
| 7259 | * a working list and release the locks before calling the abort. |
| 7260 | */ |
| 7261 | spin_lock_irq(&phba->hbalock); |
| 7262 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7263 | spin_lock(&pring->ring_lock); |
| 7264 | |
| 7265 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 7266 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 7267 | continue; |
| 7268 | |
| 7269 | if (piocb->vport != vport) |
| 7270 | continue; |
| 7271 | list_add_tail(&piocb->dlist, &abort_list); |
| 7272 | } |
| 7273 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7274 | spin_unlock(&pring->ring_lock); |
| 7275 | spin_unlock_irq(&phba->hbalock); |
| 7276 | /* Abort each iocb on the aborted list and remove the dlist links. */ |
| 7277 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 7278 | spin_lock_irq(&phba->hbalock); |
| 7279 | list_del_init(&piocb->dlist); |
| 7280 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 7281 | spin_unlock_irq(&phba->hbalock); |
| 7282 | } |
| 7283 | if (!list_empty(&abort_list)) |
| 7284 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7285 | "3387 abort list for txq not empty\n"); |
| 7286 | INIT_LIST_HEAD(&abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7287 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7288 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7289 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7290 | spin_lock(&pring->ring_lock); |
| 7291 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7292 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 7293 | cmd = &piocb->iocb; |
| 7294 | |
| 7295 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 7296 | continue; |
| 7297 | } |
| 7298 | |
| 7299 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7300 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 7301 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 7302 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 7303 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7304 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7305 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7306 | if (piocb->vport != vport) |
| 7307 | continue; |
| 7308 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7309 | list_del_init(&piocb->list); |
| 7310 | list_add_tail(&piocb->list, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7311 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7312 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7313 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7314 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 7315 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7316 | /* Cancell all the IOCBs from the completions list */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7317 | lpfc_sli_cancel_iocbs(phba, &abort_list, |
| 7318 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 7319 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7320 | return; |
| 7321 | } |
| 7322 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7323 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7324 | * 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] | 7325 | * @phba: pointer to lpfc hba data structure. |
| 7326 | * |
| 7327 | * This routine is used to clean up all the outstanding ELS commands on a |
| 7328 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 7329 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 7330 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 7331 | * the IOCBs with the completion callback function associated, the callback |
| 7332 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 7333 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 7334 | * callback function associated, the IOCB will simply be released. Finally, |
| 7335 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 7336 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 7337 | * management plane IOCBs that are not part of the discovery state machine) |
| 7338 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 7339 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 7340 | void |
| 7341 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 7342 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7343 | struct lpfc_vport *vport; |
| 7344 | list_for_each_entry(vport, &phba->port_list, listentry) |
| 7345 | lpfc_els_flush_cmd(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7346 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 7347 | return; |
| 7348 | } |
| 7349 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7350 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7351 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7352 | * @phba: Pointer to hba context object. |
| 7353 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 7354 | * @rspiocbp: Pointer to response iocb which reported error. |
| 7355 | * |
| 7356 | * This function sends an event when there is an ELS command |
| 7357 | * failure. |
| 7358 | **/ |
| 7359 | void |
| 7360 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 7361 | struct lpfc_iocbq *cmdiocbp, |
| 7362 | struct lpfc_iocbq *rspiocbp) |
| 7363 | { |
| 7364 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 7365 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7366 | struct lpfc_lsrjt_event lsrjt_event; |
| 7367 | struct lpfc_fabric_event_header fabric_event; |
| 7368 | struct ls_rjt stat; |
| 7369 | struct lpfc_nodelist *ndlp; |
| 7370 | uint32_t *pcmd; |
| 7371 | |
| 7372 | ndlp = cmdiocbp->context1; |
| 7373 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 7374 | return; |
| 7375 | |
| 7376 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 7377 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 7378 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 7379 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 7380 | sizeof(struct lpfc_name)); |
| 7381 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 7382 | sizeof(struct lpfc_name)); |
| 7383 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 7384 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7385 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7386 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 7387 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 7388 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 7389 | fc_host_post_vendor_event(shost, |
| 7390 | fc_get_event_number(), |
| 7391 | sizeof(lsrjt_event), |
| 7392 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7393 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7394 | return; |
| 7395 | } |
| 7396 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 7397 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 7398 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 7399 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 7400 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 7401 | else |
| 7402 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 7403 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 7404 | sizeof(struct lpfc_name)); |
| 7405 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 7406 | sizeof(struct lpfc_name)); |
| 7407 | fc_host_post_vendor_event(shost, |
| 7408 | fc_get_event_number(), |
| 7409 | sizeof(fabric_event), |
| 7410 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7411 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7412 | return; |
| 7413 | } |
| 7414 | |
| 7415 | } |
| 7416 | |
| 7417 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7418 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7419 | * @vport: Pointer to vport object. |
| 7420 | * @ndlp: Pointer FC node object. |
| 7421 | * @cmd: ELS command code. |
| 7422 | * |
| 7423 | * This function posts an event when there is an incoming |
| 7424 | * unsolicited ELS command. |
| 7425 | **/ |
| 7426 | static void |
| 7427 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 7428 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7429 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7430 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7431 | struct lpfc_els_event_header *els_data = NULL; |
| 7432 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7433 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7434 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7435 | if (*payload == ELS_CMD_LOGO) { |
| 7436 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 7437 | if (!logo_data) { |
| 7438 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7439 | "0148 Failed to allocate memory " |
| 7440 | "for LOGO event\n"); |
| 7441 | return; |
| 7442 | } |
| 7443 | els_data = &logo_data->header; |
| 7444 | } else { |
| 7445 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 7446 | GFP_KERNEL); |
| 7447 | if (!els_data) { |
| 7448 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7449 | "0149 Failed to allocate memory " |
| 7450 | "for ELS event\n"); |
| 7451 | return; |
| 7452 | } |
| 7453 | } |
| 7454 | els_data->event_type = FC_REG_ELS_EVENT; |
| 7455 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7456 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7457 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7458 | break; |
| 7459 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7460 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7461 | break; |
| 7462 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7463 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 7464 | break; |
| 7465 | case ELS_CMD_LOGO: |
| 7466 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 7467 | /* Copy the WWPN in the LOGO payload */ |
| 7468 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 7469 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7470 | break; |
| 7471 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 7472 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7473 | return; |
| 7474 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7475 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 7476 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 7477 | if (*payload == ELS_CMD_LOGO) { |
| 7478 | fc_host_post_vendor_event(shost, |
| 7479 | fc_get_event_number(), |
| 7480 | sizeof(struct lpfc_logo_event), |
| 7481 | (char *)logo_data, |
| 7482 | LPFC_NL_VENDOR_ID); |
| 7483 | kfree(logo_data); |
| 7484 | } else { |
| 7485 | fc_host_post_vendor_event(shost, |
| 7486 | fc_get_event_number(), |
| 7487 | sizeof(struct lpfc_els_event_header), |
| 7488 | (char *)els_data, |
| 7489 | LPFC_NL_VENDOR_ID); |
| 7490 | kfree(els_data); |
| 7491 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7492 | |
| 7493 | return; |
| 7494 | } |
| 7495 | |
| 7496 | |
| 7497 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7498 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7499 | * @phba: pointer to lpfc hba data structure. |
| 7500 | * @pring: pointer to a SLI ring. |
| 7501 | * @vport: pointer to a host virtual N_Port data structure. |
| 7502 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 7503 | * |
| 7504 | * This routine is used for processing the IOCB associated with a unsolicited |
| 7505 | * event. It first determines whether there is an existing ndlp that matches |
| 7506 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 7507 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 7508 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 7509 | * of the discovery state machine. |
| 7510 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7511 | static void |
| 7512 | 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] | 7513 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7514 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7515 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7516 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7517 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7518 | uint32_t *payload; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7519 | uint32_t cmd, did, newnode; |
| 7520 | uint8_t rjt_exp, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7521 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7522 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7523 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7524 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7525 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7526 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7527 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 7528 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7529 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 7530 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7531 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7532 | did = icmd->un.rcvels.remoteID; |
| 7533 | if (icmd->ulpStatus) { |
| 7534 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7535 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 7536 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7537 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7538 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7539 | |
| 7540 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7541 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7542 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7543 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7544 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7545 | if (vport->load_flag & FC_UNLOADING) |
| 7546 | goto dropit; |
| 7547 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7548 | /* If NPort discovery is delayed drop incoming ELS */ |
| 7549 | if ((vport->fc_flag & FC_DISC_DELAYED) && |
| 7550 | (cmd != ELS_CMD_PLOGI)) |
| 7551 | goto dropit; |
| 7552 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7553 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7554 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7555 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7556 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7557 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7558 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7559 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7560 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7561 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7562 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7563 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7564 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7565 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 7566 | ndlp = lpfc_enable_node(vport, ndlp, |
| 7567 | NLP_STE_UNUSED_NODE); |
| 7568 | if (!ndlp) |
| 7569 | goto dropit; |
| 7570 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 7571 | newnode = 1; |
| 7572 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 7573 | ndlp->nlp_type |= NLP_FABRIC; |
| 7574 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 7575 | /* This is similar to the new node path */ |
| 7576 | ndlp = lpfc_nlp_get(ndlp); |
| 7577 | if (!ndlp) |
| 7578 | goto dropit; |
| 7579 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 7580 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7581 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7582 | |
| 7583 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7584 | |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7585 | /* |
| 7586 | * Do not process any unsolicited ELS commands |
| 7587 | * if the ndlp is in DEV_LOSS |
| 7588 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 7589 | shost = lpfc_shost_from_vport(vport); |
| 7590 | spin_lock_irq(shost->host_lock); |
| 7591 | if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) { |
| 7592 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7593 | goto dropit; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 7594 | } |
| 7595 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7596 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7597 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7598 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7599 | |
| 7600 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 7601 | cmd &= ELS_CMD_MASK; |
| 7602 | } |
| 7603 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7604 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7605 | "0112 ELS command x%x received from NPORT x%x " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7606 | "Data: x%x x%x x%x x%x\n", |
| 7607 | cmd, did, vport->port_state, vport->fc_flag, |
| 7608 | vport->fc_myDID, vport->fc_prevDID); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7609 | |
| 7610 | /* reject till our FLOGI completes */ |
| 7611 | if ((vport->port_state < LPFC_FABRIC_CFG_LINK) && |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7612 | (cmd != ELS_CMD_FLOGI)) { |
James Smart | 401304c | 2016-10-13 15:06:14 -0700 | [diff] [blame] | 7613 | rjt_err = LSRJT_LOGICAL_BSY; |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7614 | rjt_exp = LSEXP_NOTHING_MORE; |
| 7615 | goto lsrjt; |
| 7616 | } |
| 7617 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7618 | switch (cmd) { |
| 7619 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7620 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7621 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 7622 | did, vport->port_state, ndlp->nlp_flag); |
| 7623 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7624 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7625 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7626 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 7627 | (phba->pport->fc_flag & FC_PT2PT)) { |
| 7628 | vport->fc_prevDID = vport->fc_myDID; |
| 7629 | /* Our DID needs to be updated before registering |
| 7630 | * the vfi. This is done in lpfc_rcv_plogi but |
| 7631 | * that is called after the reg_vfi. |
| 7632 | */ |
| 7633 | vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo; |
| 7634 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7635 | "3312 Remote port assigned DID x%x " |
| 7636 | "%x\n", vport->fc_myDID, |
| 7637 | vport->fc_prevDID); |
| 7638 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7639 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7640 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7641 | |
| 7642 | /* If Nport discovery is delayed, reject PLOGIs */ |
| 7643 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 7644 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7645 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7646 | break; |
| 7647 | } |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7648 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7649 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 7650 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 7651 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 7652 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7653 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 7654 | break; |
| 7655 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7656 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7657 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7658 | spin_lock_irq(shost->host_lock); |
| 7659 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 7660 | spin_unlock_irq(shost->host_lock); |
| 7661 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7662 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7663 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7664 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7665 | break; |
| 7666 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7667 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7668 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 7669 | did, vport->port_state, ndlp->nlp_flag); |
| 7670 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7671 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7672 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7673 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7674 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7675 | break; |
| 7676 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7677 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7678 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 7679 | did, vport->port_state, ndlp->nlp_flag); |
| 7680 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7681 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7682 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7683 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7684 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7685 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7686 | break; |
| 7687 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7688 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7689 | break; |
| 7690 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7691 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7692 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 7693 | did, vport->port_state, ndlp->nlp_flag); |
| 7694 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7695 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7696 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7697 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7698 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7699 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7700 | break; |
| 7701 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7702 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7703 | break; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 7704 | case ELS_CMD_LCB: |
| 7705 | phba->fc_stat.elsRcvLCB++; |
| 7706 | lpfc_els_rcv_lcb(vport, elsiocb, ndlp); |
| 7707 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 7708 | case ELS_CMD_RDP: |
| 7709 | phba->fc_stat.elsRcvRDP++; |
| 7710 | lpfc_els_rcv_rdp(vport, elsiocb, ndlp); |
| 7711 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7712 | case ELS_CMD_RSCN: |
| 7713 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7714 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7715 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7716 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7717 | break; |
| 7718 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7719 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7720 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 7721 | did, vport->port_state, ndlp->nlp_flag); |
| 7722 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7723 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7724 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7725 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7726 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7727 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7728 | break; |
| 7729 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7730 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7731 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7732 | break; |
| 7733 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7734 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7735 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 7736 | did, vport->port_state, ndlp->nlp_flag); |
| 7737 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7738 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7739 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7740 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7741 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7742 | break; |
| 7743 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7744 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7745 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7746 | break; |
| 7747 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7748 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7749 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 7750 | did, vport->port_state, ndlp->nlp_flag); |
| 7751 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7752 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7753 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7754 | break; |
| 7755 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7756 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7757 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 7758 | did, vport->port_state, ndlp->nlp_flag); |
| 7759 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7760 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7761 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7762 | break; |
| 7763 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7764 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7765 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 7766 | did, vport->port_state, ndlp->nlp_flag); |
| 7767 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7768 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7769 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7770 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7771 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7772 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7773 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 7774 | did, vport->port_state, ndlp->nlp_flag); |
| 7775 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7776 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7777 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7778 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7779 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7780 | break; |
| 7781 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7782 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7783 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7784 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7785 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7786 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 7787 | did, vport->port_state, ndlp->nlp_flag); |
| 7788 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7789 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7790 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7791 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7792 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7793 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7794 | case ELS_CMD_RLS: |
| 7795 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7796 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 7797 | did, vport->port_state, ndlp->nlp_flag); |
| 7798 | |
| 7799 | phba->fc_stat.elsRcvRLS++; |
| 7800 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 7801 | if (newnode) |
| 7802 | lpfc_nlp_put(ndlp); |
| 7803 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7804 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7805 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7806 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 7807 | did, vport->port_state, ndlp->nlp_flag); |
| 7808 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7809 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7810 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7811 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7812 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7813 | break; |
| 7814 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7815 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7816 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 7817 | did, vport->port_state, ndlp->nlp_flag); |
| 7818 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7819 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7820 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7821 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7822 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7823 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7824 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7825 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7826 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 7827 | did, vport->port_state, ndlp->nlp_flag); |
| 7828 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7829 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7830 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7831 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7832 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7833 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7834 | case ELS_CMD_RTV: |
| 7835 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7836 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 7837 | did, vport->port_state, ndlp->nlp_flag); |
| 7838 | phba->fc_stat.elsRcvRTV++; |
| 7839 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 7840 | if (newnode) |
| 7841 | lpfc_nlp_put(ndlp); |
| 7842 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7843 | case ELS_CMD_RRQ: |
| 7844 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7845 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 7846 | did, vport->port_state, ndlp->nlp_flag); |
| 7847 | |
| 7848 | phba->fc_stat.elsRcvRRQ++; |
| 7849 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 7850 | if (newnode) |
| 7851 | lpfc_nlp_put(ndlp); |
| 7852 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7853 | case ELS_CMD_ECHO: |
| 7854 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7855 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 7856 | did, vport->port_state, ndlp->nlp_flag); |
| 7857 | |
| 7858 | phba->fc_stat.elsRcvECHO++; |
| 7859 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 7860 | if (newnode) |
| 7861 | lpfc_nlp_put(ndlp); |
| 7862 | break; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7863 | case ELS_CMD_REC: |
| 7864 | /* receive this due to exchange closed */ |
| 7865 | rjt_err = LSRJT_UNABLE_TPC; |
| 7866 | rjt_exp = LSEXP_INVALID_OX_RX; |
| 7867 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7868 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7869 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7870 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 7871 | cmd, did, vport->port_state); |
| 7872 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7873 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7874 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7875 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7876 | |
| 7877 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7878 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7879 | "0115 Unknown ELS command x%x " |
| 7880 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7881 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7882 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7883 | break; |
| 7884 | } |
| 7885 | |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7886 | lsrjt: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7887 | /* check if need to LS_RJT received ELS cmd */ |
| 7888 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7889 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7890 | stat.un.b.lsRjtRsnCode = rjt_err; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7891 | stat.un.b.lsRjtRsnCodeExp = rjt_exp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7892 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 7893 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7894 | } |
| 7895 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7896 | lpfc_nlp_put(elsiocb->context1); |
| 7897 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7898 | return; |
| 7899 | |
| 7900 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7901 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7902 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7903 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7904 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7905 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7906 | phba->fc_stat.elsRcvDrop++; |
| 7907 | } |
| 7908 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7909 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7910 | * 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] | 7911 | * @phba: pointer to lpfc hba data structure. |
| 7912 | * @pring: pointer to a SLI ring. |
| 7913 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 7914 | * |
| 7915 | * This routine is used to process an unsolicited event received from a SLI |
| 7916 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 7917 | * associated with the unsolicited event is done by invoking the routine |
| 7918 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 7919 | * SLI ring on which the unsolicited event was received. |
| 7920 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7921 | void |
| 7922 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 7923 | struct lpfc_iocbq *elsiocb) |
| 7924 | { |
| 7925 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7926 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7927 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7928 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 7929 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7930 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7931 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7932 | elsiocb->context2 = NULL; |
| 7933 | elsiocb->context3 = NULL; |
| 7934 | |
| 7935 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 7936 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 7937 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 7938 | (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 7939 | IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7940 | phba->fc_stat.NoRcvBuf++; |
| 7941 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7942 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 7943 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7944 | return; |
| 7945 | } |
| 7946 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7947 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 7948 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 7949 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 7950 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 7951 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7952 | else |
| 7953 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7954 | icmd->unsli3.rcvsli3.vpi); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7955 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7956 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7957 | /* If there are no BDEs associated |
| 7958 | * with this IOCB, there is nothing to do. |
| 7959 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7960 | if (icmd->ulpBdeCount == 0) |
| 7961 | return; |
| 7962 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7963 | /* type of ELS cmd is first 32bit word |
| 7964 | * in packet |
| 7965 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7966 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7967 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7968 | } else { |
| 7969 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 7970 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7971 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 7972 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7973 | } |
| 7974 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7975 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 7976 | /* |
| 7977 | * The different unsolicited event handlers would tell us |
| 7978 | * if they are done with "mp" by setting context2 to NULL. |
| 7979 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7980 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7981 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 7982 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7983 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7984 | |
| 7985 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7986 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7987 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7988 | elsiocb->context2 = bdeBuf2; |
| 7989 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7990 | /* free mp if we are done with it */ |
| 7991 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7992 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 7993 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7994 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7995 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7996 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7997 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 7998 | static void |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7999 | lpfc_start_fdmi(struct lpfc_vport *vport) |
| 8000 | { |
| 8001 | struct lpfc_hba *phba = vport->phba; |
| 8002 | struct lpfc_nodelist *ndlp; |
| 8003 | |
| 8004 | /* If this is the first time, allocate an ndlp and initialize |
| 8005 | * it. Otherwise, make sure the node is enabled and then do the |
| 8006 | * login. |
| 8007 | */ |
| 8008 | ndlp = lpfc_findnode_did(vport, FDMI_DID); |
| 8009 | if (!ndlp) { |
| 8010 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 8011 | if (ndlp) { |
| 8012 | lpfc_nlp_init(vport, ndlp, FDMI_DID); |
| 8013 | ndlp->nlp_type |= NLP_FABRIC; |
| 8014 | } else { |
| 8015 | return; |
| 8016 | } |
| 8017 | } |
| 8018 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 8019 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 8020 | |
| 8021 | if (ndlp) { |
| 8022 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 8023 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| 8024 | } |
| 8025 | } |
| 8026 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8027 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8028 | * 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] | 8029 | * @phba: pointer to lpfc hba data structure. |
| 8030 | * @vport: pointer to a virtual N_Port data structure. |
| 8031 | * |
| 8032 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 8033 | * State Change Request (SCR) for a @vport. This routine will create an |
| 8034 | * ndlp for the Name Server associated to the @vport if such node does |
| 8035 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 8036 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 8037 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 8038 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 8039 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8040 | void |
| 8041 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 8042 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8043 | struct lpfc_nodelist *ndlp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8044 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8045 | |
| 8046 | /* |
| 8047 | * If lpfc_delay_discovery parameter is set and the clean address |
| 8048 | * bit is cleared and fc fabric parameters chenged, delay FC NPort |
| 8049 | * discovery. |
| 8050 | */ |
| 8051 | spin_lock_irq(shost->host_lock); |
| 8052 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 8053 | spin_unlock_irq(shost->host_lock); |
James Smart | 1877570 | 2013-04-17 20:19:25 -0400 | [diff] [blame] | 8054 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 8055 | "3334 Delay fc port discovery for %d seconds\n", |
| 8056 | phba->fc_ratov); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8057 | mod_timer(&vport->delayed_disc_tmo, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8058 | jiffies + msecs_to_jiffies(1000 * phba->fc_ratov)); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8059 | return; |
| 8060 | } |
| 8061 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8062 | |
| 8063 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 8064 | if (!ndlp) { |
| 8065 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 8066 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8067 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8068 | lpfc_disc_start(vport); |
| 8069 | return; |
| 8070 | } |
| 8071 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8072 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8073 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8074 | return; |
| 8075 | } |
| 8076 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8077 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 8078 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 8079 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8080 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8081 | lpfc_disc_start(vport); |
| 8082 | return; |
| 8083 | } |
| 8084 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 8085 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8086 | "0348 NameServer login: node freed\n"); |
| 8087 | return; |
| 8088 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8089 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8090 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8091 | |
| 8092 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 8093 | |
| 8094 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 8095 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8096 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8097 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8098 | return; |
| 8099 | } |
| 8100 | |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 8101 | if ((phba->cfg_enable_SmartSAN || |
| 8102 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) && |
| 8103 | (vport->load_flag & FC_ALLOW_FDMI)) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8104 | lpfc_start_fdmi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8105 | } |
| 8106 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8107 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8108 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8109 | * @phba: pointer to lpfc hba data structure. |
| 8110 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 8111 | * |
| 8112 | * This routine is the completion callback function to register new vport |
| 8113 | * mailbox command. If the new vport mailbox command completes successfully, |
| 8114 | * the fabric registration login shall be performed on physical port (the |
| 8115 | * new vport created is actually a physical port, with VPI 0) or the port |
| 8116 | * login to Name Server for State Change Request (SCR) will be performed |
| 8117 | * on virtual port (real virtual port, with VPI greater than 0). |
| 8118 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8119 | static void |
| 8120 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 8121 | { |
| 8122 | struct lpfc_vport *vport = pmb->vport; |
| 8123 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8124 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 8125 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8126 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8127 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8128 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8129 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8130 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8131 | |
| 8132 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8133 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8134 | "0915 Register VPI failed : Status: x%x" |
| 8135 | " upd bit: x%x \n", mb->mbxStatus, |
| 8136 | mb->un.varRegVpi.upd); |
| 8137 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 8138 | mb->un.varRegVpi.upd) |
| 8139 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8140 | |
| 8141 | switch (mb->mbxStatus) { |
| 8142 | case 0x11: /* unsupported feature */ |
| 8143 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8144 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8145 | /* giving up on vport registration */ |
| 8146 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 8147 | spin_lock_irq(shost->host_lock); |
| 8148 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 8149 | spin_unlock_irq(shost->host_lock); |
| 8150 | lpfc_can_disctmo(vport); |
| 8151 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8152 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 8153 | case 0x20: |
| 8154 | spin_lock_irq(shost->host_lock); |
| 8155 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 8156 | spin_unlock_irq(shost->host_lock); |
| 8157 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 8158 | pmb->vport = vport; |
| 8159 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 8160 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 8161 | MBX_NOWAIT); |
| 8162 | if (rc == MBX_NOT_FINISHED) { |
| 8163 | lpfc_printf_vlog(vport, |
| 8164 | KERN_ERR, LOG_MBOX, |
| 8165 | "2732 Failed to issue INIT_VPI" |
| 8166 | " mailbox command\n"); |
| 8167 | } else { |
| 8168 | lpfc_nlp_put(ndlp); |
| 8169 | return; |
| 8170 | } |
| 8171 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8172 | default: |
| 8173 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8174 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8175 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8176 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8177 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8178 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8179 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8180 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 8181 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8182 | lpfc_issue_init_vfi(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8183 | else |
| 8184 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8185 | break; |
| 8186 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8187 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8188 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 8189 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8190 | spin_unlock_irq(shost->host_lock); |
| 8191 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8192 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 8193 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8194 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 8195 | /* |
| 8196 | * If the physical port is instantiated using |
| 8197 | * FDISC, do not start vport discovery. |
| 8198 | */ |
| 8199 | if (vport->port_state != LPFC_FDISC) |
| 8200 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8201 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8202 | } |
| 8203 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8204 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8205 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8206 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8207 | /* Now, we decrement the ndlp reference count held for this |
| 8208 | * callback function |
| 8209 | */ |
| 8210 | lpfc_nlp_put(ndlp); |
| 8211 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8212 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8213 | return; |
| 8214 | } |
| 8215 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8216 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8217 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8218 | * @phba: pointer to lpfc hba data structure. |
| 8219 | * @vport: pointer to a host virtual N_Port data structure. |
| 8220 | * @ndlp: pointer to a node-list data structure. |
| 8221 | * |
| 8222 | * This routine registers the @vport as a new virtual port with a HBA. |
| 8223 | * It is done through a registering vpi mailbox command. |
| 8224 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8225 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8226 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 8227 | struct lpfc_nodelist *ndlp) |
| 8228 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8229 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8230 | LPFC_MBOXQ_t *mbox; |
| 8231 | |
| 8232 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8233 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8234 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8235 | mbox->vport = vport; |
| 8236 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 8237 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8238 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8239 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8240 | /* mailbox command not success, decrement ndlp |
| 8241 | * reference count for this command |
| 8242 | */ |
| 8243 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8244 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8245 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8246 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 8247 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8248 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8249 | } |
| 8250 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8251 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 8252 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8253 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8254 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8255 | return; |
| 8256 | |
| 8257 | mbox_err_exit: |
| 8258 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 8259 | spin_lock_irq(shost->host_lock); |
| 8260 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 8261 | spin_unlock_irq(shost->host_lock); |
| 8262 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8263 | } |
| 8264 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8265 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8266 | * 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] | 8267 | * @phba: pointer to lpfc hba data structure. |
| 8268 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8269 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8270 | **/ |
| 8271 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8272 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8273 | { |
| 8274 | struct lpfc_vport **vports; |
| 8275 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8276 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8277 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8278 | |
| 8279 | /* Treat this failure as linkdown for all vports */ |
| 8280 | link_state = phba->link_state; |
| 8281 | lpfc_linkdown(phba); |
| 8282 | phba->link_state = link_state; |
| 8283 | |
| 8284 | vports = lpfc_create_vport_work_array(phba); |
| 8285 | |
| 8286 | if (vports) { |
| 8287 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 8288 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 8289 | if (ndlp) |
| 8290 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 8291 | lpfc_els_flush_cmd(vports[i]); |
| 8292 | } |
| 8293 | lpfc_destroy_vport_work_array(phba, vports); |
| 8294 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8295 | } |
| 8296 | |
| 8297 | /** |
| 8298 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 8299 | * @phba: pointer to lpfc hba data structure. |
| 8300 | * |
| 8301 | * This routine abort all pending discovery commands and |
| 8302 | * start a timer to retry FLOGI for the physical port |
| 8303 | * discovery. |
| 8304 | **/ |
| 8305 | void |
| 8306 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 8307 | { |
| 8308 | struct lpfc_nodelist *ndlp; |
| 8309 | struct Scsi_Host *shost; |
| 8310 | |
| 8311 | /* Cancel the all vports retry delay retry timers */ |
| 8312 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8313 | |
| 8314 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 8315 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 8316 | if (!ndlp) |
| 8317 | return; |
| 8318 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8319 | shost = lpfc_shost_from_vport(phba->pport); |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8320 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000)); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8321 | spin_lock_irq(shost->host_lock); |
| 8322 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 8323 | spin_unlock_irq(shost->host_lock); |
| 8324 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 8325 | phba->pport->port_state = LPFC_FLOGI; |
| 8326 | return; |
| 8327 | } |
| 8328 | |
| 8329 | /** |
| 8330 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 8331 | * @phba: pointer to lpfc hba data structure. |
| 8332 | * @cmdiocb: pointer to FDISC command iocb. |
| 8333 | * @rspiocb: pointer to FDISC response iocb. |
| 8334 | * |
| 8335 | * This routine checks if a FLOGI is reguired for FDISC |
| 8336 | * to succeed. |
| 8337 | **/ |
| 8338 | static int |
| 8339 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 8340 | struct lpfc_iocbq *cmdiocb, |
| 8341 | struct lpfc_iocbq *rspiocb) |
| 8342 | { |
| 8343 | |
| 8344 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 8345 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 8346 | return 0; |
| 8347 | else |
| 8348 | return 1; |
| 8349 | } |
| 8350 | |
| 8351 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8352 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8353 | * @phba: pointer to lpfc hba data structure. |
| 8354 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8355 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8356 | * |
| 8357 | * This routine is the completion callback function to a Fabric Discover |
| 8358 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 8359 | * single threaded, each FDISC completion callback function will reset |
| 8360 | * the discovery timer for all vports such that the timers will not get |
| 8361 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 8362 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 8363 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 8364 | * assigned to the vport has been changed with the completion of the FDISC |
| 8365 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 8366 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 8367 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 8368 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 8369 | * Server for State Change Request (SCR). |
| 8370 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8371 | static void |
| 8372 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8373 | struct lpfc_iocbq *rspiocb) |
| 8374 | { |
| 8375 | struct lpfc_vport *vport = cmdiocb->vport; |
| 8376 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8377 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 8378 | struct lpfc_nodelist *np; |
| 8379 | struct lpfc_nodelist *next_np; |
| 8380 | IOCB_t *irsp = &rspiocb->iocb; |
| 8381 | struct lpfc_iocbq *piocb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8382 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 8383 | struct serv_parm *sp; |
| 8384 | uint8_t fabric_param_changed; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8385 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8386 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8387 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 8388 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 8389 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8390 | /* Since all FDISCs are being single threaded, we |
| 8391 | * must reset the discovery timer for ALL vports |
| 8392 | * waiting to send FDISC when one completes. |
| 8393 | */ |
| 8394 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 8395 | lpfc_set_disctmo(piocb->vport); |
| 8396 | } |
| 8397 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8398 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8399 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 8400 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 8401 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8402 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8403 | |
| 8404 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 8405 | lpfc_retry_pport_discovery(phba); |
| 8406 | goto out; |
| 8407 | } |
| 8408 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8409 | /* Check for retry */ |
| 8410 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 8411 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8412 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8413 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8414 | "0126 FDISC failed. (x%x/x%x)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8415 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8416 | goto fdisc_failed; |
| 8417 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8418 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8419 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8420 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8421 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8422 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8423 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 8424 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8425 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8426 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 8427 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8428 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 8429 | if (!prsp) |
| 8430 | goto out; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8431 | sp = prsp->virt + sizeof(uint32_t); |
| 8432 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 8433 | memcpy(&vport->fabric_portname, &sp->portName, |
| 8434 | sizeof(struct lpfc_name)); |
| 8435 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 8436 | sizeof(struct lpfc_name)); |
| 8437 | if (fabric_param_changed && |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8438 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 8439 | /* If our NportID changed, we need to ensure all |
| 8440 | * remaining NPORTs get unreg_login'ed so we can |
| 8441 | * issue unreg_vpi. |
| 8442 | */ |
| 8443 | list_for_each_entry_safe(np, next_np, |
| 8444 | &vport->fc_nodes, nlp_listp) { |
| 8445 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 8446 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 8447 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 8448 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8449 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8450 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8451 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8452 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8453 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 8454 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8455 | |
| 8456 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8457 | lpfc_sli4_unreg_all_rpis(vport); |
| 8458 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8459 | lpfc_mbx_unreg_vpi(vport); |
| 8460 | spin_lock_irq(shost->host_lock); |
| 8461 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8462 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8463 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8464 | else |
| 8465 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8466 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8467 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 8468 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 8469 | /* |
| 8470 | * Driver needs to re-reg VPI in order for f/w |
| 8471 | * to update the MAC address. |
| 8472 | */ |
| 8473 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 8474 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8475 | } |
| 8476 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 8477 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 8478 | lpfc_issue_init_vpi(vport); |
| 8479 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8480 | lpfc_register_new_vport(phba, vport, ndlp); |
| 8481 | else |
| 8482 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8483 | goto out; |
| 8484 | fdisc_failed: |
James Smart | c84163d | 2015-05-21 13:55:22 -0400 | [diff] [blame] | 8485 | if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS) |
| 8486 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8487 | /* Cancel discovery timer */ |
| 8488 | lpfc_can_disctmo(vport); |
| 8489 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8490 | out: |
| 8491 | lpfc_els_free_iocb(phba, cmdiocb); |
| 8492 | } |
| 8493 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8494 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8495 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8496 | * @vport: pointer to a virtual N_Port data structure. |
| 8497 | * @ndlp: pointer to a node-list data structure. |
| 8498 | * @retry: number of retries to the command IOCB. |
| 8499 | * |
| 8500 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 8501 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 8502 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 8503 | * IOCB will be sent off HBA at any given time. |
| 8504 | * |
| 8505 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 8506 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 8507 | * will be stored into the context1 field of the IOCB for the completion |
| 8508 | * callback function to the FDISC ELS command. |
| 8509 | * |
| 8510 | * Return code |
| 8511 | * 0 - Successfully issued fdisc iocb command |
| 8512 | * 1 - Failed to issue fdisc iocb command |
| 8513 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8514 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8515 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 8516 | uint8_t retry) |
| 8517 | { |
| 8518 | struct lpfc_hba *phba = vport->phba; |
| 8519 | IOCB_t *icmd; |
| 8520 | struct lpfc_iocbq *elsiocb; |
| 8521 | struct serv_parm *sp; |
| 8522 | uint8_t *pcmd; |
| 8523 | uint16_t cmdsize; |
| 8524 | int did = ndlp->nlp_DID; |
| 8525 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8526 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8527 | vport->port_state = LPFC_FDISC; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8528 | vport->fc_myDID = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8529 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 8530 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 8531 | ELS_CMD_FDISC); |
| 8532 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8533 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8534 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8535 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8536 | return 1; |
| 8537 | } |
| 8538 | |
| 8539 | icmd = &elsiocb->iocb; |
| 8540 | icmd->un.elsreq64.myID = 0; |
| 8541 | icmd->un.elsreq64.fl = 1; |
| 8542 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 8543 | /* |
| 8544 | * SLI3 ports require a different context type value than SLI4. |
| 8545 | * Catch SLI3 ports here and override the prep. |
| 8546 | */ |
| 8547 | if (phba->sli_rev == LPFC_SLI_REV3) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8548 | icmd->ulpCt_h = 1; |
| 8549 | icmd->ulpCt_l = 0; |
| 8550 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8551 | |
| 8552 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 8553 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 8554 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 8555 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 8556 | sp = (struct serv_parm *) pcmd; |
| 8557 | /* Setup CSPs accordingly for Fabric */ |
| 8558 | sp->cmn.e_d_tov = 0; |
| 8559 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 8560 | sp->cmn.virtual_fabric_support = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8561 | sp->cls1.classValid = 0; |
| 8562 | sp->cls2.seqDelivery = 1; |
| 8563 | sp->cls3.seqDelivery = 1; |
| 8564 | |
| 8565 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 8566 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 8567 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 8568 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 8569 | memcpy(pcmd, &vport->fc_portname, 8); |
| 8570 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 8571 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 8572 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 8573 | |
| 8574 | lpfc_set_disctmo(vport); |
| 8575 | |
| 8576 | phba->fc_stat.elsXmitFDISC++; |
| 8577 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 8578 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8579 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8580 | "Issue FDISC: did:x%x", |
| 8581 | did, 0, 0); |
| 8582 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8583 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 8584 | if (rc == IOCB_ERROR) { |
| 8585 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8586 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8587 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8588 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8589 | return 1; |
| 8590 | } |
| 8591 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8592 | return 0; |
| 8593 | } |
| 8594 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8595 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8596 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8597 | * @phba: pointer to lpfc hba data structure. |
| 8598 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8599 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8600 | * |
| 8601 | * This routine is the completion callback function to the issuing of a LOGO |
| 8602 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 8603 | * reference count held on ndlp for this completion function, indicating that |
| 8604 | * the reference to the ndlp is no long needed. Note that the |
| 8605 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 8606 | * callback function and an additional explicit ndlp reference decrementation |
| 8607 | * will trigger the actual release of the ndlp. |
| 8608 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8609 | static void |
| 8610 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8611 | struct lpfc_iocbq *rspiocb) |
| 8612 | { |
| 8613 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8614 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8615 | struct lpfc_nodelist *ndlp; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8616 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8617 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8618 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8619 | irsp = &rspiocb->iocb; |
| 8620 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8621 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 8622 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8623 | |
| 8624 | lpfc_els_free_iocb(phba, cmdiocb); |
| 8625 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8626 | |
| 8627 | /* Trigger the release of the ndlp after logo */ |
| 8628 | lpfc_nlp_put(ndlp); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8629 | |
| 8630 | /* NPIV LOGO completes to NPort <nlp_DID> */ |
| 8631 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8632 | "2928 NPIV LOGO completes to NPort x%x " |
| 8633 | "Data: x%x x%x x%x x%x\n", |
| 8634 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 8635 | irsp->ulpTimeout, vport->num_disc_nodes); |
| 8636 | |
| 8637 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 8638 | spin_lock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 8639 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8640 | vport->fc_flag &= ~FC_FABRIC; |
| 8641 | spin_unlock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 8642 | lpfc_can_disctmo(vport); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8643 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8644 | } |
| 8645 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8646 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8647 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8648 | * @vport: pointer to a virtual N_Port data structure. |
| 8649 | * @ndlp: pointer to a node-list data structure. |
| 8650 | * |
| 8651 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 8652 | * |
| 8653 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 8654 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 8655 | * will be stored into the context1 field of the IOCB for the completion |
| 8656 | * callback function to the LOGO ELS command. |
| 8657 | * |
| 8658 | * Return codes |
| 8659 | * 0 - Successfully issued logo off the @vport |
| 8660 | * 1 - Failed to issue logo off the @vport |
| 8661 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8662 | int |
| 8663 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 8664 | { |
| 8665 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8666 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8667 | struct lpfc_iocbq *elsiocb; |
| 8668 | uint8_t *pcmd; |
| 8669 | uint16_t cmdsize; |
| 8670 | |
| 8671 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 8672 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 8673 | ELS_CMD_LOGO); |
| 8674 | if (!elsiocb) |
| 8675 | return 1; |
| 8676 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8677 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 8678 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 8679 | pcmd += sizeof(uint32_t); |
| 8680 | |
| 8681 | /* Fill in LOGO payload */ |
| 8682 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 8683 | pcmd += sizeof(uint32_t); |
| 8684 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 8685 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8686 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8687 | "Issue LOGO npiv did:x%x flg:x%x", |
| 8688 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 8689 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8690 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 8691 | spin_lock_irq(shost->host_lock); |
| 8692 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 8693 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8694 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 8695 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8696 | spin_lock_irq(shost->host_lock); |
| 8697 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 8698 | spin_unlock_irq(shost->host_lock); |
| 8699 | lpfc_els_free_iocb(phba, elsiocb); |
| 8700 | return 1; |
| 8701 | } |
| 8702 | return 0; |
| 8703 | } |
| 8704 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8705 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8706 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8707 | * @ptr: holder for the timer function associated data. |
| 8708 | * |
| 8709 | * This routine is invoked by the fabric iocb block timer after |
| 8710 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 8711 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 8712 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 8713 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 8714 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 8715 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8716 | void |
| 8717 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 8718 | { |
| 8719 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 8720 | unsigned long iflags; |
| 8721 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8722 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8723 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 8724 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 8725 | if (!tmo_posted) |
| 8726 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 8727 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 8728 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8729 | if (!tmo_posted) |
| 8730 | lpfc_worker_wake_up(phba); |
| 8731 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8732 | } |
| 8733 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8734 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8735 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8736 | * @phba: pointer to lpfc hba data structure. |
| 8737 | * |
| 8738 | * This routine issues one fabric iocb from the driver internal list to |
| 8739 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 8740 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 8741 | * remove one pending fabric iocb from the driver internal list and invokes |
| 8742 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 8743 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8744 | static void |
| 8745 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 8746 | { |
| 8747 | struct lpfc_iocbq *iocb; |
| 8748 | unsigned long iflags; |
| 8749 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8750 | IOCB_t *cmd; |
| 8751 | |
| 8752 | repeat: |
| 8753 | iocb = NULL; |
| 8754 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8755 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8756 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 8757 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 8758 | list); |
| 8759 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8760 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8761 | atomic_inc(&phba->fabric_iocb_count); |
| 8762 | } |
| 8763 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8764 | if (iocb) { |
| 8765 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 8766 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 8767 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 8768 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8769 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 8770 | "Fabric sched1: ste:x%x", |
| 8771 | iocb->vport->port_state, 0, 0); |
| 8772 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8773 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8774 | |
| 8775 | if (ret == IOCB_ERROR) { |
| 8776 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 8777 | iocb->fabric_iocb_cmpl = NULL; |
| 8778 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 8779 | cmd = &iocb->iocb; |
| 8780 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 8781 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 8782 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 8783 | |
| 8784 | atomic_dec(&phba->fabric_iocb_count); |
| 8785 | goto repeat; |
| 8786 | } |
| 8787 | } |
| 8788 | |
| 8789 | return; |
| 8790 | } |
| 8791 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8792 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8793 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8794 | * @phba: pointer to lpfc hba data structure. |
| 8795 | * |
| 8796 | * This routine unblocks the issuing fabric iocb command. The function |
| 8797 | * will clear the fabric iocb block bit and then invoke the routine |
| 8798 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 8799 | * from the driver internal fabric iocb list. |
| 8800 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8801 | void |
| 8802 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 8803 | { |
| 8804 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 8805 | |
| 8806 | lpfc_resume_fabric_iocbs(phba); |
| 8807 | return; |
| 8808 | } |
| 8809 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8810 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8811 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8812 | * @phba: pointer to lpfc hba data structure. |
| 8813 | * |
| 8814 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 8815 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 8816 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 8817 | * fabric iocb will be issued out of the HBA. |
| 8818 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8819 | static void |
| 8820 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 8821 | { |
| 8822 | int blocked; |
| 8823 | |
| 8824 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8825 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8826 | if (!blocked) |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8827 | mod_timer(&phba->fabric_block_timer, |
| 8828 | jiffies + msecs_to_jiffies(100)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8829 | |
| 8830 | return; |
| 8831 | } |
| 8832 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8833 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8834 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8835 | * @phba: pointer to lpfc hba data structure. |
| 8836 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8837 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8838 | * |
| 8839 | * This routine is the callback function that is put to the fabric iocb's |
| 8840 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 8841 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 8842 | * function first restores and invokes the original iocb's callback function |
| 8843 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 8844 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 8845 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8846 | static void |
| 8847 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8848 | struct lpfc_iocbq *rspiocb) |
| 8849 | { |
| 8850 | struct ls_rjt stat; |
| 8851 | |
| 8852 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 8853 | BUG(); |
| 8854 | |
| 8855 | switch (rspiocb->iocb.ulpStatus) { |
| 8856 | case IOSTAT_NPORT_RJT: |
| 8857 | case IOSTAT_FABRIC_RJT: |
| 8858 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 8859 | lpfc_block_fabric_iocbs(phba); |
| 8860 | } |
| 8861 | break; |
| 8862 | |
| 8863 | case IOSTAT_NPORT_BSY: |
| 8864 | case IOSTAT_FABRIC_BSY: |
| 8865 | lpfc_block_fabric_iocbs(phba); |
| 8866 | break; |
| 8867 | |
| 8868 | case IOSTAT_LS_RJT: |
| 8869 | stat.un.lsRjtError = |
| 8870 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 8871 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 8872 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 8873 | lpfc_block_fabric_iocbs(phba); |
| 8874 | break; |
| 8875 | } |
| 8876 | |
| 8877 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 8878 | BUG(); |
| 8879 | |
| 8880 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 8881 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 8882 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 8883 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 8884 | |
| 8885 | atomic_dec(&phba->fabric_iocb_count); |
| 8886 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8887 | /* Post any pending iocbs to HBA */ |
| 8888 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8889 | } |
| 8890 | } |
| 8891 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8892 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8893 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8894 | * @phba: pointer to lpfc hba data structure. |
| 8895 | * @iocb: pointer to lpfc command iocb data structure. |
| 8896 | * |
| 8897 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 8898 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 8899 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 8900 | * any given time. As such, this function will first check to see whether there |
| 8901 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 8902 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 8903 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 8904 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 8905 | * |
| 8906 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 8907 | * order. The problem is caused by the construction of the "ready" boolen does |
| 8908 | * not include the condition that the internal fabric IOCB list is empty. As |
| 8909 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 8910 | * ahead of the fabric IOCBs in the internal list. |
| 8911 | * |
| 8912 | * Return code |
| 8913 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 8914 | * IOCB_ERROR - failed to issue fabric iocb |
| 8915 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8916 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8917 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 8918 | { |
| 8919 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8920 | int ready; |
| 8921 | int ret; |
| 8922 | |
| 8923 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 8924 | BUG(); |
| 8925 | |
| 8926 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8927 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 8928 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 8929 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8930 | if (ready) |
| 8931 | /* Increment fabric iocb count to hold the position */ |
| 8932 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8933 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8934 | if (ready) { |
| 8935 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 8936 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 8937 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 8938 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8939 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 8940 | "Fabric sched2: ste:x%x", |
| 8941 | iocb->vport->port_state, 0, 0); |
| 8942 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8943 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8944 | |
| 8945 | if (ret == IOCB_ERROR) { |
| 8946 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 8947 | iocb->fabric_iocb_cmpl = NULL; |
| 8948 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 8949 | atomic_dec(&phba->fabric_iocb_count); |
| 8950 | } |
| 8951 | } else { |
| 8952 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8953 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 8954 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8955 | ret = IOCB_SUCCESS; |
| 8956 | } |
| 8957 | return ret; |
| 8958 | } |
| 8959 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8960 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8961 | * 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] | 8962 | * @vport: pointer to a virtual N_Port data structure. |
| 8963 | * |
| 8964 | * This routine aborts all the IOCBs associated with a @vport from the |
| 8965 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 8966 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 8967 | * list, removes each IOCB associated with the @vport off the list, set the |
| 8968 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 8969 | * associated with the IOCB. |
| 8970 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8971 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8972 | { |
| 8973 | LIST_HEAD(completions); |
| 8974 | struct lpfc_hba *phba = vport->phba; |
| 8975 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8976 | |
| 8977 | spin_lock_irq(&phba->hbalock); |
| 8978 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 8979 | list) { |
| 8980 | |
| 8981 | if (piocb->vport != vport) |
| 8982 | continue; |
| 8983 | |
| 8984 | list_move_tail(&piocb->list, &completions); |
| 8985 | } |
| 8986 | spin_unlock_irq(&phba->hbalock); |
| 8987 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8988 | /* Cancel all the IOCBs from the completions list */ |
| 8989 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8990 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8991 | } |
| 8992 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8993 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8994 | * 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] | 8995 | * @ndlp: pointer to a node-list data structure. |
| 8996 | * |
| 8997 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 8998 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 8999 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 9000 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 9001 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 9002 | * associated with the IOCB. |
| 9003 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9004 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 9005 | { |
| 9006 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9007 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9008 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 9009 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9010 | |
| 9011 | spin_lock_irq(&phba->hbalock); |
| 9012 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 9013 | list) { |
| 9014 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 9015 | |
| 9016 | list_move_tail(&piocb->list, &completions); |
| 9017 | } |
| 9018 | } |
| 9019 | spin_unlock_irq(&phba->hbalock); |
| 9020 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9021 | /* Cancel all the IOCBs from the completions list */ |
| 9022 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9023 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9024 | } |
| 9025 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9026 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9027 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9028 | * @phba: pointer to lpfc hba data structure. |
| 9029 | * |
| 9030 | * This routine aborts all the IOCBs currently on the driver internal |
| 9031 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 9032 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 9033 | * list, removes IOCBs off the list, set the status feild to |
| 9034 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 9035 | * the IOCB. |
| 9036 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9037 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 9038 | { |
| 9039 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9040 | |
| 9041 | spin_lock_irq(&phba->hbalock); |
| 9042 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 9043 | spin_unlock_irq(&phba->hbalock); |
| 9044 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9045 | /* Cancel all the IOCBs from the completions list */ |
| 9046 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9047 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9048 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9049 | |
| 9050 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 9051 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport |
| 9052 | * @vport: pointer to lpfc vport data structure. |
| 9053 | * |
| 9054 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 9055 | * for an ndlp on removal. |
| 9056 | **/ |
| 9057 | void |
| 9058 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) |
| 9059 | { |
| 9060 | struct lpfc_hba *phba = vport->phba; |
| 9061 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 9062 | unsigned long iflag = 0; |
| 9063 | |
| 9064 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 9065 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
| 9066 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 9067 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 9068 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) |
| 9069 | sglq_entry->ndlp = NULL; |
| 9070 | } |
| 9071 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 9072 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9073 | return; |
| 9074 | } |
| 9075 | |
| 9076 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9077 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 9078 | * @phba: pointer to lpfc hba data structure. |
| 9079 | * @axri: pointer to the els xri abort wcqe structure. |
| 9080 | * |
| 9081 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 9082 | * ELS aborted xri. |
| 9083 | **/ |
| 9084 | void |
| 9085 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 9086 | struct sli4_wcqe_xri_aborted *axri) |
| 9087 | { |
| 9088 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9089 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9090 | uint16_t lxri = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9091 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9092 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 9093 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9094 | struct lpfc_nodelist *ndlp; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 9095 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9096 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9097 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 9098 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9099 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 9100 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 9101 | if (sglq_entry->sli4_xritag == xri) { |
| 9102 | list_del(&sglq_entry->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9103 | ndlp = sglq_entry->ndlp; |
| 9104 | sglq_entry->ndlp = NULL; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 9105 | spin_lock(&pring->ring_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9106 | list_add_tail(&sglq_entry->list, |
| 9107 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9108 | sglq_entry->state = SGL_FREED; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 9109 | spin_unlock(&pring->ring_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9110 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9111 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 9112 | lpfc_set_rrq_active(phba, ndlp, |
| 9113 | sglq_entry->sli4_lxritag, |
| 9114 | rxid, 1); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 9115 | |
| 9116 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9117 | if (!(list_empty(&pring->txq))) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 9118 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9119 | return; |
| 9120 | } |
| 9121 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9122 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9123 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 9124 | if (lxri == NO_XRI) { |
| 9125 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9126 | return; |
| 9127 | } |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 9128 | spin_lock(&pring->ring_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9129 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9130 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 9131 | spin_unlock(&pring->ring_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9132 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9133 | return; |
| 9134 | } |
| 9135 | sglq_entry->state = SGL_XRI_ABORTED; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 9136 | spin_unlock(&pring->ring_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9137 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9138 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9139 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 9140 | |
| 9141 | /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. |
| 9142 | * @vport: pointer to virtual port object. |
| 9143 | * @ndlp: nodelist pointer for the impacted node. |
| 9144 | * |
| 9145 | * The driver calls this routine in response to an SLI4 XRI ABORT CQE |
| 9146 | * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, |
| 9147 | * the driver is required to send a LOGO to the remote node before it |
| 9148 | * attempts to recover its login to the remote node. |
| 9149 | */ |
| 9150 | void |
| 9151 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 9152 | struct lpfc_nodelist *ndlp) |
| 9153 | { |
| 9154 | struct Scsi_Host *shost; |
| 9155 | struct lpfc_hba *phba; |
| 9156 | unsigned long flags = 0; |
| 9157 | |
| 9158 | shost = lpfc_shost_from_vport(vport); |
| 9159 | phba = vport->phba; |
| 9160 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 9161 | lpfc_printf_log(phba, KERN_INFO, |
| 9162 | LOG_SLI, "3093 No rport recovery needed. " |
| 9163 | "rport in state 0x%x\n", ndlp->nlp_state); |
| 9164 | return; |
| 9165 | } |
| 9166 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9167 | "3094 Start rport recovery on shost id 0x%x " |
| 9168 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 9169 | "flags 0x%x\n", |
| 9170 | shost->host_no, ndlp->nlp_DID, |
| 9171 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 9172 | ndlp->nlp_flag); |
| 9173 | /* |
| 9174 | * The rport is not responding. Remove the FCP-2 flag to prevent |
| 9175 | * an ADISC in the follow-up recovery code. |
| 9176 | */ |
| 9177 | spin_lock_irqsave(shost->host_lock, flags); |
| 9178 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 9179 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 9180 | lpfc_issue_els_logo(vport, ndlp, 0); |
| 9181 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
| 9182 | } |
| 9183 | |