| 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 | { |
| 597 | uint8_t fabric_param_changed = 0; |
| 598 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 599 | |
| 600 | if ((vport->fc_prevDID != vport->fc_myDID) || |
| 601 | memcmp(&vport->fabric_portname, &sp->portName, |
| 602 | sizeof(struct lpfc_name)) || |
| 603 | memcmp(&vport->fabric_nodename, &sp->nodeName, |
| 604 | sizeof(struct lpfc_name))) |
| 605 | fabric_param_changed = 1; |
| 606 | |
| 607 | /* |
| 608 | * Word 1 Bit 31 in common service parameter is overloaded. |
| 609 | * Word 1 Bit 31 in FLOGI request is multiple NPort request |
| 610 | * Word 1 Bit 31 in FLOGI response is clean address bit |
| 611 | * |
| 612 | * If fabric parameter is changed and clean address bit is |
| 613 | * cleared delay nport discovery if |
| 614 | * - vport->fc_prevDID != 0 (not initial discovery) OR |
| 615 | * - lpfc_delay_discovery module parameter is set. |
| 616 | */ |
| 617 | if (fabric_param_changed && !sp->cmn.clean_address_bit && |
| 618 | (vport->fc_prevDID || lpfc_delay_discovery)) { |
| 619 | spin_lock_irq(shost->host_lock); |
| 620 | vport->fc_flag |= FC_DISC_DELAYED; |
| 621 | spin_unlock_irq(shost->host_lock); |
| 622 | } |
| 623 | |
| 624 | return fabric_param_changed; |
| 625 | } |
| 626 | |
| 627 | |
| 628 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 629 | * 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] | 630 | * @vport: pointer to a host virtual N_Port data structure. |
| 631 | * @ndlp: pointer to a node-list data structure. |
| 632 | * @sp: pointer to service parameter data structure. |
| 633 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 634 | * |
| 635 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 636 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 637 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 638 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 639 | * @vport against the previously assigned N_Port ID. If it is different from |
| 640 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 641 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 642 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 643 | * is invoked to register login to the fabric. |
| 644 | * |
| 645 | * Return code |
| 646 | * 0 - Success (currently, always return 0) |
| 647 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 648 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 649 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 650 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 651 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 652 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 653 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 654 | struct lpfc_nodelist *np; |
| 655 | struct lpfc_nodelist *next_np; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 656 | uint8_t fabric_param_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 657 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 658 | spin_lock_irq(shost->host_lock); |
| 659 | vport->fc_flag |= FC_FABRIC; |
| 660 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 661 | |
| 662 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 663 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 664 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 665 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 666 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 667 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 668 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 669 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 670 | spin_lock_irq(shost->host_lock); |
| 671 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 672 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 673 | } |
| 674 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 675 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 676 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 677 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 678 | ndlp->nlp_class_sup = 0; |
| 679 | if (sp->cls1.classValid) |
| 680 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 681 | if (sp->cls2.classValid) |
| 682 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 683 | if (sp->cls3.classValid) |
| 684 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 685 | if (sp->cls4.classValid) |
| 686 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 687 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 688 | sp->cmn.bbRcvSizeLsb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 689 | |
| 690 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 691 | if (fabric_param_changed) { |
| 692 | /* Reset FDMI attribute masks based on config parameter */ |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 693 | if (phba->cfg_enable_SmartSAN || |
| 694 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 695 | /* Setup appropriate attribute masks */ |
| 696 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 697 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 698 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 699 | else |
| 700 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 701 | } else { |
| 702 | vport->fdmi_hba_mask = 0; |
| 703 | vport->fdmi_port_mask = 0; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | } |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 707 | memcpy(&vport->fabric_portname, &sp->portName, |
| 708 | sizeof(struct lpfc_name)); |
| 709 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 710 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 711 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 712 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 713 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 714 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 715 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 716 | LOG_ELS | LOG_VPORT, |
| 717 | "1816 FLOGI NPIV supported, " |
| 718 | "response data 0x%x\n", |
| 719 | sp->cmn.response_multiple_NPort); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 720 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 721 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 722 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 723 | } else { |
| 724 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 725 | to call reg_vnpid atleast for the physcial host */ |
| 726 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 727 | LOG_ELS | LOG_VPORT, |
| 728 | "1817 Fabric does not support NPIV " |
| 729 | "- configuring single port mode.\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 730 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 731 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 732 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 736 | /* |
| 737 | * For FC we need to do some special processing because of the SLI |
| 738 | * Port's default settings of the Common Service Parameters. |
| 739 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 740 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 741 | (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) { |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 742 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 743 | if (fabric_param_changed) |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 744 | lpfc_unregister_fcf_prep(phba); |
| 745 | |
| 746 | /* This should just update the VFI CSPs*/ |
| 747 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 748 | lpfc_issue_reg_vfi(vport); |
| 749 | } |
| 750 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 751 | if (fabric_param_changed && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 752 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 753 | |
| 754 | /* If our NportID changed, we need to ensure all |
| 755 | * remaining NPORTs get unreg_login'ed. |
| 756 | */ |
| 757 | list_for_each_entry_safe(np, next_np, |
| 758 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 759 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 760 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 761 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 762 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 763 | continue; |
| 764 | spin_lock_irq(shost->host_lock); |
| 765 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 766 | spin_unlock_irq(shost->host_lock); |
| 767 | lpfc_unreg_rpi(vport, np); |
| 768 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 769 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 770 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 771 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 772 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 773 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 774 | spin_lock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 775 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 776 | spin_unlock_irq(shost->host_lock); |
| 777 | } |
James Smart | 27aa1b7 | 2012-05-09 21:18:49 -0400 | [diff] [blame] | 778 | |
| 779 | /* |
| 780 | * For SLI3 and SLI4, the VPI needs to be reregistered in |
| 781 | * response to this fabric parameter change event. |
| 782 | */ |
| 783 | spin_lock_irq(shost->host_lock); |
| 784 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 785 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 786 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 787 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 788 | /* |
| 789 | * Driver needs to re-reg VPI in order for f/w |
| 790 | * to update the MAC address. |
| 791 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 792 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 793 | lpfc_register_new_vport(phba, vport, ndlp); |
| 794 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 795 | } |
| 796 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 797 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 798 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 799 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 800 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 801 | lpfc_register_new_vport(phba, vport, ndlp); |
| 802 | else |
| 803 | lpfc_issue_fabric_reglogin(vport); |
| 804 | } else { |
| 805 | ndlp->nlp_type |= NLP_FABRIC; |
| 806 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 807 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 808 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 809 | lpfc_start_fdiscs(phba); |
| 810 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 811 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 812 | lpfc_issue_init_vpi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 813 | else { |
| 814 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 815 | "3135 Need register VFI: (x%x/%x)\n", |
| 816 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 817 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 818 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 819 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 820 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 821 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 822 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 823 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 824 | * 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] | 825 | * @vport: pointer to a host virtual N_Port data structure. |
| 826 | * @ndlp: pointer to a node-list data structure. |
| 827 | * @sp: pointer to service parameter data structure. |
| 828 | * |
| 829 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 830 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 831 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 832 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 833 | * the received N_Port Name lexicographically, this node shall assign local |
| 834 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 835 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 836 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 837 | * N_Port IDs. |
| 838 | * |
| 839 | * Return code |
| 840 | * 0 - Success |
| 841 | * -ENXIO - Fail |
| 842 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 843 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 844 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 845 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 846 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 847 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 848 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 849 | LPFC_MBOXQ_t *mbox; |
| 850 | int rc; |
| 851 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 852 | spin_lock_irq(shost->host_lock); |
| 853 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 854 | vport->fc_flag |= FC_PT2PT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 855 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 856 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 857 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
| 858 | if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) { |
| 859 | lpfc_unregister_fcf_prep(phba); |
| 860 | |
| 861 | spin_lock_irq(shost->host_lock); |
| 862 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 863 | spin_unlock_irq(shost->host_lock); |
| 864 | phba->fc_topology_changed = 0; |
| 865 | } |
| 866 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 867 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 868 | sizeof(vport->fc_portname)); |
James Smart | 2eb6862 | 2012-09-29 11:32:27 -0400 | [diff] [blame] | 869 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 870 | if (rc >= 0) { |
| 871 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 872 | spin_lock_irq(shost->host_lock); |
| 873 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 874 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 875 | |
| 876 | /* |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 877 | * N_Port ID cannot be 0, set our Id to LocalID |
| 878 | * the other side will be RemoteID. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 879 | */ |
| 880 | |
| 881 | /* not equal */ |
| 882 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 883 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 884 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 885 | /* Decrement ndlp reference count indicating that ndlp can be |
| 886 | * safely released when other references to it are done. |
| 887 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 888 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 889 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 890 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 891 | if (!ndlp) { |
| 892 | /* |
| 893 | * Cannot find existing Fabric ndlp, so allocate a |
| 894 | * new one |
| 895 | */ |
| 896 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 897 | if (!ndlp) |
| 898 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 899 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 900 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 901 | ndlp = lpfc_enable_node(vport, ndlp, |
| 902 | NLP_STE_UNUSED_NODE); |
| 903 | if(!ndlp) |
| 904 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 908 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 909 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 910 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 911 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 912 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 913 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 914 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 915 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 916 | } else |
| 917 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 918 | * count indicating that ndlp can be released when other |
| 919 | * references to it are done. |
| 920 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 921 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 922 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 923 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 924 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 925 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 926 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 927 | if (!mbox) |
| 928 | goto fail; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 929 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 930 | lpfc_config_link(phba, mbox); |
| 931 | |
| 932 | mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
| 933 | mbox->vport = vport; |
| 934 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 935 | if (rc == MBX_NOT_FINISHED) { |
| 936 | mempool_free(mbox, phba->mbox_mem_pool); |
| 937 | goto fail; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 938 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 939 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 940 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 941 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 942 | return -ENXIO; |
| 943 | } |
| 944 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 945 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 946 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 947 | * @phba: pointer to lpfc hba data structure. |
| 948 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 949 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 950 | * |
| 951 | * This routine is the top-level completion callback function for issuing |
| 952 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 953 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 954 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 955 | * returning 1), the command IOCB will be released and function returned. |
| 956 | * If the retry attempt has been given up (possibly reach the maximum |
| 957 | * number of retries), one additional decrement of ndlp reference shall be |
| 958 | * invoked before going out after releasing the command IOCB. This will |
| 959 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 960 | * invoke one decrement of ndlp reference count). If no error reported in |
| 961 | * the IOCB status, the command Port ID field is used to determine whether |
| 962 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 963 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 964 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 965 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 966 | * specific topology completion conditions. |
| 967 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 968 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 969 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 970 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 971 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 972 | struct lpfc_vport *vport = cmdiocb->vport; |
| 973 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 974 | IOCB_t *irsp = &rspiocb->iocb; |
| 975 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 976 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 977 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 978 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 979 | int rc; |
| 980 | |
| 981 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 982 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 983 | /* One additional decrement on node reference count to |
| 984 | * trigger the release of the node |
| 985 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 986 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 987 | goto out; |
| 988 | } |
| 989 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 990 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 991 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 992 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 993 | vport->port_state); |
| 994 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 995 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 996 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 997 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 998 | * due to new FCF discovery |
| 999 | */ |
| 1000 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1001 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 1002 | if (phba->link_state < LPFC_LINK_UP) |
| 1003 | goto stop_rr_fcf_flogi; |
| 1004 | if ((phba->fcoe_cvl_eventtag_attn == |
| 1005 | phba->fcoe_cvl_eventtag) && |
| 1006 | (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1007 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1008 | IOERR_SLI_ABORTED)) |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1009 | goto stop_rr_fcf_flogi; |
| 1010 | else |
| 1011 | phba->fcoe_cvl_eventtag_attn = |
| 1012 | phba->fcoe_cvl_eventtag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1013 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1014 | "2611 FLOGI failed on FCF (x%x), " |
| 1015 | "status:x%x/x%x, tmo:x%x, perform " |
| 1016 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1017 | phba->fcf.current_rec.fcf_indx, |
| 1018 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1019 | irsp->ulpTimeout); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1020 | lpfc_sli4_set_fcf_flogi_fail(phba, |
| 1021 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1022 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1023 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 1024 | if (rc) |
| 1025 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1026 | } |
| 1027 | |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1028 | stop_rr_fcf_flogi: |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1029 | /* FLOGI failure */ |
| 1030 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1031 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x " |
| 1032 | "Data x%x x%x\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1033 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1034 | irsp->ulpTimeout, phba->hba_flag, |
| 1035 | phba->fcf.fcf_flag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1036 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1037 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1038 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1039 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1040 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1041 | /* FLOGI failure */ |
| 1042 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1043 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 1044 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1045 | irsp->ulpTimeout); |
| 1046 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1047 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1048 | spin_lock_irq(shost->host_lock); |
| 1049 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 1050 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1051 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1052 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1053 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 1054 | * alpa map would take too long otherwise. |
| 1055 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1056 | if (phba->alpa_map[0] == 0) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1057 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1058 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1059 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1060 | (vport->fc_prevDID != vport->fc_myDID) || |
| 1061 | phba->fc_topology_changed)) { |
| 1062 | if (vport->fc_flag & FC_VFI_REGISTERED) { |
| 1063 | if (phba->fc_topology_changed) { |
| 1064 | lpfc_unregister_fcf_prep(phba); |
| 1065 | spin_lock_irq(shost->host_lock); |
| 1066 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 1067 | spin_unlock_irq(shost->host_lock); |
| 1068 | phba->fc_topology_changed = 0; |
| 1069 | } else { |
| 1070 | lpfc_sli4_unreg_all_rpis(vport); |
| 1071 | } |
| 1072 | } |
James Smart | 342b59c | 2016-03-31 14:12:31 -0700 | [diff] [blame] | 1073 | |
| 1074 | /* Do not register VFI if the driver aborted FLOGI */ |
| 1075 | if (!lpfc_error_lost_link(irsp)) |
| 1076 | lpfc_issue_reg_vfi(vport); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1077 | lpfc_nlp_put(ndlp); |
| 1078 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1079 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1080 | goto flogifail; |
| 1081 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1082 | spin_lock_irq(shost->host_lock); |
| 1083 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 1084 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1085 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1086 | |
| 1087 | /* |
| 1088 | * The FLogI succeeded. Sync the data for the CPU before |
| 1089 | * accessing it. |
| 1090 | */ |
| 1091 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 1092 | if (!prsp) |
| 1093 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1094 | sp = prsp->virt + sizeof(uint32_t); |
| 1095 | |
| 1096 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1097 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 1098 | "0101 FLOGI completes successfully, I/O tag:x%x, " |
| 1099 | "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] | 1100 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1101 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution, |
| 1102 | vport->port_state, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1103 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1104 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1105 | /* |
| 1106 | * If Common Service Parameters indicate Nport |
| 1107 | * we are point to point, if Fport we are Fabric. |
| 1108 | */ |
| 1109 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1110 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1111 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1112 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1113 | else { |
| 1114 | lpfc_printf_vlog(vport, KERN_ERR, |
| 1115 | LOG_FIP | LOG_ELS, |
| 1116 | "2831 FLOGI response with cleared Fabric " |
| 1117 | "bit fcf_index 0x%x " |
| 1118 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 1119 | "Fabric Name " |
| 1120 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 1121 | phba->fcf.current_rec.fcf_indx, |
| 1122 | phba->fcf.current_rec.switch_name[0], |
| 1123 | phba->fcf.current_rec.switch_name[1], |
| 1124 | phba->fcf.current_rec.switch_name[2], |
| 1125 | phba->fcf.current_rec.switch_name[3], |
| 1126 | phba->fcf.current_rec.switch_name[4], |
| 1127 | phba->fcf.current_rec.switch_name[5], |
| 1128 | phba->fcf.current_rec.switch_name[6], |
| 1129 | phba->fcf.current_rec.switch_name[7], |
| 1130 | phba->fcf.current_rec.fabric_name[0], |
| 1131 | phba->fcf.current_rec.fabric_name[1], |
| 1132 | phba->fcf.current_rec.fabric_name[2], |
| 1133 | phba->fcf.current_rec.fabric_name[3], |
| 1134 | phba->fcf.current_rec.fabric_name[4], |
| 1135 | phba->fcf.current_rec.fabric_name[5], |
| 1136 | phba->fcf.current_rec.fabric_name[6], |
| 1137 | phba->fcf.current_rec.fabric_name[7]); |
| 1138 | lpfc_nlp_put(ndlp); |
| 1139 | spin_lock_irq(&phba->hbalock); |
| 1140 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1141 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1142 | spin_unlock_irq(&phba->hbalock); |
| 1143 | goto out; |
| 1144 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1145 | if (!rc) { |
| 1146 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1147 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 1148 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 1149 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1150 | "2769 FLOGI to FCF (x%x) " |
| 1151 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1152 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1153 | spin_lock_irq(&phba->hbalock); |
| 1154 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1155 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1156 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1157 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1158 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | flogifail: |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1162 | spin_lock_irq(&phba->hbalock); |
| 1163 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 1164 | spin_unlock_irq(&phba->hbalock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1165 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1166 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1167 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1168 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1169 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1170 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1171 | |
| 1172 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1173 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1174 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1175 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1176 | IOERR_SLI_ABORTED) && |
| 1177 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1178 | IOERR_SLI_DOWN))) && |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1179 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 1180 | /* If FLOGI failed enable link interrupt. */ |
| 1181 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1182 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1183 | out: |
| 1184 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1185 | } |
| 1186 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1187 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1188 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1189 | * @vport: pointer to a host virtual N_Port data structure. |
| 1190 | * @ndlp: pointer to a node-list data structure. |
| 1191 | * @retry: number of retries to the command IOCB. |
| 1192 | * |
| 1193 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 1194 | * for a @vport. The initiator service parameters are put into the payload |
| 1195 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 1196 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 1197 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 1198 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 1199 | * |
| 1200 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1201 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1202 | * will be stored into the context1 field of the IOCB for the completion |
| 1203 | * callback function to the FLOGI ELS command. |
| 1204 | * |
| 1205 | * Return code |
| 1206 | * 0 - successfully issued flogi iocb for @vport |
| 1207 | * 1 - failed to issue flogi iocb for @vport |
| 1208 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1209 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1210 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1211 | uint8_t retry) |
| 1212 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1213 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1214 | struct serv_parm *sp; |
| 1215 | IOCB_t *icmd; |
| 1216 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1217 | uint8_t *pcmd; |
| 1218 | uint16_t cmdsize; |
| 1219 | uint32_t tmo; |
| 1220 | int rc; |
| 1221 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1222 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1223 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1224 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1225 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1226 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1227 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1228 | |
| 1229 | icmd = &elsiocb->iocb; |
| 1230 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1231 | |
| 1232 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1233 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1234 | pcmd += sizeof(uint32_t); |
| 1235 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1236 | sp = (struct serv_parm *) pcmd; |
| 1237 | |
| 1238 | /* Setup CSPs accordingly for Fabric */ |
| 1239 | sp->cmn.e_d_tov = 0; |
| 1240 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 1241 | sp->cmn.virtual_fabric_support = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1242 | sp->cls1.classValid = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | if (sp->cmn.fcphLow < FC_PH3) |
| 1244 | sp->cmn.fcphLow = FC_PH3; |
| 1245 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1246 | sp->cmn.fcphHigh = FC_PH3; |
| 1247 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 1248 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1249 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1250 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 1251 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1252 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1253 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1254 | /* Set the fcfi to the fcfi we registered with */ |
| 1255 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1256 | } |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1257 | /* Can't do SLI4 class2 without support sequence coalescing */ |
| 1258 | sp->cls2.classValid = 0; |
| 1259 | sp->cls2.seqDelivery = 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1260 | } else { |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1261 | /* Historical, setting sequential-delivery bit for SLI3 */ |
| 1262 | sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; |
| 1263 | sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1264 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 1265 | sp->cmn.request_multiple_Nport = 1; |
| 1266 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1267 | icmd->ulpCt_h = 1; |
| 1268 | icmd->ulpCt_l = 0; |
| 1269 | } else |
| 1270 | sp->cmn.request_multiple_Nport = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1271 | } |
| 1272 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1273 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1274 | icmd->un.elsreq64.myID = 0; |
| 1275 | icmd->un.elsreq64.fl = 1; |
| 1276 | } |
| 1277 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1278 | tmo = phba->fc_ratov; |
| 1279 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1280 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1281 | phba->fc_ratov = tmo; |
| 1282 | |
| 1283 | phba->fc_stat.elsXmitFLOGI++; |
| 1284 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1285 | |
| 1286 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1287 | "Issue FLOGI: opt:x%x", |
| 1288 | phba->sli3_options, 0, 0); |
| 1289 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1290 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1291 | if (rc == IOCB_ERROR) { |
| 1292 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1293 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1294 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1295 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1296 | } |
| 1297 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1298 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1299 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1300 | * @phba: pointer to lpfc hba data structure. |
| 1301 | * |
| 1302 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1303 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1304 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1305 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1306 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1307 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1308 | * |
| 1309 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1310 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1311 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1312 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1313 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1314 | { |
| 1315 | struct lpfc_sli_ring *pring; |
| 1316 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1317 | struct lpfc_nodelist *ndlp; |
| 1318 | IOCB_t *icmd; |
| 1319 | |
| 1320 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1321 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1322 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1323 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1324 | |
| 1325 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1326 | |
| 1327 | /* |
| 1328 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1329 | * searching for. |
| 1330 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1331 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1332 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1333 | icmd = &iocb->iocb; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1334 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1336 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1337 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1338 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1339 | } |
| 1340 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1341 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1342 | |
| 1343 | return 0; |
| 1344 | } |
| 1345 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1346 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1347 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1348 | * @vport: pointer to a host virtual N_Port data structure. |
| 1349 | * |
| 1350 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1351 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1352 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1353 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1354 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1355 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1356 | * @vport. |
| 1357 | * |
| 1358 | * Return code |
| 1359 | * 0 - failed to issue initial flogi for @vport |
| 1360 | * 1 - successfully issued initial flogi for @vport |
| 1361 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1362 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1363 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1364 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1365 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1366 | struct lpfc_nodelist *ndlp; |
| 1367 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1368 | vport->port_state = LPFC_FLOGI; |
| 1369 | lpfc_set_disctmo(vport); |
| 1370 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1371 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1372 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1373 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1374 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1375 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1376 | if (!ndlp) |
| 1377 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1378 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1379 | /* Set the node type */ |
| 1380 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1381 | /* Put ndlp onto node list */ |
| 1382 | lpfc_enqueue_node(vport, ndlp); |
| 1383 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1384 | /* re-setup ndlp without removing from node list */ |
| 1385 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1386 | if (!ndlp) |
| 1387 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1388 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1389 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1390 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1391 | /* This decrement of reference count to node shall kick off |
| 1392 | * the release of the node. |
| 1393 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1394 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1395 | return 0; |
| 1396 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1397 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1398 | } |
| 1399 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1400 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1401 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1402 | * @vport: pointer to a host virtual N_Port data structure. |
| 1403 | * |
| 1404 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1405 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1406 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1407 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1408 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1409 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1410 | * @vport. |
| 1411 | * |
| 1412 | * Return code |
| 1413 | * 0 - failed to issue initial fdisc for @vport |
| 1414 | * 1 - successfully issued initial fdisc for @vport |
| 1415 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1416 | int |
| 1417 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1418 | { |
| 1419 | struct lpfc_hba *phba = vport->phba; |
| 1420 | struct lpfc_nodelist *ndlp; |
| 1421 | |
| 1422 | /* First look for the Fabric ndlp */ |
| 1423 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1424 | if (!ndlp) { |
| 1425 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1426 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1427 | if (!ndlp) |
| 1428 | return 0; |
| 1429 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1430 | /* Put ndlp onto node list */ |
| 1431 | lpfc_enqueue_node(vport, ndlp); |
| 1432 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1433 | /* re-setup ndlp without removing from node list */ |
| 1434 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1435 | if (!ndlp) |
| 1436 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1437 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1438 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1439 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1440 | /* decrement node reference count to trigger the release of |
| 1441 | * the node. |
| 1442 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1443 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1444 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1445 | } |
| 1446 | return 1; |
| 1447 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1448 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1449 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1450 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1451 | * @vport: pointer to a host virtual N_Port data structure. |
| 1452 | * |
| 1453 | * This routine checks whether there are more remaining Port Logins |
| 1454 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1455 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1456 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1457 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1458 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1459 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1460 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1461 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1462 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1463 | if (vport->num_disc_nodes) |
| 1464 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1465 | |
| 1466 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1467 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1468 | "0232 Continue discovery with %d PLOGIs to go " |
| 1469 | "Data: x%x x%x x%x\n", |
| 1470 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1471 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1472 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1473 | if (vport->fc_flag & FC_NLP_MORE) |
| 1474 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 1475 | lpfc_els_disc_plogi(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1476 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1477 | return; |
| 1478 | } |
| 1479 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1480 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1481 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1482 | * @phba: pointer to lpfc hba data structure. |
| 1483 | * @prsp: pointer to response IOCB payload. |
| 1484 | * @ndlp: pointer to a node-list data structure. |
| 1485 | * |
| 1486 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1487 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1488 | * The following cases are considered N_Port confirmed: |
| 1489 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1490 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1491 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1492 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1493 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1494 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1495 | * on that node to release the RPI associated with the node; 2) if there is |
| 1496 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1497 | * into, a new node shall be allocated (or activated). In either case, the |
| 1498 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1499 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1500 | * its pointer returned as the confirmed node. |
| 1501 | * |
| 1502 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1503 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1504 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1505 | * into an inactive state on the vport node list and the vport node list |
| 1506 | * management algorithm does not allow two node with a same DID. |
| 1507 | * |
| 1508 | * Return code |
| 1509 | * pointer to the PLOGI N_Port @ndlp |
| 1510 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1511 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1512 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1513 | struct lpfc_nodelist *ndlp) |
| 1514 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1515 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1516 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1517 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1518 | struct lpfc_rport_data *rdata; |
| 1519 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1520 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1521 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1522 | uint32_t rc, keepDID = 0, keep_nlp_flag = 0; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1523 | uint16_t keep_nlp_state; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1524 | int put_node; |
| 1525 | int put_rport; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1526 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1527 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1528 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1529 | * by WWPN. Just return the ndlp that was given to us. |
| 1530 | */ |
| 1531 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1532 | return ndlp; |
| 1533 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1534 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1535 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1536 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1537 | /* 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] | 1538 | * we have for that ndlp. If not, we have some work to do. |
| 1539 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1540 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1541 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1542 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1543 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1544 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1545 | active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool, |
| 1546 | GFP_KERNEL); |
| 1547 | if (active_rrqs_xri_bitmap) |
| 1548 | memset(active_rrqs_xri_bitmap, 0, |
| 1549 | phba->cfg_rrq_xri_bitmap_sz); |
| 1550 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1551 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1552 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1553 | "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n", |
| 1554 | ndlp, ndlp->nlp_DID, new_ndlp); |
| 1555 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1556 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1557 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1558 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1559 | if (!rc) { |
| 1560 | if (active_rrqs_xri_bitmap) |
| 1561 | mempool_free(active_rrqs_xri_bitmap, |
| 1562 | phba->active_rrq_pool); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1563 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1564 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1565 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1566 | if (!new_ndlp) { |
| 1567 | if (active_rrqs_xri_bitmap) |
| 1568 | mempool_free(active_rrqs_xri_bitmap, |
| 1569 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1570 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1571 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1572 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1573 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1574 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1575 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1576 | if (!rc) { |
| 1577 | if (active_rrqs_xri_bitmap) |
| 1578 | mempool_free(active_rrqs_xri_bitmap, |
| 1579 | phba->active_rrq_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1580 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1581 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1582 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1583 | NLP_STE_UNUSED_NODE); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1584 | if (!new_ndlp) { |
| 1585 | if (active_rrqs_xri_bitmap) |
| 1586 | mempool_free(active_rrqs_xri_bitmap, |
| 1587 | phba->active_rrq_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1588 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1589 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1590 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1591 | if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap) |
| 1592 | memcpy(active_rrqs_xri_bitmap, |
| 1593 | new_ndlp->active_rrqs_xri_bitmap, |
| 1594 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1595 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1596 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1597 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1598 | active_rrqs_xri_bitmap) |
| 1599 | memcpy(active_rrqs_xri_bitmap, |
| 1600 | new_ndlp->active_rrqs_xri_bitmap, |
| 1601 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1602 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1603 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1604 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1605 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1606 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1607 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1608 | memcpy(new_ndlp->active_rrqs_xri_bitmap, |
| 1609 | ndlp->active_rrqs_xri_bitmap, |
| 1610 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1611 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1612 | spin_lock_irq(shost->host_lock); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1613 | keep_nlp_flag = new_ndlp->nlp_flag; |
| 1614 | new_ndlp->nlp_flag = ndlp->nlp_flag; |
| 1615 | ndlp->nlp_flag = keep_nlp_flag; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1616 | spin_unlock_irq(shost->host_lock); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1617 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1618 | /* Set nlp_states accordingly */ |
| 1619 | keep_nlp_state = new_ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1620 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1621 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1622 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1623 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1624 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1625 | * to put ndlp on UNUSED list and try to free it. |
| 1626 | */ |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1627 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1628 | "3179 PLOGI confirm NEW: %x %x\n", |
| 1629 | new_ndlp->nlp_DID, keepDID); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1630 | |
| 1631 | /* Fix up the rport accordingly */ |
| 1632 | rport = ndlp->rport; |
| 1633 | if (rport) { |
| 1634 | rdata = rport->dd_data; |
| 1635 | if (rdata->pnode == ndlp) { |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1636 | /* break the link before dropping the ref */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1637 | ndlp->rport = NULL; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1638 | lpfc_nlp_put(ndlp); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1639 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1640 | new_ndlp->rport = rport; |
| 1641 | } |
| 1642 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1643 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1644 | /* We shall actually free the ndlp with both nlp_DID and |
| 1645 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1646 | * nodelist never to be used. |
| 1647 | */ |
| 1648 | if (ndlp->nlp_DID == 0) { |
| 1649 | spin_lock_irq(&phba->ndlp_lock); |
| 1650 | NLP_SET_FREE_REQ(ndlp); |
| 1651 | spin_unlock_irq(&phba->ndlp_lock); |
| 1652 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1653 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1654 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1655 | ndlp->nlp_DID = keepDID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1656 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1657 | active_rrqs_xri_bitmap) |
| 1658 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1659 | active_rrqs_xri_bitmap, |
| 1660 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1661 | |
| 1662 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 1663 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1664 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1665 | else { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1666 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1667 | "3180 PLOGI confirm SWAP: %x %x\n", |
| 1668 | new_ndlp->nlp_DID, keepDID); |
| 1669 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1670 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1671 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1672 | /* Two ndlps cannot have the same did */ |
| 1673 | ndlp->nlp_DID = keepDID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1674 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1675 | active_rrqs_xri_bitmap) |
| 1676 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1677 | active_rrqs_xri_bitmap, |
| 1678 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1679 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1680 | /* Since we are switching over to the new_ndlp, |
| 1681 | * reset the old ndlp state |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1682 | */ |
| 1683 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 1684 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1685 | keep_nlp_state = NLP_STE_NPR_NODE; |
| 1686 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1687 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1688 | /* Fix up the rport accordingly */ |
| 1689 | rport = ndlp->rport; |
| 1690 | if (rport) { |
| 1691 | rdata = rport->dd_data; |
| 1692 | put_node = rdata->pnode != NULL; |
| 1693 | put_rport = ndlp->rport != NULL; |
| 1694 | rdata->pnode = NULL; |
| 1695 | ndlp->rport = NULL; |
| 1696 | if (put_node) |
| 1697 | lpfc_nlp_put(ndlp); |
| 1698 | if (put_rport) |
| 1699 | put_device(&rport->dev); |
| 1700 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1701 | } |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1702 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1703 | active_rrqs_xri_bitmap) |
| 1704 | mempool_free(active_rrqs_xri_bitmap, |
| 1705 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1706 | return new_ndlp; |
| 1707 | } |
| 1708 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1709 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1710 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1711 | * @vport: pointer to a host virtual N_Port data structure. |
| 1712 | * |
| 1713 | * This routine checks whether more Registration State Change |
| 1714 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1715 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1716 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1717 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1718 | * handling the RSCNs. |
| 1719 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1720 | void |
| 1721 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1722 | { |
| 1723 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1724 | |
| 1725 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1726 | /* |
| 1727 | * Check to see if more RSCNs came in while we were |
| 1728 | * processing this one. |
| 1729 | */ |
| 1730 | if (vport->fc_rscn_id_cnt || |
| 1731 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1732 | lpfc_els_handle_rscn(vport); |
| 1733 | else { |
| 1734 | spin_lock_irq(shost->host_lock); |
| 1735 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1736 | spin_unlock_irq(shost->host_lock); |
| 1737 | } |
| 1738 | } |
| 1739 | } |
| 1740 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1741 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1742 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. |
| 1743 | * @phba: pointer to lpfc hba data structure. |
| 1744 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1745 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1746 | * |
| 1747 | * This routine will call the clear rrq function to free the rrq and |
| 1748 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not |
| 1749 | * exist then the clear_rrq is still called because the rrq needs to |
| 1750 | * be freed. |
| 1751 | **/ |
| 1752 | |
| 1753 | static void |
| 1754 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1755 | struct lpfc_iocbq *rspiocb) |
| 1756 | { |
| 1757 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1758 | IOCB_t *irsp; |
| 1759 | struct lpfc_nodelist *ndlp; |
| 1760 | struct lpfc_node_rrq *rrq; |
| 1761 | |
| 1762 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1763 | rrq = cmdiocb->context_un.rrq; |
| 1764 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1765 | |
| 1766 | irsp = &rspiocb->iocb; |
| 1767 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1768 | "RRQ cmpl: status:x%x/x%x did:x%x", |
| 1769 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1770 | irsp->un.elsreq64.remoteID); |
| 1771 | |
| 1772 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
| 1773 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { |
| 1774 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1775 | "2882 RRQ completes to NPort x%x " |
| 1776 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1777 | irsp->un.elsreq64.remoteID, |
| 1778 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1779 | irsp->ulpIoTag); |
| 1780 | goto out; |
| 1781 | } |
| 1782 | |
| 1783 | /* rrq completes to NPort <nlp_DID> */ |
| 1784 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1785 | "2880 RRQ completes to NPort x%x " |
| 1786 | "Data: x%x x%x x%x x%x x%x\n", |
| 1787 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1788 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); |
| 1789 | |
| 1790 | if (irsp->ulpStatus) { |
| 1791 | /* Check for retry */ |
| 1792 | /* RRQ failed Don't print the vport to vport rjts */ |
| 1793 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1794 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1795 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1796 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1797 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1798 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", |
| 1799 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1800 | irsp->un.ulpWord[4]); |
| 1801 | } |
| 1802 | out: |
| 1803 | if (rrq) |
| 1804 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1805 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1806 | return; |
| 1807 | } |
| 1808 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1809 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1810 | * @phba: pointer to lpfc hba data structure. |
| 1811 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1812 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1813 | * |
| 1814 | * This routine is the completion callback function for issuing the Port |
| 1815 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1816 | * 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] | 1817 | * 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] | 1818 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1819 | * checked for error conditons. If there is error status reported, PLOGI |
| 1820 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1821 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1822 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1823 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1824 | * there are additional N_Port nodes with the vport that need to perform |
| 1825 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1826 | * PLOGIs. |
| 1827 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1828 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1829 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1830 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1831 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1832 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1833 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1834 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1835 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1836 | struct lpfc_dmabuf *prsp; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 1837 | int disc, rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1838 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1839 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1840 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1841 | |
| 1842 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1843 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1844 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1845 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1846 | irsp->un.elsreq64.remoteID); |
| 1847 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1848 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1849 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1850 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1851 | "0136 PLOGI completes to NPort x%x " |
| 1852 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1853 | irsp->un.elsreq64.remoteID, |
| 1854 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1855 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1856 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1857 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1858 | |
| 1859 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1860 | * is being used during discovery. |
| 1861 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1862 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1863 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1864 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1865 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1866 | rc = 0; |
| 1867 | |
| 1868 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1869 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1870 | "0102 PLOGI completes to NPort x%x " |
| 1871 | "Data: x%x x%x x%x x%x x%x\n", |
| 1872 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1873 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1874 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1875 | if (lpfc_els_chk_latt(vport)) { |
| 1876 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1877 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1878 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1879 | goto out; |
| 1880 | } |
| 1881 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1882 | if (irsp->ulpStatus) { |
| 1883 | /* Check for retry */ |
| 1884 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1885 | /* ELS command is being retried */ |
| 1886 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1887 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1888 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1889 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1890 | } |
| 1891 | goto out; |
| 1892 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1893 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1894 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1895 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1896 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1897 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1898 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1899 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1900 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1901 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1902 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1903 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1904 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1905 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1906 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1907 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | } else { |
| 1909 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1910 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1911 | cmdiocb->context2)->list.next, |
| 1912 | struct lpfc_dmabuf, list); |
| 1913 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1914 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1915 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1916 | } |
| 1917 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1918 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1919 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1920 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1921 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1922 | if (vport->num_disc_nodes == 0) { |
| 1923 | spin_lock_irq(shost->host_lock); |
| 1924 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1925 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1926 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1927 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1928 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | out: |
| 1933 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1934 | return; |
| 1935 | } |
| 1936 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1937 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1938 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1939 | * @vport: pointer to a host virtual N_Port data structure. |
| 1940 | * @did: destination port identifier. |
| 1941 | * @retry: number of retries to the command IOCB. |
| 1942 | * |
| 1943 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1944 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1945 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1946 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1947 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1948 | * |
| 1949 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1950 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1951 | * will be stored into the context1 field of the IOCB for the completion |
| 1952 | * callback function to the PLOGI ELS command. |
| 1953 | * |
| 1954 | * Return code |
| 1955 | * 0 - Successfully issued a plogi for @vport |
| 1956 | * 1 - failed to issue a plogi for @vport |
| 1957 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1958 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1959 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1961 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1962 | struct serv_parm *sp; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1963 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1964 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1965 | uint8_t *pcmd; |
| 1966 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1967 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1968 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1969 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1970 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1971 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1972 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1973 | /* If ndlp is not NULL, we will bump the reference count on it */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1974 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1975 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1976 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1977 | if (!elsiocb) |
| 1978 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1979 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1980 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1981 | |
| 1982 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1983 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1984 | pcmd += sizeof(uint32_t); |
| 1985 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | sp = (struct serv_parm *) pcmd; |
| 1987 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1988 | /* |
| 1989 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 1990 | * to device on remote loops work. |
| 1991 | */ |
| 1992 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 1993 | sp->cmn.altBbCredit = 1; |
| 1994 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1995 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1996 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1997 | |
| 1998 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1999 | sp->cmn.fcphHigh = FC_PH3; |
| 2000 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2001 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2002 | "Issue PLOGI: did:x%x", |
| 2003 | did, 0, 0); |
| 2004 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2005 | phba->fc_stat.elsXmitPLOGI++; |
| 2006 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2007 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2008 | |
| 2009 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2010 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2011 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2012 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2013 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2014 | } |
| 2015 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2016 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2017 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2018 | * @phba: pointer to lpfc hba data structure. |
| 2019 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2020 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2021 | * |
| 2022 | * This routine is the completion callback function for a Process Login |
| 2023 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 2024 | * status. If there is error status reported, PRLI retry shall be attempted |
| 2025 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 2026 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 2027 | * ndlp to mark the PRLI completion. |
| 2028 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2029 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2030 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2031 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2032 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2033 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2034 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2035 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2036 | struct lpfc_nodelist *ndlp; |
| 2037 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2038 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2039 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2040 | |
| 2041 | irsp = &(rspiocb->iocb); |
| 2042 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2043 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2044 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2045 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2046 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2047 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2048 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 2049 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2050 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2051 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2052 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2053 | "0103 PRLI completes to NPort x%x " |
| 2054 | "Data: x%x x%x x%x x%x\n", |
| 2055 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2056 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2057 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2058 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2059 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2060 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2061 | goto out; |
| 2062 | |
| 2063 | if (irsp->ulpStatus) { |
| 2064 | /* Check for retry */ |
| 2065 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2066 | /* ELS command is being retried */ |
| 2067 | goto out; |
| 2068 | } |
| 2069 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2070 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2071 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 2072 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2073 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2074 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2075 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2077 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2078 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2079 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2080 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2081 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2082 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2083 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2084 | out: |
| 2085 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2086 | return; |
| 2087 | } |
| 2088 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2089 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2090 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2091 | * @vport: pointer to a host virtual N_Port data structure. |
| 2092 | * @ndlp: pointer to a node-list data structure. |
| 2093 | * @retry: number of retries to the command IOCB. |
| 2094 | * |
| 2095 | * This routine issues a Process Login (PRLI) ELS command for the |
| 2096 | * @vport. The PRLI service parameters are set up in the payload of the |
| 2097 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 2098 | * is put to the IOCB completion callback func field before invoking the |
| 2099 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 2100 | * |
| 2101 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2102 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2103 | * will be stored into the context1 field of the IOCB for the completion |
| 2104 | * callback function to the PRLI ELS command. |
| 2105 | * |
| 2106 | * Return code |
| 2107 | * 0 - successfully issued prli iocb command for @vport |
| 2108 | * 1 - failed to issue prli iocb command for @vport |
| 2109 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2110 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2111 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2112 | uint8_t retry) |
| 2113 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2114 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2115 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2116 | PRLI *npr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2117 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2118 | uint8_t *pcmd; |
| 2119 | uint16_t cmdsize; |
| 2120 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2121 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2122 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2123 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2124 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2125 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2126 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2127 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2128 | |
| 2129 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2130 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2131 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2132 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | |
| 2134 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 2135 | npr = (PRLI *) pcmd; |
| 2136 | /* |
| 2137 | * If our firmware version is 3.20 or later, |
| 2138 | * set the following bits for FC-TAPE support. |
| 2139 | */ |
| 2140 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 2141 | npr->ConfmComplAllowed = 1; |
| 2142 | npr->Retry = 1; |
| 2143 | npr->TaskRetryIdReq = 1; |
| 2144 | } |
| 2145 | npr->estabImagePair = 1; |
| 2146 | npr->readXferRdyDis = 1; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 2147 | if (vport->cfg_first_burst_size) |
| 2148 | npr->writeXferRdyDis = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2149 | |
| 2150 | /* For FCP support */ |
| 2151 | npr->prliType = PRLI_FCP_TYPE; |
| 2152 | npr->initiatorFunc = 1; |
| 2153 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2154 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2155 | "Issue PRLI: did:x%x", |
| 2156 | ndlp->nlp_DID, 0, 0); |
| 2157 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2158 | phba->fc_stat.elsXmitPRLI++; |
| 2159 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2160 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2161 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2162 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2163 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2164 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2165 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2167 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2168 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2169 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2170 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2171 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2172 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2173 | } |
| 2174 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2175 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2176 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2177 | * @vport: pointer to a host virtual N_Port data structure. |
| 2178 | * |
| 2179 | * This routine performs Registration State Change Notification (RSCN) |
| 2180 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 2181 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 2182 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 2183 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 2184 | * invoked to check and handle possible more RSCN came in during the period |
| 2185 | * of processing the current ones. |
| 2186 | **/ |
| 2187 | static void |
| 2188 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 2189 | { |
| 2190 | lpfc_can_disctmo(vport); |
| 2191 | |
| 2192 | /* RSCN discovery */ |
| 2193 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 2194 | if (vport->fc_npr_cnt) |
| 2195 | if (lpfc_els_disc_plogi(vport)) |
| 2196 | return; |
| 2197 | |
| 2198 | lpfc_end_rscn(vport); |
| 2199 | } |
| 2200 | |
| 2201 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2202 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2203 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 2204 | * |
| 2205 | * This function is called when the final ADISC is completed during discovery. |
| 2206 | * This function handles clearing link attention or issuing reg_vpi depending |
| 2207 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 2208 | * discovery. |
| 2209 | * This function is called with no locks held. |
| 2210 | **/ |
| 2211 | static void |
| 2212 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 2213 | { |
| 2214 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2215 | struct lpfc_hba *phba = vport->phba; |
| 2216 | |
| 2217 | /* |
| 2218 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 2219 | * and continue discovery. |
| 2220 | */ |
| 2221 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2222 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 2223 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | d454c91 | 2014-12-30 12:08:58 -0500 | [diff] [blame] | 2224 | /* The ADISCs are complete. Doesn't matter if they |
| 2225 | * succeeded or failed because the ADISC completion |
| 2226 | * routine guarantees to call the state machine and |
| 2227 | * the RPI is either unregistered (failed ADISC response) |
| 2228 | * or the RPI is still valid and the node is marked |
| 2229 | * mapped for a target. The exchanges should be in the |
| 2230 | * correct state. This code is specific to SLI3. |
| 2231 | */ |
| 2232 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2233 | lpfc_issue_reg_vpi(phba, vport); |
| 2234 | return; |
| 2235 | } |
| 2236 | /* |
| 2237 | * For SLI2, we need to set port_state to READY |
| 2238 | * and continue discovery. |
| 2239 | */ |
| 2240 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2241 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 2242 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2243 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 2244 | vport->num_disc_nodes = 0; |
| 2245 | /* go thru NPR list, issue ELS PLOGIs */ |
| 2246 | if (vport->fc_npr_cnt) |
| 2247 | lpfc_els_disc_plogi(vport); |
| 2248 | if (!vport->num_disc_nodes) { |
| 2249 | spin_lock_irq(shost->host_lock); |
| 2250 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2251 | spin_unlock_irq(shost->host_lock); |
| 2252 | lpfc_can_disctmo(vport); |
| 2253 | lpfc_end_rscn(vport); |
| 2254 | } |
| 2255 | } |
| 2256 | vport->port_state = LPFC_VPORT_READY; |
| 2257 | } else |
| 2258 | lpfc_rscn_disc(vport); |
| 2259 | } |
| 2260 | |
| 2261 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2262 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2263 | * @vport: pointer to a host virtual N_Port data structure. |
| 2264 | * |
| 2265 | * This routine determines whether there are more ndlps on a @vport |
| 2266 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 2267 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 2268 | * remaining nodes which need to have ADISC sent. |
| 2269 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2270 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2271 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2272 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2273 | if (vport->num_disc_nodes) |
| 2274 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2275 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2276 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2277 | "0210 Continue discovery with %d ADISCs to go " |
| 2278 | "Data: x%x x%x x%x\n", |
| 2279 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 2280 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2281 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2282 | if (vport->fc_flag & FC_NLP_MORE) { |
| 2283 | lpfc_set_disctmo(vport); |
| 2284 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 2285 | lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2286 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2287 | if (!vport->num_disc_nodes) |
| 2288 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2289 | return; |
| 2290 | } |
| 2291 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2292 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2293 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2294 | * @phba: pointer to lpfc hba data structure. |
| 2295 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2296 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2297 | * |
| 2298 | * This routine is the completion function for issuing the Address Discover |
| 2299 | * (ADISC) command. It first checks to see whether link went down during |
| 2300 | * the discovery process. If so, the node will be marked as node port |
| 2301 | * recovery for issuing discover IOCB by the link attention handler and |
| 2302 | * exit. Otherwise, the response status is checked. If error was reported |
| 2303 | * in the response status, the ADISC command shall be retried by invoking |
| 2304 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 2305 | * the response status, the state machine is invoked to set transition |
| 2306 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 2307 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2309 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2310 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2311 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2312 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2313 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2314 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2316 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2317 | |
| 2318 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2319 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2320 | |
| 2321 | irsp = &(rspiocb->iocb); |
| 2322 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2323 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2324 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2325 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 2326 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2327 | ndlp->nlp_DID); |
| 2328 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2329 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2330 | * is being used during discovery. |
| 2331 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2332 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2333 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2334 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2335 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2337 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2338 | "0104 ADISC completes to NPort x%x " |
| 2339 | "Data: x%x x%x x%x x%x x%x\n", |
| 2340 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2341 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2342 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2343 | if (lpfc_els_chk_latt(vport)) { |
| 2344 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2346 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2347 | goto out; |
| 2348 | } |
| 2349 | |
| 2350 | if (irsp->ulpStatus) { |
| 2351 | /* Check for retry */ |
| 2352 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2353 | /* ELS command is being retried */ |
| 2354 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2355 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2356 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2357 | spin_unlock_irq(shost->host_lock); |
| 2358 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2359 | } |
| 2360 | goto out; |
| 2361 | } |
| 2362 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2363 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2364 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2365 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2366 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2367 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2368 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2369 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2370 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2371 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2372 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2373 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2375 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2376 | /* Check to see if there are more ADISCs to be sent */ |
| 2377 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2378 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2379 | out: |
| 2380 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2381 | return; |
| 2382 | } |
| 2383 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2384 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2385 | * lpfc_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] | 2386 | * @vport: pointer to a virtual N_Port data structure. |
| 2387 | * @ndlp: pointer to a node-list data structure. |
| 2388 | * @retry: number of retries to the command IOCB. |
| 2389 | * |
| 2390 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2391 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2392 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2393 | * to issue the ADISC ELS command. |
| 2394 | * |
| 2395 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2396 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2397 | * will be stored into the context1 field of the IOCB for the completion |
| 2398 | * callback function to the ADISC ELS command. |
| 2399 | * |
| 2400 | * Return code |
| 2401 | * 0 - successfully issued adisc |
| 2402 | * 1 - failed to issue adisc |
| 2403 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2405 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | uint8_t retry) |
| 2407 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2408 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2409 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2410 | ADISC *ap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2411 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2412 | uint8_t *pcmd; |
| 2413 | uint16_t cmdsize; |
| 2414 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2415 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2416 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2417 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2418 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2419 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2420 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2421 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2422 | |
| 2423 | /* For ADISC request, remainder of payload is service parameters */ |
| 2424 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2425 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2426 | |
| 2427 | /* Fill in ADISC payload */ |
| 2428 | ap = (ADISC *) pcmd; |
| 2429 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2430 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2431 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2432 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2433 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2434 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2435 | "Issue ADISC: did:x%x", |
| 2436 | ndlp->nlp_DID, 0, 0); |
| 2437 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2438 | phba->fc_stat.elsXmitADISC++; |
| 2439 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2440 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2441 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2442 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2443 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2444 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2445 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2446 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2447 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2448 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2449 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2450 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2451 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2452 | } |
| 2453 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2454 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2455 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2456 | * @phba: pointer to lpfc hba data structure. |
| 2457 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2458 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2459 | * |
| 2460 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2461 | * command. If no error status was reported from the LOGO response, the |
| 2462 | * state machine of the associated ndlp shall be invoked for transition with |
| 2463 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2464 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2465 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2466 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2467 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2468 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2469 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2470 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2471 | struct lpfc_vport *vport = ndlp->vport; |
| 2472 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2473 | IOCB_t *irsp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2474 | struct lpfcMboxq *mbox; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2475 | unsigned long flags; |
| 2476 | uint32_t skip_recovery = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2477 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2478 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2479 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2480 | |
| 2481 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2482 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2483 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2484 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2485 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2486 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2487 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2488 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2489 | ndlp->nlp_DID); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2490 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2491 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2492 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2493 | "0105 LOGO completes to NPort x%x " |
| 2494 | "Data: x%x x%x x%x x%x\n", |
| 2495 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2496 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2497 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2498 | if (lpfc_els_chk_latt(vport)) { |
| 2499 | skip_recovery = 1; |
| 2500 | goto out; |
| 2501 | } |
| 2502 | |
| 2503 | /* Check to see if link went down during discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2504 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2505 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2506 | * which should abort all outstanding IOs. |
| 2507 | */ |
| 2508 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2509 | NLP_EVT_DEVICE_RM); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2510 | skip_recovery = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2511 | goto out; |
| 2512 | } |
| 2513 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2514 | if (irsp->ulpStatus) { |
| 2515 | /* Check for retry */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2516 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2517 | /* ELS command is being retried */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2518 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2519 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2520 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2521 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2522 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2523 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2524 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2525 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2526 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2527 | if (lpfc_error_lost_link(irsp)) { |
| 2528 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2529 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2530 | } |
| 2531 | } |
| 2532 | |
| 2533 | /* Call state machine. This will unregister the rpi if needed. */ |
| 2534 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); |
| 2535 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2536 | out: |
| 2537 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2538 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ |
| 2539 | if ((vport->fc_flag & FC_PT2PT) && |
| 2540 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { |
| 2541 | phba->pport->fc_myDID = 0; |
| 2542 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2543 | if (mbox) { |
| 2544 | lpfc_config_link(phba, mbox); |
| 2545 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2546 | mbox->vport = vport; |
| 2547 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 2548 | MBX_NOT_FINISHED) { |
| 2549 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2550 | skip_recovery = 1; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2551 | } |
| 2552 | } |
| 2553 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2554 | |
| 2555 | /* |
| 2556 | * If the node is a target, the handling attempts to recover the port. |
| 2557 | * For any other port type, the rpi is unregistered as an implicit |
| 2558 | * LOGO. |
| 2559 | */ |
| 2560 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) { |
| 2561 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 2562 | spin_lock_irqsave(shost->host_lock, flags); |
| 2563 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 2564 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2565 | |
| 2566 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2567 | "3187 LOGO completes to NPort x%x: Start " |
| 2568 | "Recovery Data: x%x x%x x%x x%x\n", |
| 2569 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2570 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 2571 | vport->num_disc_nodes); |
| 2572 | lpfc_disc_start(vport); |
| 2573 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2574 | return; |
| 2575 | } |
| 2576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2577 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2578 | * 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] | 2579 | * @vport: pointer to a virtual N_Port data structure. |
| 2580 | * @ndlp: pointer to a node-list data structure. |
| 2581 | * @retry: number of retries to the command IOCB. |
| 2582 | * |
| 2583 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2584 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2585 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2586 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2587 | * |
| 2588 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2589 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2590 | * will be stored into the context1 field of the IOCB for the completion |
| 2591 | * callback function to the LOGO ELS command. |
| 2592 | * |
| 2593 | * Return code |
| 2594 | * 0 - successfully issued logo |
| 2595 | * 1 - failed to issue logo |
| 2596 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2597 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2598 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2599 | uint8_t retry) |
| 2600 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2601 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2602 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2603 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2604 | uint8_t *pcmd; |
| 2605 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2606 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2607 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2608 | spin_lock_irq(shost->host_lock); |
| 2609 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2610 | spin_unlock_irq(shost->host_lock); |
| 2611 | return 0; |
| 2612 | } |
| 2613 | spin_unlock_irq(shost->host_lock); |
| 2614 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2615 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2616 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2617 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2618 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2619 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2620 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2622 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2623 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2624 | |
| 2625 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2626 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2627 | pcmd += sizeof(uint32_t); |
| 2628 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2629 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2630 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2631 | "Issue LOGO: did:x%x", |
| 2632 | ndlp->nlp_DID, 0, 0); |
| 2633 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2634 | /* |
| 2635 | * If we are issuing a LOGO, we may try to recover the remote NPort |
| 2636 | * by issuing a PLOGI later. Even though we issue ELS cmds by the |
| 2637 | * VPI, if we have a valid RPI, and that RPI gets unreg'ed while |
| 2638 | * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI |
| 2639 | * for that ELS cmd. To avoid this situation, lets get rid of the |
| 2640 | * RPI right now, before any ELS cmds are sent. |
| 2641 | */ |
| 2642 | spin_lock_irq(shost->host_lock); |
| 2643 | ndlp->nlp_flag |= NLP_ISSUE_LOGO; |
| 2644 | spin_unlock_irq(shost->host_lock); |
| 2645 | if (lpfc_unreg_rpi(vport, ndlp)) { |
| 2646 | lpfc_els_free_iocb(phba, elsiocb); |
| 2647 | return 0; |
| 2648 | } |
| 2649 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2650 | phba->fc_stat.elsXmitLOGO++; |
| 2651 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2652 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2653 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2654 | ndlp->nlp_flag &= ~NLP_ISSUE_LOGO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2655 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2656 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2657 | |
| 2658 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2659 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2660 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2661 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2663 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2664 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2665 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2666 | } |
| 2667 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2668 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2669 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2670 | * @phba: pointer to lpfc hba data structure. |
| 2671 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2672 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2673 | * |
| 2674 | * This routine is a generic completion callback function for ELS commands. |
| 2675 | * Specifically, it is the callback function which does not need to perform |
| 2676 | * any command specific operations. It is currently used by the ELS command |
| 2677 | * issuing routines for the ELS State Change Request (SCR), |
| 2678 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2679 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2680 | * certain debug loggings, this callback function simply invokes the |
| 2681 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2682 | * discovery process. |
| 2683 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2684 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2685 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2686 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2687 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2688 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2689 | IOCB_t *irsp; |
| 2690 | |
| 2691 | irsp = &rspiocb->iocb; |
| 2692 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2693 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2694 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2695 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2696 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2697 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2698 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2699 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2700 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2701 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2702 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2703 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2704 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2705 | return; |
| 2706 | } |
| 2707 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2708 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2709 | * 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] | 2710 | * @vport: pointer to a host virtual N_Port data structure. |
| 2711 | * @nportid: N_Port identifier to the remote node. |
| 2712 | * @retry: number of retries to the command IOCB. |
| 2713 | * |
| 2714 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2715 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2716 | * first search the @vport node list to find the matching ndlp. If no such |
| 2717 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2718 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2719 | * routine is invoked to send the SCR IOCB. |
| 2720 | * |
| 2721 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2722 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2723 | * will be stored into the context1 field of the IOCB for the completion |
| 2724 | * callback function to the SCR ELS command. |
| 2725 | * |
| 2726 | * Return code |
| 2727 | * 0 - Successfully issued scr command |
| 2728 | * 1 - Failed to issue scr command |
| 2729 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2730 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2731 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2732 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2733 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2734 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2735 | uint8_t *pcmd; |
| 2736 | uint16_t cmdsize; |
| 2737 | struct lpfc_nodelist *ndlp; |
| 2738 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2739 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2740 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2741 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2742 | if (!ndlp) { |
| 2743 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2744 | if (!ndlp) |
| 2745 | return 1; |
| 2746 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2747 | lpfc_enqueue_node(vport, ndlp); |
| 2748 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2749 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2750 | if (!ndlp) |
| 2751 | return 1; |
| 2752 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2753 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2754 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2755 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2756 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2757 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2758 | /* This will trigger the release of the node just |
| 2759 | * allocated |
| 2760 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2761 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2762 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2763 | } |
| 2764 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2765 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2766 | |
| 2767 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2768 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2769 | |
| 2770 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2771 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2772 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2773 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2774 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2775 | "Issue SCR: did:x%x", |
| 2776 | ndlp->nlp_DID, 0, 0); |
| 2777 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2778 | phba->fc_stat.elsXmitSCR++; |
| 2779 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2780 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2781 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2782 | /* The additional lpfc_nlp_put will cause the following |
| 2783 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2784 | * the node. |
| 2785 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2786 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2787 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2788 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2789 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2790 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2791 | * trigger the release of node. |
| 2792 | */ |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 2793 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2794 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2795 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2796 | } |
| 2797 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2798 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2799 | * 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] | 2800 | * @vport: pointer to a host virtual N_Port data structure. |
| 2801 | * @nportid: N_Port identifier to the remote node. |
| 2802 | * @retry: number of retries to the command IOCB. |
| 2803 | * |
| 2804 | * This routine issues a Fibre Channel Address Resolution Response |
| 2805 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2806 | * is passed into the function. It first search the @vport node list to find |
| 2807 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2808 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2809 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2810 | * |
| 2811 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2812 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2813 | * will be stored into the context1 field of the IOCB for the completion |
| 2814 | * callback function to the PARPR ELS command. |
| 2815 | * |
| 2816 | * Return code |
| 2817 | * 0 - Successfully issued farpr command |
| 2818 | * 1 - Failed to issue farpr command |
| 2819 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2820 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2821 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2822 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2823 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2824 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2825 | FARP *fp; |
| 2826 | uint8_t *pcmd; |
| 2827 | uint32_t *lp; |
| 2828 | uint16_t cmdsize; |
| 2829 | struct lpfc_nodelist *ondlp; |
| 2830 | struct lpfc_nodelist *ndlp; |
| 2831 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2832 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2833 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2834 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2835 | if (!ndlp) { |
| 2836 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2837 | if (!ndlp) |
| 2838 | return 1; |
| 2839 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2840 | lpfc_enqueue_node(vport, ndlp); |
| 2841 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2842 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2843 | if (!ndlp) |
| 2844 | return 1; |
| 2845 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2846 | |
| 2847 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2848 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2849 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2850 | /* This will trigger the release of the node just |
| 2851 | * allocated |
| 2852 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2853 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2854 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2855 | } |
| 2856 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2858 | |
| 2859 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2860 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2861 | |
| 2862 | /* Fill in FARPR payload */ |
| 2863 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2864 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2865 | lp = (uint32_t *) pcmd; |
| 2866 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2867 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2868 | fp->Rflags = 0; |
| 2869 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2870 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2871 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2872 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2873 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2874 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2875 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2876 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2877 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2878 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2879 | } |
| 2880 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2881 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2882 | "Issue FARPR: did:x%x", |
| 2883 | ndlp->nlp_DID, 0, 0); |
| 2884 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2885 | phba->fc_stat.elsXmitFARPR++; |
| 2886 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2887 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2888 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2889 | /* The additional lpfc_nlp_put will cause the following |
| 2890 | * lpfc_els_free_iocb routine to trigger the release of |
| 2891 | * the node. |
| 2892 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2893 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2894 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2895 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2896 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2897 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2898 | * trigger the release of the node. |
| 2899 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2900 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2901 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2902 | } |
| 2903 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2904 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2905 | * 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] | 2906 | * @vport: pointer to a host virtual N_Port data structure. |
| 2907 | * @nlp: pointer to a node-list data structure. |
| 2908 | * |
| 2909 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2910 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2911 | * removes the ELS retry event if it presents. In addition, if the |
| 2912 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2913 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2914 | * ADISC. |
| 2915 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2916 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2917 | 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] | 2918 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2919 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2920 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2921 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2922 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2923 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2924 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2925 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2926 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2927 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2928 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2929 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2930 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2931 | /* Decrement nlp reference count held for the delayed retry */ |
| 2932 | evtp = &nlp->els_retry_evt; |
| 2933 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2934 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2935 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2936 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2937 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2938 | spin_unlock_irq(shost->host_lock); |
| 2939 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2940 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2941 | /* Check if there are more ADISCs to be sent */ |
| 2942 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2943 | } else { |
| 2944 | /* Check if there are more PLOGIs to be sent */ |
| 2945 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2946 | if (vport->num_disc_nodes == 0) { |
| 2947 | spin_lock_irq(shost->host_lock); |
| 2948 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2949 | spin_unlock_irq(shost->host_lock); |
| 2950 | lpfc_can_disctmo(vport); |
| 2951 | lpfc_end_rscn(vport); |
| 2952 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2953 | } |
| 2954 | } |
| 2955 | } |
| 2956 | return; |
| 2957 | } |
| 2958 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2959 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2960 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2961 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2962 | * |
| 2963 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2964 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2965 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2966 | * adds the delayed events to the HBA work list and invokes the |
| 2967 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2968 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2969 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2970 | * reference to ndlp will still be available when the worker thread gets |
| 2971 | * to the event associated with the ndlp. |
| 2972 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2973 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2974 | lpfc_els_retry_delay(unsigned long ptr) |
| 2975 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2976 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2977 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2978 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2979 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2980 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2981 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2982 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2984 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2985 | return; |
| 2986 | } |
| 2987 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2988 | /* We need to hold the node by incrementing the reference |
| 2989 | * count until the queued work is done |
| 2990 | */ |
| 2991 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2992 | if (evtp->evt_arg1) { |
| 2993 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2994 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2995 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2996 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2997 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2998 | return; |
| 2999 | } |
| 3000 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3001 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3002 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3003 | * @ndlp: pointer to a node-list data structure. |
| 3004 | * |
| 3005 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 3006 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 3007 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 3008 | * function according to the delayed ELS command to retry the command. |
| 3009 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3010 | void |
| 3011 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 3012 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3013 | struct lpfc_vport *vport = ndlp->vport; |
| 3014 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3015 | uint32_t cmd, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3016 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3017 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3018 | cmd = ndlp->nlp_last_elscmd; |
| 3019 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3020 | |
| 3021 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3022 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3023 | return; |
| 3024 | } |
| 3025 | |
| 3026 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3027 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 3028 | /* |
| 3029 | * If a discovery event readded nlp_delayfunc after timer |
| 3030 | * firing and before processing the timer, cancel the |
| 3031 | * nlp_delayfunc. |
| 3032 | */ |
| 3033 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3034 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3035 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3036 | |
| 3037 | switch (cmd) { |
| 3038 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3039 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3040 | break; |
| 3041 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3042 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3043 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3044 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3045 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3046 | break; |
| 3047 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3048 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3049 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3050 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3051 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3052 | break; |
| 3053 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3054 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3055 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3056 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3057 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3058 | break; |
| 3059 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3060 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3061 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3062 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3063 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3064 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3065 | case ELS_CMD_FDISC: |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3066 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
| 3067 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3068 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3069 | } |
| 3070 | return; |
| 3071 | } |
| 3072 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3073 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3074 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3075 | * @phba: pointer to lpfc hba data structure. |
| 3076 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3077 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3078 | * |
| 3079 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 3080 | * failed. The following ELS IOCBs use this function for retrying the command |
| 3081 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 3082 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 3083 | * returned error status, it makes the decision whether a retry shall be |
| 3084 | * issued for the command, and whether a retry shall be made immediately or |
| 3085 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 3086 | * is called to retry the command. In the later case, the ELS command shall |
| 3087 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 3088 | * ndlp for the delayed command issusing. |
| 3089 | * |
| 3090 | * Return code |
| 3091 | * 0 - No retry of els command is made |
| 3092 | * 1 - Immediate or delayed retry of els command is made |
| 3093 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3094 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3095 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3096 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3098 | struct lpfc_vport *vport = cmdiocb->vport; |
| 3099 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3100 | IOCB_t *irsp = &rspiocb->iocb; |
| 3101 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3102 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3103 | uint32_t *elscmd; |
| 3104 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3105 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3106 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3107 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3108 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3109 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3110 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3111 | /* Note: context2 may be 0 for internal driver abort |
| 3112 | * of delays ELS command. |
| 3113 | */ |
| 3114 | |
| 3115 | if (pcmd && pcmd->virt) { |
| 3116 | elscmd = (uint32_t *) (pcmd->virt); |
| 3117 | cmd = *elscmd++; |
| 3118 | } |
| 3119 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3120 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3121 | did = ndlp->nlp_DID; |
| 3122 | else { |
| 3123 | /* We should only hit this case for retrying PLOGI */ |
| 3124 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3125 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3126 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 3127 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3128 | return 1; |
| 3129 | } |
| 3130 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3131 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3132 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 3133 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 3134 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3135 | switch (irsp->ulpStatus) { |
| 3136 | case IOSTAT_FCP_RSP_ERROR: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3137 | break; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3138 | case IOSTAT_REMOTE_STOP: |
| 3139 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3140 | /* This IO was aborted by the target, we don't |
| 3141 | * know the rxid and because we did not send the |
| 3142 | * ABTS we cannot generate and RRQ. |
| 3143 | */ |
| 3144 | lpfc_set_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 3145 | cmdiocb->sli4_lxritag, 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3146 | } |
| 3147 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3148 | case IOSTAT_LOCAL_REJECT: |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3149 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3150 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3151 | if (cmd == ELS_CMD_FLOGI) { |
| 3152 | if (PCI_DEVICE_ID_HORNET == |
| 3153 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3154 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3155 | phba->pport->fc_myDID = 0; |
| 3156 | phba->alpa_map[0] = 0; |
| 3157 | phba->alpa_map[1] = 0; |
| 3158 | } |
| 3159 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3160 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3161 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3162 | retry = 1; |
| 3163 | break; |
| 3164 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3165 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3166 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3167 | "0124 Retry illegal cmd x%x " |
| 3168 | "retry:x%x delay:x%x\n", |
| 3169 | cmd, cmdiocb->retry, delay); |
| 3170 | retry = 1; |
| 3171 | /* All command's retry policy */ |
| 3172 | maxretry = 8; |
| 3173 | if (cmdiocb->retry > 2) |
| 3174 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3175 | break; |
| 3176 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3177 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3178 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3179 | retry = 1; |
| 3180 | if (cmdiocb->retry > 100) |
| 3181 | delay = 100; |
| 3182 | maxretry = 250; |
| 3183 | break; |
| 3184 | |
| 3185 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3186 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3187 | retry = 1; |
| 3188 | break; |
| 3189 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3190 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3191 | case IOERR_INVALID_RPI: |
James Smart | 5b5b36a | 2013-01-03 15:43:19 -0500 | [diff] [blame] | 3192 | if (cmd == ELS_CMD_PLOGI && |
| 3193 | did == NameServer_DID) { |
| 3194 | /* Continue forever if plogi to */ |
| 3195 | /* the nameserver fails */ |
| 3196 | maxretry = 0; |
| 3197 | delay = 100; |
| 3198 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3199 | retry = 1; |
| 3200 | break; |
| 3201 | } |
| 3202 | break; |
| 3203 | |
| 3204 | case IOSTAT_NPORT_RJT: |
| 3205 | case IOSTAT_FABRIC_RJT: |
| 3206 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 3207 | retry = 1; |
| 3208 | break; |
| 3209 | } |
| 3210 | break; |
| 3211 | |
| 3212 | case IOSTAT_NPORT_BSY: |
| 3213 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3214 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3215 | retry = 1; |
| 3216 | break; |
| 3217 | |
| 3218 | case IOSTAT_LS_RJT: |
| 3219 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 3220 | /* Added for Vendor specifc support |
| 3221 | * Just keep retrying for these Rsn / Exp codes |
| 3222 | */ |
| 3223 | switch (stat.un.b.lsRjtRsnCode) { |
| 3224 | case LSRJT_UNABLE_TPC: |
| 3225 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3226 | LSEXP_CMD_IN_PROGRESS) { |
| 3227 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3228 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3229 | maxretry = 48; |
| 3230 | } |
| 3231 | retry = 1; |
| 3232 | break; |
| 3233 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3234 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3235 | LSEXP_CANT_GIVE_DATA) { |
| 3236 | if (cmd == ELS_CMD_PLOGI) { |
| 3237 | delay = 1000; |
| 3238 | maxretry = 48; |
| 3239 | } |
| 3240 | retry = 1; |
| 3241 | break; |
| 3242 | } |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 3243 | if ((cmd == ELS_CMD_PLOGI) || |
| 3244 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3245 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3246 | maxretry = lpfc_max_els_tries + 1; |
| 3247 | retry = 1; |
| 3248 | break; |
| 3249 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3250 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3251 | (cmd == ELS_CMD_FDISC) && |
| 3252 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3253 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3254 | "0125 FDISC Failed (x%x). " |
| 3255 | "Fabric out of resources\n", |
| 3256 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3257 | lpfc_vport_set_state(vport, |
| 3258 | FC_VPORT_NO_FABRIC_RSCS); |
| 3259 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3260 | break; |
| 3261 | |
| 3262 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3263 | if ((cmd == ELS_CMD_PLOGI) || |
| 3264 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3265 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3267 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3268 | /* FDISC retry policy */ |
| 3269 | maxretry = 48; |
| 3270 | if (cmdiocb->retry >= 32) |
| 3271 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3272 | } |
| 3273 | retry = 1; |
| 3274 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3275 | |
| 3276 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3277 | /* There are some cases where switches return this |
| 3278 | * error when they are not ready and should be returning |
| 3279 | * Logical Busy. We should delay every time. |
| 3280 | */ |
| 3281 | if (cmd == ELS_CMD_FDISC && |
| 3282 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 3283 | maxretry = 3; |
| 3284 | delay = 1000; |
| 3285 | retry = 1; |
| 3286 | break; |
| 3287 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3288 | case LSRJT_PROTOCOL_ERR: |
| 3289 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3290 | (cmd == ELS_CMD_FDISC) && |
| 3291 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 3292 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 3293 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3294 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3295 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3296 | "Fabric Detected Bad WWN\n", |
| 3297 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3298 | lpfc_vport_set_state(vport, |
| 3299 | FC_VPORT_FABRIC_REJ_WWN); |
| 3300 | } |
| 3301 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3302 | } |
| 3303 | break; |
| 3304 | |
| 3305 | case IOSTAT_INTERMED_RSP: |
| 3306 | case IOSTAT_BA_RJT: |
| 3307 | break; |
| 3308 | |
| 3309 | default: |
| 3310 | break; |
| 3311 | } |
| 3312 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3313 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3314 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3315 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3316 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3317 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 3318 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3319 | /* FLOGI retry policy */ |
| 3320 | retry = 1; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3321 | /* retry FLOGI forever */ |
James Smart | 6eae430 | 2015-04-07 15:07:23 -0400 | [diff] [blame] | 3322 | if (phba->link_flag != LS_LOOPBACK_MODE) |
| 3323 | maxretry = 0; |
| 3324 | else |
| 3325 | maxretry = 2; |
| 3326 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3327 | if (cmdiocb->retry >= 100) |
| 3328 | delay = 5000; |
| 3329 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3330 | delay = 1000; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3331 | } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) { |
| 3332 | /* retry FDISCs every second up to devloss */ |
| 3333 | retry = 1; |
| 3334 | maxretry = vport->cfg_devloss_tmo; |
| 3335 | delay = 1000; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3336 | } |
| 3337 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3338 | cmdiocb->retry++; |
| 3339 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3340 | phba->fc_stat.elsRetryExceeded++; |
| 3341 | retry = 0; |
| 3342 | } |
| 3343 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3344 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 3345 | retry = 0; |
| 3346 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3347 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3348 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 3349 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 3350 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 3351 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3352 | "2849 Stop retry ELS command " |
| 3353 | "x%x to remote NPORT x%x, " |
| 3354 | "Data: x%x x%x\n", cmd, did, |
| 3355 | cmdiocb->retry, delay); |
| 3356 | return 0; |
| 3357 | } |
| 3358 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3359 | |
| 3360 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3361 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3362 | "0107 Retry ELS command x%x to remote " |
| 3363 | "NPORT x%x Data: x%x x%x\n", |
| 3364 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3365 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3366 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 3367 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3368 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 3369 | IOERR_NO_RESOURCES))) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3370 | /* Don't reset timer for no resources */ |
| 3371 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3372 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3373 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3374 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3375 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3379 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3380 | phba->fc_stat.elsDelayRetry++; |
| 3381 | ndlp->nlp_retry = cmdiocb->retry; |
| 3382 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3383 | /* delay is specified in milliseconds */ |
| 3384 | mod_timer(&ndlp->nlp_delayfunc, |
| 3385 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3386 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3387 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3388 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3389 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3390 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3391 | if (cmd == ELS_CMD_PRLI) |
| 3392 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 3393 | NLP_STE_PRLI_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3394 | else |
| 3395 | lpfc_nlp_set_state(vport, ndlp, |
| 3396 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | ndlp->nlp_last_elscmd = cmd; |
| 3398 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3399 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3400 | } |
| 3401 | switch (cmd) { |
| 3402 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3403 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3404 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3405 | case ELS_CMD_FDISC: |
| 3406 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 3407 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3409 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3410 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3411 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3412 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3413 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3414 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3415 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3416 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3417 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3418 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3419 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3420 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3421 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3422 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3423 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 3424 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3425 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3426 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3427 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3428 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3429 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3430 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3431 | } |
| 3432 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3433 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3434 | if (logerr) { |
| 3435 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3436 | "0137 No retry ELS command x%x to remote " |
| 3437 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 3438 | cmd, did, irsp->ulpStatus, |
| 3439 | irsp->un.ulpWord[4]); |
| 3440 | } |
| 3441 | else { |
| 3442 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3443 | "0108 No retry ELS command x%x to remote " |
| 3444 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 3445 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 3446 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3447 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3448 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3449 | } |
| 3450 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3451 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3452 | * 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] | 3453 | * @phba: pointer to lpfc hba data structure. |
| 3454 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3455 | * |
| 3456 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3457 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3458 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3459 | * response of the command IOCB. If so, it will be released before releasing |
| 3460 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3461 | * |
| 3462 | * Return code |
| 3463 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3464 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3465 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3466 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3467 | { |
| 3468 | struct lpfc_dmabuf *buf_ptr; |
| 3469 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3470 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3471 | if (!list_empty(&buf_ptr1->list)) { |
| 3472 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3473 | struct lpfc_dmabuf, |
| 3474 | list); |
| 3475 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3476 | kfree(buf_ptr); |
| 3477 | } |
| 3478 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3479 | kfree(buf_ptr1); |
| 3480 | return 0; |
| 3481 | } |
| 3482 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3483 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3484 | * 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] | 3485 | * @phba: pointer to lpfc hba data structure. |
| 3486 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3487 | * |
| 3488 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3489 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3490 | * pool. |
| 3491 | * |
| 3492 | * Return code |
| 3493 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3494 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3495 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3496 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3497 | { |
| 3498 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3499 | kfree(buf_ptr); |
| 3500 | return 0; |
| 3501 | } |
| 3502 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3503 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3504 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3505 | * @phba: pointer to lpfc hba data structure. |
| 3506 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3507 | * |
| 3508 | * This routine frees a command IOCB and its associated resources. The |
| 3509 | * command IOCB data structure contains the reference to various associated |
| 3510 | * resources, these fields must be set to NULL if the associated reference |
| 3511 | * not present: |
| 3512 | * context1 - reference to ndlp |
| 3513 | * context2 - reference to cmd |
| 3514 | * context2->next - reference to rsp |
| 3515 | * context3 - reference to bpl |
| 3516 | * |
| 3517 | * It first properly decrements the reference count held on ndlp for the |
| 3518 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3519 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3520 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3521 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3522 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3523 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3524 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3525 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3526 | * |
| 3527 | * Return code |
| 3528 | * 0 - Success (currently, always return 0) |
| 3529 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3530 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3531 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3532 | { |
| 3533 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3534 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3535 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3536 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3537 | if (ndlp) { |
| 3538 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3539 | lpfc_nlp_put(ndlp); |
| 3540 | |
| 3541 | /* If the ndlp is not being used by another discovery |
| 3542 | * thread, free it. |
| 3543 | */ |
| 3544 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3545 | /* If ndlp is being used by another discovery |
| 3546 | * thread, just clear NLP_DEFER_RM |
| 3547 | */ |
| 3548 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3549 | } |
| 3550 | } |
| 3551 | else |
| 3552 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3553 | elsiocb->context1 = NULL; |
| 3554 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3555 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3556 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3557 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3558 | /* Firmware could still be in progress of DMAing |
| 3559 | * payload, so don't free data buffer till after |
| 3560 | * a hbeat. |
| 3561 | */ |
| 3562 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3563 | buf_ptr = elsiocb->context2; |
| 3564 | elsiocb->context2 = NULL; |
| 3565 | if (buf_ptr) { |
| 3566 | buf_ptr1 = NULL; |
| 3567 | spin_lock_irq(&phba->hbalock); |
| 3568 | if (!list_empty(&buf_ptr->list)) { |
| 3569 | list_remove_head(&buf_ptr->list, |
| 3570 | buf_ptr1, struct lpfc_dmabuf, |
| 3571 | list); |
| 3572 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3573 | list_add_tail(&buf_ptr1->list, |
| 3574 | &phba->elsbuf); |
| 3575 | phba->elsbuf_cnt++; |
| 3576 | } |
| 3577 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3578 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3579 | phba->elsbuf_cnt++; |
| 3580 | spin_unlock_irq(&phba->hbalock); |
| 3581 | } |
| 3582 | } else { |
| 3583 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3584 | lpfc_els_free_data(phba, buf_ptr1); |
| 3585 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | if (elsiocb->context3) { |
| 3589 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3590 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3592 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3593 | return 0; |
| 3594 | } |
| 3595 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3596 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3597 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3598 | * @phba: pointer to lpfc hba data structure. |
| 3599 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3600 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3601 | * |
| 3602 | * This routine is the completion callback function to the Logout (LOGO) |
| 3603 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3604 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3605 | * release the ndlp if it has the last reference remaining (reference count |
| 3606 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3607 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3608 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3609 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3610 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3611 | * IOCB data structure. |
| 3612 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3613 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3614 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3615 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3616 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3617 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3618 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3619 | IOCB_t *irsp; |
| 3620 | |
| 3621 | irsp = &rspiocb->iocb; |
| 3622 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3623 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3624 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3625 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3626 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3627 | "0109 ACC to LOGO completes to NPort x%x " |
| 3628 | "Data: x%x x%x x%x\n", |
| 3629 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3630 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3631 | |
| 3632 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3633 | /* NPort Recovery mode or node is just allocated */ |
| 3634 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3635 | /* If the ndlp is being used by another discovery |
| 3636 | * thread, just unregister the RPI. |
| 3637 | */ |
| 3638 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3639 | } else { |
| 3640 | /* Indicate the node has already released, should |
| 3641 | * not reference to it from within lpfc_els_free_iocb. |
| 3642 | */ |
| 3643 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3644 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3645 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3646 | |
| 3647 | /* |
| 3648 | * 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] | 3649 | * At this point, the driver is done so release the IOCB |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3650 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3651 | lpfc_els_free_iocb(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3652 | } |
| 3653 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3654 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3655 | * 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] | 3656 | * @phba: pointer to lpfc hba data structure. |
| 3657 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3658 | * |
| 3659 | * This routine is the completion callback function for unregister default |
| 3660 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3661 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3662 | * decrements the ndlp reference count held for this completion callback |
| 3663 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3664 | * whether there is only one reference left on the ndlp. If so, it will |
| 3665 | * perform one more decrement and trigger the release of the ndlp. |
| 3666 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3667 | void |
| 3668 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3669 | { |
| 3670 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3671 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3672 | |
| 3673 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3674 | pmb->context2 = NULL; |
| 3675 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3676 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3677 | kfree(mp); |
| 3678 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3679 | if (ndlp) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3680 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3681 | "0006 rpi%x DID:%x flg:%x %d map:%x %p\n", |
| 3682 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
| 3683 | atomic_read(&ndlp->kref.refcount), |
| 3684 | ndlp->nlp_usg_map, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3685 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 3686 | lpfc_nlp_put(ndlp); |
| 3687 | /* This is the end of the default RPI cleanup logic for |
| 3688 | * this ndlp. If no other discovery threads are using |
| 3689 | * this ndlp, free all resources associated with it. |
| 3690 | */ |
| 3691 | lpfc_nlp_not_used(ndlp); |
| 3692 | } else { |
| 3693 | lpfc_drop_node(ndlp->vport, ndlp); |
| 3694 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3695 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3696 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3697 | return; |
| 3698 | } |
| 3699 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3700 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3701 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3702 | * @phba: pointer to lpfc hba data structure. |
| 3703 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3704 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3705 | * |
| 3706 | * This routine is the completion callback function for ELS Response IOCB |
| 3707 | * command. In normal case, this callback function just properly sets the |
| 3708 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3709 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3710 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3711 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3712 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3713 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3714 | * are currently referring it. |
| 3715 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3717 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3718 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3719 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3720 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3721 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3722 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3723 | IOCB_t *irsp; |
| 3724 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3725 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3726 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3727 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3728 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3729 | irsp = &rspiocb->iocb; |
| 3730 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3731 | if (cmdiocb->context_un.mbox) |
| 3732 | mbox = cmdiocb->context_un.mbox; |
| 3733 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3734 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3735 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3736 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3737 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3738 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3739 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3740 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3741 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3742 | */ |
| 3743 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3744 | ls_rjt = 1; |
| 3745 | } |
| 3746 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3747 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3748 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3749 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3750 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3751 | if (mp) { |
| 3752 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3753 | kfree(mp); |
| 3754 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3755 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3756 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3757 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3758 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3759 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3760 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3761 | /* Indicate the node has already released, |
| 3762 | * should not reference to it from within |
| 3763 | * the routine lpfc_els_free_iocb. |
| 3764 | */ |
| 3765 | cmdiocb->context1 = NULL; |
| 3766 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3767 | goto out; |
| 3768 | } |
| 3769 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3770 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3771 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3772 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3773 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3774 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3775 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3776 | "0110 ELS response tag x%x completes " |
| 3777 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3778 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3779 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3780 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3781 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3782 | if (mbox) { |
| 3783 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3784 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3785 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3786 | /* Increment reference count to ndlp to hold the |
| 3787 | * reference to ndlp for the callback function. |
| 3788 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3789 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3790 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3791 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3792 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3793 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3794 | } |
| 3795 | else { |
| 3796 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3797 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3798 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3799 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3800 | } |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3801 | |
| 3802 | ndlp->nlp_flag |= NLP_REG_LOGIN_SEND; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3803 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3804 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3805 | goto out; |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3806 | |
| 3807 | /* Decrement the ndlp reference count we |
| 3808 | * set for this failed mailbox command. |
| 3809 | */ |
| 3810 | lpfc_nlp_put(ndlp); |
| 3811 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3812 | |
| 3813 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3814 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3815 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3816 | "Data: x%x x%x x%x\n", |
| 3817 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3818 | ndlp->nlp_rpi); |
| 3819 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3820 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3821 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3822 | /* Indicate node has already been released, |
| 3823 | * should not reference to it from within |
| 3824 | * the routine lpfc_els_free_iocb. |
| 3825 | */ |
| 3826 | cmdiocb->context1 = NULL; |
| 3827 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3828 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3829 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3830 | if (!lpfc_error_lost_link(irsp) && |
| 3831 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3832 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3833 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3834 | /* Indicate node has already been |
| 3835 | * released, should not reference |
| 3836 | * to it from within the routine |
| 3837 | * lpfc_els_free_iocb. |
| 3838 | */ |
| 3839 | cmdiocb->context1 = NULL; |
| 3840 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3841 | } |
| 3842 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3843 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3844 | if (mp) { |
| 3845 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3846 | kfree(mp); |
| 3847 | } |
| 3848 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | } |
| 3850 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3851 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3852 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3853 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3854 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3855 | |
| 3856 | /* If the node is not being used by another discovery thread, |
| 3857 | * and we are sending a reject, we are done with it. |
| 3858 | * Release driver reference count here and free associated |
| 3859 | * resources. |
| 3860 | */ |
| 3861 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3862 | if (lpfc_nlp_not_used(ndlp)) |
| 3863 | /* Indicate node has already been released, |
| 3864 | * should not reference to it from within |
| 3865 | * the routine lpfc_els_free_iocb. |
| 3866 | */ |
| 3867 | cmdiocb->context1 = NULL; |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3868 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3869 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3870 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3871 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3872 | return; |
| 3873 | } |
| 3874 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3875 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3876 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3877 | * @vport: pointer to a host virtual N_Port data structure. |
| 3878 | * @flag: the els command code to be accepted. |
| 3879 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3880 | * @ndlp: pointer to a node-list data structure. |
| 3881 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3882 | * |
| 3883 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3884 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3885 | * specific ACC response command to be issued and invokes the |
| 3886 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3887 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3888 | * field of the IOCB for the completion callback function to issue the |
| 3889 | * mailbox command to the HBA later when callback is invoked. |
| 3890 | * |
| 3891 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3892 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3893 | * will be stored into the context1 field of the IOCB for the completion |
| 3894 | * callback function to the corresponding response ELS IOCB command. |
| 3895 | * |
| 3896 | * Return code |
| 3897 | * 0 - Successfully issued acc response |
| 3898 | * 1 - Failed to issue acc response |
| 3899 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3900 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3901 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3902 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3903 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3904 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3905 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3906 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3907 | IOCB_t *icmd; |
| 3908 | IOCB_t *oldcmd; |
| 3909 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3910 | uint8_t *pcmd; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3911 | struct serv_parm *sp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3912 | uint16_t cmdsize; |
| 3913 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3914 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3915 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3916 | oldcmd = &oldiocb->iocb; |
| 3917 | |
| 3918 | switch (flag) { |
| 3919 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3920 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3921 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3922 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3923 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3924 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3925 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3926 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3927 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3928 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3929 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3930 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3931 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3932 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3933 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3934 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3935 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3936 | |
| 3937 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3938 | "Issue ACC: did:x%x flg:x%x", |
| 3939 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3940 | break; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3941 | case ELS_CMD_FLOGI: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3942 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3943 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3944 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3945 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3946 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3947 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3948 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3949 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3950 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3951 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3952 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3953 | |
| 3954 | if (mbox) |
| 3955 | elsiocb->context_un.mbox = mbox; |
| 3956 | |
| 3957 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3958 | pcmd += sizeof(uint32_t); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3959 | sp = (struct serv_parm *)pcmd; |
| 3960 | |
| 3961 | if (flag == ELS_CMD_FLOGI) { |
| 3962 | /* Copy the received service parameters back */ |
| 3963 | memcpy(sp, &phba->fc_fabparam, |
| 3964 | sizeof(struct serv_parm)); |
| 3965 | |
| 3966 | /* Clear the F_Port bit */ |
| 3967 | sp->cmn.fPort = 0; |
| 3968 | |
| 3969 | /* Mark all class service parameters as invalid */ |
| 3970 | sp->cls1.classValid = 0; |
| 3971 | sp->cls2.classValid = 0; |
| 3972 | sp->cls3.classValid = 0; |
| 3973 | sp->cls4.classValid = 0; |
| 3974 | |
| 3975 | /* Copy our worldwide names */ |
| 3976 | memcpy(&sp->portName, &vport->fc_sparam.portName, |
| 3977 | sizeof(struct lpfc_name)); |
| 3978 | memcpy(&sp->nodeName, &vport->fc_sparam.nodeName, |
| 3979 | sizeof(struct lpfc_name)); |
| 3980 | } else { |
| 3981 | memcpy(pcmd, &vport->fc_sparam, |
| 3982 | sizeof(struct serv_parm)); |
| 3983 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3984 | |
| 3985 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3986 | "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3987 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3988 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3989 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3990 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3991 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3992 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3993 | if (!elsiocb) |
| 3994 | return 1; |
| 3995 | |
| 3996 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3997 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3998 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3999 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4000 | |
| 4001 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4002 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4003 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 4004 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 4005 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4006 | |
| 4007 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4008 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 4009 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4010 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4011 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4012 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4013 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4014 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4015 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4016 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 4017 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x " |
| 4018 | "fc_flag x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4019 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4020 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 4021 | ndlp->nlp_rpi, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4022 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4023 | spin_lock_irq(shost->host_lock); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4024 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4025 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND)) |
| 4026 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4027 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4028 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 4029 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4030 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4034 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4035 | if (rc == IOCB_ERROR) { |
| 4036 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4037 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4038 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4039 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4040 | } |
| 4041 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4042 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4043 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4044 | * @vport: pointer to a virtual N_Port data structure. |
| 4045 | * @rejectError: |
| 4046 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4047 | * @ndlp: pointer to a node-list data structure. |
| 4048 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4049 | * |
| 4050 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 4051 | * command. If a @mbox pointer is passed in, it will be put into the |
| 4052 | * context_un.mbox field of the IOCB for the completion callback function |
| 4053 | * to issue to the HBA later. |
| 4054 | * |
| 4055 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4056 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4057 | * will be stored into the context1 field of the IOCB for the completion |
| 4058 | * callback function to the reject response ELS IOCB command. |
| 4059 | * |
| 4060 | * Return code |
| 4061 | * 0 - Successfully issued reject response |
| 4062 | * 1 - Failed to issue reject response |
| 4063 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4064 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4065 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4066 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 4067 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4068 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4069 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4070 | IOCB_t *icmd; |
| 4071 | IOCB_t *oldcmd; |
| 4072 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4073 | uint8_t *pcmd; |
| 4074 | uint16_t cmdsize; |
| 4075 | int rc; |
| 4076 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4077 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4078 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4079 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4080 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4081 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 | |
| 4083 | icmd = &elsiocb->iocb; |
| 4084 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4085 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4086 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4087 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4088 | |
| 4089 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4090 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4091 | *((uint32_t *) (pcmd)) = rejectError; |
| 4092 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4093 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4094 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4095 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4096 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4097 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4098 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 4099 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4100 | "rpi x%x\n", |
| 4101 | rejectError, elsiocb->iotag, |
| 4102 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 4103 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4104 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4105 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 4106 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 4107 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4108 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4109 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4110 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4111 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4112 | if (rc == IOCB_ERROR) { |
| 4113 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4114 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4115 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4116 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4117 | } |
| 4118 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4119 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4120 | * 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] | 4121 | * @vport: pointer to a virtual N_Port data structure. |
| 4122 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4123 | * @ndlp: pointer to a node-list data structure. |
| 4124 | * |
| 4125 | * This routine prepares and issues an Accept (ACC) response to Address |
| 4126 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 4127 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4128 | * |
| 4129 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4130 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4131 | * will be stored into the context1 field of the IOCB for the completion |
| 4132 | * callback function to the ADISC Accept response ELS IOCB command. |
| 4133 | * |
| 4134 | * Return code |
| 4135 | * 0 - Successfully issued acc adisc response |
| 4136 | * 1 - Failed to issue adisc acc response |
| 4137 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4138 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4139 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 4140 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4141 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4142 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4143 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4144 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4145 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4146 | uint8_t *pcmd; |
| 4147 | uint16_t cmdsize; |
| 4148 | int rc; |
| 4149 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4150 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4151 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4152 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4153 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4154 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4155 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4156 | icmd = &elsiocb->iocb; |
| 4157 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4158 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4159 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4160 | |
| 4161 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4162 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4163 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 4164 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 4165 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4166 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4167 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4169 | |
| 4170 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4171 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4172 | |
| 4173 | ap = (ADISC *) (pcmd); |
| 4174 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4175 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4176 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4177 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4178 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4179 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4180 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 4181 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4182 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4183 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4184 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4185 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4186 | if (rc == IOCB_ERROR) { |
| 4187 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4188 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4189 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4190 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4191 | } |
| 4192 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4193 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4194 | * 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] | 4195 | * @vport: pointer to a virtual N_Port data structure. |
| 4196 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4197 | * @ndlp: pointer to a node-list data structure. |
| 4198 | * |
| 4199 | * This routine prepares and issues an Accept (ACC) response to Process |
| 4200 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 4201 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4202 | * |
| 4203 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4204 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4205 | * will be stored into the context1 field of the IOCB for the completion |
| 4206 | * callback function to the PRLI Accept response ELS IOCB command. |
| 4207 | * |
| 4208 | * Return code |
| 4209 | * 0 - Successfully issued acc prli response |
| 4210 | * 1 - Failed to issue acc prli response |
| 4211 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4212 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4213 | 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] | 4214 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4215 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4216 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4217 | PRLI *npr; |
| 4218 | lpfc_vpd_t *vpd; |
| 4219 | IOCB_t *icmd; |
| 4220 | IOCB_t *oldcmd; |
| 4221 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4222 | uint8_t *pcmd; |
| 4223 | uint16_t cmdsize; |
| 4224 | int rc; |
| 4225 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4226 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4227 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4228 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4229 | if (!elsiocb) |
| 4230 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4231 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4232 | icmd = &elsiocb->iocb; |
| 4233 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4234 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4235 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4236 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4237 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4238 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4239 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 4240 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4241 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4242 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4243 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4244 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4245 | |
| 4246 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4247 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4248 | |
| 4249 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4250 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4251 | |
| 4252 | npr = (PRLI *) pcmd; |
| 4253 | vpd = &phba->vpd; |
| 4254 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4255 | * If the remote port is a target and our firmware version is 3.20 or |
| 4256 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4257 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4258 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 4259 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4260 | npr->ConfmComplAllowed = 1; |
| 4261 | npr->Retry = 1; |
| 4262 | npr->TaskRetryIdReq = 1; |
| 4263 | } |
| 4264 | |
| 4265 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 4266 | npr->estabImagePair = 1; |
| 4267 | npr->readXferRdyDis = 1; |
| 4268 | npr->ConfmComplAllowed = 1; |
| 4269 | |
| 4270 | npr->prliType = PRLI_FCP_TYPE; |
| 4271 | npr->initiatorFunc = 1; |
| 4272 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4273 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4274 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 4275 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4276 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4277 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4278 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4279 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4280 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4281 | if (rc == IOCB_ERROR) { |
| 4282 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4283 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4284 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4285 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4286 | } |
| 4287 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4288 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4289 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4290 | * @vport: pointer to a virtual N_Port data structure. |
| 4291 | * @format: rnid command format. |
| 4292 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4293 | * @ndlp: pointer to a node-list data structure. |
| 4294 | * |
| 4295 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 4296 | * (ACC) response. It constructs the RNID ACC response command according to |
| 4297 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 4298 | * issue the response. Note that this command does not need to hold the ndlp |
| 4299 | * reference count for the callback. So, the ndlp reference count taken by |
| 4300 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 4301 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 4302 | * there is no ndlp reference available. |
| 4303 | * |
| 4304 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4305 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4306 | * will be stored into the context1 field of the IOCB for the completion |
| 4307 | * callback function. However, for the RNID Accept Response ELS command, |
| 4308 | * this is undone later by this routine after the IOCB is allocated. |
| 4309 | * |
| 4310 | * Return code |
| 4311 | * 0 - Successfully issued acc rnid response |
| 4312 | * 1 - Failed to issue acc rnid response |
| 4313 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4314 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4315 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4316 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4317 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4318 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4319 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4320 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4321 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4322 | uint8_t *pcmd; |
| 4323 | uint16_t cmdsize; |
| 4324 | int rc; |
| 4325 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4326 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 4327 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4328 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4329 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4330 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4331 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4332 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4333 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4334 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4335 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4336 | icmd = &elsiocb->iocb; |
| 4337 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4338 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4339 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4340 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4341 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4342 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4343 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 4344 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4345 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4346 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4347 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4348 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4349 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4350 | rn = (RNID *) (pcmd); |
| 4351 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4352 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 4353 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4354 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4355 | switch (format) { |
| 4356 | case 0: |
| 4357 | rn->SpecificLen = 0; |
| 4358 | break; |
| 4359 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4360 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4361 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4362 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4363 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 4364 | rn->un.topologyDisc.physPort = 0; |
| 4365 | rn->un.topologyDisc.attachedNodes = 0; |
| 4366 | break; |
| 4367 | default: |
| 4368 | rn->CommonLen = 0; |
| 4369 | rn->SpecificLen = 0; |
| 4370 | break; |
| 4371 | } |
| 4372 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4373 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4374 | "Issue ACC RNID: did:x%x flg:x%x", |
| 4375 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4376 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4377 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4378 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4379 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4380 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4381 | if (rc == IOCB_ERROR) { |
| 4382 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4383 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4384 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4385 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4386 | } |
| 4387 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4388 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4389 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. |
| 4390 | * @vport: pointer to a virtual N_Port data structure. |
| 4391 | * @iocb: pointer to the lpfc command iocb data structure. |
| 4392 | * @ndlp: pointer to a node-list data structure. |
| 4393 | * |
| 4394 | * Return |
| 4395 | **/ |
| 4396 | static void |
| 4397 | lpfc_els_clear_rrq(struct lpfc_vport *vport, |
| 4398 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
| 4399 | { |
| 4400 | struct lpfc_hba *phba = vport->phba; |
| 4401 | uint8_t *pcmd; |
| 4402 | struct RRQ *rrq; |
| 4403 | uint16_t rxid; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4404 | uint16_t xri; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4405 | struct lpfc_node_rrq *prrq; |
| 4406 | |
| 4407 | |
| 4408 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); |
| 4409 | pcmd += sizeof(uint32_t); |
| 4410 | rrq = (struct RRQ *)pcmd; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4411 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4412 | rxid = bf_get(rrq_rxid, rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4413 | |
| 4414 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4415 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" |
| 4416 | " x%x x%x\n", |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4417 | be32_to_cpu(bf_get(rrq_did, rrq)), |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4418 | bf_get(rrq_oxid, rrq), |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4419 | rxid, |
| 4420 | iocb->iotag, iocb->iocb.ulpContext); |
| 4421 | |
| 4422 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4423 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", |
| 4424 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4425 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4426 | xri = bf_get(rrq_oxid, rrq); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4427 | else |
| 4428 | xri = rxid; |
| 4429 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4430 | if (prrq) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4431 | lpfc_clr_rrq_active(phba, xri, prrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4432 | return; |
| 4433 | } |
| 4434 | |
| 4435 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4436 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 4437 | * @vport: pointer to a virtual N_Port data structure. |
| 4438 | * @data: pointer to echo data to return in the accept. |
| 4439 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4440 | * @ndlp: pointer to a node-list data structure. |
| 4441 | * |
| 4442 | * Return code |
| 4443 | * 0 - Successfully issued acc echo response |
| 4444 | * 1 - Failed to issue acc echo response |
| 4445 | **/ |
| 4446 | static int |
| 4447 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 4448 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 4449 | { |
| 4450 | struct lpfc_hba *phba = vport->phba; |
| 4451 | struct lpfc_iocbq *elsiocb; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4452 | uint8_t *pcmd; |
| 4453 | uint16_t cmdsize; |
| 4454 | int rc; |
| 4455 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4456 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 4457 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4458 | /* The accumulated length can exceed the BPL_SIZE. For |
| 4459 | * now, use this as the limit |
| 4460 | */ |
| 4461 | if (cmdsize > LPFC_BPL_SIZE) |
| 4462 | cmdsize = LPFC_BPL_SIZE; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4463 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4464 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4465 | if (!elsiocb) |
| 4466 | return 1; |
| 4467 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4468 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 4469 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; |
| 4470 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4471 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 4472 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4473 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 4474 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 4475 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4476 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4477 | pcmd += sizeof(uint32_t); |
| 4478 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 4479 | |
| 4480 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4481 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 4482 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4483 | |
| 4484 | phba->fc_stat.elsXmitACC++; |
| 4485 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4486 | |
| 4487 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4488 | if (rc == IOCB_ERROR) { |
| 4489 | lpfc_els_free_iocb(phba, elsiocb); |
| 4490 | return 1; |
| 4491 | } |
| 4492 | return 0; |
| 4493 | } |
| 4494 | |
| 4495 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4496 | * 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] | 4497 | * @vport: pointer to a host virtual N_Port data structure. |
| 4498 | * |
| 4499 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 4500 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 4501 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 4502 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 4503 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 4504 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 4505 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 4506 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 4507 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 4508 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 4509 | * no more ADISC need to be sent. |
| 4510 | * |
| 4511 | * Return code |
| 4512 | * The number of N_Ports with adisc issued. |
| 4513 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4514 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4515 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4516 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4517 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4518 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4519 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4520 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4521 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4522 | 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] | 4523 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4524 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4525 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4526 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4527 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4528 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4529 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4530 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4531 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4532 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4533 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4534 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4535 | vport->num_disc_nodes++; |
| 4536 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4537 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4538 | spin_lock_irq(shost->host_lock); |
| 4539 | vport->fc_flag |= FC_NLP_MORE; |
| 4540 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4541 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4542 | } |
| 4543 | } |
| 4544 | } |
| 4545 | if (sentadisc == 0) { |
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); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4549 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4550 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4551 | } |
| 4552 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4553 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4554 | * 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] | 4555 | * @vport: pointer to a host virtual N_Port data structure. |
| 4556 | * |
| 4557 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4558 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4559 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4560 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4561 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4562 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4563 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4564 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4565 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4566 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4567 | * PLOGI need to be sent. |
| 4568 | * |
| 4569 | * Return code |
| 4570 | * The number of N_Ports with plogi issued. |
| 4571 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4572 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4573 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4574 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4575 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4576 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4577 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4578 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4579 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4580 | 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] | 4581 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4582 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4583 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4584 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4585 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4586 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4587 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4588 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4589 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4590 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4591 | vport->num_disc_nodes++; |
| 4592 | if (vport->num_disc_nodes >= |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4593 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4594 | spin_lock_irq(shost->host_lock); |
| 4595 | vport->fc_flag |= FC_NLP_MORE; |
| 4596 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4597 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4598 | } |
| 4599 | } |
| 4600 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4601 | if (sentplogi) { |
| 4602 | lpfc_set_disctmo(vport); |
| 4603 | } |
| 4604 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4605 | spin_lock_irq(shost->host_lock); |
| 4606 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4607 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4608 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4609 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4610 | } |
| 4611 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4612 | uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4613 | lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc, |
| 4614 | uint32_t word0) |
| 4615 | { |
| 4616 | |
| 4617 | desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG); |
| 4618 | desc->payload.els_req = word0; |
| 4619 | desc->length = cpu_to_be32(sizeof(desc->payload)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4620 | |
| 4621 | return sizeof(struct fc_rdp_link_service_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4622 | } |
| 4623 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4624 | uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4625 | lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc, |
| 4626 | uint8_t *page_a0, uint8_t *page_a2) |
| 4627 | { |
| 4628 | uint16_t wavelength; |
| 4629 | uint16_t temperature; |
| 4630 | uint16_t rx_power; |
| 4631 | uint16_t tx_bias; |
| 4632 | uint16_t tx_power; |
| 4633 | uint16_t vcc; |
| 4634 | uint16_t flag = 0; |
| 4635 | struct sff_trasnceiver_codes_byte4 *trasn_code_byte4; |
| 4636 | struct sff_trasnceiver_codes_byte5 *trasn_code_byte5; |
| 4637 | |
| 4638 | desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG); |
| 4639 | |
| 4640 | trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *) |
| 4641 | &page_a0[SSF_TRANSCEIVER_CODE_B4]; |
| 4642 | trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *) |
| 4643 | &page_a0[SSF_TRANSCEIVER_CODE_B5]; |
| 4644 | |
| 4645 | if ((trasn_code_byte4->fc_sw_laser) || |
| 4646 | (trasn_code_byte5->fc_sw_laser_sl) || |
| 4647 | (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */ |
| 4648 | flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT); |
| 4649 | } else if (trasn_code_byte4->fc_lw_laser) { |
| 4650 | wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) | |
| 4651 | page_a0[SSF_WAVELENGTH_B0]; |
| 4652 | if (wavelength == SFP_WAVELENGTH_LC1310) |
| 4653 | flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT; |
| 4654 | if (wavelength == SFP_WAVELENGTH_LL1550) |
| 4655 | flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT; |
| 4656 | } |
| 4657 | /* check if its SFP+ */ |
| 4658 | flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ? |
| 4659 | SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN) |
| 4660 | << SFP_FLAG_CT_SHIFT; |
| 4661 | |
| 4662 | /* check if its OPTICAL */ |
| 4663 | flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ? |
| 4664 | SFP_FLAG_IS_OPTICAL_PORT : 0) |
| 4665 | << SFP_FLAG_IS_OPTICAL_SHIFT; |
| 4666 | |
| 4667 | temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 | |
| 4668 | page_a2[SFF_TEMPERATURE_B0]); |
| 4669 | vcc = (page_a2[SFF_VCC_B1] << 8 | |
| 4670 | page_a2[SFF_VCC_B0]); |
| 4671 | tx_power = (page_a2[SFF_TXPOWER_B1] << 8 | |
| 4672 | page_a2[SFF_TXPOWER_B0]); |
| 4673 | tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 | |
| 4674 | page_a2[SFF_TX_BIAS_CURRENT_B0]); |
| 4675 | rx_power = (page_a2[SFF_RXPOWER_B1] << 8 | |
| 4676 | page_a2[SFF_RXPOWER_B0]); |
| 4677 | desc->sfp_info.temperature = cpu_to_be16(temperature); |
| 4678 | desc->sfp_info.rx_power = cpu_to_be16(rx_power); |
| 4679 | desc->sfp_info.tx_bias = cpu_to_be16(tx_bias); |
| 4680 | desc->sfp_info.tx_power = cpu_to_be16(tx_power); |
| 4681 | desc->sfp_info.vcc = cpu_to_be16(vcc); |
| 4682 | |
| 4683 | desc->sfp_info.flags = cpu_to_be16(flag); |
| 4684 | desc->length = cpu_to_be32(sizeof(desc->sfp_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4685 | |
| 4686 | return sizeof(struct fc_rdp_sfp_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4687 | } |
| 4688 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4689 | uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4690 | lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc, |
| 4691 | READ_LNK_VAR *stat) |
| 4692 | { |
| 4693 | uint32_t type; |
| 4694 | |
| 4695 | desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG); |
| 4696 | |
| 4697 | type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT; |
| 4698 | |
| 4699 | desc->info.port_type = cpu_to_be32(type); |
| 4700 | |
| 4701 | desc->info.link_status.link_failure_cnt = |
| 4702 | cpu_to_be32(stat->linkFailureCnt); |
| 4703 | desc->info.link_status.loss_of_synch_cnt = |
| 4704 | cpu_to_be32(stat->lossSyncCnt); |
| 4705 | desc->info.link_status.loss_of_signal_cnt = |
| 4706 | cpu_to_be32(stat->lossSignalCnt); |
| 4707 | desc->info.link_status.primitive_seq_proto_err = |
| 4708 | cpu_to_be32(stat->primSeqErrCnt); |
| 4709 | desc->info.link_status.invalid_trans_word = |
| 4710 | cpu_to_be32(stat->invalidXmitWord); |
| 4711 | desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt); |
| 4712 | |
| 4713 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4714 | |
| 4715 | return sizeof(struct fc_rdp_link_error_status_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4716 | } |
| 4717 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4718 | uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4719 | lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat, |
| 4720 | struct lpfc_vport *vport) |
| 4721 | { |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4722 | uint32_t bbCredit; |
| 4723 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4724 | desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG); |
| 4725 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4726 | bbCredit = vport->fc_sparam.cmn.bbCreditLsb | |
| 4727 | (vport->fc_sparam.cmn.bbCreditMsb << 8); |
| 4728 | desc->bbc_info.port_bbc = cpu_to_be32(bbCredit); |
| 4729 | if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
| 4730 | bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb | |
| 4731 | (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8); |
| 4732 | desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit); |
| 4733 | } else { |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4734 | desc->bbc_info.attached_port_bbc = 0; |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4735 | } |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4736 | |
| 4737 | desc->bbc_info.rtt = 0; |
| 4738 | desc->length = cpu_to_be32(sizeof(desc->bbc_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4739 | |
| 4740 | return sizeof(struct fc_rdp_bbc_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4741 | } |
| 4742 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4743 | uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4744 | lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba, |
| 4745 | struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2) |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4746 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4747 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4748 | |
| 4749 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 4750 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4751 | desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM]; |
| 4752 | desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM]; |
| 4753 | desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING]; |
| 4754 | desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4755 | |
| 4756 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 4757 | flags |= RDP_OET_HIGH_ALARM; |
| 4758 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 4759 | flags |= RDP_OET_LOW_ALARM; |
| 4760 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 4761 | flags |= RDP_OET_HIGH_WARNING; |
| 4762 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 4763 | flags |= RDP_OET_LOW_WARNING; |
| 4764 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4765 | flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT); |
| 4766 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 4767 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4768 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4769 | } |
| 4770 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4771 | uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4772 | lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba, |
| 4773 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4774 | uint8_t *page_a2) |
| 4775 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4776 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4777 | |
| 4778 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 4779 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4780 | desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM]; |
| 4781 | desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM]; |
| 4782 | desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING]; |
| 4783 | desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4784 | |
| 4785 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 4786 | flags |= RDP_OET_HIGH_ALARM; |
| 4787 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 4788 | flags |= RDP_OET_LOW_ALARM; |
| 4789 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 4790 | flags |= RDP_OET_HIGH_WARNING; |
| 4791 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 4792 | flags |= RDP_OET_LOW_WARNING; |
| 4793 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4794 | flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT); |
| 4795 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 4796 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4797 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4798 | } |
| 4799 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4800 | uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4801 | lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba, |
| 4802 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4803 | uint8_t *page_a2) |
| 4804 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4805 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4806 | |
| 4807 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 4808 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4809 | desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM]; |
| 4810 | desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM]; |
| 4811 | desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING]; |
| 4812 | desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4813 | |
| 4814 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 4815 | flags |= RDP_OET_HIGH_ALARM; |
| 4816 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 4817 | flags |= RDP_OET_LOW_ALARM; |
| 4818 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 4819 | flags |= RDP_OET_HIGH_WARNING; |
| 4820 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 4821 | flags |= RDP_OET_LOW_WARNING; |
| 4822 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4823 | flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT); |
| 4824 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 4825 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4826 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4827 | } |
| 4828 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4829 | uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4830 | lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba, |
| 4831 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4832 | uint8_t *page_a2) |
| 4833 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4834 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4835 | |
| 4836 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 4837 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4838 | desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM]; |
| 4839 | desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM]; |
| 4840 | desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING]; |
| 4841 | desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4842 | |
| 4843 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 4844 | flags |= RDP_OET_HIGH_ALARM; |
| 4845 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 4846 | flags |= RDP_OET_LOW_ALARM; |
| 4847 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 4848 | flags |= RDP_OET_HIGH_WARNING; |
| 4849 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 4850 | flags |= RDP_OET_LOW_WARNING; |
| 4851 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4852 | flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT); |
| 4853 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 4854 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4855 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4856 | } |
| 4857 | |
| 4858 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4859 | uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4860 | lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba, |
| 4861 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4862 | uint8_t *page_a2) |
| 4863 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4864 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4865 | |
| 4866 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 4867 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 4868 | desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM]; |
| 4869 | desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM]; |
| 4870 | desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING]; |
| 4871 | desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4872 | |
| 4873 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 4874 | flags |= RDP_OET_HIGH_ALARM; |
| 4875 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 4876 | flags |= RDP_OET_LOW_ALARM; |
| 4877 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 4878 | flags |= RDP_OET_HIGH_WARNING; |
| 4879 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 4880 | flags |= RDP_OET_LOW_WARNING; |
| 4881 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4882 | flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT); |
| 4883 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 4884 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4885 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4886 | } |
| 4887 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4888 | uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4889 | lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc, |
| 4890 | uint8_t *page_a0, struct lpfc_vport *vport) |
| 4891 | { |
| 4892 | desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG); |
| 4893 | memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16); |
| 4894 | memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16); |
| 4895 | memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16); |
| 4896 | memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 2); |
| 4897 | memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8); |
| 4898 | desc->length = cpu_to_be32(sizeof(desc->opd_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4899 | return sizeof(struct fc_rdp_opd_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4900 | } |
| 4901 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4902 | uint32_t |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 4903 | lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat) |
| 4904 | { |
| 4905 | if (bf_get(lpfc_read_link_stat_gec2, stat) == 0) |
| 4906 | return 0; |
| 4907 | desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG); |
| 4908 | |
| 4909 | desc->info.CorrectedBlocks = |
| 4910 | cpu_to_be32(stat->fecCorrBlkCount); |
| 4911 | desc->info.UncorrectableBlocks = |
| 4912 | cpu_to_be32(stat->fecUncorrBlkCount); |
| 4913 | |
| 4914 | desc->length = cpu_to_be32(sizeof(desc->info)); |
| 4915 | |
| 4916 | return sizeof(struct fc_fec_rdp_desc); |
| 4917 | } |
| 4918 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4919 | uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4920 | lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba) |
| 4921 | { |
| 4922 | uint16_t rdp_cap = 0; |
| 4923 | uint16_t rdp_speed; |
| 4924 | |
| 4925 | desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG); |
| 4926 | |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4927 | switch (phba->fc_linkspeed) { |
| 4928 | case LPFC_LINK_SPEED_1GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4929 | rdp_speed = RDP_PS_1GB; |
| 4930 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4931 | case LPFC_LINK_SPEED_2GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4932 | rdp_speed = RDP_PS_2GB; |
| 4933 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4934 | case LPFC_LINK_SPEED_4GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4935 | rdp_speed = RDP_PS_4GB; |
| 4936 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4937 | case LPFC_LINK_SPEED_8GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4938 | rdp_speed = RDP_PS_8GB; |
| 4939 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4940 | case LPFC_LINK_SPEED_10GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4941 | rdp_speed = RDP_PS_10GB; |
| 4942 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4943 | case LPFC_LINK_SPEED_16GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4944 | rdp_speed = RDP_PS_16GB; |
| 4945 | break; |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4946 | case LPFC_LINK_SPEED_32GHZ: |
| 4947 | rdp_speed = RDP_PS_32GB; |
| 4948 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4949 | default: |
| 4950 | rdp_speed = RDP_PS_UNKNOWN; |
| 4951 | break; |
| 4952 | } |
| 4953 | |
| 4954 | desc->info.port_speed.speed = cpu_to_be16(rdp_speed); |
| 4955 | |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4956 | if (phba->lmt & LMT_32Gb) |
| 4957 | rdp_cap |= RDP_PS_32GB; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4958 | if (phba->lmt & LMT_16Gb) |
| 4959 | rdp_cap |= RDP_PS_16GB; |
| 4960 | if (phba->lmt & LMT_10Gb) |
| 4961 | rdp_cap |= RDP_PS_10GB; |
| 4962 | if (phba->lmt & LMT_8Gb) |
| 4963 | rdp_cap |= RDP_PS_8GB; |
| 4964 | if (phba->lmt & LMT_4Gb) |
| 4965 | rdp_cap |= RDP_PS_4GB; |
| 4966 | if (phba->lmt & LMT_2Gb) |
| 4967 | rdp_cap |= RDP_PS_2GB; |
| 4968 | if (phba->lmt & LMT_1Gb) |
| 4969 | rdp_cap |= RDP_PS_1GB; |
| 4970 | |
| 4971 | if (rdp_cap == 0) |
| 4972 | rdp_cap = RDP_CAP_UNKNOWN; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 4973 | if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO) |
| 4974 | rdp_cap |= RDP_CAP_USER_CONFIGURED; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4975 | |
| 4976 | desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap); |
| 4977 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4978 | return sizeof(struct fc_rdp_port_speed_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4979 | } |
| 4980 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4981 | uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4982 | lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc, |
| 4983 | struct lpfc_hba *phba) |
| 4984 | { |
| 4985 | |
| 4986 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 4987 | |
| 4988 | memcpy(desc->port_names.wwnn, phba->wwnn, |
| 4989 | sizeof(desc->port_names.wwnn)); |
| 4990 | |
| 4991 | memcpy(desc->port_names.wwpn, &phba->wwpn, |
| 4992 | sizeof(desc->port_names.wwpn)); |
| 4993 | |
| 4994 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4995 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4996 | } |
| 4997 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 4998 | uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4999 | lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc, |
| 5000 | struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 5001 | { |
| 5002 | |
| 5003 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 5004 | if (vport->fc_flag & FC_FABRIC) { |
| 5005 | memcpy(desc->port_names.wwnn, &vport->fabric_nodename, |
| 5006 | sizeof(desc->port_names.wwnn)); |
| 5007 | |
| 5008 | memcpy(desc->port_names.wwpn, &vport->fabric_portname, |
| 5009 | sizeof(desc->port_names.wwpn)); |
| 5010 | } else { /* Point to Point */ |
| 5011 | memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename, |
| 5012 | sizeof(desc->port_names.wwnn)); |
| 5013 | |
| 5014 | memcpy(desc->port_names.wwnn, &ndlp->nlp_portname, |
| 5015 | sizeof(desc->port_names.wwpn)); |
| 5016 | } |
| 5017 | |
| 5018 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5019 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5020 | } |
| 5021 | |
| 5022 | void |
| 5023 | lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context, |
| 5024 | int status) |
| 5025 | { |
| 5026 | struct lpfc_nodelist *ndlp = rdp_context->ndlp; |
| 5027 | struct lpfc_vport *vport = ndlp->vport; |
| 5028 | struct lpfc_iocbq *elsiocb; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5029 | struct ulp_bde64 *bpl; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5030 | IOCB_t *icmd; |
| 5031 | uint8_t *pcmd; |
| 5032 | struct ls_rjt *stat; |
| 5033 | struct fc_rdp_res_frame *rdp_res; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5034 | uint32_t cmdsize, len; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5035 | uint16_t *flag_ptr; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5036 | int rc; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5037 | |
| 5038 | if (status != SUCCESS) |
| 5039 | goto error; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5040 | |
| 5041 | /* 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] | 5042 | cmdsize = sizeof(struct fc_rdp_res_frame); |
| 5043 | |
| 5044 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, |
| 5045 | lpfc_max_els_tries, rdp_context->ndlp, |
| 5046 | rdp_context->ndlp->nlp_DID, ELS_CMD_ACC); |
| 5047 | lpfc_nlp_put(ndlp); |
| 5048 | if (!elsiocb) |
| 5049 | goto free_rdp_context; |
| 5050 | |
| 5051 | icmd = &elsiocb->iocb; |
| 5052 | icmd->ulpContext = rdp_context->rx_id; |
| 5053 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 5054 | |
| 5055 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5056 | "2171 Xmit RDP response tag x%x xri x%x, " |
| 5057 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x", |
| 5058 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5059 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5060 | ndlp->nlp_rpi); |
| 5061 | rdp_res = (struct fc_rdp_res_frame *) |
| 5062 | (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5063 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5064 | memset(pcmd, 0, sizeof(struct fc_rdp_res_frame)); |
| 5065 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5066 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5067 | /* Update Alarm and Warning */ |
| 5068 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS); |
| 5069 | phba->sfp_alarm |= *flag_ptr; |
| 5070 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS); |
| 5071 | phba->sfp_warning |= *flag_ptr; |
| 5072 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5073 | /* For RDP payload */ |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5074 | len = 8; |
| 5075 | len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *) |
| 5076 | (len + pcmd), ELS_CMD_RDP); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5077 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5078 | 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] | 5079 | rdp_context->page_a0, rdp_context->page_a2); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5080 | len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd), |
| 5081 | phba); |
| 5082 | len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *) |
| 5083 | (len + pcmd), &rdp_context->link_stat); |
| 5084 | len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *) |
| 5085 | (len + pcmd), phba); |
| 5086 | len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *) |
| 5087 | (len + pcmd), vport, ndlp); |
| 5088 | 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] | 5089 | &rdp_context->link_stat); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5090 | /* Check if nport is logged, BZ190632 */ |
| 5091 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) |
| 5092 | goto lpfc_skip_descriptor; |
| 5093 | |
| 5094 | len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd), |
| 5095 | &rdp_context->link_stat, vport); |
| 5096 | len += lpfc_rdp_res_oed_temp_desc(phba, |
| 5097 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5098 | rdp_context->page_a2); |
| 5099 | len += lpfc_rdp_res_oed_voltage_desc(phba, |
| 5100 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5101 | rdp_context->page_a2); |
| 5102 | len += lpfc_rdp_res_oed_txbias_desc(phba, |
| 5103 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5104 | rdp_context->page_a2); |
| 5105 | len += lpfc_rdp_res_oed_txpower_desc(phba, |
| 5106 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5107 | rdp_context->page_a2); |
| 5108 | len += lpfc_rdp_res_oed_rxpower_desc(phba, |
| 5109 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 5110 | rdp_context->page_a2); |
| 5111 | len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd), |
| 5112 | rdp_context->page_a0, vport); |
| 5113 | |
| 5114 | lpfc_skip_descriptor: |
| 5115 | rdp_res->length = cpu_to_be32(len - 8); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5116 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5117 | |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5118 | /* Now that we know the true size of the payload, update the BPL */ |
| 5119 | bpl = (struct ulp_bde64 *) |
| 5120 | (((struct lpfc_dmabuf *)(elsiocb->context3))->virt); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5121 | bpl->tus.f.bdeSize = len; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5122 | bpl->tus.f.bdeFlags = 0; |
| 5123 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 5124 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5125 | phba->fc_stat.elsXmitACC++; |
| 5126 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5127 | if (rc == IOCB_ERROR) |
| 5128 | lpfc_els_free_iocb(phba, elsiocb); |
| 5129 | |
| 5130 | kfree(rdp_context); |
| 5131 | |
| 5132 | return; |
| 5133 | error: |
| 5134 | cmdsize = 2 * sizeof(uint32_t); |
| 5135 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries, |
| 5136 | ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 5137 | lpfc_nlp_put(ndlp); |
| 5138 | if (!elsiocb) |
| 5139 | goto free_rdp_context; |
| 5140 | |
| 5141 | icmd = &elsiocb->iocb; |
| 5142 | icmd->ulpContext = rdp_context->rx_id; |
| 5143 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 5144 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5145 | |
| 5146 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
| 5147 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 5148 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5149 | |
| 5150 | phba->fc_stat.elsXmitLSRJT++; |
| 5151 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5152 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5153 | |
| 5154 | if (rc == IOCB_ERROR) |
| 5155 | lpfc_els_free_iocb(phba, elsiocb); |
| 5156 | free_rdp_context: |
| 5157 | kfree(rdp_context); |
| 5158 | } |
| 5159 | |
| 5160 | int |
| 5161 | lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) |
| 5162 | { |
| 5163 | LPFC_MBOXQ_t *mbox = NULL; |
| 5164 | int rc; |
| 5165 | |
| 5166 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5167 | if (!mbox) { |
| 5168 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, |
| 5169 | "7105 failed to allocate mailbox memory"); |
| 5170 | return 1; |
| 5171 | } |
| 5172 | |
| 5173 | if (lpfc_sli4_dump_page_a0(phba, mbox)) |
| 5174 | goto prep_mbox_fail; |
| 5175 | mbox->vport = rdp_context->ndlp->vport; |
| 5176 | mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; |
| 5177 | mbox->context2 = (struct lpfc_rdp_context *) rdp_context; |
| 5178 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5179 | if (rc == MBX_NOT_FINISHED) |
| 5180 | goto issue_mbox_fail; |
| 5181 | |
| 5182 | return 0; |
| 5183 | |
| 5184 | prep_mbox_fail: |
| 5185 | issue_mbox_fail: |
| 5186 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5187 | return 1; |
| 5188 | } |
| 5189 | |
| 5190 | /* |
| 5191 | * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS. |
| 5192 | * @vport: pointer to a host virtual N_Port data structure. |
| 5193 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5194 | * @ndlp: pointer to a node-list data structure. |
| 5195 | * |
| 5196 | * This routine processes an unsolicited RDP(Read Diagnostic Parameters) |
| 5197 | * IOCB. First, the payload of the unsolicited RDP is checked. |
| 5198 | * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3 |
| 5199 | * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2, |
| 5200 | * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl |
| 5201 | * gather all data and send RDP response. |
| 5202 | * |
| 5203 | * Return code |
| 5204 | * 0 - Sent the acc response |
| 5205 | * 1 - Sent the reject response. |
| 5206 | */ |
| 5207 | static int |
| 5208 | lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5209 | struct lpfc_nodelist *ndlp) |
| 5210 | { |
| 5211 | struct lpfc_hba *phba = vport->phba; |
| 5212 | struct lpfc_dmabuf *pcmd; |
| 5213 | uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE; |
| 5214 | struct fc_rdp_req_frame *rdp_req; |
| 5215 | struct lpfc_rdp_context *rdp_context; |
| 5216 | IOCB_t *cmd = NULL; |
| 5217 | struct ls_rjt stat; |
| 5218 | |
| 5219 | if (phba->sli_rev < LPFC_SLI_REV4 || |
| 5220 | (bf_get(lpfc_sli_intf_if_type, |
| 5221 | &phba->sli4_hba.sli_intf) != |
| 5222 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 5223 | rjt_err = LSRJT_UNABLE_TPC; |
| 5224 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 5225 | goto error; |
| 5226 | } |
| 5227 | |
| 5228 | if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) { |
| 5229 | rjt_err = LSRJT_UNABLE_TPC; |
| 5230 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 5231 | goto error; |
| 5232 | } |
| 5233 | |
| 5234 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5235 | rdp_req = (struct fc_rdp_req_frame *) pcmd->virt; |
| 5236 | |
| 5237 | |
| 5238 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5239 | "2422 ELS RDP Request " |
| 5240 | "dec len %d tag x%x port_id %d len %d\n", |
| 5241 | be32_to_cpu(rdp_req->rdp_des_length), |
| 5242 | be32_to_cpu(rdp_req->nport_id_desc.tag), |
| 5243 | be32_to_cpu(rdp_req->nport_id_desc.nport_id), |
| 5244 | be32_to_cpu(rdp_req->nport_id_desc.length)); |
| 5245 | |
James Smart | 7d93331 | 2016-07-06 12:35:58 -0700 | [diff] [blame^] | 5246 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) && |
| 5247 | !phba->cfg_enable_SmartSAN) { |
| 5248 | rjt_err = LSRJT_UNABLE_TPC; |
| 5249 | rjt_expl = LSEXP_PORT_LOGIN_REQ; |
| 5250 | goto error; |
| 5251 | } |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5252 | if (sizeof(struct fc_rdp_nport_desc) != |
| 5253 | be32_to_cpu(rdp_req->rdp_des_length)) |
| 5254 | goto rjt_logerr; |
| 5255 | if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag)) |
| 5256 | goto rjt_logerr; |
| 5257 | if (RDP_NPORT_ID_SIZE != |
| 5258 | be32_to_cpu(rdp_req->nport_id_desc.length)) |
| 5259 | goto rjt_logerr; |
Punit Vara | 699acd6 | 2015-12-16 18:12:07 -0500 | [diff] [blame] | 5260 | rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5261 | if (!rdp_context) { |
| 5262 | rjt_err = LSRJT_UNABLE_TPC; |
| 5263 | goto error; |
| 5264 | } |
| 5265 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5266 | cmd = &cmdiocb->iocb; |
| 5267 | rdp_context->ndlp = lpfc_nlp_get(ndlp); |
| 5268 | rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id; |
| 5269 | rdp_context->rx_id = cmd->ulpContext; |
| 5270 | rdp_context->cmpl = lpfc_els_rdp_cmpl; |
| 5271 | if (lpfc_get_rdp_info(phba, rdp_context)) { |
| 5272 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS, |
| 5273 | "2423 Unable to send mailbox"); |
| 5274 | kfree(rdp_context); |
| 5275 | rjt_err = LSRJT_UNABLE_TPC; |
| 5276 | lpfc_nlp_put(ndlp); |
| 5277 | goto error; |
| 5278 | } |
| 5279 | |
| 5280 | return 0; |
| 5281 | |
| 5282 | rjt_logerr: |
| 5283 | rjt_err = LSRJT_LOGICAL_ERR; |
| 5284 | |
| 5285 | error: |
| 5286 | memset(&stat, 0, sizeof(stat)); |
| 5287 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 5288 | stat.un.b.lsRjtRsnCodeExp = rjt_expl; |
| 5289 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5290 | return 1; |
| 5291 | } |
| 5292 | |
| 5293 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5294 | static void |
| 5295 | lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5296 | { |
| 5297 | MAILBOX_t *mb; |
| 5298 | IOCB_t *icmd; |
| 5299 | uint8_t *pcmd; |
| 5300 | struct lpfc_iocbq *elsiocb; |
| 5301 | struct lpfc_nodelist *ndlp; |
| 5302 | struct ls_rjt *stat; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5303 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5304 | struct lpfc_lcb_context *lcb_context; |
| 5305 | struct fc_lcb_res_frame *lcb_res; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5306 | uint32_t cmdsize, shdr_status, shdr_add_status; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5307 | int rc; |
| 5308 | |
| 5309 | mb = &pmb->u.mb; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5310 | lcb_context = (struct lpfc_lcb_context *)pmb->context1; |
| 5311 | ndlp = lcb_context->ndlp; |
| 5312 | pmb->context1 = NULL; |
| 5313 | pmb->context2 = NULL; |
| 5314 | |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5315 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 5316 | &pmb->u.mqe.un.beacon_config.header.cfg_shdr; |
| 5317 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5318 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5319 | |
| 5320 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX, |
| 5321 | "0194 SET_BEACON_CONFIG mailbox " |
| 5322 | "completed with status x%x add_status x%x," |
| 5323 | " mbx status x%x\n", |
| 5324 | shdr_status, shdr_add_status, mb->mbxStatus); |
| 5325 | |
| 5326 | if (mb->mbxStatus && !(shdr_status && |
| 5327 | shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5328 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5329 | goto error; |
| 5330 | } |
| 5331 | |
| 5332 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5333 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 5334 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5335 | lpfc_max_els_tries, ndlp, |
| 5336 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5337 | |
| 5338 | /* Decrement the ndlp reference count from previous mbox command */ |
| 5339 | lpfc_nlp_put(ndlp); |
| 5340 | |
| 5341 | if (!elsiocb) |
| 5342 | goto free_lcb_context; |
| 5343 | |
| 5344 | lcb_res = (struct fc_lcb_res_frame *) |
| 5345 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5346 | |
| 5347 | icmd = &elsiocb->iocb; |
| 5348 | icmd->ulpContext = lcb_context->rx_id; |
| 5349 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 5350 | |
| 5351 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5352 | *((uint32_t *)(pcmd)) = ELS_CMD_ACC; |
| 5353 | lcb_res->lcb_sub_command = lcb_context->sub_command; |
| 5354 | lcb_res->lcb_type = lcb_context->type; |
| 5355 | lcb_res->lcb_frequency = lcb_context->frequency; |
| 5356 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5357 | phba->fc_stat.elsXmitACC++; |
| 5358 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5359 | if (rc == IOCB_ERROR) |
| 5360 | lpfc_els_free_iocb(phba, elsiocb); |
| 5361 | |
| 5362 | kfree(lcb_context); |
| 5363 | return; |
| 5364 | |
| 5365 | error: |
| 5366 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 5367 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5368 | lpfc_max_els_tries, ndlp, |
| 5369 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 5370 | lpfc_nlp_put(ndlp); |
| 5371 | if (!elsiocb) |
| 5372 | goto free_lcb_context; |
| 5373 | |
| 5374 | icmd = &elsiocb->iocb; |
| 5375 | icmd->ulpContext = lcb_context->rx_id; |
| 5376 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 5377 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5378 | |
| 5379 | *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT; |
| 5380 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 5381 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5382 | |
| 5383 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5384 | phba->fc_stat.elsXmitLSRJT++; |
| 5385 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5386 | if (rc == IOCB_ERROR) |
| 5387 | lpfc_els_free_iocb(phba, elsiocb); |
| 5388 | free_lcb_context: |
| 5389 | kfree(lcb_context); |
| 5390 | } |
| 5391 | |
| 5392 | static int |
| 5393 | lpfc_sli4_set_beacon(struct lpfc_vport *vport, |
| 5394 | struct lpfc_lcb_context *lcb_context, |
| 5395 | uint32_t beacon_state) |
| 5396 | { |
| 5397 | struct lpfc_hba *phba = vport->phba; |
| 5398 | LPFC_MBOXQ_t *mbox = NULL; |
| 5399 | uint32_t len; |
| 5400 | int rc; |
| 5401 | |
| 5402 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5403 | if (!mbox) |
| 5404 | return 1; |
| 5405 | |
| 5406 | len = sizeof(struct lpfc_mbx_set_beacon_config) - |
| 5407 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 5408 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5409 | LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len, |
| 5410 | LPFC_SLI4_MBX_EMBED); |
| 5411 | mbox->context1 = (void *)lcb_context; |
| 5412 | mbox->vport = phba->pport; |
| 5413 | mbox->mbox_cmpl = lpfc_els_lcb_rsp; |
| 5414 | bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config, |
| 5415 | phba->sli4_hba.physical_port); |
| 5416 | bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config, |
| 5417 | beacon_state); |
| 5418 | bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1); |
| 5419 | bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0); |
| 5420 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5421 | if (rc == MBX_NOT_FINISHED) { |
| 5422 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5423 | return 1; |
| 5424 | } |
| 5425 | |
| 5426 | return 0; |
| 5427 | } |
| 5428 | |
| 5429 | |
| 5430 | /** |
| 5431 | * lpfc_els_rcv_lcb - Process an unsolicited LCB |
| 5432 | * @vport: pointer to a host virtual N_Port data structure. |
| 5433 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5434 | * @ndlp: pointer to a node-list data structure. |
| 5435 | * |
| 5436 | * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB. |
| 5437 | * First, the payload of the unsolicited LCB is checked. |
| 5438 | * Then based on Subcommand beacon will either turn on or off. |
| 5439 | * |
| 5440 | * Return code |
| 5441 | * 0 - Sent the acc response |
| 5442 | * 1 - Sent the reject response. |
| 5443 | **/ |
| 5444 | static int |
| 5445 | lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5446 | struct lpfc_nodelist *ndlp) |
| 5447 | { |
| 5448 | struct lpfc_hba *phba = vport->phba; |
| 5449 | struct lpfc_dmabuf *pcmd; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5450 | uint8_t *lp; |
| 5451 | struct fc_lcb_request_frame *beacon; |
| 5452 | struct lpfc_lcb_context *lcb_context; |
| 5453 | uint8_t state, rjt_err; |
| 5454 | struct ls_rjt stat; |
| 5455 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5456 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 5457 | lp = (uint8_t *)pcmd->virt; |
| 5458 | beacon = (struct fc_lcb_request_frame *)pcmd->virt; |
| 5459 | |
| 5460 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5461 | "0192 ELS LCB Data x%x x%x x%x x%x sub x%x " |
| 5462 | "type x%x frequency %x duration x%x\n", |
| 5463 | lp[0], lp[1], lp[2], |
| 5464 | beacon->lcb_command, |
| 5465 | beacon->lcb_sub_command, |
| 5466 | beacon->lcb_type, |
| 5467 | beacon->lcb_frequency, |
| 5468 | be16_to_cpu(beacon->lcb_duration)); |
| 5469 | |
| 5470 | if (phba->sli_rev < LPFC_SLI_REV4 || |
| 5471 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 5472 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 5473 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5474 | goto rjt; |
| 5475 | } |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5476 | |
| 5477 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 5478 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5479 | goto rjt; |
| 5480 | } |
| 5481 | if (beacon->lcb_frequency == 0) { |
| 5482 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5483 | goto rjt; |
| 5484 | } |
| 5485 | if ((beacon->lcb_type != LPFC_LCB_GREEN) && |
| 5486 | (beacon->lcb_type != LPFC_LCB_AMBER)) { |
| 5487 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5488 | goto rjt; |
| 5489 | } |
| 5490 | if ((beacon->lcb_sub_command != LPFC_LCB_ON) && |
| 5491 | (beacon->lcb_sub_command != LPFC_LCB_OFF)) { |
| 5492 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5493 | goto rjt; |
| 5494 | } |
| 5495 | if ((beacon->lcb_sub_command == LPFC_LCB_ON) && |
| 5496 | (beacon->lcb_type != LPFC_LCB_GREEN) && |
| 5497 | (beacon->lcb_type != LPFC_LCB_AMBER)) { |
| 5498 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5499 | goto rjt; |
| 5500 | } |
| 5501 | if (be16_to_cpu(beacon->lcb_duration) != 0) { |
| 5502 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5503 | goto rjt; |
| 5504 | } |
| 5505 | |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 5506 | lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL); |
| 5507 | if (!lcb_context) { |
| 5508 | rjt_err = LSRJT_UNABLE_TPC; |
| 5509 | goto rjt; |
| 5510 | } |
| 5511 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5512 | state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; |
| 5513 | lcb_context->sub_command = beacon->lcb_sub_command; |
| 5514 | lcb_context->type = beacon->lcb_type; |
| 5515 | lcb_context->frequency = beacon->lcb_frequency; |
| 5516 | lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
| 5517 | lcb_context->rx_id = cmdiocb->iocb.ulpContext; |
| 5518 | lcb_context->ndlp = lpfc_nlp_get(ndlp); |
| 5519 | if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { |
| 5520 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 5521 | LOG_ELS, "0193 failed to send mail box"); |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 5522 | kfree(lcb_context); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5523 | lpfc_nlp_put(ndlp); |
| 5524 | rjt_err = LSRJT_UNABLE_TPC; |
| 5525 | goto rjt; |
| 5526 | } |
| 5527 | return 0; |
| 5528 | rjt: |
| 5529 | memset(&stat, 0, sizeof(stat)); |
| 5530 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 5531 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5532 | return 1; |
| 5533 | } |
| 5534 | |
| 5535 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5536 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5537 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5538 | * @vport: pointer to a host virtual N_Port data structure. |
| 5539 | * |
| 5540 | * This routine cleans up any Registration State Change Notification |
| 5541 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 5542 | * @vport together with the host_lock is used to prevent multiple thread |
| 5543 | * trying to access the RSCN array on a same @vport at the same time. |
| 5544 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5545 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5546 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5547 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5548 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5549 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5550 | int i; |
| 5551 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5552 | spin_lock_irq(shost->host_lock); |
| 5553 | if (vport->fc_rscn_flush) { |
| 5554 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 5555 | spin_unlock_irq(shost->host_lock); |
| 5556 | return; |
| 5557 | } |
| 5558 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 5559 | vport->fc_rscn_flush = 1; |
| 5560 | spin_unlock_irq(shost->host_lock); |
| 5561 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5562 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5563 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5564 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5565 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5566 | spin_lock_irq(shost->host_lock); |
| 5567 | vport->fc_rscn_id_cnt = 0; |
| 5568 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 5569 | spin_unlock_irq(shost->host_lock); |
| 5570 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5571 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 5572 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5573 | } |
| 5574 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5575 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5576 | * 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] | 5577 | * @vport: pointer to a host virtual N_Port data structure. |
| 5578 | * @did: remote destination port identifier. |
| 5579 | * |
| 5580 | * This routine checks whether there is any pending Registration State |
| 5581 | * Configuration Notification (RSCN) to a @did on @vport. |
| 5582 | * |
| 5583 | * Return code |
| 5584 | * None zero - The @did matched with a pending rscn |
| 5585 | * 0 - not able to match @did with a pending rscn |
| 5586 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5587 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5588 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5589 | { |
| 5590 | D_ID ns_did; |
| 5591 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5592 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5593 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5594 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5595 | |
| 5596 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5597 | |
| 5598 | /* Never match fabric nodes for RSCNs */ |
| 5599 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5600 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5601 | |
| 5602 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5603 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5604 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5605 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5606 | spin_lock_irq(shost->host_lock); |
| 5607 | if (vport->fc_rscn_flush) { |
| 5608 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 5609 | spin_unlock_irq(shost->host_lock); |
| 5610 | return 0; |
| 5611 | } |
| 5612 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 5613 | vport->fc_rscn_flush = 1; |
| 5614 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5615 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5616 | lp = vport->fc_rscn_id_list[i]->virt; |
| 5617 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 5618 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5619 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5620 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 5621 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5622 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 5623 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5624 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 5625 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 5626 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5627 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5628 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5629 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5630 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 5631 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5632 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5633 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5634 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5635 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5636 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5637 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5638 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5639 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5640 | } |
| 5641 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5642 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5643 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 5644 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5645 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5646 | return_did_out: |
| 5647 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 5648 | vport->fc_rscn_flush = 0; |
| 5649 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5650 | } |
| 5651 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5652 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5653 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5654 | * @vport: pointer to a host virtual N_Port data structure. |
| 5655 | * |
| 5656 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 5657 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 5658 | * State Change Notification). |
| 5659 | * |
| 5660 | * Return code |
| 5661 | * 0 - Successful (currently alway return 0) |
| 5662 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5663 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5664 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5665 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5666 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5667 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5668 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5669 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5670 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5671 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 5672 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5673 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5674 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5675 | NLP_EVT_DEVICE_RECOVERY); |
| 5676 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5677 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5678 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5679 | } |
| 5680 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5681 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5682 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5683 | * @vport: pointer to a host virtual N_Port data structure. |
| 5684 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5685 | * |
| 5686 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 5687 | * applications. |
| 5688 | */ |
| 5689 | static void |
| 5690 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 5691 | struct lpfc_iocbq *cmdiocb) |
| 5692 | { |
| 5693 | struct lpfc_dmabuf *pcmd; |
| 5694 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5695 | uint32_t *payload_ptr; |
| 5696 | uint32_t payload_len; |
| 5697 | struct lpfc_rscn_event_header *rscn_event_data; |
| 5698 | |
| 5699 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5700 | payload_ptr = (uint32_t *) pcmd->virt; |
| 5701 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 5702 | |
| 5703 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 5704 | payload_len, GFP_KERNEL); |
| 5705 | if (!rscn_event_data) { |
| 5706 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5707 | "0147 Failed to allocate memory for RSCN event\n"); |
| 5708 | return; |
| 5709 | } |
| 5710 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 5711 | rscn_event_data->payload_length = payload_len; |
| 5712 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 5713 | payload_len); |
| 5714 | |
| 5715 | fc_host_post_vendor_event(shost, |
| 5716 | fc_get_event_number(), |
Ales Novak | 6599eaa | 2015-08-31 16:48:16 -0400 | [diff] [blame] | 5717 | sizeof(struct lpfc_rscn_event_header) + payload_len, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5718 | (char *)rscn_event_data, |
| 5719 | LPFC_NL_VENDOR_ID); |
| 5720 | |
| 5721 | kfree(rscn_event_data); |
| 5722 | } |
| 5723 | |
| 5724 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5725 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5726 | * @vport: pointer to a host virtual N_Port data structure. |
| 5727 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5728 | * @ndlp: pointer to a node-list data structure. |
| 5729 | * |
| 5730 | * This routine processes an unsolicited RSCN (Registration State Change |
| 5731 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 5732 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 5733 | * discover state machine is about to begin discovery, it just accepts the |
| 5734 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 5735 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 5736 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 5737 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 5738 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 5739 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 5740 | * routine is invoked to handle the RSCN event. |
| 5741 | * |
| 5742 | * Return code |
| 5743 | * 0 - Just sent the acc response |
| 5744 | * 1 - Sent the acc response and waited for name server completion |
| 5745 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5746 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5747 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5748 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5749 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5750 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5751 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5752 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5753 | uint32_t *lp, *datap; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5754 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5755 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5756 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5757 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5758 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5759 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5760 | lp = (uint32_t *) pcmd->virt; |
| 5761 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5762 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 5763 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5764 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5765 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5766 | "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] | 5767 | vport->fc_flag, payload_len, *lp, |
| 5768 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5769 | |
| 5770 | /* Send an RSCN event to the management application */ |
| 5771 | lpfc_send_rscn_event(vport, cmdiocb); |
| 5772 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5773 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5774 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5775 | FCH_EVT_RSCN, lp[i]); |
| 5776 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5777 | /* If we are about to begin discovery, just ACC the RSCN. |
| 5778 | * Discovery processing will satisfy it. |
| 5779 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5780 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5781 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5782 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 5783 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 5784 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5785 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5786 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5787 | } |
| 5788 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5789 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 5790 | * just ACC and ignore it. |
| 5791 | */ |
| 5792 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5793 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5794 | i = payload_len; |
| 5795 | datap = lp; |
| 5796 | while (i > 0) { |
| 5797 | nportid = *datap++; |
| 5798 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 5799 | i -= sizeof(uint32_t); |
| 5800 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5801 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 5802 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5803 | } |
| 5804 | if (rscn_id == hba_id) { |
| 5805 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5806 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5807 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5808 | "Data: x%x x%x x%x x%x\n", |
| 5809 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5810 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5811 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5812 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 5813 | ndlp->nlp_DID, vport->port_state, |
| 5814 | ndlp->nlp_flag); |
| 5815 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5816 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5817 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5818 | return 0; |
| 5819 | } |
| 5820 | } |
| 5821 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5822 | spin_lock_irq(shost->host_lock); |
| 5823 | if (vport->fc_rscn_flush) { |
| 5824 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5825 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 5826 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5827 | /* Send back ACC */ |
| 5828 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5829 | return 0; |
| 5830 | } |
| 5831 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 5832 | vport->fc_rscn_flush = 1; |
| 5833 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5834 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5835 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5836 | /* If we are already processing an RSCN, save the received |
| 5837 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 5838 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5839 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5840 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5841 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 5842 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 5843 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5844 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5845 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 5846 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5847 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5848 | vport->fc_flag |= FC_RSCN_MODE; |
| 5849 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5850 | if (rscn_cnt) { |
| 5851 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 5852 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 5853 | } |
| 5854 | if ((rscn_cnt) && |
| 5855 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 5856 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5857 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5858 | memcpy(((uint8_t *)cmd) + length, lp, |
| 5859 | payload_len); |
| 5860 | } else { |
| 5861 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 5862 | vport->fc_rscn_id_cnt++; |
| 5863 | /* If we zero, cmdiocb->context2, the calling |
| 5864 | * routine will not try to free it. |
| 5865 | */ |
| 5866 | cmdiocb->context2 = NULL; |
| 5867 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5868 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5869 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5870 | "0235 Deferred RSCN " |
| 5871 | "Data: x%x x%x x%x\n", |
| 5872 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 5873 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5874 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5875 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 5876 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5877 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5878 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5879 | "0234 ReDiscovery RSCN " |
| 5880 | "Data: x%x x%x x%x\n", |
| 5881 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 5882 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5883 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5884 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 5885 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5886 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5887 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5888 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5889 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5890 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5891 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5892 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5893 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5894 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5895 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5896 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 5897 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 5898 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5899 | spin_lock_irq(shost->host_lock); |
| 5900 | vport->fc_flag |= FC_RSCN_MODE; |
| 5901 | spin_unlock_irq(shost->host_lock); |
| 5902 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5903 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 5904 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5905 | /* |
| 5906 | * If we zero, cmdiocb->context2, the calling routine will |
| 5907 | * not try to free it. |
| 5908 | */ |
| 5909 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5910 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5911 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5912 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5913 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5914 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5915 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5916 | } |
| 5917 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5918 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5919 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5920 | * @vport: pointer to a host virtual N_Port data structure. |
| 5921 | * |
| 5922 | * This routine handles the Registration State Configuration Notification |
| 5923 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 5924 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 5925 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 5926 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 5927 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 5928 | * RSCN activities with the @vport. |
| 5929 | * |
| 5930 | * Return code |
| 5931 | * 0 - Cleaned up rscn on the @vport |
| 5932 | * 1 - Wait for plogi to name server before proceed |
| 5933 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5934 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5935 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5936 | { |
| 5937 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5938 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5939 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5940 | /* Ignore RSCN if the port is being torn down. */ |
| 5941 | if (vport->load_flag & FC_UNLOADING) { |
| 5942 | lpfc_els_flush_rscn(vport); |
| 5943 | return 0; |
| 5944 | } |
| 5945 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5946 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5947 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5948 | |
| 5949 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5950 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5951 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 5952 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 5953 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5954 | |
| 5955 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5956 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5957 | vport->num_disc_nodes = 0; |
| 5958 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5959 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5960 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 5961 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5962 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5963 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5964 | /* Wait for NameServer query cmpl before we can |
| 5965 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5966 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5967 | } else { |
| 5968 | /* If login to NameServer does not exist, issue one */ |
| 5969 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5970 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5971 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5972 | /* Wait for NameServer login cmpl before we can |
| 5973 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5974 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5975 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5976 | if (ndlp) { |
| 5977 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5978 | NLP_STE_PLOGI_ISSUE); |
| 5979 | if (!ndlp) { |
| 5980 | lpfc_els_flush_rscn(vport); |
| 5981 | return 0; |
| 5982 | } |
| 5983 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5984 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5985 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5986 | if (!ndlp) { |
| 5987 | lpfc_els_flush_rscn(vport); |
| 5988 | return 0; |
| 5989 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5990 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5991 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5992 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5993 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5994 | ndlp->nlp_type |= NLP_FABRIC; |
| 5995 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 5996 | /* Wait for NameServer login cmpl before we can |
| 5997 | * continue |
| 5998 | */ |
| 5999 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6000 | } |
| 6001 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6002 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6003 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6004 | } |
| 6005 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6006 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6007 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6008 | * @vport: pointer to a host virtual N_Port data structure. |
| 6009 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6010 | * @ndlp: pointer to a node-list data structure. |
| 6011 | * |
| 6012 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 6013 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 6014 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 6015 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 6016 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 6017 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 6018 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 6019 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 6020 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 6021 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 6022 | * higher priority (as the winning port) and will initiate PLOGI and |
| 6023 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 6024 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 6025 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 6026 | * |
| 6027 | * Return code |
| 6028 | * 0 - Successfully processed the unsolicited flogi |
| 6029 | * 1 - Failed to process the unsolicited flogi |
| 6030 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6031 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6032 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6033 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6034 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6035 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6036 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6037 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6038 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 6039 | IOCB_t *icmd = &cmdiocb->iocb; |
| 6040 | struct serv_parm *sp; |
| 6041 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6042 | uint32_t cmd, did; |
| 6043 | int rc; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6044 | uint32_t fc_flag = 0; |
| 6045 | uint32_t port_state = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6046 | |
| 6047 | cmd = *lp++; |
| 6048 | sp = (struct serv_parm *) lp; |
| 6049 | |
| 6050 | /* FLOGI received */ |
| 6051 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6052 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6053 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6054 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6055 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 6056 | did = icmd->un.elsreq64.remoteID; |
| 6057 | |
| 6058 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 6059 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6060 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6061 | "0113 An FLOGI ELS command x%x was " |
| 6062 | "received from DID x%x in Loop Mode\n", |
| 6063 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6064 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6065 | } |
| 6066 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6067 | (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6068 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6069 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6070 | /* |
| 6071 | * If our portname is greater than the remote portname, |
| 6072 | * then we initiate Nport login. |
| 6073 | */ |
| 6074 | |
| 6075 | rc = memcmp(&vport->fc_portname, &sp->portName, |
| 6076 | sizeof(struct lpfc_name)); |
| 6077 | |
| 6078 | if (!rc) { |
| 6079 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 6080 | mbox = mempool_alloc(phba->mbox_mem_pool, |
| 6081 | GFP_KERNEL); |
| 6082 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6083 | return 1; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6084 | lpfc_linkdown(phba); |
| 6085 | lpfc_init_link(phba, mbox, |
| 6086 | phba->cfg_topology, |
| 6087 | phba->cfg_link_speed); |
| 6088 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 6089 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 6090 | mbox->vport = vport; |
| 6091 | rc = lpfc_sli_issue_mbox(phba, mbox, |
| 6092 | MBX_NOWAIT); |
| 6093 | lpfc_set_loopback_flag(phba); |
| 6094 | if (rc == MBX_NOT_FINISHED) |
| 6095 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6096 | return 1; |
| 6097 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6098 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6099 | /* abort the flogi coming back to ourselves |
| 6100 | * due to external loopback on the port. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6101 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6102 | lpfc_els_abort_flogi(phba); |
| 6103 | return 0; |
| 6104 | |
| 6105 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6106 | spin_lock_irq(shost->host_lock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6107 | vport->fc_flag |= FC_PT2PT_PLOGI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6108 | spin_unlock_irq(shost->host_lock); |
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 | /* If we have the high WWPN we can assign our own |
| 6111 | * myDID; otherwise, we have to WAIT for a PLOGI |
| 6112 | * from the remote NPort to find out what it |
| 6113 | * will be. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6114 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6115 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6116 | } else { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6117 | vport->fc_myDID = PT2PT_RemoteID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6118 | } |
| 6119 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6120 | /* |
| 6121 | * The vport state should go to LPFC_FLOGI only |
| 6122 | * AFTER we issue a FLOGI, not receive one. |
| 6123 | */ |
| 6124 | spin_lock_irq(shost->host_lock); |
| 6125 | fc_flag = vport->fc_flag; |
| 6126 | port_state = vport->port_state; |
| 6127 | vport->fc_flag |= FC_PT2PT; |
| 6128 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6129 | spin_unlock_irq(shost->host_lock); |
| 6130 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6131 | "3311 Rcv Flogi PS x%x new PS x%x " |
| 6132 | "fc_flag x%x new fc_flag x%x\n", |
| 6133 | port_state, vport->port_state, |
| 6134 | fc_flag, vport->fc_flag); |
| 6135 | |
| 6136 | /* |
| 6137 | * We temporarily set fc_myDID to make it look like we are |
| 6138 | * a Fabric. This is done just so we end up with the right |
| 6139 | * did / sid on the FLOGI ACC rsp. |
| 6140 | */ |
| 6141 | did = vport->fc_myDID; |
| 6142 | vport->fc_myDID = Fabric_DID; |
| 6143 | |
| 6144 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 6145 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6146 | /* Send back ACC */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 6147 | lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6148 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6149 | /* Now lets put fc_myDID back to what its supposed to be */ |
| 6150 | vport->fc_myDID = did; |
| 6151 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6152 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6153 | } |
| 6154 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6155 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6156 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6157 | * @vport: pointer to a host virtual N_Port data structure. |
| 6158 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6159 | * @ndlp: pointer to a node-list data structure. |
| 6160 | * |
| 6161 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 6162 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 6163 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 6164 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 6165 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 6166 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 6167 | * |
| 6168 | * Return code |
| 6169 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 6170 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6171 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6172 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6173 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6174 | { |
| 6175 | struct lpfc_dmabuf *pcmd; |
| 6176 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6177 | RNID *rn; |
| 6178 | struct ls_rjt stat; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6179 | uint32_t cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6180 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6181 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6182 | lp = (uint32_t *) pcmd->virt; |
| 6183 | |
| 6184 | cmd = *lp++; |
| 6185 | rn = (RNID *) lp; |
| 6186 | |
| 6187 | /* RNID received */ |
| 6188 | |
| 6189 | switch (rn->Format) { |
| 6190 | case 0: |
| 6191 | case RNID_TOPOLOGY_DISC: |
| 6192 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6193 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6194 | break; |
| 6195 | default: |
| 6196 | /* Reject this request because format not supported */ |
| 6197 | stat.un.b.lsRjtRsvd0 = 0; |
| 6198 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6199 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6200 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6201 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 6202 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6203 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6204 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6205 | } |
| 6206 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6207 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6208 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 6209 | * @vport: pointer to a host virtual N_Port data structure. |
| 6210 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6211 | * @ndlp: pointer to a node-list data structure. |
| 6212 | * |
| 6213 | * Return code |
| 6214 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 6215 | **/ |
| 6216 | static int |
| 6217 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6218 | struct lpfc_nodelist *ndlp) |
| 6219 | { |
| 6220 | uint8_t *pcmd; |
| 6221 | |
| 6222 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 6223 | |
| 6224 | /* skip over first word of echo command to find echo data */ |
| 6225 | pcmd += sizeof(uint32_t); |
| 6226 | |
| 6227 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 6228 | return 0; |
| 6229 | } |
| 6230 | |
| 6231 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6232 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6233 | * @vport: pointer to a host virtual N_Port data structure. |
| 6234 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6235 | * @ndlp: pointer to a node-list data structure. |
| 6236 | * |
| 6237 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 6238 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 6239 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 6240 | * |
| 6241 | * Return code |
| 6242 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 6243 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6244 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6245 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6246 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6247 | { |
| 6248 | struct ls_rjt stat; |
| 6249 | |
| 6250 | /* For now, unconditionally reject this command */ |
| 6251 | stat.un.b.lsRjtRsvd0 = 0; |
| 6252 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6253 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6254 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6255 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6256 | return 0; |
| 6257 | } |
| 6258 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6259 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6260 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 6261 | * @vport: pointer to a host virtual N_Port data structure. |
| 6262 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6263 | * @ndlp: pointer to a node-list data structure. |
| 6264 | * |
| 6265 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 6266 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 6267 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 6268 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 6269 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 6270 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 6271 | * command request" and reason code explanation "Invalid Originator |
| 6272 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 6273 | * RRQ from the target. |
| 6274 | **/ |
| 6275 | static void |
| 6276 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6277 | struct lpfc_nodelist *ndlp) |
| 6278 | { |
| 6279 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6280 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 6281 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6282 | } |
| 6283 | |
| 6284 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6285 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 6286 | * @phba: pointer to lpfc hba data structure. |
| 6287 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6288 | * |
| 6289 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 6290 | * mailbox command. This callback function is to actually send the Accept |
| 6291 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 6292 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 6293 | * mailbox command, constructs the RPS response with the link statistics |
| 6294 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 6295 | * response to the RPS. |
| 6296 | * |
| 6297 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6298 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6299 | * will be stored into the context1 field of the IOCB for the completion |
| 6300 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6301 | * |
| 6302 | **/ |
| 6303 | static void |
| 6304 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6305 | { |
| 6306 | MAILBOX_t *mb; |
| 6307 | IOCB_t *icmd; |
| 6308 | struct RLS_RSP *rls_rsp; |
| 6309 | uint8_t *pcmd; |
| 6310 | struct lpfc_iocbq *elsiocb; |
| 6311 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6312 | uint16_t oxid; |
| 6313 | uint16_t rxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6314 | uint32_t cmdsize; |
| 6315 | |
| 6316 | mb = &pmb->u.mb; |
| 6317 | |
| 6318 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6319 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 6320 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6321 | pmb->context1 = NULL; |
| 6322 | pmb->context2 = NULL; |
| 6323 | |
| 6324 | if (mb->mbxStatus) { |
| 6325 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6326 | return; |
| 6327 | } |
| 6328 | |
| 6329 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6330 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6331 | lpfc_max_els_tries, ndlp, |
| 6332 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6333 | |
| 6334 | /* Decrement the ndlp reference count from previous mbox command */ |
| 6335 | lpfc_nlp_put(ndlp); |
| 6336 | |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6337 | if (!elsiocb) { |
| 6338 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6339 | return; |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6340 | } |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6341 | |
| 6342 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6343 | icmd->ulpContext = rxid; |
| 6344 | icmd->unsli3.rcvsli3.ox_id = oxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6345 | |
| 6346 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6347 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6348 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 6349 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 6350 | |
| 6351 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 6352 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 6353 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 6354 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 6355 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 6356 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6357 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6358 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 6359 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6360 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 6361 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 6362 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6363 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6364 | ndlp->nlp_rpi); |
| 6365 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6366 | phba->fc_stat.elsXmitACC++; |
| 6367 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 6368 | lpfc_els_free_iocb(phba, elsiocb); |
| 6369 | } |
| 6370 | |
| 6371 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6372 | * 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] | 6373 | * @phba: pointer to lpfc hba data structure. |
| 6374 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6375 | * |
| 6376 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 6377 | * mailbox command. This callback function is to actually send the Accept |
| 6378 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 6379 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 6380 | * mailbox command, constructs the RPS response with the link statistics |
| 6381 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 6382 | * response to the RPS. |
| 6383 | * |
| 6384 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6385 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6386 | * will be stored into the context1 field of the IOCB for the completion |
| 6387 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6388 | * |
| 6389 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 6390 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6391 | 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] | 6392 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6393 | MAILBOX_t *mb; |
| 6394 | IOCB_t *icmd; |
| 6395 | RPS_RSP *rps_rsp; |
| 6396 | uint8_t *pcmd; |
| 6397 | struct lpfc_iocbq *elsiocb; |
| 6398 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6399 | uint16_t status; |
| 6400 | uint16_t oxid; |
| 6401 | uint16_t rxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6402 | uint32_t cmdsize; |
| 6403 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6404 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6405 | |
| 6406 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6407 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 6408 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 6409 | pmb->context1 = NULL; |
| 6410 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6411 | |
| 6412 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6413 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6414 | return; |
| 6415 | } |
| 6416 | |
| 6417 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6418 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6419 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6420 | lpfc_max_els_tries, ndlp, |
| 6421 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6422 | |
| 6423 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6424 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6425 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6426 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6427 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6428 | |
| 6429 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6430 | icmd->ulpContext = rxid; |
| 6431 | icmd->unsli3.rcvsli3.ox_id = oxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6432 | |
| 6433 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6434 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6435 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6436 | rps_rsp = (RPS_RSP *)pcmd; |
| 6437 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6438 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6439 | status = 0x10; |
| 6440 | else |
| 6441 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6442 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6443 | status |= 0x4; |
| 6444 | |
| 6445 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6446 | rps_rsp->portStatus = cpu_to_be16(status); |
| 6447 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 6448 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 6449 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 6450 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 6451 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 6452 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6453 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6454 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6455 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 6456 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 6457 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6458 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6459 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6460 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6461 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6462 | 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] | 6463 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6464 | return; |
| 6465 | } |
| 6466 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6467 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6468 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 6469 | * @vport: pointer to a host virtual N_Port data structure. |
| 6470 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6471 | * @ndlp: pointer to a node-list data structure. |
| 6472 | * |
| 6473 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 6474 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6475 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6476 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 6477 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 6478 | * for reading the HBA link statistics. It is for the callback function, |
| 6479 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 6480 | * to actually sending out RPL Accept (ACC) response. |
| 6481 | * |
| 6482 | * Return codes |
| 6483 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 6484 | **/ |
| 6485 | static int |
| 6486 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6487 | struct lpfc_nodelist *ndlp) |
| 6488 | { |
| 6489 | struct lpfc_hba *phba = vport->phba; |
| 6490 | LPFC_MBOXQ_t *mbox; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6491 | struct ls_rjt stat; |
| 6492 | |
| 6493 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6494 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6495 | /* reject the unsolicited RPS request and done with it */ |
| 6496 | goto reject_out; |
| 6497 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6498 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 6499 | if (mbox) { |
| 6500 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6501 | mbox->context1 = (void *)((unsigned long) |
| 6502 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 6503 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6504 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6505 | mbox->vport = vport; |
| 6506 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 6507 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 6508 | != MBX_NOT_FINISHED) |
| 6509 | /* Mbox completion will send ELS Response */ |
| 6510 | return 0; |
| 6511 | /* Decrement reference count used for the failed mbox |
| 6512 | * command. |
| 6513 | */ |
| 6514 | lpfc_nlp_put(ndlp); |
| 6515 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6516 | } |
| 6517 | reject_out: |
| 6518 | /* issue rejection response */ |
| 6519 | stat.un.b.lsRjtRsvd0 = 0; |
| 6520 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6521 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6522 | stat.un.b.vendorUnique = 0; |
| 6523 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6524 | return 0; |
| 6525 | } |
| 6526 | |
| 6527 | /** |
| 6528 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 6529 | * @vport: pointer to a host virtual N_Port data structure. |
| 6530 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6531 | * @ndlp: pointer to a node-list data structure. |
| 6532 | * |
| 6533 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 6534 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6535 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6536 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 6537 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 6538 | * Value (RTV) unsolicited IOCB event. |
| 6539 | * |
| 6540 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6541 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6542 | * will be stored into the context1 field of the IOCB for the completion |
| 6543 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6544 | * |
| 6545 | * Return codes |
| 6546 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 6547 | **/ |
| 6548 | static int |
| 6549 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6550 | struct lpfc_nodelist *ndlp) |
| 6551 | { |
| 6552 | struct lpfc_hba *phba = vport->phba; |
| 6553 | struct ls_rjt stat; |
| 6554 | struct RTV_RSP *rtv_rsp; |
| 6555 | uint8_t *pcmd; |
| 6556 | struct lpfc_iocbq *elsiocb; |
| 6557 | uint32_t cmdsize; |
| 6558 | |
| 6559 | |
| 6560 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6561 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6562 | /* reject the unsolicited RPS request and done with it */ |
| 6563 | goto reject_out; |
| 6564 | |
| 6565 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 6566 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6567 | lpfc_max_els_tries, ndlp, |
| 6568 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6569 | |
| 6570 | if (!elsiocb) |
| 6571 | return 1; |
| 6572 | |
| 6573 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6574 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6575 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 6576 | |
| 6577 | /* use the command's xri in the response */ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6578 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 6579 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6580 | |
| 6581 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 6582 | |
| 6583 | /* populate RTV payload */ |
| 6584 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 6585 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 6586 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 6587 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 6588 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 6589 | |
| 6590 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 6591 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6592 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 6593 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 6594 | "Data: x%x x%x x%x\n", |
| 6595 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6596 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6597 | ndlp->nlp_rpi, |
| 6598 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 6599 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6600 | phba->fc_stat.elsXmitACC++; |
| 6601 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 6602 | lpfc_els_free_iocb(phba, elsiocb); |
| 6603 | return 0; |
| 6604 | |
| 6605 | reject_out: |
| 6606 | /* issue rejection response */ |
| 6607 | stat.un.b.lsRjtRsvd0 = 0; |
| 6608 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6609 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6610 | stat.un.b.vendorUnique = 0; |
| 6611 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6612 | return 0; |
| 6613 | } |
| 6614 | |
| 6615 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6616 | * @vport: pointer to a host virtual N_Port data structure. |
| 6617 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6618 | * @ndlp: pointer to a node-list data structure. |
| 6619 | * |
| 6620 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 6621 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6622 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6623 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 6624 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 6625 | * for reading the HBA link statistics. It is for the callback function, |
| 6626 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 6627 | * to actually sending out RPS Accept (ACC) response. |
| 6628 | * |
| 6629 | * Return codes |
| 6630 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 6631 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6632 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6633 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6634 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6635 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6636 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6637 | uint32_t *lp; |
| 6638 | uint8_t flag; |
| 6639 | LPFC_MBOXQ_t *mbox; |
| 6640 | struct lpfc_dmabuf *pcmd; |
| 6641 | RPS *rps; |
| 6642 | struct ls_rjt stat; |
| 6643 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6644 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6645 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6646 | /* reject the unsolicited RPS request and done with it */ |
| 6647 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6648 | |
| 6649 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6650 | lp = (uint32_t *) pcmd->virt; |
| 6651 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 6652 | rps = (RPS *) lp; |
| 6653 | |
| 6654 | if ((flag == 0) || |
| 6655 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6656 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6657 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6658 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6659 | printk("Fix me....\n"); |
| 6660 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6661 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 6662 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6663 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6664 | mbox->context1 = (void *)((unsigned long) |
| 6665 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 6666 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6667 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6668 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6669 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6670 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6671 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6672 | /* Mbox completion will send ELS Response */ |
| 6673 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6674 | /* Decrement reference count used for the failed mbox |
| 6675 | * command. |
| 6676 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6677 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6678 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6679 | } |
| 6680 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6681 | |
| 6682 | reject_out: |
| 6683 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6684 | stat.un.b.lsRjtRsvd0 = 0; |
| 6685 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6686 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6687 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6688 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6689 | return 0; |
| 6690 | } |
| 6691 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6692 | /* lpfc_issue_els_rrq - Process an unsolicited rps iocb |
| 6693 | * @vport: pointer to a host virtual N_Port data structure. |
| 6694 | * @ndlp: pointer to a node-list data structure. |
| 6695 | * @did: DID of the target. |
| 6696 | * @rrq: Pointer to the rrq struct. |
| 6697 | * |
| 6698 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is |
| 6699 | * Successful the the completion handler will clear the RRQ. |
| 6700 | * |
| 6701 | * Return codes |
| 6702 | * 0 - Successfully sent rrq els iocb. |
| 6703 | * 1 - Failed to send rrq els iocb. |
| 6704 | **/ |
| 6705 | static int |
| 6706 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6707 | uint32_t did, struct lpfc_node_rrq *rrq) |
| 6708 | { |
| 6709 | struct lpfc_hba *phba = vport->phba; |
| 6710 | struct RRQ *els_rrq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6711 | struct lpfc_iocbq *elsiocb; |
| 6712 | uint8_t *pcmd; |
| 6713 | uint16_t cmdsize; |
| 6714 | int ret; |
| 6715 | |
| 6716 | |
| 6717 | if (ndlp != rrq->ndlp) |
| 6718 | ndlp = rrq->ndlp; |
| 6719 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 6720 | return 1; |
| 6721 | |
| 6722 | /* If ndlp is not NULL, we will bump the reference count on it */ |
| 6723 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); |
| 6724 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, |
| 6725 | ELS_CMD_RRQ); |
| 6726 | if (!elsiocb) |
| 6727 | return 1; |
| 6728 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6729 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6730 | |
| 6731 | /* For RRQ request, remainder of payload is Exchange IDs */ |
| 6732 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; |
| 6733 | pcmd += sizeof(uint32_t); |
| 6734 | els_rrq = (struct RRQ *) pcmd; |
| 6735 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 6736 | 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] | 6737 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
| 6738 | bf_set(rrq_did, els_rrq, vport->fc_myDID); |
| 6739 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); |
| 6740 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); |
| 6741 | |
| 6742 | |
| 6743 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6744 | "Issue RRQ: did:x%x", |
| 6745 | did, rrq->xritag, rrq->rxid); |
| 6746 | elsiocb->context_un.rrq = rrq; |
| 6747 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; |
| 6748 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6749 | |
| 6750 | if (ret == IOCB_ERROR) { |
| 6751 | lpfc_els_free_iocb(phba, elsiocb); |
| 6752 | return 1; |
| 6753 | } |
| 6754 | return 0; |
| 6755 | } |
| 6756 | |
| 6757 | /** |
| 6758 | * lpfc_send_rrq - Sends ELS RRQ if needed. |
| 6759 | * @phba: pointer to lpfc hba data structure. |
| 6760 | * @rrq: pointer to the active rrq. |
| 6761 | * |
| 6762 | * This routine will call the lpfc_issue_els_rrq if the rrq is |
| 6763 | * still active for the xri. If this function returns a failure then |
| 6764 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. |
| 6765 | * |
| 6766 | * Returns 0 Success. |
| 6767 | * 1 Failure. |
| 6768 | **/ |
| 6769 | int |
| 6770 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) |
| 6771 | { |
| 6772 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, |
| 6773 | rrq->nlp_DID); |
| 6774 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) |
| 6775 | return lpfc_issue_els_rrq(rrq->vport, ndlp, |
| 6776 | rrq->nlp_DID, rrq); |
| 6777 | else |
| 6778 | return 1; |
| 6779 | } |
| 6780 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6781 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6782 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6783 | * @vport: pointer to a host virtual N_Port data structure. |
| 6784 | * @cmdsize: size of the ELS command. |
| 6785 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 6786 | * @ndlp: pointer to a node-list data structure. |
| 6787 | * |
| 6788 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 6789 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 6790 | * |
| 6791 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6792 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6793 | * will be stored into the context1 field of the IOCB for the completion |
| 6794 | * callback function to the RPL Accept Response ELS command. |
| 6795 | * |
| 6796 | * Return code |
| 6797 | * 0 - Successfully issued ACC RPL ELS command |
| 6798 | * 1 - Failed to issue ACC RPL ELS command |
| 6799 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 6800 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6801 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 6802 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6803 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6804 | struct lpfc_hba *phba = vport->phba; |
| 6805 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6806 | RPL_RSP rpl_rsp; |
| 6807 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6808 | uint8_t *pcmd; |
| 6809 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6810 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 6811 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6812 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6813 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6814 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6815 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6816 | icmd = &elsiocb->iocb; |
| 6817 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6818 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 6819 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6820 | |
| 6821 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6822 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6823 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6824 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 6825 | pcmd += sizeof(uint16_t); |
| 6826 | |
| 6827 | /* Setup the RPL ACC payload */ |
| 6828 | rpl_rsp.listLen = be32_to_cpu(1); |
| 6829 | rpl_rsp.index = 0; |
| 6830 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6831 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 6832 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6833 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6834 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6835 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6836 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6837 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 6838 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 6839 | "rpi x%x\n", |
| 6840 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6841 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6842 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6843 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6844 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6845 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6846 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6847 | lpfc_els_free_iocb(phba, elsiocb); |
| 6848 | return 1; |
| 6849 | } |
| 6850 | return 0; |
| 6851 | } |
| 6852 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6853 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6854 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6855 | * @vport: pointer to a host virtual N_Port data structure. |
| 6856 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6857 | * @ndlp: pointer to a node-list data structure. |
| 6858 | * |
| 6859 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 6860 | * unsolicited event. It first checks the remote port state. If the remote |
| 6861 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 6862 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 6863 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 6864 | * to accept the RPL. |
| 6865 | * |
| 6866 | * Return code |
| 6867 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 6868 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6869 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6870 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6871 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6872 | { |
| 6873 | struct lpfc_dmabuf *pcmd; |
| 6874 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6875 | uint32_t maxsize; |
| 6876 | uint16_t cmdsize; |
| 6877 | RPL *rpl; |
| 6878 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6879 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6880 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6881 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6882 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6883 | stat.un.b.lsRjtRsvd0 = 0; |
| 6884 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6885 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6886 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6887 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 6888 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6889 | /* rejected the unsolicited RPL request and done with it */ |
| 6890 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6891 | } |
| 6892 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6893 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6894 | lp = (uint32_t *) pcmd->virt; |
| 6895 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6896 | maxsize = be32_to_cpu(rpl->maxsize); |
| 6897 | |
| 6898 | /* We support only one port */ |
| 6899 | if ((rpl->index == 0) && |
| 6900 | ((maxsize == 0) || |
| 6901 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 6902 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6903 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6904 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 6905 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6906 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6907 | |
| 6908 | return 0; |
| 6909 | } |
| 6910 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6911 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6912 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6913 | * @vport: pointer to a virtual N_Port data structure. |
| 6914 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6915 | * @ndlp: pointer to a node-list data structure. |
| 6916 | * |
| 6917 | * This routine processes Fibre Channel Address Resolution Protocol |
| 6918 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 6919 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 6920 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 6921 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 6922 | * remote PortName is compared against the FC PortName stored in the @vport |
| 6923 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 6924 | * compared against the FC NodeName stored in the @vport data structure. |
| 6925 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 6926 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 6927 | * invoked to send out FARP Response to the remote node. Before sending the |
| 6928 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 6929 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 6930 | * routine is invoked to log into the remote port first. |
| 6931 | * |
| 6932 | * Return code |
| 6933 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 6934 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6935 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6936 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6937 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6938 | { |
| 6939 | struct lpfc_dmabuf *pcmd; |
| 6940 | uint32_t *lp; |
| 6941 | IOCB_t *icmd; |
| 6942 | FARP *fp; |
| 6943 | uint32_t cmd, cnt, did; |
| 6944 | |
| 6945 | icmd = &cmdiocb->iocb; |
| 6946 | did = icmd->un.elsreq64.remoteID; |
| 6947 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6948 | lp = (uint32_t *) pcmd->virt; |
| 6949 | |
| 6950 | cmd = *lp++; |
| 6951 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6952 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6953 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6954 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6955 | /* We will only support match on WWPN or WWNN */ |
| 6956 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6957 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6958 | } |
| 6959 | |
| 6960 | cnt = 0; |
| 6961 | /* If this FARP command is searching for my portname */ |
| 6962 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6963 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6964 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6965 | cnt = 1; |
| 6966 | } |
| 6967 | |
| 6968 | /* If this FARP command is searching for my nodename */ |
| 6969 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6970 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6971 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6972 | cnt = 1; |
| 6973 | } |
| 6974 | |
| 6975 | if (cnt) { |
| 6976 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 6977 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 6978 | /* Log back into the node before sending the FARP. */ |
| 6979 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6980 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6981 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 6982 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6983 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6984 | } |
| 6985 | |
| 6986 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6987 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 6988 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6989 | } |
| 6990 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6991 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6992 | } |
| 6993 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6994 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6995 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6996 | * @vport: pointer to a host virtual N_Port data structure. |
| 6997 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6998 | * @ndlp: pointer to a node-list data structure. |
| 6999 | * |
| 7000 | * This routine processes Fibre Channel Address Resolution Protocol |
| 7001 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 7002 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 7003 | * the FARP response request. |
| 7004 | * |
| 7005 | * Return code |
| 7006 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 7007 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7008 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7009 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7010 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7011 | { |
| 7012 | struct lpfc_dmabuf *pcmd; |
| 7013 | uint32_t *lp; |
| 7014 | IOCB_t *icmd; |
| 7015 | uint32_t cmd, did; |
| 7016 | |
| 7017 | icmd = &cmdiocb->iocb; |
| 7018 | did = icmd->un.elsreq64.remoteID; |
| 7019 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7020 | lp = (uint32_t *) pcmd->virt; |
| 7021 | |
| 7022 | cmd = *lp++; |
| 7023 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7024 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7025 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7026 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7027 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7028 | |
| 7029 | return 0; |
| 7030 | } |
| 7031 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7032 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7033 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7034 | * @vport: pointer to a host virtual N_Port data structure. |
| 7035 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7036 | * @fan_ndlp: pointer to a node-list data structure. |
| 7037 | * |
| 7038 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 7039 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 7040 | * only be processed on a physical port (i.e., the @vport represents the |
| 7041 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 7042 | * compared against those in the phba data structure. If any of those is |
| 7043 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 7044 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 7045 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 7046 | * is invoked to register login to the fabric. |
| 7047 | * |
| 7048 | * Return code |
| 7049 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 7050 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7051 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7052 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7053 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7054 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7055 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7056 | uint32_t *lp; |
| 7057 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7058 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7059 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 7060 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 7061 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7062 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7063 | if ((vport == phba->pport) && |
| 7064 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7065 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7066 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7067 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7068 | sizeof(struct lpfc_name)))) { |
| 7069 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7070 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7071 | } else { |
| 7072 | /* FAN verified - skip FLOGI */ |
| 7073 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7074 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 7075 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7076 | else { |
| 7077 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7078 | "3138 Need register VFI: (x%x/%x)\n", |
| 7079 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7080 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7081 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7082 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7083 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7084 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7085 | } |
| 7086 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7087 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7088 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7089 | * @ptr: holder for the timer function associated data. |
| 7090 | * |
| 7091 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 7092 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 7093 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 7094 | * up the worker thread. It is for the worker thread to invoke the routine |
| 7095 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 7096 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7097 | void |
| 7098 | lpfc_els_timeout(unsigned long ptr) |
| 7099 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7100 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 7101 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7102 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7103 | unsigned long iflag; |
| 7104 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7105 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7106 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7107 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7108 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7109 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7110 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7111 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7112 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7113 | return; |
| 7114 | } |
| 7115 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7116 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7117 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7118 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7119 | * @vport: pointer to a virtual N_Port data structure. |
| 7120 | * |
| 7121 | * This routine is the actual handler function that processes an ELS timeout |
| 7122 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 7123 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 7124 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 7125 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7126 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7127 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7128 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7129 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7130 | struct lpfc_sli_ring *pring; |
| 7131 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7132 | IOCB_t *cmd = NULL; |
| 7133 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7134 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7135 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7136 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7137 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7138 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7139 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7140 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 7141 | |
| 7142 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7143 | if ((phba->pport->load_flag & FC_UNLOADING)) |
| 7144 | return; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7145 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7146 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7147 | spin_lock(&pring->ring_lock); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7148 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7149 | if ((phba->pport->load_flag & FC_UNLOADING)) { |
| 7150 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7151 | spin_unlock(&pring->ring_lock); |
| 7152 | spin_unlock_irq(&phba->hbalock); |
| 7153 | return; |
| 7154 | } |
| 7155 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7156 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7157 | cmd = &piocb->iocb; |
| 7158 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7159 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 7160 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 7161 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7162 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7163 | |
| 7164 | if (piocb->vport != vport) |
| 7165 | continue; |
| 7166 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7167 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7168 | if (pcmd) |
| 7169 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7170 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7171 | if (els_command == ELS_CMD_FARP || |
| 7172 | els_command == ELS_CMD_FARPR || |
| 7173 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7174 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7175 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7176 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7177 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7178 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7179 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7180 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7181 | continue; |
| 7182 | } |
| 7183 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7184 | remote_ID = 0xffffffff; |
| 7185 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7186 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7187 | else { |
| 7188 | struct lpfc_nodelist *ndlp; |
| 7189 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7190 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7191 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7192 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7193 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7194 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7195 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7196 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7197 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 7198 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7199 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
James Smart | 15026c9 | 2013-12-17 20:30:09 -0500 | [diff] [blame] | 7200 | cmd = &piocb->iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7201 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7202 | "0127 ELS timeout Data: x%x x%x x%x " |
| 7203 | "x%x\n", els_command, |
| 7204 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 7205 | spin_lock_irq(&phba->hbalock); |
| 7206 | list_del_init(&piocb->dlist); |
| 7207 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 7208 | spin_unlock_irq(&phba->hbalock); |
| 7209 | } |
| 7210 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 7211 | if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq)) |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 7212 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 7213 | mod_timer(&vport->els_tmofunc, |
| 7214 | jiffies + msecs_to_jiffies(1000 * timeout)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7215 | } |
| 7216 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7217 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7218 | * 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] | 7219 | * @vport: pointer to a host virtual N_Port data structure. |
| 7220 | * |
| 7221 | * This routine is used to clean up all the outstanding ELS commands on a |
| 7222 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 7223 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 7224 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 7225 | * the IOCBs with a non-NULL completion callback function, the callback |
| 7226 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 7227 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 7228 | * callback function, the IOCB will simply be released. Finally, it walks |
| 7229 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 7230 | * completion queue IOCB that is associated with the @vport and is not |
| 7231 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 7232 | * part of the discovery state machine) out to HBA by invoking the |
| 7233 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 7234 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 7235 | * the IOCBs are aborted when this function returns. |
| 7236 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7237 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7238 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7239 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7240 | LIST_HEAD(abort_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7241 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7242 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7243 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7244 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7245 | |
| 7246 | lpfc_fabric_abort_vport(vport); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7247 | /* |
| 7248 | * For SLI3, only the hbalock is required. But SLI4 needs to coordinate |
| 7249 | * with the ring insert operation. Because lpfc_sli_issue_abort_iotag |
| 7250 | * ultimately grabs the ring_lock, the driver must splice the list into |
| 7251 | * a working list and release the locks before calling the abort. |
| 7252 | */ |
| 7253 | spin_lock_irq(&phba->hbalock); |
| 7254 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7255 | spin_lock(&pring->ring_lock); |
| 7256 | |
| 7257 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 7258 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 7259 | continue; |
| 7260 | |
| 7261 | if (piocb->vport != vport) |
| 7262 | continue; |
| 7263 | list_add_tail(&piocb->dlist, &abort_list); |
| 7264 | } |
| 7265 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7266 | spin_unlock(&pring->ring_lock); |
| 7267 | spin_unlock_irq(&phba->hbalock); |
| 7268 | /* Abort each iocb on the aborted list and remove the dlist links. */ |
| 7269 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 7270 | spin_lock_irq(&phba->hbalock); |
| 7271 | list_del_init(&piocb->dlist); |
| 7272 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 7273 | spin_unlock_irq(&phba->hbalock); |
| 7274 | } |
| 7275 | if (!list_empty(&abort_list)) |
| 7276 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7277 | "3387 abort list for txq not empty\n"); |
| 7278 | INIT_LIST_HEAD(&abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7279 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7280 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7281 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7282 | spin_lock(&pring->ring_lock); |
| 7283 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7284 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 7285 | cmd = &piocb->iocb; |
| 7286 | |
| 7287 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 7288 | continue; |
| 7289 | } |
| 7290 | |
| 7291 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7292 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 7293 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 7294 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 7295 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7296 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7297 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7298 | if (piocb->vport != vport) |
| 7299 | continue; |
| 7300 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7301 | list_del_init(&piocb->list); |
| 7302 | list_add_tail(&piocb->list, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7303 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7304 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7305 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7306 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 7307 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7308 | /* Cancell all the IOCBs from the completions list */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7309 | lpfc_sli_cancel_iocbs(phba, &abort_list, |
| 7310 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 7311 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7312 | return; |
| 7313 | } |
| 7314 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7315 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7316 | * lpfc_els_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] | 7317 | * @phba: pointer to lpfc hba data structure. |
| 7318 | * |
| 7319 | * This routine is used to clean up all the outstanding ELS commands on a |
| 7320 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 7321 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 7322 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 7323 | * the IOCBs with the completion callback function associated, the callback |
| 7324 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 7325 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 7326 | * callback function associated, the IOCB will simply be released. Finally, |
| 7327 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 7328 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 7329 | * management plane IOCBs that are not part of the discovery state machine) |
| 7330 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 7331 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 7332 | void |
| 7333 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 7334 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7335 | struct lpfc_vport *vport; |
| 7336 | list_for_each_entry(vport, &phba->port_list, listentry) |
| 7337 | lpfc_els_flush_cmd(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7338 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 7339 | return; |
| 7340 | } |
| 7341 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7342 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7343 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7344 | * @phba: Pointer to hba context object. |
| 7345 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 7346 | * @rspiocbp: Pointer to response iocb which reported error. |
| 7347 | * |
| 7348 | * This function sends an event when there is an ELS command |
| 7349 | * failure. |
| 7350 | **/ |
| 7351 | void |
| 7352 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 7353 | struct lpfc_iocbq *cmdiocbp, |
| 7354 | struct lpfc_iocbq *rspiocbp) |
| 7355 | { |
| 7356 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 7357 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7358 | struct lpfc_lsrjt_event lsrjt_event; |
| 7359 | struct lpfc_fabric_event_header fabric_event; |
| 7360 | struct ls_rjt stat; |
| 7361 | struct lpfc_nodelist *ndlp; |
| 7362 | uint32_t *pcmd; |
| 7363 | |
| 7364 | ndlp = cmdiocbp->context1; |
| 7365 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 7366 | return; |
| 7367 | |
| 7368 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 7369 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 7370 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 7371 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 7372 | sizeof(struct lpfc_name)); |
| 7373 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 7374 | sizeof(struct lpfc_name)); |
| 7375 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 7376 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7377 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7378 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 7379 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 7380 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 7381 | fc_host_post_vendor_event(shost, |
| 7382 | fc_get_event_number(), |
| 7383 | sizeof(lsrjt_event), |
| 7384 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7385 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7386 | return; |
| 7387 | } |
| 7388 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 7389 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 7390 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 7391 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 7392 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 7393 | else |
| 7394 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 7395 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 7396 | sizeof(struct lpfc_name)); |
| 7397 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 7398 | sizeof(struct lpfc_name)); |
| 7399 | fc_host_post_vendor_event(shost, |
| 7400 | fc_get_event_number(), |
| 7401 | sizeof(fabric_event), |
| 7402 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7403 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7404 | return; |
| 7405 | } |
| 7406 | |
| 7407 | } |
| 7408 | |
| 7409 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7410 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7411 | * @vport: Pointer to vport object. |
| 7412 | * @ndlp: Pointer FC node object. |
| 7413 | * @cmd: ELS command code. |
| 7414 | * |
| 7415 | * This function posts an event when there is an incoming |
| 7416 | * unsolicited ELS command. |
| 7417 | **/ |
| 7418 | static void |
| 7419 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 7420 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7421 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7422 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7423 | struct lpfc_els_event_header *els_data = NULL; |
| 7424 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7425 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7426 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7427 | if (*payload == ELS_CMD_LOGO) { |
| 7428 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 7429 | if (!logo_data) { |
| 7430 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7431 | "0148 Failed to allocate memory " |
| 7432 | "for LOGO event\n"); |
| 7433 | return; |
| 7434 | } |
| 7435 | els_data = &logo_data->header; |
| 7436 | } else { |
| 7437 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 7438 | GFP_KERNEL); |
| 7439 | if (!els_data) { |
| 7440 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7441 | "0149 Failed to allocate memory " |
| 7442 | "for ELS event\n"); |
| 7443 | return; |
| 7444 | } |
| 7445 | } |
| 7446 | els_data->event_type = FC_REG_ELS_EVENT; |
| 7447 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7448 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7449 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7450 | break; |
| 7451 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7452 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7453 | break; |
| 7454 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7455 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 7456 | break; |
| 7457 | case ELS_CMD_LOGO: |
| 7458 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 7459 | /* Copy the WWPN in the LOGO payload */ |
| 7460 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 7461 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7462 | break; |
| 7463 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 7464 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7465 | return; |
| 7466 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7467 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 7468 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 7469 | if (*payload == ELS_CMD_LOGO) { |
| 7470 | fc_host_post_vendor_event(shost, |
| 7471 | fc_get_event_number(), |
| 7472 | sizeof(struct lpfc_logo_event), |
| 7473 | (char *)logo_data, |
| 7474 | LPFC_NL_VENDOR_ID); |
| 7475 | kfree(logo_data); |
| 7476 | } else { |
| 7477 | fc_host_post_vendor_event(shost, |
| 7478 | fc_get_event_number(), |
| 7479 | sizeof(struct lpfc_els_event_header), |
| 7480 | (char *)els_data, |
| 7481 | LPFC_NL_VENDOR_ID); |
| 7482 | kfree(els_data); |
| 7483 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7484 | |
| 7485 | return; |
| 7486 | } |
| 7487 | |
| 7488 | |
| 7489 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7490 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7491 | * @phba: pointer to lpfc hba data structure. |
| 7492 | * @pring: pointer to a SLI ring. |
| 7493 | * @vport: pointer to a host virtual N_Port data structure. |
| 7494 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 7495 | * |
| 7496 | * This routine is used for processing the IOCB associated with a unsolicited |
| 7497 | * event. It first determines whether there is an existing ndlp that matches |
| 7498 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 7499 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 7500 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 7501 | * of the discovery state machine. |
| 7502 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7503 | static void |
| 7504 | 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] | 7505 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7506 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7507 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7508 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7509 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7510 | uint32_t *payload; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7511 | uint32_t cmd, did, newnode; |
| 7512 | uint8_t rjt_exp, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7513 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7514 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7515 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7516 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7517 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7518 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7519 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 7520 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7521 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 7522 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7523 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7524 | did = icmd->un.rcvels.remoteID; |
| 7525 | if (icmd->ulpStatus) { |
| 7526 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7527 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 7528 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7529 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7530 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7531 | |
| 7532 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7533 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7534 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7535 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7536 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7537 | if (vport->load_flag & FC_UNLOADING) |
| 7538 | goto dropit; |
| 7539 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7540 | /* If NPort discovery is delayed drop incoming ELS */ |
| 7541 | if ((vport->fc_flag & FC_DISC_DELAYED) && |
| 7542 | (cmd != ELS_CMD_PLOGI)) |
| 7543 | goto dropit; |
| 7544 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7545 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7546 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7547 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7548 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7549 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7550 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7551 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7552 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7553 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7554 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7555 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7556 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7557 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 7558 | ndlp = lpfc_enable_node(vport, ndlp, |
| 7559 | NLP_STE_UNUSED_NODE); |
| 7560 | if (!ndlp) |
| 7561 | goto dropit; |
| 7562 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 7563 | newnode = 1; |
| 7564 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 7565 | ndlp->nlp_type |= NLP_FABRIC; |
| 7566 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 7567 | /* This is similar to the new node path */ |
| 7568 | ndlp = lpfc_nlp_get(ndlp); |
| 7569 | if (!ndlp) |
| 7570 | goto dropit; |
| 7571 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 7572 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7573 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7574 | |
| 7575 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7576 | |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7577 | /* |
| 7578 | * Do not process any unsolicited ELS commands |
| 7579 | * if the ndlp is in DEV_LOSS |
| 7580 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 7581 | shost = lpfc_shost_from_vport(vport); |
| 7582 | spin_lock_irq(shost->host_lock); |
| 7583 | if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) { |
| 7584 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7585 | goto dropit; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 7586 | } |
| 7587 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7588 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7589 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7590 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7591 | |
| 7592 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 7593 | cmd &= ELS_CMD_MASK; |
| 7594 | } |
| 7595 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7596 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7597 | "0112 ELS command x%x received from NPORT x%x " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7598 | "Data: x%x x%x x%x x%x\n", |
| 7599 | cmd, did, vport->port_state, vport->fc_flag, |
| 7600 | vport->fc_myDID, vport->fc_prevDID); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7601 | |
| 7602 | /* reject till our FLOGI completes */ |
| 7603 | if ((vport->port_state < LPFC_FABRIC_CFG_LINK) && |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7604 | (cmd != ELS_CMD_FLOGI)) { |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7605 | rjt_err = LSRJT_UNABLE_TPC; |
| 7606 | rjt_exp = LSEXP_NOTHING_MORE; |
| 7607 | goto lsrjt; |
| 7608 | } |
| 7609 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7610 | switch (cmd) { |
| 7611 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7612 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7613 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 7614 | did, vport->port_state, ndlp->nlp_flag); |
| 7615 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7616 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7617 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7618 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 7619 | (phba->pport->fc_flag & FC_PT2PT)) { |
| 7620 | vport->fc_prevDID = vport->fc_myDID; |
| 7621 | /* Our DID needs to be updated before registering |
| 7622 | * the vfi. This is done in lpfc_rcv_plogi but |
| 7623 | * that is called after the reg_vfi. |
| 7624 | */ |
| 7625 | vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo; |
| 7626 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7627 | "3312 Remote port assigned DID x%x " |
| 7628 | "%x\n", vport->fc_myDID, |
| 7629 | vport->fc_prevDID); |
| 7630 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7631 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7632 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7633 | |
| 7634 | /* If Nport discovery is delayed, reject PLOGIs */ |
| 7635 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 7636 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7637 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7638 | break; |
| 7639 | } |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7640 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7641 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 7642 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 7643 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 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 | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 7646 | break; |
| 7647 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7648 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7649 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7650 | spin_lock_irq(shost->host_lock); |
| 7651 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 7652 | spin_unlock_irq(shost->host_lock); |
| 7653 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7654 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7655 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7656 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7657 | break; |
| 7658 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7659 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7660 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 7661 | did, vport->port_state, ndlp->nlp_flag); |
| 7662 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7663 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7664 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7665 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7666 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7667 | break; |
| 7668 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7669 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7670 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 7671 | did, vport->port_state, ndlp->nlp_flag); |
| 7672 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7673 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7674 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7675 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7676 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7677 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7678 | break; |
| 7679 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7680 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7681 | break; |
| 7682 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7683 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7684 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 7685 | did, vport->port_state, ndlp->nlp_flag); |
| 7686 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7687 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7688 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7689 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7690 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7691 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7692 | break; |
| 7693 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7694 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7695 | break; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 7696 | case ELS_CMD_LCB: |
| 7697 | phba->fc_stat.elsRcvLCB++; |
| 7698 | lpfc_els_rcv_lcb(vport, elsiocb, ndlp); |
| 7699 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 7700 | case ELS_CMD_RDP: |
| 7701 | phba->fc_stat.elsRcvRDP++; |
| 7702 | lpfc_els_rcv_rdp(vport, elsiocb, ndlp); |
| 7703 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7704 | case ELS_CMD_RSCN: |
| 7705 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7706 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7707 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7708 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7709 | break; |
| 7710 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7711 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7712 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 7713 | did, vport->port_state, ndlp->nlp_flag); |
| 7714 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7715 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7716 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7717 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7718 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7719 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7720 | break; |
| 7721 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7722 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7723 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7724 | break; |
| 7725 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7726 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7727 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 7728 | did, vport->port_state, ndlp->nlp_flag); |
| 7729 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7730 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7731 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7732 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7733 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7734 | break; |
| 7735 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7736 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7737 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7738 | break; |
| 7739 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7740 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7741 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 7742 | did, vport->port_state, ndlp->nlp_flag); |
| 7743 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7744 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7745 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7746 | break; |
| 7747 | case ELS_CMD_FARP: |
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 FARP: 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.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7753 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7754 | break; |
| 7755 | case ELS_CMD_FAN: |
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 FAN: 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.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7761 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7762 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7763 | case ELS_CMD_PRLI: |
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 PRLI: 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.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7769 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7770 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7771 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7772 | break; |
| 7773 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7774 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7775 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7776 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7777 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7778 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 7779 | did, vport->port_state, ndlp->nlp_flag); |
| 7780 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7781 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7782 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7783 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7784 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7785 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7786 | case ELS_CMD_RLS: |
| 7787 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7788 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 7789 | did, vport->port_state, ndlp->nlp_flag); |
| 7790 | |
| 7791 | phba->fc_stat.elsRcvRLS++; |
| 7792 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 7793 | if (newnode) |
| 7794 | lpfc_nlp_put(ndlp); |
| 7795 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7796 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7797 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7798 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 7799 | did, vport->port_state, ndlp->nlp_flag); |
| 7800 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7801 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7802 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7803 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7804 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7805 | break; |
| 7806 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7807 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7808 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 7809 | did, vport->port_state, ndlp->nlp_flag); |
| 7810 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7811 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7812 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7813 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7814 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7815 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7816 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7817 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7818 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 7819 | did, vport->port_state, ndlp->nlp_flag); |
| 7820 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7821 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7822 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7823 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7824 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7825 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7826 | case ELS_CMD_RTV: |
| 7827 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7828 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 7829 | did, vport->port_state, ndlp->nlp_flag); |
| 7830 | phba->fc_stat.elsRcvRTV++; |
| 7831 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 7832 | if (newnode) |
| 7833 | lpfc_nlp_put(ndlp); |
| 7834 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7835 | case ELS_CMD_RRQ: |
| 7836 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7837 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 7838 | did, vport->port_state, ndlp->nlp_flag); |
| 7839 | |
| 7840 | phba->fc_stat.elsRcvRRQ++; |
| 7841 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 7842 | if (newnode) |
| 7843 | lpfc_nlp_put(ndlp); |
| 7844 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7845 | case ELS_CMD_ECHO: |
| 7846 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7847 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 7848 | did, vport->port_state, ndlp->nlp_flag); |
| 7849 | |
| 7850 | phba->fc_stat.elsRcvECHO++; |
| 7851 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 7852 | if (newnode) |
| 7853 | lpfc_nlp_put(ndlp); |
| 7854 | break; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7855 | case ELS_CMD_REC: |
| 7856 | /* receive this due to exchange closed */ |
| 7857 | rjt_err = LSRJT_UNABLE_TPC; |
| 7858 | rjt_exp = LSEXP_INVALID_OX_RX; |
| 7859 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7860 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7861 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7862 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 7863 | cmd, did, vport->port_state); |
| 7864 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7865 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7866 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7867 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7868 | |
| 7869 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7870 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7871 | "0115 Unknown ELS command x%x " |
| 7872 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7873 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7874 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7875 | break; |
| 7876 | } |
| 7877 | |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7878 | lsrjt: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7879 | /* check if need to LS_RJT received ELS cmd */ |
| 7880 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7881 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7882 | stat.un.b.lsRjtRsnCode = rjt_err; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7883 | stat.un.b.lsRjtRsnCodeExp = rjt_exp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7884 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 7885 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7886 | } |
| 7887 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7888 | lpfc_nlp_put(elsiocb->context1); |
| 7889 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7890 | return; |
| 7891 | |
| 7892 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7893 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7894 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7895 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7896 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7897 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7898 | phba->fc_stat.elsRcvDrop++; |
| 7899 | } |
| 7900 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7901 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7902 | * 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] | 7903 | * @phba: pointer to lpfc hba data structure. |
| 7904 | * @pring: pointer to a SLI ring. |
| 7905 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 7906 | * |
| 7907 | * This routine is used to process an unsolicited event received from a SLI |
| 7908 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 7909 | * associated with the unsolicited event is done by invoking the routine |
| 7910 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 7911 | * SLI ring on which the unsolicited event was received. |
| 7912 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7913 | void |
| 7914 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 7915 | struct lpfc_iocbq *elsiocb) |
| 7916 | { |
| 7917 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7918 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7919 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7920 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 7921 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7922 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7923 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7924 | elsiocb->context2 = NULL; |
| 7925 | elsiocb->context3 = NULL; |
| 7926 | |
| 7927 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 7928 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 7929 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 7930 | (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 7931 | IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7932 | phba->fc_stat.NoRcvBuf++; |
| 7933 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7934 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 7935 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7936 | return; |
| 7937 | } |
| 7938 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7939 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 7940 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 7941 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 7942 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 7943 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7944 | else |
| 7945 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7946 | icmd->unsli3.rcvsli3.vpi); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7947 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7948 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7949 | /* If there are no BDEs associated |
| 7950 | * with this IOCB, there is nothing to do. |
| 7951 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7952 | if (icmd->ulpBdeCount == 0) |
| 7953 | return; |
| 7954 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7955 | /* type of ELS cmd is first 32bit word |
| 7956 | * in packet |
| 7957 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7958 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7959 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7960 | } else { |
| 7961 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 7962 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7963 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 7964 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7965 | } |
| 7966 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7967 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 7968 | /* |
| 7969 | * The different unsolicited event handlers would tell us |
| 7970 | * if they are done with "mp" by setting context2 to NULL. |
| 7971 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7972 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7973 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 7974 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7975 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7976 | |
| 7977 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7978 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7979 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7980 | elsiocb->context2 = bdeBuf2; |
| 7981 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7982 | /* free mp if we are done with it */ |
| 7983 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7984 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 7985 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7986 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7987 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7988 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7989 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7990 | void |
| 7991 | lpfc_start_fdmi(struct lpfc_vport *vport) |
| 7992 | { |
| 7993 | struct lpfc_hba *phba = vport->phba; |
| 7994 | struct lpfc_nodelist *ndlp; |
| 7995 | |
| 7996 | /* If this is the first time, allocate an ndlp and initialize |
| 7997 | * it. Otherwise, make sure the node is enabled and then do the |
| 7998 | * login. |
| 7999 | */ |
| 8000 | ndlp = lpfc_findnode_did(vport, FDMI_DID); |
| 8001 | if (!ndlp) { |
| 8002 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 8003 | if (ndlp) { |
| 8004 | lpfc_nlp_init(vport, ndlp, FDMI_DID); |
| 8005 | ndlp->nlp_type |= NLP_FABRIC; |
| 8006 | } else { |
| 8007 | return; |
| 8008 | } |
| 8009 | } |
| 8010 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 8011 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 8012 | |
| 8013 | if (ndlp) { |
| 8014 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 8015 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| 8016 | } |
| 8017 | } |
| 8018 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8019 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8020 | * 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] | 8021 | * @phba: pointer to lpfc hba data structure. |
| 8022 | * @vport: pointer to a virtual N_Port data structure. |
| 8023 | * |
| 8024 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 8025 | * State Change Request (SCR) for a @vport. This routine will create an |
| 8026 | * ndlp for the Name Server associated to the @vport if such node does |
| 8027 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 8028 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 8029 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 8030 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 8031 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8032 | void |
| 8033 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 8034 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8035 | struct lpfc_nodelist *ndlp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8036 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8037 | |
| 8038 | /* |
| 8039 | * If lpfc_delay_discovery parameter is set and the clean address |
| 8040 | * bit is cleared and fc fabric parameters chenged, delay FC NPort |
| 8041 | * discovery. |
| 8042 | */ |
| 8043 | spin_lock_irq(shost->host_lock); |
| 8044 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 8045 | spin_unlock_irq(shost->host_lock); |
James Smart | 1877570 | 2013-04-17 20:19:25 -0400 | [diff] [blame] | 8046 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 8047 | "3334 Delay fc port discovery for %d seconds\n", |
| 8048 | phba->fc_ratov); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8049 | mod_timer(&vport->delayed_disc_tmo, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8050 | jiffies + msecs_to_jiffies(1000 * phba->fc_ratov)); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8051 | return; |
| 8052 | } |
| 8053 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8054 | |
| 8055 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 8056 | if (!ndlp) { |
| 8057 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 8058 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8059 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8060 | lpfc_disc_start(vport); |
| 8061 | return; |
| 8062 | } |
| 8063 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8064 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8065 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8066 | return; |
| 8067 | } |
| 8068 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8069 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 8070 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 8071 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8072 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8073 | lpfc_disc_start(vport); |
| 8074 | return; |
| 8075 | } |
| 8076 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 8077 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8078 | "0348 NameServer login: node freed\n"); |
| 8079 | return; |
| 8080 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8081 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8082 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8083 | |
| 8084 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 8085 | |
| 8086 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 8087 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8088 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8089 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8090 | return; |
| 8091 | } |
| 8092 | |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 8093 | if ((phba->cfg_enable_SmartSAN || |
| 8094 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) && |
| 8095 | (vport->load_flag & FC_ALLOW_FDMI)) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8096 | lpfc_start_fdmi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8097 | } |
| 8098 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8099 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8100 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8101 | * @phba: pointer to lpfc hba data structure. |
| 8102 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 8103 | * |
| 8104 | * This routine is the completion callback function to register new vport |
| 8105 | * mailbox command. If the new vport mailbox command completes successfully, |
| 8106 | * the fabric registration login shall be performed on physical port (the |
| 8107 | * new vport created is actually a physical port, with VPI 0) or the port |
| 8108 | * login to Name Server for State Change Request (SCR) will be performed |
| 8109 | * on virtual port (real virtual port, with VPI greater than 0). |
| 8110 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8111 | static void |
| 8112 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 8113 | { |
| 8114 | struct lpfc_vport *vport = pmb->vport; |
| 8115 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8116 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 8117 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8118 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8119 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8120 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8121 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8122 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8123 | |
| 8124 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8125 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8126 | "0915 Register VPI failed : Status: x%x" |
| 8127 | " upd bit: x%x \n", mb->mbxStatus, |
| 8128 | mb->un.varRegVpi.upd); |
| 8129 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 8130 | mb->un.varRegVpi.upd) |
| 8131 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8132 | |
| 8133 | switch (mb->mbxStatus) { |
| 8134 | case 0x11: /* unsupported feature */ |
| 8135 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8136 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8137 | /* giving up on vport registration */ |
| 8138 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 8139 | spin_lock_irq(shost->host_lock); |
| 8140 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 8141 | spin_unlock_irq(shost->host_lock); |
| 8142 | lpfc_can_disctmo(vport); |
| 8143 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8144 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 8145 | case 0x20: |
| 8146 | spin_lock_irq(shost->host_lock); |
| 8147 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 8148 | spin_unlock_irq(shost->host_lock); |
| 8149 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 8150 | pmb->vport = vport; |
| 8151 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 8152 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 8153 | MBX_NOWAIT); |
| 8154 | if (rc == MBX_NOT_FINISHED) { |
| 8155 | lpfc_printf_vlog(vport, |
| 8156 | KERN_ERR, LOG_MBOX, |
| 8157 | "2732 Failed to issue INIT_VPI" |
| 8158 | " mailbox command\n"); |
| 8159 | } else { |
| 8160 | lpfc_nlp_put(ndlp); |
| 8161 | return; |
| 8162 | } |
| 8163 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8164 | default: |
| 8165 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8166 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8167 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8168 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8169 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8170 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8171 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8172 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 8173 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8174 | lpfc_issue_init_vfi(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8175 | else |
| 8176 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8177 | break; |
| 8178 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8179 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8180 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 8181 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8182 | spin_unlock_irq(shost->host_lock); |
| 8183 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8184 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 8185 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8186 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 8187 | /* |
| 8188 | * If the physical port is instantiated using |
| 8189 | * FDISC, do not start vport discovery. |
| 8190 | */ |
| 8191 | if (vport->port_state != LPFC_FDISC) |
| 8192 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8193 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8194 | } |
| 8195 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8196 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8197 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8198 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8199 | /* Now, we decrement the ndlp reference count held for this |
| 8200 | * callback function |
| 8201 | */ |
| 8202 | lpfc_nlp_put(ndlp); |
| 8203 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8204 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8205 | return; |
| 8206 | } |
| 8207 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8208 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8209 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8210 | * @phba: pointer to lpfc hba data structure. |
| 8211 | * @vport: pointer to a host virtual N_Port data structure. |
| 8212 | * @ndlp: pointer to a node-list data structure. |
| 8213 | * |
| 8214 | * This routine registers the @vport as a new virtual port with a HBA. |
| 8215 | * It is done through a registering vpi mailbox command. |
| 8216 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8217 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8218 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 8219 | struct lpfc_nodelist *ndlp) |
| 8220 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8221 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8222 | LPFC_MBOXQ_t *mbox; |
| 8223 | |
| 8224 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8225 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8226 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8227 | mbox->vport = vport; |
| 8228 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 8229 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8230 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8231 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8232 | /* mailbox command not success, decrement ndlp |
| 8233 | * reference count for this command |
| 8234 | */ |
| 8235 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8236 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8237 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8238 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 8239 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8240 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8241 | } |
| 8242 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8243 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 8244 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8245 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8246 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8247 | return; |
| 8248 | |
| 8249 | mbox_err_exit: |
| 8250 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 8251 | spin_lock_irq(shost->host_lock); |
| 8252 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 8253 | spin_unlock_irq(shost->host_lock); |
| 8254 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8255 | } |
| 8256 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8257 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8258 | * 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] | 8259 | * @phba: pointer to lpfc hba data structure. |
| 8260 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8261 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8262 | **/ |
| 8263 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8264 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8265 | { |
| 8266 | struct lpfc_vport **vports; |
| 8267 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8268 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8269 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8270 | |
| 8271 | /* Treat this failure as linkdown for all vports */ |
| 8272 | link_state = phba->link_state; |
| 8273 | lpfc_linkdown(phba); |
| 8274 | phba->link_state = link_state; |
| 8275 | |
| 8276 | vports = lpfc_create_vport_work_array(phba); |
| 8277 | |
| 8278 | if (vports) { |
| 8279 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 8280 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 8281 | if (ndlp) |
| 8282 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 8283 | lpfc_els_flush_cmd(vports[i]); |
| 8284 | } |
| 8285 | lpfc_destroy_vport_work_array(phba, vports); |
| 8286 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8287 | } |
| 8288 | |
| 8289 | /** |
| 8290 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 8291 | * @phba: pointer to lpfc hba data structure. |
| 8292 | * |
| 8293 | * This routine abort all pending discovery commands and |
| 8294 | * start a timer to retry FLOGI for the physical port |
| 8295 | * discovery. |
| 8296 | **/ |
| 8297 | void |
| 8298 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 8299 | { |
| 8300 | struct lpfc_nodelist *ndlp; |
| 8301 | struct Scsi_Host *shost; |
| 8302 | |
| 8303 | /* Cancel the all vports retry delay retry timers */ |
| 8304 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8305 | |
| 8306 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 8307 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 8308 | if (!ndlp) |
| 8309 | return; |
| 8310 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8311 | shost = lpfc_shost_from_vport(phba->pport); |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8312 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000)); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8313 | spin_lock_irq(shost->host_lock); |
| 8314 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 8315 | spin_unlock_irq(shost->host_lock); |
| 8316 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 8317 | phba->pport->port_state = LPFC_FLOGI; |
| 8318 | return; |
| 8319 | } |
| 8320 | |
| 8321 | /** |
| 8322 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 8323 | * @phba: pointer to lpfc hba data structure. |
| 8324 | * @cmdiocb: pointer to FDISC command iocb. |
| 8325 | * @rspiocb: pointer to FDISC response iocb. |
| 8326 | * |
| 8327 | * This routine checks if a FLOGI is reguired for FDISC |
| 8328 | * to succeed. |
| 8329 | **/ |
| 8330 | static int |
| 8331 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 8332 | struct lpfc_iocbq *cmdiocb, |
| 8333 | struct lpfc_iocbq *rspiocb) |
| 8334 | { |
| 8335 | |
| 8336 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 8337 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 8338 | return 0; |
| 8339 | else |
| 8340 | return 1; |
| 8341 | } |
| 8342 | |
| 8343 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8344 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8345 | * @phba: pointer to lpfc hba data structure. |
| 8346 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8347 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8348 | * |
| 8349 | * This routine is the completion callback function to a Fabric Discover |
| 8350 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 8351 | * single threaded, each FDISC completion callback function will reset |
| 8352 | * the discovery timer for all vports such that the timers will not get |
| 8353 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 8354 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 8355 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 8356 | * assigned to the vport has been changed with the completion of the FDISC |
| 8357 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 8358 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 8359 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 8360 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 8361 | * Server for State Change Request (SCR). |
| 8362 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8363 | static void |
| 8364 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8365 | struct lpfc_iocbq *rspiocb) |
| 8366 | { |
| 8367 | struct lpfc_vport *vport = cmdiocb->vport; |
| 8368 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8369 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 8370 | struct lpfc_nodelist *np; |
| 8371 | struct lpfc_nodelist *next_np; |
| 8372 | IOCB_t *irsp = &rspiocb->iocb; |
| 8373 | struct lpfc_iocbq *piocb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8374 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 8375 | struct serv_parm *sp; |
| 8376 | uint8_t fabric_param_changed; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8377 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8378 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8379 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 8380 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 8381 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8382 | /* Since all FDISCs are being single threaded, we |
| 8383 | * must reset the discovery timer for ALL vports |
| 8384 | * waiting to send FDISC when one completes. |
| 8385 | */ |
| 8386 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 8387 | lpfc_set_disctmo(piocb->vport); |
| 8388 | } |
| 8389 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8390 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8391 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 8392 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 8393 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8394 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8395 | |
| 8396 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 8397 | lpfc_retry_pport_discovery(phba); |
| 8398 | goto out; |
| 8399 | } |
| 8400 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8401 | /* Check for retry */ |
| 8402 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 8403 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8404 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8405 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8406 | "0126 FDISC failed. (x%x/x%x)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8407 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8408 | goto fdisc_failed; |
| 8409 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8410 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8411 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8412 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8413 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8414 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8415 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 8416 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8417 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8418 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 8419 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8420 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 8421 | if (!prsp) |
| 8422 | goto out; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8423 | sp = prsp->virt + sizeof(uint32_t); |
| 8424 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 8425 | memcpy(&vport->fabric_portname, &sp->portName, |
| 8426 | sizeof(struct lpfc_name)); |
| 8427 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 8428 | sizeof(struct lpfc_name)); |
| 8429 | if (fabric_param_changed && |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8430 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 8431 | /* If our NportID changed, we need to ensure all |
| 8432 | * remaining NPORTs get unreg_login'ed so we can |
| 8433 | * issue unreg_vpi. |
| 8434 | */ |
| 8435 | list_for_each_entry_safe(np, next_np, |
| 8436 | &vport->fc_nodes, nlp_listp) { |
| 8437 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 8438 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 8439 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 8440 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8441 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8442 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8443 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8444 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8445 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 8446 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8447 | |
| 8448 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8449 | lpfc_sli4_unreg_all_rpis(vport); |
| 8450 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8451 | lpfc_mbx_unreg_vpi(vport); |
| 8452 | spin_lock_irq(shost->host_lock); |
| 8453 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8454 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8455 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8456 | else |
| 8457 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8458 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8459 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 8460 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 8461 | /* |
| 8462 | * Driver needs to re-reg VPI in order for f/w |
| 8463 | * to update the MAC address. |
| 8464 | */ |
| 8465 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 8466 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8467 | } |
| 8468 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 8469 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 8470 | lpfc_issue_init_vpi(vport); |
| 8471 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8472 | lpfc_register_new_vport(phba, vport, ndlp); |
| 8473 | else |
| 8474 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8475 | goto out; |
| 8476 | fdisc_failed: |
James Smart | c84163d | 2015-05-21 13:55:22 -0400 | [diff] [blame] | 8477 | if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS) |
| 8478 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8479 | /* Cancel discovery timer */ |
| 8480 | lpfc_can_disctmo(vport); |
| 8481 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8482 | out: |
| 8483 | lpfc_els_free_iocb(phba, cmdiocb); |
| 8484 | } |
| 8485 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8486 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8487 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8488 | * @vport: pointer to a virtual N_Port data structure. |
| 8489 | * @ndlp: pointer to a node-list data structure. |
| 8490 | * @retry: number of retries to the command IOCB. |
| 8491 | * |
| 8492 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 8493 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 8494 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 8495 | * IOCB will be sent off HBA at any given time. |
| 8496 | * |
| 8497 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 8498 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 8499 | * will be stored into the context1 field of the IOCB for the completion |
| 8500 | * callback function to the FDISC ELS command. |
| 8501 | * |
| 8502 | * Return code |
| 8503 | * 0 - Successfully issued fdisc iocb command |
| 8504 | * 1 - Failed to issue fdisc iocb command |
| 8505 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8506 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8507 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 8508 | uint8_t retry) |
| 8509 | { |
| 8510 | struct lpfc_hba *phba = vport->phba; |
| 8511 | IOCB_t *icmd; |
| 8512 | struct lpfc_iocbq *elsiocb; |
| 8513 | struct serv_parm *sp; |
| 8514 | uint8_t *pcmd; |
| 8515 | uint16_t cmdsize; |
| 8516 | int did = ndlp->nlp_DID; |
| 8517 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8518 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8519 | vport->port_state = LPFC_FDISC; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8520 | vport->fc_myDID = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8521 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 8522 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 8523 | ELS_CMD_FDISC); |
| 8524 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8525 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8526 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8527 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8528 | return 1; |
| 8529 | } |
| 8530 | |
| 8531 | icmd = &elsiocb->iocb; |
| 8532 | icmd->un.elsreq64.myID = 0; |
| 8533 | icmd->un.elsreq64.fl = 1; |
| 8534 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 8535 | /* |
| 8536 | * SLI3 ports require a different context type value than SLI4. |
| 8537 | * Catch SLI3 ports here and override the prep. |
| 8538 | */ |
| 8539 | if (phba->sli_rev == LPFC_SLI_REV3) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8540 | icmd->ulpCt_h = 1; |
| 8541 | icmd->ulpCt_l = 0; |
| 8542 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8543 | |
| 8544 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 8545 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 8546 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 8547 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 8548 | sp = (struct serv_parm *) pcmd; |
| 8549 | /* Setup CSPs accordingly for Fabric */ |
| 8550 | sp->cmn.e_d_tov = 0; |
| 8551 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 8552 | sp->cmn.virtual_fabric_support = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8553 | sp->cls1.classValid = 0; |
| 8554 | sp->cls2.seqDelivery = 1; |
| 8555 | sp->cls3.seqDelivery = 1; |
| 8556 | |
| 8557 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 8558 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 8559 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 8560 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 8561 | memcpy(pcmd, &vport->fc_portname, 8); |
| 8562 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 8563 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 8564 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 8565 | |
| 8566 | lpfc_set_disctmo(vport); |
| 8567 | |
| 8568 | phba->fc_stat.elsXmitFDISC++; |
| 8569 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 8570 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8571 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8572 | "Issue FDISC: did:x%x", |
| 8573 | did, 0, 0); |
| 8574 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8575 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 8576 | if (rc == IOCB_ERROR) { |
| 8577 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8578 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8579 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8580 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8581 | return 1; |
| 8582 | } |
| 8583 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8584 | return 0; |
| 8585 | } |
| 8586 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8587 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8588 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8589 | * @phba: pointer to lpfc hba data structure. |
| 8590 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8591 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8592 | * |
| 8593 | * This routine is the completion callback function to the issuing of a LOGO |
| 8594 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 8595 | * reference count held on ndlp for this completion function, indicating that |
| 8596 | * the reference to the ndlp is no long needed. Note that the |
| 8597 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 8598 | * callback function and an additional explicit ndlp reference decrementation |
| 8599 | * will trigger the actual release of the ndlp. |
| 8600 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8601 | static void |
| 8602 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8603 | struct lpfc_iocbq *rspiocb) |
| 8604 | { |
| 8605 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8606 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8607 | struct lpfc_nodelist *ndlp; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8608 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8609 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8610 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8611 | irsp = &rspiocb->iocb; |
| 8612 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8613 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 8614 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8615 | |
| 8616 | lpfc_els_free_iocb(phba, cmdiocb); |
| 8617 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8618 | |
| 8619 | /* Trigger the release of the ndlp after logo */ |
| 8620 | lpfc_nlp_put(ndlp); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8621 | |
| 8622 | /* NPIV LOGO completes to NPort <nlp_DID> */ |
| 8623 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8624 | "2928 NPIV LOGO completes to NPort x%x " |
| 8625 | "Data: x%x x%x x%x x%x\n", |
| 8626 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 8627 | irsp->ulpTimeout, vport->num_disc_nodes); |
| 8628 | |
| 8629 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 8630 | spin_lock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 8631 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8632 | vport->fc_flag &= ~FC_FABRIC; |
| 8633 | spin_unlock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 8634 | lpfc_can_disctmo(vport); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8635 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8636 | } |
| 8637 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8638 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8639 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8640 | * @vport: pointer to a virtual N_Port data structure. |
| 8641 | * @ndlp: pointer to a node-list data structure. |
| 8642 | * |
| 8643 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 8644 | * |
| 8645 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 8646 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 8647 | * will be stored into the context1 field of the IOCB for the completion |
| 8648 | * callback function to the LOGO ELS command. |
| 8649 | * |
| 8650 | * Return codes |
| 8651 | * 0 - Successfully issued logo off the @vport |
| 8652 | * 1 - Failed to issue logo off the @vport |
| 8653 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8654 | int |
| 8655 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 8656 | { |
| 8657 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8658 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8659 | struct lpfc_iocbq *elsiocb; |
| 8660 | uint8_t *pcmd; |
| 8661 | uint16_t cmdsize; |
| 8662 | |
| 8663 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 8664 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 8665 | ELS_CMD_LOGO); |
| 8666 | if (!elsiocb) |
| 8667 | return 1; |
| 8668 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8669 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 8670 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 8671 | pcmd += sizeof(uint32_t); |
| 8672 | |
| 8673 | /* Fill in LOGO payload */ |
| 8674 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 8675 | pcmd += sizeof(uint32_t); |
| 8676 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 8677 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8678 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8679 | "Issue LOGO npiv did:x%x flg:x%x", |
| 8680 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 8681 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8682 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 8683 | spin_lock_irq(shost->host_lock); |
| 8684 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 8685 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8686 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 8687 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8688 | spin_lock_irq(shost->host_lock); |
| 8689 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 8690 | spin_unlock_irq(shost->host_lock); |
| 8691 | lpfc_els_free_iocb(phba, elsiocb); |
| 8692 | return 1; |
| 8693 | } |
| 8694 | return 0; |
| 8695 | } |
| 8696 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8697 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8698 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8699 | * @ptr: holder for the timer function associated data. |
| 8700 | * |
| 8701 | * This routine is invoked by the fabric iocb block timer after |
| 8702 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 8703 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 8704 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 8705 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 8706 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 8707 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8708 | void |
| 8709 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 8710 | { |
| 8711 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 8712 | unsigned long iflags; |
| 8713 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8714 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8715 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 8716 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 8717 | if (!tmo_posted) |
| 8718 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 8719 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 8720 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8721 | if (!tmo_posted) |
| 8722 | lpfc_worker_wake_up(phba); |
| 8723 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8724 | } |
| 8725 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8726 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8727 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8728 | * @phba: pointer to lpfc hba data structure. |
| 8729 | * |
| 8730 | * This routine issues one fabric iocb from the driver internal list to |
| 8731 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 8732 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 8733 | * remove one pending fabric iocb from the driver internal list and invokes |
| 8734 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 8735 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8736 | static void |
| 8737 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 8738 | { |
| 8739 | struct lpfc_iocbq *iocb; |
| 8740 | unsigned long iflags; |
| 8741 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8742 | IOCB_t *cmd; |
| 8743 | |
| 8744 | repeat: |
| 8745 | iocb = NULL; |
| 8746 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8747 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8748 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 8749 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 8750 | list); |
| 8751 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8752 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8753 | atomic_inc(&phba->fabric_iocb_count); |
| 8754 | } |
| 8755 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8756 | if (iocb) { |
| 8757 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 8758 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 8759 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 8760 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8761 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 8762 | "Fabric sched1: ste:x%x", |
| 8763 | iocb->vport->port_state, 0, 0); |
| 8764 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8765 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8766 | |
| 8767 | if (ret == IOCB_ERROR) { |
| 8768 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 8769 | iocb->fabric_iocb_cmpl = NULL; |
| 8770 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 8771 | cmd = &iocb->iocb; |
| 8772 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 8773 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 8774 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 8775 | |
| 8776 | atomic_dec(&phba->fabric_iocb_count); |
| 8777 | goto repeat; |
| 8778 | } |
| 8779 | } |
| 8780 | |
| 8781 | return; |
| 8782 | } |
| 8783 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8784 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8785 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8786 | * @phba: pointer to lpfc hba data structure. |
| 8787 | * |
| 8788 | * This routine unblocks the issuing fabric iocb command. The function |
| 8789 | * will clear the fabric iocb block bit and then invoke the routine |
| 8790 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 8791 | * from the driver internal fabric iocb list. |
| 8792 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8793 | void |
| 8794 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 8795 | { |
| 8796 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 8797 | |
| 8798 | lpfc_resume_fabric_iocbs(phba); |
| 8799 | return; |
| 8800 | } |
| 8801 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8802 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8803 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8804 | * @phba: pointer to lpfc hba data structure. |
| 8805 | * |
| 8806 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 8807 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 8808 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 8809 | * fabric iocb will be issued out of the HBA. |
| 8810 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8811 | static void |
| 8812 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 8813 | { |
| 8814 | int blocked; |
| 8815 | |
| 8816 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8817 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8818 | if (!blocked) |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8819 | mod_timer(&phba->fabric_block_timer, |
| 8820 | jiffies + msecs_to_jiffies(100)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8821 | |
| 8822 | return; |
| 8823 | } |
| 8824 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8825 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8826 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8827 | * @phba: pointer to lpfc hba data structure. |
| 8828 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8829 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8830 | * |
| 8831 | * This routine is the callback function that is put to the fabric iocb's |
| 8832 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 8833 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 8834 | * function first restores and invokes the original iocb's callback function |
| 8835 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 8836 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 8837 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8838 | static void |
| 8839 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8840 | struct lpfc_iocbq *rspiocb) |
| 8841 | { |
| 8842 | struct ls_rjt stat; |
| 8843 | |
| 8844 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 8845 | BUG(); |
| 8846 | |
| 8847 | switch (rspiocb->iocb.ulpStatus) { |
| 8848 | case IOSTAT_NPORT_RJT: |
| 8849 | case IOSTAT_FABRIC_RJT: |
| 8850 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 8851 | lpfc_block_fabric_iocbs(phba); |
| 8852 | } |
| 8853 | break; |
| 8854 | |
| 8855 | case IOSTAT_NPORT_BSY: |
| 8856 | case IOSTAT_FABRIC_BSY: |
| 8857 | lpfc_block_fabric_iocbs(phba); |
| 8858 | break; |
| 8859 | |
| 8860 | case IOSTAT_LS_RJT: |
| 8861 | stat.un.lsRjtError = |
| 8862 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 8863 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 8864 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 8865 | lpfc_block_fabric_iocbs(phba); |
| 8866 | break; |
| 8867 | } |
| 8868 | |
| 8869 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 8870 | BUG(); |
| 8871 | |
| 8872 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 8873 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 8874 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 8875 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 8876 | |
| 8877 | atomic_dec(&phba->fabric_iocb_count); |
| 8878 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8879 | /* Post any pending iocbs to HBA */ |
| 8880 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8881 | } |
| 8882 | } |
| 8883 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8884 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8885 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8886 | * @phba: pointer to lpfc hba data structure. |
| 8887 | * @iocb: pointer to lpfc command iocb data structure. |
| 8888 | * |
| 8889 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 8890 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 8891 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 8892 | * any given time. As such, this function will first check to see whether there |
| 8893 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 8894 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 8895 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 8896 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 8897 | * |
| 8898 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 8899 | * order. The problem is caused by the construction of the "ready" boolen does |
| 8900 | * not include the condition that the internal fabric IOCB list is empty. As |
| 8901 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 8902 | * ahead of the fabric IOCBs in the internal list. |
| 8903 | * |
| 8904 | * Return code |
| 8905 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 8906 | * IOCB_ERROR - failed to issue fabric iocb |
| 8907 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8908 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8909 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 8910 | { |
| 8911 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8912 | int ready; |
| 8913 | int ret; |
| 8914 | |
| 8915 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 8916 | BUG(); |
| 8917 | |
| 8918 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8919 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 8920 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 8921 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8922 | if (ready) |
| 8923 | /* Increment fabric iocb count to hold the position */ |
| 8924 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8925 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8926 | if (ready) { |
| 8927 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 8928 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 8929 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 8930 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8931 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 8932 | "Fabric sched2: ste:x%x", |
| 8933 | iocb->vport->port_state, 0, 0); |
| 8934 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8935 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8936 | |
| 8937 | if (ret == IOCB_ERROR) { |
| 8938 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 8939 | iocb->fabric_iocb_cmpl = NULL; |
| 8940 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 8941 | atomic_dec(&phba->fabric_iocb_count); |
| 8942 | } |
| 8943 | } else { |
| 8944 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8945 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 8946 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8947 | ret = IOCB_SUCCESS; |
| 8948 | } |
| 8949 | return ret; |
| 8950 | } |
| 8951 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8952 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8953 | * 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] | 8954 | * @vport: pointer to a virtual N_Port data structure. |
| 8955 | * |
| 8956 | * This routine aborts all the IOCBs associated with a @vport from the |
| 8957 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 8958 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 8959 | * list, removes each IOCB associated with the @vport off the list, set the |
| 8960 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 8961 | * associated with the IOCB. |
| 8962 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8963 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8964 | { |
| 8965 | LIST_HEAD(completions); |
| 8966 | struct lpfc_hba *phba = vport->phba; |
| 8967 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8968 | |
| 8969 | spin_lock_irq(&phba->hbalock); |
| 8970 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 8971 | list) { |
| 8972 | |
| 8973 | if (piocb->vport != vport) |
| 8974 | continue; |
| 8975 | |
| 8976 | list_move_tail(&piocb->list, &completions); |
| 8977 | } |
| 8978 | spin_unlock_irq(&phba->hbalock); |
| 8979 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8980 | /* Cancel all the IOCBs from the completions list */ |
| 8981 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8982 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8983 | } |
| 8984 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8985 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8986 | * 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] | 8987 | * @ndlp: pointer to a node-list data structure. |
| 8988 | * |
| 8989 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 8990 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 8991 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 8992 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 8993 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 8994 | * associated with the IOCB. |
| 8995 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8996 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 8997 | { |
| 8998 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8999 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9000 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 9001 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9002 | |
| 9003 | spin_lock_irq(&phba->hbalock); |
| 9004 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 9005 | list) { |
| 9006 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 9007 | |
| 9008 | list_move_tail(&piocb->list, &completions); |
| 9009 | } |
| 9010 | } |
| 9011 | spin_unlock_irq(&phba->hbalock); |
| 9012 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9013 | /* Cancel all the IOCBs from the completions list */ |
| 9014 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9015 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9016 | } |
| 9017 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9018 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9019 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9020 | * @phba: pointer to lpfc hba data structure. |
| 9021 | * |
| 9022 | * This routine aborts all the IOCBs currently on the driver internal |
| 9023 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 9024 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 9025 | * list, removes IOCBs off the list, set the status feild to |
| 9026 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 9027 | * the IOCB. |
| 9028 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9029 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 9030 | { |
| 9031 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9032 | |
| 9033 | spin_lock_irq(&phba->hbalock); |
| 9034 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 9035 | spin_unlock_irq(&phba->hbalock); |
| 9036 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9037 | /* Cancel all the IOCBs from the completions list */ |
| 9038 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9039 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9040 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9041 | |
| 9042 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 9043 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport |
| 9044 | * @vport: pointer to lpfc vport data structure. |
| 9045 | * |
| 9046 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 9047 | * for an ndlp on removal. |
| 9048 | **/ |
| 9049 | void |
| 9050 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) |
| 9051 | { |
| 9052 | struct lpfc_hba *phba = vport->phba; |
| 9053 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 9054 | unsigned long iflag = 0; |
| 9055 | |
| 9056 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 9057 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
| 9058 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 9059 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 9060 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) |
| 9061 | sglq_entry->ndlp = NULL; |
| 9062 | } |
| 9063 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 9064 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9065 | return; |
| 9066 | } |
| 9067 | |
| 9068 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9069 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 9070 | * @phba: pointer to lpfc hba data structure. |
| 9071 | * @axri: pointer to the els xri abort wcqe structure. |
| 9072 | * |
| 9073 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 9074 | * ELS aborted xri. |
| 9075 | **/ |
| 9076 | void |
| 9077 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 9078 | struct sli4_wcqe_xri_aborted *axri) |
| 9079 | { |
| 9080 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9081 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9082 | uint16_t lxri = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9083 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9084 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 9085 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9086 | struct lpfc_nodelist *ndlp; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 9087 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9088 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9089 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 9090 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9091 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 9092 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 9093 | if (sglq_entry->sli4_xritag == xri) { |
| 9094 | list_del(&sglq_entry->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9095 | ndlp = sglq_entry->ndlp; |
| 9096 | sglq_entry->ndlp = NULL; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 9097 | spin_lock(&pring->ring_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9098 | list_add_tail(&sglq_entry->list, |
| 9099 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9100 | sglq_entry->state = SGL_FREED; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 9101 | spin_unlock(&pring->ring_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9102 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9103 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 9104 | lpfc_set_rrq_active(phba, ndlp, |
| 9105 | sglq_entry->sli4_lxritag, |
| 9106 | rxid, 1); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 9107 | |
| 9108 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9109 | if (!(list_empty(&pring->txq))) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 9110 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9111 | return; |
| 9112 | } |
| 9113 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9114 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9115 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 9116 | if (lxri == NO_XRI) { |
| 9117 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9118 | return; |
| 9119 | } |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 9120 | spin_lock(&pring->ring_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9121 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9122 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 9123 | spin_unlock(&pring->ring_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9124 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9125 | return; |
| 9126 | } |
| 9127 | sglq_entry->state = SGL_XRI_ABORTED; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 9128 | spin_unlock(&pring->ring_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9129 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9130 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9131 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 9132 | |
| 9133 | /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. |
| 9134 | * @vport: pointer to virtual port object. |
| 9135 | * @ndlp: nodelist pointer for the impacted node. |
| 9136 | * |
| 9137 | * The driver calls this routine in response to an SLI4 XRI ABORT CQE |
| 9138 | * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, |
| 9139 | * the driver is required to send a LOGO to the remote node before it |
| 9140 | * attempts to recover its login to the remote node. |
| 9141 | */ |
| 9142 | void |
| 9143 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 9144 | struct lpfc_nodelist *ndlp) |
| 9145 | { |
| 9146 | struct Scsi_Host *shost; |
| 9147 | struct lpfc_hba *phba; |
| 9148 | unsigned long flags = 0; |
| 9149 | |
| 9150 | shost = lpfc_shost_from_vport(vport); |
| 9151 | phba = vport->phba; |
| 9152 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 9153 | lpfc_printf_log(phba, KERN_INFO, |
| 9154 | LOG_SLI, "3093 No rport recovery needed. " |
| 9155 | "rport in state 0x%x\n", ndlp->nlp_state); |
| 9156 | return; |
| 9157 | } |
| 9158 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9159 | "3094 Start rport recovery on shost id 0x%x " |
| 9160 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 9161 | "flags 0x%x\n", |
| 9162 | shost->host_no, ndlp->nlp_DID, |
| 9163 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 9164 | ndlp->nlp_flag); |
| 9165 | /* |
| 9166 | * The rport is not responding. Remove the FCP-2 flag to prevent |
| 9167 | * an ADISC in the follow-up recovery code. |
| 9168 | */ |
| 9169 | spin_lock_irqsave(shost->host_lock, flags); |
| 9170 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 9171 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 9172 | lpfc_issue_els_logo(vport, ndlp, 0); |
| 9173 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
| 9174 | } |
| 9175 | |