| 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 | f25e8e7 | 2015-04-07 15:07:28 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2015 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 */ |
| 693 | if (phba->cfg_fdmi_on == LPFC_FDMI_NO_SUPPORT) { |
| 694 | vport->fdmi_hba_mask = 0; |
| 695 | vport->fdmi_port_mask = 0; |
| 696 | } else { |
| 697 | /* Setup appropriate attribute masks */ |
| 698 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
| 699 | if (phba->cfg_fdmi_on == LPFC_FDMI_SMART_SAN) |
| 700 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 701 | else |
| 702 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 703 | } |
| 704 | |
| 705 | } |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 706 | memcpy(&vport->fabric_portname, &sp->portName, |
| 707 | sizeof(struct lpfc_name)); |
| 708 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 709 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 710 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 711 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 712 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 713 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 714 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 715 | LOG_ELS | LOG_VPORT, |
| 716 | "1816 FLOGI NPIV supported, " |
| 717 | "response data 0x%x\n", |
| 718 | sp->cmn.response_multiple_NPort); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 719 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 720 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 721 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 722 | } else { |
| 723 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 724 | to call reg_vnpid atleast for the physcial host */ |
| 725 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 726 | LOG_ELS | LOG_VPORT, |
| 727 | "1817 Fabric does not support NPIV " |
| 728 | "- configuring single port mode.\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 729 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 730 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 731 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 735 | /* |
| 736 | * For FC we need to do some special processing because of the SLI |
| 737 | * Port's default settings of the Common Service Parameters. |
| 738 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 739 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 740 | (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) { |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 741 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 742 | if (fabric_param_changed) |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 743 | lpfc_unregister_fcf_prep(phba); |
| 744 | |
| 745 | /* This should just update the VFI CSPs*/ |
| 746 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 747 | lpfc_issue_reg_vfi(vport); |
| 748 | } |
| 749 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 750 | if (fabric_param_changed && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 751 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 752 | |
| 753 | /* If our NportID changed, we need to ensure all |
| 754 | * remaining NPORTs get unreg_login'ed. |
| 755 | */ |
| 756 | list_for_each_entry_safe(np, next_np, |
| 757 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 758 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 759 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 760 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 761 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 762 | continue; |
| 763 | spin_lock_irq(shost->host_lock); |
| 764 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 765 | spin_unlock_irq(shost->host_lock); |
| 766 | lpfc_unreg_rpi(vport, np); |
| 767 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 768 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 769 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 770 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 771 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 772 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 773 | spin_lock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 774 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 775 | spin_unlock_irq(shost->host_lock); |
| 776 | } |
James Smart | 27aa1b7 | 2012-05-09 21:18:49 -0400 | [diff] [blame] | 777 | |
| 778 | /* |
| 779 | * For SLI3 and SLI4, the VPI needs to be reregistered in |
| 780 | * response to this fabric parameter change event. |
| 781 | */ |
| 782 | spin_lock_irq(shost->host_lock); |
| 783 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 784 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 785 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 786 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 787 | /* |
| 788 | * Driver needs to re-reg VPI in order for f/w |
| 789 | * to update the MAC address. |
| 790 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 791 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 792 | lpfc_register_new_vport(phba, vport, ndlp); |
| 793 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 794 | } |
| 795 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 796 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 797 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 798 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 799 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 800 | lpfc_register_new_vport(phba, vport, ndlp); |
| 801 | else |
| 802 | lpfc_issue_fabric_reglogin(vport); |
| 803 | } else { |
| 804 | ndlp->nlp_type |= NLP_FABRIC; |
| 805 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 806 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 807 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 808 | lpfc_start_fdiscs(phba); |
| 809 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 810 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 811 | lpfc_issue_init_vpi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 812 | else { |
| 813 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 814 | "3135 Need register VFI: (x%x/%x)\n", |
| 815 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 816 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 817 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 818 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 819 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 820 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 821 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 822 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 823 | * 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] | 824 | * @vport: pointer to a host virtual N_Port data structure. |
| 825 | * @ndlp: pointer to a node-list data structure. |
| 826 | * @sp: pointer to service parameter data structure. |
| 827 | * |
| 828 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 829 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 830 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 831 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 832 | * the received N_Port Name lexicographically, this node shall assign local |
| 833 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 834 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 835 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 836 | * N_Port IDs. |
| 837 | * |
| 838 | * Return code |
| 839 | * 0 - Success |
| 840 | * -ENXIO - Fail |
| 841 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 842 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 843 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 844 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 845 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 846 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 847 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 848 | LPFC_MBOXQ_t *mbox; |
| 849 | int rc; |
| 850 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 851 | spin_lock_irq(shost->host_lock); |
| 852 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 853 | vport->fc_flag |= FC_PT2PT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 854 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 855 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 856 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
| 857 | if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) { |
| 858 | lpfc_unregister_fcf_prep(phba); |
| 859 | |
| 860 | spin_lock_irq(shost->host_lock); |
| 861 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 862 | spin_unlock_irq(shost->host_lock); |
| 863 | phba->fc_topology_changed = 0; |
| 864 | } |
| 865 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 866 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 867 | sizeof(vport->fc_portname)); |
James Smart | 2eb6862 | 2012-09-29 11:32:27 -0400 | [diff] [blame] | 868 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 869 | if (rc >= 0) { |
| 870 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 871 | spin_lock_irq(shost->host_lock); |
| 872 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 873 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 874 | |
| 875 | /* |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 876 | * N_Port ID cannot be 0, set our Id to LocalID |
| 877 | * the other side will be RemoteID. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 878 | */ |
| 879 | |
| 880 | /* not equal */ |
| 881 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 882 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 883 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 884 | /* Decrement ndlp reference count indicating that ndlp can be |
| 885 | * safely released when other references to it are done. |
| 886 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 887 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 888 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 889 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 890 | if (!ndlp) { |
| 891 | /* |
| 892 | * Cannot find existing Fabric ndlp, so allocate a |
| 893 | * new one |
| 894 | */ |
| 895 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 896 | if (!ndlp) |
| 897 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 898 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 899 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 900 | ndlp = lpfc_enable_node(vport, ndlp, |
| 901 | NLP_STE_UNUSED_NODE); |
| 902 | if(!ndlp) |
| 903 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 907 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 908 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 909 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 910 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 911 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 912 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 913 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 914 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 915 | } else |
| 916 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 917 | * count indicating that ndlp can be released when other |
| 918 | * references to it are done. |
| 919 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 920 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 921 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 922 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 923 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 924 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 925 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 926 | if (!mbox) |
| 927 | goto fail; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 928 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 929 | lpfc_config_link(phba, mbox); |
| 930 | |
| 931 | mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
| 932 | mbox->vport = vport; |
| 933 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 934 | if (rc == MBX_NOT_FINISHED) { |
| 935 | mempool_free(mbox, phba->mbox_mem_pool); |
| 936 | goto fail; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 937 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 938 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 939 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 940 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 941 | return -ENXIO; |
| 942 | } |
| 943 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 944 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 945 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 946 | * @phba: pointer to lpfc hba data structure. |
| 947 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 948 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 949 | * |
| 950 | * This routine is the top-level completion callback function for issuing |
| 951 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 952 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 953 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 954 | * returning 1), the command IOCB will be released and function returned. |
| 955 | * If the retry attempt has been given up (possibly reach the maximum |
| 956 | * number of retries), one additional decrement of ndlp reference shall be |
| 957 | * invoked before going out after releasing the command IOCB. This will |
| 958 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 959 | * invoke one decrement of ndlp reference count). If no error reported in |
| 960 | * the IOCB status, the command Port ID field is used to determine whether |
| 961 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 962 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 963 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 964 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 965 | * specific topology completion conditions. |
| 966 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 967 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 968 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 969 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 970 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 971 | struct lpfc_vport *vport = cmdiocb->vport; |
| 972 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 973 | IOCB_t *irsp = &rspiocb->iocb; |
| 974 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 975 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 976 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 977 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 978 | int rc; |
| 979 | |
| 980 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 981 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 982 | /* One additional decrement on node reference count to |
| 983 | * trigger the release of the node |
| 984 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 985 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 986 | goto out; |
| 987 | } |
| 988 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 989 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 990 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 991 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 992 | vport->port_state); |
| 993 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 994 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 995 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 996 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 997 | * due to new FCF discovery |
| 998 | */ |
| 999 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1000 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 1001 | if (phba->link_state < LPFC_LINK_UP) |
| 1002 | goto stop_rr_fcf_flogi; |
| 1003 | if ((phba->fcoe_cvl_eventtag_attn == |
| 1004 | phba->fcoe_cvl_eventtag) && |
| 1005 | (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1006 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1007 | IOERR_SLI_ABORTED)) |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1008 | goto stop_rr_fcf_flogi; |
| 1009 | else |
| 1010 | phba->fcoe_cvl_eventtag_attn = |
| 1011 | phba->fcoe_cvl_eventtag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1012 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1013 | "2611 FLOGI failed on FCF (x%x), " |
| 1014 | "status:x%x/x%x, tmo:x%x, perform " |
| 1015 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1016 | phba->fcf.current_rec.fcf_indx, |
| 1017 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1018 | irsp->ulpTimeout); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1019 | lpfc_sli4_set_fcf_flogi_fail(phba, |
| 1020 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1021 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1022 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 1023 | if (rc) |
| 1024 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1025 | } |
| 1026 | |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1027 | stop_rr_fcf_flogi: |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1028 | /* FLOGI failure */ |
| 1029 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1030 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x " |
| 1031 | "Data x%x x%x\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1032 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1033 | irsp->ulpTimeout, phba->hba_flag, |
| 1034 | phba->fcf.fcf_flag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1035 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1036 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1037 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1038 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1039 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1040 | /* FLOGI failure */ |
| 1041 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1042 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 1043 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1044 | irsp->ulpTimeout); |
| 1045 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1046 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1047 | spin_lock_irq(shost->host_lock); |
| 1048 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 1049 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1050 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1051 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1052 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 1053 | * alpa map would take too long otherwise. |
| 1054 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1055 | if (phba->alpa_map[0] == 0) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1056 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1057 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1058 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1059 | (vport->fc_prevDID != vport->fc_myDID) || |
| 1060 | phba->fc_topology_changed)) { |
| 1061 | if (vport->fc_flag & FC_VFI_REGISTERED) { |
| 1062 | if (phba->fc_topology_changed) { |
| 1063 | lpfc_unregister_fcf_prep(phba); |
| 1064 | spin_lock_irq(shost->host_lock); |
| 1065 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 1066 | spin_unlock_irq(shost->host_lock); |
| 1067 | phba->fc_topology_changed = 0; |
| 1068 | } else { |
| 1069 | lpfc_sli4_unreg_all_rpis(vport); |
| 1070 | } |
| 1071 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1072 | lpfc_issue_reg_vfi(vport); |
| 1073 | lpfc_nlp_put(ndlp); |
| 1074 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1075 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1076 | goto flogifail; |
| 1077 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1078 | spin_lock_irq(shost->host_lock); |
| 1079 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 1080 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1081 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1082 | |
| 1083 | /* |
| 1084 | * The FLogI succeeded. Sync the data for the CPU before |
| 1085 | * accessing it. |
| 1086 | */ |
| 1087 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 1088 | if (!prsp) |
| 1089 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1090 | sp = prsp->virt + sizeof(uint32_t); |
| 1091 | |
| 1092 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1093 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 1094 | "0101 FLOGI completes successfully, I/O tag:x%x, " |
| 1095 | "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] | 1096 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1097 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution, |
| 1098 | vport->port_state, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1099 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1100 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1101 | /* |
| 1102 | * If Common Service Parameters indicate Nport |
| 1103 | * we are point to point, if Fport we are Fabric. |
| 1104 | */ |
| 1105 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1106 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1107 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1108 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1109 | else { |
| 1110 | lpfc_printf_vlog(vport, KERN_ERR, |
| 1111 | LOG_FIP | LOG_ELS, |
| 1112 | "2831 FLOGI response with cleared Fabric " |
| 1113 | "bit fcf_index 0x%x " |
| 1114 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 1115 | "Fabric Name " |
| 1116 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 1117 | phba->fcf.current_rec.fcf_indx, |
| 1118 | phba->fcf.current_rec.switch_name[0], |
| 1119 | phba->fcf.current_rec.switch_name[1], |
| 1120 | phba->fcf.current_rec.switch_name[2], |
| 1121 | phba->fcf.current_rec.switch_name[3], |
| 1122 | phba->fcf.current_rec.switch_name[4], |
| 1123 | phba->fcf.current_rec.switch_name[5], |
| 1124 | phba->fcf.current_rec.switch_name[6], |
| 1125 | phba->fcf.current_rec.switch_name[7], |
| 1126 | phba->fcf.current_rec.fabric_name[0], |
| 1127 | phba->fcf.current_rec.fabric_name[1], |
| 1128 | phba->fcf.current_rec.fabric_name[2], |
| 1129 | phba->fcf.current_rec.fabric_name[3], |
| 1130 | phba->fcf.current_rec.fabric_name[4], |
| 1131 | phba->fcf.current_rec.fabric_name[5], |
| 1132 | phba->fcf.current_rec.fabric_name[6], |
| 1133 | phba->fcf.current_rec.fabric_name[7]); |
| 1134 | lpfc_nlp_put(ndlp); |
| 1135 | spin_lock_irq(&phba->hbalock); |
| 1136 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1137 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1138 | spin_unlock_irq(&phba->hbalock); |
| 1139 | goto out; |
| 1140 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1141 | if (!rc) { |
| 1142 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1143 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 1144 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 1145 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1146 | "2769 FLOGI to FCF (x%x) " |
| 1147 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1148 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1149 | spin_lock_irq(&phba->hbalock); |
| 1150 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1151 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1152 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1153 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1154 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | flogifail: |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1158 | spin_lock_irq(&phba->hbalock); |
| 1159 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 1160 | spin_unlock_irq(&phba->hbalock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1161 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1162 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1163 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1164 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1165 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1166 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1167 | |
| 1168 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1169 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1170 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1171 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1172 | IOERR_SLI_ABORTED) && |
| 1173 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1174 | IOERR_SLI_DOWN))) && |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1175 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 1176 | /* If FLOGI failed enable link interrupt. */ |
| 1177 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1178 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1179 | out: |
| 1180 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1181 | } |
| 1182 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1183 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1184 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1185 | * @vport: pointer to a host virtual N_Port data structure. |
| 1186 | * @ndlp: pointer to a node-list data structure. |
| 1187 | * @retry: number of retries to the command IOCB. |
| 1188 | * |
| 1189 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 1190 | * for a @vport. The initiator service parameters are put into the payload |
| 1191 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 1192 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 1193 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 1194 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 1195 | * |
| 1196 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1197 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1198 | * will be stored into the context1 field of the IOCB for the completion |
| 1199 | * callback function to the FLOGI ELS command. |
| 1200 | * |
| 1201 | * Return code |
| 1202 | * 0 - successfully issued flogi iocb for @vport |
| 1203 | * 1 - failed to issue flogi iocb for @vport |
| 1204 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1205 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1206 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1207 | uint8_t retry) |
| 1208 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1209 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1210 | struct serv_parm *sp; |
| 1211 | IOCB_t *icmd; |
| 1212 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1213 | uint8_t *pcmd; |
| 1214 | uint16_t cmdsize; |
| 1215 | uint32_t tmo; |
| 1216 | int rc; |
| 1217 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1218 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1219 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1220 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1221 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1222 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1223 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1224 | |
| 1225 | icmd = &elsiocb->iocb; |
| 1226 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1227 | |
| 1228 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1229 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1230 | pcmd += sizeof(uint32_t); |
| 1231 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | sp = (struct serv_parm *) pcmd; |
| 1233 | |
| 1234 | /* Setup CSPs accordingly for Fabric */ |
| 1235 | sp->cmn.e_d_tov = 0; |
| 1236 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 1237 | sp->cmn.virtual_fabric_support = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1238 | sp->cls1.classValid = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1239 | if (sp->cmn.fcphLow < FC_PH3) |
| 1240 | sp->cmn.fcphLow = FC_PH3; |
| 1241 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1242 | sp->cmn.fcphHigh = FC_PH3; |
| 1243 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 1244 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1245 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1246 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 1247 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1248 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1249 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1250 | /* Set the fcfi to the fcfi we registered with */ |
| 1251 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1252 | } |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1253 | /* Can't do SLI4 class2 without support sequence coalescing */ |
| 1254 | sp->cls2.classValid = 0; |
| 1255 | sp->cls2.seqDelivery = 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1256 | } else { |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1257 | /* Historical, setting sequential-delivery bit for SLI3 */ |
| 1258 | sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; |
| 1259 | sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1260 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 1261 | sp->cmn.request_multiple_Nport = 1; |
| 1262 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1263 | icmd->ulpCt_h = 1; |
| 1264 | icmd->ulpCt_l = 0; |
| 1265 | } else |
| 1266 | sp->cmn.request_multiple_Nport = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1267 | } |
| 1268 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1269 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1270 | icmd->un.elsreq64.myID = 0; |
| 1271 | icmd->un.elsreq64.fl = 1; |
| 1272 | } |
| 1273 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1274 | tmo = phba->fc_ratov; |
| 1275 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1276 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1277 | phba->fc_ratov = tmo; |
| 1278 | |
| 1279 | phba->fc_stat.elsXmitFLOGI++; |
| 1280 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1281 | |
| 1282 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1283 | "Issue FLOGI: opt:x%x", |
| 1284 | phba->sli3_options, 0, 0); |
| 1285 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1286 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1287 | if (rc == IOCB_ERROR) { |
| 1288 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1289 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1290 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1291 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1292 | } |
| 1293 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1294 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1295 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1296 | * @phba: pointer to lpfc hba data structure. |
| 1297 | * |
| 1298 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1299 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1300 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1301 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1302 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1303 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1304 | * |
| 1305 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1306 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1307 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1308 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1309 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1310 | { |
| 1311 | struct lpfc_sli_ring *pring; |
| 1312 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1313 | struct lpfc_nodelist *ndlp; |
| 1314 | IOCB_t *icmd; |
| 1315 | |
| 1316 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1317 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1318 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1319 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1320 | |
| 1321 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1322 | |
| 1323 | /* |
| 1324 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1325 | * searching for. |
| 1326 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1327 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1328 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1329 | icmd = &iocb->iocb; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1330 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1331 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1332 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1333 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1334 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | } |
| 1336 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1337 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1338 | |
| 1339 | return 0; |
| 1340 | } |
| 1341 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1342 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1343 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1344 | * @vport: pointer to a host virtual N_Port data structure. |
| 1345 | * |
| 1346 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1347 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1348 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1349 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1350 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1351 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1352 | * @vport. |
| 1353 | * |
| 1354 | * Return code |
| 1355 | * 0 - failed to issue initial flogi for @vport |
| 1356 | * 1 - successfully issued initial flogi for @vport |
| 1357 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1358 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1359 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1360 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1361 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1362 | struct lpfc_nodelist *ndlp; |
| 1363 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1364 | vport->port_state = LPFC_FLOGI; |
| 1365 | lpfc_set_disctmo(vport); |
| 1366 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1367 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1368 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1369 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1370 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1371 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1372 | if (!ndlp) |
| 1373 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1374 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1375 | /* Set the node type */ |
| 1376 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1377 | /* Put ndlp onto node list */ |
| 1378 | lpfc_enqueue_node(vport, ndlp); |
| 1379 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1380 | /* re-setup ndlp without removing from node list */ |
| 1381 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1382 | if (!ndlp) |
| 1383 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1384 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1385 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1386 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1387 | /* This decrement of reference count to node shall kick off |
| 1388 | * the release of the node. |
| 1389 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1390 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1391 | return 0; |
| 1392 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1393 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1394 | } |
| 1395 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1396 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1397 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1398 | * @vport: pointer to a host virtual N_Port data structure. |
| 1399 | * |
| 1400 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1401 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1402 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1403 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1404 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1405 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1406 | * @vport. |
| 1407 | * |
| 1408 | * Return code |
| 1409 | * 0 - failed to issue initial fdisc for @vport |
| 1410 | * 1 - successfully issued initial fdisc for @vport |
| 1411 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1412 | int |
| 1413 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1414 | { |
| 1415 | struct lpfc_hba *phba = vport->phba; |
| 1416 | struct lpfc_nodelist *ndlp; |
| 1417 | |
| 1418 | /* First look for the Fabric ndlp */ |
| 1419 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1420 | if (!ndlp) { |
| 1421 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1422 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1423 | if (!ndlp) |
| 1424 | return 0; |
| 1425 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1426 | /* Put ndlp onto node list */ |
| 1427 | lpfc_enqueue_node(vport, ndlp); |
| 1428 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1429 | /* re-setup ndlp without removing from node list */ |
| 1430 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1431 | if (!ndlp) |
| 1432 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1433 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1434 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1435 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1436 | /* decrement node reference count to trigger the release of |
| 1437 | * the node. |
| 1438 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1439 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1440 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1441 | } |
| 1442 | return 1; |
| 1443 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1444 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1445 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1446 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1447 | * @vport: pointer to a host virtual N_Port data structure. |
| 1448 | * |
| 1449 | * This routine checks whether there are more remaining Port Logins |
| 1450 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1451 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1452 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1453 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1454 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1455 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1456 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1457 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1458 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1459 | if (vport->num_disc_nodes) |
| 1460 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | |
| 1462 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1463 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1464 | "0232 Continue discovery with %d PLOGIs to go " |
| 1465 | "Data: x%x x%x x%x\n", |
| 1466 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1467 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1468 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1469 | if (vport->fc_flag & FC_NLP_MORE) |
| 1470 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 1471 | lpfc_els_disc_plogi(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1472 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1473 | return; |
| 1474 | } |
| 1475 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1476 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1477 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1478 | * @phba: pointer to lpfc hba data structure. |
| 1479 | * @prsp: pointer to response IOCB payload. |
| 1480 | * @ndlp: pointer to a node-list data structure. |
| 1481 | * |
| 1482 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1483 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1484 | * The following cases are considered N_Port confirmed: |
| 1485 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1486 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1487 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1488 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1489 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1490 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1491 | * on that node to release the RPI associated with the node; 2) if there is |
| 1492 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1493 | * into, a new node shall be allocated (or activated). In either case, the |
| 1494 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1495 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1496 | * its pointer returned as the confirmed node. |
| 1497 | * |
| 1498 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1499 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1500 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1501 | * into an inactive state on the vport node list and the vport node list |
| 1502 | * management algorithm does not allow two node with a same DID. |
| 1503 | * |
| 1504 | * Return code |
| 1505 | * pointer to the PLOGI N_Port @ndlp |
| 1506 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1507 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1508 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1509 | struct lpfc_nodelist *ndlp) |
| 1510 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1511 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1512 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1513 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1514 | struct lpfc_rport_data *rdata; |
| 1515 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1516 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1517 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1518 | uint32_t rc, keepDID = 0, keep_nlp_flag = 0; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1519 | uint16_t keep_nlp_state; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1520 | int put_node; |
| 1521 | int put_rport; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1522 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1523 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1524 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1525 | * by WWPN. Just return the ndlp that was given to us. |
| 1526 | */ |
| 1527 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1528 | return ndlp; |
| 1529 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1530 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1531 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1532 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1533 | /* 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] | 1534 | * we have for that ndlp. If not, we have some work to do. |
| 1535 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1536 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1537 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1538 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1539 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1540 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1541 | active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool, |
| 1542 | GFP_KERNEL); |
| 1543 | if (active_rrqs_xri_bitmap) |
| 1544 | memset(active_rrqs_xri_bitmap, 0, |
| 1545 | phba->cfg_rrq_xri_bitmap_sz); |
| 1546 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1547 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1548 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1549 | "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n", |
| 1550 | ndlp, ndlp->nlp_DID, new_ndlp); |
| 1551 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1552 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1553 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1554 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1555 | if (!rc) { |
| 1556 | if (active_rrqs_xri_bitmap) |
| 1557 | mempool_free(active_rrqs_xri_bitmap, |
| 1558 | phba->active_rrq_pool); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1559 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1560 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1561 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1562 | if (!new_ndlp) { |
| 1563 | if (active_rrqs_xri_bitmap) |
| 1564 | mempool_free(active_rrqs_xri_bitmap, |
| 1565 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1566 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1567 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1568 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1569 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1570 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1571 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1572 | if (!rc) { |
| 1573 | if (active_rrqs_xri_bitmap) |
| 1574 | mempool_free(active_rrqs_xri_bitmap, |
| 1575 | phba->active_rrq_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1576 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1577 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1578 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1579 | NLP_STE_UNUSED_NODE); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1580 | if (!new_ndlp) { |
| 1581 | if (active_rrqs_xri_bitmap) |
| 1582 | mempool_free(active_rrqs_xri_bitmap, |
| 1583 | phba->active_rrq_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1584 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1585 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1586 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1587 | if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap) |
| 1588 | memcpy(active_rrqs_xri_bitmap, |
| 1589 | new_ndlp->active_rrqs_xri_bitmap, |
| 1590 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1591 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1592 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1593 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1594 | active_rrqs_xri_bitmap) |
| 1595 | memcpy(active_rrqs_xri_bitmap, |
| 1596 | new_ndlp->active_rrqs_xri_bitmap, |
| 1597 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1598 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1599 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1600 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1601 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1602 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1603 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1604 | memcpy(new_ndlp->active_rrqs_xri_bitmap, |
| 1605 | ndlp->active_rrqs_xri_bitmap, |
| 1606 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1607 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1608 | spin_lock_irq(shost->host_lock); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1609 | keep_nlp_flag = new_ndlp->nlp_flag; |
| 1610 | new_ndlp->nlp_flag = ndlp->nlp_flag; |
| 1611 | ndlp->nlp_flag = keep_nlp_flag; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1612 | spin_unlock_irq(shost->host_lock); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1613 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1614 | /* Set nlp_states accordingly */ |
| 1615 | keep_nlp_state = new_ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1616 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1617 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1618 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1619 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1620 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1621 | * to put ndlp on UNUSED list and try to free it. |
| 1622 | */ |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1623 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1624 | "3179 PLOGI confirm NEW: %x %x\n", |
| 1625 | new_ndlp->nlp_DID, keepDID); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1626 | |
| 1627 | /* Fix up the rport accordingly */ |
| 1628 | rport = ndlp->rport; |
| 1629 | if (rport) { |
| 1630 | rdata = rport->dd_data; |
| 1631 | if (rdata->pnode == ndlp) { |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1632 | /* break the link before dropping the ref */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1633 | ndlp->rport = NULL; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1634 | lpfc_nlp_put(ndlp); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1635 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1636 | new_ndlp->rport = rport; |
| 1637 | } |
| 1638 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1639 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1640 | /* We shall actually free the ndlp with both nlp_DID and |
| 1641 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1642 | * nodelist never to be used. |
| 1643 | */ |
| 1644 | if (ndlp->nlp_DID == 0) { |
| 1645 | spin_lock_irq(&phba->ndlp_lock); |
| 1646 | NLP_SET_FREE_REQ(ndlp); |
| 1647 | spin_unlock_irq(&phba->ndlp_lock); |
| 1648 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1649 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1650 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1651 | ndlp->nlp_DID = keepDID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1652 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1653 | active_rrqs_xri_bitmap) |
| 1654 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1655 | active_rrqs_xri_bitmap, |
| 1656 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1657 | |
| 1658 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 1659 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1660 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1661 | else { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1662 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1663 | "3180 PLOGI confirm SWAP: %x %x\n", |
| 1664 | new_ndlp->nlp_DID, keepDID); |
| 1665 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1666 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1667 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1668 | /* Two ndlps cannot have the same did */ |
| 1669 | ndlp->nlp_DID = keepDID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1670 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1671 | active_rrqs_xri_bitmap) |
| 1672 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1673 | active_rrqs_xri_bitmap, |
| 1674 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1675 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1676 | /* Since we are switching over to the new_ndlp, |
| 1677 | * reset the old ndlp state |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1678 | */ |
| 1679 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 1680 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1681 | keep_nlp_state = NLP_STE_NPR_NODE; |
| 1682 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1683 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1684 | /* Fix up the rport accordingly */ |
| 1685 | rport = ndlp->rport; |
| 1686 | if (rport) { |
| 1687 | rdata = rport->dd_data; |
| 1688 | put_node = rdata->pnode != NULL; |
| 1689 | put_rport = ndlp->rport != NULL; |
| 1690 | rdata->pnode = NULL; |
| 1691 | ndlp->rport = NULL; |
| 1692 | if (put_node) |
| 1693 | lpfc_nlp_put(ndlp); |
| 1694 | if (put_rport) |
| 1695 | put_device(&rport->dev); |
| 1696 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1697 | } |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1698 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1699 | active_rrqs_xri_bitmap) |
| 1700 | mempool_free(active_rrqs_xri_bitmap, |
| 1701 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1702 | return new_ndlp; |
| 1703 | } |
| 1704 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1705 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1706 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1707 | * @vport: pointer to a host virtual N_Port data structure. |
| 1708 | * |
| 1709 | * This routine checks whether more Registration State Change |
| 1710 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1711 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1712 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1713 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1714 | * handling the RSCNs. |
| 1715 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1716 | void |
| 1717 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1718 | { |
| 1719 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1720 | |
| 1721 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1722 | /* |
| 1723 | * Check to see if more RSCNs came in while we were |
| 1724 | * processing this one. |
| 1725 | */ |
| 1726 | if (vport->fc_rscn_id_cnt || |
| 1727 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1728 | lpfc_els_handle_rscn(vport); |
| 1729 | else { |
| 1730 | spin_lock_irq(shost->host_lock); |
| 1731 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1732 | spin_unlock_irq(shost->host_lock); |
| 1733 | } |
| 1734 | } |
| 1735 | } |
| 1736 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1737 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1738 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. |
| 1739 | * @phba: pointer to lpfc hba data structure. |
| 1740 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1741 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1742 | * |
| 1743 | * This routine will call the clear rrq function to free the rrq and |
| 1744 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not |
| 1745 | * exist then the clear_rrq is still called because the rrq needs to |
| 1746 | * be freed. |
| 1747 | **/ |
| 1748 | |
| 1749 | static void |
| 1750 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1751 | struct lpfc_iocbq *rspiocb) |
| 1752 | { |
| 1753 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1754 | IOCB_t *irsp; |
| 1755 | struct lpfc_nodelist *ndlp; |
| 1756 | struct lpfc_node_rrq *rrq; |
| 1757 | |
| 1758 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1759 | rrq = cmdiocb->context_un.rrq; |
| 1760 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1761 | |
| 1762 | irsp = &rspiocb->iocb; |
| 1763 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1764 | "RRQ cmpl: status:x%x/x%x did:x%x", |
| 1765 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1766 | irsp->un.elsreq64.remoteID); |
| 1767 | |
| 1768 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
| 1769 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { |
| 1770 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1771 | "2882 RRQ completes to NPort x%x " |
| 1772 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1773 | irsp->un.elsreq64.remoteID, |
| 1774 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1775 | irsp->ulpIoTag); |
| 1776 | goto out; |
| 1777 | } |
| 1778 | |
| 1779 | /* rrq completes to NPort <nlp_DID> */ |
| 1780 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1781 | "2880 RRQ completes to NPort x%x " |
| 1782 | "Data: x%x x%x x%x x%x x%x\n", |
| 1783 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1784 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); |
| 1785 | |
| 1786 | if (irsp->ulpStatus) { |
| 1787 | /* Check for retry */ |
| 1788 | /* RRQ failed Don't print the vport to vport rjts */ |
| 1789 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1790 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1791 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1792 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1793 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1794 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", |
| 1795 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1796 | irsp->un.ulpWord[4]); |
| 1797 | } |
| 1798 | out: |
| 1799 | if (rrq) |
| 1800 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1801 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1802 | return; |
| 1803 | } |
| 1804 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1805 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1806 | * @phba: pointer to lpfc hba data structure. |
| 1807 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1808 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1809 | * |
| 1810 | * This routine is the completion callback function for issuing the Port |
| 1811 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1812 | * 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] | 1813 | * 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] | 1814 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1815 | * checked for error conditons. If there is error status reported, PLOGI |
| 1816 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1817 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1818 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1819 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1820 | * there are additional N_Port nodes with the vport that need to perform |
| 1821 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1822 | * PLOGIs. |
| 1823 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1824 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1825 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1826 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1827 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1828 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1829 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1830 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1831 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1832 | struct lpfc_dmabuf *prsp; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 1833 | int disc, rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1834 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1835 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1836 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1837 | |
| 1838 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1839 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1840 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1841 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1842 | irsp->un.elsreq64.remoteID); |
| 1843 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1844 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1845 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1846 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1847 | "0136 PLOGI completes to NPort x%x " |
| 1848 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1849 | irsp->un.elsreq64.remoteID, |
| 1850 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1851 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1852 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1853 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1854 | |
| 1855 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1856 | * is being used during discovery. |
| 1857 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1858 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1859 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1860 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1861 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1862 | rc = 0; |
| 1863 | |
| 1864 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1865 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1866 | "0102 PLOGI completes to NPort x%x " |
| 1867 | "Data: x%x x%x x%x x%x x%x\n", |
| 1868 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1869 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1870 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1871 | if (lpfc_els_chk_latt(vport)) { |
| 1872 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1873 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1874 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1875 | goto out; |
| 1876 | } |
| 1877 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1878 | if (irsp->ulpStatus) { |
| 1879 | /* Check for retry */ |
| 1880 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1881 | /* ELS command is being retried */ |
| 1882 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1883 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1884 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1885 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1886 | } |
| 1887 | goto out; |
| 1888 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1889 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1890 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1891 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1892 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1893 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1894 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1895 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1896 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1897 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1898 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1899 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1900 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1901 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1902 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1903 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1904 | } else { |
| 1905 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1906 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1907 | cmdiocb->context2)->list.next, |
| 1908 | struct lpfc_dmabuf, list); |
| 1909 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1910 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1911 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1912 | } |
| 1913 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1914 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1915 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1916 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1917 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1918 | if (vport->num_disc_nodes == 0) { |
| 1919 | spin_lock_irq(shost->host_lock); |
| 1920 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1921 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1922 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1923 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1924 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | out: |
| 1929 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1930 | return; |
| 1931 | } |
| 1932 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1933 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1934 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1935 | * @vport: pointer to a host virtual N_Port data structure. |
| 1936 | * @did: destination port identifier. |
| 1937 | * @retry: number of retries to the command IOCB. |
| 1938 | * |
| 1939 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1940 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1941 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1942 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1943 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1944 | * |
| 1945 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1946 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1947 | * will be stored into the context1 field of the IOCB for the completion |
| 1948 | * callback function to the PLOGI ELS command. |
| 1949 | * |
| 1950 | * Return code |
| 1951 | * 0 - Successfully issued a plogi for @vport |
| 1952 | * 1 - failed to issue a plogi for @vport |
| 1953 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1954 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1955 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1956 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1957 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1958 | struct serv_parm *sp; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1959 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1961 | uint8_t *pcmd; |
| 1962 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1963 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1964 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1965 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1966 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1967 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1968 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1969 | /* 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] | 1970 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1971 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1972 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1973 | if (!elsiocb) |
| 1974 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1975 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1976 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1977 | |
| 1978 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1979 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1980 | pcmd += sizeof(uint32_t); |
| 1981 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1982 | sp = (struct serv_parm *) pcmd; |
| 1983 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1984 | /* |
| 1985 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 1986 | * to device on remote loops work. |
| 1987 | */ |
| 1988 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 1989 | sp->cmn.altBbCredit = 1; |
| 1990 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1991 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1992 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1993 | |
| 1994 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1995 | sp->cmn.fcphHigh = FC_PH3; |
| 1996 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1997 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1998 | "Issue PLOGI: did:x%x", |
| 1999 | did, 0, 0); |
| 2000 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2001 | phba->fc_stat.elsXmitPLOGI++; |
| 2002 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2003 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2004 | |
| 2005 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2007 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2008 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2009 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2010 | } |
| 2011 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2012 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2013 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2014 | * @phba: pointer to lpfc hba data structure. |
| 2015 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2016 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2017 | * |
| 2018 | * This routine is the completion callback function for a Process Login |
| 2019 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 2020 | * status. If there is error status reported, PRLI retry shall be attempted |
| 2021 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 2022 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 2023 | * ndlp to mark the PRLI completion. |
| 2024 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2025 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2026 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2027 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2028 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2029 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2030 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2031 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2032 | struct lpfc_nodelist *ndlp; |
| 2033 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2034 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2035 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2036 | |
| 2037 | irsp = &(rspiocb->iocb); |
| 2038 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2039 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2040 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2041 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2042 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2043 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2044 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 2045 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2046 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2048 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2049 | "0103 PRLI completes to NPort x%x " |
| 2050 | "Data: x%x x%x x%x x%x\n", |
| 2051 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2052 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2053 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2054 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2055 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2056 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2057 | goto out; |
| 2058 | |
| 2059 | if (irsp->ulpStatus) { |
| 2060 | /* Check for retry */ |
| 2061 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2062 | /* ELS command is being retried */ |
| 2063 | goto out; |
| 2064 | } |
| 2065 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2066 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2067 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 2068 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2069 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2070 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2071 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2072 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2073 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2074 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2075 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2076 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2077 | /* Good status, call state machine */ |
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); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2080 | out: |
| 2081 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2082 | return; |
| 2083 | } |
| 2084 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2085 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2086 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2087 | * @vport: pointer to a host virtual N_Port data structure. |
| 2088 | * @ndlp: pointer to a node-list data structure. |
| 2089 | * @retry: number of retries to the command IOCB. |
| 2090 | * |
| 2091 | * This routine issues a Process Login (PRLI) ELS command for the |
| 2092 | * @vport. The PRLI service parameters are set up in the payload of the |
| 2093 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 2094 | * is put to the IOCB completion callback func field before invoking the |
| 2095 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 2096 | * |
| 2097 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2098 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2099 | * will be stored into the context1 field of the IOCB for the completion |
| 2100 | * callback function to the PRLI ELS command. |
| 2101 | * |
| 2102 | * Return code |
| 2103 | * 0 - successfully issued prli iocb command for @vport |
| 2104 | * 1 - failed to issue prli iocb command for @vport |
| 2105 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2107 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | uint8_t retry) |
| 2109 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2110 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2111 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2112 | PRLI *npr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2113 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2114 | uint8_t *pcmd; |
| 2115 | uint16_t cmdsize; |
| 2116 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2117 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2118 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2119 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2120 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2121 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2123 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2124 | |
| 2125 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2126 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2127 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2128 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2129 | |
| 2130 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 2131 | npr = (PRLI *) pcmd; |
| 2132 | /* |
| 2133 | * If our firmware version is 3.20 or later, |
| 2134 | * set the following bits for FC-TAPE support. |
| 2135 | */ |
| 2136 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 2137 | npr->ConfmComplAllowed = 1; |
| 2138 | npr->Retry = 1; |
| 2139 | npr->TaskRetryIdReq = 1; |
| 2140 | } |
| 2141 | npr->estabImagePair = 1; |
| 2142 | npr->readXferRdyDis = 1; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 2143 | if (vport->cfg_first_burst_size) |
| 2144 | npr->writeXferRdyDis = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2145 | |
| 2146 | /* For FCP support */ |
| 2147 | npr->prliType = PRLI_FCP_TYPE; |
| 2148 | npr->initiatorFunc = 1; |
| 2149 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2150 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2151 | "Issue PRLI: did:x%x", |
| 2152 | ndlp->nlp_DID, 0, 0); |
| 2153 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2154 | phba->fc_stat.elsXmitPRLI++; |
| 2155 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2156 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2157 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2158 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2159 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2160 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2161 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2163 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2164 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2165 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2167 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2168 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | } |
| 2170 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2171 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2172 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2173 | * @vport: pointer to a host virtual N_Port data structure. |
| 2174 | * |
| 2175 | * This routine performs Registration State Change Notification (RSCN) |
| 2176 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 2177 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 2178 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 2179 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 2180 | * invoked to check and handle possible more RSCN came in during the period |
| 2181 | * of processing the current ones. |
| 2182 | **/ |
| 2183 | static void |
| 2184 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 2185 | { |
| 2186 | lpfc_can_disctmo(vport); |
| 2187 | |
| 2188 | /* RSCN discovery */ |
| 2189 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 2190 | if (vport->fc_npr_cnt) |
| 2191 | if (lpfc_els_disc_plogi(vport)) |
| 2192 | return; |
| 2193 | |
| 2194 | lpfc_end_rscn(vport); |
| 2195 | } |
| 2196 | |
| 2197 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2198 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2199 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 2200 | * |
| 2201 | * This function is called when the final ADISC is completed during discovery. |
| 2202 | * This function handles clearing link attention or issuing reg_vpi depending |
| 2203 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 2204 | * discovery. |
| 2205 | * This function is called with no locks held. |
| 2206 | **/ |
| 2207 | static void |
| 2208 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 2209 | { |
| 2210 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2211 | struct lpfc_hba *phba = vport->phba; |
| 2212 | |
| 2213 | /* |
| 2214 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 2215 | * and continue discovery. |
| 2216 | */ |
| 2217 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2218 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 2219 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | d454c91 | 2014-12-30 12:08:58 -0500 | [diff] [blame] | 2220 | /* The ADISCs are complete. Doesn't matter if they |
| 2221 | * succeeded or failed because the ADISC completion |
| 2222 | * routine guarantees to call the state machine and |
| 2223 | * the RPI is either unregistered (failed ADISC response) |
| 2224 | * or the RPI is still valid and the node is marked |
| 2225 | * mapped for a target. The exchanges should be in the |
| 2226 | * correct state. This code is specific to SLI3. |
| 2227 | */ |
| 2228 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2229 | lpfc_issue_reg_vpi(phba, vport); |
| 2230 | return; |
| 2231 | } |
| 2232 | /* |
| 2233 | * For SLI2, we need to set port_state to READY |
| 2234 | * and continue discovery. |
| 2235 | */ |
| 2236 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2237 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 2238 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2239 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 2240 | vport->num_disc_nodes = 0; |
| 2241 | /* go thru NPR list, issue ELS PLOGIs */ |
| 2242 | if (vport->fc_npr_cnt) |
| 2243 | lpfc_els_disc_plogi(vport); |
| 2244 | if (!vport->num_disc_nodes) { |
| 2245 | spin_lock_irq(shost->host_lock); |
| 2246 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2247 | spin_unlock_irq(shost->host_lock); |
| 2248 | lpfc_can_disctmo(vport); |
| 2249 | lpfc_end_rscn(vport); |
| 2250 | } |
| 2251 | } |
| 2252 | vport->port_state = LPFC_VPORT_READY; |
| 2253 | } else |
| 2254 | lpfc_rscn_disc(vport); |
| 2255 | } |
| 2256 | |
| 2257 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2258 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2259 | * @vport: pointer to a host virtual N_Port data structure. |
| 2260 | * |
| 2261 | * This routine determines whether there are more ndlps on a @vport |
| 2262 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 2263 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 2264 | * remaining nodes which need to have ADISC sent. |
| 2265 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2266 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2267 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2268 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2269 | if (vport->num_disc_nodes) |
| 2270 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2271 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2272 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2273 | "0210 Continue discovery with %d ADISCs to go " |
| 2274 | "Data: x%x x%x x%x\n", |
| 2275 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 2276 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2277 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2278 | if (vport->fc_flag & FC_NLP_MORE) { |
| 2279 | lpfc_set_disctmo(vport); |
| 2280 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 2281 | lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2282 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2283 | if (!vport->num_disc_nodes) |
| 2284 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2285 | return; |
| 2286 | } |
| 2287 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2288 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2289 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2290 | * @phba: pointer to lpfc hba data structure. |
| 2291 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2292 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2293 | * |
| 2294 | * This routine is the completion function for issuing the Address Discover |
| 2295 | * (ADISC) command. It first checks to see whether link went down during |
| 2296 | * the discovery process. If so, the node will be marked as node port |
| 2297 | * recovery for issuing discover IOCB by the link attention handler and |
| 2298 | * exit. Otherwise, the response status is checked. If error was reported |
| 2299 | * in the response status, the ADISC command shall be retried by invoking |
| 2300 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 2301 | * the response status, the state machine is invoked to set transition |
| 2302 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 2303 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2304 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2305 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2306 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2307 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2308 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2309 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2311 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2312 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2313 | |
| 2314 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2315 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2316 | |
| 2317 | irsp = &(rspiocb->iocb); |
| 2318 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2319 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2320 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2321 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 2322 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2323 | ndlp->nlp_DID); |
| 2324 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2325 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2326 | * is being used during discovery. |
| 2327 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2328 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2329 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2330 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2331 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2332 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2333 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2334 | "0104 ADISC completes to NPort x%x " |
| 2335 | "Data: x%x x%x x%x x%x x%x\n", |
| 2336 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2337 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2338 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2339 | if (lpfc_els_chk_latt(vport)) { |
| 2340 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2341 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2342 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2343 | goto out; |
| 2344 | } |
| 2345 | |
| 2346 | if (irsp->ulpStatus) { |
| 2347 | /* Check for retry */ |
| 2348 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2349 | /* ELS command is being retried */ |
| 2350 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2351 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2352 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2353 | spin_unlock_irq(shost->host_lock); |
| 2354 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2355 | } |
| 2356 | goto out; |
| 2357 | } |
| 2358 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2359 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2360 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2361 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2362 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2364 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2365 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2366 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2367 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2368 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2369 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2370 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2371 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2372 | /* Check to see if there are more ADISCs to be sent */ |
| 2373 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2374 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2375 | out: |
| 2376 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2377 | return; |
| 2378 | } |
| 2379 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2380 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2381 | * 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] | 2382 | * @vport: pointer to a virtual N_Port data structure. |
| 2383 | * @ndlp: pointer to a node-list data structure. |
| 2384 | * @retry: number of retries to the command IOCB. |
| 2385 | * |
| 2386 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2387 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2388 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2389 | * to issue the ADISC ELS command. |
| 2390 | * |
| 2391 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2392 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2393 | * will be stored into the context1 field of the IOCB for the completion |
| 2394 | * callback function to the ADISC ELS command. |
| 2395 | * |
| 2396 | * Return code |
| 2397 | * 0 - successfully issued adisc |
| 2398 | * 1 - failed to issue adisc |
| 2399 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2400 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2401 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2402 | uint8_t retry) |
| 2403 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2404 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2405 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | ADISC *ap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2408 | uint8_t *pcmd; |
| 2409 | uint16_t cmdsize; |
| 2410 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2411 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2412 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2413 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2414 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2415 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2416 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2417 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2418 | |
| 2419 | /* For ADISC request, remainder of payload is service parameters */ |
| 2420 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2421 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | |
| 2423 | /* Fill in ADISC payload */ |
| 2424 | ap = (ADISC *) pcmd; |
| 2425 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2426 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2427 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2428 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2429 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2430 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2431 | "Issue ADISC: did:x%x", |
| 2432 | ndlp->nlp_DID, 0, 0); |
| 2433 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2434 | phba->fc_stat.elsXmitADISC++; |
| 2435 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2436 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2438 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2439 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2440 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2441 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2442 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2443 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2445 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2446 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2447 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2448 | } |
| 2449 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2450 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2451 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2452 | * @phba: pointer to lpfc hba data structure. |
| 2453 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2454 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2455 | * |
| 2456 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2457 | * command. If no error status was reported from the LOGO response, the |
| 2458 | * state machine of the associated ndlp shall be invoked for transition with |
| 2459 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2460 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2461 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2462 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2463 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2464 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2465 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2466 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2467 | struct lpfc_vport *vport = ndlp->vport; |
| 2468 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2469 | IOCB_t *irsp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2470 | struct lpfcMboxq *mbox; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2471 | unsigned long flags; |
| 2472 | uint32_t skip_recovery = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2473 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2474 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2475 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2476 | |
| 2477 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2478 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2479 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2480 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2481 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2482 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2483 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2484 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2485 | ndlp->nlp_DID); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2486 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2487 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2488 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2489 | "0105 LOGO completes to NPort x%x " |
| 2490 | "Data: x%x x%x x%x x%x\n", |
| 2491 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2492 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2493 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2494 | if (lpfc_els_chk_latt(vport)) { |
| 2495 | skip_recovery = 1; |
| 2496 | goto out; |
| 2497 | } |
| 2498 | |
| 2499 | /* Check to see if link went down during discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2500 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2501 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2502 | * which should abort all outstanding IOs. |
| 2503 | */ |
| 2504 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2505 | NLP_EVT_DEVICE_RM); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2506 | skip_recovery = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2507 | goto out; |
| 2508 | } |
| 2509 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2510 | if (irsp->ulpStatus) { |
| 2511 | /* Check for retry */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2512 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2513 | /* ELS command is being retried */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2514 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2515 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2516 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2517 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2518 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2519 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2520 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2521 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2522 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2523 | if (lpfc_error_lost_link(irsp)) { |
| 2524 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2525 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | /* Call state machine. This will unregister the rpi if needed. */ |
| 2530 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); |
| 2531 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2532 | out: |
| 2533 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2534 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ |
| 2535 | if ((vport->fc_flag & FC_PT2PT) && |
| 2536 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { |
| 2537 | phba->pport->fc_myDID = 0; |
| 2538 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2539 | if (mbox) { |
| 2540 | lpfc_config_link(phba, mbox); |
| 2541 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2542 | mbox->vport = vport; |
| 2543 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 2544 | MBX_NOT_FINISHED) { |
| 2545 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2546 | skip_recovery = 1; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2547 | } |
| 2548 | } |
| 2549 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2550 | |
| 2551 | /* |
| 2552 | * If the node is a target, the handling attempts to recover the port. |
| 2553 | * For any other port type, the rpi is unregistered as an implicit |
| 2554 | * LOGO. |
| 2555 | */ |
| 2556 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) { |
| 2557 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 2558 | spin_lock_irqsave(shost->host_lock, flags); |
| 2559 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 2560 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2561 | |
| 2562 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2563 | "3187 LOGO completes to NPort x%x: Start " |
| 2564 | "Recovery Data: x%x x%x x%x x%x\n", |
| 2565 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2566 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 2567 | vport->num_disc_nodes); |
| 2568 | lpfc_disc_start(vport); |
| 2569 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2570 | return; |
| 2571 | } |
| 2572 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2573 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2574 | * 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] | 2575 | * @vport: pointer to a virtual N_Port data structure. |
| 2576 | * @ndlp: pointer to a node-list data structure. |
| 2577 | * @retry: number of retries to the command IOCB. |
| 2578 | * |
| 2579 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2580 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2581 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2582 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2583 | * |
| 2584 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2585 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2586 | * will be stored into the context1 field of the IOCB for the completion |
| 2587 | * callback function to the LOGO ELS command. |
| 2588 | * |
| 2589 | * Return code |
| 2590 | * 0 - successfully issued logo |
| 2591 | * 1 - failed to issue logo |
| 2592 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2593 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2594 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2595 | uint8_t retry) |
| 2596 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2597 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2598 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2599 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2600 | uint8_t *pcmd; |
| 2601 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2602 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2603 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2604 | spin_lock_irq(shost->host_lock); |
| 2605 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2606 | spin_unlock_irq(shost->host_lock); |
| 2607 | return 0; |
| 2608 | } |
| 2609 | spin_unlock_irq(shost->host_lock); |
| 2610 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2611 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2612 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2613 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2614 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2615 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2616 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2617 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2618 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2619 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2620 | |
| 2621 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2622 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2623 | pcmd += sizeof(uint32_t); |
| 2624 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2626 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2627 | "Issue LOGO: did:x%x", |
| 2628 | ndlp->nlp_DID, 0, 0); |
| 2629 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2630 | /* |
| 2631 | * If we are issuing a LOGO, we may try to recover the remote NPort |
| 2632 | * by issuing a PLOGI later. Even though we issue ELS cmds by the |
| 2633 | * VPI, if we have a valid RPI, and that RPI gets unreg'ed while |
| 2634 | * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI |
| 2635 | * for that ELS cmd. To avoid this situation, lets get rid of the |
| 2636 | * RPI right now, before any ELS cmds are sent. |
| 2637 | */ |
| 2638 | spin_lock_irq(shost->host_lock); |
| 2639 | ndlp->nlp_flag |= NLP_ISSUE_LOGO; |
| 2640 | spin_unlock_irq(shost->host_lock); |
| 2641 | if (lpfc_unreg_rpi(vport, ndlp)) { |
| 2642 | lpfc_els_free_iocb(phba, elsiocb); |
| 2643 | return 0; |
| 2644 | } |
| 2645 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2646 | phba->fc_stat.elsXmitLOGO++; |
| 2647 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2648 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2650 | ndlp->nlp_flag &= ~NLP_ISSUE_LOGO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2651 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2652 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2653 | |
| 2654 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2655 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2656 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2657 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2659 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2660 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2661 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | } |
| 2663 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2664 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2665 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2666 | * @phba: pointer to lpfc hba data structure. |
| 2667 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2668 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2669 | * |
| 2670 | * This routine is a generic completion callback function for ELS commands. |
| 2671 | * Specifically, it is the callback function which does not need to perform |
| 2672 | * any command specific operations. It is currently used by the ELS command |
| 2673 | * issuing routines for the ELS State Change Request (SCR), |
| 2674 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2675 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2676 | * certain debug loggings, this callback function simply invokes the |
| 2677 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2678 | * discovery process. |
| 2679 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2680 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2681 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2682 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2683 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2684 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2685 | IOCB_t *irsp; |
| 2686 | |
| 2687 | irsp = &rspiocb->iocb; |
| 2688 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2689 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2690 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2691 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2692 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2693 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2694 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2695 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2696 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2697 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2698 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2699 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2700 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2701 | return; |
| 2702 | } |
| 2703 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2704 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2705 | * 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] | 2706 | * @vport: pointer to a host virtual N_Port data structure. |
| 2707 | * @nportid: N_Port identifier to the remote node. |
| 2708 | * @retry: number of retries to the command IOCB. |
| 2709 | * |
| 2710 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2711 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2712 | * first search the @vport node list to find the matching ndlp. If no such |
| 2713 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2714 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2715 | * routine is invoked to send the SCR IOCB. |
| 2716 | * |
| 2717 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2718 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2719 | * will be stored into the context1 field of the IOCB for the completion |
| 2720 | * callback function to the SCR ELS command. |
| 2721 | * |
| 2722 | * Return code |
| 2723 | * 0 - Successfully issued scr command |
| 2724 | * 1 - Failed to issue scr command |
| 2725 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2726 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2727 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2728 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2729 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2730 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2731 | uint8_t *pcmd; |
| 2732 | uint16_t cmdsize; |
| 2733 | struct lpfc_nodelist *ndlp; |
| 2734 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2735 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2736 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2737 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2738 | if (!ndlp) { |
| 2739 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2740 | if (!ndlp) |
| 2741 | return 1; |
| 2742 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2743 | lpfc_enqueue_node(vport, ndlp); |
| 2744 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2745 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2746 | if (!ndlp) |
| 2747 | return 1; |
| 2748 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2749 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2750 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2751 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2752 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2753 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2754 | /* This will trigger the release of the node just |
| 2755 | * allocated |
| 2756 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2757 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2758 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2759 | } |
| 2760 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2761 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2762 | |
| 2763 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2764 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2765 | |
| 2766 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2767 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2768 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2769 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2770 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2771 | "Issue SCR: did:x%x", |
| 2772 | ndlp->nlp_DID, 0, 0); |
| 2773 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2774 | phba->fc_stat.elsXmitSCR++; |
| 2775 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2776 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2777 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2778 | /* The additional lpfc_nlp_put will cause the following |
| 2779 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2780 | * the node. |
| 2781 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2782 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2783 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2784 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2785 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2786 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2787 | * trigger the release of node. |
| 2788 | */ |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 2789 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2790 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2791 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2792 | } |
| 2793 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2794 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2795 | * 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] | 2796 | * @vport: pointer to a host virtual N_Port data structure. |
| 2797 | * @nportid: N_Port identifier to the remote node. |
| 2798 | * @retry: number of retries to the command IOCB. |
| 2799 | * |
| 2800 | * This routine issues a Fibre Channel Address Resolution Response |
| 2801 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2802 | * is passed into the function. It first search the @vport node list to find |
| 2803 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2804 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2805 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2806 | * |
| 2807 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2808 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2809 | * will be stored into the context1 field of the IOCB for the completion |
| 2810 | * callback function to the PARPR ELS command. |
| 2811 | * |
| 2812 | * Return code |
| 2813 | * 0 - Successfully issued farpr command |
| 2814 | * 1 - Failed to issue farpr command |
| 2815 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2816 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2817 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2818 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2819 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2820 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2821 | FARP *fp; |
| 2822 | uint8_t *pcmd; |
| 2823 | uint32_t *lp; |
| 2824 | uint16_t cmdsize; |
| 2825 | struct lpfc_nodelist *ondlp; |
| 2826 | struct lpfc_nodelist *ndlp; |
| 2827 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2828 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2829 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2830 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2831 | if (!ndlp) { |
| 2832 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2833 | if (!ndlp) |
| 2834 | return 1; |
| 2835 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2836 | lpfc_enqueue_node(vport, ndlp); |
| 2837 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2838 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2839 | if (!ndlp) |
| 2840 | return 1; |
| 2841 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2842 | |
| 2843 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2844 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2845 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2846 | /* This will trigger the release of the node just |
| 2847 | * allocated |
| 2848 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2849 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2850 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2851 | } |
| 2852 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2853 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2854 | |
| 2855 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2856 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | |
| 2858 | /* Fill in FARPR payload */ |
| 2859 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2860 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2861 | lp = (uint32_t *) pcmd; |
| 2862 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2863 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2864 | fp->Rflags = 0; |
| 2865 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2866 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2867 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2868 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2869 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2870 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2871 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2872 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2873 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2874 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2875 | } |
| 2876 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2877 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2878 | "Issue FARPR: did:x%x", |
| 2879 | ndlp->nlp_DID, 0, 0); |
| 2880 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2881 | phba->fc_stat.elsXmitFARPR++; |
| 2882 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2883 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2884 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2885 | /* The additional lpfc_nlp_put will cause the following |
| 2886 | * lpfc_els_free_iocb routine to trigger the release of |
| 2887 | * the node. |
| 2888 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2889 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2890 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2891 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2892 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2893 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2894 | * trigger the release of the node. |
| 2895 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2896 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2897 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2898 | } |
| 2899 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2900 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2901 | * 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] | 2902 | * @vport: pointer to a host virtual N_Port data structure. |
| 2903 | * @nlp: pointer to a node-list data structure. |
| 2904 | * |
| 2905 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2906 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2907 | * removes the ELS retry event if it presents. In addition, if the |
| 2908 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2909 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2910 | * ADISC. |
| 2911 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2912 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2913 | 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] | 2914 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2915 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2916 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2917 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2918 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2919 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2920 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2921 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2922 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2923 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2924 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2925 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2926 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2927 | /* Decrement nlp reference count held for the delayed retry */ |
| 2928 | evtp = &nlp->els_retry_evt; |
| 2929 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2930 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2931 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2932 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2933 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2934 | spin_unlock_irq(shost->host_lock); |
| 2935 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2936 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2937 | /* Check if there are more ADISCs to be sent */ |
| 2938 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2939 | } else { |
| 2940 | /* Check if there are more PLOGIs to be sent */ |
| 2941 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2942 | if (vport->num_disc_nodes == 0) { |
| 2943 | spin_lock_irq(shost->host_lock); |
| 2944 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2945 | spin_unlock_irq(shost->host_lock); |
| 2946 | lpfc_can_disctmo(vport); |
| 2947 | lpfc_end_rscn(vport); |
| 2948 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2949 | } |
| 2950 | } |
| 2951 | } |
| 2952 | return; |
| 2953 | } |
| 2954 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2955 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2956 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2957 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2958 | * |
| 2959 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2960 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2961 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2962 | * adds the delayed events to the HBA work list and invokes the |
| 2963 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2964 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2965 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2966 | * reference to ndlp will still be available when the worker thread gets |
| 2967 | * to the event associated with the ndlp. |
| 2968 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2969 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2970 | lpfc_els_retry_delay(unsigned long ptr) |
| 2971 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2972 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2973 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2974 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2975 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2976 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2977 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2978 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2979 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2980 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2981 | return; |
| 2982 | } |
| 2983 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2984 | /* We need to hold the node by incrementing the reference |
| 2985 | * count until the queued work is done |
| 2986 | */ |
| 2987 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2988 | if (evtp->evt_arg1) { |
| 2989 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2990 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2991 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2992 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2993 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2994 | return; |
| 2995 | } |
| 2996 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2997 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2998 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2999 | * @ndlp: pointer to a node-list data structure. |
| 3000 | * |
| 3001 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 3002 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 3003 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 3004 | * function according to the delayed ELS command to retry the command. |
| 3005 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3006 | void |
| 3007 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 3008 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3009 | struct lpfc_vport *vport = ndlp->vport; |
| 3010 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3011 | uint32_t cmd, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3012 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3013 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3014 | cmd = ndlp->nlp_last_elscmd; |
| 3015 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3016 | |
| 3017 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3018 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3019 | return; |
| 3020 | } |
| 3021 | |
| 3022 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3023 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 3024 | /* |
| 3025 | * If a discovery event readded nlp_delayfunc after timer |
| 3026 | * firing and before processing the timer, cancel the |
| 3027 | * nlp_delayfunc. |
| 3028 | */ |
| 3029 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3030 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3031 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3032 | |
| 3033 | switch (cmd) { |
| 3034 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3035 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3036 | break; |
| 3037 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3038 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3039 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3040 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3041 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3042 | break; |
| 3043 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3044 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3045 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3046 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3047 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3048 | break; |
| 3049 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3050 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3051 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3052 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3053 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3054 | break; |
| 3055 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3056 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3057 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3058 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3059 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3060 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3061 | case ELS_CMD_FDISC: |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3062 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
| 3063 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3064 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3065 | } |
| 3066 | return; |
| 3067 | } |
| 3068 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3069 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3070 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3071 | * @phba: pointer to lpfc hba data structure. |
| 3072 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3073 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3074 | * |
| 3075 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 3076 | * failed. The following ELS IOCBs use this function for retrying the command |
| 3077 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 3078 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 3079 | * returned error status, it makes the decision whether a retry shall be |
| 3080 | * issued for the command, and whether a retry shall be made immediately or |
| 3081 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 3082 | * is called to retry the command. In the later case, the ELS command shall |
| 3083 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 3084 | * ndlp for the delayed command issusing. |
| 3085 | * |
| 3086 | * Return code |
| 3087 | * 0 - No retry of els command is made |
| 3088 | * 1 - Immediate or delayed retry of els command is made |
| 3089 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3090 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3091 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3092 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3093 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3094 | struct lpfc_vport *vport = cmdiocb->vport; |
| 3095 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3096 | IOCB_t *irsp = &rspiocb->iocb; |
| 3097 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3098 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3099 | uint32_t *elscmd; |
| 3100 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3101 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3102 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3103 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3104 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3105 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3106 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3107 | /* Note: context2 may be 0 for internal driver abort |
| 3108 | * of delays ELS command. |
| 3109 | */ |
| 3110 | |
| 3111 | if (pcmd && pcmd->virt) { |
| 3112 | elscmd = (uint32_t *) (pcmd->virt); |
| 3113 | cmd = *elscmd++; |
| 3114 | } |
| 3115 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3116 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3117 | did = ndlp->nlp_DID; |
| 3118 | else { |
| 3119 | /* We should only hit this case for retrying PLOGI */ |
| 3120 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3121 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3122 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 3123 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3124 | return 1; |
| 3125 | } |
| 3126 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3127 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3128 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 3129 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 3130 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3131 | switch (irsp->ulpStatus) { |
| 3132 | case IOSTAT_FCP_RSP_ERROR: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3133 | break; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3134 | case IOSTAT_REMOTE_STOP: |
| 3135 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3136 | /* This IO was aborted by the target, we don't |
| 3137 | * know the rxid and because we did not send the |
| 3138 | * ABTS we cannot generate and RRQ. |
| 3139 | */ |
| 3140 | lpfc_set_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 3141 | cmdiocb->sli4_lxritag, 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3142 | } |
| 3143 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3144 | case IOSTAT_LOCAL_REJECT: |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3145 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3146 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3147 | if (cmd == ELS_CMD_FLOGI) { |
| 3148 | if (PCI_DEVICE_ID_HORNET == |
| 3149 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3150 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3151 | phba->pport->fc_myDID = 0; |
| 3152 | phba->alpa_map[0] = 0; |
| 3153 | phba->alpa_map[1] = 0; |
| 3154 | } |
| 3155 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3156 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3157 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3158 | retry = 1; |
| 3159 | break; |
| 3160 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3161 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3162 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3163 | "0124 Retry illegal cmd x%x " |
| 3164 | "retry:x%x delay:x%x\n", |
| 3165 | cmd, cmdiocb->retry, delay); |
| 3166 | retry = 1; |
| 3167 | /* All command's retry policy */ |
| 3168 | maxretry = 8; |
| 3169 | if (cmdiocb->retry > 2) |
| 3170 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3171 | break; |
| 3172 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3173 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3174 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3175 | retry = 1; |
| 3176 | if (cmdiocb->retry > 100) |
| 3177 | delay = 100; |
| 3178 | maxretry = 250; |
| 3179 | break; |
| 3180 | |
| 3181 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3182 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3183 | retry = 1; |
| 3184 | break; |
| 3185 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3186 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3187 | case IOERR_INVALID_RPI: |
James Smart | 5b5b36a | 2013-01-03 15:43:19 -0500 | [diff] [blame] | 3188 | if (cmd == ELS_CMD_PLOGI && |
| 3189 | did == NameServer_DID) { |
| 3190 | /* Continue forever if plogi to */ |
| 3191 | /* the nameserver fails */ |
| 3192 | maxretry = 0; |
| 3193 | delay = 100; |
| 3194 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3195 | retry = 1; |
| 3196 | break; |
| 3197 | } |
| 3198 | break; |
| 3199 | |
| 3200 | case IOSTAT_NPORT_RJT: |
| 3201 | case IOSTAT_FABRIC_RJT: |
| 3202 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 3203 | retry = 1; |
| 3204 | break; |
| 3205 | } |
| 3206 | break; |
| 3207 | |
| 3208 | case IOSTAT_NPORT_BSY: |
| 3209 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3210 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3211 | retry = 1; |
| 3212 | break; |
| 3213 | |
| 3214 | case IOSTAT_LS_RJT: |
| 3215 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 3216 | /* Added for Vendor specifc support |
| 3217 | * Just keep retrying for these Rsn / Exp codes |
| 3218 | */ |
| 3219 | switch (stat.un.b.lsRjtRsnCode) { |
| 3220 | case LSRJT_UNABLE_TPC: |
| 3221 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3222 | LSEXP_CMD_IN_PROGRESS) { |
| 3223 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3224 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3225 | maxretry = 48; |
| 3226 | } |
| 3227 | retry = 1; |
| 3228 | break; |
| 3229 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3230 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3231 | LSEXP_CANT_GIVE_DATA) { |
| 3232 | if (cmd == ELS_CMD_PLOGI) { |
| 3233 | delay = 1000; |
| 3234 | maxretry = 48; |
| 3235 | } |
| 3236 | retry = 1; |
| 3237 | break; |
| 3238 | } |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 3239 | if ((cmd == ELS_CMD_PLOGI) || |
| 3240 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3241 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3242 | maxretry = lpfc_max_els_tries + 1; |
| 3243 | retry = 1; |
| 3244 | break; |
| 3245 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3246 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3247 | (cmd == ELS_CMD_FDISC) && |
| 3248 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3249 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3250 | "0125 FDISC Failed (x%x). " |
| 3251 | "Fabric out of resources\n", |
| 3252 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3253 | lpfc_vport_set_state(vport, |
| 3254 | FC_VPORT_NO_FABRIC_RSCS); |
| 3255 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3256 | break; |
| 3257 | |
| 3258 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3259 | if ((cmd == ELS_CMD_PLOGI) || |
| 3260 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3261 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3262 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3263 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3264 | /* FDISC retry policy */ |
| 3265 | maxretry = 48; |
| 3266 | if (cmdiocb->retry >= 32) |
| 3267 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3268 | } |
| 3269 | retry = 1; |
| 3270 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3271 | |
| 3272 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3273 | /* There are some cases where switches return this |
| 3274 | * error when they are not ready and should be returning |
| 3275 | * Logical Busy. We should delay every time. |
| 3276 | */ |
| 3277 | if (cmd == ELS_CMD_FDISC && |
| 3278 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 3279 | maxretry = 3; |
| 3280 | delay = 1000; |
| 3281 | retry = 1; |
| 3282 | break; |
| 3283 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3284 | case LSRJT_PROTOCOL_ERR: |
| 3285 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3286 | (cmd == ELS_CMD_FDISC) && |
| 3287 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 3288 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 3289 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3290 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3291 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3292 | "Fabric Detected Bad WWN\n", |
| 3293 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3294 | lpfc_vport_set_state(vport, |
| 3295 | FC_VPORT_FABRIC_REJ_WWN); |
| 3296 | } |
| 3297 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3298 | } |
| 3299 | break; |
| 3300 | |
| 3301 | case IOSTAT_INTERMED_RSP: |
| 3302 | case IOSTAT_BA_RJT: |
| 3303 | break; |
| 3304 | |
| 3305 | default: |
| 3306 | break; |
| 3307 | } |
| 3308 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3309 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3310 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3311 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3312 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3313 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 3314 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3315 | /* FLOGI retry policy */ |
| 3316 | retry = 1; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3317 | /* retry FLOGI forever */ |
James Smart | 6eae430 | 2015-04-07 15:07:23 -0400 | [diff] [blame] | 3318 | if (phba->link_flag != LS_LOOPBACK_MODE) |
| 3319 | maxretry = 0; |
| 3320 | else |
| 3321 | maxretry = 2; |
| 3322 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3323 | if (cmdiocb->retry >= 100) |
| 3324 | delay = 5000; |
| 3325 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3326 | delay = 1000; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3327 | } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) { |
| 3328 | /* retry FDISCs every second up to devloss */ |
| 3329 | retry = 1; |
| 3330 | maxretry = vport->cfg_devloss_tmo; |
| 3331 | delay = 1000; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3332 | } |
| 3333 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3334 | cmdiocb->retry++; |
| 3335 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3336 | phba->fc_stat.elsRetryExceeded++; |
| 3337 | retry = 0; |
| 3338 | } |
| 3339 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3340 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 3341 | retry = 0; |
| 3342 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3343 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3344 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 3345 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 3346 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 3347 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3348 | "2849 Stop retry ELS command " |
| 3349 | "x%x to remote NPORT x%x, " |
| 3350 | "Data: x%x x%x\n", cmd, did, |
| 3351 | cmdiocb->retry, delay); |
| 3352 | return 0; |
| 3353 | } |
| 3354 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3355 | |
| 3356 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3357 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3358 | "0107 Retry ELS command x%x to remote " |
| 3359 | "NPORT x%x Data: x%x x%x\n", |
| 3360 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3361 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3362 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 3363 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3364 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 3365 | IOERR_NO_RESOURCES))) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3366 | /* Don't reset timer for no resources */ |
| 3367 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3368 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3369 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3370 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3371 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3375 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | phba->fc_stat.elsDelayRetry++; |
| 3377 | ndlp->nlp_retry = cmdiocb->retry; |
| 3378 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3379 | /* delay is specified in milliseconds */ |
| 3380 | mod_timer(&ndlp->nlp_delayfunc, |
| 3381 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3382 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3383 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3384 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3385 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3386 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3387 | if (cmd == ELS_CMD_PRLI) |
| 3388 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 3389 | NLP_STE_PRLI_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3390 | else |
| 3391 | lpfc_nlp_set_state(vport, ndlp, |
| 3392 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3393 | ndlp->nlp_last_elscmd = cmd; |
| 3394 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3395 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3396 | } |
| 3397 | switch (cmd) { |
| 3398 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3399 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3400 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3401 | case ELS_CMD_FDISC: |
| 3402 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 3403 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3404 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3405 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3406 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3407 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3408 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3409 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3410 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3411 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3412 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3413 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3414 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3415 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3416 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3418 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3419 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 3420 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3421 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3422 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3423 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3424 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3425 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3426 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3427 | } |
| 3428 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3429 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3430 | if (logerr) { |
| 3431 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3432 | "0137 No retry ELS command x%x to remote " |
| 3433 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 3434 | cmd, did, irsp->ulpStatus, |
| 3435 | irsp->un.ulpWord[4]); |
| 3436 | } |
| 3437 | else { |
| 3438 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3439 | "0108 No retry ELS command x%x to remote " |
| 3440 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 3441 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 3442 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3443 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3444 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3445 | } |
| 3446 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3447 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3448 | * 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] | 3449 | * @phba: pointer to lpfc hba data structure. |
| 3450 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3451 | * |
| 3452 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3453 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3454 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3455 | * response of the command IOCB. If so, it will be released before releasing |
| 3456 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3457 | * |
| 3458 | * Return code |
| 3459 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3460 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3461 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3462 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3463 | { |
| 3464 | struct lpfc_dmabuf *buf_ptr; |
| 3465 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3466 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3467 | if (!list_empty(&buf_ptr1->list)) { |
| 3468 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3469 | struct lpfc_dmabuf, |
| 3470 | list); |
| 3471 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3472 | kfree(buf_ptr); |
| 3473 | } |
| 3474 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3475 | kfree(buf_ptr1); |
| 3476 | return 0; |
| 3477 | } |
| 3478 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3479 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3480 | * 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] | 3481 | * @phba: pointer to lpfc hba data structure. |
| 3482 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3483 | * |
| 3484 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3485 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3486 | * pool. |
| 3487 | * |
| 3488 | * Return code |
| 3489 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3490 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3491 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3492 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3493 | { |
| 3494 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3495 | kfree(buf_ptr); |
| 3496 | return 0; |
| 3497 | } |
| 3498 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3499 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3500 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3501 | * @phba: pointer to lpfc hba data structure. |
| 3502 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3503 | * |
| 3504 | * This routine frees a command IOCB and its associated resources. The |
| 3505 | * command IOCB data structure contains the reference to various associated |
| 3506 | * resources, these fields must be set to NULL if the associated reference |
| 3507 | * not present: |
| 3508 | * context1 - reference to ndlp |
| 3509 | * context2 - reference to cmd |
| 3510 | * context2->next - reference to rsp |
| 3511 | * context3 - reference to bpl |
| 3512 | * |
| 3513 | * It first properly decrements the reference count held on ndlp for the |
| 3514 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3515 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3516 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3517 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3518 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3519 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3520 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3521 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3522 | * |
| 3523 | * Return code |
| 3524 | * 0 - Success (currently, always return 0) |
| 3525 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3526 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3527 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3528 | { |
| 3529 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3530 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3531 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3532 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3533 | if (ndlp) { |
| 3534 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3535 | lpfc_nlp_put(ndlp); |
| 3536 | |
| 3537 | /* If the ndlp is not being used by another discovery |
| 3538 | * thread, free it. |
| 3539 | */ |
| 3540 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3541 | /* If ndlp is being used by another discovery |
| 3542 | * thread, just clear NLP_DEFER_RM |
| 3543 | */ |
| 3544 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3545 | } |
| 3546 | } |
| 3547 | else |
| 3548 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3549 | elsiocb->context1 = NULL; |
| 3550 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3551 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3552 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3553 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3554 | /* Firmware could still be in progress of DMAing |
| 3555 | * payload, so don't free data buffer till after |
| 3556 | * a hbeat. |
| 3557 | */ |
| 3558 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3559 | buf_ptr = elsiocb->context2; |
| 3560 | elsiocb->context2 = NULL; |
| 3561 | if (buf_ptr) { |
| 3562 | buf_ptr1 = NULL; |
| 3563 | spin_lock_irq(&phba->hbalock); |
| 3564 | if (!list_empty(&buf_ptr->list)) { |
| 3565 | list_remove_head(&buf_ptr->list, |
| 3566 | buf_ptr1, struct lpfc_dmabuf, |
| 3567 | list); |
| 3568 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3569 | list_add_tail(&buf_ptr1->list, |
| 3570 | &phba->elsbuf); |
| 3571 | phba->elsbuf_cnt++; |
| 3572 | } |
| 3573 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3574 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3575 | phba->elsbuf_cnt++; |
| 3576 | spin_unlock_irq(&phba->hbalock); |
| 3577 | } |
| 3578 | } else { |
| 3579 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3580 | lpfc_els_free_data(phba, buf_ptr1); |
| 3581 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | } |
| 3583 | |
| 3584 | if (elsiocb->context3) { |
| 3585 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3586 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3587 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3588 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3589 | return 0; |
| 3590 | } |
| 3591 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3592 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3593 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3594 | * @phba: pointer to lpfc hba data structure. |
| 3595 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3596 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3597 | * |
| 3598 | * This routine is the completion callback function to the Logout (LOGO) |
| 3599 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3600 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3601 | * release the ndlp if it has the last reference remaining (reference count |
| 3602 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3603 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3604 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3605 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3606 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3607 | * IOCB data structure. |
| 3608 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3609 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3610 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3611 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3612 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3613 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3614 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3615 | IOCB_t *irsp; |
| 3616 | |
| 3617 | irsp = &rspiocb->iocb; |
| 3618 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3619 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3620 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3621 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3622 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3623 | "0109 ACC to LOGO completes to NPort x%x " |
| 3624 | "Data: x%x x%x x%x\n", |
| 3625 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3626 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3627 | |
| 3628 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3629 | /* NPort Recovery mode or node is just allocated */ |
| 3630 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3631 | /* If the ndlp is being used by another discovery |
| 3632 | * thread, just unregister the RPI. |
| 3633 | */ |
| 3634 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3635 | } else { |
| 3636 | /* Indicate the node has already released, should |
| 3637 | * not reference to it from within lpfc_els_free_iocb. |
| 3638 | */ |
| 3639 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3640 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3641 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3642 | |
| 3643 | /* |
| 3644 | * 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] | 3645 | * At this point, the driver is done so release the IOCB |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3646 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3647 | lpfc_els_free_iocb(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3648 | } |
| 3649 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3650 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3651 | * 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] | 3652 | * @phba: pointer to lpfc hba data structure. |
| 3653 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3654 | * |
| 3655 | * This routine is the completion callback function for unregister default |
| 3656 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3657 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3658 | * decrements the ndlp reference count held for this completion callback |
| 3659 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3660 | * whether there is only one reference left on the ndlp. If so, it will |
| 3661 | * perform one more decrement and trigger the release of the ndlp. |
| 3662 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3663 | void |
| 3664 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3665 | { |
| 3666 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3667 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3668 | |
| 3669 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3670 | pmb->context2 = NULL; |
| 3671 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3672 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3673 | kfree(mp); |
| 3674 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3675 | if (ndlp) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3676 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3677 | "0006 rpi%x DID:%x flg:%x %d map:%x %p\n", |
| 3678 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
| 3679 | atomic_read(&ndlp->kref.refcount), |
| 3680 | ndlp->nlp_usg_map, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3681 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 3682 | lpfc_nlp_put(ndlp); |
| 3683 | /* This is the end of the default RPI cleanup logic for |
| 3684 | * this ndlp. If no other discovery threads are using |
| 3685 | * this ndlp, free all resources associated with it. |
| 3686 | */ |
| 3687 | lpfc_nlp_not_used(ndlp); |
| 3688 | } else { |
| 3689 | lpfc_drop_node(ndlp->vport, ndlp); |
| 3690 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3691 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3692 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3693 | return; |
| 3694 | } |
| 3695 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3696 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3697 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3698 | * @phba: pointer to lpfc hba data structure. |
| 3699 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3700 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3701 | * |
| 3702 | * This routine is the completion callback function for ELS Response IOCB |
| 3703 | * command. In normal case, this callback function just properly sets the |
| 3704 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3705 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3706 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3707 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3708 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3709 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3710 | * are currently referring it. |
| 3711 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3712 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3713 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3714 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3715 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3716 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3717 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3718 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3719 | IOCB_t *irsp; |
| 3720 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3721 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3722 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3723 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3724 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3725 | irsp = &rspiocb->iocb; |
| 3726 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3727 | if (cmdiocb->context_un.mbox) |
| 3728 | mbox = cmdiocb->context_un.mbox; |
| 3729 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3730 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3731 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3732 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3733 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3734 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3735 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3736 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3737 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3738 | */ |
| 3739 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3740 | ls_rjt = 1; |
| 3741 | } |
| 3742 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3743 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3744 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3745 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3746 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3747 | if (mp) { |
| 3748 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3749 | kfree(mp); |
| 3750 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3751 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3752 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3753 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3754 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3755 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3756 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3757 | /* Indicate the node has already released, |
| 3758 | * should not reference to it from within |
| 3759 | * the routine lpfc_els_free_iocb. |
| 3760 | */ |
| 3761 | cmdiocb->context1 = NULL; |
| 3762 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3763 | goto out; |
| 3764 | } |
| 3765 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3766 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3767 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3768 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3769 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3770 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3771 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3772 | "0110 ELS response tag x%x completes " |
| 3773 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3774 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3775 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3776 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3777 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3778 | if (mbox) { |
| 3779 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3780 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3781 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3782 | /* Increment reference count to ndlp to hold the |
| 3783 | * reference to ndlp for the callback function. |
| 3784 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3785 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3786 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3787 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3788 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3789 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3790 | } |
| 3791 | else { |
| 3792 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3793 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3794 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3795 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3796 | } |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3797 | |
| 3798 | ndlp->nlp_flag |= NLP_REG_LOGIN_SEND; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3799 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3800 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 | goto out; |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3802 | |
| 3803 | /* Decrement the ndlp reference count we |
| 3804 | * set for this failed mailbox command. |
| 3805 | */ |
| 3806 | lpfc_nlp_put(ndlp); |
| 3807 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3808 | |
| 3809 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3810 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3811 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3812 | "Data: x%x x%x x%x\n", |
| 3813 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3814 | ndlp->nlp_rpi); |
| 3815 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3816 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3817 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3818 | /* Indicate node has already been released, |
| 3819 | * should not reference to it from within |
| 3820 | * the routine lpfc_els_free_iocb. |
| 3821 | */ |
| 3822 | cmdiocb->context1 = NULL; |
| 3823 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3824 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3825 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3826 | if (!lpfc_error_lost_link(irsp) && |
| 3827 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3828 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3829 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3830 | /* Indicate node has already been |
| 3831 | * released, should not reference |
| 3832 | * to it from within the routine |
| 3833 | * lpfc_els_free_iocb. |
| 3834 | */ |
| 3835 | cmdiocb->context1 = NULL; |
| 3836 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3837 | } |
| 3838 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3839 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3840 | if (mp) { |
| 3841 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3842 | kfree(mp); |
| 3843 | } |
| 3844 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3845 | } |
| 3846 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3847 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3848 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3849 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3850 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3851 | |
| 3852 | /* If the node is not being used by another discovery thread, |
| 3853 | * and we are sending a reject, we are done with it. |
| 3854 | * Release driver reference count here and free associated |
| 3855 | * resources. |
| 3856 | */ |
| 3857 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3858 | if (lpfc_nlp_not_used(ndlp)) |
| 3859 | /* Indicate node has already been released, |
| 3860 | * should not reference to it from within |
| 3861 | * the routine lpfc_els_free_iocb. |
| 3862 | */ |
| 3863 | cmdiocb->context1 = NULL; |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3864 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3865 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3866 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3867 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3868 | return; |
| 3869 | } |
| 3870 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3871 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3872 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3873 | * @vport: pointer to a host virtual N_Port data structure. |
| 3874 | * @flag: the els command code to be accepted. |
| 3875 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3876 | * @ndlp: pointer to a node-list data structure. |
| 3877 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3878 | * |
| 3879 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3880 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3881 | * specific ACC response command to be issued and invokes the |
| 3882 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3883 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3884 | * field of the IOCB for the completion callback function to issue the |
| 3885 | * mailbox command to the HBA later when callback is invoked. |
| 3886 | * |
| 3887 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3888 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3889 | * will be stored into the context1 field of the IOCB for the completion |
| 3890 | * callback function to the corresponding response ELS IOCB command. |
| 3891 | * |
| 3892 | * Return code |
| 3893 | * 0 - Successfully issued acc response |
| 3894 | * 1 - Failed to issue acc response |
| 3895 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3896 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3897 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3898 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3899 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3900 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3901 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3902 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3903 | IOCB_t *icmd; |
| 3904 | IOCB_t *oldcmd; |
| 3905 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3906 | uint8_t *pcmd; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3907 | struct serv_parm *sp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3908 | uint16_t cmdsize; |
| 3909 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3910 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3911 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3912 | oldcmd = &oldiocb->iocb; |
| 3913 | |
| 3914 | switch (flag) { |
| 3915 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3916 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3917 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3918 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3919 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3920 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3921 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3922 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3923 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3924 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3925 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3926 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3927 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3928 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3929 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3930 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3931 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3932 | |
| 3933 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3934 | "Issue ACC: did:x%x flg:x%x", |
| 3935 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3936 | break; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3937 | case ELS_CMD_FLOGI: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3938 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3939 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3940 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3941 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3942 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3943 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3944 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3945 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3946 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3947 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3948 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3949 | |
| 3950 | if (mbox) |
| 3951 | elsiocb->context_un.mbox = mbox; |
| 3952 | |
| 3953 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3954 | pcmd += sizeof(uint32_t); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3955 | sp = (struct serv_parm *)pcmd; |
| 3956 | |
| 3957 | if (flag == ELS_CMD_FLOGI) { |
| 3958 | /* Copy the received service parameters back */ |
| 3959 | memcpy(sp, &phba->fc_fabparam, |
| 3960 | sizeof(struct serv_parm)); |
| 3961 | |
| 3962 | /* Clear the F_Port bit */ |
| 3963 | sp->cmn.fPort = 0; |
| 3964 | |
| 3965 | /* Mark all class service parameters as invalid */ |
| 3966 | sp->cls1.classValid = 0; |
| 3967 | sp->cls2.classValid = 0; |
| 3968 | sp->cls3.classValid = 0; |
| 3969 | sp->cls4.classValid = 0; |
| 3970 | |
| 3971 | /* Copy our worldwide names */ |
| 3972 | memcpy(&sp->portName, &vport->fc_sparam.portName, |
| 3973 | sizeof(struct lpfc_name)); |
| 3974 | memcpy(&sp->nodeName, &vport->fc_sparam.nodeName, |
| 3975 | sizeof(struct lpfc_name)); |
| 3976 | } else { |
| 3977 | memcpy(pcmd, &vport->fc_sparam, |
| 3978 | sizeof(struct serv_parm)); |
| 3979 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3980 | |
| 3981 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3982 | "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3983 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3984 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3985 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3986 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3987 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3988 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3989 | if (!elsiocb) |
| 3990 | return 1; |
| 3991 | |
| 3992 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3993 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3994 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3995 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3996 | |
| 3997 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3998 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3999 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 4000 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 4001 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4002 | |
| 4003 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4004 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 4005 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4006 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4007 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4008 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4009 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4010 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4011 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4012 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 4013 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x " |
| 4014 | "fc_flag x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4015 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4016 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 4017 | ndlp->nlp_rpi, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4018 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4019 | spin_lock_irq(shost->host_lock); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4020 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4021 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND)) |
| 4022 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4023 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4024 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 4025 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4026 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4027 | } |
| 4028 | |
| 4029 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4030 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4031 | if (rc == IOCB_ERROR) { |
| 4032 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4033 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4034 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4035 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4036 | } |
| 4037 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4038 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4039 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4040 | * @vport: pointer to a virtual N_Port data structure. |
| 4041 | * @rejectError: |
| 4042 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4043 | * @ndlp: pointer to a node-list data structure. |
| 4044 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4045 | * |
| 4046 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 4047 | * command. If a @mbox pointer is passed in, it will be put into the |
| 4048 | * context_un.mbox field of the IOCB for the completion callback function |
| 4049 | * to issue to the HBA later. |
| 4050 | * |
| 4051 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4052 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4053 | * will be stored into the context1 field of the IOCB for the completion |
| 4054 | * callback function to the reject response ELS IOCB command. |
| 4055 | * |
| 4056 | * Return code |
| 4057 | * 0 - Successfully issued reject response |
| 4058 | * 1 - Failed to issue reject response |
| 4059 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4060 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4061 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4062 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 4063 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4064 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4065 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4066 | IOCB_t *icmd; |
| 4067 | IOCB_t *oldcmd; |
| 4068 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4069 | uint8_t *pcmd; |
| 4070 | uint16_t cmdsize; |
| 4071 | int rc; |
| 4072 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4073 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4074 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4075 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4076 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4077 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4078 | |
| 4079 | icmd = &elsiocb->iocb; |
| 4080 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4081 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4082 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4083 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4084 | |
| 4085 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4086 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4087 | *((uint32_t *) (pcmd)) = rejectError; |
| 4088 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4089 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4090 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4091 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4092 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4093 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4094 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 4095 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4096 | "rpi x%x\n", |
| 4097 | rejectError, elsiocb->iotag, |
| 4098 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 4099 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4100 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4101 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 4102 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 4103 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4105 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4106 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4107 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4108 | if (rc == IOCB_ERROR) { |
| 4109 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4110 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4111 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4112 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4113 | } |
| 4114 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4115 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4116 | * 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] | 4117 | * @vport: pointer to a virtual N_Port data structure. |
| 4118 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4119 | * @ndlp: pointer to a node-list data structure. |
| 4120 | * |
| 4121 | * This routine prepares and issues an Accept (ACC) response to Address |
| 4122 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 4123 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4124 | * |
| 4125 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4126 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4127 | * will be stored into the context1 field of the IOCB for the completion |
| 4128 | * callback function to the ADISC Accept response ELS IOCB command. |
| 4129 | * |
| 4130 | * Return code |
| 4131 | * 0 - Successfully issued acc adisc response |
| 4132 | * 1 - Failed to issue adisc acc response |
| 4133 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4135 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 4136 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4137 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4138 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4139 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4140 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4141 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4142 | uint8_t *pcmd; |
| 4143 | uint16_t cmdsize; |
| 4144 | int rc; |
| 4145 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4146 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4147 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4148 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4149 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4150 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4151 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4152 | icmd = &elsiocb->iocb; |
| 4153 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4154 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4155 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4156 | |
| 4157 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4158 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4159 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 4160 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 4161 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4162 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4163 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4164 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4165 | |
| 4166 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4167 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | |
| 4169 | ap = (ADISC *) (pcmd); |
| 4170 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4171 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4172 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4173 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4174 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4175 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4176 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 4177 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4178 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4179 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4180 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4181 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4182 | if (rc == IOCB_ERROR) { |
| 4183 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4184 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4185 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4186 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4187 | } |
| 4188 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4189 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4190 | * 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] | 4191 | * @vport: pointer to a virtual N_Port data structure. |
| 4192 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4193 | * @ndlp: pointer to a node-list data structure. |
| 4194 | * |
| 4195 | * This routine prepares and issues an Accept (ACC) response to Process |
| 4196 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 4197 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4198 | * |
| 4199 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4200 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4201 | * will be stored into the context1 field of the IOCB for the completion |
| 4202 | * callback function to the PRLI Accept response ELS IOCB command. |
| 4203 | * |
| 4204 | * Return code |
| 4205 | * 0 - Successfully issued acc prli response |
| 4206 | * 1 - Failed to issue acc prli response |
| 4207 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4208 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4209 | 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] | 4210 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4211 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4212 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4213 | PRLI *npr; |
| 4214 | lpfc_vpd_t *vpd; |
| 4215 | IOCB_t *icmd; |
| 4216 | IOCB_t *oldcmd; |
| 4217 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4218 | uint8_t *pcmd; |
| 4219 | uint16_t cmdsize; |
| 4220 | int rc; |
| 4221 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4222 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4223 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4224 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4225 | if (!elsiocb) |
| 4226 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4227 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4228 | icmd = &elsiocb->iocb; |
| 4229 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4230 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4231 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4232 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4233 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4234 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4235 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 4236 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4237 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4238 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4239 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4240 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4241 | |
| 4242 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4243 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4244 | |
| 4245 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4246 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4247 | |
| 4248 | npr = (PRLI *) pcmd; |
| 4249 | vpd = &phba->vpd; |
| 4250 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4251 | * If the remote port is a target and our firmware version is 3.20 or |
| 4252 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4253 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4254 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 4255 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4256 | npr->ConfmComplAllowed = 1; |
| 4257 | npr->Retry = 1; |
| 4258 | npr->TaskRetryIdReq = 1; |
| 4259 | } |
| 4260 | |
| 4261 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 4262 | npr->estabImagePair = 1; |
| 4263 | npr->readXferRdyDis = 1; |
| 4264 | npr->ConfmComplAllowed = 1; |
| 4265 | |
| 4266 | npr->prliType = PRLI_FCP_TYPE; |
| 4267 | npr->initiatorFunc = 1; |
| 4268 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4269 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4270 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 4271 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4272 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4273 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4274 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4275 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4276 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4277 | if (rc == IOCB_ERROR) { |
| 4278 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4279 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4280 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4281 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | } |
| 4283 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4284 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4285 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4286 | * @vport: pointer to a virtual N_Port data structure. |
| 4287 | * @format: rnid command format. |
| 4288 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4289 | * @ndlp: pointer to a node-list data structure. |
| 4290 | * |
| 4291 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 4292 | * (ACC) response. It constructs the RNID ACC response command according to |
| 4293 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 4294 | * issue the response. Note that this command does not need to hold the ndlp |
| 4295 | * reference count for the callback. So, the ndlp reference count taken by |
| 4296 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 4297 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 4298 | * there is no ndlp reference available. |
| 4299 | * |
| 4300 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4301 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4302 | * will be stored into the context1 field of the IOCB for the completion |
| 4303 | * callback function. However, for the RNID Accept Response ELS command, |
| 4304 | * this is undone later by this routine after the IOCB is allocated. |
| 4305 | * |
| 4306 | * Return code |
| 4307 | * 0 - Successfully issued acc rnid response |
| 4308 | * 1 - Failed to issue acc rnid response |
| 4309 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4310 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4311 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4312 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4313 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4314 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4315 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4316 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4317 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4318 | uint8_t *pcmd; |
| 4319 | uint16_t cmdsize; |
| 4320 | int rc; |
| 4321 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4322 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 4323 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4324 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4325 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4326 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4327 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4328 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4329 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4330 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4331 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4332 | icmd = &elsiocb->iocb; |
| 4333 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4334 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4335 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4336 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4337 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4338 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4339 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 4340 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4341 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4342 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4343 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4345 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4346 | rn = (RNID *) (pcmd); |
| 4347 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4348 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 4349 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4350 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4351 | switch (format) { |
| 4352 | case 0: |
| 4353 | rn->SpecificLen = 0; |
| 4354 | break; |
| 4355 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4356 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4357 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4358 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4359 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 4360 | rn->un.topologyDisc.physPort = 0; |
| 4361 | rn->un.topologyDisc.attachedNodes = 0; |
| 4362 | break; |
| 4363 | default: |
| 4364 | rn->CommonLen = 0; |
| 4365 | rn->SpecificLen = 0; |
| 4366 | break; |
| 4367 | } |
| 4368 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4369 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4370 | "Issue ACC RNID: did:x%x flg:x%x", |
| 4371 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4372 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4374 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4375 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4376 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4377 | if (rc == IOCB_ERROR) { |
| 4378 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4379 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4380 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4381 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4382 | } |
| 4383 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4384 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4385 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. |
| 4386 | * @vport: pointer to a virtual N_Port data structure. |
| 4387 | * @iocb: pointer to the lpfc command iocb data structure. |
| 4388 | * @ndlp: pointer to a node-list data structure. |
| 4389 | * |
| 4390 | * Return |
| 4391 | **/ |
| 4392 | static void |
| 4393 | lpfc_els_clear_rrq(struct lpfc_vport *vport, |
| 4394 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
| 4395 | { |
| 4396 | struct lpfc_hba *phba = vport->phba; |
| 4397 | uint8_t *pcmd; |
| 4398 | struct RRQ *rrq; |
| 4399 | uint16_t rxid; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4400 | uint16_t xri; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4401 | struct lpfc_node_rrq *prrq; |
| 4402 | |
| 4403 | |
| 4404 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); |
| 4405 | pcmd += sizeof(uint32_t); |
| 4406 | rrq = (struct RRQ *)pcmd; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4407 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4408 | rxid = bf_get(rrq_rxid, rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4409 | |
| 4410 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4411 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" |
| 4412 | " x%x x%x\n", |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4413 | be32_to_cpu(bf_get(rrq_did, rrq)), |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4414 | bf_get(rrq_oxid, rrq), |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4415 | rxid, |
| 4416 | iocb->iotag, iocb->iocb.ulpContext); |
| 4417 | |
| 4418 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4419 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", |
| 4420 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4421 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4422 | xri = bf_get(rrq_oxid, rrq); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4423 | else |
| 4424 | xri = rxid; |
| 4425 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4426 | if (prrq) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4427 | lpfc_clr_rrq_active(phba, xri, prrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4428 | return; |
| 4429 | } |
| 4430 | |
| 4431 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4432 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 4433 | * @vport: pointer to a virtual N_Port data structure. |
| 4434 | * @data: pointer to echo data to return in the accept. |
| 4435 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4436 | * @ndlp: pointer to a node-list data structure. |
| 4437 | * |
| 4438 | * Return code |
| 4439 | * 0 - Successfully issued acc echo response |
| 4440 | * 1 - Failed to issue acc echo response |
| 4441 | **/ |
| 4442 | static int |
| 4443 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 4444 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 4445 | { |
| 4446 | struct lpfc_hba *phba = vport->phba; |
| 4447 | struct lpfc_iocbq *elsiocb; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4448 | uint8_t *pcmd; |
| 4449 | uint16_t cmdsize; |
| 4450 | int rc; |
| 4451 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4452 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 4453 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4454 | /* The accumulated length can exceed the BPL_SIZE. For |
| 4455 | * now, use this as the limit |
| 4456 | */ |
| 4457 | if (cmdsize > LPFC_BPL_SIZE) |
| 4458 | cmdsize = LPFC_BPL_SIZE; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4459 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4460 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4461 | if (!elsiocb) |
| 4462 | return 1; |
| 4463 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4464 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 4465 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; |
| 4466 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4467 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 4468 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4469 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 4470 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 4471 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4472 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4473 | pcmd += sizeof(uint32_t); |
| 4474 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 4475 | |
| 4476 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4477 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 4478 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4479 | |
| 4480 | phba->fc_stat.elsXmitACC++; |
| 4481 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4482 | |
| 4483 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4484 | if (rc == IOCB_ERROR) { |
| 4485 | lpfc_els_free_iocb(phba, elsiocb); |
| 4486 | return 1; |
| 4487 | } |
| 4488 | return 0; |
| 4489 | } |
| 4490 | |
| 4491 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4492 | * 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] | 4493 | * @vport: pointer to a host virtual N_Port data structure. |
| 4494 | * |
| 4495 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 4496 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 4497 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 4498 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 4499 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 4500 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 4501 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 4502 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 4503 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 4504 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 4505 | * no more ADISC need to be sent. |
| 4506 | * |
| 4507 | * Return code |
| 4508 | * The number of N_Ports with adisc issued. |
| 4509 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4510 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4511 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4512 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4513 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4514 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4515 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4516 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4517 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4518 | 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] | 4519 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4520 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4521 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4522 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4523 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4524 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4525 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4526 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4527 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4528 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4529 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4530 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4531 | vport->num_disc_nodes++; |
| 4532 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4533 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4534 | spin_lock_irq(shost->host_lock); |
| 4535 | vport->fc_flag |= FC_NLP_MORE; |
| 4536 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4537 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4538 | } |
| 4539 | } |
| 4540 | } |
| 4541 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4542 | spin_lock_irq(shost->host_lock); |
| 4543 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4544 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4545 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4546 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4547 | } |
| 4548 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4549 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4550 | * 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] | 4551 | * @vport: pointer to a host virtual N_Port data structure. |
| 4552 | * |
| 4553 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4554 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4555 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4556 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4557 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4558 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4559 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4560 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4561 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4562 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4563 | * PLOGI need to be sent. |
| 4564 | * |
| 4565 | * Return code |
| 4566 | * The number of N_Ports with plogi issued. |
| 4567 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4568 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4569 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4570 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4571 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4572 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4573 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4574 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4575 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4576 | 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] | 4577 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4578 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4579 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4580 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4581 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4582 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4583 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4584 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4585 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4586 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4587 | vport->num_disc_nodes++; |
| 4588 | if (vport->num_disc_nodes >= |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4589 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4590 | spin_lock_irq(shost->host_lock); |
| 4591 | vport->fc_flag |= FC_NLP_MORE; |
| 4592 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4593 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4594 | } |
| 4595 | } |
| 4596 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4597 | if (sentplogi) { |
| 4598 | lpfc_set_disctmo(vport); |
| 4599 | } |
| 4600 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4601 | spin_lock_irq(shost->host_lock); |
| 4602 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4603 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4604 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4605 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4606 | } |
| 4607 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4608 | void |
| 4609 | lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc, |
| 4610 | uint32_t word0) |
| 4611 | { |
| 4612 | |
| 4613 | desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG); |
| 4614 | desc->payload.els_req = word0; |
| 4615 | desc->length = cpu_to_be32(sizeof(desc->payload)); |
| 4616 | } |
| 4617 | |
| 4618 | void |
| 4619 | lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc, |
| 4620 | uint8_t *page_a0, uint8_t *page_a2) |
| 4621 | { |
| 4622 | uint16_t wavelength; |
| 4623 | uint16_t temperature; |
| 4624 | uint16_t rx_power; |
| 4625 | uint16_t tx_bias; |
| 4626 | uint16_t tx_power; |
| 4627 | uint16_t vcc; |
| 4628 | uint16_t flag = 0; |
| 4629 | struct sff_trasnceiver_codes_byte4 *trasn_code_byte4; |
| 4630 | struct sff_trasnceiver_codes_byte5 *trasn_code_byte5; |
| 4631 | |
| 4632 | desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG); |
| 4633 | |
| 4634 | trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *) |
| 4635 | &page_a0[SSF_TRANSCEIVER_CODE_B4]; |
| 4636 | trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *) |
| 4637 | &page_a0[SSF_TRANSCEIVER_CODE_B5]; |
| 4638 | |
| 4639 | if ((trasn_code_byte4->fc_sw_laser) || |
| 4640 | (trasn_code_byte5->fc_sw_laser_sl) || |
| 4641 | (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */ |
| 4642 | flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT); |
| 4643 | } else if (trasn_code_byte4->fc_lw_laser) { |
| 4644 | wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) | |
| 4645 | page_a0[SSF_WAVELENGTH_B0]; |
| 4646 | if (wavelength == SFP_WAVELENGTH_LC1310) |
| 4647 | flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT; |
| 4648 | if (wavelength == SFP_WAVELENGTH_LL1550) |
| 4649 | flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT; |
| 4650 | } |
| 4651 | /* check if its SFP+ */ |
| 4652 | flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ? |
| 4653 | SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN) |
| 4654 | << SFP_FLAG_CT_SHIFT; |
| 4655 | |
| 4656 | /* check if its OPTICAL */ |
| 4657 | flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ? |
| 4658 | SFP_FLAG_IS_OPTICAL_PORT : 0) |
| 4659 | << SFP_FLAG_IS_OPTICAL_SHIFT; |
| 4660 | |
| 4661 | temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 | |
| 4662 | page_a2[SFF_TEMPERATURE_B0]); |
| 4663 | vcc = (page_a2[SFF_VCC_B1] << 8 | |
| 4664 | page_a2[SFF_VCC_B0]); |
| 4665 | tx_power = (page_a2[SFF_TXPOWER_B1] << 8 | |
| 4666 | page_a2[SFF_TXPOWER_B0]); |
| 4667 | tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 | |
| 4668 | page_a2[SFF_TX_BIAS_CURRENT_B0]); |
| 4669 | rx_power = (page_a2[SFF_RXPOWER_B1] << 8 | |
| 4670 | page_a2[SFF_RXPOWER_B0]); |
| 4671 | desc->sfp_info.temperature = cpu_to_be16(temperature); |
| 4672 | desc->sfp_info.rx_power = cpu_to_be16(rx_power); |
| 4673 | desc->sfp_info.tx_bias = cpu_to_be16(tx_bias); |
| 4674 | desc->sfp_info.tx_power = cpu_to_be16(tx_power); |
| 4675 | desc->sfp_info.vcc = cpu_to_be16(vcc); |
| 4676 | |
| 4677 | desc->sfp_info.flags = cpu_to_be16(flag); |
| 4678 | desc->length = cpu_to_be32(sizeof(desc->sfp_info)); |
| 4679 | } |
| 4680 | |
| 4681 | void |
| 4682 | lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc, |
| 4683 | READ_LNK_VAR *stat) |
| 4684 | { |
| 4685 | uint32_t type; |
| 4686 | |
| 4687 | desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG); |
| 4688 | |
| 4689 | type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT; |
| 4690 | |
| 4691 | desc->info.port_type = cpu_to_be32(type); |
| 4692 | |
| 4693 | desc->info.link_status.link_failure_cnt = |
| 4694 | cpu_to_be32(stat->linkFailureCnt); |
| 4695 | desc->info.link_status.loss_of_synch_cnt = |
| 4696 | cpu_to_be32(stat->lossSyncCnt); |
| 4697 | desc->info.link_status.loss_of_signal_cnt = |
| 4698 | cpu_to_be32(stat->lossSignalCnt); |
| 4699 | desc->info.link_status.primitive_seq_proto_err = |
| 4700 | cpu_to_be32(stat->primSeqErrCnt); |
| 4701 | desc->info.link_status.invalid_trans_word = |
| 4702 | cpu_to_be32(stat->invalidXmitWord); |
| 4703 | desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt); |
| 4704 | |
| 4705 | desc->length = cpu_to_be32(sizeof(desc->info)); |
| 4706 | } |
| 4707 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 4708 | int |
| 4709 | lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat) |
| 4710 | { |
| 4711 | if (bf_get(lpfc_read_link_stat_gec2, stat) == 0) |
| 4712 | return 0; |
| 4713 | desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG); |
| 4714 | |
| 4715 | desc->info.CorrectedBlocks = |
| 4716 | cpu_to_be32(stat->fecCorrBlkCount); |
| 4717 | desc->info.UncorrectableBlocks = |
| 4718 | cpu_to_be32(stat->fecUncorrBlkCount); |
| 4719 | |
| 4720 | desc->length = cpu_to_be32(sizeof(desc->info)); |
| 4721 | |
| 4722 | return sizeof(struct fc_fec_rdp_desc); |
| 4723 | } |
| 4724 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4725 | void |
| 4726 | lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba) |
| 4727 | { |
| 4728 | uint16_t rdp_cap = 0; |
| 4729 | uint16_t rdp_speed; |
| 4730 | |
| 4731 | desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG); |
| 4732 | |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4733 | switch (phba->fc_linkspeed) { |
| 4734 | case LPFC_LINK_SPEED_1GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4735 | rdp_speed = RDP_PS_1GB; |
| 4736 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4737 | case LPFC_LINK_SPEED_2GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4738 | rdp_speed = RDP_PS_2GB; |
| 4739 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4740 | case LPFC_LINK_SPEED_4GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4741 | rdp_speed = RDP_PS_4GB; |
| 4742 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4743 | case LPFC_LINK_SPEED_8GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4744 | rdp_speed = RDP_PS_8GB; |
| 4745 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4746 | case LPFC_LINK_SPEED_10GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4747 | rdp_speed = RDP_PS_10GB; |
| 4748 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 4749 | case LPFC_LINK_SPEED_16GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4750 | rdp_speed = RDP_PS_16GB; |
| 4751 | break; |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4752 | case LPFC_LINK_SPEED_32GHZ: |
| 4753 | rdp_speed = RDP_PS_32GB; |
| 4754 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4755 | default: |
| 4756 | rdp_speed = RDP_PS_UNKNOWN; |
| 4757 | break; |
| 4758 | } |
| 4759 | |
| 4760 | desc->info.port_speed.speed = cpu_to_be16(rdp_speed); |
| 4761 | |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4762 | if (phba->lmt & LMT_32Gb) |
| 4763 | rdp_cap |= RDP_PS_32GB; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4764 | if (phba->lmt & LMT_16Gb) |
| 4765 | rdp_cap |= RDP_PS_16GB; |
| 4766 | if (phba->lmt & LMT_10Gb) |
| 4767 | rdp_cap |= RDP_PS_10GB; |
| 4768 | if (phba->lmt & LMT_8Gb) |
| 4769 | rdp_cap |= RDP_PS_8GB; |
| 4770 | if (phba->lmt & LMT_4Gb) |
| 4771 | rdp_cap |= RDP_PS_4GB; |
| 4772 | if (phba->lmt & LMT_2Gb) |
| 4773 | rdp_cap |= RDP_PS_2GB; |
| 4774 | if (phba->lmt & LMT_1Gb) |
| 4775 | rdp_cap |= RDP_PS_1GB; |
| 4776 | |
| 4777 | if (rdp_cap == 0) |
| 4778 | rdp_cap = RDP_CAP_UNKNOWN; |
| 4779 | |
| 4780 | desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap); |
| 4781 | desc->length = cpu_to_be32(sizeof(desc->info)); |
| 4782 | } |
| 4783 | |
| 4784 | void |
| 4785 | lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc, |
| 4786 | struct lpfc_hba *phba) |
| 4787 | { |
| 4788 | |
| 4789 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 4790 | |
| 4791 | memcpy(desc->port_names.wwnn, phba->wwnn, |
| 4792 | sizeof(desc->port_names.wwnn)); |
| 4793 | |
| 4794 | memcpy(desc->port_names.wwpn, &phba->wwpn, |
| 4795 | sizeof(desc->port_names.wwpn)); |
| 4796 | |
| 4797 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
| 4798 | } |
| 4799 | |
| 4800 | void |
| 4801 | lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc, |
| 4802 | struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4803 | { |
| 4804 | |
| 4805 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 4806 | if (vport->fc_flag & FC_FABRIC) { |
| 4807 | memcpy(desc->port_names.wwnn, &vport->fabric_nodename, |
| 4808 | sizeof(desc->port_names.wwnn)); |
| 4809 | |
| 4810 | memcpy(desc->port_names.wwpn, &vport->fabric_portname, |
| 4811 | sizeof(desc->port_names.wwpn)); |
| 4812 | } else { /* Point to Point */ |
| 4813 | memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename, |
| 4814 | sizeof(desc->port_names.wwnn)); |
| 4815 | |
| 4816 | memcpy(desc->port_names.wwnn, &ndlp->nlp_portname, |
| 4817 | sizeof(desc->port_names.wwpn)); |
| 4818 | } |
| 4819 | |
| 4820 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
| 4821 | } |
| 4822 | |
| 4823 | void |
| 4824 | lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context, |
| 4825 | int status) |
| 4826 | { |
| 4827 | struct lpfc_nodelist *ndlp = rdp_context->ndlp; |
| 4828 | struct lpfc_vport *vport = ndlp->vport; |
| 4829 | struct lpfc_iocbq *elsiocb; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 4830 | struct ulp_bde64 *bpl; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4831 | IOCB_t *icmd; |
| 4832 | uint8_t *pcmd; |
| 4833 | struct ls_rjt *stat; |
| 4834 | struct fc_rdp_res_frame *rdp_res; |
| 4835 | uint32_t cmdsize; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 4836 | int rc, fec_size; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4837 | |
| 4838 | if (status != SUCCESS) |
| 4839 | goto error; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 4840 | |
| 4841 | /* 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] | 4842 | cmdsize = sizeof(struct fc_rdp_res_frame); |
| 4843 | |
| 4844 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, |
| 4845 | lpfc_max_els_tries, rdp_context->ndlp, |
| 4846 | rdp_context->ndlp->nlp_DID, ELS_CMD_ACC); |
| 4847 | lpfc_nlp_put(ndlp); |
| 4848 | if (!elsiocb) |
| 4849 | goto free_rdp_context; |
| 4850 | |
| 4851 | icmd = &elsiocb->iocb; |
| 4852 | icmd->ulpContext = rdp_context->rx_id; |
| 4853 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 4854 | |
| 4855 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4856 | "2171 Xmit RDP response tag x%x xri x%x, " |
| 4857 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x", |
| 4858 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4859 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4860 | ndlp->nlp_rpi); |
| 4861 | rdp_res = (struct fc_rdp_res_frame *) |
| 4862 | (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4863 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4864 | memset(pcmd, 0, sizeof(struct fc_rdp_res_frame)); |
| 4865 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4866 | |
| 4867 | /* For RDP payload */ |
| 4868 | lpfc_rdp_res_link_service(&rdp_res->link_service_desc, ELS_CMD_RDP); |
| 4869 | |
| 4870 | lpfc_rdp_res_sfp_desc(&rdp_res->sfp_desc, |
| 4871 | rdp_context->page_a0, rdp_context->page_a2); |
| 4872 | lpfc_rdp_res_speed(&rdp_res->portspeed_desc, phba); |
| 4873 | lpfc_rdp_res_link_error(&rdp_res->link_error_desc, |
| 4874 | &rdp_context->link_stat); |
| 4875 | lpfc_rdp_res_diag_port_names(&rdp_res->diag_port_names_desc, phba); |
| 4876 | lpfc_rdp_res_attach_port_names(&rdp_res->attached_port_names_desc, |
| 4877 | vport, ndlp); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 4878 | fec_size = lpfc_rdp_res_fec_desc(&rdp_res->fec_desc, |
| 4879 | &rdp_context->link_stat); |
| 4880 | rdp_res->length = cpu_to_be32(fec_size + RDP_DESC_PAYLOAD_SIZE); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4881 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 4882 | |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 4883 | /* Now that we know the true size of the payload, update the BPL */ |
| 4884 | bpl = (struct ulp_bde64 *) |
| 4885 | (((struct lpfc_dmabuf *)(elsiocb->context3))->virt); |
| 4886 | bpl->tus.f.bdeSize = (fec_size + RDP_DESC_PAYLOAD_SIZE + 8); |
| 4887 | bpl->tus.f.bdeFlags = 0; |
| 4888 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 4889 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4890 | phba->fc_stat.elsXmitACC++; |
| 4891 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4892 | if (rc == IOCB_ERROR) |
| 4893 | lpfc_els_free_iocb(phba, elsiocb); |
| 4894 | |
| 4895 | kfree(rdp_context); |
| 4896 | |
| 4897 | return; |
| 4898 | error: |
| 4899 | cmdsize = 2 * sizeof(uint32_t); |
| 4900 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries, |
| 4901 | ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 4902 | lpfc_nlp_put(ndlp); |
| 4903 | if (!elsiocb) |
| 4904 | goto free_rdp_context; |
| 4905 | |
| 4906 | icmd = &elsiocb->iocb; |
| 4907 | icmd->ulpContext = rdp_context->rx_id; |
| 4908 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 4909 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4910 | |
| 4911 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
| 4912 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 4913 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4914 | |
| 4915 | phba->fc_stat.elsXmitLSRJT++; |
| 4916 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 4917 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4918 | |
| 4919 | if (rc == IOCB_ERROR) |
| 4920 | lpfc_els_free_iocb(phba, elsiocb); |
| 4921 | free_rdp_context: |
| 4922 | kfree(rdp_context); |
| 4923 | } |
| 4924 | |
| 4925 | int |
| 4926 | lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) |
| 4927 | { |
| 4928 | LPFC_MBOXQ_t *mbox = NULL; |
| 4929 | int rc; |
| 4930 | |
| 4931 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4932 | if (!mbox) { |
| 4933 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, |
| 4934 | "7105 failed to allocate mailbox memory"); |
| 4935 | return 1; |
| 4936 | } |
| 4937 | |
| 4938 | if (lpfc_sli4_dump_page_a0(phba, mbox)) |
| 4939 | goto prep_mbox_fail; |
| 4940 | mbox->vport = rdp_context->ndlp->vport; |
| 4941 | mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; |
| 4942 | mbox->context2 = (struct lpfc_rdp_context *) rdp_context; |
| 4943 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 4944 | if (rc == MBX_NOT_FINISHED) |
| 4945 | goto issue_mbox_fail; |
| 4946 | |
| 4947 | return 0; |
| 4948 | |
| 4949 | prep_mbox_fail: |
| 4950 | issue_mbox_fail: |
| 4951 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4952 | return 1; |
| 4953 | } |
| 4954 | |
| 4955 | /* |
| 4956 | * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS. |
| 4957 | * @vport: pointer to a host virtual N_Port data structure. |
| 4958 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4959 | * @ndlp: pointer to a node-list data structure. |
| 4960 | * |
| 4961 | * This routine processes an unsolicited RDP(Read Diagnostic Parameters) |
| 4962 | * IOCB. First, the payload of the unsolicited RDP is checked. |
| 4963 | * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3 |
| 4964 | * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2, |
| 4965 | * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl |
| 4966 | * gather all data and send RDP response. |
| 4967 | * |
| 4968 | * Return code |
| 4969 | * 0 - Sent the acc response |
| 4970 | * 1 - Sent the reject response. |
| 4971 | */ |
| 4972 | static int |
| 4973 | lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4974 | struct lpfc_nodelist *ndlp) |
| 4975 | { |
| 4976 | struct lpfc_hba *phba = vport->phba; |
| 4977 | struct lpfc_dmabuf *pcmd; |
| 4978 | uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE; |
| 4979 | struct fc_rdp_req_frame *rdp_req; |
| 4980 | struct lpfc_rdp_context *rdp_context; |
| 4981 | IOCB_t *cmd = NULL; |
| 4982 | struct ls_rjt stat; |
| 4983 | |
| 4984 | if (phba->sli_rev < LPFC_SLI_REV4 || |
| 4985 | (bf_get(lpfc_sli_intf_if_type, |
| 4986 | &phba->sli4_hba.sli_intf) != |
| 4987 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 4988 | rjt_err = LSRJT_UNABLE_TPC; |
| 4989 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 4990 | goto error; |
| 4991 | } |
| 4992 | |
| 4993 | if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) { |
| 4994 | rjt_err = LSRJT_UNABLE_TPC; |
| 4995 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 4996 | goto error; |
| 4997 | } |
| 4998 | |
| 4999 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5000 | rdp_req = (struct fc_rdp_req_frame *) pcmd->virt; |
| 5001 | |
| 5002 | |
| 5003 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5004 | "2422 ELS RDP Request " |
| 5005 | "dec len %d tag x%x port_id %d len %d\n", |
| 5006 | be32_to_cpu(rdp_req->rdp_des_length), |
| 5007 | be32_to_cpu(rdp_req->nport_id_desc.tag), |
| 5008 | be32_to_cpu(rdp_req->nport_id_desc.nport_id), |
| 5009 | be32_to_cpu(rdp_req->nport_id_desc.length)); |
| 5010 | |
| 5011 | if (sizeof(struct fc_rdp_nport_desc) != |
| 5012 | be32_to_cpu(rdp_req->rdp_des_length)) |
| 5013 | goto rjt_logerr; |
| 5014 | if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag)) |
| 5015 | goto rjt_logerr; |
| 5016 | if (RDP_NPORT_ID_SIZE != |
| 5017 | be32_to_cpu(rdp_req->nport_id_desc.length)) |
| 5018 | goto rjt_logerr; |
Punit Vara | 699acd6 | 2015-12-16 18:12:07 -0500 | [diff] [blame^] | 5019 | rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5020 | if (!rdp_context) { |
| 5021 | rjt_err = LSRJT_UNABLE_TPC; |
| 5022 | goto error; |
| 5023 | } |
| 5024 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5025 | cmd = &cmdiocb->iocb; |
| 5026 | rdp_context->ndlp = lpfc_nlp_get(ndlp); |
| 5027 | rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id; |
| 5028 | rdp_context->rx_id = cmd->ulpContext; |
| 5029 | rdp_context->cmpl = lpfc_els_rdp_cmpl; |
| 5030 | if (lpfc_get_rdp_info(phba, rdp_context)) { |
| 5031 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS, |
| 5032 | "2423 Unable to send mailbox"); |
| 5033 | kfree(rdp_context); |
| 5034 | rjt_err = LSRJT_UNABLE_TPC; |
| 5035 | lpfc_nlp_put(ndlp); |
| 5036 | goto error; |
| 5037 | } |
| 5038 | |
| 5039 | return 0; |
| 5040 | |
| 5041 | rjt_logerr: |
| 5042 | rjt_err = LSRJT_LOGICAL_ERR; |
| 5043 | |
| 5044 | error: |
| 5045 | memset(&stat, 0, sizeof(stat)); |
| 5046 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 5047 | stat.un.b.lsRjtRsnCodeExp = rjt_expl; |
| 5048 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5049 | return 1; |
| 5050 | } |
| 5051 | |
| 5052 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5053 | static void |
| 5054 | lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5055 | { |
| 5056 | MAILBOX_t *mb; |
| 5057 | IOCB_t *icmd; |
| 5058 | uint8_t *pcmd; |
| 5059 | struct lpfc_iocbq *elsiocb; |
| 5060 | struct lpfc_nodelist *ndlp; |
| 5061 | struct ls_rjt *stat; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5062 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5063 | struct lpfc_lcb_context *lcb_context; |
| 5064 | struct fc_lcb_res_frame *lcb_res; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5065 | uint32_t cmdsize, shdr_status, shdr_add_status; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5066 | int rc; |
| 5067 | |
| 5068 | mb = &pmb->u.mb; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5069 | lcb_context = (struct lpfc_lcb_context *)pmb->context1; |
| 5070 | ndlp = lcb_context->ndlp; |
| 5071 | pmb->context1 = NULL; |
| 5072 | pmb->context2 = NULL; |
| 5073 | |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5074 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 5075 | &pmb->u.mqe.un.beacon_config.header.cfg_shdr; |
| 5076 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5077 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5078 | |
| 5079 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX, |
| 5080 | "0194 SET_BEACON_CONFIG mailbox " |
| 5081 | "completed with status x%x add_status x%x," |
| 5082 | " mbx status x%x\n", |
| 5083 | shdr_status, shdr_add_status, mb->mbxStatus); |
| 5084 | |
| 5085 | if (mb->mbxStatus && !(shdr_status && |
| 5086 | shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5087 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5088 | goto error; |
| 5089 | } |
| 5090 | |
| 5091 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5092 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 5093 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5094 | lpfc_max_els_tries, ndlp, |
| 5095 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5096 | |
| 5097 | /* Decrement the ndlp reference count from previous mbox command */ |
| 5098 | lpfc_nlp_put(ndlp); |
| 5099 | |
| 5100 | if (!elsiocb) |
| 5101 | goto free_lcb_context; |
| 5102 | |
| 5103 | lcb_res = (struct fc_lcb_res_frame *) |
| 5104 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5105 | |
| 5106 | icmd = &elsiocb->iocb; |
| 5107 | icmd->ulpContext = lcb_context->rx_id; |
| 5108 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 5109 | |
| 5110 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5111 | *((uint32_t *)(pcmd)) = ELS_CMD_ACC; |
| 5112 | lcb_res->lcb_sub_command = lcb_context->sub_command; |
| 5113 | lcb_res->lcb_type = lcb_context->type; |
| 5114 | lcb_res->lcb_frequency = lcb_context->frequency; |
| 5115 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5116 | phba->fc_stat.elsXmitACC++; |
| 5117 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5118 | if (rc == IOCB_ERROR) |
| 5119 | lpfc_els_free_iocb(phba, elsiocb); |
| 5120 | |
| 5121 | kfree(lcb_context); |
| 5122 | return; |
| 5123 | |
| 5124 | error: |
| 5125 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 5126 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5127 | lpfc_max_els_tries, ndlp, |
| 5128 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 5129 | lpfc_nlp_put(ndlp); |
| 5130 | if (!elsiocb) |
| 5131 | goto free_lcb_context; |
| 5132 | |
| 5133 | icmd = &elsiocb->iocb; |
| 5134 | icmd->ulpContext = lcb_context->rx_id; |
| 5135 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 5136 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5137 | |
| 5138 | *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT; |
| 5139 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 5140 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5141 | |
| 5142 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5143 | phba->fc_stat.elsXmitLSRJT++; |
| 5144 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5145 | if (rc == IOCB_ERROR) |
| 5146 | lpfc_els_free_iocb(phba, elsiocb); |
| 5147 | free_lcb_context: |
| 5148 | kfree(lcb_context); |
| 5149 | } |
| 5150 | |
| 5151 | static int |
| 5152 | lpfc_sli4_set_beacon(struct lpfc_vport *vport, |
| 5153 | struct lpfc_lcb_context *lcb_context, |
| 5154 | uint32_t beacon_state) |
| 5155 | { |
| 5156 | struct lpfc_hba *phba = vport->phba; |
| 5157 | LPFC_MBOXQ_t *mbox = NULL; |
| 5158 | uint32_t len; |
| 5159 | int rc; |
| 5160 | |
| 5161 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5162 | if (!mbox) |
| 5163 | return 1; |
| 5164 | |
| 5165 | len = sizeof(struct lpfc_mbx_set_beacon_config) - |
| 5166 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 5167 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5168 | LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len, |
| 5169 | LPFC_SLI4_MBX_EMBED); |
| 5170 | mbox->context1 = (void *)lcb_context; |
| 5171 | mbox->vport = phba->pport; |
| 5172 | mbox->mbox_cmpl = lpfc_els_lcb_rsp; |
| 5173 | bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config, |
| 5174 | phba->sli4_hba.physical_port); |
| 5175 | bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config, |
| 5176 | beacon_state); |
| 5177 | bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1); |
| 5178 | bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0); |
| 5179 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5180 | if (rc == MBX_NOT_FINISHED) { |
| 5181 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5182 | return 1; |
| 5183 | } |
| 5184 | |
| 5185 | return 0; |
| 5186 | } |
| 5187 | |
| 5188 | |
| 5189 | /** |
| 5190 | * lpfc_els_rcv_lcb - Process an unsolicited LCB |
| 5191 | * @vport: pointer to a host virtual N_Port data structure. |
| 5192 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5193 | * @ndlp: pointer to a node-list data structure. |
| 5194 | * |
| 5195 | * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB. |
| 5196 | * First, the payload of the unsolicited LCB is checked. |
| 5197 | * Then based on Subcommand beacon will either turn on or off. |
| 5198 | * |
| 5199 | * Return code |
| 5200 | * 0 - Sent the acc response |
| 5201 | * 1 - Sent the reject response. |
| 5202 | **/ |
| 5203 | static int |
| 5204 | lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5205 | struct lpfc_nodelist *ndlp) |
| 5206 | { |
| 5207 | struct lpfc_hba *phba = vport->phba; |
| 5208 | struct lpfc_dmabuf *pcmd; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5209 | uint8_t *lp; |
| 5210 | struct fc_lcb_request_frame *beacon; |
| 5211 | struct lpfc_lcb_context *lcb_context; |
| 5212 | uint8_t state, rjt_err; |
| 5213 | struct ls_rjt stat; |
| 5214 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5215 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 5216 | lp = (uint8_t *)pcmd->virt; |
| 5217 | beacon = (struct fc_lcb_request_frame *)pcmd->virt; |
| 5218 | |
| 5219 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5220 | "0192 ELS LCB Data x%x x%x x%x x%x sub x%x " |
| 5221 | "type x%x frequency %x duration x%x\n", |
| 5222 | lp[0], lp[1], lp[2], |
| 5223 | beacon->lcb_command, |
| 5224 | beacon->lcb_sub_command, |
| 5225 | beacon->lcb_type, |
| 5226 | beacon->lcb_frequency, |
| 5227 | be16_to_cpu(beacon->lcb_duration)); |
| 5228 | |
| 5229 | if (phba->sli_rev < LPFC_SLI_REV4 || |
| 5230 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 5231 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 5232 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5233 | goto rjt; |
| 5234 | } |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5235 | |
| 5236 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 5237 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5238 | goto rjt; |
| 5239 | } |
| 5240 | if (beacon->lcb_frequency == 0) { |
| 5241 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5242 | goto rjt; |
| 5243 | } |
| 5244 | if ((beacon->lcb_type != LPFC_LCB_GREEN) && |
| 5245 | (beacon->lcb_type != LPFC_LCB_AMBER)) { |
| 5246 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5247 | goto rjt; |
| 5248 | } |
| 5249 | if ((beacon->lcb_sub_command != LPFC_LCB_ON) && |
| 5250 | (beacon->lcb_sub_command != LPFC_LCB_OFF)) { |
| 5251 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5252 | goto rjt; |
| 5253 | } |
| 5254 | if ((beacon->lcb_sub_command == LPFC_LCB_ON) && |
| 5255 | (beacon->lcb_type != LPFC_LCB_GREEN) && |
| 5256 | (beacon->lcb_type != LPFC_LCB_AMBER)) { |
| 5257 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5258 | goto rjt; |
| 5259 | } |
| 5260 | if (be16_to_cpu(beacon->lcb_duration) != 0) { |
| 5261 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5262 | goto rjt; |
| 5263 | } |
| 5264 | |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 5265 | lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL); |
| 5266 | if (!lcb_context) { |
| 5267 | rjt_err = LSRJT_UNABLE_TPC; |
| 5268 | goto rjt; |
| 5269 | } |
| 5270 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5271 | state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; |
| 5272 | lcb_context->sub_command = beacon->lcb_sub_command; |
| 5273 | lcb_context->type = beacon->lcb_type; |
| 5274 | lcb_context->frequency = beacon->lcb_frequency; |
| 5275 | lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
| 5276 | lcb_context->rx_id = cmdiocb->iocb.ulpContext; |
| 5277 | lcb_context->ndlp = lpfc_nlp_get(ndlp); |
| 5278 | if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { |
| 5279 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 5280 | LOG_ELS, "0193 failed to send mail box"); |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 5281 | kfree(lcb_context); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5282 | lpfc_nlp_put(ndlp); |
| 5283 | rjt_err = LSRJT_UNABLE_TPC; |
| 5284 | goto rjt; |
| 5285 | } |
| 5286 | return 0; |
| 5287 | rjt: |
| 5288 | memset(&stat, 0, sizeof(stat)); |
| 5289 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 5290 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5291 | return 1; |
| 5292 | } |
| 5293 | |
| 5294 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5295 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5296 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5297 | * @vport: pointer to a host virtual N_Port data structure. |
| 5298 | * |
| 5299 | * This routine cleans up any Registration State Change Notification |
| 5300 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 5301 | * @vport together with the host_lock is used to prevent multiple thread |
| 5302 | * trying to access the RSCN array on a same @vport at the same time. |
| 5303 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5304 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5305 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5306 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5307 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5308 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5309 | int i; |
| 5310 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5311 | spin_lock_irq(shost->host_lock); |
| 5312 | if (vport->fc_rscn_flush) { |
| 5313 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 5314 | spin_unlock_irq(shost->host_lock); |
| 5315 | return; |
| 5316 | } |
| 5317 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 5318 | vport->fc_rscn_flush = 1; |
| 5319 | spin_unlock_irq(shost->host_lock); |
| 5320 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5321 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5322 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5323 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5324 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5325 | spin_lock_irq(shost->host_lock); |
| 5326 | vport->fc_rscn_id_cnt = 0; |
| 5327 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 5328 | spin_unlock_irq(shost->host_lock); |
| 5329 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5330 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 5331 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5332 | } |
| 5333 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5334 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5335 | * 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] | 5336 | * @vport: pointer to a host virtual N_Port data structure. |
| 5337 | * @did: remote destination port identifier. |
| 5338 | * |
| 5339 | * This routine checks whether there is any pending Registration State |
| 5340 | * Configuration Notification (RSCN) to a @did on @vport. |
| 5341 | * |
| 5342 | * Return code |
| 5343 | * None zero - The @did matched with a pending rscn |
| 5344 | * 0 - not able to match @did with a pending rscn |
| 5345 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5346 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5347 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5348 | { |
| 5349 | D_ID ns_did; |
| 5350 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5351 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5352 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5353 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5354 | |
| 5355 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5356 | |
| 5357 | /* Never match fabric nodes for RSCNs */ |
| 5358 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5359 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5360 | |
| 5361 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5362 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5363 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5364 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5365 | spin_lock_irq(shost->host_lock); |
| 5366 | if (vport->fc_rscn_flush) { |
| 5367 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 5368 | spin_unlock_irq(shost->host_lock); |
| 5369 | return 0; |
| 5370 | } |
| 5371 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 5372 | vport->fc_rscn_flush = 1; |
| 5373 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5374 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5375 | lp = vport->fc_rscn_id_list[i]->virt; |
| 5376 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 5377 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5378 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5379 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 5380 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5381 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 5382 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5383 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 5384 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 5385 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5386 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5387 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5388 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5389 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 5390 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5391 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5392 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5393 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5394 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5395 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5396 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5397 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5398 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5399 | } |
| 5400 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5401 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5402 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 5403 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5404 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5405 | return_did_out: |
| 5406 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 5407 | vport->fc_rscn_flush = 0; |
| 5408 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5409 | } |
| 5410 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5411 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5412 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5413 | * @vport: pointer to a host virtual N_Port data structure. |
| 5414 | * |
| 5415 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 5416 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 5417 | * State Change Notification). |
| 5418 | * |
| 5419 | * Return code |
| 5420 | * 0 - Successful (currently alway return 0) |
| 5421 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5422 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5423 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5424 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5425 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5426 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5427 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5428 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5429 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5430 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 5431 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5432 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5433 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5434 | NLP_EVT_DEVICE_RECOVERY); |
| 5435 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5436 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5437 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5438 | } |
| 5439 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5440 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5441 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5442 | * @vport: pointer to a host virtual N_Port data structure. |
| 5443 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5444 | * |
| 5445 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 5446 | * applications. |
| 5447 | */ |
| 5448 | static void |
| 5449 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 5450 | struct lpfc_iocbq *cmdiocb) |
| 5451 | { |
| 5452 | struct lpfc_dmabuf *pcmd; |
| 5453 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5454 | uint32_t *payload_ptr; |
| 5455 | uint32_t payload_len; |
| 5456 | struct lpfc_rscn_event_header *rscn_event_data; |
| 5457 | |
| 5458 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5459 | payload_ptr = (uint32_t *) pcmd->virt; |
| 5460 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 5461 | |
| 5462 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 5463 | payload_len, GFP_KERNEL); |
| 5464 | if (!rscn_event_data) { |
| 5465 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5466 | "0147 Failed to allocate memory for RSCN event\n"); |
| 5467 | return; |
| 5468 | } |
| 5469 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 5470 | rscn_event_data->payload_length = payload_len; |
| 5471 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 5472 | payload_len); |
| 5473 | |
| 5474 | fc_host_post_vendor_event(shost, |
| 5475 | fc_get_event_number(), |
Ales Novak | 6599eaa | 2015-08-31 16:48:16 -0400 | [diff] [blame] | 5476 | sizeof(struct lpfc_rscn_event_header) + payload_len, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5477 | (char *)rscn_event_data, |
| 5478 | LPFC_NL_VENDOR_ID); |
| 5479 | |
| 5480 | kfree(rscn_event_data); |
| 5481 | } |
| 5482 | |
| 5483 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5484 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5485 | * @vport: pointer to a host virtual N_Port data structure. |
| 5486 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5487 | * @ndlp: pointer to a node-list data structure. |
| 5488 | * |
| 5489 | * This routine processes an unsolicited RSCN (Registration State Change |
| 5490 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 5491 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 5492 | * discover state machine is about to begin discovery, it just accepts the |
| 5493 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 5494 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 5495 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 5496 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 5497 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 5498 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 5499 | * routine is invoked to handle the RSCN event. |
| 5500 | * |
| 5501 | * Return code |
| 5502 | * 0 - Just sent the acc response |
| 5503 | * 1 - Sent the acc response and waited for name server completion |
| 5504 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5505 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5506 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5507 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5508 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5509 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5510 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5511 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5512 | uint32_t *lp, *datap; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5513 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5514 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5515 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5516 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5517 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5518 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5519 | lp = (uint32_t *) pcmd->virt; |
| 5520 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5521 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 5522 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5523 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5524 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5525 | "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] | 5526 | vport->fc_flag, payload_len, *lp, |
| 5527 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5528 | |
| 5529 | /* Send an RSCN event to the management application */ |
| 5530 | lpfc_send_rscn_event(vport, cmdiocb); |
| 5531 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5532 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5533 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5534 | FCH_EVT_RSCN, lp[i]); |
| 5535 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5536 | /* If we are about to begin discovery, just ACC the RSCN. |
| 5537 | * Discovery processing will satisfy it. |
| 5538 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5539 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5540 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5541 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 5542 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 5543 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5544 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5545 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5546 | } |
| 5547 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5548 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 5549 | * just ACC and ignore it. |
| 5550 | */ |
| 5551 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5552 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5553 | i = payload_len; |
| 5554 | datap = lp; |
| 5555 | while (i > 0) { |
| 5556 | nportid = *datap++; |
| 5557 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 5558 | i -= sizeof(uint32_t); |
| 5559 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5560 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 5561 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5562 | } |
| 5563 | if (rscn_id == hba_id) { |
| 5564 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5565 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5566 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5567 | "Data: x%x x%x x%x x%x\n", |
| 5568 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5569 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5570 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5571 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 5572 | ndlp->nlp_DID, vport->port_state, |
| 5573 | ndlp->nlp_flag); |
| 5574 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5575 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5576 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5577 | return 0; |
| 5578 | } |
| 5579 | } |
| 5580 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5581 | spin_lock_irq(shost->host_lock); |
| 5582 | if (vport->fc_rscn_flush) { |
| 5583 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5584 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 5585 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5586 | /* Send back ACC */ |
| 5587 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5588 | return 0; |
| 5589 | } |
| 5590 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 5591 | vport->fc_rscn_flush = 1; |
| 5592 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5593 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5594 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5595 | /* If we are already processing an RSCN, save the received |
| 5596 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 5597 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5598 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5599 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5600 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 5601 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 5602 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5603 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5604 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 5605 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5606 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5607 | vport->fc_flag |= FC_RSCN_MODE; |
| 5608 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5609 | if (rscn_cnt) { |
| 5610 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 5611 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 5612 | } |
| 5613 | if ((rscn_cnt) && |
| 5614 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 5615 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5616 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5617 | memcpy(((uint8_t *)cmd) + length, lp, |
| 5618 | payload_len); |
| 5619 | } else { |
| 5620 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 5621 | vport->fc_rscn_id_cnt++; |
| 5622 | /* If we zero, cmdiocb->context2, the calling |
| 5623 | * routine will not try to free it. |
| 5624 | */ |
| 5625 | cmdiocb->context2 = NULL; |
| 5626 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5627 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5628 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5629 | "0235 Deferred RSCN " |
| 5630 | "Data: x%x x%x x%x\n", |
| 5631 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 5632 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5633 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5634 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 5635 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5636 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5637 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5638 | "0234 ReDiscovery RSCN " |
| 5639 | "Data: x%x x%x x%x\n", |
| 5640 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 5641 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5642 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5643 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 5644 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5645 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5646 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5647 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5648 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5649 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5650 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5651 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5652 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5653 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5654 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5655 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 5656 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 5657 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5658 | spin_lock_irq(shost->host_lock); |
| 5659 | vport->fc_flag |= FC_RSCN_MODE; |
| 5660 | spin_unlock_irq(shost->host_lock); |
| 5661 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5662 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 5663 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5664 | /* |
| 5665 | * If we zero, cmdiocb->context2, the calling routine will |
| 5666 | * not try to free it. |
| 5667 | */ |
| 5668 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5669 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5670 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5671 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5672 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5673 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5674 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5675 | } |
| 5676 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5677 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5678 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5679 | * @vport: pointer to a host virtual N_Port data structure. |
| 5680 | * |
| 5681 | * This routine handles the Registration State Configuration Notification |
| 5682 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 5683 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 5684 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 5685 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 5686 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 5687 | * RSCN activities with the @vport. |
| 5688 | * |
| 5689 | * Return code |
| 5690 | * 0 - Cleaned up rscn on the @vport |
| 5691 | * 1 - Wait for plogi to name server before proceed |
| 5692 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5693 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5694 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5695 | { |
| 5696 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5697 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5698 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5699 | /* Ignore RSCN if the port is being torn down. */ |
| 5700 | if (vport->load_flag & FC_UNLOADING) { |
| 5701 | lpfc_els_flush_rscn(vport); |
| 5702 | return 0; |
| 5703 | } |
| 5704 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5705 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5706 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5707 | |
| 5708 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5709 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5710 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 5711 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 5712 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5713 | |
| 5714 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5715 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5716 | vport->num_disc_nodes = 0; |
| 5717 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5718 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5719 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 5720 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5721 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5722 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5723 | /* Wait for NameServer query cmpl before we can |
| 5724 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5725 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5726 | } else { |
| 5727 | /* If login to NameServer does not exist, issue one */ |
| 5728 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5729 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5730 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5731 | /* Wait for NameServer login cmpl before we can |
| 5732 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5733 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5734 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5735 | if (ndlp) { |
| 5736 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5737 | NLP_STE_PLOGI_ISSUE); |
| 5738 | if (!ndlp) { |
| 5739 | lpfc_els_flush_rscn(vport); |
| 5740 | return 0; |
| 5741 | } |
| 5742 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5743 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5744 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5745 | if (!ndlp) { |
| 5746 | lpfc_els_flush_rscn(vport); |
| 5747 | return 0; |
| 5748 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5749 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5750 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5751 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5752 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5753 | ndlp->nlp_type |= NLP_FABRIC; |
| 5754 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 5755 | /* Wait for NameServer login cmpl before we can |
| 5756 | * continue |
| 5757 | */ |
| 5758 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5759 | } |
| 5760 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5761 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5762 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5763 | } |
| 5764 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5765 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5766 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5767 | * @vport: pointer to a host virtual N_Port data structure. |
| 5768 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5769 | * @ndlp: pointer to a node-list data structure. |
| 5770 | * |
| 5771 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 5772 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 5773 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 5774 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 5775 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 5776 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 5777 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 5778 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 5779 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 5780 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 5781 | * higher priority (as the winning port) and will initiate PLOGI and |
| 5782 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 5783 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 5784 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 5785 | * |
| 5786 | * Return code |
| 5787 | * 0 - Successfully processed the unsolicited flogi |
| 5788 | * 1 - Failed to process the unsolicited flogi |
| 5789 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5790 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5791 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5792 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5793 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5794 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5795 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5796 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5797 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 5798 | IOCB_t *icmd = &cmdiocb->iocb; |
| 5799 | struct serv_parm *sp; |
| 5800 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5801 | uint32_t cmd, did; |
| 5802 | int rc; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5803 | uint32_t fc_flag = 0; |
| 5804 | uint32_t port_state = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5805 | |
| 5806 | cmd = *lp++; |
| 5807 | sp = (struct serv_parm *) lp; |
| 5808 | |
| 5809 | /* FLOGI received */ |
| 5810 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5811 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5812 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5813 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5814 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 5815 | did = icmd->un.elsreq64.remoteID; |
| 5816 | |
| 5817 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 5818 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5819 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5820 | "0113 An FLOGI ELS command x%x was " |
| 5821 | "received from DID x%x in Loop Mode\n", |
| 5822 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5823 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5824 | } |
| 5825 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 5826 | (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5827 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5828 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 5829 | /* |
| 5830 | * If our portname is greater than the remote portname, |
| 5831 | * then we initiate Nport login. |
| 5832 | */ |
| 5833 | |
| 5834 | rc = memcmp(&vport->fc_portname, &sp->portName, |
| 5835 | sizeof(struct lpfc_name)); |
| 5836 | |
| 5837 | if (!rc) { |
| 5838 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5839 | mbox = mempool_alloc(phba->mbox_mem_pool, |
| 5840 | GFP_KERNEL); |
| 5841 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5842 | return 1; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 5843 | lpfc_linkdown(phba); |
| 5844 | lpfc_init_link(phba, mbox, |
| 5845 | phba->cfg_topology, |
| 5846 | phba->cfg_link_speed); |
| 5847 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 5848 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5849 | mbox->vport = vport; |
| 5850 | rc = lpfc_sli_issue_mbox(phba, mbox, |
| 5851 | MBX_NOWAIT); |
| 5852 | lpfc_set_loopback_flag(phba); |
| 5853 | if (rc == MBX_NOT_FINISHED) |
| 5854 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5855 | return 1; |
| 5856 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5857 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 5858 | /* abort the flogi coming back to ourselves |
| 5859 | * due to external loopback on the port. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5860 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 5861 | lpfc_els_abort_flogi(phba); |
| 5862 | return 0; |
| 5863 | |
| 5864 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5865 | spin_lock_irq(shost->host_lock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 5866 | vport->fc_flag |= FC_PT2PT_PLOGI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5867 | spin_unlock_irq(shost->host_lock); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5868 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 5869 | /* If we have the high WWPN we can assign our own |
| 5870 | * myDID; otherwise, we have to WAIT for a PLOGI |
| 5871 | * from the remote NPort to find out what it |
| 5872 | * will be. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5873 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 5874 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5875 | } else { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 5876 | vport->fc_myDID = PT2PT_RemoteID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5877 | } |
| 5878 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 5879 | /* |
| 5880 | * The vport state should go to LPFC_FLOGI only |
| 5881 | * AFTER we issue a FLOGI, not receive one. |
| 5882 | */ |
| 5883 | spin_lock_irq(shost->host_lock); |
| 5884 | fc_flag = vport->fc_flag; |
| 5885 | port_state = vport->port_state; |
| 5886 | vport->fc_flag |= FC_PT2PT; |
| 5887 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 5888 | spin_unlock_irq(shost->host_lock); |
| 5889 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5890 | "3311 Rcv Flogi PS x%x new PS x%x " |
| 5891 | "fc_flag x%x new fc_flag x%x\n", |
| 5892 | port_state, vport->port_state, |
| 5893 | fc_flag, vport->fc_flag); |
| 5894 | |
| 5895 | /* |
| 5896 | * We temporarily set fc_myDID to make it look like we are |
| 5897 | * a Fabric. This is done just so we end up with the right |
| 5898 | * did / sid on the FLOGI ACC rsp. |
| 5899 | */ |
| 5900 | did = vport->fc_myDID; |
| 5901 | vport->fc_myDID = Fabric_DID; |
| 5902 | |
| 5903 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 5904 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5905 | /* Send back ACC */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 5906 | lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5907 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5908 | /* Now lets put fc_myDID back to what its supposed to be */ |
| 5909 | vport->fc_myDID = did; |
| 5910 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5911 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5912 | } |
| 5913 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5914 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5915 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5916 | * @vport: pointer to a host virtual N_Port data structure. |
| 5917 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5918 | * @ndlp: pointer to a node-list data structure. |
| 5919 | * |
| 5920 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 5921 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 5922 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 5923 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 5924 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 5925 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 5926 | * |
| 5927 | * Return code |
| 5928 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 5929 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5930 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5931 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5932 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5933 | { |
| 5934 | struct lpfc_dmabuf *pcmd; |
| 5935 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5936 | RNID *rn; |
| 5937 | struct ls_rjt stat; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 5938 | uint32_t cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5939 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5940 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5941 | lp = (uint32_t *) pcmd->virt; |
| 5942 | |
| 5943 | cmd = *lp++; |
| 5944 | rn = (RNID *) lp; |
| 5945 | |
| 5946 | /* RNID received */ |
| 5947 | |
| 5948 | switch (rn->Format) { |
| 5949 | case 0: |
| 5950 | case RNID_TOPOLOGY_DISC: |
| 5951 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5952 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5953 | break; |
| 5954 | default: |
| 5955 | /* Reject this request because format not supported */ |
| 5956 | stat.un.b.lsRjtRsvd0 = 0; |
| 5957 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5958 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5959 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5960 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5961 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5962 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5963 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5964 | } |
| 5965 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5966 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5967 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 5968 | * @vport: pointer to a host virtual N_Port data structure. |
| 5969 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5970 | * @ndlp: pointer to a node-list data structure. |
| 5971 | * |
| 5972 | * Return code |
| 5973 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 5974 | **/ |
| 5975 | static int |
| 5976 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5977 | struct lpfc_nodelist *ndlp) |
| 5978 | { |
| 5979 | uint8_t *pcmd; |
| 5980 | |
| 5981 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 5982 | |
| 5983 | /* skip over first word of echo command to find echo data */ |
| 5984 | pcmd += sizeof(uint32_t); |
| 5985 | |
| 5986 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 5987 | return 0; |
| 5988 | } |
| 5989 | |
| 5990 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5991 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5992 | * @vport: pointer to a host virtual N_Port data structure. |
| 5993 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5994 | * @ndlp: pointer to a node-list data structure. |
| 5995 | * |
| 5996 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 5997 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 5998 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 5999 | * |
| 6000 | * Return code |
| 6001 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 6002 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6003 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6004 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6005 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6006 | { |
| 6007 | struct ls_rjt stat; |
| 6008 | |
| 6009 | /* For now, unconditionally reject this command */ |
| 6010 | stat.un.b.lsRjtRsvd0 = 0; |
| 6011 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6012 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6013 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6014 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6015 | return 0; |
| 6016 | } |
| 6017 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6018 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6019 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 6020 | * @vport: pointer to a host virtual N_Port data structure. |
| 6021 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6022 | * @ndlp: pointer to a node-list data structure. |
| 6023 | * |
| 6024 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 6025 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 6026 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 6027 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 6028 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 6029 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 6030 | * command request" and reason code explanation "Invalid Originator |
| 6031 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 6032 | * RRQ from the target. |
| 6033 | **/ |
| 6034 | static void |
| 6035 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6036 | struct lpfc_nodelist *ndlp) |
| 6037 | { |
| 6038 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6039 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 6040 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6041 | } |
| 6042 | |
| 6043 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6044 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 6045 | * @phba: pointer to lpfc hba data structure. |
| 6046 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6047 | * |
| 6048 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 6049 | * mailbox command. This callback function is to actually send the Accept |
| 6050 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 6051 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 6052 | * mailbox command, constructs the RPS response with the link statistics |
| 6053 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 6054 | * response to the RPS. |
| 6055 | * |
| 6056 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6057 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6058 | * will be stored into the context1 field of the IOCB for the completion |
| 6059 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6060 | * |
| 6061 | **/ |
| 6062 | static void |
| 6063 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6064 | { |
| 6065 | MAILBOX_t *mb; |
| 6066 | IOCB_t *icmd; |
| 6067 | struct RLS_RSP *rls_rsp; |
| 6068 | uint8_t *pcmd; |
| 6069 | struct lpfc_iocbq *elsiocb; |
| 6070 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6071 | uint16_t oxid; |
| 6072 | uint16_t rxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6073 | uint32_t cmdsize; |
| 6074 | |
| 6075 | mb = &pmb->u.mb; |
| 6076 | |
| 6077 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6078 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 6079 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6080 | pmb->context1 = NULL; |
| 6081 | pmb->context2 = NULL; |
| 6082 | |
| 6083 | if (mb->mbxStatus) { |
| 6084 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6085 | return; |
| 6086 | } |
| 6087 | |
| 6088 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6089 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6090 | lpfc_max_els_tries, ndlp, |
| 6091 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6092 | |
| 6093 | /* Decrement the ndlp reference count from previous mbox command */ |
| 6094 | lpfc_nlp_put(ndlp); |
| 6095 | |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6096 | if (!elsiocb) { |
| 6097 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6098 | return; |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6099 | } |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6100 | |
| 6101 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6102 | icmd->ulpContext = rxid; |
| 6103 | icmd->unsli3.rcvsli3.ox_id = oxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6104 | |
| 6105 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6106 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6107 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 6108 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 6109 | |
| 6110 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 6111 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 6112 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 6113 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 6114 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 6115 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6116 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6117 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 6118 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6119 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 6120 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 6121 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6122 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6123 | ndlp->nlp_rpi); |
| 6124 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6125 | phba->fc_stat.elsXmitACC++; |
| 6126 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 6127 | lpfc_els_free_iocb(phba, elsiocb); |
| 6128 | } |
| 6129 | |
| 6130 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6131 | * 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] | 6132 | * @phba: pointer to lpfc hba data structure. |
| 6133 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6134 | * |
| 6135 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 6136 | * mailbox command. This callback function is to actually send the Accept |
| 6137 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 6138 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 6139 | * mailbox command, constructs the RPS response with the link statistics |
| 6140 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 6141 | * response to the RPS. |
| 6142 | * |
| 6143 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6144 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6145 | * will be stored into the context1 field of the IOCB for the completion |
| 6146 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6147 | * |
| 6148 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 6149 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6150 | 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] | 6151 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6152 | MAILBOX_t *mb; |
| 6153 | IOCB_t *icmd; |
| 6154 | RPS_RSP *rps_rsp; |
| 6155 | uint8_t *pcmd; |
| 6156 | struct lpfc_iocbq *elsiocb; |
| 6157 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6158 | uint16_t status; |
| 6159 | uint16_t oxid; |
| 6160 | uint16_t rxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6161 | uint32_t cmdsize; |
| 6162 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6163 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6164 | |
| 6165 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6166 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 6167 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 6168 | pmb->context1 = NULL; |
| 6169 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6170 | |
| 6171 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6172 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6173 | return; |
| 6174 | } |
| 6175 | |
| 6176 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6177 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6178 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6179 | lpfc_max_els_tries, ndlp, |
| 6180 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6181 | |
| 6182 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6183 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6184 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6185 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6186 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6187 | |
| 6188 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6189 | icmd->ulpContext = rxid; |
| 6190 | icmd->unsli3.rcvsli3.ox_id = oxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6191 | |
| 6192 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6193 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6194 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6195 | rps_rsp = (RPS_RSP *)pcmd; |
| 6196 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6197 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6198 | status = 0x10; |
| 6199 | else |
| 6200 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6201 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6202 | status |= 0x4; |
| 6203 | |
| 6204 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6205 | rps_rsp->portStatus = cpu_to_be16(status); |
| 6206 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 6207 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 6208 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 6209 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 6210 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 6211 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6212 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6213 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6214 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 6215 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 6216 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6217 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6218 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6219 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6220 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6221 | 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] | 6222 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6223 | return; |
| 6224 | } |
| 6225 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6226 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6227 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 6228 | * @vport: pointer to a host virtual N_Port data structure. |
| 6229 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6230 | * @ndlp: pointer to a node-list data structure. |
| 6231 | * |
| 6232 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 6233 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6234 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6235 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 6236 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 6237 | * for reading the HBA link statistics. It is for the callback function, |
| 6238 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 6239 | * to actually sending out RPL Accept (ACC) response. |
| 6240 | * |
| 6241 | * Return codes |
| 6242 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 6243 | **/ |
| 6244 | static int |
| 6245 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6246 | struct lpfc_nodelist *ndlp) |
| 6247 | { |
| 6248 | struct lpfc_hba *phba = vport->phba; |
| 6249 | LPFC_MBOXQ_t *mbox; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6250 | struct ls_rjt stat; |
| 6251 | |
| 6252 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6253 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6254 | /* reject the unsolicited RPS request and done with it */ |
| 6255 | goto reject_out; |
| 6256 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6257 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 6258 | if (mbox) { |
| 6259 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6260 | mbox->context1 = (void *)((unsigned long) |
| 6261 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 6262 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6263 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6264 | mbox->vport = vport; |
| 6265 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 6266 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 6267 | != MBX_NOT_FINISHED) |
| 6268 | /* Mbox completion will send ELS Response */ |
| 6269 | return 0; |
| 6270 | /* Decrement reference count used for the failed mbox |
| 6271 | * command. |
| 6272 | */ |
| 6273 | lpfc_nlp_put(ndlp); |
| 6274 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6275 | } |
| 6276 | reject_out: |
| 6277 | /* issue rejection response */ |
| 6278 | stat.un.b.lsRjtRsvd0 = 0; |
| 6279 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6280 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6281 | stat.un.b.vendorUnique = 0; |
| 6282 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6283 | return 0; |
| 6284 | } |
| 6285 | |
| 6286 | /** |
| 6287 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 6288 | * @vport: pointer to a host virtual N_Port data structure. |
| 6289 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6290 | * @ndlp: pointer to a node-list data structure. |
| 6291 | * |
| 6292 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 6293 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6294 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6295 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 6296 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 6297 | * Value (RTV) unsolicited IOCB event. |
| 6298 | * |
| 6299 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6300 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6301 | * will be stored into the context1 field of the IOCB for the completion |
| 6302 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6303 | * |
| 6304 | * Return codes |
| 6305 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 6306 | **/ |
| 6307 | static int |
| 6308 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6309 | struct lpfc_nodelist *ndlp) |
| 6310 | { |
| 6311 | struct lpfc_hba *phba = vport->phba; |
| 6312 | struct ls_rjt stat; |
| 6313 | struct RTV_RSP *rtv_rsp; |
| 6314 | uint8_t *pcmd; |
| 6315 | struct lpfc_iocbq *elsiocb; |
| 6316 | uint32_t cmdsize; |
| 6317 | |
| 6318 | |
| 6319 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6320 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6321 | /* reject the unsolicited RPS request and done with it */ |
| 6322 | goto reject_out; |
| 6323 | |
| 6324 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 6325 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6326 | lpfc_max_els_tries, ndlp, |
| 6327 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6328 | |
| 6329 | if (!elsiocb) |
| 6330 | return 1; |
| 6331 | |
| 6332 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6333 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6334 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 6335 | |
| 6336 | /* use the command's xri in the response */ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6337 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 6338 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6339 | |
| 6340 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 6341 | |
| 6342 | /* populate RTV payload */ |
| 6343 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 6344 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 6345 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 6346 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 6347 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 6348 | |
| 6349 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 6350 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6351 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 6352 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 6353 | "Data: x%x x%x x%x\n", |
| 6354 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6355 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6356 | ndlp->nlp_rpi, |
| 6357 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 6358 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6359 | phba->fc_stat.elsXmitACC++; |
| 6360 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 6361 | lpfc_els_free_iocb(phba, elsiocb); |
| 6362 | return 0; |
| 6363 | |
| 6364 | reject_out: |
| 6365 | /* issue rejection response */ |
| 6366 | stat.un.b.lsRjtRsvd0 = 0; |
| 6367 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6368 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6369 | stat.un.b.vendorUnique = 0; |
| 6370 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6371 | return 0; |
| 6372 | } |
| 6373 | |
| 6374 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6375 | * @vport: pointer to a host virtual N_Port data structure. |
| 6376 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6377 | * @ndlp: pointer to a node-list data structure. |
| 6378 | * |
| 6379 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 6380 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6381 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6382 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 6383 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 6384 | * for reading the HBA link statistics. It is for the callback function, |
| 6385 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 6386 | * to actually sending out RPS Accept (ACC) response. |
| 6387 | * |
| 6388 | * Return codes |
| 6389 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 6390 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6391 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6392 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6393 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6394 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6395 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6396 | uint32_t *lp; |
| 6397 | uint8_t flag; |
| 6398 | LPFC_MBOXQ_t *mbox; |
| 6399 | struct lpfc_dmabuf *pcmd; |
| 6400 | RPS *rps; |
| 6401 | struct ls_rjt stat; |
| 6402 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6403 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6404 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6405 | /* reject the unsolicited RPS request and done with it */ |
| 6406 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6407 | |
| 6408 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6409 | lp = (uint32_t *) pcmd->virt; |
| 6410 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 6411 | rps = (RPS *) lp; |
| 6412 | |
| 6413 | if ((flag == 0) || |
| 6414 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6415 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6416 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6417 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6418 | printk("Fix me....\n"); |
| 6419 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6420 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 6421 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6422 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6423 | mbox->context1 = (void *)((unsigned long) |
| 6424 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 6425 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6426 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6427 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6428 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6429 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6430 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6431 | /* Mbox completion will send ELS Response */ |
| 6432 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6433 | /* Decrement reference count used for the failed mbox |
| 6434 | * command. |
| 6435 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6436 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6437 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6438 | } |
| 6439 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6440 | |
| 6441 | reject_out: |
| 6442 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6443 | stat.un.b.lsRjtRsvd0 = 0; |
| 6444 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6445 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6446 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6447 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6448 | return 0; |
| 6449 | } |
| 6450 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6451 | /* lpfc_issue_els_rrq - Process an unsolicited rps iocb |
| 6452 | * @vport: pointer to a host virtual N_Port data structure. |
| 6453 | * @ndlp: pointer to a node-list data structure. |
| 6454 | * @did: DID of the target. |
| 6455 | * @rrq: Pointer to the rrq struct. |
| 6456 | * |
| 6457 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is |
| 6458 | * Successful the the completion handler will clear the RRQ. |
| 6459 | * |
| 6460 | * Return codes |
| 6461 | * 0 - Successfully sent rrq els iocb. |
| 6462 | * 1 - Failed to send rrq els iocb. |
| 6463 | **/ |
| 6464 | static int |
| 6465 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6466 | uint32_t did, struct lpfc_node_rrq *rrq) |
| 6467 | { |
| 6468 | struct lpfc_hba *phba = vport->phba; |
| 6469 | struct RRQ *els_rrq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6470 | struct lpfc_iocbq *elsiocb; |
| 6471 | uint8_t *pcmd; |
| 6472 | uint16_t cmdsize; |
| 6473 | int ret; |
| 6474 | |
| 6475 | |
| 6476 | if (ndlp != rrq->ndlp) |
| 6477 | ndlp = rrq->ndlp; |
| 6478 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 6479 | return 1; |
| 6480 | |
| 6481 | /* If ndlp is not NULL, we will bump the reference count on it */ |
| 6482 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); |
| 6483 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, |
| 6484 | ELS_CMD_RRQ); |
| 6485 | if (!elsiocb) |
| 6486 | return 1; |
| 6487 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6488 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6489 | |
| 6490 | /* For RRQ request, remainder of payload is Exchange IDs */ |
| 6491 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; |
| 6492 | pcmd += sizeof(uint32_t); |
| 6493 | els_rrq = (struct RRQ *) pcmd; |
| 6494 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 6495 | 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] | 6496 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
| 6497 | bf_set(rrq_did, els_rrq, vport->fc_myDID); |
| 6498 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); |
| 6499 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); |
| 6500 | |
| 6501 | |
| 6502 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6503 | "Issue RRQ: did:x%x", |
| 6504 | did, rrq->xritag, rrq->rxid); |
| 6505 | elsiocb->context_un.rrq = rrq; |
| 6506 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; |
| 6507 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6508 | |
| 6509 | if (ret == IOCB_ERROR) { |
| 6510 | lpfc_els_free_iocb(phba, elsiocb); |
| 6511 | return 1; |
| 6512 | } |
| 6513 | return 0; |
| 6514 | } |
| 6515 | |
| 6516 | /** |
| 6517 | * lpfc_send_rrq - Sends ELS RRQ if needed. |
| 6518 | * @phba: pointer to lpfc hba data structure. |
| 6519 | * @rrq: pointer to the active rrq. |
| 6520 | * |
| 6521 | * This routine will call the lpfc_issue_els_rrq if the rrq is |
| 6522 | * still active for the xri. If this function returns a failure then |
| 6523 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. |
| 6524 | * |
| 6525 | * Returns 0 Success. |
| 6526 | * 1 Failure. |
| 6527 | **/ |
| 6528 | int |
| 6529 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) |
| 6530 | { |
| 6531 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, |
| 6532 | rrq->nlp_DID); |
| 6533 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) |
| 6534 | return lpfc_issue_els_rrq(rrq->vport, ndlp, |
| 6535 | rrq->nlp_DID, rrq); |
| 6536 | else |
| 6537 | return 1; |
| 6538 | } |
| 6539 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6540 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6541 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6542 | * @vport: pointer to a host virtual N_Port data structure. |
| 6543 | * @cmdsize: size of the ELS command. |
| 6544 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 6545 | * @ndlp: pointer to a node-list data structure. |
| 6546 | * |
| 6547 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 6548 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 6549 | * |
| 6550 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6551 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6552 | * will be stored into the context1 field of the IOCB for the completion |
| 6553 | * callback function to the RPL Accept Response ELS command. |
| 6554 | * |
| 6555 | * Return code |
| 6556 | * 0 - Successfully issued ACC RPL ELS command |
| 6557 | * 1 - Failed to issue ACC RPL ELS command |
| 6558 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 6559 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6560 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 6561 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6562 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6563 | struct lpfc_hba *phba = vport->phba; |
| 6564 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6565 | RPL_RSP rpl_rsp; |
| 6566 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6567 | uint8_t *pcmd; |
| 6568 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6569 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 6570 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6571 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6572 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6573 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6574 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6575 | icmd = &elsiocb->iocb; |
| 6576 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6577 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 6578 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6579 | |
| 6580 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6581 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6582 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6583 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 6584 | pcmd += sizeof(uint16_t); |
| 6585 | |
| 6586 | /* Setup the RPL ACC payload */ |
| 6587 | rpl_rsp.listLen = be32_to_cpu(1); |
| 6588 | rpl_rsp.index = 0; |
| 6589 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6590 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 6591 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6592 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6593 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6594 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6595 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6596 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 6597 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 6598 | "rpi x%x\n", |
| 6599 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6600 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6601 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6602 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6603 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6604 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6605 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6606 | lpfc_els_free_iocb(phba, elsiocb); |
| 6607 | return 1; |
| 6608 | } |
| 6609 | return 0; |
| 6610 | } |
| 6611 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6612 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6613 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6614 | * @vport: pointer to a host virtual N_Port data structure. |
| 6615 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6616 | * @ndlp: pointer to a node-list data structure. |
| 6617 | * |
| 6618 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 6619 | * unsolicited event. It first checks the remote port state. If the remote |
| 6620 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 6621 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 6622 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 6623 | * to accept the RPL. |
| 6624 | * |
| 6625 | * Return code |
| 6626 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 6627 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6628 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6629 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6630 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6631 | { |
| 6632 | struct lpfc_dmabuf *pcmd; |
| 6633 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6634 | uint32_t maxsize; |
| 6635 | uint16_t cmdsize; |
| 6636 | RPL *rpl; |
| 6637 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6638 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6639 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6640 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6641 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6642 | stat.un.b.lsRjtRsvd0 = 0; |
| 6643 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6644 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6645 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6646 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 6647 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6648 | /* rejected the unsolicited RPL request and done with it */ |
| 6649 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6650 | } |
| 6651 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6652 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6653 | lp = (uint32_t *) pcmd->virt; |
| 6654 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6655 | maxsize = be32_to_cpu(rpl->maxsize); |
| 6656 | |
| 6657 | /* We support only one port */ |
| 6658 | if ((rpl->index == 0) && |
| 6659 | ((maxsize == 0) || |
| 6660 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 6661 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6662 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6663 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 6664 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6665 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6666 | |
| 6667 | return 0; |
| 6668 | } |
| 6669 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6670 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6671 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6672 | * @vport: pointer to a virtual N_Port data structure. |
| 6673 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6674 | * @ndlp: pointer to a node-list data structure. |
| 6675 | * |
| 6676 | * This routine processes Fibre Channel Address Resolution Protocol |
| 6677 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 6678 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 6679 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 6680 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 6681 | * remote PortName is compared against the FC PortName stored in the @vport |
| 6682 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 6683 | * compared against the FC NodeName stored in the @vport data structure. |
| 6684 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 6685 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 6686 | * invoked to send out FARP Response to the remote node. Before sending the |
| 6687 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 6688 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 6689 | * routine is invoked to log into the remote port first. |
| 6690 | * |
| 6691 | * Return code |
| 6692 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 6693 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6694 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6695 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6696 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6697 | { |
| 6698 | struct lpfc_dmabuf *pcmd; |
| 6699 | uint32_t *lp; |
| 6700 | IOCB_t *icmd; |
| 6701 | FARP *fp; |
| 6702 | uint32_t cmd, cnt, did; |
| 6703 | |
| 6704 | icmd = &cmdiocb->iocb; |
| 6705 | did = icmd->un.elsreq64.remoteID; |
| 6706 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6707 | lp = (uint32_t *) pcmd->virt; |
| 6708 | |
| 6709 | cmd = *lp++; |
| 6710 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6711 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6712 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6713 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6714 | /* We will only support match on WWPN or WWNN */ |
| 6715 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6716 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6717 | } |
| 6718 | |
| 6719 | cnt = 0; |
| 6720 | /* If this FARP command is searching for my portname */ |
| 6721 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6722 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6723 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6724 | cnt = 1; |
| 6725 | } |
| 6726 | |
| 6727 | /* If this FARP command is searching for my nodename */ |
| 6728 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6729 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6730 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6731 | cnt = 1; |
| 6732 | } |
| 6733 | |
| 6734 | if (cnt) { |
| 6735 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 6736 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 6737 | /* Log back into the node before sending the FARP. */ |
| 6738 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6739 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6740 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 6741 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6742 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6743 | } |
| 6744 | |
| 6745 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6746 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 6747 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6748 | } |
| 6749 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6750 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6751 | } |
| 6752 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6753 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6754 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6755 | * @vport: pointer to a host virtual N_Port data structure. |
| 6756 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6757 | * @ndlp: pointer to a node-list data structure. |
| 6758 | * |
| 6759 | * This routine processes Fibre Channel Address Resolution Protocol |
| 6760 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 6761 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 6762 | * the FARP response request. |
| 6763 | * |
| 6764 | * Return code |
| 6765 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 6766 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6767 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6768 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6769 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6770 | { |
| 6771 | struct lpfc_dmabuf *pcmd; |
| 6772 | uint32_t *lp; |
| 6773 | IOCB_t *icmd; |
| 6774 | uint32_t cmd, did; |
| 6775 | |
| 6776 | icmd = &cmdiocb->iocb; |
| 6777 | did = icmd->un.elsreq64.remoteID; |
| 6778 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6779 | lp = (uint32_t *) pcmd->virt; |
| 6780 | |
| 6781 | cmd = *lp++; |
| 6782 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6783 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6784 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6785 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6786 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6787 | |
| 6788 | return 0; |
| 6789 | } |
| 6790 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6791 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6792 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6793 | * @vport: pointer to a host virtual N_Port data structure. |
| 6794 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6795 | * @fan_ndlp: pointer to a node-list data structure. |
| 6796 | * |
| 6797 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 6798 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 6799 | * only be processed on a physical port (i.e., the @vport represents the |
| 6800 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 6801 | * compared against those in the phba data structure. If any of those is |
| 6802 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 6803 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 6804 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 6805 | * is invoked to register login to the fabric. |
| 6806 | * |
| 6807 | * Return code |
| 6808 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 6809 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6810 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6811 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6812 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6813 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6814 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6815 | uint32_t *lp; |
| 6816 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6817 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6818 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 6819 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 6820 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6821 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6822 | if ((vport == phba->pport) && |
| 6823 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6824 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6825 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6826 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6827 | sizeof(struct lpfc_name)))) { |
| 6828 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6829 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6830 | } else { |
| 6831 | /* FAN verified - skip FLOGI */ |
| 6832 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6833 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6834 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6835 | else { |
| 6836 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6837 | "3138 Need register VFI: (x%x/%x)\n", |
| 6838 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6839 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6840 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6841 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6842 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6843 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6844 | } |
| 6845 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6846 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6847 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6848 | * @ptr: holder for the timer function associated data. |
| 6849 | * |
| 6850 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 6851 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 6852 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 6853 | * up the worker thread. It is for the worker thread to invoke the routine |
| 6854 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 6855 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6856 | void |
| 6857 | lpfc_els_timeout(unsigned long ptr) |
| 6858 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6859 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 6860 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6861 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6862 | unsigned long iflag; |
| 6863 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6864 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6865 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 6866 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6867 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6868 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6869 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 6870 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6871 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6872 | return; |
| 6873 | } |
| 6874 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6875 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6876 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6877 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6878 | * @vport: pointer to a virtual N_Port data structure. |
| 6879 | * |
| 6880 | * This routine is the actual handler function that processes an ELS timeout |
| 6881 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 6882 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 6883 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 6884 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6885 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6886 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6887 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6888 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6889 | struct lpfc_sli_ring *pring; |
| 6890 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6891 | IOCB_t *cmd = NULL; |
| 6892 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6893 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6894 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6895 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6896 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6897 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6898 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6899 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 6900 | |
| 6901 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 6902 | if ((phba->pport->load_flag & FC_UNLOADING)) |
| 6903 | return; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6904 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 6905 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6906 | spin_lock(&pring->ring_lock); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6907 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 6908 | if ((phba->pport->load_flag & FC_UNLOADING)) { |
| 6909 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6910 | spin_unlock(&pring->ring_lock); |
| 6911 | spin_unlock_irq(&phba->hbalock); |
| 6912 | return; |
| 6913 | } |
| 6914 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 6915 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6916 | cmd = &piocb->iocb; |
| 6917 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6918 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 6919 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 6920 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6921 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6922 | |
| 6923 | if (piocb->vport != vport) |
| 6924 | continue; |
| 6925 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6926 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6927 | if (pcmd) |
| 6928 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6929 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6930 | if (els_command == ELS_CMD_FARP || |
| 6931 | els_command == ELS_CMD_FARPR || |
| 6932 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6933 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6934 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6935 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6936 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6937 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6938 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6939 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6940 | continue; |
| 6941 | } |
| 6942 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6943 | remote_ID = 0xffffffff; |
| 6944 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6945 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6946 | else { |
| 6947 | struct lpfc_nodelist *ndlp; |
| 6948 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6949 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6950 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6951 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6952 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6953 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 6954 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6955 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6956 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 6957 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6958 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
James Smart | 15026c9 | 2013-12-17 20:30:09 -0500 | [diff] [blame] | 6959 | cmd = &piocb->iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6960 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6961 | "0127 ELS timeout Data: x%x x%x x%x " |
| 6962 | "x%x\n", els_command, |
| 6963 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 6964 | spin_lock_irq(&phba->hbalock); |
| 6965 | list_del_init(&piocb->dlist); |
| 6966 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 6967 | spin_unlock_irq(&phba->hbalock); |
| 6968 | } |
| 6969 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 6970 | if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq)) |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 6971 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 6972 | mod_timer(&vport->els_tmofunc, |
| 6973 | jiffies + msecs_to_jiffies(1000 * timeout)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6974 | } |
| 6975 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6976 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6977 | * 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] | 6978 | * @vport: pointer to a host virtual N_Port data structure. |
| 6979 | * |
| 6980 | * This routine is used to clean up all the outstanding ELS commands on a |
| 6981 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 6982 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 6983 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 6984 | * the IOCBs with a non-NULL completion callback function, the callback |
| 6985 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 6986 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 6987 | * callback function, the IOCB will simply be released. Finally, it walks |
| 6988 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 6989 | * completion queue IOCB that is associated with the @vport and is not |
| 6990 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 6991 | * part of the discovery state machine) out to HBA by invoking the |
| 6992 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 6993 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 6994 | * the IOCBs are aborted when this function returns. |
| 6995 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6996 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6997 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6998 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 6999 | LIST_HEAD(abort_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7000 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7001 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7002 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7003 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7004 | |
| 7005 | lpfc_fabric_abort_vport(vport); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7006 | /* |
| 7007 | * For SLI3, only the hbalock is required. But SLI4 needs to coordinate |
| 7008 | * with the ring insert operation. Because lpfc_sli_issue_abort_iotag |
| 7009 | * ultimately grabs the ring_lock, the driver must splice the list into |
| 7010 | * a working list and release the locks before calling the abort. |
| 7011 | */ |
| 7012 | spin_lock_irq(&phba->hbalock); |
| 7013 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7014 | spin_lock(&pring->ring_lock); |
| 7015 | |
| 7016 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 7017 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 7018 | continue; |
| 7019 | |
| 7020 | if (piocb->vport != vport) |
| 7021 | continue; |
| 7022 | list_add_tail(&piocb->dlist, &abort_list); |
| 7023 | } |
| 7024 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7025 | spin_unlock(&pring->ring_lock); |
| 7026 | spin_unlock_irq(&phba->hbalock); |
| 7027 | /* Abort each iocb on the aborted list and remove the dlist links. */ |
| 7028 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 7029 | spin_lock_irq(&phba->hbalock); |
| 7030 | list_del_init(&piocb->dlist); |
| 7031 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 7032 | spin_unlock_irq(&phba->hbalock); |
| 7033 | } |
| 7034 | if (!list_empty(&abort_list)) |
| 7035 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7036 | "3387 abort list for txq not empty\n"); |
| 7037 | INIT_LIST_HEAD(&abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7038 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7039 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7040 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7041 | spin_lock(&pring->ring_lock); |
| 7042 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7043 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 7044 | cmd = &piocb->iocb; |
| 7045 | |
| 7046 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 7047 | continue; |
| 7048 | } |
| 7049 | |
| 7050 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7051 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 7052 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 7053 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 7054 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7055 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7056 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7057 | if (piocb->vport != vport) |
| 7058 | continue; |
| 7059 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7060 | list_del_init(&piocb->list); |
| 7061 | list_add_tail(&piocb->list, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7062 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7063 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7064 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7065 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 7066 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7067 | /* Cancell all the IOCBs from the completions list */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7068 | lpfc_sli_cancel_iocbs(phba, &abort_list, |
| 7069 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 7070 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7071 | return; |
| 7072 | } |
| 7073 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7074 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7075 | * 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] | 7076 | * @phba: pointer to lpfc hba data structure. |
| 7077 | * |
| 7078 | * This routine is used to clean up all the outstanding ELS commands on a |
| 7079 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 7080 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 7081 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 7082 | * the IOCBs with the completion callback function associated, the callback |
| 7083 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 7084 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 7085 | * callback function associated, the IOCB will simply be released. Finally, |
| 7086 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 7087 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 7088 | * management plane IOCBs that are not part of the discovery state machine) |
| 7089 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 7090 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 7091 | void |
| 7092 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 7093 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7094 | struct lpfc_vport *vport; |
| 7095 | list_for_each_entry(vport, &phba->port_list, listentry) |
| 7096 | lpfc_els_flush_cmd(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7097 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 7098 | return; |
| 7099 | } |
| 7100 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7101 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7102 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7103 | * @phba: Pointer to hba context object. |
| 7104 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 7105 | * @rspiocbp: Pointer to response iocb which reported error. |
| 7106 | * |
| 7107 | * This function sends an event when there is an ELS command |
| 7108 | * failure. |
| 7109 | **/ |
| 7110 | void |
| 7111 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 7112 | struct lpfc_iocbq *cmdiocbp, |
| 7113 | struct lpfc_iocbq *rspiocbp) |
| 7114 | { |
| 7115 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 7116 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7117 | struct lpfc_lsrjt_event lsrjt_event; |
| 7118 | struct lpfc_fabric_event_header fabric_event; |
| 7119 | struct ls_rjt stat; |
| 7120 | struct lpfc_nodelist *ndlp; |
| 7121 | uint32_t *pcmd; |
| 7122 | |
| 7123 | ndlp = cmdiocbp->context1; |
| 7124 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 7125 | return; |
| 7126 | |
| 7127 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 7128 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 7129 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 7130 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 7131 | sizeof(struct lpfc_name)); |
| 7132 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 7133 | sizeof(struct lpfc_name)); |
| 7134 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 7135 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7136 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7137 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 7138 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 7139 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 7140 | fc_host_post_vendor_event(shost, |
| 7141 | fc_get_event_number(), |
| 7142 | sizeof(lsrjt_event), |
| 7143 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7144 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7145 | return; |
| 7146 | } |
| 7147 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 7148 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 7149 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 7150 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 7151 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 7152 | else |
| 7153 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 7154 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 7155 | sizeof(struct lpfc_name)); |
| 7156 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 7157 | sizeof(struct lpfc_name)); |
| 7158 | fc_host_post_vendor_event(shost, |
| 7159 | fc_get_event_number(), |
| 7160 | sizeof(fabric_event), |
| 7161 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7162 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7163 | return; |
| 7164 | } |
| 7165 | |
| 7166 | } |
| 7167 | |
| 7168 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7169 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7170 | * @vport: Pointer to vport object. |
| 7171 | * @ndlp: Pointer FC node object. |
| 7172 | * @cmd: ELS command code. |
| 7173 | * |
| 7174 | * This function posts an event when there is an incoming |
| 7175 | * unsolicited ELS command. |
| 7176 | **/ |
| 7177 | static void |
| 7178 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 7179 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7180 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7181 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7182 | struct lpfc_els_event_header *els_data = NULL; |
| 7183 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7184 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7185 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7186 | if (*payload == ELS_CMD_LOGO) { |
| 7187 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 7188 | if (!logo_data) { |
| 7189 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7190 | "0148 Failed to allocate memory " |
| 7191 | "for LOGO event\n"); |
| 7192 | return; |
| 7193 | } |
| 7194 | els_data = &logo_data->header; |
| 7195 | } else { |
| 7196 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 7197 | GFP_KERNEL); |
| 7198 | if (!els_data) { |
| 7199 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7200 | "0149 Failed to allocate memory " |
| 7201 | "for ELS event\n"); |
| 7202 | return; |
| 7203 | } |
| 7204 | } |
| 7205 | els_data->event_type = FC_REG_ELS_EVENT; |
| 7206 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7207 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7208 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7209 | break; |
| 7210 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7211 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7212 | break; |
| 7213 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7214 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 7215 | break; |
| 7216 | case ELS_CMD_LOGO: |
| 7217 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 7218 | /* Copy the WWPN in the LOGO payload */ |
| 7219 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 7220 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7221 | break; |
| 7222 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 7223 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7224 | return; |
| 7225 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7226 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 7227 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 7228 | if (*payload == ELS_CMD_LOGO) { |
| 7229 | fc_host_post_vendor_event(shost, |
| 7230 | fc_get_event_number(), |
| 7231 | sizeof(struct lpfc_logo_event), |
| 7232 | (char *)logo_data, |
| 7233 | LPFC_NL_VENDOR_ID); |
| 7234 | kfree(logo_data); |
| 7235 | } else { |
| 7236 | fc_host_post_vendor_event(shost, |
| 7237 | fc_get_event_number(), |
| 7238 | sizeof(struct lpfc_els_event_header), |
| 7239 | (char *)els_data, |
| 7240 | LPFC_NL_VENDOR_ID); |
| 7241 | kfree(els_data); |
| 7242 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7243 | |
| 7244 | return; |
| 7245 | } |
| 7246 | |
| 7247 | |
| 7248 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7249 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7250 | * @phba: pointer to lpfc hba data structure. |
| 7251 | * @pring: pointer to a SLI ring. |
| 7252 | * @vport: pointer to a host virtual N_Port data structure. |
| 7253 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 7254 | * |
| 7255 | * This routine is used for processing the IOCB associated with a unsolicited |
| 7256 | * event. It first determines whether there is an existing ndlp that matches |
| 7257 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 7258 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 7259 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 7260 | * of the discovery state machine. |
| 7261 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7262 | static void |
| 7263 | 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] | 7264 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7265 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7266 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7267 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7268 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7269 | uint32_t *payload; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7270 | uint32_t cmd, did, newnode; |
| 7271 | uint8_t rjt_exp, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7272 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7273 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7274 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7275 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7276 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7277 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7278 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 7279 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7280 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 7281 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7282 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7283 | did = icmd->un.rcvels.remoteID; |
| 7284 | if (icmd->ulpStatus) { |
| 7285 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7286 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 7287 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7288 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7289 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7290 | |
| 7291 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7292 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7293 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7294 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7295 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7296 | if (vport->load_flag & FC_UNLOADING) |
| 7297 | goto dropit; |
| 7298 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7299 | /* If NPort discovery is delayed drop incoming ELS */ |
| 7300 | if ((vport->fc_flag & FC_DISC_DELAYED) && |
| 7301 | (cmd != ELS_CMD_PLOGI)) |
| 7302 | goto dropit; |
| 7303 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7304 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7305 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7306 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7307 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7308 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7309 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7310 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7311 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7312 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7313 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7314 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7315 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7316 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 7317 | ndlp = lpfc_enable_node(vport, ndlp, |
| 7318 | NLP_STE_UNUSED_NODE); |
| 7319 | if (!ndlp) |
| 7320 | goto dropit; |
| 7321 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 7322 | newnode = 1; |
| 7323 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 7324 | ndlp->nlp_type |= NLP_FABRIC; |
| 7325 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 7326 | /* This is similar to the new node path */ |
| 7327 | ndlp = lpfc_nlp_get(ndlp); |
| 7328 | if (!ndlp) |
| 7329 | goto dropit; |
| 7330 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 7331 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7332 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7333 | |
| 7334 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7335 | |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7336 | /* |
| 7337 | * Do not process any unsolicited ELS commands |
| 7338 | * if the ndlp is in DEV_LOSS |
| 7339 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 7340 | shost = lpfc_shost_from_vport(vport); |
| 7341 | spin_lock_irq(shost->host_lock); |
| 7342 | if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) { |
| 7343 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7344 | goto dropit; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 7345 | } |
| 7346 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7347 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7348 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7349 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7350 | |
| 7351 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 7352 | cmd &= ELS_CMD_MASK; |
| 7353 | } |
| 7354 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7355 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7356 | "0112 ELS command x%x received from NPORT x%x " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7357 | "Data: x%x x%x x%x x%x\n", |
| 7358 | cmd, did, vport->port_state, vport->fc_flag, |
| 7359 | vport->fc_myDID, vport->fc_prevDID); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7360 | |
| 7361 | /* reject till our FLOGI completes */ |
| 7362 | if ((vport->port_state < LPFC_FABRIC_CFG_LINK) && |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7363 | (cmd != ELS_CMD_FLOGI)) { |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7364 | rjt_err = LSRJT_UNABLE_TPC; |
| 7365 | rjt_exp = LSEXP_NOTHING_MORE; |
| 7366 | goto lsrjt; |
| 7367 | } |
| 7368 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7369 | switch (cmd) { |
| 7370 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7371 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7372 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 7373 | did, vport->port_state, ndlp->nlp_flag); |
| 7374 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7375 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7376 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7377 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 7378 | (phba->pport->fc_flag & FC_PT2PT)) { |
| 7379 | vport->fc_prevDID = vport->fc_myDID; |
| 7380 | /* Our DID needs to be updated before registering |
| 7381 | * the vfi. This is done in lpfc_rcv_plogi but |
| 7382 | * that is called after the reg_vfi. |
| 7383 | */ |
| 7384 | vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo; |
| 7385 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7386 | "3312 Remote port assigned DID x%x " |
| 7387 | "%x\n", vport->fc_myDID, |
| 7388 | vport->fc_prevDID); |
| 7389 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7390 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7391 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7392 | |
| 7393 | /* If Nport discovery is delayed, reject PLOGIs */ |
| 7394 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 7395 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7396 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7397 | break; |
| 7398 | } |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7399 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7400 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 7401 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 7402 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 7403 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7404 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 7405 | break; |
| 7406 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7407 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7408 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7409 | spin_lock_irq(shost->host_lock); |
| 7410 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 7411 | spin_unlock_irq(shost->host_lock); |
| 7412 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7413 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7414 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7415 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7416 | break; |
| 7417 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7418 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7419 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 7420 | did, vport->port_state, ndlp->nlp_flag); |
| 7421 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7422 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7423 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7424 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7425 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7426 | break; |
| 7427 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7428 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7429 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 7430 | did, vport->port_state, ndlp->nlp_flag); |
| 7431 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7432 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7433 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7434 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7435 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7436 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7437 | break; |
| 7438 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7439 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7440 | break; |
| 7441 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7442 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7443 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 7444 | did, vport->port_state, ndlp->nlp_flag); |
| 7445 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7446 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7447 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7448 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7449 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7450 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7451 | break; |
| 7452 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7453 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7454 | break; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 7455 | case ELS_CMD_LCB: |
| 7456 | phba->fc_stat.elsRcvLCB++; |
| 7457 | lpfc_els_rcv_lcb(vport, elsiocb, ndlp); |
| 7458 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 7459 | case ELS_CMD_RDP: |
| 7460 | phba->fc_stat.elsRcvRDP++; |
| 7461 | lpfc_els_rcv_rdp(vport, elsiocb, ndlp); |
| 7462 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7463 | case ELS_CMD_RSCN: |
| 7464 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7465 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7466 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7467 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7468 | break; |
| 7469 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7470 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7471 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 7472 | did, vport->port_state, ndlp->nlp_flag); |
| 7473 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7474 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7475 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7476 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7477 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7478 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7479 | break; |
| 7480 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7481 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7482 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7483 | break; |
| 7484 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7485 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7486 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 7487 | did, vport->port_state, ndlp->nlp_flag); |
| 7488 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7489 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7490 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7491 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7492 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7493 | break; |
| 7494 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7495 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7496 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7497 | break; |
| 7498 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7499 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7500 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 7501 | did, vport->port_state, ndlp->nlp_flag); |
| 7502 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7503 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7504 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7505 | break; |
| 7506 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7507 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7508 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 7509 | did, vport->port_state, ndlp->nlp_flag); |
| 7510 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7511 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7512 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7513 | break; |
| 7514 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7515 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7516 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 7517 | did, vport->port_state, ndlp->nlp_flag); |
| 7518 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7519 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7520 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7521 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7522 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7523 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7524 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 7525 | did, vport->port_state, ndlp->nlp_flag); |
| 7526 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7527 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7528 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7529 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7530 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7531 | break; |
| 7532 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7533 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7534 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7535 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7536 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7537 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 7538 | did, vport->port_state, ndlp->nlp_flag); |
| 7539 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7540 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7541 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7542 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7543 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7544 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7545 | case ELS_CMD_RLS: |
| 7546 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7547 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 7548 | did, vport->port_state, ndlp->nlp_flag); |
| 7549 | |
| 7550 | phba->fc_stat.elsRcvRLS++; |
| 7551 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 7552 | if (newnode) |
| 7553 | lpfc_nlp_put(ndlp); |
| 7554 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7555 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7556 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7557 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 7558 | did, vport->port_state, ndlp->nlp_flag); |
| 7559 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7560 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7561 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7562 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7563 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7564 | break; |
| 7565 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7566 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7567 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 7568 | did, vport->port_state, ndlp->nlp_flag); |
| 7569 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7570 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7571 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7572 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7573 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7574 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7575 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7576 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7577 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 7578 | did, vport->port_state, ndlp->nlp_flag); |
| 7579 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7580 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7581 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7582 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7583 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7584 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7585 | case ELS_CMD_RTV: |
| 7586 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7587 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 7588 | did, vport->port_state, ndlp->nlp_flag); |
| 7589 | phba->fc_stat.elsRcvRTV++; |
| 7590 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 7591 | if (newnode) |
| 7592 | lpfc_nlp_put(ndlp); |
| 7593 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7594 | case ELS_CMD_RRQ: |
| 7595 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7596 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 7597 | did, vport->port_state, ndlp->nlp_flag); |
| 7598 | |
| 7599 | phba->fc_stat.elsRcvRRQ++; |
| 7600 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 7601 | if (newnode) |
| 7602 | lpfc_nlp_put(ndlp); |
| 7603 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7604 | case ELS_CMD_ECHO: |
| 7605 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7606 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 7607 | did, vport->port_state, ndlp->nlp_flag); |
| 7608 | |
| 7609 | phba->fc_stat.elsRcvECHO++; |
| 7610 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 7611 | if (newnode) |
| 7612 | lpfc_nlp_put(ndlp); |
| 7613 | break; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7614 | case ELS_CMD_REC: |
| 7615 | /* receive this due to exchange closed */ |
| 7616 | rjt_err = LSRJT_UNABLE_TPC; |
| 7617 | rjt_exp = LSEXP_INVALID_OX_RX; |
| 7618 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7619 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7620 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7621 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 7622 | cmd, did, vport->port_state); |
| 7623 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7624 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7625 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7626 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7627 | |
| 7628 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7629 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7630 | "0115 Unknown ELS command x%x " |
| 7631 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7632 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7633 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7634 | break; |
| 7635 | } |
| 7636 | |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7637 | lsrjt: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7638 | /* check if need to LS_RJT received ELS cmd */ |
| 7639 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7640 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7641 | stat.un.b.lsRjtRsnCode = rjt_err; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7642 | stat.un.b.lsRjtRsnCodeExp = rjt_exp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7643 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 7644 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7645 | } |
| 7646 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7647 | lpfc_nlp_put(elsiocb->context1); |
| 7648 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7649 | return; |
| 7650 | |
| 7651 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7652 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7653 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7654 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7655 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7656 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7657 | phba->fc_stat.elsRcvDrop++; |
| 7658 | } |
| 7659 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7660 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7661 | * 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] | 7662 | * @phba: pointer to lpfc hba data structure. |
| 7663 | * @pring: pointer to a SLI ring. |
| 7664 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 7665 | * |
| 7666 | * This routine is used to process an unsolicited event received from a SLI |
| 7667 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 7668 | * associated with the unsolicited event is done by invoking the routine |
| 7669 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 7670 | * SLI ring on which the unsolicited event was received. |
| 7671 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7672 | void |
| 7673 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 7674 | struct lpfc_iocbq *elsiocb) |
| 7675 | { |
| 7676 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7677 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7678 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7679 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 7680 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7681 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7682 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7683 | elsiocb->context2 = NULL; |
| 7684 | elsiocb->context3 = NULL; |
| 7685 | |
| 7686 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 7687 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 7688 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 7689 | (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 7690 | IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7691 | phba->fc_stat.NoRcvBuf++; |
| 7692 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7693 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 7694 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7695 | return; |
| 7696 | } |
| 7697 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7698 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 7699 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 7700 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 7701 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 7702 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7703 | else |
| 7704 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7705 | icmd->unsli3.rcvsli3.vpi); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7706 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7707 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7708 | /* If there are no BDEs associated |
| 7709 | * with this IOCB, there is nothing to do. |
| 7710 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7711 | if (icmd->ulpBdeCount == 0) |
| 7712 | return; |
| 7713 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7714 | /* type of ELS cmd is first 32bit word |
| 7715 | * in packet |
| 7716 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7717 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7718 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7719 | } else { |
| 7720 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 7721 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7722 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 7723 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7724 | } |
| 7725 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7726 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 7727 | /* |
| 7728 | * The different unsolicited event handlers would tell us |
| 7729 | * if they are done with "mp" by setting context2 to NULL. |
| 7730 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7731 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7732 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 7733 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7734 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7735 | |
| 7736 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7737 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7738 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7739 | elsiocb->context2 = bdeBuf2; |
| 7740 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7741 | /* free mp if we are done with it */ |
| 7742 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7743 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 7744 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7745 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7746 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7747 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7748 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7749 | void |
| 7750 | lpfc_start_fdmi(struct lpfc_vport *vport) |
| 7751 | { |
| 7752 | struct lpfc_hba *phba = vport->phba; |
| 7753 | struct lpfc_nodelist *ndlp; |
| 7754 | |
| 7755 | /* If this is the first time, allocate an ndlp and initialize |
| 7756 | * it. Otherwise, make sure the node is enabled and then do the |
| 7757 | * login. |
| 7758 | */ |
| 7759 | ndlp = lpfc_findnode_did(vport, FDMI_DID); |
| 7760 | if (!ndlp) { |
| 7761 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 7762 | if (ndlp) { |
| 7763 | lpfc_nlp_init(vport, ndlp, FDMI_DID); |
| 7764 | ndlp->nlp_type |= NLP_FABRIC; |
| 7765 | } else { |
| 7766 | return; |
| 7767 | } |
| 7768 | } |
| 7769 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 7770 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 7771 | |
| 7772 | if (ndlp) { |
| 7773 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 7774 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| 7775 | } |
| 7776 | } |
| 7777 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7778 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7779 | * 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] | 7780 | * @phba: pointer to lpfc hba data structure. |
| 7781 | * @vport: pointer to a virtual N_Port data structure. |
| 7782 | * |
| 7783 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 7784 | * State Change Request (SCR) for a @vport. This routine will create an |
| 7785 | * ndlp for the Name Server associated to the @vport if such node does |
| 7786 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 7787 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 7788 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 7789 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 7790 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7791 | void |
| 7792 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 7793 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7794 | struct lpfc_nodelist *ndlp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7795 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7796 | |
| 7797 | /* |
| 7798 | * If lpfc_delay_discovery parameter is set and the clean address |
| 7799 | * bit is cleared and fc fabric parameters chenged, delay FC NPort |
| 7800 | * discovery. |
| 7801 | */ |
| 7802 | spin_lock_irq(shost->host_lock); |
| 7803 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 7804 | spin_unlock_irq(shost->host_lock); |
James Smart | 1877570 | 2013-04-17 20:19:25 -0400 | [diff] [blame] | 7805 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 7806 | "3334 Delay fc port discovery for %d seconds\n", |
| 7807 | phba->fc_ratov); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7808 | mod_timer(&vport->delayed_disc_tmo, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7809 | jiffies + msecs_to_jiffies(1000 * phba->fc_ratov)); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7810 | return; |
| 7811 | } |
| 7812 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7813 | |
| 7814 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 7815 | if (!ndlp) { |
| 7816 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 7817 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7818 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7819 | lpfc_disc_start(vport); |
| 7820 | return; |
| 7821 | } |
| 7822 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7823 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7824 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7825 | return; |
| 7826 | } |
| 7827 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7828 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 7829 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 7830 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7831 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7832 | lpfc_disc_start(vport); |
| 7833 | return; |
| 7834 | } |
| 7835 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 7836 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7837 | "0348 NameServer login: node freed\n"); |
| 7838 | return; |
| 7839 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7840 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7841 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7842 | |
| 7843 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 7844 | |
| 7845 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 7846 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7847 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7848 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7849 | return; |
| 7850 | } |
| 7851 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7852 | if ((phba->cfg_fdmi_on > LPFC_FDMI_NO_SUPPORT) && |
| 7853 | (vport->load_flag & FC_ALLOW_FDMI)) |
| 7854 | lpfc_start_fdmi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7855 | } |
| 7856 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7857 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7858 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7859 | * @phba: pointer to lpfc hba data structure. |
| 7860 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 7861 | * |
| 7862 | * This routine is the completion callback function to register new vport |
| 7863 | * mailbox command. If the new vport mailbox command completes successfully, |
| 7864 | * the fabric registration login shall be performed on physical port (the |
| 7865 | * new vport created is actually a physical port, with VPI 0) or the port |
| 7866 | * login to Name Server for State Change Request (SCR) will be performed |
| 7867 | * on virtual port (real virtual port, with VPI greater than 0). |
| 7868 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7869 | static void |
| 7870 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 7871 | { |
| 7872 | struct lpfc_vport *vport = pmb->vport; |
| 7873 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7874 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 7875 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7876 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7877 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7878 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7879 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7880 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7881 | |
| 7882 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7883 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 7884 | "0915 Register VPI failed : Status: x%x" |
| 7885 | " upd bit: x%x \n", mb->mbxStatus, |
| 7886 | mb->un.varRegVpi.upd); |
| 7887 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 7888 | mb->un.varRegVpi.upd) |
| 7889 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7890 | |
| 7891 | switch (mb->mbxStatus) { |
| 7892 | case 0x11: /* unsupported feature */ |
| 7893 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7894 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7895 | /* giving up on vport registration */ |
| 7896 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 7897 | spin_lock_irq(shost->host_lock); |
| 7898 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 7899 | spin_unlock_irq(shost->host_lock); |
| 7900 | lpfc_can_disctmo(vport); |
| 7901 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7902 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 7903 | case 0x20: |
| 7904 | spin_lock_irq(shost->host_lock); |
| 7905 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 7906 | spin_unlock_irq(shost->host_lock); |
| 7907 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 7908 | pmb->vport = vport; |
| 7909 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 7910 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 7911 | MBX_NOWAIT); |
| 7912 | if (rc == MBX_NOT_FINISHED) { |
| 7913 | lpfc_printf_vlog(vport, |
| 7914 | KERN_ERR, LOG_MBOX, |
| 7915 | "2732 Failed to issue INIT_VPI" |
| 7916 | " mailbox command\n"); |
| 7917 | } else { |
| 7918 | lpfc_nlp_put(ndlp); |
| 7919 | return; |
| 7920 | } |
| 7921 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7922 | default: |
| 7923 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 7924 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7925 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7926 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7927 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7928 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7929 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 7930 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 7931 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7932 | lpfc_issue_init_vfi(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7933 | else |
| 7934 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7935 | break; |
| 7936 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7937 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7938 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 7939 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7940 | spin_unlock_irq(shost->host_lock); |
| 7941 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7942 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 7943 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7944 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7945 | /* |
| 7946 | * If the physical port is instantiated using |
| 7947 | * FDISC, do not start vport discovery. |
| 7948 | */ |
| 7949 | if (vport->port_state != LPFC_FDISC) |
| 7950 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7951 | lpfc_do_scr_ns_plogi(phba, vport); |
| 7952 | } |
| 7953 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7954 | lpfc_do_scr_ns_plogi(phba, vport); |
| 7955 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 7956 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7957 | /* Now, we decrement the ndlp reference count held for this |
| 7958 | * callback function |
| 7959 | */ |
| 7960 | lpfc_nlp_put(ndlp); |
| 7961 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7962 | mempool_free(pmb, phba->mbox_mem_pool); |
| 7963 | return; |
| 7964 | } |
| 7965 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7966 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7967 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7968 | * @phba: pointer to lpfc hba data structure. |
| 7969 | * @vport: pointer to a host virtual N_Port data structure. |
| 7970 | * @ndlp: pointer to a node-list data structure. |
| 7971 | * |
| 7972 | * This routine registers the @vport as a new virtual port with a HBA. |
| 7973 | * It is done through a registering vpi mailbox command. |
| 7974 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7975 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7976 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 7977 | struct lpfc_nodelist *ndlp) |
| 7978 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7979 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7980 | LPFC_MBOXQ_t *mbox; |
| 7981 | |
| 7982 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7983 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7984 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7985 | mbox->vport = vport; |
| 7986 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 7987 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7988 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7989 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7990 | /* mailbox command not success, decrement ndlp |
| 7991 | * reference count for this command |
| 7992 | */ |
| 7993 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7994 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7995 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7996 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 7997 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7998 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7999 | } |
| 8000 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8001 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 8002 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8003 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8004 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 8005 | return; |
| 8006 | |
| 8007 | mbox_err_exit: |
| 8008 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 8009 | spin_lock_irq(shost->host_lock); |
| 8010 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 8011 | spin_unlock_irq(shost->host_lock); |
| 8012 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8013 | } |
| 8014 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8015 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8016 | * 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] | 8017 | * @phba: pointer to lpfc hba data structure. |
| 8018 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8019 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8020 | **/ |
| 8021 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8022 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8023 | { |
| 8024 | struct lpfc_vport **vports; |
| 8025 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8026 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8027 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8028 | |
| 8029 | /* Treat this failure as linkdown for all vports */ |
| 8030 | link_state = phba->link_state; |
| 8031 | lpfc_linkdown(phba); |
| 8032 | phba->link_state = link_state; |
| 8033 | |
| 8034 | vports = lpfc_create_vport_work_array(phba); |
| 8035 | |
| 8036 | if (vports) { |
| 8037 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 8038 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 8039 | if (ndlp) |
| 8040 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 8041 | lpfc_els_flush_cmd(vports[i]); |
| 8042 | } |
| 8043 | lpfc_destroy_vport_work_array(phba, vports); |
| 8044 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8045 | } |
| 8046 | |
| 8047 | /** |
| 8048 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 8049 | * @phba: pointer to lpfc hba data structure. |
| 8050 | * |
| 8051 | * This routine abort all pending discovery commands and |
| 8052 | * start a timer to retry FLOGI for the physical port |
| 8053 | * discovery. |
| 8054 | **/ |
| 8055 | void |
| 8056 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 8057 | { |
| 8058 | struct lpfc_nodelist *ndlp; |
| 8059 | struct Scsi_Host *shost; |
| 8060 | |
| 8061 | /* Cancel the all vports retry delay retry timers */ |
| 8062 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8063 | |
| 8064 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 8065 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 8066 | if (!ndlp) |
| 8067 | return; |
| 8068 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8069 | shost = lpfc_shost_from_vport(phba->pport); |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8070 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000)); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8071 | spin_lock_irq(shost->host_lock); |
| 8072 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 8073 | spin_unlock_irq(shost->host_lock); |
| 8074 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 8075 | phba->pport->port_state = LPFC_FLOGI; |
| 8076 | return; |
| 8077 | } |
| 8078 | |
| 8079 | /** |
| 8080 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 8081 | * @phba: pointer to lpfc hba data structure. |
| 8082 | * @cmdiocb: pointer to FDISC command iocb. |
| 8083 | * @rspiocb: pointer to FDISC response iocb. |
| 8084 | * |
| 8085 | * This routine checks if a FLOGI is reguired for FDISC |
| 8086 | * to succeed. |
| 8087 | **/ |
| 8088 | static int |
| 8089 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 8090 | struct lpfc_iocbq *cmdiocb, |
| 8091 | struct lpfc_iocbq *rspiocb) |
| 8092 | { |
| 8093 | |
| 8094 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 8095 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 8096 | return 0; |
| 8097 | else |
| 8098 | return 1; |
| 8099 | } |
| 8100 | |
| 8101 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8102 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8103 | * @phba: pointer to lpfc hba data structure. |
| 8104 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8105 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8106 | * |
| 8107 | * This routine is the completion callback function to a Fabric Discover |
| 8108 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 8109 | * single threaded, each FDISC completion callback function will reset |
| 8110 | * the discovery timer for all vports such that the timers will not get |
| 8111 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 8112 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 8113 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 8114 | * assigned to the vport has been changed with the completion of the FDISC |
| 8115 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 8116 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 8117 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 8118 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 8119 | * Server for State Change Request (SCR). |
| 8120 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8121 | static void |
| 8122 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8123 | struct lpfc_iocbq *rspiocb) |
| 8124 | { |
| 8125 | struct lpfc_vport *vport = cmdiocb->vport; |
| 8126 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8127 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 8128 | struct lpfc_nodelist *np; |
| 8129 | struct lpfc_nodelist *next_np; |
| 8130 | IOCB_t *irsp = &rspiocb->iocb; |
| 8131 | struct lpfc_iocbq *piocb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8132 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 8133 | struct serv_parm *sp; |
| 8134 | uint8_t fabric_param_changed; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8135 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8136 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8137 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 8138 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 8139 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8140 | /* Since all FDISCs are being single threaded, we |
| 8141 | * must reset the discovery timer for ALL vports |
| 8142 | * waiting to send FDISC when one completes. |
| 8143 | */ |
| 8144 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 8145 | lpfc_set_disctmo(piocb->vport); |
| 8146 | } |
| 8147 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8148 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8149 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 8150 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 8151 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8152 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8153 | |
| 8154 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 8155 | lpfc_retry_pport_discovery(phba); |
| 8156 | goto out; |
| 8157 | } |
| 8158 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8159 | /* Check for retry */ |
| 8160 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 8161 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8162 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8163 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8164 | "0126 FDISC failed. (x%x/x%x)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8165 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8166 | goto fdisc_failed; |
| 8167 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8168 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8169 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8170 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8171 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8172 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8173 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 8174 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8175 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8176 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 8177 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8178 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 8179 | if (!prsp) |
| 8180 | goto out; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8181 | sp = prsp->virt + sizeof(uint32_t); |
| 8182 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 8183 | memcpy(&vport->fabric_portname, &sp->portName, |
| 8184 | sizeof(struct lpfc_name)); |
| 8185 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 8186 | sizeof(struct lpfc_name)); |
| 8187 | if (fabric_param_changed && |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8188 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 8189 | /* If our NportID changed, we need to ensure all |
| 8190 | * remaining NPORTs get unreg_login'ed so we can |
| 8191 | * issue unreg_vpi. |
| 8192 | */ |
| 8193 | list_for_each_entry_safe(np, next_np, |
| 8194 | &vport->fc_nodes, nlp_listp) { |
| 8195 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 8196 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 8197 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 8198 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8199 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8200 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8201 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8202 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8203 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 8204 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8205 | |
| 8206 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8207 | lpfc_sli4_unreg_all_rpis(vport); |
| 8208 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8209 | lpfc_mbx_unreg_vpi(vport); |
| 8210 | spin_lock_irq(shost->host_lock); |
| 8211 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8212 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8213 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8214 | else |
| 8215 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8216 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8217 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 8218 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 8219 | /* |
| 8220 | * Driver needs to re-reg VPI in order for f/w |
| 8221 | * to update the MAC address. |
| 8222 | */ |
| 8223 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 8224 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8225 | } |
| 8226 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 8227 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 8228 | lpfc_issue_init_vpi(vport); |
| 8229 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8230 | lpfc_register_new_vport(phba, vport, ndlp); |
| 8231 | else |
| 8232 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8233 | goto out; |
| 8234 | fdisc_failed: |
James Smart | c84163d | 2015-05-21 13:55:22 -0400 | [diff] [blame] | 8235 | if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS) |
| 8236 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8237 | /* Cancel discovery timer */ |
| 8238 | lpfc_can_disctmo(vport); |
| 8239 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8240 | out: |
| 8241 | lpfc_els_free_iocb(phba, cmdiocb); |
| 8242 | } |
| 8243 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8244 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8245 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8246 | * @vport: pointer to a virtual N_Port data structure. |
| 8247 | * @ndlp: pointer to a node-list data structure. |
| 8248 | * @retry: number of retries to the command IOCB. |
| 8249 | * |
| 8250 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 8251 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 8252 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 8253 | * IOCB will be sent off HBA at any given time. |
| 8254 | * |
| 8255 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 8256 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 8257 | * will be stored into the context1 field of the IOCB for the completion |
| 8258 | * callback function to the FDISC ELS command. |
| 8259 | * |
| 8260 | * Return code |
| 8261 | * 0 - Successfully issued fdisc iocb command |
| 8262 | * 1 - Failed to issue fdisc iocb command |
| 8263 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8264 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8265 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 8266 | uint8_t retry) |
| 8267 | { |
| 8268 | struct lpfc_hba *phba = vport->phba; |
| 8269 | IOCB_t *icmd; |
| 8270 | struct lpfc_iocbq *elsiocb; |
| 8271 | struct serv_parm *sp; |
| 8272 | uint8_t *pcmd; |
| 8273 | uint16_t cmdsize; |
| 8274 | int did = ndlp->nlp_DID; |
| 8275 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8276 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8277 | vport->port_state = LPFC_FDISC; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8278 | vport->fc_myDID = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8279 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 8280 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 8281 | ELS_CMD_FDISC); |
| 8282 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8283 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8284 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8285 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8286 | return 1; |
| 8287 | } |
| 8288 | |
| 8289 | icmd = &elsiocb->iocb; |
| 8290 | icmd->un.elsreq64.myID = 0; |
| 8291 | icmd->un.elsreq64.fl = 1; |
| 8292 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 8293 | /* |
| 8294 | * SLI3 ports require a different context type value than SLI4. |
| 8295 | * Catch SLI3 ports here and override the prep. |
| 8296 | */ |
| 8297 | if (phba->sli_rev == LPFC_SLI_REV3) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8298 | icmd->ulpCt_h = 1; |
| 8299 | icmd->ulpCt_l = 0; |
| 8300 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8301 | |
| 8302 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 8303 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 8304 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 8305 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 8306 | sp = (struct serv_parm *) pcmd; |
| 8307 | /* Setup CSPs accordingly for Fabric */ |
| 8308 | sp->cmn.e_d_tov = 0; |
| 8309 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 8310 | sp->cmn.virtual_fabric_support = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8311 | sp->cls1.classValid = 0; |
| 8312 | sp->cls2.seqDelivery = 1; |
| 8313 | sp->cls3.seqDelivery = 1; |
| 8314 | |
| 8315 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 8316 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 8317 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 8318 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 8319 | memcpy(pcmd, &vport->fc_portname, 8); |
| 8320 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 8321 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 8322 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 8323 | |
| 8324 | lpfc_set_disctmo(vport); |
| 8325 | |
| 8326 | phba->fc_stat.elsXmitFDISC++; |
| 8327 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 8328 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8329 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8330 | "Issue FDISC: did:x%x", |
| 8331 | did, 0, 0); |
| 8332 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8333 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 8334 | if (rc == IOCB_ERROR) { |
| 8335 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8336 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8337 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8338 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8339 | return 1; |
| 8340 | } |
| 8341 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8342 | return 0; |
| 8343 | } |
| 8344 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8345 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8346 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8347 | * @phba: pointer to lpfc hba data structure. |
| 8348 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8349 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8350 | * |
| 8351 | * This routine is the completion callback function to the issuing of a LOGO |
| 8352 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 8353 | * reference count held on ndlp for this completion function, indicating that |
| 8354 | * the reference to the ndlp is no long needed. Note that the |
| 8355 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 8356 | * callback function and an additional explicit ndlp reference decrementation |
| 8357 | * will trigger the actual release of the ndlp. |
| 8358 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8359 | static void |
| 8360 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8361 | struct lpfc_iocbq *rspiocb) |
| 8362 | { |
| 8363 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8364 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8365 | struct lpfc_nodelist *ndlp; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8366 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8367 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8368 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8369 | irsp = &rspiocb->iocb; |
| 8370 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8371 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 8372 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8373 | |
| 8374 | lpfc_els_free_iocb(phba, cmdiocb); |
| 8375 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8376 | |
| 8377 | /* Trigger the release of the ndlp after logo */ |
| 8378 | lpfc_nlp_put(ndlp); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8379 | |
| 8380 | /* NPIV LOGO completes to NPort <nlp_DID> */ |
| 8381 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8382 | "2928 NPIV LOGO completes to NPort x%x " |
| 8383 | "Data: x%x x%x x%x x%x\n", |
| 8384 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 8385 | irsp->ulpTimeout, vport->num_disc_nodes); |
| 8386 | |
| 8387 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 8388 | spin_lock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 8389 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8390 | vport->fc_flag &= ~FC_FABRIC; |
| 8391 | spin_unlock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 8392 | lpfc_can_disctmo(vport); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8393 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8394 | } |
| 8395 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8396 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8397 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8398 | * @vport: pointer to a virtual N_Port data structure. |
| 8399 | * @ndlp: pointer to a node-list data structure. |
| 8400 | * |
| 8401 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 8402 | * |
| 8403 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 8404 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 8405 | * will be stored into the context1 field of the IOCB for the completion |
| 8406 | * callback function to the LOGO ELS command. |
| 8407 | * |
| 8408 | * Return codes |
| 8409 | * 0 - Successfully issued logo off the @vport |
| 8410 | * 1 - Failed to issue logo off the @vport |
| 8411 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8412 | int |
| 8413 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 8414 | { |
| 8415 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8416 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8417 | struct lpfc_iocbq *elsiocb; |
| 8418 | uint8_t *pcmd; |
| 8419 | uint16_t cmdsize; |
| 8420 | |
| 8421 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 8422 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 8423 | ELS_CMD_LOGO); |
| 8424 | if (!elsiocb) |
| 8425 | return 1; |
| 8426 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8427 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 8428 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 8429 | pcmd += sizeof(uint32_t); |
| 8430 | |
| 8431 | /* Fill in LOGO payload */ |
| 8432 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 8433 | pcmd += sizeof(uint32_t); |
| 8434 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 8435 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8436 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8437 | "Issue LOGO npiv did:x%x flg:x%x", |
| 8438 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 8439 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8440 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 8441 | spin_lock_irq(shost->host_lock); |
| 8442 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 8443 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8444 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 8445 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8446 | spin_lock_irq(shost->host_lock); |
| 8447 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 8448 | spin_unlock_irq(shost->host_lock); |
| 8449 | lpfc_els_free_iocb(phba, elsiocb); |
| 8450 | return 1; |
| 8451 | } |
| 8452 | return 0; |
| 8453 | } |
| 8454 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8455 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8456 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8457 | * @ptr: holder for the timer function associated data. |
| 8458 | * |
| 8459 | * This routine is invoked by the fabric iocb block timer after |
| 8460 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 8461 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 8462 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 8463 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 8464 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 8465 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8466 | void |
| 8467 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 8468 | { |
| 8469 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 8470 | unsigned long iflags; |
| 8471 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8472 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8473 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 8474 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 8475 | if (!tmo_posted) |
| 8476 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 8477 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 8478 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8479 | if (!tmo_posted) |
| 8480 | lpfc_worker_wake_up(phba); |
| 8481 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8482 | } |
| 8483 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8484 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8485 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8486 | * @phba: pointer to lpfc hba data structure. |
| 8487 | * |
| 8488 | * This routine issues one fabric iocb from the driver internal list to |
| 8489 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 8490 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 8491 | * remove one pending fabric iocb from the driver internal list and invokes |
| 8492 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 8493 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8494 | static void |
| 8495 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 8496 | { |
| 8497 | struct lpfc_iocbq *iocb; |
| 8498 | unsigned long iflags; |
| 8499 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8500 | IOCB_t *cmd; |
| 8501 | |
| 8502 | repeat: |
| 8503 | iocb = NULL; |
| 8504 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8505 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8506 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 8507 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 8508 | list); |
| 8509 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8510 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8511 | atomic_inc(&phba->fabric_iocb_count); |
| 8512 | } |
| 8513 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8514 | if (iocb) { |
| 8515 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 8516 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 8517 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 8518 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8519 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 8520 | "Fabric sched1: ste:x%x", |
| 8521 | iocb->vport->port_state, 0, 0); |
| 8522 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8523 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8524 | |
| 8525 | if (ret == IOCB_ERROR) { |
| 8526 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 8527 | iocb->fabric_iocb_cmpl = NULL; |
| 8528 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 8529 | cmd = &iocb->iocb; |
| 8530 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 8531 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 8532 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 8533 | |
| 8534 | atomic_dec(&phba->fabric_iocb_count); |
| 8535 | goto repeat; |
| 8536 | } |
| 8537 | } |
| 8538 | |
| 8539 | return; |
| 8540 | } |
| 8541 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8542 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8543 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8544 | * @phba: pointer to lpfc hba data structure. |
| 8545 | * |
| 8546 | * This routine unblocks the issuing fabric iocb command. The function |
| 8547 | * will clear the fabric iocb block bit and then invoke the routine |
| 8548 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 8549 | * from the driver internal fabric iocb list. |
| 8550 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8551 | void |
| 8552 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 8553 | { |
| 8554 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 8555 | |
| 8556 | lpfc_resume_fabric_iocbs(phba); |
| 8557 | return; |
| 8558 | } |
| 8559 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8560 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8561 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8562 | * @phba: pointer to lpfc hba data structure. |
| 8563 | * |
| 8564 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 8565 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 8566 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 8567 | * fabric iocb will be issued out of the HBA. |
| 8568 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8569 | static void |
| 8570 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 8571 | { |
| 8572 | int blocked; |
| 8573 | |
| 8574 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8575 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8576 | if (!blocked) |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8577 | mod_timer(&phba->fabric_block_timer, |
| 8578 | jiffies + msecs_to_jiffies(100)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8579 | |
| 8580 | return; |
| 8581 | } |
| 8582 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8583 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8584 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8585 | * @phba: pointer to lpfc hba data structure. |
| 8586 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8587 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8588 | * |
| 8589 | * This routine is the callback function that is put to the fabric iocb's |
| 8590 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 8591 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 8592 | * function first restores and invokes the original iocb's callback function |
| 8593 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 8594 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 8595 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8596 | static void |
| 8597 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8598 | struct lpfc_iocbq *rspiocb) |
| 8599 | { |
| 8600 | struct ls_rjt stat; |
| 8601 | |
| 8602 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 8603 | BUG(); |
| 8604 | |
| 8605 | switch (rspiocb->iocb.ulpStatus) { |
| 8606 | case IOSTAT_NPORT_RJT: |
| 8607 | case IOSTAT_FABRIC_RJT: |
| 8608 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 8609 | lpfc_block_fabric_iocbs(phba); |
| 8610 | } |
| 8611 | break; |
| 8612 | |
| 8613 | case IOSTAT_NPORT_BSY: |
| 8614 | case IOSTAT_FABRIC_BSY: |
| 8615 | lpfc_block_fabric_iocbs(phba); |
| 8616 | break; |
| 8617 | |
| 8618 | case IOSTAT_LS_RJT: |
| 8619 | stat.un.lsRjtError = |
| 8620 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 8621 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 8622 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 8623 | lpfc_block_fabric_iocbs(phba); |
| 8624 | break; |
| 8625 | } |
| 8626 | |
| 8627 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 8628 | BUG(); |
| 8629 | |
| 8630 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 8631 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 8632 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 8633 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 8634 | |
| 8635 | atomic_dec(&phba->fabric_iocb_count); |
| 8636 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8637 | /* Post any pending iocbs to HBA */ |
| 8638 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8639 | } |
| 8640 | } |
| 8641 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8642 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8643 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8644 | * @phba: pointer to lpfc hba data structure. |
| 8645 | * @iocb: pointer to lpfc command iocb data structure. |
| 8646 | * |
| 8647 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 8648 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 8649 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 8650 | * any given time. As such, this function will first check to see whether there |
| 8651 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 8652 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 8653 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 8654 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 8655 | * |
| 8656 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 8657 | * order. The problem is caused by the construction of the "ready" boolen does |
| 8658 | * not include the condition that the internal fabric IOCB list is empty. As |
| 8659 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 8660 | * ahead of the fabric IOCBs in the internal list. |
| 8661 | * |
| 8662 | * Return code |
| 8663 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 8664 | * IOCB_ERROR - failed to issue fabric iocb |
| 8665 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8666 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8667 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 8668 | { |
| 8669 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8670 | int ready; |
| 8671 | int ret; |
| 8672 | |
| 8673 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 8674 | BUG(); |
| 8675 | |
| 8676 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8677 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 8678 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 8679 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8680 | if (ready) |
| 8681 | /* Increment fabric iocb count to hold the position */ |
| 8682 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8683 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8684 | if (ready) { |
| 8685 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 8686 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 8687 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 8688 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8689 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 8690 | "Fabric sched2: ste:x%x", |
| 8691 | iocb->vport->port_state, 0, 0); |
| 8692 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8693 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8694 | |
| 8695 | if (ret == IOCB_ERROR) { |
| 8696 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 8697 | iocb->fabric_iocb_cmpl = NULL; |
| 8698 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 8699 | atomic_dec(&phba->fabric_iocb_count); |
| 8700 | } |
| 8701 | } else { |
| 8702 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8703 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 8704 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8705 | ret = IOCB_SUCCESS; |
| 8706 | } |
| 8707 | return ret; |
| 8708 | } |
| 8709 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8710 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8711 | * 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] | 8712 | * @vport: pointer to a virtual N_Port data structure. |
| 8713 | * |
| 8714 | * This routine aborts all the IOCBs associated with a @vport from the |
| 8715 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 8716 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 8717 | * list, removes each IOCB associated with the @vport off the list, set the |
| 8718 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 8719 | * associated with the IOCB. |
| 8720 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8721 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8722 | { |
| 8723 | LIST_HEAD(completions); |
| 8724 | struct lpfc_hba *phba = vport->phba; |
| 8725 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8726 | |
| 8727 | spin_lock_irq(&phba->hbalock); |
| 8728 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 8729 | list) { |
| 8730 | |
| 8731 | if (piocb->vport != vport) |
| 8732 | continue; |
| 8733 | |
| 8734 | list_move_tail(&piocb->list, &completions); |
| 8735 | } |
| 8736 | spin_unlock_irq(&phba->hbalock); |
| 8737 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8738 | /* Cancel all the IOCBs from the completions list */ |
| 8739 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8740 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8741 | } |
| 8742 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8743 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8744 | * 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] | 8745 | * @ndlp: pointer to a node-list data structure. |
| 8746 | * |
| 8747 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 8748 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 8749 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 8750 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 8751 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 8752 | * associated with the IOCB. |
| 8753 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8754 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 8755 | { |
| 8756 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8757 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8758 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 8759 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8760 | |
| 8761 | spin_lock_irq(&phba->hbalock); |
| 8762 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 8763 | list) { |
| 8764 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 8765 | |
| 8766 | list_move_tail(&piocb->list, &completions); |
| 8767 | } |
| 8768 | } |
| 8769 | spin_unlock_irq(&phba->hbalock); |
| 8770 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8771 | /* Cancel all the IOCBs from the completions list */ |
| 8772 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8773 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8774 | } |
| 8775 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8776 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8777 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8778 | * @phba: pointer to lpfc hba data structure. |
| 8779 | * |
| 8780 | * This routine aborts all the IOCBs currently on the driver internal |
| 8781 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 8782 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 8783 | * list, removes IOCBs off the list, set the status feild to |
| 8784 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 8785 | * the IOCB. |
| 8786 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8787 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 8788 | { |
| 8789 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8790 | |
| 8791 | spin_lock_irq(&phba->hbalock); |
| 8792 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 8793 | spin_unlock_irq(&phba->hbalock); |
| 8794 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8795 | /* Cancel all the IOCBs from the completions list */ |
| 8796 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8797 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8798 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8799 | |
| 8800 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 8801 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport |
| 8802 | * @vport: pointer to lpfc vport data structure. |
| 8803 | * |
| 8804 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 8805 | * for an ndlp on removal. |
| 8806 | **/ |
| 8807 | void |
| 8808 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) |
| 8809 | { |
| 8810 | struct lpfc_hba *phba = vport->phba; |
| 8811 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 8812 | unsigned long iflag = 0; |
| 8813 | |
| 8814 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8815 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
| 8816 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 8817 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 8818 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) |
| 8819 | sglq_entry->ndlp = NULL; |
| 8820 | } |
| 8821 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 8822 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8823 | return; |
| 8824 | } |
| 8825 | |
| 8826 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8827 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 8828 | * @phba: pointer to lpfc hba data structure. |
| 8829 | * @axri: pointer to the els xri abort wcqe structure. |
| 8830 | * |
| 8831 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 8832 | * ELS aborted xri. |
| 8833 | **/ |
| 8834 | void |
| 8835 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 8836 | struct sli4_wcqe_xri_aborted *axri) |
| 8837 | { |
| 8838 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 8839 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8840 | uint16_t lxri = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 8841 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8842 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 8843 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 8844 | struct lpfc_nodelist *ndlp; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 8845 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8846 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8847 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8848 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8849 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 8850 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 8851 | if (sglq_entry->sli4_xritag == xri) { |
| 8852 | list_del(&sglq_entry->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 8853 | ndlp = sglq_entry->ndlp; |
| 8854 | sglq_entry->ndlp = NULL; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 8855 | spin_lock(&pring->ring_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8856 | list_add_tail(&sglq_entry->list, |
| 8857 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8858 | sglq_entry->state = SGL_FREED; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 8859 | spin_unlock(&pring->ring_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8860 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8861 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 8862 | lpfc_set_rrq_active(phba, ndlp, |
| 8863 | sglq_entry->sli4_lxritag, |
| 8864 | rxid, 1); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 8865 | |
| 8866 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 8867 | if (!(list_empty(&pring->txq))) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 8868 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8869 | return; |
| 8870 | } |
| 8871 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8872 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8873 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 8874 | if (lxri == NO_XRI) { |
| 8875 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8876 | return; |
| 8877 | } |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 8878 | spin_lock(&pring->ring_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8879 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8880 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 8881 | spin_unlock(&pring->ring_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8882 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8883 | return; |
| 8884 | } |
| 8885 | sglq_entry->state = SGL_XRI_ABORTED; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 8886 | spin_unlock(&pring->ring_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8887 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8888 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8889 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 8890 | |
| 8891 | /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. |
| 8892 | * @vport: pointer to virtual port object. |
| 8893 | * @ndlp: nodelist pointer for the impacted node. |
| 8894 | * |
| 8895 | * The driver calls this routine in response to an SLI4 XRI ABORT CQE |
| 8896 | * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, |
| 8897 | * the driver is required to send a LOGO to the remote node before it |
| 8898 | * attempts to recover its login to the remote node. |
| 8899 | */ |
| 8900 | void |
| 8901 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 8902 | struct lpfc_nodelist *ndlp) |
| 8903 | { |
| 8904 | struct Scsi_Host *shost; |
| 8905 | struct lpfc_hba *phba; |
| 8906 | unsigned long flags = 0; |
| 8907 | |
| 8908 | shost = lpfc_shost_from_vport(vport); |
| 8909 | phba = vport->phba; |
| 8910 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 8911 | lpfc_printf_log(phba, KERN_INFO, |
| 8912 | LOG_SLI, "3093 No rport recovery needed. " |
| 8913 | "rport in state 0x%x\n", ndlp->nlp_state); |
| 8914 | return; |
| 8915 | } |
| 8916 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8917 | "3094 Start rport recovery on shost id 0x%x " |
| 8918 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 8919 | "flags 0x%x\n", |
| 8920 | shost->host_no, ndlp->nlp_DID, |
| 8921 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 8922 | ndlp->nlp_flag); |
| 8923 | /* |
| 8924 | * The rport is not responding. Remove the FCP-2 flag to prevent |
| 8925 | * an ADISC in the follow-up recovery code. |
| 8926 | */ |
| 8927 | spin_lock_irqsave(shost->host_lock, flags); |
| 8928 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 8929 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 8930 | lpfc_issue_els_logo(vport, ndlp, 0); |
| 8931 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
| 8932 | } |
| 8933 | |