| 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; |
| 458 | LPFC_MBOXQ_t *mboxq; |
| 459 | struct lpfc_nodelist *ndlp; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 460 | struct lpfc_dmabuf *dmabuf; |
| 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 | |
| 474 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 475 | if (!dmabuf) { |
| 476 | rc = -ENOMEM; |
| 477 | goto fail; |
| 478 | } |
| 479 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 480 | if (!dmabuf->virt) { |
| 481 | rc = -ENOMEM; |
| 482 | goto fail_free_dmabuf; |
| 483 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 484 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 485 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 486 | if (!mboxq) { |
| 487 | rc = -ENOMEM; |
| 488 | goto fail_free_coherent; |
| 489 | } |
| 490 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 491 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 492 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 493 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 494 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 495 | mboxq->vport = vport; |
| 496 | mboxq->context1 = dmabuf; |
| 497 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 498 | if (rc == MBX_NOT_FINISHED) { |
| 499 | rc = -ENXIO; |
| 500 | goto fail_free_mbox; |
| 501 | } |
| 502 | return 0; |
| 503 | |
| 504 | fail_free_mbox: |
| 505 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 506 | fail_free_coherent: |
| 507 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 508 | fail_free_dmabuf: |
| 509 | kfree(dmabuf); |
| 510 | fail: |
| 511 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 512 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 513 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 514 | return rc; |
| 515 | } |
| 516 | |
| 517 | /** |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 518 | * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login |
| 519 | * @vport: pointer to a host virtual N_Port data structure. |
| 520 | * |
| 521 | * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for |
| 522 | * the @vport. This mailbox command is necessary for SLI4 port only. |
| 523 | * |
| 524 | * Return code |
| 525 | * 0 - successfully issued REG_VFI for @vport |
| 526 | * A failure code otherwise. |
| 527 | **/ |
| 528 | int |
| 529 | lpfc_issue_unreg_vfi(struct lpfc_vport *vport) |
| 530 | { |
| 531 | struct lpfc_hba *phba = vport->phba; |
| 532 | struct Scsi_Host *shost; |
| 533 | LPFC_MBOXQ_t *mboxq; |
| 534 | int rc; |
| 535 | |
| 536 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 537 | if (!mboxq) { |
| 538 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 539 | "2556 UNREG_VFI mbox allocation failed" |
| 540 | "HBA state x%x\n", phba->pport->port_state); |
| 541 | return -ENOMEM; |
| 542 | } |
| 543 | |
| 544 | lpfc_unreg_vfi(mboxq, vport); |
| 545 | mboxq->vport = vport; |
| 546 | mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl; |
| 547 | |
| 548 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 549 | if (rc == MBX_NOT_FINISHED) { |
| 550 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 551 | "2557 UNREG_VFI issue mbox failed rc x%x " |
| 552 | "HBA state x%x\n", |
| 553 | rc, phba->pport->port_state); |
| 554 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 555 | return -EIO; |
| 556 | } |
| 557 | |
| 558 | shost = lpfc_shost_from_vport(vport); |
| 559 | spin_lock_irq(shost->host_lock); |
| 560 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 561 | spin_unlock_irq(shost->host_lock); |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | /** |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 566 | * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean. |
| 567 | * @vport: pointer to a host virtual N_Port data structure. |
| 568 | * @sp: pointer to service parameter data structure. |
| 569 | * |
| 570 | * This routine is called from FLOGI/FDISC completion handler functions. |
| 571 | * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric |
| 572 | * node nodename is changed in the completion service parameter else return |
| 573 | * 0. This function also set flag in the vport data structure to delay |
| 574 | * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit |
| 575 | * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric |
| 576 | * node nodename is changed in the completion service parameter. |
| 577 | * |
| 578 | * Return code |
| 579 | * 0 - FCID and Fabric Nodename and Fabric portname is not changed. |
| 580 | * 1 - FCID or Fabric Nodename or Fabric portname is changed. |
| 581 | * |
| 582 | **/ |
| 583 | static uint8_t |
| 584 | lpfc_check_clean_addr_bit(struct lpfc_vport *vport, |
| 585 | struct serv_parm *sp) |
| 586 | { |
| 587 | uint8_t fabric_param_changed = 0; |
| 588 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 589 | |
| 590 | if ((vport->fc_prevDID != vport->fc_myDID) || |
| 591 | memcmp(&vport->fabric_portname, &sp->portName, |
| 592 | sizeof(struct lpfc_name)) || |
| 593 | memcmp(&vport->fabric_nodename, &sp->nodeName, |
| 594 | sizeof(struct lpfc_name))) |
| 595 | fabric_param_changed = 1; |
| 596 | |
| 597 | /* |
| 598 | * Word 1 Bit 31 in common service parameter is overloaded. |
| 599 | * Word 1 Bit 31 in FLOGI request is multiple NPort request |
| 600 | * Word 1 Bit 31 in FLOGI response is clean address bit |
| 601 | * |
| 602 | * If fabric parameter is changed and clean address bit is |
| 603 | * cleared delay nport discovery if |
| 604 | * - vport->fc_prevDID != 0 (not initial discovery) OR |
| 605 | * - lpfc_delay_discovery module parameter is set. |
| 606 | */ |
| 607 | if (fabric_param_changed && !sp->cmn.clean_address_bit && |
| 608 | (vport->fc_prevDID || lpfc_delay_discovery)) { |
| 609 | spin_lock_irq(shost->host_lock); |
| 610 | vport->fc_flag |= FC_DISC_DELAYED; |
| 611 | spin_unlock_irq(shost->host_lock); |
| 612 | } |
| 613 | |
| 614 | return fabric_param_changed; |
| 615 | } |
| 616 | |
| 617 | |
| 618 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 619 | * 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] | 620 | * @vport: pointer to a host virtual N_Port data structure. |
| 621 | * @ndlp: pointer to a node-list data structure. |
| 622 | * @sp: pointer to service parameter data structure. |
| 623 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 624 | * |
| 625 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 626 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 627 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 628 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 629 | * @vport against the previously assigned N_Port ID. If it is different from |
| 630 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 631 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 632 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 633 | * is invoked to register login to the fabric. |
| 634 | * |
| 635 | * Return code |
| 636 | * 0 - Success (currently, always return 0) |
| 637 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 638 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 639 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 640 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 641 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 642 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 643 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 644 | struct lpfc_nodelist *np; |
| 645 | struct lpfc_nodelist *next_np; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 646 | uint8_t fabric_param_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 647 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 648 | spin_lock_irq(shost->host_lock); |
| 649 | vport->fc_flag |= FC_FABRIC; |
| 650 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 651 | |
| 652 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 653 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 654 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 655 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 656 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 657 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 658 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 659 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 660 | spin_lock_irq(shost->host_lock); |
| 661 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 662 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 663 | } |
| 664 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 665 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 666 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 667 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 668 | ndlp->nlp_class_sup = 0; |
| 669 | if (sp->cls1.classValid) |
| 670 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 671 | if (sp->cls2.classValid) |
| 672 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 673 | if (sp->cls3.classValid) |
| 674 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 675 | if (sp->cls4.classValid) |
| 676 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 677 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 678 | sp->cmn.bbRcvSizeLsb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 679 | |
| 680 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 681 | memcpy(&vport->fabric_portname, &sp->portName, |
| 682 | sizeof(struct lpfc_name)); |
| 683 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 684 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 685 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 686 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 687 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 688 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 689 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 690 | LOG_ELS | LOG_VPORT, |
| 691 | "1816 FLOGI NPIV supported, " |
| 692 | "response data 0x%x\n", |
| 693 | sp->cmn.response_multiple_NPort); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 694 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 695 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 696 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 697 | } else { |
| 698 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 699 | to call reg_vnpid atleast for the physcial host */ |
| 700 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 701 | LOG_ELS | LOG_VPORT, |
| 702 | "1817 Fabric does not support NPIV " |
| 703 | "- configuring single port mode.\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 704 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 705 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 706 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 710 | /* |
| 711 | * For FC we need to do some special processing because of the SLI |
| 712 | * Port's default settings of the Common Service Parameters. |
| 713 | */ |
| 714 | if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) { |
| 715 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
| 716 | if ((phba->sli_rev == LPFC_SLI_REV4) && fabric_param_changed) |
| 717 | lpfc_unregister_fcf_prep(phba); |
| 718 | |
| 719 | /* This should just update the VFI CSPs*/ |
| 720 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 721 | lpfc_issue_reg_vfi(vport); |
| 722 | } |
| 723 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 724 | if (fabric_param_changed && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 725 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 726 | |
| 727 | /* If our NportID changed, we need to ensure all |
| 728 | * remaining NPORTs get unreg_login'ed. |
| 729 | */ |
| 730 | list_for_each_entry_safe(np, next_np, |
| 731 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 732 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 733 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 734 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 735 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 736 | continue; |
| 737 | spin_lock_irq(shost->host_lock); |
| 738 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 739 | spin_unlock_irq(shost->host_lock); |
| 740 | lpfc_unreg_rpi(vport, np); |
| 741 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 742 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 743 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 744 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 745 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 746 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 747 | spin_lock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 748 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 749 | spin_unlock_irq(shost->host_lock); |
| 750 | } |
James Smart | 27aa1b7 | 2012-05-09 21:18:49 -0400 | [diff] [blame] | 751 | |
| 752 | /* |
| 753 | * For SLI3 and SLI4, the VPI needs to be reregistered in |
| 754 | * response to this fabric parameter change event. |
| 755 | */ |
| 756 | spin_lock_irq(shost->host_lock); |
| 757 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 758 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 759 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 760 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 761 | /* |
| 762 | * Driver needs to re-reg VPI in order for f/w |
| 763 | * to update the MAC address. |
| 764 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 765 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 766 | lpfc_register_new_vport(phba, vport, ndlp); |
| 767 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 768 | } |
| 769 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 770 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 771 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 772 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 773 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 774 | lpfc_register_new_vport(phba, vport, ndlp); |
| 775 | else |
| 776 | lpfc_issue_fabric_reglogin(vport); |
| 777 | } else { |
| 778 | ndlp->nlp_type |= NLP_FABRIC; |
| 779 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 780 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 781 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 782 | lpfc_start_fdiscs(phba); |
| 783 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 784 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 785 | lpfc_issue_init_vpi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 786 | else { |
| 787 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 788 | "3135 Need register VFI: (x%x/%x)\n", |
| 789 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 790 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 791 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 792 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 793 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 794 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 795 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 796 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 797 | * 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] | 798 | * @vport: pointer to a host virtual N_Port data structure. |
| 799 | * @ndlp: pointer to a node-list data structure. |
| 800 | * @sp: pointer to service parameter data structure. |
| 801 | * |
| 802 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 803 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 804 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 805 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 806 | * the received N_Port Name lexicographically, this node shall assign local |
| 807 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 808 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 809 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 810 | * N_Port IDs. |
| 811 | * |
| 812 | * Return code |
| 813 | * 0 - Success |
| 814 | * -ENXIO - Fail |
| 815 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 816 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 817 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 818 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 819 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 820 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 821 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 822 | LPFC_MBOXQ_t *mbox; |
| 823 | int rc; |
| 824 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 825 | spin_lock_irq(shost->host_lock); |
| 826 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 827 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 828 | |
| 829 | phba->fc_edtov = FF_DEF_EDTOV; |
| 830 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 831 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 832 | sizeof(vport->fc_portname)); |
James Smart | 2eb6862 | 2012-09-29 11:32:27 -0400 | [diff] [blame] | 833 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 834 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 835 | if (rc >= 0) { |
| 836 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 837 | spin_lock_irq(shost->host_lock); |
| 838 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 839 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 840 | |
| 841 | /* |
| 842 | * N_Port ID cannot be 0, set our to LocalID the other |
| 843 | * side will be RemoteID. |
| 844 | */ |
| 845 | |
| 846 | /* not equal */ |
| 847 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 848 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 849 | |
| 850 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 851 | if (!mbox) |
| 852 | goto fail; |
| 853 | |
| 854 | lpfc_config_link(phba, mbox); |
| 855 | |
| 856 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 857 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 858 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 859 | if (rc == MBX_NOT_FINISHED) { |
| 860 | mempool_free(mbox, phba->mbox_mem_pool); |
| 861 | goto fail; |
| 862 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 863 | |
| 864 | /* |
| 865 | * For SLI4, the VFI/VPI are registered AFTER the |
| 866 | * Nport with the higher WWPN sends the PLOGI with |
| 867 | * an assigned NPortId. |
| 868 | */ |
| 869 | |
| 870 | /* not equal */ |
| 871 | if ((phba->sli_rev == LPFC_SLI_REV4) && rc) |
| 872 | lpfc_issue_reg_vfi(vport); |
| 873 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 874 | /* Decrement ndlp reference count indicating that ndlp can be |
| 875 | * safely released when other references to it are done. |
| 876 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 877 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 878 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 879 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 880 | if (!ndlp) { |
| 881 | /* |
| 882 | * Cannot find existing Fabric ndlp, so allocate a |
| 883 | * new one |
| 884 | */ |
| 885 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 886 | if (!ndlp) |
| 887 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 888 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 889 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 890 | ndlp = lpfc_enable_node(vport, ndlp, |
| 891 | NLP_STE_UNUSED_NODE); |
| 892 | if(!ndlp) |
| 893 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 897 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 898 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 899 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 900 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 901 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 902 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 903 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 904 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 905 | } else |
| 906 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 907 | * count indicating that ndlp can be released when other |
| 908 | * references to it are done. |
| 909 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 910 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 911 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 912 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 913 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 914 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 915 | spin_lock_irq(shost->host_lock); |
| 916 | vport->fc_flag |= FC_PT2PT; |
| 917 | spin_unlock_irq(shost->host_lock); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 918 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
| 919 | if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) { |
| 920 | lpfc_unregister_fcf_prep(phba); |
| 921 | |
| 922 | /* The FC_VFI_REGISTERED flag will get clear in the cmpl |
| 923 | * handler for unreg_vfi, but if we don't force the |
| 924 | * FC_VFI_REGISTERED flag then the reg_vfi mailbox could be |
| 925 | * built with the update bit set instead of just the vp bit to |
| 926 | * change the Nport ID. We need to have the vp set and the |
| 927 | * Upd cleared on topology changes. |
| 928 | */ |
| 929 | spin_lock_irq(shost->host_lock); |
| 930 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 931 | spin_unlock_irq(shost->host_lock); |
| 932 | phba->fc_topology_changed = 0; |
| 933 | lpfc_issue_reg_vfi(vport); |
| 934 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 935 | |
| 936 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 937 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 938 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 939 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 940 | return -ENXIO; |
| 941 | } |
| 942 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 943 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 944 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 945 | * @phba: pointer to lpfc hba data structure. |
| 946 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 947 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 948 | * |
| 949 | * This routine is the top-level completion callback function for issuing |
| 950 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 951 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 952 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 953 | * returning 1), the command IOCB will be released and function returned. |
| 954 | * If the retry attempt has been given up (possibly reach the maximum |
| 955 | * number of retries), one additional decrement of ndlp reference shall be |
| 956 | * invoked before going out after releasing the command IOCB. This will |
| 957 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 958 | * invoke one decrement of ndlp reference count). If no error reported in |
| 959 | * the IOCB status, the command Port ID field is used to determine whether |
| 960 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 961 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 962 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 963 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 964 | * specific topology completion conditions. |
| 965 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 966 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 967 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 968 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 969 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 970 | struct lpfc_vport *vport = cmdiocb->vport; |
| 971 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 972 | IOCB_t *irsp = &rspiocb->iocb; |
| 973 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 974 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 975 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 976 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 977 | int rc; |
| 978 | |
| 979 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 980 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 981 | /* One additional decrement on node reference count to |
| 982 | * trigger the release of the node |
| 983 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 984 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 985 | goto out; |
| 986 | } |
| 987 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 988 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 989 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 990 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 991 | vport->port_state); |
| 992 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 993 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 994 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 995 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 996 | * due to new FCF discovery |
| 997 | */ |
| 998 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 999 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 1000 | if (phba->link_state < LPFC_LINK_UP) |
| 1001 | goto stop_rr_fcf_flogi; |
| 1002 | if ((phba->fcoe_cvl_eventtag_attn == |
| 1003 | phba->fcoe_cvl_eventtag) && |
| 1004 | (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1005 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1006 | IOERR_SLI_ABORTED)) |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1007 | goto stop_rr_fcf_flogi; |
| 1008 | else |
| 1009 | phba->fcoe_cvl_eventtag_attn = |
| 1010 | phba->fcoe_cvl_eventtag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1011 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1012 | "2611 FLOGI failed on FCF (x%x), " |
| 1013 | "status:x%x/x%x, tmo:x%x, perform " |
| 1014 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1015 | phba->fcf.current_rec.fcf_indx, |
| 1016 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1017 | irsp->ulpTimeout); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1018 | lpfc_sli4_set_fcf_flogi_fail(phba, |
| 1019 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1020 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1021 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 1022 | if (rc) |
| 1023 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1024 | } |
| 1025 | |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1026 | stop_rr_fcf_flogi: |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1027 | /* FLOGI failure */ |
| 1028 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1029 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 1030 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1031 | irsp->ulpTimeout); |
| 1032 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1033 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1034 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1035 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1036 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1037 | /* FLOGI failure */ |
| 1038 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1039 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 1040 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1041 | irsp->ulpTimeout); |
| 1042 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1043 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1044 | spin_lock_irq(shost->host_lock); |
| 1045 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 1046 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1047 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1048 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1049 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 1050 | * alpa map would take too long otherwise. |
| 1051 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1052 | if (phba->alpa_map[0] == 0) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1053 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1054 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1055 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1056 | (vport->fc_prevDID != vport->fc_myDID) || |
| 1057 | phba->fc_topology_changed)) { |
| 1058 | if (vport->fc_flag & FC_VFI_REGISTERED) { |
| 1059 | if (phba->fc_topology_changed) { |
| 1060 | lpfc_unregister_fcf_prep(phba); |
| 1061 | spin_lock_irq(shost->host_lock); |
| 1062 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 1063 | spin_unlock_irq(shost->host_lock); |
| 1064 | phba->fc_topology_changed = 0; |
| 1065 | } else { |
| 1066 | lpfc_sli4_unreg_all_rpis(vport); |
| 1067 | } |
| 1068 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1069 | lpfc_issue_reg_vfi(vport); |
| 1070 | lpfc_nlp_put(ndlp); |
| 1071 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1072 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1073 | goto flogifail; |
| 1074 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1075 | spin_lock_irq(shost->host_lock); |
| 1076 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 1077 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1078 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1079 | |
| 1080 | /* |
| 1081 | * The FLogI succeeded. Sync the data for the CPU before |
| 1082 | * accessing it. |
| 1083 | */ |
| 1084 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 1085 | if (!prsp) |
| 1086 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1087 | sp = prsp->virt + sizeof(uint32_t); |
| 1088 | |
| 1089 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1090 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 1091 | "0101 FLOGI completes successfully, I/O tag:x%x, " |
| 1092 | "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] | 1093 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1094 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution, |
| 1095 | vport->port_state, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1096 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1097 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1098 | /* |
| 1099 | * If Common Service Parameters indicate Nport |
| 1100 | * we are point to point, if Fport we are Fabric. |
| 1101 | */ |
| 1102 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1103 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1104 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1105 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1106 | else { |
| 1107 | lpfc_printf_vlog(vport, KERN_ERR, |
| 1108 | LOG_FIP | LOG_ELS, |
| 1109 | "2831 FLOGI response with cleared Fabric " |
| 1110 | "bit fcf_index 0x%x " |
| 1111 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 1112 | "Fabric Name " |
| 1113 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 1114 | phba->fcf.current_rec.fcf_indx, |
| 1115 | phba->fcf.current_rec.switch_name[0], |
| 1116 | phba->fcf.current_rec.switch_name[1], |
| 1117 | phba->fcf.current_rec.switch_name[2], |
| 1118 | phba->fcf.current_rec.switch_name[3], |
| 1119 | phba->fcf.current_rec.switch_name[4], |
| 1120 | phba->fcf.current_rec.switch_name[5], |
| 1121 | phba->fcf.current_rec.switch_name[6], |
| 1122 | phba->fcf.current_rec.switch_name[7], |
| 1123 | phba->fcf.current_rec.fabric_name[0], |
| 1124 | phba->fcf.current_rec.fabric_name[1], |
| 1125 | phba->fcf.current_rec.fabric_name[2], |
| 1126 | phba->fcf.current_rec.fabric_name[3], |
| 1127 | phba->fcf.current_rec.fabric_name[4], |
| 1128 | phba->fcf.current_rec.fabric_name[5], |
| 1129 | phba->fcf.current_rec.fabric_name[6], |
| 1130 | phba->fcf.current_rec.fabric_name[7]); |
| 1131 | lpfc_nlp_put(ndlp); |
| 1132 | spin_lock_irq(&phba->hbalock); |
| 1133 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1134 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1135 | spin_unlock_irq(&phba->hbalock); |
| 1136 | goto out; |
| 1137 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1138 | if (!rc) { |
| 1139 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1140 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 1141 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 1142 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1143 | "2769 FLOGI to FCF (x%x) " |
| 1144 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1145 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1146 | spin_lock_irq(&phba->hbalock); |
| 1147 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1148 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1149 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1150 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1151 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1155 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1156 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1157 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1158 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1159 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1160 | |
| 1161 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1162 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1163 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1164 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1165 | IOERR_SLI_ABORTED) && |
| 1166 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1167 | IOERR_SLI_DOWN))) && |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1168 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 1169 | /* If FLOGI failed enable link interrupt. */ |
| 1170 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1171 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1172 | out: |
| 1173 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1174 | } |
| 1175 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1176 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1177 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1178 | * @vport: pointer to a host virtual N_Port data structure. |
| 1179 | * @ndlp: pointer to a node-list data structure. |
| 1180 | * @retry: number of retries to the command IOCB. |
| 1181 | * |
| 1182 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 1183 | * for a @vport. The initiator service parameters are put into the payload |
| 1184 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 1185 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 1186 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 1187 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 1188 | * |
| 1189 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1190 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1191 | * will be stored into the context1 field of the IOCB for the completion |
| 1192 | * callback function to the FLOGI ELS command. |
| 1193 | * |
| 1194 | * Return code |
| 1195 | * 0 - successfully issued flogi iocb for @vport |
| 1196 | * 1 - failed to issue flogi iocb for @vport |
| 1197 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1198 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1199 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1200 | uint8_t retry) |
| 1201 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1202 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1203 | struct serv_parm *sp; |
| 1204 | IOCB_t *icmd; |
| 1205 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1206 | uint8_t *pcmd; |
| 1207 | uint16_t cmdsize; |
| 1208 | uint32_t tmo; |
| 1209 | int rc; |
| 1210 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1211 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1212 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1213 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1214 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1215 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1216 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1217 | |
| 1218 | icmd = &elsiocb->iocb; |
| 1219 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1220 | |
| 1221 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1222 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1223 | pcmd += sizeof(uint32_t); |
| 1224 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1225 | sp = (struct serv_parm *) pcmd; |
| 1226 | |
| 1227 | /* Setup CSPs accordingly for Fabric */ |
| 1228 | sp->cmn.e_d_tov = 0; |
| 1229 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 1230 | sp->cmn.virtual_fabric_support = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1231 | sp->cls1.classValid = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | if (sp->cmn.fcphLow < FC_PH3) |
| 1233 | sp->cmn.fcphLow = FC_PH3; |
| 1234 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1235 | sp->cmn.fcphHigh = FC_PH3; |
| 1236 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 1237 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1238 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1239 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 1240 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1241 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1242 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1243 | /* Set the fcfi to the fcfi we registered with */ |
| 1244 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1245 | } |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1246 | /* Can't do SLI4 class2 without support sequence coalescing */ |
| 1247 | sp->cls2.classValid = 0; |
| 1248 | sp->cls2.seqDelivery = 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1249 | } else { |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1250 | /* Historical, setting sequential-delivery bit for SLI3 */ |
| 1251 | sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; |
| 1252 | sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1253 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 1254 | sp->cmn.request_multiple_Nport = 1; |
| 1255 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1256 | icmd->ulpCt_h = 1; |
| 1257 | icmd->ulpCt_l = 0; |
| 1258 | } else |
| 1259 | sp->cmn.request_multiple_Nport = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1260 | } |
| 1261 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1262 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1263 | icmd->un.elsreq64.myID = 0; |
| 1264 | icmd->un.elsreq64.fl = 1; |
| 1265 | } |
| 1266 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1267 | tmo = phba->fc_ratov; |
| 1268 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1269 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1270 | phba->fc_ratov = tmo; |
| 1271 | |
| 1272 | phba->fc_stat.elsXmitFLOGI++; |
| 1273 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1274 | |
| 1275 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1276 | "Issue FLOGI: opt:x%x", |
| 1277 | phba->sli3_options, 0, 0); |
| 1278 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1279 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1280 | if (rc == IOCB_ERROR) { |
| 1281 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1282 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1283 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1284 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1285 | } |
| 1286 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1287 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1288 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1289 | * @phba: pointer to lpfc hba data structure. |
| 1290 | * |
| 1291 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1292 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1293 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1294 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1295 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1296 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1297 | * |
| 1298 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1299 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1300 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1301 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1302 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1303 | { |
| 1304 | struct lpfc_sli_ring *pring; |
| 1305 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1306 | struct lpfc_nodelist *ndlp; |
| 1307 | IOCB_t *icmd; |
| 1308 | |
| 1309 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1310 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1311 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1312 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1313 | |
| 1314 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1315 | |
| 1316 | /* |
| 1317 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1318 | * searching for. |
| 1319 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1320 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1321 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1322 | icmd = &iocb->iocb; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1323 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1324 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1325 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1326 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1327 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1328 | } |
| 1329 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1330 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1331 | |
| 1332 | return 0; |
| 1333 | } |
| 1334 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1335 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1336 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1337 | * @vport: pointer to a host virtual N_Port data structure. |
| 1338 | * |
| 1339 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1340 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1341 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1342 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1343 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1344 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1345 | * @vport. |
| 1346 | * |
| 1347 | * Return code |
| 1348 | * 0 - failed to issue initial flogi for @vport |
| 1349 | * 1 - successfully issued initial flogi for @vport |
| 1350 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1351 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1352 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1353 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1354 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1355 | struct lpfc_nodelist *ndlp; |
| 1356 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1357 | vport->port_state = LPFC_FLOGI; |
| 1358 | lpfc_set_disctmo(vport); |
| 1359 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1360 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1361 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1362 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1363 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1364 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1365 | if (!ndlp) |
| 1366 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1367 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1368 | /* Set the node type */ |
| 1369 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1370 | /* Put ndlp onto node list */ |
| 1371 | lpfc_enqueue_node(vport, ndlp); |
| 1372 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1373 | /* re-setup ndlp without removing from node list */ |
| 1374 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1375 | if (!ndlp) |
| 1376 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1377 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1378 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1379 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1380 | /* This decrement of reference count to node shall kick off |
| 1381 | * the release of the node. |
| 1382 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1383 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1384 | return 0; |
| 1385 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1386 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1387 | } |
| 1388 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1389 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1390 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1391 | * @vport: pointer to a host virtual N_Port data structure. |
| 1392 | * |
| 1393 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1394 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1395 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1396 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1397 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1398 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1399 | * @vport. |
| 1400 | * |
| 1401 | * Return code |
| 1402 | * 0 - failed to issue initial fdisc for @vport |
| 1403 | * 1 - successfully issued initial fdisc for @vport |
| 1404 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1405 | int |
| 1406 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1407 | { |
| 1408 | struct lpfc_hba *phba = vport->phba; |
| 1409 | struct lpfc_nodelist *ndlp; |
| 1410 | |
| 1411 | /* First look for the Fabric ndlp */ |
| 1412 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1413 | if (!ndlp) { |
| 1414 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1415 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1416 | if (!ndlp) |
| 1417 | return 0; |
| 1418 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1419 | /* Put ndlp onto node list */ |
| 1420 | lpfc_enqueue_node(vport, ndlp); |
| 1421 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1422 | /* re-setup ndlp without removing from node list */ |
| 1423 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1424 | if (!ndlp) |
| 1425 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1426 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1427 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1428 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1429 | /* decrement node reference count to trigger the release of |
| 1430 | * the node. |
| 1431 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1432 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1433 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1434 | } |
| 1435 | return 1; |
| 1436 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1437 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1438 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1439 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1440 | * @vport: pointer to a host virtual N_Port data structure. |
| 1441 | * |
| 1442 | * This routine checks whether there are more remaining Port Logins |
| 1443 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1444 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1445 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1446 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1447 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1448 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1449 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1450 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1451 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1452 | if (vport->num_disc_nodes) |
| 1453 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1454 | |
| 1455 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1456 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1457 | "0232 Continue discovery with %d PLOGIs to go " |
| 1458 | "Data: x%x x%x x%x\n", |
| 1459 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1460 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1462 | if (vport->fc_flag & FC_NLP_MORE) |
| 1463 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 1464 | lpfc_els_disc_plogi(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1465 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1466 | return; |
| 1467 | } |
| 1468 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1469 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1470 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1471 | * @phba: pointer to lpfc hba data structure. |
| 1472 | * @prsp: pointer to response IOCB payload. |
| 1473 | * @ndlp: pointer to a node-list data structure. |
| 1474 | * |
| 1475 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1476 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1477 | * The following cases are considered N_Port confirmed: |
| 1478 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1479 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1480 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1481 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1482 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1483 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1484 | * on that node to release the RPI associated with the node; 2) if there is |
| 1485 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1486 | * into, a new node shall be allocated (or activated). In either case, the |
| 1487 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1488 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1489 | * its pointer returned as the confirmed node. |
| 1490 | * |
| 1491 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1492 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1493 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1494 | * into an inactive state on the vport node list and the vport node list |
| 1495 | * management algorithm does not allow two node with a same DID. |
| 1496 | * |
| 1497 | * Return code |
| 1498 | * pointer to the PLOGI N_Port @ndlp |
| 1499 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1500 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1501 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1502 | struct lpfc_nodelist *ndlp) |
| 1503 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1504 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1505 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1506 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1507 | struct lpfc_rport_data *rdata; |
| 1508 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1509 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1510 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1511 | uint32_t rc, keepDID = 0, keep_nlp_flag = 0; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1512 | uint16_t keep_nlp_state; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1513 | int put_node; |
| 1514 | int put_rport; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1515 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1516 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1517 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1518 | * by WWPN. Just return the ndlp that was given to us. |
| 1519 | */ |
| 1520 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1521 | return ndlp; |
| 1522 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1523 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1524 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1525 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1526 | /* 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] | 1527 | * we have for that ndlp. If not, we have some work to do. |
| 1528 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1529 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1530 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1531 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1532 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1533 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1534 | active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool, |
| 1535 | GFP_KERNEL); |
| 1536 | if (active_rrqs_xri_bitmap) |
| 1537 | memset(active_rrqs_xri_bitmap, 0, |
| 1538 | phba->cfg_rrq_xri_bitmap_sz); |
| 1539 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1540 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1541 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1542 | "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n", |
| 1543 | ndlp, ndlp->nlp_DID, new_ndlp); |
| 1544 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1545 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1546 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1547 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1548 | if (!rc) { |
| 1549 | if (active_rrqs_xri_bitmap) |
| 1550 | mempool_free(active_rrqs_xri_bitmap, |
| 1551 | phba->active_rrq_pool); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1552 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1553 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1554 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1555 | if (!new_ndlp) { |
| 1556 | if (active_rrqs_xri_bitmap) |
| 1557 | mempool_free(active_rrqs_xri_bitmap, |
| 1558 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1559 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1560 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1561 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1562 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1563 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1564 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1565 | if (!rc) { |
| 1566 | if (active_rrqs_xri_bitmap) |
| 1567 | mempool_free(active_rrqs_xri_bitmap, |
| 1568 | phba->active_rrq_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1569 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1570 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1571 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1572 | NLP_STE_UNUSED_NODE); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1573 | if (!new_ndlp) { |
| 1574 | if (active_rrqs_xri_bitmap) |
| 1575 | mempool_free(active_rrqs_xri_bitmap, |
| 1576 | phba->active_rrq_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1577 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1578 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1579 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1580 | if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap) |
| 1581 | memcpy(active_rrqs_xri_bitmap, |
| 1582 | new_ndlp->active_rrqs_xri_bitmap, |
| 1583 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1584 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1585 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1586 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1587 | 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 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1592 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1593 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1594 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1595 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1596 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1597 | memcpy(new_ndlp->active_rrqs_xri_bitmap, |
| 1598 | ndlp->active_rrqs_xri_bitmap, |
| 1599 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1600 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1601 | spin_lock_irq(shost->host_lock); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1602 | keep_nlp_flag = new_ndlp->nlp_flag; |
| 1603 | new_ndlp->nlp_flag = ndlp->nlp_flag; |
| 1604 | ndlp->nlp_flag = keep_nlp_flag; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1605 | spin_unlock_irq(shost->host_lock); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1606 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1607 | /* Set nlp_states accordingly */ |
| 1608 | keep_nlp_state = new_ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1609 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1610 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1611 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1612 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1613 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1614 | * to put ndlp on UNUSED list and try to free it. |
| 1615 | */ |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1616 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1617 | "3179 PLOGI confirm NEW: %x %x\n", |
| 1618 | new_ndlp->nlp_DID, keepDID); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1619 | |
| 1620 | /* Fix up the rport accordingly */ |
| 1621 | rport = ndlp->rport; |
| 1622 | if (rport) { |
| 1623 | rdata = rport->dd_data; |
| 1624 | if (rdata->pnode == ndlp) { |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1625 | /* break the link before dropping the ref */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1626 | ndlp->rport = NULL; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 1627 | lpfc_nlp_put(ndlp); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1628 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1629 | new_ndlp->rport = rport; |
| 1630 | } |
| 1631 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1632 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1633 | /* We shall actually free the ndlp with both nlp_DID and |
| 1634 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1635 | * nodelist never to be used. |
| 1636 | */ |
| 1637 | if (ndlp->nlp_DID == 0) { |
| 1638 | spin_lock_irq(&phba->ndlp_lock); |
| 1639 | NLP_SET_FREE_REQ(ndlp); |
| 1640 | spin_unlock_irq(&phba->ndlp_lock); |
| 1641 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1642 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1643 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1644 | ndlp->nlp_DID = keepDID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1645 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1646 | active_rrqs_xri_bitmap) |
| 1647 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1648 | active_rrqs_xri_bitmap, |
| 1649 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1650 | |
| 1651 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 1652 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1653 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1654 | else { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1655 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1656 | "3180 PLOGI confirm SWAP: %x %x\n", |
| 1657 | new_ndlp->nlp_DID, keepDID); |
| 1658 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1659 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1660 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1661 | /* Two ndlps cannot have the same did */ |
| 1662 | ndlp->nlp_DID = keepDID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1663 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1664 | active_rrqs_xri_bitmap) |
| 1665 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1666 | active_rrqs_xri_bitmap, |
| 1667 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1668 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1669 | /* Since we are switching over to the new_ndlp, |
| 1670 | * reset the old ndlp state |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1671 | */ |
| 1672 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 1673 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1674 | keep_nlp_state = NLP_STE_NPR_NODE; |
| 1675 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1676 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1677 | /* Fix up the rport accordingly */ |
| 1678 | rport = ndlp->rport; |
| 1679 | if (rport) { |
| 1680 | rdata = rport->dd_data; |
| 1681 | put_node = rdata->pnode != NULL; |
| 1682 | put_rport = ndlp->rport != NULL; |
| 1683 | rdata->pnode = NULL; |
| 1684 | ndlp->rport = NULL; |
| 1685 | if (put_node) |
| 1686 | lpfc_nlp_put(ndlp); |
| 1687 | if (put_rport) |
| 1688 | put_device(&rport->dev); |
| 1689 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1690 | } |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1691 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1692 | active_rrqs_xri_bitmap) |
| 1693 | mempool_free(active_rrqs_xri_bitmap, |
| 1694 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1695 | return new_ndlp; |
| 1696 | } |
| 1697 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1698 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1699 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1700 | * @vport: pointer to a host virtual N_Port data structure. |
| 1701 | * |
| 1702 | * This routine checks whether more Registration State Change |
| 1703 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1704 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1705 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1706 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1707 | * handling the RSCNs. |
| 1708 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1709 | void |
| 1710 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1711 | { |
| 1712 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1713 | |
| 1714 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1715 | /* |
| 1716 | * Check to see if more RSCNs came in while we were |
| 1717 | * processing this one. |
| 1718 | */ |
| 1719 | if (vport->fc_rscn_id_cnt || |
| 1720 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1721 | lpfc_els_handle_rscn(vport); |
| 1722 | else { |
| 1723 | spin_lock_irq(shost->host_lock); |
| 1724 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1725 | spin_unlock_irq(shost->host_lock); |
| 1726 | } |
| 1727 | } |
| 1728 | } |
| 1729 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1730 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1731 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. |
| 1732 | * @phba: pointer to lpfc hba data structure. |
| 1733 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1734 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1735 | * |
| 1736 | * This routine will call the clear rrq function to free the rrq and |
| 1737 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not |
| 1738 | * exist then the clear_rrq is still called because the rrq needs to |
| 1739 | * be freed. |
| 1740 | **/ |
| 1741 | |
| 1742 | static void |
| 1743 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1744 | struct lpfc_iocbq *rspiocb) |
| 1745 | { |
| 1746 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1747 | IOCB_t *irsp; |
| 1748 | struct lpfc_nodelist *ndlp; |
| 1749 | struct lpfc_node_rrq *rrq; |
| 1750 | |
| 1751 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1752 | rrq = cmdiocb->context_un.rrq; |
| 1753 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1754 | |
| 1755 | irsp = &rspiocb->iocb; |
| 1756 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1757 | "RRQ cmpl: status:x%x/x%x did:x%x", |
| 1758 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1759 | irsp->un.elsreq64.remoteID); |
| 1760 | |
| 1761 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
| 1762 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { |
| 1763 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1764 | "2882 RRQ completes to NPort x%x " |
| 1765 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1766 | irsp->un.elsreq64.remoteID, |
| 1767 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1768 | irsp->ulpIoTag); |
| 1769 | goto out; |
| 1770 | } |
| 1771 | |
| 1772 | /* rrq completes to NPort <nlp_DID> */ |
| 1773 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1774 | "2880 RRQ completes to NPort x%x " |
| 1775 | "Data: x%x x%x x%x x%x x%x\n", |
| 1776 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1777 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); |
| 1778 | |
| 1779 | if (irsp->ulpStatus) { |
| 1780 | /* Check for retry */ |
| 1781 | /* RRQ failed Don't print the vport to vport rjts */ |
| 1782 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1783 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1784 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1785 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1786 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1787 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", |
| 1788 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1789 | irsp->un.ulpWord[4]); |
| 1790 | } |
| 1791 | out: |
| 1792 | if (rrq) |
| 1793 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1794 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1795 | return; |
| 1796 | } |
| 1797 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1798 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1799 | * @phba: pointer to lpfc hba data structure. |
| 1800 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1801 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1802 | * |
| 1803 | * This routine is the completion callback function for issuing the Port |
| 1804 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1805 | * 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] | 1806 | * 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] | 1807 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1808 | * checked for error conditons. If there is error status reported, PLOGI |
| 1809 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1810 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1811 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1812 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1813 | * there are additional N_Port nodes with the vport that need to perform |
| 1814 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1815 | * PLOGIs. |
| 1816 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1817 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1818 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1819 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1820 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1821 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1822 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1823 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1824 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1825 | struct lpfc_dmabuf *prsp; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 1826 | int disc, rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1827 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1828 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1829 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1830 | |
| 1831 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1832 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1833 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1834 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1835 | irsp->un.elsreq64.remoteID); |
| 1836 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1837 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1838 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1839 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1840 | "0136 PLOGI completes to NPort x%x " |
| 1841 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1842 | irsp->un.elsreq64.remoteID, |
| 1843 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1844 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1845 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1846 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1847 | |
| 1848 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1849 | * is being used during discovery. |
| 1850 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1851 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1852 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1853 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1854 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1855 | rc = 0; |
| 1856 | |
| 1857 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1858 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1859 | "0102 PLOGI completes to NPort x%x " |
| 1860 | "Data: x%x x%x x%x x%x x%x\n", |
| 1861 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1862 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1863 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1864 | if (lpfc_els_chk_latt(vport)) { |
| 1865 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1866 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1867 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1868 | goto out; |
| 1869 | } |
| 1870 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1871 | if (irsp->ulpStatus) { |
| 1872 | /* Check for retry */ |
| 1873 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1874 | /* ELS command is being retried */ |
| 1875 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1876 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1877 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1878 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1879 | } |
| 1880 | goto out; |
| 1881 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1882 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1883 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1884 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1885 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1886 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1887 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1888 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1889 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1890 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1891 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1892 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1893 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1894 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1895 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1896 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1897 | } else { |
| 1898 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1899 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1900 | cmdiocb->context2)->list.next, |
| 1901 | struct lpfc_dmabuf, list); |
| 1902 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1903 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1904 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1905 | } |
| 1906 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1907 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1909 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1910 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1911 | if (vport->num_disc_nodes == 0) { |
| 1912 | spin_lock_irq(shost->host_lock); |
| 1913 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1914 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1915 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1916 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1917 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | out: |
| 1922 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1923 | return; |
| 1924 | } |
| 1925 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1926 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1927 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1928 | * @vport: pointer to a host virtual N_Port data structure. |
| 1929 | * @did: destination port identifier. |
| 1930 | * @retry: number of retries to the command IOCB. |
| 1931 | * |
| 1932 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1933 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1934 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1935 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1936 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1937 | * |
| 1938 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1939 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1940 | * will be stored into the context1 field of the IOCB for the completion |
| 1941 | * callback function to the PLOGI ELS command. |
| 1942 | * |
| 1943 | * Return code |
| 1944 | * 0 - Successfully issued a plogi for @vport |
| 1945 | * 1 - failed to issue a plogi for @vport |
| 1946 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1947 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1948 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1949 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1950 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1951 | struct serv_parm *sp; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1952 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1953 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1954 | uint8_t *pcmd; |
| 1955 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1956 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1957 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1958 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1959 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1960 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1961 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1962 | /* 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] | 1963 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1964 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1965 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1966 | if (!elsiocb) |
| 1967 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1968 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1969 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1970 | |
| 1971 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1972 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1973 | pcmd += sizeof(uint32_t); |
| 1974 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1975 | sp = (struct serv_parm *) pcmd; |
| 1976 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1977 | /* |
| 1978 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 1979 | * to device on remote loops work. |
| 1980 | */ |
| 1981 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 1982 | sp->cmn.altBbCredit = 1; |
| 1983 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1984 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1985 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1986 | |
| 1987 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1988 | sp->cmn.fcphHigh = FC_PH3; |
| 1989 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1990 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1991 | "Issue PLOGI: did:x%x", |
| 1992 | did, 0, 0); |
| 1993 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | phba->fc_stat.elsXmitPLOGI++; |
| 1995 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1996 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1997 | |
| 1998 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2000 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2001 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2002 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2003 | } |
| 2004 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2005 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2006 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2007 | * @phba: pointer to lpfc hba data structure. |
| 2008 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2009 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2010 | * |
| 2011 | * This routine is the completion callback function for a Process Login |
| 2012 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 2013 | * status. If there is error status reported, PRLI retry shall be attempted |
| 2014 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 2015 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 2016 | * ndlp to mark the PRLI completion. |
| 2017 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2018 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2019 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2020 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2021 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2022 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2023 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2024 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2025 | struct lpfc_nodelist *ndlp; |
| 2026 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2027 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2028 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2029 | |
| 2030 | irsp = &(rspiocb->iocb); |
| 2031 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2032 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2033 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2034 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2035 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2036 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2037 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 2038 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2039 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2040 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2041 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2042 | "0103 PRLI completes to NPort x%x " |
| 2043 | "Data: x%x x%x x%x x%x\n", |
| 2044 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2045 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2046 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2047 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2048 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2049 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2050 | goto out; |
| 2051 | |
| 2052 | if (irsp->ulpStatus) { |
| 2053 | /* Check for retry */ |
| 2054 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2055 | /* ELS command is being retried */ |
| 2056 | goto out; |
| 2057 | } |
| 2058 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2059 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2060 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 2061 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2062 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2064 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2065 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2066 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2067 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2068 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2069 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2070 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2071 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2072 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2073 | out: |
| 2074 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2075 | return; |
| 2076 | } |
| 2077 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2078 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2079 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2080 | * @vport: pointer to a host virtual N_Port data structure. |
| 2081 | * @ndlp: pointer to a node-list data structure. |
| 2082 | * @retry: number of retries to the command IOCB. |
| 2083 | * |
| 2084 | * This routine issues a Process Login (PRLI) ELS command for the |
| 2085 | * @vport. The PRLI service parameters are set up in the payload of the |
| 2086 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 2087 | * is put to the IOCB completion callback func field before invoking the |
| 2088 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 2089 | * |
| 2090 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2091 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2092 | * will be stored into the context1 field of the IOCB for the completion |
| 2093 | * callback function to the PRLI ELS command. |
| 2094 | * |
| 2095 | * Return code |
| 2096 | * 0 - successfully issued prli iocb command for @vport |
| 2097 | * 1 - failed to issue prli iocb command for @vport |
| 2098 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2099 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2100 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | uint8_t retry) |
| 2102 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2103 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2104 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2105 | PRLI *npr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2107 | uint8_t *pcmd; |
| 2108 | uint16_t cmdsize; |
| 2109 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2110 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2111 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2112 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2113 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2114 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2115 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2116 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2117 | |
| 2118 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2119 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2121 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | |
| 2123 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 2124 | npr = (PRLI *) pcmd; |
| 2125 | /* |
| 2126 | * If our firmware version is 3.20 or later, |
| 2127 | * set the following bits for FC-TAPE support. |
| 2128 | */ |
| 2129 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 2130 | npr->ConfmComplAllowed = 1; |
| 2131 | npr->Retry = 1; |
| 2132 | npr->TaskRetryIdReq = 1; |
| 2133 | } |
| 2134 | npr->estabImagePair = 1; |
| 2135 | npr->readXferRdyDis = 1; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 2136 | if (vport->cfg_first_burst_size) |
| 2137 | npr->writeXferRdyDis = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2138 | |
| 2139 | /* For FCP support */ |
| 2140 | npr->prliType = PRLI_FCP_TYPE; |
| 2141 | npr->initiatorFunc = 1; |
| 2142 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2143 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2144 | "Issue PRLI: did:x%x", |
| 2145 | ndlp->nlp_DID, 0, 0); |
| 2146 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2147 | phba->fc_stat.elsXmitPRLI++; |
| 2148 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2149 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2151 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2152 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2153 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2154 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2155 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2156 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2157 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2158 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2159 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2160 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2161 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | } |
| 2163 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2164 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2165 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2166 | * @vport: pointer to a host virtual N_Port data structure. |
| 2167 | * |
| 2168 | * This routine performs Registration State Change Notification (RSCN) |
| 2169 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 2170 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 2171 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 2172 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 2173 | * invoked to check and handle possible more RSCN came in during the period |
| 2174 | * of processing the current ones. |
| 2175 | **/ |
| 2176 | static void |
| 2177 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 2178 | { |
| 2179 | lpfc_can_disctmo(vport); |
| 2180 | |
| 2181 | /* RSCN discovery */ |
| 2182 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 2183 | if (vport->fc_npr_cnt) |
| 2184 | if (lpfc_els_disc_plogi(vport)) |
| 2185 | return; |
| 2186 | |
| 2187 | lpfc_end_rscn(vport); |
| 2188 | } |
| 2189 | |
| 2190 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2191 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2192 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 2193 | * |
| 2194 | * This function is called when the final ADISC is completed during discovery. |
| 2195 | * This function handles clearing link attention or issuing reg_vpi depending |
| 2196 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 2197 | * discovery. |
| 2198 | * This function is called with no locks held. |
| 2199 | **/ |
| 2200 | static void |
| 2201 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 2202 | { |
| 2203 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2204 | struct lpfc_hba *phba = vport->phba; |
| 2205 | |
| 2206 | /* |
| 2207 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 2208 | * and continue discovery. |
| 2209 | */ |
| 2210 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2211 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 2212 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | d454c91 | 2014-12-30 12:08:58 -0500 | [diff] [blame] | 2213 | /* The ADISCs are complete. Doesn't matter if they |
| 2214 | * succeeded or failed because the ADISC completion |
| 2215 | * routine guarantees to call the state machine and |
| 2216 | * the RPI is either unregistered (failed ADISC response) |
| 2217 | * or the RPI is still valid and the node is marked |
| 2218 | * mapped for a target. The exchanges should be in the |
| 2219 | * correct state. This code is specific to SLI3. |
| 2220 | */ |
| 2221 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2222 | lpfc_issue_reg_vpi(phba, vport); |
| 2223 | return; |
| 2224 | } |
| 2225 | /* |
| 2226 | * For SLI2, we need to set port_state to READY |
| 2227 | * and continue discovery. |
| 2228 | */ |
| 2229 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2230 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 2231 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2232 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 2233 | vport->num_disc_nodes = 0; |
| 2234 | /* go thru NPR list, issue ELS PLOGIs */ |
| 2235 | if (vport->fc_npr_cnt) |
| 2236 | lpfc_els_disc_plogi(vport); |
| 2237 | if (!vport->num_disc_nodes) { |
| 2238 | spin_lock_irq(shost->host_lock); |
| 2239 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2240 | spin_unlock_irq(shost->host_lock); |
| 2241 | lpfc_can_disctmo(vport); |
| 2242 | lpfc_end_rscn(vport); |
| 2243 | } |
| 2244 | } |
| 2245 | vport->port_state = LPFC_VPORT_READY; |
| 2246 | } else |
| 2247 | lpfc_rscn_disc(vport); |
| 2248 | } |
| 2249 | |
| 2250 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2251 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2252 | * @vport: pointer to a host virtual N_Port data structure. |
| 2253 | * |
| 2254 | * This routine determines whether there are more ndlps on a @vport |
| 2255 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 2256 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 2257 | * remaining nodes which need to have ADISC sent. |
| 2258 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2259 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2260 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2261 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2262 | if (vport->num_disc_nodes) |
| 2263 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2264 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2265 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2266 | "0210 Continue discovery with %d ADISCs to go " |
| 2267 | "Data: x%x x%x x%x\n", |
| 2268 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 2269 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2270 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2271 | if (vport->fc_flag & FC_NLP_MORE) { |
| 2272 | lpfc_set_disctmo(vport); |
| 2273 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 2274 | lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2275 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2276 | if (!vport->num_disc_nodes) |
| 2277 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2278 | return; |
| 2279 | } |
| 2280 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2281 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2282 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2283 | * @phba: pointer to lpfc hba data structure. |
| 2284 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2285 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2286 | * |
| 2287 | * This routine is the completion function for issuing the Address Discover |
| 2288 | * (ADISC) command. It first checks to see whether link went down during |
| 2289 | * the discovery process. If so, the node will be marked as node port |
| 2290 | * recovery for issuing discover IOCB by the link attention handler and |
| 2291 | * exit. Otherwise, the response status is checked. If error was reported |
| 2292 | * in the response status, the ADISC command shall be retried by invoking |
| 2293 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 2294 | * the response status, the state machine is invoked to set transition |
| 2295 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 2296 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2297 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2298 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2299 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2300 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2301 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2302 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2303 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2304 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2305 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2306 | |
| 2307 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2308 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2309 | |
| 2310 | irsp = &(rspiocb->iocb); |
| 2311 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2312 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2313 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2314 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 2315 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2316 | ndlp->nlp_DID); |
| 2317 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2318 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2319 | * is being used during discovery. |
| 2320 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2321 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2322 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2323 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2324 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2325 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2326 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2327 | "0104 ADISC completes to NPort x%x " |
| 2328 | "Data: x%x x%x x%x x%x x%x\n", |
| 2329 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2330 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2331 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2332 | if (lpfc_els_chk_latt(vport)) { |
| 2333 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2334 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2335 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | goto out; |
| 2337 | } |
| 2338 | |
| 2339 | if (irsp->ulpStatus) { |
| 2340 | /* Check for retry */ |
| 2341 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2342 | /* ELS command is being retried */ |
| 2343 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2344 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2346 | spin_unlock_irq(shost->host_lock); |
| 2347 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | } |
| 2349 | goto out; |
| 2350 | } |
| 2351 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2352 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2353 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2354 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2355 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2356 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2357 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2358 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2359 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2360 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2362 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2364 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2365 | /* Check to see if there are more ADISCs to be sent */ |
| 2366 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2367 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2368 | out: |
| 2369 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2370 | return; |
| 2371 | } |
| 2372 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2373 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2374 | * 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] | 2375 | * @vport: pointer to a virtual N_Port data structure. |
| 2376 | * @ndlp: pointer to a node-list data structure. |
| 2377 | * @retry: number of retries to the command IOCB. |
| 2378 | * |
| 2379 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2380 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2381 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2382 | * to issue the ADISC ELS command. |
| 2383 | * |
| 2384 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2385 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2386 | * will be stored into the context1 field of the IOCB for the completion |
| 2387 | * callback function to the ADISC ELS command. |
| 2388 | * |
| 2389 | * Return code |
| 2390 | * 0 - successfully issued adisc |
| 2391 | * 1 - failed to issue adisc |
| 2392 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2393 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2394 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2395 | uint8_t retry) |
| 2396 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2397 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2398 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2399 | ADISC *ap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2400 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2401 | uint8_t *pcmd; |
| 2402 | uint16_t cmdsize; |
| 2403 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2404 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2405 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2406 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2407 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2408 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2409 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2410 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2411 | |
| 2412 | /* For ADISC request, remainder of payload is service parameters */ |
| 2413 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2414 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2415 | |
| 2416 | /* Fill in ADISC payload */ |
| 2417 | ap = (ADISC *) pcmd; |
| 2418 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2419 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2420 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2421 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2423 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2424 | "Issue ADISC: did:x%x", |
| 2425 | ndlp->nlp_DID, 0, 0); |
| 2426 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2427 | phba->fc_stat.elsXmitADISC++; |
| 2428 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2429 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2431 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2432 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2433 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2434 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2435 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2436 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2438 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2439 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2440 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2441 | } |
| 2442 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2443 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2444 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2445 | * @phba: pointer to lpfc hba data structure. |
| 2446 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2447 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2448 | * |
| 2449 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2450 | * command. If no error status was reported from the LOGO response, the |
| 2451 | * state machine of the associated ndlp shall be invoked for transition with |
| 2452 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2453 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2454 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2455 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2456 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2457 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2458 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2459 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2460 | struct lpfc_vport *vport = ndlp->vport; |
| 2461 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2462 | IOCB_t *irsp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2463 | struct lpfcMboxq *mbox; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2464 | unsigned long flags; |
| 2465 | uint32_t skip_recovery = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2466 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2467 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2468 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2469 | |
| 2470 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2471 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2472 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2473 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2474 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2475 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2476 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2477 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2478 | ndlp->nlp_DID); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2479 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2480 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2481 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2482 | "0105 LOGO completes to NPort x%x " |
| 2483 | "Data: x%x x%x x%x x%x\n", |
| 2484 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2485 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2486 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2487 | if (lpfc_els_chk_latt(vport)) { |
| 2488 | skip_recovery = 1; |
| 2489 | goto out; |
| 2490 | } |
| 2491 | |
| 2492 | /* Check to see if link went down during discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2493 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2494 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2495 | * which should abort all outstanding IOs. |
| 2496 | */ |
| 2497 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2498 | NLP_EVT_DEVICE_RM); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2499 | skip_recovery = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2500 | goto out; |
| 2501 | } |
| 2502 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2503 | if (irsp->ulpStatus) { |
| 2504 | /* Check for retry */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2505 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2506 | /* ELS command is being retried */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2507 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2508 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2509 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2510 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2511 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2512 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2513 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2514 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2515 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2516 | if (lpfc_error_lost_link(irsp)) { |
| 2517 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2518 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2519 | } |
| 2520 | } |
| 2521 | |
| 2522 | /* Call state machine. This will unregister the rpi if needed. */ |
| 2523 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); |
| 2524 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2525 | out: |
| 2526 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2527 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ |
| 2528 | if ((vport->fc_flag & FC_PT2PT) && |
| 2529 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { |
| 2530 | phba->pport->fc_myDID = 0; |
| 2531 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2532 | if (mbox) { |
| 2533 | lpfc_config_link(phba, mbox); |
| 2534 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2535 | mbox->vport = vport; |
| 2536 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 2537 | MBX_NOT_FINISHED) { |
| 2538 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2539 | skip_recovery = 1; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2540 | } |
| 2541 | } |
| 2542 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2543 | |
| 2544 | /* |
| 2545 | * If the node is a target, the handling attempts to recover the port. |
| 2546 | * For any other port type, the rpi is unregistered as an implicit |
| 2547 | * LOGO. |
| 2548 | */ |
| 2549 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) { |
| 2550 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 2551 | spin_lock_irqsave(shost->host_lock, flags); |
| 2552 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 2553 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2554 | |
| 2555 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2556 | "3187 LOGO completes to NPort x%x: Start " |
| 2557 | "Recovery Data: x%x x%x x%x x%x\n", |
| 2558 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2559 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 2560 | vport->num_disc_nodes); |
| 2561 | lpfc_disc_start(vport); |
| 2562 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2563 | return; |
| 2564 | } |
| 2565 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2566 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2567 | * 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] | 2568 | * @vport: pointer to a virtual N_Port data structure. |
| 2569 | * @ndlp: pointer to a node-list data structure. |
| 2570 | * @retry: number of retries to the command IOCB. |
| 2571 | * |
| 2572 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2573 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2574 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2575 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2576 | * |
| 2577 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2578 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2579 | * will be stored into the context1 field of the IOCB for the completion |
| 2580 | * callback function to the LOGO ELS command. |
| 2581 | * |
| 2582 | * Return code |
| 2583 | * 0 - successfully issued logo |
| 2584 | * 1 - failed to issue logo |
| 2585 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2586 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2587 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2588 | uint8_t retry) |
| 2589 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2590 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2591 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2592 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2593 | uint8_t *pcmd; |
| 2594 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2595 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2596 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2597 | spin_lock_irq(shost->host_lock); |
| 2598 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2599 | spin_unlock_irq(shost->host_lock); |
| 2600 | return 0; |
| 2601 | } |
| 2602 | spin_unlock_irq(shost->host_lock); |
| 2603 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2604 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2605 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2606 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2607 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2608 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2610 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2611 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2612 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2613 | |
| 2614 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2615 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2616 | pcmd += sizeof(uint32_t); |
| 2617 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2618 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2619 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2620 | "Issue LOGO: did:x%x", |
| 2621 | ndlp->nlp_DID, 0, 0); |
| 2622 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2623 | /* |
| 2624 | * If we are issuing a LOGO, we may try to recover the remote NPort |
| 2625 | * by issuing a PLOGI later. Even though we issue ELS cmds by the |
| 2626 | * VPI, if we have a valid RPI, and that RPI gets unreg'ed while |
| 2627 | * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI |
| 2628 | * for that ELS cmd. To avoid this situation, lets get rid of the |
| 2629 | * RPI right now, before any ELS cmds are sent. |
| 2630 | */ |
| 2631 | spin_lock_irq(shost->host_lock); |
| 2632 | ndlp->nlp_flag |= NLP_ISSUE_LOGO; |
| 2633 | spin_unlock_irq(shost->host_lock); |
| 2634 | if (lpfc_unreg_rpi(vport, ndlp)) { |
| 2635 | lpfc_els_free_iocb(phba, elsiocb); |
| 2636 | return 0; |
| 2637 | } |
| 2638 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2639 | phba->fc_stat.elsXmitLOGO++; |
| 2640 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2641 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2642 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2643 | ndlp->nlp_flag &= ~NLP_ISSUE_LOGO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2644 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2645 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2646 | |
| 2647 | if (rc == IOCB_ERROR) { |
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 | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2650 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2651 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2652 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2653 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2654 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2655 | } |
| 2656 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2657 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2658 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2659 | * @phba: pointer to lpfc hba data structure. |
| 2660 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2661 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2662 | * |
| 2663 | * This routine is a generic completion callback function for ELS commands. |
| 2664 | * Specifically, it is the callback function which does not need to perform |
| 2665 | * any command specific operations. It is currently used by the ELS command |
| 2666 | * issuing routines for the ELS State Change Request (SCR), |
| 2667 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2668 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2669 | * certain debug loggings, this callback function simply invokes the |
| 2670 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2671 | * discovery process. |
| 2672 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2673 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2674 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2675 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2676 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2677 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2678 | IOCB_t *irsp; |
| 2679 | |
| 2680 | irsp = &rspiocb->iocb; |
| 2681 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2682 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2683 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2684 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2685 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2686 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2687 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2688 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2689 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2690 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2691 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2692 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2693 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2694 | return; |
| 2695 | } |
| 2696 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2697 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2698 | * 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] | 2699 | * @vport: pointer to a host virtual N_Port data structure. |
| 2700 | * @nportid: N_Port identifier to the remote node. |
| 2701 | * @retry: number of retries to the command IOCB. |
| 2702 | * |
| 2703 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2704 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2705 | * first search the @vport node list to find the matching ndlp. If no such |
| 2706 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2707 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2708 | * routine is invoked to send the SCR IOCB. |
| 2709 | * |
| 2710 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2711 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2712 | * will be stored into the context1 field of the IOCB for the completion |
| 2713 | * callback function to the SCR ELS command. |
| 2714 | * |
| 2715 | * Return code |
| 2716 | * 0 - Successfully issued scr command |
| 2717 | * 1 - Failed to issue scr command |
| 2718 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2719 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2720 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2721 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2722 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2723 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2724 | uint8_t *pcmd; |
| 2725 | uint16_t cmdsize; |
| 2726 | struct lpfc_nodelist *ndlp; |
| 2727 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2728 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2729 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2730 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2731 | if (!ndlp) { |
| 2732 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2733 | if (!ndlp) |
| 2734 | return 1; |
| 2735 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2736 | lpfc_enqueue_node(vport, ndlp); |
| 2737 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2738 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2739 | if (!ndlp) |
| 2740 | return 1; |
| 2741 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2743 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2744 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2745 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2746 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2747 | /* This will trigger the release of the node just |
| 2748 | * allocated |
| 2749 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2750 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2751 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2752 | } |
| 2753 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2754 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2755 | |
| 2756 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2757 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | |
| 2759 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2760 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2761 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2762 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2763 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2764 | "Issue SCR: did:x%x", |
| 2765 | ndlp->nlp_DID, 0, 0); |
| 2766 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2767 | phba->fc_stat.elsXmitSCR++; |
| 2768 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2769 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2770 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2771 | /* The additional lpfc_nlp_put will cause the following |
| 2772 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2773 | * the node. |
| 2774 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2775 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2777 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2778 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2779 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2780 | * trigger the release of node. |
| 2781 | */ |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 2782 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2783 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2784 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2785 | } |
| 2786 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2787 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2788 | * 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] | 2789 | * @vport: pointer to a host virtual N_Port data structure. |
| 2790 | * @nportid: N_Port identifier to the remote node. |
| 2791 | * @retry: number of retries to the command IOCB. |
| 2792 | * |
| 2793 | * This routine issues a Fibre Channel Address Resolution Response |
| 2794 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2795 | * is passed into the function. It first search the @vport node list to find |
| 2796 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2797 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2798 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2799 | * |
| 2800 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2801 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2802 | * will be stored into the context1 field of the IOCB for the completion |
| 2803 | * callback function to the PARPR ELS command. |
| 2804 | * |
| 2805 | * Return code |
| 2806 | * 0 - Successfully issued farpr command |
| 2807 | * 1 - Failed to issue farpr command |
| 2808 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2809 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2810 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2811 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2812 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2813 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2814 | FARP *fp; |
| 2815 | uint8_t *pcmd; |
| 2816 | uint32_t *lp; |
| 2817 | uint16_t cmdsize; |
| 2818 | struct lpfc_nodelist *ondlp; |
| 2819 | struct lpfc_nodelist *ndlp; |
| 2820 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2821 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2822 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2823 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2824 | if (!ndlp) { |
| 2825 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2826 | if (!ndlp) |
| 2827 | return 1; |
| 2828 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2829 | lpfc_enqueue_node(vport, ndlp); |
| 2830 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2831 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2832 | if (!ndlp) |
| 2833 | return 1; |
| 2834 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2835 | |
| 2836 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2837 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2838 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2839 | /* This will trigger the release of the node just |
| 2840 | * allocated |
| 2841 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2842 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2843 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2844 | } |
| 2845 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2846 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2847 | |
| 2848 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2849 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2850 | |
| 2851 | /* Fill in FARPR payload */ |
| 2852 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2853 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2854 | lp = (uint32_t *) pcmd; |
| 2855 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2856 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | fp->Rflags = 0; |
| 2858 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2859 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2860 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2861 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2862 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2863 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2864 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2865 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2866 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2867 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2868 | } |
| 2869 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2870 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2871 | "Issue FARPR: did:x%x", |
| 2872 | ndlp->nlp_DID, 0, 0); |
| 2873 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2874 | phba->fc_stat.elsXmitFARPR++; |
| 2875 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2876 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2877 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2878 | /* The additional lpfc_nlp_put will cause the following |
| 2879 | * lpfc_els_free_iocb routine to trigger the release of |
| 2880 | * the node. |
| 2881 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2882 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2883 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2884 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2885 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2886 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2887 | * trigger the release of the node. |
| 2888 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2889 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2890 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2891 | } |
| 2892 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2893 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2894 | * 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] | 2895 | * @vport: pointer to a host virtual N_Port data structure. |
| 2896 | * @nlp: pointer to a node-list data structure. |
| 2897 | * |
| 2898 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2899 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2900 | * removes the ELS retry event if it presents. In addition, if the |
| 2901 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2902 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2903 | * ADISC. |
| 2904 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2905 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2906 | 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] | 2907 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2908 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2909 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2910 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2911 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2912 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2913 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2914 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2915 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2916 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2917 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2918 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2919 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2920 | /* Decrement nlp reference count held for the delayed retry */ |
| 2921 | evtp = &nlp->els_retry_evt; |
| 2922 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2923 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2924 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2925 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2926 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2927 | spin_unlock_irq(shost->host_lock); |
| 2928 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2929 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2930 | /* Check if there are more ADISCs to be sent */ |
| 2931 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2932 | } else { |
| 2933 | /* Check if there are more PLOGIs to be sent */ |
| 2934 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2935 | if (vport->num_disc_nodes == 0) { |
| 2936 | spin_lock_irq(shost->host_lock); |
| 2937 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2938 | spin_unlock_irq(shost->host_lock); |
| 2939 | lpfc_can_disctmo(vport); |
| 2940 | lpfc_end_rscn(vport); |
| 2941 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2942 | } |
| 2943 | } |
| 2944 | } |
| 2945 | return; |
| 2946 | } |
| 2947 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2948 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2949 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2950 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2951 | * |
| 2952 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2953 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2954 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2955 | * adds the delayed events to the HBA work list and invokes the |
| 2956 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2957 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2958 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2959 | * reference to ndlp will still be available when the worker thread gets |
| 2960 | * to the event associated with the ndlp. |
| 2961 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2962 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2963 | lpfc_els_retry_delay(unsigned long ptr) |
| 2964 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2965 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2966 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2967 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2968 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2969 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2970 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2971 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2972 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2973 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2974 | return; |
| 2975 | } |
| 2976 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2977 | /* We need to hold the node by incrementing the reference |
| 2978 | * count until the queued work is done |
| 2979 | */ |
| 2980 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2981 | if (evtp->evt_arg1) { |
| 2982 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2983 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2984 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2985 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2986 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2987 | return; |
| 2988 | } |
| 2989 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2990 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2991 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2992 | * @ndlp: pointer to a node-list data structure. |
| 2993 | * |
| 2994 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2995 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2996 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2997 | * function according to the delayed ELS command to retry the command. |
| 2998 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2999 | void |
| 3000 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 3001 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3002 | struct lpfc_vport *vport = ndlp->vport; |
| 3003 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3004 | uint32_t cmd, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3005 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3006 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3007 | cmd = ndlp->nlp_last_elscmd; |
| 3008 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3009 | |
| 3010 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3011 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3012 | return; |
| 3013 | } |
| 3014 | |
| 3015 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3016 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 3017 | /* |
| 3018 | * If a discovery event readded nlp_delayfunc after timer |
| 3019 | * firing and before processing the timer, cancel the |
| 3020 | * nlp_delayfunc. |
| 3021 | */ |
| 3022 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3023 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3024 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3025 | |
| 3026 | switch (cmd) { |
| 3027 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3028 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3029 | break; |
| 3030 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3031 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3032 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3033 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3034 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3035 | break; |
| 3036 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3037 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3038 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3039 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3040 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3041 | break; |
| 3042 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3043 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3044 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3045 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3046 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3047 | break; |
| 3048 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3049 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3050 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3051 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3052 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3053 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3054 | case ELS_CMD_FDISC: |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3055 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
| 3056 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3057 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3058 | } |
| 3059 | return; |
| 3060 | } |
| 3061 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3062 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3063 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3064 | * @phba: pointer to lpfc hba data structure. |
| 3065 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3066 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3067 | * |
| 3068 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 3069 | * failed. The following ELS IOCBs use this function for retrying the command |
| 3070 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 3071 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 3072 | * returned error status, it makes the decision whether a retry shall be |
| 3073 | * issued for the command, and whether a retry shall be made immediately or |
| 3074 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 3075 | * is called to retry the command. In the later case, the ELS command shall |
| 3076 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 3077 | * ndlp for the delayed command issusing. |
| 3078 | * |
| 3079 | * Return code |
| 3080 | * 0 - No retry of els command is made |
| 3081 | * 1 - Immediate or delayed retry of els command is made |
| 3082 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3083 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3084 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3085 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3086 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3087 | struct lpfc_vport *vport = cmdiocb->vport; |
| 3088 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3089 | IOCB_t *irsp = &rspiocb->iocb; |
| 3090 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3091 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3092 | uint32_t *elscmd; |
| 3093 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3094 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3095 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3096 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3097 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3098 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3099 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3100 | /* Note: context2 may be 0 for internal driver abort |
| 3101 | * of delays ELS command. |
| 3102 | */ |
| 3103 | |
| 3104 | if (pcmd && pcmd->virt) { |
| 3105 | elscmd = (uint32_t *) (pcmd->virt); |
| 3106 | cmd = *elscmd++; |
| 3107 | } |
| 3108 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3109 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3110 | did = ndlp->nlp_DID; |
| 3111 | else { |
| 3112 | /* We should only hit this case for retrying PLOGI */ |
| 3113 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3114 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3115 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 3116 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3117 | return 1; |
| 3118 | } |
| 3119 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3120 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3121 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 3122 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 3123 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3124 | switch (irsp->ulpStatus) { |
| 3125 | case IOSTAT_FCP_RSP_ERROR: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3126 | break; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3127 | case IOSTAT_REMOTE_STOP: |
| 3128 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3129 | /* This IO was aborted by the target, we don't |
| 3130 | * know the rxid and because we did not send the |
| 3131 | * ABTS we cannot generate and RRQ. |
| 3132 | */ |
| 3133 | lpfc_set_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 3134 | cmdiocb->sli4_lxritag, 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3135 | } |
| 3136 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3137 | case IOSTAT_LOCAL_REJECT: |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3138 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3139 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3140 | if (cmd == ELS_CMD_FLOGI) { |
| 3141 | if (PCI_DEVICE_ID_HORNET == |
| 3142 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3143 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3144 | phba->pport->fc_myDID = 0; |
| 3145 | phba->alpa_map[0] = 0; |
| 3146 | phba->alpa_map[1] = 0; |
| 3147 | } |
| 3148 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3149 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3150 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3151 | retry = 1; |
| 3152 | break; |
| 3153 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3154 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3155 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3156 | "0124 Retry illegal cmd x%x " |
| 3157 | "retry:x%x delay:x%x\n", |
| 3158 | cmd, cmdiocb->retry, delay); |
| 3159 | retry = 1; |
| 3160 | /* All command's retry policy */ |
| 3161 | maxretry = 8; |
| 3162 | if (cmdiocb->retry > 2) |
| 3163 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3164 | break; |
| 3165 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3166 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3167 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3168 | retry = 1; |
| 3169 | if (cmdiocb->retry > 100) |
| 3170 | delay = 100; |
| 3171 | maxretry = 250; |
| 3172 | break; |
| 3173 | |
| 3174 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3175 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3176 | retry = 1; |
| 3177 | break; |
| 3178 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3179 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3180 | case IOERR_INVALID_RPI: |
James Smart | 5b5b36a | 2013-01-03 15:43:19 -0500 | [diff] [blame] | 3181 | if (cmd == ELS_CMD_PLOGI && |
| 3182 | did == NameServer_DID) { |
| 3183 | /* Continue forever if plogi to */ |
| 3184 | /* the nameserver fails */ |
| 3185 | maxretry = 0; |
| 3186 | delay = 100; |
| 3187 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3188 | retry = 1; |
| 3189 | break; |
| 3190 | } |
| 3191 | break; |
| 3192 | |
| 3193 | case IOSTAT_NPORT_RJT: |
| 3194 | case IOSTAT_FABRIC_RJT: |
| 3195 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 3196 | retry = 1; |
| 3197 | break; |
| 3198 | } |
| 3199 | break; |
| 3200 | |
| 3201 | case IOSTAT_NPORT_BSY: |
| 3202 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3203 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3204 | retry = 1; |
| 3205 | break; |
| 3206 | |
| 3207 | case IOSTAT_LS_RJT: |
| 3208 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 3209 | /* Added for Vendor specifc support |
| 3210 | * Just keep retrying for these Rsn / Exp codes |
| 3211 | */ |
| 3212 | switch (stat.un.b.lsRjtRsnCode) { |
| 3213 | case LSRJT_UNABLE_TPC: |
| 3214 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3215 | LSEXP_CMD_IN_PROGRESS) { |
| 3216 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3217 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3218 | maxretry = 48; |
| 3219 | } |
| 3220 | retry = 1; |
| 3221 | break; |
| 3222 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3223 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3224 | LSEXP_CANT_GIVE_DATA) { |
| 3225 | if (cmd == ELS_CMD_PLOGI) { |
| 3226 | delay = 1000; |
| 3227 | maxretry = 48; |
| 3228 | } |
| 3229 | retry = 1; |
| 3230 | break; |
| 3231 | } |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 3232 | if ((cmd == ELS_CMD_PLOGI) || |
| 3233 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3234 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3235 | maxretry = lpfc_max_els_tries + 1; |
| 3236 | retry = 1; |
| 3237 | break; |
| 3238 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3239 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3240 | (cmd == ELS_CMD_FDISC) && |
| 3241 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3242 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3243 | "0125 FDISC Failed (x%x). " |
| 3244 | "Fabric out of resources\n", |
| 3245 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3246 | lpfc_vport_set_state(vport, |
| 3247 | FC_VPORT_NO_FABRIC_RSCS); |
| 3248 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3249 | break; |
| 3250 | |
| 3251 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3252 | if ((cmd == ELS_CMD_PLOGI) || |
| 3253 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3254 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3255 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3256 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3257 | /* FDISC retry policy */ |
| 3258 | maxretry = 48; |
| 3259 | if (cmdiocb->retry >= 32) |
| 3260 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | } |
| 3262 | retry = 1; |
| 3263 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3264 | |
| 3265 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3266 | /* There are some cases where switches return this |
| 3267 | * error when they are not ready and should be returning |
| 3268 | * Logical Busy. We should delay every time. |
| 3269 | */ |
| 3270 | if (cmd == ELS_CMD_FDISC && |
| 3271 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 3272 | maxretry = 3; |
| 3273 | delay = 1000; |
| 3274 | retry = 1; |
| 3275 | break; |
| 3276 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3277 | case LSRJT_PROTOCOL_ERR: |
| 3278 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3279 | (cmd == ELS_CMD_FDISC) && |
| 3280 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 3281 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 3282 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3283 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3284 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3285 | "Fabric Detected Bad WWN\n", |
| 3286 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3287 | lpfc_vport_set_state(vport, |
| 3288 | FC_VPORT_FABRIC_REJ_WWN); |
| 3289 | } |
| 3290 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3291 | } |
| 3292 | break; |
| 3293 | |
| 3294 | case IOSTAT_INTERMED_RSP: |
| 3295 | case IOSTAT_BA_RJT: |
| 3296 | break; |
| 3297 | |
| 3298 | default: |
| 3299 | break; |
| 3300 | } |
| 3301 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3302 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3303 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3304 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3305 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3306 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 3307 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3308 | /* FLOGI retry policy */ |
| 3309 | retry = 1; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3310 | /* retry FLOGI forever */ |
James Smart | 6eae430 | 2015-04-07 15:07:23 -0400 | [diff] [blame] | 3311 | if (phba->link_flag != LS_LOOPBACK_MODE) |
| 3312 | maxretry = 0; |
| 3313 | else |
| 3314 | maxretry = 2; |
| 3315 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3316 | if (cmdiocb->retry >= 100) |
| 3317 | delay = 5000; |
| 3318 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3319 | delay = 1000; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3320 | } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) { |
| 3321 | /* retry FDISCs every second up to devloss */ |
| 3322 | retry = 1; |
| 3323 | maxretry = vport->cfg_devloss_tmo; |
| 3324 | delay = 1000; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3325 | } |
| 3326 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3327 | cmdiocb->retry++; |
| 3328 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3329 | phba->fc_stat.elsRetryExceeded++; |
| 3330 | retry = 0; |
| 3331 | } |
| 3332 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3333 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 3334 | retry = 0; |
| 3335 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3336 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3337 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 3338 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 3339 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 3340 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3341 | "2849 Stop retry ELS command " |
| 3342 | "x%x to remote NPORT x%x, " |
| 3343 | "Data: x%x x%x\n", cmd, did, |
| 3344 | cmdiocb->retry, delay); |
| 3345 | return 0; |
| 3346 | } |
| 3347 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3348 | |
| 3349 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3350 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3351 | "0107 Retry ELS command x%x to remote " |
| 3352 | "NPORT x%x Data: x%x x%x\n", |
| 3353 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3354 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3355 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 3356 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3357 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 3358 | IOERR_NO_RESOURCES))) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3359 | /* Don't reset timer for no resources */ |
| 3360 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3361 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3362 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3363 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3364 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3368 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3369 | phba->fc_stat.elsDelayRetry++; |
| 3370 | ndlp->nlp_retry = cmdiocb->retry; |
| 3371 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3372 | /* delay is specified in milliseconds */ |
| 3373 | mod_timer(&ndlp->nlp_delayfunc, |
| 3374 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3375 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3377 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3378 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3379 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3380 | if (cmd == ELS_CMD_PRLI) |
| 3381 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 3382 | NLP_STE_PRLI_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3383 | else |
| 3384 | lpfc_nlp_set_state(vport, ndlp, |
| 3385 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | ndlp->nlp_last_elscmd = cmd; |
| 3387 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3388 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3389 | } |
| 3390 | switch (cmd) { |
| 3391 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3392 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3393 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3394 | case ELS_CMD_FDISC: |
| 3395 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 3396 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3398 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3399 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3400 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3401 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3402 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3403 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3404 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -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, NLP_STE_ADISC_ISSUE); |
| 3408 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3409 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3411 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3412 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 3413 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3414 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3415 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3416 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3417 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3418 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3419 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3420 | } |
| 3421 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3422 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3423 | if (logerr) { |
| 3424 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3425 | "0137 No retry ELS command x%x to remote " |
| 3426 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 3427 | cmd, did, irsp->ulpStatus, |
| 3428 | irsp->un.ulpWord[4]); |
| 3429 | } |
| 3430 | else { |
| 3431 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3432 | "0108 No retry ELS command x%x to remote " |
| 3433 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 3434 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 3435 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3436 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3437 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3438 | } |
| 3439 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3440 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3441 | * 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] | 3442 | * @phba: pointer to lpfc hba data structure. |
| 3443 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3444 | * |
| 3445 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3446 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3447 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3448 | * response of the command IOCB. If so, it will be released before releasing |
| 3449 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3450 | * |
| 3451 | * Return code |
| 3452 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3453 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3454 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3455 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3456 | { |
| 3457 | struct lpfc_dmabuf *buf_ptr; |
| 3458 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3459 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3460 | if (!list_empty(&buf_ptr1->list)) { |
| 3461 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3462 | struct lpfc_dmabuf, |
| 3463 | list); |
| 3464 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3465 | kfree(buf_ptr); |
| 3466 | } |
| 3467 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3468 | kfree(buf_ptr1); |
| 3469 | return 0; |
| 3470 | } |
| 3471 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3472 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3473 | * 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] | 3474 | * @phba: pointer to lpfc hba data structure. |
| 3475 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3476 | * |
| 3477 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3478 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3479 | * pool. |
| 3480 | * |
| 3481 | * Return code |
| 3482 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3483 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3484 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3485 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3486 | { |
| 3487 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3488 | kfree(buf_ptr); |
| 3489 | return 0; |
| 3490 | } |
| 3491 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3492 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3493 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3494 | * @phba: pointer to lpfc hba data structure. |
| 3495 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3496 | * |
| 3497 | * This routine frees a command IOCB and its associated resources. The |
| 3498 | * command IOCB data structure contains the reference to various associated |
| 3499 | * resources, these fields must be set to NULL if the associated reference |
| 3500 | * not present: |
| 3501 | * context1 - reference to ndlp |
| 3502 | * context2 - reference to cmd |
| 3503 | * context2->next - reference to rsp |
| 3504 | * context3 - reference to bpl |
| 3505 | * |
| 3506 | * It first properly decrements the reference count held on ndlp for the |
| 3507 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3508 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3509 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3510 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3511 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3512 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3513 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3514 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3515 | * |
| 3516 | * Return code |
| 3517 | * 0 - Success (currently, always return 0) |
| 3518 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3519 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3520 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3521 | { |
| 3522 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3523 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3524 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3525 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3526 | if (ndlp) { |
| 3527 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3528 | lpfc_nlp_put(ndlp); |
| 3529 | |
| 3530 | /* If the ndlp is not being used by another discovery |
| 3531 | * thread, free it. |
| 3532 | */ |
| 3533 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3534 | /* If ndlp is being used by another discovery |
| 3535 | * thread, just clear NLP_DEFER_RM |
| 3536 | */ |
| 3537 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3538 | } |
| 3539 | } |
| 3540 | else |
| 3541 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3542 | elsiocb->context1 = NULL; |
| 3543 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3544 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3545 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3546 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3547 | /* Firmware could still be in progress of DMAing |
| 3548 | * payload, so don't free data buffer till after |
| 3549 | * a hbeat. |
| 3550 | */ |
| 3551 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3552 | buf_ptr = elsiocb->context2; |
| 3553 | elsiocb->context2 = NULL; |
| 3554 | if (buf_ptr) { |
| 3555 | buf_ptr1 = NULL; |
| 3556 | spin_lock_irq(&phba->hbalock); |
| 3557 | if (!list_empty(&buf_ptr->list)) { |
| 3558 | list_remove_head(&buf_ptr->list, |
| 3559 | buf_ptr1, struct lpfc_dmabuf, |
| 3560 | list); |
| 3561 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3562 | list_add_tail(&buf_ptr1->list, |
| 3563 | &phba->elsbuf); |
| 3564 | phba->elsbuf_cnt++; |
| 3565 | } |
| 3566 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3567 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3568 | phba->elsbuf_cnt++; |
| 3569 | spin_unlock_irq(&phba->hbalock); |
| 3570 | } |
| 3571 | } else { |
| 3572 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3573 | lpfc_els_free_data(phba, buf_ptr1); |
| 3574 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | if (elsiocb->context3) { |
| 3578 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3579 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3580 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3581 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | return 0; |
| 3583 | } |
| 3584 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3585 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3586 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3587 | * @phba: pointer to lpfc hba data structure. |
| 3588 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3589 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3590 | * |
| 3591 | * This routine is the completion callback function to the Logout (LOGO) |
| 3592 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3593 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3594 | * release the ndlp if it has the last reference remaining (reference count |
| 3595 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3596 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3597 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3598 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3599 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3600 | * IOCB data structure. |
| 3601 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3602 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3603 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3604 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3605 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3606 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3607 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3608 | IOCB_t *irsp; |
| 3609 | |
| 3610 | irsp = &rspiocb->iocb; |
| 3611 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3612 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3613 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3614 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3615 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3616 | "0109 ACC to LOGO completes to NPort x%x " |
| 3617 | "Data: x%x x%x x%x\n", |
| 3618 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3619 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3620 | |
| 3621 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3622 | /* NPort Recovery mode or node is just allocated */ |
| 3623 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3624 | /* If the ndlp is being used by another discovery |
| 3625 | * thread, just unregister the RPI. |
| 3626 | */ |
| 3627 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3628 | } else { |
| 3629 | /* Indicate the node has already released, should |
| 3630 | * not reference to it from within lpfc_els_free_iocb. |
| 3631 | */ |
| 3632 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3633 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3634 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3635 | |
| 3636 | /* |
| 3637 | * 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] | 3638 | * At this point, the driver is done so release the IOCB |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3639 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3640 | lpfc_els_free_iocb(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3641 | } |
| 3642 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3643 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3644 | * 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] | 3645 | * @phba: pointer to lpfc hba data structure. |
| 3646 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3647 | * |
| 3648 | * This routine is the completion callback function for unregister default |
| 3649 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3650 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3651 | * decrements the ndlp reference count held for this completion callback |
| 3652 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3653 | * whether there is only one reference left on the ndlp. If so, it will |
| 3654 | * perform one more decrement and trigger the release of the ndlp. |
| 3655 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3656 | void |
| 3657 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3658 | { |
| 3659 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3660 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3661 | |
| 3662 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3663 | pmb->context2 = NULL; |
| 3664 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3665 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3666 | kfree(mp); |
| 3667 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3668 | if (ndlp) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3669 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3670 | "0006 rpi%x DID:%x flg:%x %d map:%x %p\n", |
| 3671 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
| 3672 | atomic_read(&ndlp->kref.refcount), |
| 3673 | ndlp->nlp_usg_map, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3674 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 3675 | lpfc_nlp_put(ndlp); |
| 3676 | /* This is the end of the default RPI cleanup logic for |
| 3677 | * this ndlp. If no other discovery threads are using |
| 3678 | * this ndlp, free all resources associated with it. |
| 3679 | */ |
| 3680 | lpfc_nlp_not_used(ndlp); |
| 3681 | } else { |
| 3682 | lpfc_drop_node(ndlp->vport, ndlp); |
| 3683 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3684 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3685 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3686 | return; |
| 3687 | } |
| 3688 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3689 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3690 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3691 | * @phba: pointer to lpfc hba data structure. |
| 3692 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3693 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3694 | * |
| 3695 | * This routine is the completion callback function for ELS Response IOCB |
| 3696 | * command. In normal case, this callback function just properly sets the |
| 3697 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3698 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3699 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3700 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3701 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3702 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3703 | * are currently referring it. |
| 3704 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3705 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3706 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3707 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3708 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3709 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3710 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3711 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3712 | IOCB_t *irsp; |
| 3713 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3714 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3715 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3716 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3717 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3718 | irsp = &rspiocb->iocb; |
| 3719 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3720 | if (cmdiocb->context_un.mbox) |
| 3721 | mbox = cmdiocb->context_un.mbox; |
| 3722 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3723 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3724 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3725 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3726 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3727 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3728 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3729 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3730 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3731 | */ |
| 3732 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3733 | ls_rjt = 1; |
| 3734 | } |
| 3735 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3736 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3737 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3738 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3739 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3740 | if (mp) { |
| 3741 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3742 | kfree(mp); |
| 3743 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3744 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3745 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3746 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3747 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3748 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3749 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3750 | /* Indicate the node has already released, |
| 3751 | * should not reference to it from within |
| 3752 | * the routine lpfc_els_free_iocb. |
| 3753 | */ |
| 3754 | cmdiocb->context1 = NULL; |
| 3755 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3756 | goto out; |
| 3757 | } |
| 3758 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3759 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3760 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3761 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3762 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3763 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3764 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3765 | "0110 ELS response tag x%x completes " |
| 3766 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3767 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3768 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3769 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3770 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3771 | if (mbox) { |
| 3772 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3773 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3774 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3775 | /* Increment reference count to ndlp to hold the |
| 3776 | * reference to ndlp for the callback function. |
| 3777 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3778 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3779 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3780 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3781 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3782 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3783 | } |
| 3784 | else { |
| 3785 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3786 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3787 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3788 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3789 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3790 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3791 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3792 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3793 | else |
| 3794 | /* Decrement the ndlp reference count we |
| 3795 | * set for this failed mailbox command. |
| 3796 | */ |
| 3797 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3798 | |
| 3799 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3800 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3801 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3802 | "Data: x%x x%x x%x\n", |
| 3803 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3804 | ndlp->nlp_rpi); |
| 3805 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3806 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3807 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3808 | /* Indicate node has already been released, |
| 3809 | * should not reference to it from within |
| 3810 | * the routine lpfc_els_free_iocb. |
| 3811 | */ |
| 3812 | cmdiocb->context1 = NULL; |
| 3813 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3814 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3815 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3816 | if (!lpfc_error_lost_link(irsp) && |
| 3817 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3818 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3819 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3820 | /* Indicate node has already been |
| 3821 | * released, should not reference |
| 3822 | * to it from within the routine |
| 3823 | * lpfc_els_free_iocb. |
| 3824 | */ |
| 3825 | cmdiocb->context1 = NULL; |
| 3826 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3827 | } |
| 3828 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3829 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3830 | if (mp) { |
| 3831 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3832 | kfree(mp); |
| 3833 | } |
| 3834 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3835 | } |
| 3836 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3837 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3838 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3839 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3840 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3841 | |
| 3842 | /* If the node is not being used by another discovery thread, |
| 3843 | * and we are sending a reject, we are done with it. |
| 3844 | * Release driver reference count here and free associated |
| 3845 | * resources. |
| 3846 | */ |
| 3847 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3848 | if (lpfc_nlp_not_used(ndlp)) |
| 3849 | /* Indicate node has already been released, |
| 3850 | * should not reference to it from within |
| 3851 | * the routine lpfc_els_free_iocb. |
| 3852 | */ |
| 3853 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3854 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3855 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3856 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3857 | return; |
| 3858 | } |
| 3859 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3860 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3861 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3862 | * @vport: pointer to a host virtual N_Port data structure. |
| 3863 | * @flag: the els command code to be accepted. |
| 3864 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3865 | * @ndlp: pointer to a node-list data structure. |
| 3866 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3867 | * |
| 3868 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3869 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3870 | * specific ACC response command to be issued and invokes the |
| 3871 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3872 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3873 | * field of the IOCB for the completion callback function to issue the |
| 3874 | * mailbox command to the HBA later when callback is invoked. |
| 3875 | * |
| 3876 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3877 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3878 | * will be stored into the context1 field of the IOCB for the completion |
| 3879 | * callback function to the corresponding response ELS IOCB command. |
| 3880 | * |
| 3881 | * Return code |
| 3882 | * 0 - Successfully issued acc response |
| 3883 | * 1 - Failed to issue acc response |
| 3884 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3885 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3886 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3887 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3888 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3889 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3890 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3891 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3892 | IOCB_t *icmd; |
| 3893 | IOCB_t *oldcmd; |
| 3894 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3895 | uint8_t *pcmd; |
| 3896 | uint16_t cmdsize; |
| 3897 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3898 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3900 | oldcmd = &oldiocb->iocb; |
| 3901 | |
| 3902 | switch (flag) { |
| 3903 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3904 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3905 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3906 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3907 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3908 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3909 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3910 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3911 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3912 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3913 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3914 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3915 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3916 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3917 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3918 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3919 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3920 | |
| 3921 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3922 | "Issue ACC: did:x%x flg:x%x", |
| 3923 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3924 | break; |
| 3925 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3926 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3927 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3928 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3929 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3930 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3931 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3932 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3933 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3934 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3935 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3936 | |
| 3937 | if (mbox) |
| 3938 | elsiocb->context_un.mbox = mbox; |
| 3939 | |
| 3940 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3941 | pcmd += sizeof(uint32_t); |
| 3942 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3943 | |
| 3944 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3945 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3946 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3947 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3948 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3949 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3950 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3951 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3952 | if (!elsiocb) |
| 3953 | return 1; |
| 3954 | |
| 3955 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3956 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3957 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3958 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3959 | |
| 3960 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3961 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3962 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3963 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3964 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3965 | |
| 3966 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3967 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3968 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3969 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3970 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3971 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3972 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3973 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3974 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3975 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 3976 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x " |
| 3977 | "fc_flag x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3978 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3979 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 3980 | ndlp->nlp_rpi, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3981 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3982 | spin_lock_irq(shost->host_lock); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 3983 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 3984 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND)) |
| 3985 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3986 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3987 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3988 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3989 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3990 | } |
| 3991 | |
| 3992 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3993 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3994 | if (rc == IOCB_ERROR) { |
| 3995 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3996 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3997 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3998 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3999 | } |
| 4000 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4001 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4002 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4003 | * @vport: pointer to a virtual N_Port data structure. |
| 4004 | * @rejectError: |
| 4005 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4006 | * @ndlp: pointer to a node-list data structure. |
| 4007 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4008 | * |
| 4009 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 4010 | * command. If a @mbox pointer is passed in, it will be put into the |
| 4011 | * context_un.mbox field of the IOCB for the completion callback function |
| 4012 | * to issue to the HBA later. |
| 4013 | * |
| 4014 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4015 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4016 | * will be stored into the context1 field of the IOCB for the completion |
| 4017 | * callback function to the reject response ELS IOCB command. |
| 4018 | * |
| 4019 | * Return code |
| 4020 | * 0 - Successfully issued reject response |
| 4021 | * 1 - Failed to issue reject response |
| 4022 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4023 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4024 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4025 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 4026 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4027 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4028 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4029 | IOCB_t *icmd; |
| 4030 | IOCB_t *oldcmd; |
| 4031 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4032 | uint8_t *pcmd; |
| 4033 | uint16_t cmdsize; |
| 4034 | int rc; |
| 4035 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4036 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4037 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4038 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4039 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4040 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4041 | |
| 4042 | icmd = &elsiocb->iocb; |
| 4043 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4044 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4045 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4046 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4047 | |
| 4048 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4049 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4050 | *((uint32_t *) (pcmd)) = rejectError; |
| 4051 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4052 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4053 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4054 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4055 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4056 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4057 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 4058 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4059 | "rpi x%x\n", |
| 4060 | rejectError, elsiocb->iotag, |
| 4061 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 4062 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4063 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4064 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 4065 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 4066 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4067 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4068 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4069 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4070 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4071 | if (rc == IOCB_ERROR) { |
| 4072 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4073 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4075 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | } |
| 4077 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4078 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4079 | * 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] | 4080 | * @vport: pointer to a virtual N_Port data structure. |
| 4081 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4082 | * @ndlp: pointer to a node-list data structure. |
| 4083 | * |
| 4084 | * This routine prepares and issues an Accept (ACC) response to Address |
| 4085 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 4086 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4087 | * |
| 4088 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4089 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4090 | * will be stored into the context1 field of the IOCB for the completion |
| 4091 | * callback function to the ADISC Accept response ELS IOCB command. |
| 4092 | * |
| 4093 | * Return code |
| 4094 | * 0 - Successfully issued acc adisc response |
| 4095 | * 1 - Failed to issue adisc acc response |
| 4096 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4097 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4098 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 4099 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4100 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4101 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4102 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4103 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4105 | uint8_t *pcmd; |
| 4106 | uint16_t cmdsize; |
| 4107 | int rc; |
| 4108 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4109 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4110 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4111 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4112 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4113 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4114 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4115 | icmd = &elsiocb->iocb; |
| 4116 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4117 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4118 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4119 | |
| 4120 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4121 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4122 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 4123 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 4124 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4125 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4126 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4127 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4128 | |
| 4129 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4130 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4131 | |
| 4132 | ap = (ADISC *) (pcmd); |
| 4133 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4134 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4135 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4136 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4137 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4138 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4139 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 4140 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4141 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4142 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4143 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4144 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4145 | if (rc == IOCB_ERROR) { |
| 4146 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4147 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4148 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4149 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4150 | } |
| 4151 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4152 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4153 | * 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] | 4154 | * @vport: pointer to a virtual N_Port data structure. |
| 4155 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4156 | * @ndlp: pointer to a node-list data structure. |
| 4157 | * |
| 4158 | * This routine prepares and issues an Accept (ACC) response to Process |
| 4159 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 4160 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4161 | * |
| 4162 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4163 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4164 | * will be stored into the context1 field of the IOCB for the completion |
| 4165 | * callback function to the PRLI Accept response ELS IOCB command. |
| 4166 | * |
| 4167 | * Return code |
| 4168 | * 0 - Successfully issued acc prli response |
| 4169 | * 1 - Failed to issue acc prli response |
| 4170 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4171 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4172 | 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] | 4173 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4174 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4175 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4176 | PRLI *npr; |
| 4177 | lpfc_vpd_t *vpd; |
| 4178 | IOCB_t *icmd; |
| 4179 | IOCB_t *oldcmd; |
| 4180 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4181 | uint8_t *pcmd; |
| 4182 | uint16_t cmdsize; |
| 4183 | int rc; |
| 4184 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4185 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4186 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4187 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4188 | if (!elsiocb) |
| 4189 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4190 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4191 | icmd = &elsiocb->iocb; |
| 4192 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4193 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4194 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4195 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4196 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4197 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4198 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 4199 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4200 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4201 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4202 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4203 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4204 | |
| 4205 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4206 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4207 | |
| 4208 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4209 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4210 | |
| 4211 | npr = (PRLI *) pcmd; |
| 4212 | vpd = &phba->vpd; |
| 4213 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4214 | * If the remote port is a target and our firmware version is 3.20 or |
| 4215 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4216 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4217 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 4218 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4219 | npr->ConfmComplAllowed = 1; |
| 4220 | npr->Retry = 1; |
| 4221 | npr->TaskRetryIdReq = 1; |
| 4222 | } |
| 4223 | |
| 4224 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 4225 | npr->estabImagePair = 1; |
| 4226 | npr->readXferRdyDis = 1; |
| 4227 | npr->ConfmComplAllowed = 1; |
| 4228 | |
| 4229 | npr->prliType = PRLI_FCP_TYPE; |
| 4230 | npr->initiatorFunc = 1; |
| 4231 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4232 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4233 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 4234 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4235 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4236 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4237 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4238 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4239 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4240 | if (rc == IOCB_ERROR) { |
| 4241 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4242 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4243 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4244 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4245 | } |
| 4246 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4247 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4248 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4249 | * @vport: pointer to a virtual N_Port data structure. |
| 4250 | * @format: rnid command format. |
| 4251 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4252 | * @ndlp: pointer to a node-list data structure. |
| 4253 | * |
| 4254 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 4255 | * (ACC) response. It constructs the RNID ACC response command according to |
| 4256 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 4257 | * issue the response. Note that this command does not need to hold the ndlp |
| 4258 | * reference count for the callback. So, the ndlp reference count taken by |
| 4259 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 4260 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 4261 | * there is no ndlp reference available. |
| 4262 | * |
| 4263 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4264 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4265 | * will be stored into the context1 field of the IOCB for the completion |
| 4266 | * callback function. However, for the RNID Accept Response ELS command, |
| 4267 | * this is undone later by this routine after the IOCB is allocated. |
| 4268 | * |
| 4269 | * Return code |
| 4270 | * 0 - Successfully issued acc rnid response |
| 4271 | * 1 - Failed to issue acc rnid response |
| 4272 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4273 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4274 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4275 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4276 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4277 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4278 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4279 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4280 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4281 | uint8_t *pcmd; |
| 4282 | uint16_t cmdsize; |
| 4283 | int rc; |
| 4284 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4285 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 4286 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4287 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4288 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4289 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4290 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4291 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4292 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4293 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4294 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4295 | icmd = &elsiocb->iocb; |
| 4296 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4297 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4298 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4299 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4300 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4301 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4302 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 4303 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4304 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4305 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4306 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4307 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4308 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4309 | rn = (RNID *) (pcmd); |
| 4310 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4311 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 4312 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4313 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4314 | switch (format) { |
| 4315 | case 0: |
| 4316 | rn->SpecificLen = 0; |
| 4317 | break; |
| 4318 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4319 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4320 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4321 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4322 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 4323 | rn->un.topologyDisc.physPort = 0; |
| 4324 | rn->un.topologyDisc.attachedNodes = 0; |
| 4325 | break; |
| 4326 | default: |
| 4327 | rn->CommonLen = 0; |
| 4328 | rn->SpecificLen = 0; |
| 4329 | break; |
| 4330 | } |
| 4331 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4332 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4333 | "Issue ACC RNID: did:x%x flg:x%x", |
| 4334 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4335 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4336 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4337 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4338 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4339 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4340 | if (rc == IOCB_ERROR) { |
| 4341 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4342 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4343 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4344 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4345 | } |
| 4346 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4347 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4348 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. |
| 4349 | * @vport: pointer to a virtual N_Port data structure. |
| 4350 | * @iocb: pointer to the lpfc command iocb data structure. |
| 4351 | * @ndlp: pointer to a node-list data structure. |
| 4352 | * |
| 4353 | * Return |
| 4354 | **/ |
| 4355 | static void |
| 4356 | lpfc_els_clear_rrq(struct lpfc_vport *vport, |
| 4357 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
| 4358 | { |
| 4359 | struct lpfc_hba *phba = vport->phba; |
| 4360 | uint8_t *pcmd; |
| 4361 | struct RRQ *rrq; |
| 4362 | uint16_t rxid; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4363 | uint16_t xri; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4364 | struct lpfc_node_rrq *prrq; |
| 4365 | |
| 4366 | |
| 4367 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); |
| 4368 | pcmd += sizeof(uint32_t); |
| 4369 | rrq = (struct RRQ *)pcmd; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4370 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4371 | rxid = bf_get(rrq_rxid, rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4372 | |
| 4373 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4374 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" |
| 4375 | " x%x x%x\n", |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4376 | be32_to_cpu(bf_get(rrq_did, rrq)), |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4377 | bf_get(rrq_oxid, rrq), |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4378 | rxid, |
| 4379 | iocb->iotag, iocb->iocb.ulpContext); |
| 4380 | |
| 4381 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4382 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", |
| 4383 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4384 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4385 | xri = bf_get(rrq_oxid, rrq); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4386 | else |
| 4387 | xri = rxid; |
| 4388 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4389 | if (prrq) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4390 | lpfc_clr_rrq_active(phba, xri, prrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4391 | return; |
| 4392 | } |
| 4393 | |
| 4394 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4395 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 4396 | * @vport: pointer to a virtual N_Port data structure. |
| 4397 | * @data: pointer to echo data to return in the accept. |
| 4398 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4399 | * @ndlp: pointer to a node-list data structure. |
| 4400 | * |
| 4401 | * Return code |
| 4402 | * 0 - Successfully issued acc echo response |
| 4403 | * 1 - Failed to issue acc echo response |
| 4404 | **/ |
| 4405 | static int |
| 4406 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 4407 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 4408 | { |
| 4409 | struct lpfc_hba *phba = vport->phba; |
| 4410 | struct lpfc_iocbq *elsiocb; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4411 | uint8_t *pcmd; |
| 4412 | uint16_t cmdsize; |
| 4413 | int rc; |
| 4414 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4415 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 4416 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4417 | /* The accumulated length can exceed the BPL_SIZE. For |
| 4418 | * now, use this as the limit |
| 4419 | */ |
| 4420 | if (cmdsize > LPFC_BPL_SIZE) |
| 4421 | cmdsize = LPFC_BPL_SIZE; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4422 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4423 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4424 | if (!elsiocb) |
| 4425 | return 1; |
| 4426 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4427 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 4428 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; |
| 4429 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4430 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 4431 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4432 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 4433 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 4434 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4435 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4436 | pcmd += sizeof(uint32_t); |
| 4437 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 4438 | |
| 4439 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4440 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 4441 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4442 | |
| 4443 | phba->fc_stat.elsXmitACC++; |
| 4444 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4445 | |
| 4446 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4447 | if (rc == IOCB_ERROR) { |
| 4448 | lpfc_els_free_iocb(phba, elsiocb); |
| 4449 | return 1; |
| 4450 | } |
| 4451 | return 0; |
| 4452 | } |
| 4453 | |
| 4454 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4455 | * 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] | 4456 | * @vport: pointer to a host virtual N_Port data structure. |
| 4457 | * |
| 4458 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 4459 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 4460 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 4461 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 4462 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 4463 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 4464 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 4465 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 4466 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 4467 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 4468 | * no more ADISC need to be sent. |
| 4469 | * |
| 4470 | * Return code |
| 4471 | * The number of N_Ports with adisc issued. |
| 4472 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4473 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4474 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4475 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4476 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4477 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4478 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4479 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4480 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4481 | 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] | 4482 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4483 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4484 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4485 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4486 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4487 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4488 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4489 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4490 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4491 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4492 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4493 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4494 | vport->num_disc_nodes++; |
| 4495 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4496 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4497 | spin_lock_irq(shost->host_lock); |
| 4498 | vport->fc_flag |= FC_NLP_MORE; |
| 4499 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4500 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4501 | } |
| 4502 | } |
| 4503 | } |
| 4504 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4505 | spin_lock_irq(shost->host_lock); |
| 4506 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4507 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4508 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4509 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4510 | } |
| 4511 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4512 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4513 | * 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] | 4514 | * @vport: pointer to a host virtual N_Port data structure. |
| 4515 | * |
| 4516 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4517 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4518 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4519 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4520 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4521 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4522 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4523 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4524 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4525 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4526 | * PLOGI need to be sent. |
| 4527 | * |
| 4528 | * Return code |
| 4529 | * The number of N_Ports with plogi issued. |
| 4530 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4531 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4532 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4533 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4534 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4535 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4536 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4537 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4538 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4539 | 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] | 4540 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4541 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4542 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4543 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4544 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4545 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4546 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4547 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4548 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4549 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4550 | vport->num_disc_nodes++; |
| 4551 | if (vport->num_disc_nodes >= |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4552 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4553 | spin_lock_irq(shost->host_lock); |
| 4554 | vport->fc_flag |= FC_NLP_MORE; |
| 4555 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4556 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4557 | } |
| 4558 | } |
| 4559 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4560 | if (sentplogi) { |
| 4561 | lpfc_set_disctmo(vport); |
| 4562 | } |
| 4563 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4564 | spin_lock_irq(shost->host_lock); |
| 4565 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4566 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4567 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4568 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4569 | } |
| 4570 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4571 | void |
| 4572 | lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc, |
| 4573 | uint32_t word0) |
| 4574 | { |
| 4575 | |
| 4576 | desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG); |
| 4577 | desc->payload.els_req = word0; |
| 4578 | desc->length = cpu_to_be32(sizeof(desc->payload)); |
| 4579 | } |
| 4580 | |
| 4581 | void |
| 4582 | lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc, |
| 4583 | uint8_t *page_a0, uint8_t *page_a2) |
| 4584 | { |
| 4585 | uint16_t wavelength; |
| 4586 | uint16_t temperature; |
| 4587 | uint16_t rx_power; |
| 4588 | uint16_t tx_bias; |
| 4589 | uint16_t tx_power; |
| 4590 | uint16_t vcc; |
| 4591 | uint16_t flag = 0; |
| 4592 | struct sff_trasnceiver_codes_byte4 *trasn_code_byte4; |
| 4593 | struct sff_trasnceiver_codes_byte5 *trasn_code_byte5; |
| 4594 | |
| 4595 | desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG); |
| 4596 | |
| 4597 | trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *) |
| 4598 | &page_a0[SSF_TRANSCEIVER_CODE_B4]; |
| 4599 | trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *) |
| 4600 | &page_a0[SSF_TRANSCEIVER_CODE_B5]; |
| 4601 | |
| 4602 | if ((trasn_code_byte4->fc_sw_laser) || |
| 4603 | (trasn_code_byte5->fc_sw_laser_sl) || |
| 4604 | (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */ |
| 4605 | flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT); |
| 4606 | } else if (trasn_code_byte4->fc_lw_laser) { |
| 4607 | wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) | |
| 4608 | page_a0[SSF_WAVELENGTH_B0]; |
| 4609 | if (wavelength == SFP_WAVELENGTH_LC1310) |
| 4610 | flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT; |
| 4611 | if (wavelength == SFP_WAVELENGTH_LL1550) |
| 4612 | flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT; |
| 4613 | } |
| 4614 | /* check if its SFP+ */ |
| 4615 | flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ? |
| 4616 | SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN) |
| 4617 | << SFP_FLAG_CT_SHIFT; |
| 4618 | |
| 4619 | /* check if its OPTICAL */ |
| 4620 | flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ? |
| 4621 | SFP_FLAG_IS_OPTICAL_PORT : 0) |
| 4622 | << SFP_FLAG_IS_OPTICAL_SHIFT; |
| 4623 | |
| 4624 | temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 | |
| 4625 | page_a2[SFF_TEMPERATURE_B0]); |
| 4626 | vcc = (page_a2[SFF_VCC_B1] << 8 | |
| 4627 | page_a2[SFF_VCC_B0]); |
| 4628 | tx_power = (page_a2[SFF_TXPOWER_B1] << 8 | |
| 4629 | page_a2[SFF_TXPOWER_B0]); |
| 4630 | tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 | |
| 4631 | page_a2[SFF_TX_BIAS_CURRENT_B0]); |
| 4632 | rx_power = (page_a2[SFF_RXPOWER_B1] << 8 | |
| 4633 | page_a2[SFF_RXPOWER_B0]); |
| 4634 | desc->sfp_info.temperature = cpu_to_be16(temperature); |
| 4635 | desc->sfp_info.rx_power = cpu_to_be16(rx_power); |
| 4636 | desc->sfp_info.tx_bias = cpu_to_be16(tx_bias); |
| 4637 | desc->sfp_info.tx_power = cpu_to_be16(tx_power); |
| 4638 | desc->sfp_info.vcc = cpu_to_be16(vcc); |
| 4639 | |
| 4640 | desc->sfp_info.flags = cpu_to_be16(flag); |
| 4641 | desc->length = cpu_to_be32(sizeof(desc->sfp_info)); |
| 4642 | } |
| 4643 | |
| 4644 | void |
| 4645 | lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc, |
| 4646 | READ_LNK_VAR *stat) |
| 4647 | { |
| 4648 | uint32_t type; |
| 4649 | |
| 4650 | desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG); |
| 4651 | |
| 4652 | type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT; |
| 4653 | |
| 4654 | desc->info.port_type = cpu_to_be32(type); |
| 4655 | |
| 4656 | desc->info.link_status.link_failure_cnt = |
| 4657 | cpu_to_be32(stat->linkFailureCnt); |
| 4658 | desc->info.link_status.loss_of_synch_cnt = |
| 4659 | cpu_to_be32(stat->lossSyncCnt); |
| 4660 | desc->info.link_status.loss_of_signal_cnt = |
| 4661 | cpu_to_be32(stat->lossSignalCnt); |
| 4662 | desc->info.link_status.primitive_seq_proto_err = |
| 4663 | cpu_to_be32(stat->primSeqErrCnt); |
| 4664 | desc->info.link_status.invalid_trans_word = |
| 4665 | cpu_to_be32(stat->invalidXmitWord); |
| 4666 | desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt); |
| 4667 | |
| 4668 | desc->length = cpu_to_be32(sizeof(desc->info)); |
| 4669 | } |
| 4670 | |
| 4671 | void |
| 4672 | lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba) |
| 4673 | { |
| 4674 | uint16_t rdp_cap = 0; |
| 4675 | uint16_t rdp_speed; |
| 4676 | |
| 4677 | desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG); |
| 4678 | |
| 4679 | switch (phba->sli4_hba.link_state.speed) { |
| 4680 | case LPFC_FC_LA_SPEED_1G: |
| 4681 | rdp_speed = RDP_PS_1GB; |
| 4682 | break; |
| 4683 | case LPFC_FC_LA_SPEED_2G: |
| 4684 | rdp_speed = RDP_PS_2GB; |
| 4685 | break; |
| 4686 | case LPFC_FC_LA_SPEED_4G: |
| 4687 | rdp_speed = RDP_PS_4GB; |
| 4688 | break; |
| 4689 | case LPFC_FC_LA_SPEED_8G: |
| 4690 | rdp_speed = RDP_PS_8GB; |
| 4691 | break; |
| 4692 | case LPFC_FC_LA_SPEED_10G: |
| 4693 | rdp_speed = RDP_PS_10GB; |
| 4694 | break; |
| 4695 | case LPFC_FC_LA_SPEED_16G: |
| 4696 | rdp_speed = RDP_PS_16GB; |
| 4697 | break; |
| 4698 | case LPFC_FC_LA_SPEED_32G: |
| 4699 | rdp_speed = RDP_PS_32GB; |
| 4700 | break; |
| 4701 | default: |
| 4702 | rdp_speed = RDP_PS_UNKNOWN; |
| 4703 | break; |
| 4704 | } |
| 4705 | |
| 4706 | desc->info.port_speed.speed = cpu_to_be16(rdp_speed); |
| 4707 | |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4708 | if (phba->lmt & LMT_32Gb) |
| 4709 | rdp_cap |= RDP_PS_32GB; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 4710 | if (phba->lmt & LMT_16Gb) |
| 4711 | rdp_cap |= RDP_PS_16GB; |
| 4712 | if (phba->lmt & LMT_10Gb) |
| 4713 | rdp_cap |= RDP_PS_10GB; |
| 4714 | if (phba->lmt & LMT_8Gb) |
| 4715 | rdp_cap |= RDP_PS_8GB; |
| 4716 | if (phba->lmt & LMT_4Gb) |
| 4717 | rdp_cap |= RDP_PS_4GB; |
| 4718 | if (phba->lmt & LMT_2Gb) |
| 4719 | rdp_cap |= RDP_PS_2GB; |
| 4720 | if (phba->lmt & LMT_1Gb) |
| 4721 | rdp_cap |= RDP_PS_1GB; |
| 4722 | |
| 4723 | if (rdp_cap == 0) |
| 4724 | rdp_cap = RDP_CAP_UNKNOWN; |
| 4725 | |
| 4726 | desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap); |
| 4727 | desc->length = cpu_to_be32(sizeof(desc->info)); |
| 4728 | } |
| 4729 | |
| 4730 | void |
| 4731 | lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc, |
| 4732 | struct lpfc_hba *phba) |
| 4733 | { |
| 4734 | |
| 4735 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 4736 | |
| 4737 | memcpy(desc->port_names.wwnn, phba->wwnn, |
| 4738 | sizeof(desc->port_names.wwnn)); |
| 4739 | |
| 4740 | memcpy(desc->port_names.wwpn, &phba->wwpn, |
| 4741 | sizeof(desc->port_names.wwpn)); |
| 4742 | |
| 4743 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
| 4744 | } |
| 4745 | |
| 4746 | void |
| 4747 | lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc, |
| 4748 | struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4749 | { |
| 4750 | |
| 4751 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 4752 | if (vport->fc_flag & FC_FABRIC) { |
| 4753 | memcpy(desc->port_names.wwnn, &vport->fabric_nodename, |
| 4754 | sizeof(desc->port_names.wwnn)); |
| 4755 | |
| 4756 | memcpy(desc->port_names.wwpn, &vport->fabric_portname, |
| 4757 | sizeof(desc->port_names.wwpn)); |
| 4758 | } else { /* Point to Point */ |
| 4759 | memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename, |
| 4760 | sizeof(desc->port_names.wwnn)); |
| 4761 | |
| 4762 | memcpy(desc->port_names.wwnn, &ndlp->nlp_portname, |
| 4763 | sizeof(desc->port_names.wwpn)); |
| 4764 | } |
| 4765 | |
| 4766 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
| 4767 | } |
| 4768 | |
| 4769 | void |
| 4770 | lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context, |
| 4771 | int status) |
| 4772 | { |
| 4773 | struct lpfc_nodelist *ndlp = rdp_context->ndlp; |
| 4774 | struct lpfc_vport *vport = ndlp->vport; |
| 4775 | struct lpfc_iocbq *elsiocb; |
| 4776 | IOCB_t *icmd; |
| 4777 | uint8_t *pcmd; |
| 4778 | struct ls_rjt *stat; |
| 4779 | struct fc_rdp_res_frame *rdp_res; |
| 4780 | uint32_t cmdsize; |
| 4781 | int rc; |
| 4782 | |
| 4783 | if (status != SUCCESS) |
| 4784 | goto error; |
| 4785 | cmdsize = sizeof(struct fc_rdp_res_frame); |
| 4786 | |
| 4787 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, |
| 4788 | lpfc_max_els_tries, rdp_context->ndlp, |
| 4789 | rdp_context->ndlp->nlp_DID, ELS_CMD_ACC); |
| 4790 | lpfc_nlp_put(ndlp); |
| 4791 | if (!elsiocb) |
| 4792 | goto free_rdp_context; |
| 4793 | |
| 4794 | icmd = &elsiocb->iocb; |
| 4795 | icmd->ulpContext = rdp_context->rx_id; |
| 4796 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 4797 | |
| 4798 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4799 | "2171 Xmit RDP response tag x%x xri x%x, " |
| 4800 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x", |
| 4801 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4802 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4803 | ndlp->nlp_rpi); |
| 4804 | rdp_res = (struct fc_rdp_res_frame *) |
| 4805 | (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4806 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4807 | memset(pcmd, 0, sizeof(struct fc_rdp_res_frame)); |
| 4808 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4809 | |
| 4810 | /* For RDP payload */ |
| 4811 | lpfc_rdp_res_link_service(&rdp_res->link_service_desc, ELS_CMD_RDP); |
| 4812 | |
| 4813 | lpfc_rdp_res_sfp_desc(&rdp_res->sfp_desc, |
| 4814 | rdp_context->page_a0, rdp_context->page_a2); |
| 4815 | lpfc_rdp_res_speed(&rdp_res->portspeed_desc, phba); |
| 4816 | lpfc_rdp_res_link_error(&rdp_res->link_error_desc, |
| 4817 | &rdp_context->link_stat); |
| 4818 | lpfc_rdp_res_diag_port_names(&rdp_res->diag_port_names_desc, phba); |
| 4819 | lpfc_rdp_res_attach_port_names(&rdp_res->attached_port_names_desc, |
| 4820 | vport, ndlp); |
| 4821 | rdp_res->length = cpu_to_be32(RDP_DESC_PAYLOAD_SIZE); |
| 4822 | |
| 4823 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 4824 | |
| 4825 | phba->fc_stat.elsXmitACC++; |
| 4826 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4827 | if (rc == IOCB_ERROR) |
| 4828 | lpfc_els_free_iocb(phba, elsiocb); |
| 4829 | |
| 4830 | kfree(rdp_context); |
| 4831 | |
| 4832 | return; |
| 4833 | error: |
| 4834 | cmdsize = 2 * sizeof(uint32_t); |
| 4835 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries, |
| 4836 | ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 4837 | lpfc_nlp_put(ndlp); |
| 4838 | if (!elsiocb) |
| 4839 | goto free_rdp_context; |
| 4840 | |
| 4841 | icmd = &elsiocb->iocb; |
| 4842 | icmd->ulpContext = rdp_context->rx_id; |
| 4843 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 4844 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4845 | |
| 4846 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
| 4847 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 4848 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4849 | |
| 4850 | phba->fc_stat.elsXmitLSRJT++; |
| 4851 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 4852 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4853 | |
| 4854 | if (rc == IOCB_ERROR) |
| 4855 | lpfc_els_free_iocb(phba, elsiocb); |
| 4856 | free_rdp_context: |
| 4857 | kfree(rdp_context); |
| 4858 | } |
| 4859 | |
| 4860 | int |
| 4861 | lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) |
| 4862 | { |
| 4863 | LPFC_MBOXQ_t *mbox = NULL; |
| 4864 | int rc; |
| 4865 | |
| 4866 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4867 | if (!mbox) { |
| 4868 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, |
| 4869 | "7105 failed to allocate mailbox memory"); |
| 4870 | return 1; |
| 4871 | } |
| 4872 | |
| 4873 | if (lpfc_sli4_dump_page_a0(phba, mbox)) |
| 4874 | goto prep_mbox_fail; |
| 4875 | mbox->vport = rdp_context->ndlp->vport; |
| 4876 | mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; |
| 4877 | mbox->context2 = (struct lpfc_rdp_context *) rdp_context; |
| 4878 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 4879 | if (rc == MBX_NOT_FINISHED) |
| 4880 | goto issue_mbox_fail; |
| 4881 | |
| 4882 | return 0; |
| 4883 | |
| 4884 | prep_mbox_fail: |
| 4885 | issue_mbox_fail: |
| 4886 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4887 | return 1; |
| 4888 | } |
| 4889 | |
| 4890 | /* |
| 4891 | * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS. |
| 4892 | * @vport: pointer to a host virtual N_Port data structure. |
| 4893 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4894 | * @ndlp: pointer to a node-list data structure. |
| 4895 | * |
| 4896 | * This routine processes an unsolicited RDP(Read Diagnostic Parameters) |
| 4897 | * IOCB. First, the payload of the unsolicited RDP is checked. |
| 4898 | * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3 |
| 4899 | * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2, |
| 4900 | * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl |
| 4901 | * gather all data and send RDP response. |
| 4902 | * |
| 4903 | * Return code |
| 4904 | * 0 - Sent the acc response |
| 4905 | * 1 - Sent the reject response. |
| 4906 | */ |
| 4907 | static int |
| 4908 | lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4909 | struct lpfc_nodelist *ndlp) |
| 4910 | { |
| 4911 | struct lpfc_hba *phba = vport->phba; |
| 4912 | struct lpfc_dmabuf *pcmd; |
| 4913 | uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE; |
| 4914 | struct fc_rdp_req_frame *rdp_req; |
| 4915 | struct lpfc_rdp_context *rdp_context; |
| 4916 | IOCB_t *cmd = NULL; |
| 4917 | struct ls_rjt stat; |
| 4918 | |
| 4919 | if (phba->sli_rev < LPFC_SLI_REV4 || |
| 4920 | (bf_get(lpfc_sli_intf_if_type, |
| 4921 | &phba->sli4_hba.sli_intf) != |
| 4922 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 4923 | rjt_err = LSRJT_UNABLE_TPC; |
| 4924 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 4925 | goto error; |
| 4926 | } |
| 4927 | |
| 4928 | if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) { |
| 4929 | rjt_err = LSRJT_UNABLE_TPC; |
| 4930 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 4931 | goto error; |
| 4932 | } |
| 4933 | |
| 4934 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4935 | rdp_req = (struct fc_rdp_req_frame *) pcmd->virt; |
| 4936 | |
| 4937 | |
| 4938 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4939 | "2422 ELS RDP Request " |
| 4940 | "dec len %d tag x%x port_id %d len %d\n", |
| 4941 | be32_to_cpu(rdp_req->rdp_des_length), |
| 4942 | be32_to_cpu(rdp_req->nport_id_desc.tag), |
| 4943 | be32_to_cpu(rdp_req->nport_id_desc.nport_id), |
| 4944 | be32_to_cpu(rdp_req->nport_id_desc.length)); |
| 4945 | |
| 4946 | if (sizeof(struct fc_rdp_nport_desc) != |
| 4947 | be32_to_cpu(rdp_req->rdp_des_length)) |
| 4948 | goto rjt_logerr; |
| 4949 | if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag)) |
| 4950 | goto rjt_logerr; |
| 4951 | if (RDP_NPORT_ID_SIZE != |
| 4952 | be32_to_cpu(rdp_req->nport_id_desc.length)) |
| 4953 | goto rjt_logerr; |
| 4954 | rdp_context = kmalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL); |
| 4955 | if (!rdp_context) { |
| 4956 | rjt_err = LSRJT_UNABLE_TPC; |
| 4957 | goto error; |
| 4958 | } |
| 4959 | |
| 4960 | memset(rdp_context, 0, sizeof(struct lpfc_rdp_context)); |
| 4961 | cmd = &cmdiocb->iocb; |
| 4962 | rdp_context->ndlp = lpfc_nlp_get(ndlp); |
| 4963 | rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id; |
| 4964 | rdp_context->rx_id = cmd->ulpContext; |
| 4965 | rdp_context->cmpl = lpfc_els_rdp_cmpl; |
| 4966 | if (lpfc_get_rdp_info(phba, rdp_context)) { |
| 4967 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS, |
| 4968 | "2423 Unable to send mailbox"); |
| 4969 | kfree(rdp_context); |
| 4970 | rjt_err = LSRJT_UNABLE_TPC; |
| 4971 | lpfc_nlp_put(ndlp); |
| 4972 | goto error; |
| 4973 | } |
| 4974 | |
| 4975 | return 0; |
| 4976 | |
| 4977 | rjt_logerr: |
| 4978 | rjt_err = LSRJT_LOGICAL_ERR; |
| 4979 | |
| 4980 | error: |
| 4981 | memset(&stat, 0, sizeof(stat)); |
| 4982 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 4983 | stat.un.b.lsRjtRsnCodeExp = rjt_expl; |
| 4984 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 4985 | return 1; |
| 4986 | } |
| 4987 | |
| 4988 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4989 | static void |
| 4990 | lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4991 | { |
| 4992 | MAILBOX_t *mb; |
| 4993 | IOCB_t *icmd; |
| 4994 | uint8_t *pcmd; |
| 4995 | struct lpfc_iocbq *elsiocb; |
| 4996 | struct lpfc_nodelist *ndlp; |
| 4997 | struct ls_rjt *stat; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 4998 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 4999 | struct lpfc_lcb_context *lcb_context; |
| 5000 | struct fc_lcb_res_frame *lcb_res; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5001 | uint32_t cmdsize, shdr_status, shdr_add_status; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5002 | int rc; |
| 5003 | |
| 5004 | mb = &pmb->u.mb; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5005 | lcb_context = (struct lpfc_lcb_context *)pmb->context1; |
| 5006 | ndlp = lcb_context->ndlp; |
| 5007 | pmb->context1 = NULL; |
| 5008 | pmb->context2 = NULL; |
| 5009 | |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 5010 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 5011 | &pmb->u.mqe.un.beacon_config.header.cfg_shdr; |
| 5012 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5013 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5014 | |
| 5015 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX, |
| 5016 | "0194 SET_BEACON_CONFIG mailbox " |
| 5017 | "completed with status x%x add_status x%x," |
| 5018 | " mbx status x%x\n", |
| 5019 | shdr_status, shdr_add_status, mb->mbxStatus); |
| 5020 | |
| 5021 | if (mb->mbxStatus && !(shdr_status && |
| 5022 | shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5023 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5024 | goto error; |
| 5025 | } |
| 5026 | |
| 5027 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5028 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 5029 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5030 | lpfc_max_els_tries, ndlp, |
| 5031 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5032 | |
| 5033 | /* Decrement the ndlp reference count from previous mbox command */ |
| 5034 | lpfc_nlp_put(ndlp); |
| 5035 | |
| 5036 | if (!elsiocb) |
| 5037 | goto free_lcb_context; |
| 5038 | |
| 5039 | lcb_res = (struct fc_lcb_res_frame *) |
| 5040 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5041 | |
| 5042 | icmd = &elsiocb->iocb; |
| 5043 | icmd->ulpContext = lcb_context->rx_id; |
| 5044 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 5045 | |
| 5046 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5047 | *((uint32_t *)(pcmd)) = ELS_CMD_ACC; |
| 5048 | lcb_res->lcb_sub_command = lcb_context->sub_command; |
| 5049 | lcb_res->lcb_type = lcb_context->type; |
| 5050 | lcb_res->lcb_frequency = lcb_context->frequency; |
| 5051 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5052 | phba->fc_stat.elsXmitACC++; |
| 5053 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5054 | if (rc == IOCB_ERROR) |
| 5055 | lpfc_els_free_iocb(phba, elsiocb); |
| 5056 | |
| 5057 | kfree(lcb_context); |
| 5058 | return; |
| 5059 | |
| 5060 | error: |
| 5061 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 5062 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5063 | lpfc_max_els_tries, ndlp, |
| 5064 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 5065 | lpfc_nlp_put(ndlp); |
| 5066 | if (!elsiocb) |
| 5067 | goto free_lcb_context; |
| 5068 | |
| 5069 | icmd = &elsiocb->iocb; |
| 5070 | icmd->ulpContext = lcb_context->rx_id; |
| 5071 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 5072 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 5073 | |
| 5074 | *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT; |
| 5075 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 5076 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5077 | |
| 5078 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5079 | phba->fc_stat.elsXmitLSRJT++; |
| 5080 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5081 | if (rc == IOCB_ERROR) |
| 5082 | lpfc_els_free_iocb(phba, elsiocb); |
| 5083 | free_lcb_context: |
| 5084 | kfree(lcb_context); |
| 5085 | } |
| 5086 | |
| 5087 | static int |
| 5088 | lpfc_sli4_set_beacon(struct lpfc_vport *vport, |
| 5089 | struct lpfc_lcb_context *lcb_context, |
| 5090 | uint32_t beacon_state) |
| 5091 | { |
| 5092 | struct lpfc_hba *phba = vport->phba; |
| 5093 | LPFC_MBOXQ_t *mbox = NULL; |
| 5094 | uint32_t len; |
| 5095 | int rc; |
| 5096 | |
| 5097 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5098 | if (!mbox) |
| 5099 | return 1; |
| 5100 | |
| 5101 | len = sizeof(struct lpfc_mbx_set_beacon_config) - |
| 5102 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 5103 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5104 | LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len, |
| 5105 | LPFC_SLI4_MBX_EMBED); |
| 5106 | mbox->context1 = (void *)lcb_context; |
| 5107 | mbox->vport = phba->pport; |
| 5108 | mbox->mbox_cmpl = lpfc_els_lcb_rsp; |
| 5109 | bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config, |
| 5110 | phba->sli4_hba.physical_port); |
| 5111 | bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config, |
| 5112 | beacon_state); |
| 5113 | bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1); |
| 5114 | bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0); |
| 5115 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5116 | if (rc == MBX_NOT_FINISHED) { |
| 5117 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5118 | return 1; |
| 5119 | } |
| 5120 | |
| 5121 | return 0; |
| 5122 | } |
| 5123 | |
| 5124 | |
| 5125 | /** |
| 5126 | * lpfc_els_rcv_lcb - Process an unsolicited LCB |
| 5127 | * @vport: pointer to a host virtual N_Port data structure. |
| 5128 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5129 | * @ndlp: pointer to a node-list data structure. |
| 5130 | * |
| 5131 | * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB. |
| 5132 | * First, the payload of the unsolicited LCB is checked. |
| 5133 | * Then based on Subcommand beacon will either turn on or off. |
| 5134 | * |
| 5135 | * Return code |
| 5136 | * 0 - Sent the acc response |
| 5137 | * 1 - Sent the reject response. |
| 5138 | **/ |
| 5139 | static int |
| 5140 | lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5141 | struct lpfc_nodelist *ndlp) |
| 5142 | { |
| 5143 | struct lpfc_hba *phba = vport->phba; |
| 5144 | struct lpfc_dmabuf *pcmd; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5145 | uint8_t *lp; |
| 5146 | struct fc_lcb_request_frame *beacon; |
| 5147 | struct lpfc_lcb_context *lcb_context; |
| 5148 | uint8_t state, rjt_err; |
| 5149 | struct ls_rjt stat; |
| 5150 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5151 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 5152 | lp = (uint8_t *)pcmd->virt; |
| 5153 | beacon = (struct fc_lcb_request_frame *)pcmd->virt; |
| 5154 | |
| 5155 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5156 | "0192 ELS LCB Data x%x x%x x%x x%x sub x%x " |
| 5157 | "type x%x frequency %x duration x%x\n", |
| 5158 | lp[0], lp[1], lp[2], |
| 5159 | beacon->lcb_command, |
| 5160 | beacon->lcb_sub_command, |
| 5161 | beacon->lcb_type, |
| 5162 | beacon->lcb_frequency, |
| 5163 | be16_to_cpu(beacon->lcb_duration)); |
| 5164 | |
| 5165 | if (phba->sli_rev < LPFC_SLI_REV4 || |
| 5166 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 5167 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 5168 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5169 | goto rjt; |
| 5170 | } |
| 5171 | lcb_context = kmalloc(sizeof(struct lpfc_lcb_context), GFP_KERNEL); |
| 5172 | |
| 5173 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 5174 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5175 | goto rjt; |
| 5176 | } |
| 5177 | if (beacon->lcb_frequency == 0) { |
| 5178 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5179 | goto rjt; |
| 5180 | } |
| 5181 | if ((beacon->lcb_type != LPFC_LCB_GREEN) && |
| 5182 | (beacon->lcb_type != LPFC_LCB_AMBER)) { |
| 5183 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5184 | goto rjt; |
| 5185 | } |
| 5186 | if ((beacon->lcb_sub_command != LPFC_LCB_ON) && |
| 5187 | (beacon->lcb_sub_command != LPFC_LCB_OFF)) { |
| 5188 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5189 | goto rjt; |
| 5190 | } |
| 5191 | if ((beacon->lcb_sub_command == LPFC_LCB_ON) && |
| 5192 | (beacon->lcb_type != LPFC_LCB_GREEN) && |
| 5193 | (beacon->lcb_type != LPFC_LCB_AMBER)) { |
| 5194 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5195 | goto rjt; |
| 5196 | } |
| 5197 | if (be16_to_cpu(beacon->lcb_duration) != 0) { |
| 5198 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 5199 | goto rjt; |
| 5200 | } |
| 5201 | |
| 5202 | state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; |
| 5203 | lcb_context->sub_command = beacon->lcb_sub_command; |
| 5204 | lcb_context->type = beacon->lcb_type; |
| 5205 | lcb_context->frequency = beacon->lcb_frequency; |
| 5206 | lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
| 5207 | lcb_context->rx_id = cmdiocb->iocb.ulpContext; |
| 5208 | lcb_context->ndlp = lpfc_nlp_get(ndlp); |
| 5209 | if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { |
| 5210 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 5211 | LOG_ELS, "0193 failed to send mail box"); |
| 5212 | lpfc_nlp_put(ndlp); |
| 5213 | rjt_err = LSRJT_UNABLE_TPC; |
| 5214 | goto rjt; |
| 5215 | } |
| 5216 | return 0; |
| 5217 | rjt: |
| 5218 | memset(&stat, 0, sizeof(stat)); |
| 5219 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 5220 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5221 | return 1; |
| 5222 | } |
| 5223 | |
| 5224 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5225 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5226 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5227 | * @vport: pointer to a host virtual N_Port data structure. |
| 5228 | * |
| 5229 | * This routine cleans up any Registration State Change Notification |
| 5230 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 5231 | * @vport together with the host_lock is used to prevent multiple thread |
| 5232 | * trying to access the RSCN array on a same @vport at the same time. |
| 5233 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5234 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5235 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5236 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5237 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5238 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5239 | int i; |
| 5240 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5241 | spin_lock_irq(shost->host_lock); |
| 5242 | if (vport->fc_rscn_flush) { |
| 5243 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 5244 | spin_unlock_irq(shost->host_lock); |
| 5245 | return; |
| 5246 | } |
| 5247 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 5248 | vport->fc_rscn_flush = 1; |
| 5249 | spin_unlock_irq(shost->host_lock); |
| 5250 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5251 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5252 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5253 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5254 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5255 | spin_lock_irq(shost->host_lock); |
| 5256 | vport->fc_rscn_id_cnt = 0; |
| 5257 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 5258 | spin_unlock_irq(shost->host_lock); |
| 5259 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5260 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 5261 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5262 | } |
| 5263 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5264 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5265 | * 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] | 5266 | * @vport: pointer to a host virtual N_Port data structure. |
| 5267 | * @did: remote destination port identifier. |
| 5268 | * |
| 5269 | * This routine checks whether there is any pending Registration State |
| 5270 | * Configuration Notification (RSCN) to a @did on @vport. |
| 5271 | * |
| 5272 | * Return code |
| 5273 | * None zero - The @did matched with a pending rscn |
| 5274 | * 0 - not able to match @did with a pending rscn |
| 5275 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5276 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5277 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5278 | { |
| 5279 | D_ID ns_did; |
| 5280 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5281 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5282 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5283 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5284 | |
| 5285 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5286 | |
| 5287 | /* Never match fabric nodes for RSCNs */ |
| 5288 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5289 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5290 | |
| 5291 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5292 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5293 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5294 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5295 | spin_lock_irq(shost->host_lock); |
| 5296 | if (vport->fc_rscn_flush) { |
| 5297 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 5298 | spin_unlock_irq(shost->host_lock); |
| 5299 | return 0; |
| 5300 | } |
| 5301 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 5302 | vport->fc_rscn_flush = 1; |
| 5303 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5304 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5305 | lp = vport->fc_rscn_id_list[i]->virt; |
| 5306 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 5307 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5308 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5309 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 5310 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5311 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 5312 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5313 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 5314 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 5315 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5316 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5317 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5318 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5319 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 5320 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5321 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5322 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5323 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5324 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5325 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5326 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5327 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5328 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5329 | } |
| 5330 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5331 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5332 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 5333 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5334 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5335 | return_did_out: |
| 5336 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 5337 | vport->fc_rscn_flush = 0; |
| 5338 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5339 | } |
| 5340 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5341 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5342 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5343 | * @vport: pointer to a host virtual N_Port data structure. |
| 5344 | * |
| 5345 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 5346 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 5347 | * State Change Notification). |
| 5348 | * |
| 5349 | * Return code |
| 5350 | * 0 - Successful (currently alway return 0) |
| 5351 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5352 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5353 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5354 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5355 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5356 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5357 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5358 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5359 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5360 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 5361 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5362 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5363 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5364 | NLP_EVT_DEVICE_RECOVERY); |
| 5365 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5366 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5367 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5368 | } |
| 5369 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5370 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5371 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5372 | * @vport: pointer to a host virtual N_Port data structure. |
| 5373 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5374 | * |
| 5375 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 5376 | * applications. |
| 5377 | */ |
| 5378 | static void |
| 5379 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 5380 | struct lpfc_iocbq *cmdiocb) |
| 5381 | { |
| 5382 | struct lpfc_dmabuf *pcmd; |
| 5383 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5384 | uint32_t *payload_ptr; |
| 5385 | uint32_t payload_len; |
| 5386 | struct lpfc_rscn_event_header *rscn_event_data; |
| 5387 | |
| 5388 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5389 | payload_ptr = (uint32_t *) pcmd->virt; |
| 5390 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 5391 | |
| 5392 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 5393 | payload_len, GFP_KERNEL); |
| 5394 | if (!rscn_event_data) { |
| 5395 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5396 | "0147 Failed to allocate memory for RSCN event\n"); |
| 5397 | return; |
| 5398 | } |
| 5399 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 5400 | rscn_event_data->payload_length = payload_len; |
| 5401 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 5402 | payload_len); |
| 5403 | |
| 5404 | fc_host_post_vendor_event(shost, |
| 5405 | fc_get_event_number(), |
Ales Novak | 6599eaa | 2015-08-31 16:48:16 -0400 | [diff] [blame] | 5406 | sizeof(struct lpfc_rscn_event_header) + payload_len, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5407 | (char *)rscn_event_data, |
| 5408 | LPFC_NL_VENDOR_ID); |
| 5409 | |
| 5410 | kfree(rscn_event_data); |
| 5411 | } |
| 5412 | |
| 5413 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5414 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5415 | * @vport: pointer to a host virtual N_Port data structure. |
| 5416 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5417 | * @ndlp: pointer to a node-list data structure. |
| 5418 | * |
| 5419 | * This routine processes an unsolicited RSCN (Registration State Change |
| 5420 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 5421 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 5422 | * discover state machine is about to begin discovery, it just accepts the |
| 5423 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 5424 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 5425 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 5426 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 5427 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 5428 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 5429 | * routine is invoked to handle the RSCN event. |
| 5430 | * |
| 5431 | * Return code |
| 5432 | * 0 - Just sent the acc response |
| 5433 | * 1 - Sent the acc response and waited for name server completion |
| 5434 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5435 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5436 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5437 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5438 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5439 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5440 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5441 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5442 | uint32_t *lp, *datap; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5443 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5444 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5445 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5446 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5447 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5448 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5449 | lp = (uint32_t *) pcmd->virt; |
| 5450 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5451 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 5452 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5453 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5454 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5455 | "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] | 5456 | vport->fc_flag, payload_len, *lp, |
| 5457 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5458 | |
| 5459 | /* Send an RSCN event to the management application */ |
| 5460 | lpfc_send_rscn_event(vport, cmdiocb); |
| 5461 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5462 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5463 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 5464 | FCH_EVT_RSCN, lp[i]); |
| 5465 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5466 | /* If we are about to begin discovery, just ACC the RSCN. |
| 5467 | * Discovery processing will satisfy it. |
| 5468 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5469 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5470 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5471 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 5472 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 5473 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5474 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5475 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5476 | } |
| 5477 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5478 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 5479 | * just ACC and ignore it. |
| 5480 | */ |
| 5481 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5482 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5483 | i = payload_len; |
| 5484 | datap = lp; |
| 5485 | while (i > 0) { |
| 5486 | nportid = *datap++; |
| 5487 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 5488 | i -= sizeof(uint32_t); |
| 5489 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5490 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 5491 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5492 | } |
| 5493 | if (rscn_id == hba_id) { |
| 5494 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5495 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5496 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5497 | "Data: x%x x%x x%x x%x\n", |
| 5498 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5499 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5500 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5501 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 5502 | ndlp->nlp_DID, vport->port_state, |
| 5503 | ndlp->nlp_flag); |
| 5504 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5505 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5506 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5507 | return 0; |
| 5508 | } |
| 5509 | } |
| 5510 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5511 | spin_lock_irq(shost->host_lock); |
| 5512 | if (vport->fc_rscn_flush) { |
| 5513 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5514 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 5515 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5516 | /* Send back ACC */ |
| 5517 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5518 | return 0; |
| 5519 | } |
| 5520 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 5521 | vport->fc_rscn_flush = 1; |
| 5522 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5523 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5524 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5525 | /* If we are already processing an RSCN, save the received |
| 5526 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 5527 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5528 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5529 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5530 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 5531 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 5532 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5533 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5534 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 5535 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5536 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5537 | vport->fc_flag |= FC_RSCN_MODE; |
| 5538 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5539 | if (rscn_cnt) { |
| 5540 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 5541 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 5542 | } |
| 5543 | if ((rscn_cnt) && |
| 5544 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 5545 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5546 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5547 | memcpy(((uint8_t *)cmd) + length, lp, |
| 5548 | payload_len); |
| 5549 | } else { |
| 5550 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 5551 | vport->fc_rscn_id_cnt++; |
| 5552 | /* If we zero, cmdiocb->context2, the calling |
| 5553 | * routine will not try to free it. |
| 5554 | */ |
| 5555 | cmdiocb->context2 = NULL; |
| 5556 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5557 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5558 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5559 | "0235 Deferred RSCN " |
| 5560 | "Data: x%x x%x x%x\n", |
| 5561 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 5562 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5563 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5564 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 5565 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5566 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5567 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5568 | "0234 ReDiscovery RSCN " |
| 5569 | "Data: x%x x%x x%x\n", |
| 5570 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 5571 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5572 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5573 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 5574 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5575 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5576 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5577 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5578 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5579 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5580 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5581 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5582 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5583 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5584 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5585 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 5586 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 5587 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5588 | spin_lock_irq(shost->host_lock); |
| 5589 | vport->fc_flag |= FC_RSCN_MODE; |
| 5590 | spin_unlock_irq(shost->host_lock); |
| 5591 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5592 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 5593 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5594 | /* |
| 5595 | * If we zero, cmdiocb->context2, the calling routine will |
| 5596 | * not try to free it. |
| 5597 | */ |
| 5598 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5599 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5600 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5601 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5602 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5603 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5604 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5605 | } |
| 5606 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5607 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5608 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5609 | * @vport: pointer to a host virtual N_Port data structure. |
| 5610 | * |
| 5611 | * This routine handles the Registration State Configuration Notification |
| 5612 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 5613 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 5614 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 5615 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 5616 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 5617 | * RSCN activities with the @vport. |
| 5618 | * |
| 5619 | * Return code |
| 5620 | * 0 - Cleaned up rscn on the @vport |
| 5621 | * 1 - Wait for plogi to name server before proceed |
| 5622 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5623 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5624 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5625 | { |
| 5626 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5627 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5628 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5629 | /* Ignore RSCN if the port is being torn down. */ |
| 5630 | if (vport->load_flag & FC_UNLOADING) { |
| 5631 | lpfc_els_flush_rscn(vport); |
| 5632 | return 0; |
| 5633 | } |
| 5634 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5635 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5636 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5637 | |
| 5638 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5639 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5640 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 5641 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 5642 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5643 | |
| 5644 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5645 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5646 | vport->num_disc_nodes = 0; |
| 5647 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5648 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5649 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 5650 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5651 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5652 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5653 | /* Wait for NameServer query cmpl before we can |
| 5654 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5655 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5656 | } else { |
| 5657 | /* If login to NameServer does not exist, issue one */ |
| 5658 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5659 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5660 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5661 | /* Wait for NameServer login cmpl before we can |
| 5662 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5663 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5664 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5665 | if (ndlp) { |
| 5666 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5667 | NLP_STE_PLOGI_ISSUE); |
| 5668 | if (!ndlp) { |
| 5669 | lpfc_els_flush_rscn(vport); |
| 5670 | return 0; |
| 5671 | } |
| 5672 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5673 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5674 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5675 | if (!ndlp) { |
| 5676 | lpfc_els_flush_rscn(vport); |
| 5677 | return 0; |
| 5678 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5679 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5680 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5681 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5682 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5683 | ndlp->nlp_type |= NLP_FABRIC; |
| 5684 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 5685 | /* Wait for NameServer login cmpl before we can |
| 5686 | * continue |
| 5687 | */ |
| 5688 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5689 | } |
| 5690 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5691 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5692 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5693 | } |
| 5694 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5695 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5696 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5697 | * @vport: pointer to a host virtual N_Port data structure. |
| 5698 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5699 | * @ndlp: pointer to a node-list data structure. |
| 5700 | * |
| 5701 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 5702 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 5703 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 5704 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 5705 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 5706 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 5707 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 5708 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 5709 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 5710 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 5711 | * higher priority (as the winning port) and will initiate PLOGI and |
| 5712 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 5713 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 5714 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 5715 | * |
| 5716 | * Return code |
| 5717 | * 0 - Successfully processed the unsolicited flogi |
| 5718 | * 1 - Failed to process the unsolicited flogi |
| 5719 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5720 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5721 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5722 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5723 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5724 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5725 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5726 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5727 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 5728 | IOCB_t *icmd = &cmdiocb->iocb; |
| 5729 | struct serv_parm *sp; |
| 5730 | LPFC_MBOXQ_t *mbox; |
| 5731 | struct ls_rjt stat; |
| 5732 | uint32_t cmd, did; |
| 5733 | int rc; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5734 | uint32_t fc_flag = 0; |
| 5735 | uint32_t port_state = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5736 | |
| 5737 | cmd = *lp++; |
| 5738 | sp = (struct serv_parm *) lp; |
| 5739 | |
| 5740 | /* FLOGI received */ |
| 5741 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5742 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5743 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5744 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5745 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 5746 | did = icmd->un.elsreq64.remoteID; |
| 5747 | |
| 5748 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 5749 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5750 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5751 | "0113 An FLOGI ELS command x%x was " |
| 5752 | "received from DID x%x in Loop Mode\n", |
| 5753 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5754 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5755 | } |
| 5756 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 5757 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5758 | /* For a FLOGI we accept, then if our portname is greater |
| 5759 | * then the remote portname we initiate Nport login. |
| 5760 | */ |
| 5761 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5762 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5763 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5764 | |
| 5765 | if (!rc) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 5766 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5767 | mbox = mempool_alloc(phba->mbox_mem_pool, |
| 5768 | GFP_KERNEL); |
| 5769 | if (!mbox) |
| 5770 | return 1; |
| 5771 | lpfc_linkdown(phba); |
| 5772 | lpfc_init_link(phba, mbox, |
| 5773 | phba->cfg_topology, |
| 5774 | phba->cfg_link_speed); |
| 5775 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 5776 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5777 | mbox->vport = vport; |
| 5778 | rc = lpfc_sli_issue_mbox(phba, mbox, |
| 5779 | MBX_NOWAIT); |
| 5780 | lpfc_set_loopback_flag(phba); |
| 5781 | if (rc == MBX_NOT_FINISHED) |
| 5782 | mempool_free(mbox, phba->mbox_mem_pool); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5783 | return 1; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 5784 | } else { |
| 5785 | /* abort the flogi coming back to ourselves |
| 5786 | * due to external loopback on the port. |
| 5787 | */ |
| 5788 | lpfc_els_abort_flogi(phba); |
| 5789 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5790 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5791 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5792 | spin_lock_irq(shost->host_lock); |
| 5793 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 5794 | spin_unlock_irq(shost->host_lock); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5795 | |
| 5796 | /* If we have the high WWPN we can assign our own |
| 5797 | * myDID; otherwise, we have to WAIT for a PLOGI |
| 5798 | * from the remote NPort to find out what it |
| 5799 | * will be. |
| 5800 | */ |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 5801 | vport->fc_myDID = PT2PT_LocalID; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5802 | } else |
| 5803 | vport->fc_myDID = PT2PT_RemoteID; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5804 | |
| 5805 | /* |
| 5806 | * The vport state should go to LPFC_FLOGI only |
| 5807 | * AFTER we issue a FLOGI, not receive one. |
| 5808 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5809 | spin_lock_irq(shost->host_lock); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5810 | fc_flag = vport->fc_flag; |
| 5811 | port_state = vport->port_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5812 | vport->fc_flag |= FC_PT2PT; |
| 5813 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 5814 | spin_unlock_irq(shost->host_lock); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5815 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5816 | "3311 Rcv Flogi PS x%x new PS x%x " |
| 5817 | "fc_flag x%x new fc_flag x%x\n", |
| 5818 | port_state, vport->port_state, |
| 5819 | fc_flag, vport->fc_flag); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5820 | |
| 5821 | /* |
| 5822 | * We temporarily set fc_myDID to make it look like we are |
| 5823 | * a Fabric. This is done just so we end up with the right |
| 5824 | * did / sid on the FLOGI ACC rsp. |
| 5825 | */ |
| 5826 | did = vport->fc_myDID; |
| 5827 | vport->fc_myDID = Fabric_DID; |
| 5828 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5829 | } else { |
| 5830 | /* Reject this request because invalid parameters */ |
| 5831 | stat.un.b.lsRjtRsvd0 = 0; |
| 5832 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5833 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 5834 | stat.un.b.vendorUnique = 0; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5835 | |
| 5836 | /* |
| 5837 | * We temporarily set fc_myDID to make it look like we are |
| 5838 | * a Fabric. This is done just so we end up with the right |
| 5839 | * did / sid on the FLOGI LS_RJT rsp. |
| 5840 | */ |
| 5841 | did = vport->fc_myDID; |
| 5842 | vport->fc_myDID = Fabric_DID; |
| 5843 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5844 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5845 | NULL); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5846 | |
| 5847 | /* Now lets put fc_myDID back to what its supposed to be */ |
| 5848 | vport->fc_myDID = did; |
| 5849 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5850 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5851 | } |
| 5852 | |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame^] | 5853 | /* send our FLOGI first */ |
| 5854 | if (vport->port_state < LPFC_FLOGI) { |
| 5855 | vport->fc_myDID = 0; |
| 5856 | lpfc_initial_flogi(vport); |
| 5857 | vport->fc_myDID = Fabric_DID; |
| 5858 | } |
| 5859 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5860 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5861 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5862 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5863 | /* Now lets put fc_myDID back to what its supposed to be */ |
| 5864 | vport->fc_myDID = did; |
| 5865 | |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 5866 | if (!(vport->fc_flag & FC_PT2PT_PLOGI)) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5867 | |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 5868 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5869 | if (!mbox) |
| 5870 | goto fail; |
| 5871 | |
| 5872 | lpfc_config_link(phba, mbox); |
| 5873 | |
| 5874 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5875 | mbox->vport = vport; |
| 5876 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5877 | if (rc == MBX_NOT_FINISHED) { |
| 5878 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5879 | goto fail; |
| 5880 | } |
| 5881 | } |
| 5882 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5883 | return 0; |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 5884 | fail: |
| 5885 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5886 | } |
| 5887 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5888 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5889 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5890 | * @vport: pointer to a host virtual N_Port data structure. |
| 5891 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5892 | * @ndlp: pointer to a node-list data structure. |
| 5893 | * |
| 5894 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 5895 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 5896 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 5897 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 5898 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 5899 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 5900 | * |
| 5901 | * Return code |
| 5902 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 5903 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5904 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5905 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5906 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5907 | { |
| 5908 | struct lpfc_dmabuf *pcmd; |
| 5909 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5910 | RNID *rn; |
| 5911 | struct ls_rjt stat; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 5912 | uint32_t cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5913 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5914 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5915 | lp = (uint32_t *) pcmd->virt; |
| 5916 | |
| 5917 | cmd = *lp++; |
| 5918 | rn = (RNID *) lp; |
| 5919 | |
| 5920 | /* RNID received */ |
| 5921 | |
| 5922 | switch (rn->Format) { |
| 5923 | case 0: |
| 5924 | case RNID_TOPOLOGY_DISC: |
| 5925 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5926 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5927 | break; |
| 5928 | default: |
| 5929 | /* Reject this request because format not supported */ |
| 5930 | stat.un.b.lsRjtRsvd0 = 0; |
| 5931 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5932 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5933 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5934 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5935 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5936 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5937 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5938 | } |
| 5939 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5940 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5941 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 5942 | * @vport: pointer to a host virtual N_Port data structure. |
| 5943 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5944 | * @ndlp: pointer to a node-list data structure. |
| 5945 | * |
| 5946 | * Return code |
| 5947 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 5948 | **/ |
| 5949 | static int |
| 5950 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5951 | struct lpfc_nodelist *ndlp) |
| 5952 | { |
| 5953 | uint8_t *pcmd; |
| 5954 | |
| 5955 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 5956 | |
| 5957 | /* skip over first word of echo command to find echo data */ |
| 5958 | pcmd += sizeof(uint32_t); |
| 5959 | |
| 5960 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 5961 | return 0; |
| 5962 | } |
| 5963 | |
| 5964 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5965 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5966 | * @vport: pointer to a host virtual N_Port data structure. |
| 5967 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5968 | * @ndlp: pointer to a node-list data structure. |
| 5969 | * |
| 5970 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 5971 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 5972 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 5973 | * |
| 5974 | * Return code |
| 5975 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 5976 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5977 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5978 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5979 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5980 | { |
| 5981 | struct ls_rjt stat; |
| 5982 | |
| 5983 | /* For now, unconditionally reject this command */ |
| 5984 | stat.un.b.lsRjtRsvd0 = 0; |
| 5985 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5986 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5987 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5988 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5989 | return 0; |
| 5990 | } |
| 5991 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5992 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5993 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 5994 | * @vport: pointer to a host virtual N_Port data structure. |
| 5995 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5996 | * @ndlp: pointer to a node-list data structure. |
| 5997 | * |
| 5998 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 5999 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 6000 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 6001 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 6002 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 6003 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 6004 | * command request" and reason code explanation "Invalid Originator |
| 6005 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 6006 | * RRQ from the target. |
| 6007 | **/ |
| 6008 | static void |
| 6009 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6010 | struct lpfc_nodelist *ndlp) |
| 6011 | { |
| 6012 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6013 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 6014 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6018 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 6019 | * @phba: pointer to lpfc hba data structure. |
| 6020 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6021 | * |
| 6022 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 6023 | * mailbox command. This callback function is to actually send the Accept |
| 6024 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 6025 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 6026 | * mailbox command, constructs the RPS response with the link statistics |
| 6027 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 6028 | * response to the RPS. |
| 6029 | * |
| 6030 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6031 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6032 | * will be stored into the context1 field of the IOCB for the completion |
| 6033 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6034 | * |
| 6035 | **/ |
| 6036 | static void |
| 6037 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6038 | { |
| 6039 | MAILBOX_t *mb; |
| 6040 | IOCB_t *icmd; |
| 6041 | struct RLS_RSP *rls_rsp; |
| 6042 | uint8_t *pcmd; |
| 6043 | struct lpfc_iocbq *elsiocb; |
| 6044 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6045 | uint16_t oxid; |
| 6046 | uint16_t rxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6047 | uint32_t cmdsize; |
| 6048 | |
| 6049 | mb = &pmb->u.mb; |
| 6050 | |
| 6051 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6052 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 6053 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6054 | pmb->context1 = NULL; |
| 6055 | pmb->context2 = NULL; |
| 6056 | |
| 6057 | if (mb->mbxStatus) { |
| 6058 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6059 | return; |
| 6060 | } |
| 6061 | |
| 6062 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6063 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6064 | lpfc_max_els_tries, ndlp, |
| 6065 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6066 | |
| 6067 | /* Decrement the ndlp reference count from previous mbox command */ |
| 6068 | lpfc_nlp_put(ndlp); |
| 6069 | |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6070 | if (!elsiocb) { |
| 6071 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6072 | return; |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6073 | } |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6074 | |
| 6075 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6076 | icmd->ulpContext = rxid; |
| 6077 | icmd->unsli3.rcvsli3.ox_id = oxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6078 | |
| 6079 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6080 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6081 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 6082 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 6083 | |
| 6084 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 6085 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 6086 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 6087 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 6088 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 6089 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 6090 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6091 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 6092 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6093 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 6094 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 6095 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6096 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6097 | ndlp->nlp_rpi); |
| 6098 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6099 | phba->fc_stat.elsXmitACC++; |
| 6100 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 6101 | lpfc_els_free_iocb(phba, elsiocb); |
| 6102 | } |
| 6103 | |
| 6104 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6105 | * 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] | 6106 | * @phba: pointer to lpfc hba data structure. |
| 6107 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6108 | * |
| 6109 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 6110 | * mailbox command. This callback function is to actually send the Accept |
| 6111 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 6112 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 6113 | * mailbox command, constructs the RPS response with the link statistics |
| 6114 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 6115 | * response to the RPS. |
| 6116 | * |
| 6117 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6118 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6119 | * will be stored into the context1 field of the IOCB for the completion |
| 6120 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6121 | * |
| 6122 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 6123 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6124 | 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] | 6125 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6126 | MAILBOX_t *mb; |
| 6127 | IOCB_t *icmd; |
| 6128 | RPS_RSP *rps_rsp; |
| 6129 | uint8_t *pcmd; |
| 6130 | struct lpfc_iocbq *elsiocb; |
| 6131 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6132 | uint16_t status; |
| 6133 | uint16_t oxid; |
| 6134 | uint16_t rxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6135 | uint32_t cmdsize; |
| 6136 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6137 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6138 | |
| 6139 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6140 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 6141 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 6142 | pmb->context1 = NULL; |
| 6143 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6144 | |
| 6145 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6146 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6147 | return; |
| 6148 | } |
| 6149 | |
| 6150 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6151 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6152 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6153 | lpfc_max_els_tries, ndlp, |
| 6154 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6155 | |
| 6156 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6157 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6158 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6159 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6160 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6161 | |
| 6162 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6163 | icmd->ulpContext = rxid; |
| 6164 | icmd->unsli3.rcvsli3.ox_id = oxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6165 | |
| 6166 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6167 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6168 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6169 | rps_rsp = (RPS_RSP *)pcmd; |
| 6170 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6171 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6172 | status = 0x10; |
| 6173 | else |
| 6174 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6175 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6176 | status |= 0x4; |
| 6177 | |
| 6178 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6179 | rps_rsp->portStatus = cpu_to_be16(status); |
| 6180 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 6181 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 6182 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 6183 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 6184 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 6185 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6186 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6187 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6188 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 6189 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 6190 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6191 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6192 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6193 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6194 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6195 | 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] | 6196 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6197 | return; |
| 6198 | } |
| 6199 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6200 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6201 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 6202 | * @vport: pointer to a host virtual N_Port data structure. |
| 6203 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6204 | * @ndlp: pointer to a node-list data structure. |
| 6205 | * |
| 6206 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 6207 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6208 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6209 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 6210 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 6211 | * for reading the HBA link statistics. It is for the callback function, |
| 6212 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 6213 | * to actually sending out RPL Accept (ACC) response. |
| 6214 | * |
| 6215 | * Return codes |
| 6216 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 6217 | **/ |
| 6218 | static int |
| 6219 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6220 | struct lpfc_nodelist *ndlp) |
| 6221 | { |
| 6222 | struct lpfc_hba *phba = vport->phba; |
| 6223 | LPFC_MBOXQ_t *mbox; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6224 | struct ls_rjt stat; |
| 6225 | |
| 6226 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6227 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6228 | /* reject the unsolicited RPS request and done with it */ |
| 6229 | goto reject_out; |
| 6230 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6231 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 6232 | if (mbox) { |
| 6233 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6234 | mbox->context1 = (void *)((unsigned long) |
| 6235 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 6236 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6237 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6238 | mbox->vport = vport; |
| 6239 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 6240 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 6241 | != MBX_NOT_FINISHED) |
| 6242 | /* Mbox completion will send ELS Response */ |
| 6243 | return 0; |
| 6244 | /* Decrement reference count used for the failed mbox |
| 6245 | * command. |
| 6246 | */ |
| 6247 | lpfc_nlp_put(ndlp); |
| 6248 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6249 | } |
| 6250 | reject_out: |
| 6251 | /* issue rejection response */ |
| 6252 | stat.un.b.lsRjtRsvd0 = 0; |
| 6253 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6254 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6255 | stat.un.b.vendorUnique = 0; |
| 6256 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6257 | return 0; |
| 6258 | } |
| 6259 | |
| 6260 | /** |
| 6261 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 6262 | * @vport: pointer to a host virtual N_Port data structure. |
| 6263 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6264 | * @ndlp: pointer to a node-list data structure. |
| 6265 | * |
| 6266 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 6267 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6268 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6269 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 6270 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 6271 | * Value (RTV) unsolicited IOCB event. |
| 6272 | * |
| 6273 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6274 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6275 | * will be stored into the context1 field of the IOCB for the completion |
| 6276 | * callback function to the RPS Accept Response ELS IOCB command. |
| 6277 | * |
| 6278 | * Return codes |
| 6279 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 6280 | **/ |
| 6281 | static int |
| 6282 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6283 | struct lpfc_nodelist *ndlp) |
| 6284 | { |
| 6285 | struct lpfc_hba *phba = vport->phba; |
| 6286 | struct ls_rjt stat; |
| 6287 | struct RTV_RSP *rtv_rsp; |
| 6288 | uint8_t *pcmd; |
| 6289 | struct lpfc_iocbq *elsiocb; |
| 6290 | uint32_t cmdsize; |
| 6291 | |
| 6292 | |
| 6293 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6294 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6295 | /* reject the unsolicited RPS request and done with it */ |
| 6296 | goto reject_out; |
| 6297 | |
| 6298 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 6299 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6300 | lpfc_max_els_tries, ndlp, |
| 6301 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6302 | |
| 6303 | if (!elsiocb) |
| 6304 | return 1; |
| 6305 | |
| 6306 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6307 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6308 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 6309 | |
| 6310 | /* use the command's xri in the response */ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6311 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 6312 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6313 | |
| 6314 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 6315 | |
| 6316 | /* populate RTV payload */ |
| 6317 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 6318 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 6319 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 6320 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 6321 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 6322 | |
| 6323 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 6324 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 6325 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 6326 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 6327 | "Data: x%x x%x x%x\n", |
| 6328 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6329 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6330 | ndlp->nlp_rpi, |
| 6331 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 6332 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6333 | phba->fc_stat.elsXmitACC++; |
| 6334 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 6335 | lpfc_els_free_iocb(phba, elsiocb); |
| 6336 | return 0; |
| 6337 | |
| 6338 | reject_out: |
| 6339 | /* issue rejection response */ |
| 6340 | stat.un.b.lsRjtRsvd0 = 0; |
| 6341 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6342 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6343 | stat.un.b.vendorUnique = 0; |
| 6344 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6345 | return 0; |
| 6346 | } |
| 6347 | |
| 6348 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6349 | * @vport: pointer to a host virtual N_Port data structure. |
| 6350 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6351 | * @ndlp: pointer to a node-list data structure. |
| 6352 | * |
| 6353 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 6354 | * ELS unsolicited event. It first checks the remote port state. If the |
| 6355 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 6356 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 6357 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 6358 | * for reading the HBA link statistics. It is for the callback function, |
| 6359 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 6360 | * to actually sending out RPS Accept (ACC) response. |
| 6361 | * |
| 6362 | * Return codes |
| 6363 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 6364 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6365 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6366 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6367 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6368 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6369 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6370 | uint32_t *lp; |
| 6371 | uint8_t flag; |
| 6372 | LPFC_MBOXQ_t *mbox; |
| 6373 | struct lpfc_dmabuf *pcmd; |
| 6374 | RPS *rps; |
| 6375 | struct ls_rjt stat; |
| 6376 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6377 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6378 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 6379 | /* reject the unsolicited RPS request and done with it */ |
| 6380 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6381 | |
| 6382 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6383 | lp = (uint32_t *) pcmd->virt; |
| 6384 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 6385 | rps = (RPS *) lp; |
| 6386 | |
| 6387 | if ((flag == 0) || |
| 6388 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6389 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6390 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6391 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6392 | printk("Fix me....\n"); |
| 6393 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6394 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 6395 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6396 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6397 | mbox->context1 = (void *)((unsigned long) |
| 6398 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 6399 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6400 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6401 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6402 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6403 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6404 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6405 | /* Mbox completion will send ELS Response */ |
| 6406 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6407 | /* Decrement reference count used for the failed mbox |
| 6408 | * command. |
| 6409 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6410 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6411 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6412 | } |
| 6413 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6414 | |
| 6415 | reject_out: |
| 6416 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6417 | stat.un.b.lsRjtRsvd0 = 0; |
| 6418 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6419 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6420 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6421 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6422 | return 0; |
| 6423 | } |
| 6424 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6425 | /* lpfc_issue_els_rrq - Process an unsolicited rps iocb |
| 6426 | * @vport: pointer to a host virtual N_Port data structure. |
| 6427 | * @ndlp: pointer to a node-list data structure. |
| 6428 | * @did: DID of the target. |
| 6429 | * @rrq: Pointer to the rrq struct. |
| 6430 | * |
| 6431 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is |
| 6432 | * Successful the the completion handler will clear the RRQ. |
| 6433 | * |
| 6434 | * Return codes |
| 6435 | * 0 - Successfully sent rrq els iocb. |
| 6436 | * 1 - Failed to send rrq els iocb. |
| 6437 | **/ |
| 6438 | static int |
| 6439 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6440 | uint32_t did, struct lpfc_node_rrq *rrq) |
| 6441 | { |
| 6442 | struct lpfc_hba *phba = vport->phba; |
| 6443 | struct RRQ *els_rrq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6444 | struct lpfc_iocbq *elsiocb; |
| 6445 | uint8_t *pcmd; |
| 6446 | uint16_t cmdsize; |
| 6447 | int ret; |
| 6448 | |
| 6449 | |
| 6450 | if (ndlp != rrq->ndlp) |
| 6451 | ndlp = rrq->ndlp; |
| 6452 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 6453 | return 1; |
| 6454 | |
| 6455 | /* If ndlp is not NULL, we will bump the reference count on it */ |
| 6456 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); |
| 6457 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, |
| 6458 | ELS_CMD_RRQ); |
| 6459 | if (!elsiocb) |
| 6460 | return 1; |
| 6461 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 6462 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6463 | |
| 6464 | /* For RRQ request, remainder of payload is Exchange IDs */ |
| 6465 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; |
| 6466 | pcmd += sizeof(uint32_t); |
| 6467 | els_rrq = (struct RRQ *) pcmd; |
| 6468 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 6469 | 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] | 6470 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
| 6471 | bf_set(rrq_did, els_rrq, vport->fc_myDID); |
| 6472 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); |
| 6473 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); |
| 6474 | |
| 6475 | |
| 6476 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6477 | "Issue RRQ: did:x%x", |
| 6478 | did, rrq->xritag, rrq->rxid); |
| 6479 | elsiocb->context_un.rrq = rrq; |
| 6480 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; |
| 6481 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6482 | |
| 6483 | if (ret == IOCB_ERROR) { |
| 6484 | lpfc_els_free_iocb(phba, elsiocb); |
| 6485 | return 1; |
| 6486 | } |
| 6487 | return 0; |
| 6488 | } |
| 6489 | |
| 6490 | /** |
| 6491 | * lpfc_send_rrq - Sends ELS RRQ if needed. |
| 6492 | * @phba: pointer to lpfc hba data structure. |
| 6493 | * @rrq: pointer to the active rrq. |
| 6494 | * |
| 6495 | * This routine will call the lpfc_issue_els_rrq if the rrq is |
| 6496 | * still active for the xri. If this function returns a failure then |
| 6497 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. |
| 6498 | * |
| 6499 | * Returns 0 Success. |
| 6500 | * 1 Failure. |
| 6501 | **/ |
| 6502 | int |
| 6503 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) |
| 6504 | { |
| 6505 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, |
| 6506 | rrq->nlp_DID); |
| 6507 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) |
| 6508 | return lpfc_issue_els_rrq(rrq->vport, ndlp, |
| 6509 | rrq->nlp_DID, rrq); |
| 6510 | else |
| 6511 | return 1; |
| 6512 | } |
| 6513 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6514 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6515 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6516 | * @vport: pointer to a host virtual N_Port data structure. |
| 6517 | * @cmdsize: size of the ELS command. |
| 6518 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 6519 | * @ndlp: pointer to a node-list data structure. |
| 6520 | * |
| 6521 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 6522 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 6523 | * |
| 6524 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6525 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6526 | * will be stored into the context1 field of the IOCB for the completion |
| 6527 | * callback function to the RPL Accept Response ELS command. |
| 6528 | * |
| 6529 | * Return code |
| 6530 | * 0 - Successfully issued ACC RPL ELS command |
| 6531 | * 1 - Failed to issue ACC RPL ELS command |
| 6532 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 6533 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6534 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 6535 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6536 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6537 | struct lpfc_hba *phba = vport->phba; |
| 6538 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6539 | RPL_RSP rpl_rsp; |
| 6540 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6541 | uint8_t *pcmd; |
| 6542 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6543 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 6544 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6545 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6546 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6547 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6548 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6549 | icmd = &elsiocb->iocb; |
| 6550 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 6551 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 6552 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6553 | |
| 6554 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6555 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6556 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6557 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 6558 | pcmd += sizeof(uint16_t); |
| 6559 | |
| 6560 | /* Setup the RPL ACC payload */ |
| 6561 | rpl_rsp.listLen = be32_to_cpu(1); |
| 6562 | rpl_rsp.index = 0; |
| 6563 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6564 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 6565 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6566 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6567 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6568 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6569 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6570 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 6571 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 6572 | "rpi x%x\n", |
| 6573 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 6574 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 6575 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6576 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6577 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6578 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6579 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6580 | lpfc_els_free_iocb(phba, elsiocb); |
| 6581 | return 1; |
| 6582 | } |
| 6583 | return 0; |
| 6584 | } |
| 6585 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6586 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6587 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6588 | * @vport: pointer to a host virtual N_Port data structure. |
| 6589 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6590 | * @ndlp: pointer to a node-list data structure. |
| 6591 | * |
| 6592 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 6593 | * unsolicited event. It first checks the remote port state. If the remote |
| 6594 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 6595 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 6596 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 6597 | * to accept the RPL. |
| 6598 | * |
| 6599 | * Return code |
| 6600 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 6601 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6602 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6603 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6604 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6605 | { |
| 6606 | struct lpfc_dmabuf *pcmd; |
| 6607 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6608 | uint32_t maxsize; |
| 6609 | uint16_t cmdsize; |
| 6610 | RPL *rpl; |
| 6611 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6612 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6613 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 6614 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6615 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6616 | stat.un.b.lsRjtRsvd0 = 0; |
| 6617 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6618 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 6619 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6620 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 6621 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 6622 | /* rejected the unsolicited RPL request and done with it */ |
| 6623 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6624 | } |
| 6625 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6626 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6627 | lp = (uint32_t *) pcmd->virt; |
| 6628 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6629 | maxsize = be32_to_cpu(rpl->maxsize); |
| 6630 | |
| 6631 | /* We support only one port */ |
| 6632 | if ((rpl->index == 0) && |
| 6633 | ((maxsize == 0) || |
| 6634 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 6635 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6636 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6637 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 6638 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6639 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6640 | |
| 6641 | return 0; |
| 6642 | } |
| 6643 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6644 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6645 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6646 | * @vport: pointer to a virtual N_Port data structure. |
| 6647 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6648 | * @ndlp: pointer to a node-list data structure. |
| 6649 | * |
| 6650 | * This routine processes Fibre Channel Address Resolution Protocol |
| 6651 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 6652 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 6653 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 6654 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 6655 | * remote PortName is compared against the FC PortName stored in the @vport |
| 6656 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 6657 | * compared against the FC NodeName stored in the @vport data structure. |
| 6658 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 6659 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 6660 | * invoked to send out FARP Response to the remote node. Before sending the |
| 6661 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 6662 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 6663 | * routine is invoked to log into the remote port first. |
| 6664 | * |
| 6665 | * Return code |
| 6666 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 6667 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6668 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6669 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6670 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6671 | { |
| 6672 | struct lpfc_dmabuf *pcmd; |
| 6673 | uint32_t *lp; |
| 6674 | IOCB_t *icmd; |
| 6675 | FARP *fp; |
| 6676 | uint32_t cmd, cnt, did; |
| 6677 | |
| 6678 | icmd = &cmdiocb->iocb; |
| 6679 | did = icmd->un.elsreq64.remoteID; |
| 6680 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6681 | lp = (uint32_t *) pcmd->virt; |
| 6682 | |
| 6683 | cmd = *lp++; |
| 6684 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6685 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6686 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6687 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6688 | /* We will only support match on WWPN or WWNN */ |
| 6689 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6690 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | cnt = 0; |
| 6694 | /* If this FARP command is searching for my portname */ |
| 6695 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6696 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6697 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6698 | cnt = 1; |
| 6699 | } |
| 6700 | |
| 6701 | /* If this FARP command is searching for my nodename */ |
| 6702 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6703 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6704 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6705 | cnt = 1; |
| 6706 | } |
| 6707 | |
| 6708 | if (cnt) { |
| 6709 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 6710 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 6711 | /* Log back into the node before sending the FARP. */ |
| 6712 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6713 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6714 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 6715 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6716 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6717 | } |
| 6718 | |
| 6719 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6720 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 6721 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6722 | } |
| 6723 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6724 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6725 | } |
| 6726 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6727 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6728 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6729 | * @vport: pointer to a host virtual N_Port data structure. |
| 6730 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6731 | * @ndlp: pointer to a node-list data structure. |
| 6732 | * |
| 6733 | * This routine processes Fibre Channel Address Resolution Protocol |
| 6734 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 6735 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 6736 | * the FARP response request. |
| 6737 | * |
| 6738 | * Return code |
| 6739 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 6740 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6741 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6742 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6743 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6744 | { |
| 6745 | struct lpfc_dmabuf *pcmd; |
| 6746 | uint32_t *lp; |
| 6747 | IOCB_t *icmd; |
| 6748 | uint32_t cmd, did; |
| 6749 | |
| 6750 | icmd = &cmdiocb->iocb; |
| 6751 | did = icmd->un.elsreq64.remoteID; |
| 6752 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6753 | lp = (uint32_t *) pcmd->virt; |
| 6754 | |
| 6755 | cmd = *lp++; |
| 6756 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6757 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6758 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6759 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6760 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6761 | |
| 6762 | return 0; |
| 6763 | } |
| 6764 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6765 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6766 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6767 | * @vport: pointer to a host virtual N_Port data structure. |
| 6768 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6769 | * @fan_ndlp: pointer to a node-list data structure. |
| 6770 | * |
| 6771 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 6772 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 6773 | * only be processed on a physical port (i.e., the @vport represents the |
| 6774 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 6775 | * compared against those in the phba data structure. If any of those is |
| 6776 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 6777 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 6778 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 6779 | * is invoked to register login to the fabric. |
| 6780 | * |
| 6781 | * Return code |
| 6782 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 6783 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6784 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6785 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6786 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6787 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6788 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6789 | uint32_t *lp; |
| 6790 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6791 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6792 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 6793 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 6794 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6795 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6796 | if ((vport == phba->pport) && |
| 6797 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6798 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6799 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6800 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6801 | sizeof(struct lpfc_name)))) { |
| 6802 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6803 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6804 | } else { |
| 6805 | /* FAN verified - skip FLOGI */ |
| 6806 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6807 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6808 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6809 | else { |
| 6810 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6811 | "3138 Need register VFI: (x%x/%x)\n", |
| 6812 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6813 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6814 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6815 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6816 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6817 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6818 | } |
| 6819 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6820 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6821 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6822 | * @ptr: holder for the timer function associated data. |
| 6823 | * |
| 6824 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 6825 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 6826 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 6827 | * up the worker thread. It is for the worker thread to invoke the routine |
| 6828 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 6829 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6830 | void |
| 6831 | lpfc_els_timeout(unsigned long ptr) |
| 6832 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6833 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 6834 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6835 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6836 | unsigned long iflag; |
| 6837 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6838 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6839 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 6840 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6841 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6842 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6843 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 6844 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6845 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6846 | return; |
| 6847 | } |
| 6848 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6849 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6850 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6851 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6852 | * @vport: pointer to a virtual N_Port data structure. |
| 6853 | * |
| 6854 | * This routine is the actual handler function that processes an ELS timeout |
| 6855 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 6856 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 6857 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 6858 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6859 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6860 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6861 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6862 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6863 | struct lpfc_sli_ring *pring; |
| 6864 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6865 | IOCB_t *cmd = NULL; |
| 6866 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6867 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6868 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6869 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6870 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6871 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6872 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6873 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 6874 | |
| 6875 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 6876 | if ((phba->pport->load_flag & FC_UNLOADING)) |
| 6877 | return; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6878 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 6879 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6880 | spin_lock(&pring->ring_lock); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6881 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 6882 | if ((phba->pport->load_flag & FC_UNLOADING)) { |
| 6883 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6884 | spin_unlock(&pring->ring_lock); |
| 6885 | spin_unlock_irq(&phba->hbalock); |
| 6886 | return; |
| 6887 | } |
| 6888 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 6889 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6890 | cmd = &piocb->iocb; |
| 6891 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6892 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 6893 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 6894 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6895 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6896 | |
| 6897 | if (piocb->vport != vport) |
| 6898 | continue; |
| 6899 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6900 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6901 | if (pcmd) |
| 6902 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6903 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6904 | if (els_command == ELS_CMD_FARP || |
| 6905 | els_command == ELS_CMD_FARPR || |
| 6906 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6907 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6908 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6909 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6910 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6911 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6912 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6913 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6914 | continue; |
| 6915 | } |
| 6916 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6917 | remote_ID = 0xffffffff; |
| 6918 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6919 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6920 | else { |
| 6921 | struct lpfc_nodelist *ndlp; |
| 6922 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6923 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6924 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6925 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6926 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6927 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 6928 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6929 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6930 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 6931 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6932 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
James Smart | 15026c9 | 2013-12-17 20:30:09 -0500 | [diff] [blame] | 6933 | cmd = &piocb->iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6934 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6935 | "0127 ELS timeout Data: x%x x%x x%x " |
| 6936 | "x%x\n", els_command, |
| 6937 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 6938 | spin_lock_irq(&phba->hbalock); |
| 6939 | list_del_init(&piocb->dlist); |
| 6940 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 6941 | spin_unlock_irq(&phba->hbalock); |
| 6942 | } |
| 6943 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 6944 | if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq)) |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 6945 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 6946 | mod_timer(&vport->els_tmofunc, |
| 6947 | jiffies + msecs_to_jiffies(1000 * timeout)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6948 | } |
| 6949 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6950 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6951 | * 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] | 6952 | * @vport: pointer to a host virtual N_Port data structure. |
| 6953 | * |
| 6954 | * This routine is used to clean up all the outstanding ELS commands on a |
| 6955 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 6956 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 6957 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 6958 | * the IOCBs with a non-NULL completion callback function, the callback |
| 6959 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 6960 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 6961 | * callback function, the IOCB will simply be released. Finally, it walks |
| 6962 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 6963 | * completion queue IOCB that is associated with the @vport and is not |
| 6964 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 6965 | * part of the discovery state machine) out to HBA by invoking the |
| 6966 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 6967 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 6968 | * the IOCBs are aborted when this function returns. |
| 6969 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6970 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6971 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6972 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 6973 | LIST_HEAD(abort_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6974 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6975 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6976 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6977 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6978 | |
| 6979 | lpfc_fabric_abort_vport(vport); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 6980 | /* |
| 6981 | * For SLI3, only the hbalock is required. But SLI4 needs to coordinate |
| 6982 | * with the ring insert operation. Because lpfc_sli_issue_abort_iotag |
| 6983 | * ultimately grabs the ring_lock, the driver must splice the list into |
| 6984 | * a working list and release the locks before calling the abort. |
| 6985 | */ |
| 6986 | spin_lock_irq(&phba->hbalock); |
| 6987 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6988 | spin_lock(&pring->ring_lock); |
| 6989 | |
| 6990 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 6991 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 6992 | continue; |
| 6993 | |
| 6994 | if (piocb->vport != vport) |
| 6995 | continue; |
| 6996 | list_add_tail(&piocb->dlist, &abort_list); |
| 6997 | } |
| 6998 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6999 | spin_unlock(&pring->ring_lock); |
| 7000 | spin_unlock_irq(&phba->hbalock); |
| 7001 | /* Abort each iocb on the aborted list and remove the dlist links. */ |
| 7002 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 7003 | spin_lock_irq(&phba->hbalock); |
| 7004 | list_del_init(&piocb->dlist); |
| 7005 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 7006 | spin_unlock_irq(&phba->hbalock); |
| 7007 | } |
| 7008 | if (!list_empty(&abort_list)) |
| 7009 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7010 | "3387 abort list for txq not empty\n"); |
| 7011 | INIT_LIST_HEAD(&abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7012 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7013 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7014 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7015 | spin_lock(&pring->ring_lock); |
| 7016 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7017 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 7018 | cmd = &piocb->iocb; |
| 7019 | |
| 7020 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 7021 | continue; |
| 7022 | } |
| 7023 | |
| 7024 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7025 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 7026 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 7027 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 7028 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7029 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7030 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7031 | if (piocb->vport != vport) |
| 7032 | continue; |
| 7033 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7034 | list_del_init(&piocb->list); |
| 7035 | list_add_tail(&piocb->list, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7036 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7037 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7038 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7039 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 7040 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7041 | /* Cancell all the IOCBs from the completions list */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7042 | lpfc_sli_cancel_iocbs(phba, &abort_list, |
| 7043 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 7044 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7045 | return; |
| 7046 | } |
| 7047 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7048 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7049 | * 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] | 7050 | * @phba: pointer to lpfc hba data structure. |
| 7051 | * |
| 7052 | * This routine is used to clean up all the outstanding ELS commands on a |
| 7053 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 7054 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 7055 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 7056 | * the IOCBs with the completion callback function associated, the callback |
| 7057 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 7058 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 7059 | * callback function associated, the IOCB will simply be released. Finally, |
| 7060 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 7061 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 7062 | * management plane IOCBs that are not part of the discovery state machine) |
| 7063 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 7064 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 7065 | void |
| 7066 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 7067 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 7068 | struct lpfc_vport *vport; |
| 7069 | list_for_each_entry(vport, &phba->port_list, listentry) |
| 7070 | lpfc_els_flush_cmd(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7071 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 7072 | return; |
| 7073 | } |
| 7074 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7075 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7076 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7077 | * @phba: Pointer to hba context object. |
| 7078 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 7079 | * @rspiocbp: Pointer to response iocb which reported error. |
| 7080 | * |
| 7081 | * This function sends an event when there is an ELS command |
| 7082 | * failure. |
| 7083 | **/ |
| 7084 | void |
| 7085 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 7086 | struct lpfc_iocbq *cmdiocbp, |
| 7087 | struct lpfc_iocbq *rspiocbp) |
| 7088 | { |
| 7089 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 7090 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7091 | struct lpfc_lsrjt_event lsrjt_event; |
| 7092 | struct lpfc_fabric_event_header fabric_event; |
| 7093 | struct ls_rjt stat; |
| 7094 | struct lpfc_nodelist *ndlp; |
| 7095 | uint32_t *pcmd; |
| 7096 | |
| 7097 | ndlp = cmdiocbp->context1; |
| 7098 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 7099 | return; |
| 7100 | |
| 7101 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 7102 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 7103 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 7104 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 7105 | sizeof(struct lpfc_name)); |
| 7106 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 7107 | sizeof(struct lpfc_name)); |
| 7108 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 7109 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7110 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7111 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 7112 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 7113 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 7114 | fc_host_post_vendor_event(shost, |
| 7115 | fc_get_event_number(), |
| 7116 | sizeof(lsrjt_event), |
| 7117 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7118 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7119 | return; |
| 7120 | } |
| 7121 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 7122 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 7123 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 7124 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 7125 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 7126 | else |
| 7127 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 7128 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 7129 | sizeof(struct lpfc_name)); |
| 7130 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 7131 | sizeof(struct lpfc_name)); |
| 7132 | fc_host_post_vendor_event(shost, |
| 7133 | fc_get_event_number(), |
| 7134 | sizeof(fabric_event), |
| 7135 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7136 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7137 | return; |
| 7138 | } |
| 7139 | |
| 7140 | } |
| 7141 | |
| 7142 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7143 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7144 | * @vport: Pointer to vport object. |
| 7145 | * @ndlp: Pointer FC node object. |
| 7146 | * @cmd: ELS command code. |
| 7147 | * |
| 7148 | * This function posts an event when there is an incoming |
| 7149 | * unsolicited ELS command. |
| 7150 | **/ |
| 7151 | static void |
| 7152 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 7153 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7154 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7155 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7156 | struct lpfc_els_event_header *els_data = NULL; |
| 7157 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7158 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7159 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7160 | if (*payload == ELS_CMD_LOGO) { |
| 7161 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 7162 | if (!logo_data) { |
| 7163 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7164 | "0148 Failed to allocate memory " |
| 7165 | "for LOGO event\n"); |
| 7166 | return; |
| 7167 | } |
| 7168 | els_data = &logo_data->header; |
| 7169 | } else { |
| 7170 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 7171 | GFP_KERNEL); |
| 7172 | if (!els_data) { |
| 7173 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7174 | "0149 Failed to allocate memory " |
| 7175 | "for ELS event\n"); |
| 7176 | return; |
| 7177 | } |
| 7178 | } |
| 7179 | els_data->event_type = FC_REG_ELS_EVENT; |
| 7180 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7181 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7182 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7183 | break; |
| 7184 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7185 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7186 | break; |
| 7187 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7188 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 7189 | break; |
| 7190 | case ELS_CMD_LOGO: |
| 7191 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 7192 | /* Copy the WWPN in the LOGO payload */ |
| 7193 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 7194 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7195 | break; |
| 7196 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 7197 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7198 | return; |
| 7199 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7200 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 7201 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 7202 | if (*payload == ELS_CMD_LOGO) { |
| 7203 | fc_host_post_vendor_event(shost, |
| 7204 | fc_get_event_number(), |
| 7205 | sizeof(struct lpfc_logo_event), |
| 7206 | (char *)logo_data, |
| 7207 | LPFC_NL_VENDOR_ID); |
| 7208 | kfree(logo_data); |
| 7209 | } else { |
| 7210 | fc_host_post_vendor_event(shost, |
| 7211 | fc_get_event_number(), |
| 7212 | sizeof(struct lpfc_els_event_header), |
| 7213 | (char *)els_data, |
| 7214 | LPFC_NL_VENDOR_ID); |
| 7215 | kfree(els_data); |
| 7216 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7217 | |
| 7218 | return; |
| 7219 | } |
| 7220 | |
| 7221 | |
| 7222 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7223 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7224 | * @phba: pointer to lpfc hba data structure. |
| 7225 | * @pring: pointer to a SLI ring. |
| 7226 | * @vport: pointer to a host virtual N_Port data structure. |
| 7227 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 7228 | * |
| 7229 | * This routine is used for processing the IOCB associated with a unsolicited |
| 7230 | * event. It first determines whether there is an existing ndlp that matches |
| 7231 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 7232 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 7233 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 7234 | * of the discovery state machine. |
| 7235 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7236 | static void |
| 7237 | 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] | 7238 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7239 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7240 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7241 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7242 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7243 | uint32_t *payload; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7244 | uint32_t cmd, did, newnode; |
| 7245 | uint8_t rjt_exp, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7246 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7247 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7248 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7249 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7250 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7251 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7252 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 7253 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7254 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 7255 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7256 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7257 | did = icmd->un.rcvels.remoteID; |
| 7258 | if (icmd->ulpStatus) { |
| 7259 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7260 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 7261 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7262 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7263 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7264 | |
| 7265 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7266 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7267 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7268 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7269 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7270 | if (vport->load_flag & FC_UNLOADING) |
| 7271 | goto dropit; |
| 7272 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7273 | /* If NPort discovery is delayed drop incoming ELS */ |
| 7274 | if ((vport->fc_flag & FC_DISC_DELAYED) && |
| 7275 | (cmd != ELS_CMD_PLOGI)) |
| 7276 | goto dropit; |
| 7277 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7278 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7279 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7280 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7281 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7282 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7283 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7284 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7285 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7286 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7287 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7288 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7289 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7290 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 7291 | ndlp = lpfc_enable_node(vport, ndlp, |
| 7292 | NLP_STE_UNUSED_NODE); |
| 7293 | if (!ndlp) |
| 7294 | goto dropit; |
| 7295 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 7296 | newnode = 1; |
| 7297 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 7298 | ndlp->nlp_type |= NLP_FABRIC; |
| 7299 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 7300 | /* This is similar to the new node path */ |
| 7301 | ndlp = lpfc_nlp_get(ndlp); |
| 7302 | if (!ndlp) |
| 7303 | goto dropit; |
| 7304 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 7305 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7306 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7307 | |
| 7308 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7309 | |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7310 | /* |
| 7311 | * Do not process any unsolicited ELS commands |
| 7312 | * if the ndlp is in DEV_LOSS |
| 7313 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 7314 | shost = lpfc_shost_from_vport(vport); |
| 7315 | spin_lock_irq(shost->host_lock); |
| 7316 | if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) { |
| 7317 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7318 | goto dropit; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 7319 | } |
| 7320 | spin_unlock_irq(shost->host_lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 7321 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 7322 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7323 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7324 | |
| 7325 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 7326 | cmd &= ELS_CMD_MASK; |
| 7327 | } |
| 7328 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7329 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7330 | "0112 ELS command x%x received from NPORT x%x " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7331 | "Data: x%x x%x x%x x%x\n", |
| 7332 | cmd, did, vport->port_state, vport->fc_flag, |
| 7333 | vport->fc_myDID, vport->fc_prevDID); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame^] | 7334 | |
| 7335 | /* reject till our FLOGI completes */ |
| 7336 | if ((vport->port_state < LPFC_FABRIC_CFG_LINK) && |
| 7337 | (cmd != ELS_CMD_FLOGI)) { |
| 7338 | rjt_err = LSRJT_UNABLE_TPC; |
| 7339 | rjt_exp = LSEXP_NOTHING_MORE; |
| 7340 | goto lsrjt; |
| 7341 | } |
| 7342 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7343 | switch (cmd) { |
| 7344 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7345 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7346 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 7347 | did, vport->port_state, ndlp->nlp_flag); |
| 7348 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7349 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7350 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7351 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 7352 | (phba->pport->fc_flag & FC_PT2PT)) { |
| 7353 | vport->fc_prevDID = vport->fc_myDID; |
| 7354 | /* Our DID needs to be updated before registering |
| 7355 | * the vfi. This is done in lpfc_rcv_plogi but |
| 7356 | * that is called after the reg_vfi. |
| 7357 | */ |
| 7358 | vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo; |
| 7359 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7360 | "3312 Remote port assigned DID x%x " |
| 7361 | "%x\n", vport->fc_myDID, |
| 7362 | vport->fc_prevDID); |
| 7363 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7364 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7365 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7366 | |
| 7367 | /* If Nport discovery is delayed, reject PLOGIs */ |
| 7368 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 7369 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7370 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7371 | break; |
| 7372 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7373 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 7374 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 7375 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 7376 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7377 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 7378 | break; |
| 7379 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7380 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7381 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7382 | spin_lock_irq(shost->host_lock); |
| 7383 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 7384 | spin_unlock_irq(shost->host_lock); |
| 7385 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7386 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7387 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7388 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7389 | break; |
| 7390 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7391 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7392 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 7393 | did, vport->port_state, ndlp->nlp_flag); |
| 7394 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7395 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7396 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7397 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7398 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7399 | break; |
| 7400 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7401 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7402 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 7403 | did, vport->port_state, ndlp->nlp_flag); |
| 7404 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7405 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7406 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7407 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7408 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7409 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7410 | break; |
| 7411 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7412 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7413 | break; |
| 7414 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7415 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7416 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 7417 | did, vport->port_state, ndlp->nlp_flag); |
| 7418 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7419 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7420 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7421 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7422 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7423 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7424 | break; |
| 7425 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7426 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7427 | break; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 7428 | case ELS_CMD_LCB: |
| 7429 | phba->fc_stat.elsRcvLCB++; |
| 7430 | lpfc_els_rcv_lcb(vport, elsiocb, ndlp); |
| 7431 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 7432 | case ELS_CMD_RDP: |
| 7433 | phba->fc_stat.elsRcvRDP++; |
| 7434 | lpfc_els_rcv_rdp(vport, elsiocb, ndlp); |
| 7435 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7436 | case ELS_CMD_RSCN: |
| 7437 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7438 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7439 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7440 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7441 | break; |
| 7442 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7443 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7444 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 7445 | did, vport->port_state, ndlp->nlp_flag); |
| 7446 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 7447 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7448 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7449 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7450 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7451 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7452 | break; |
| 7453 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7454 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7455 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7456 | break; |
| 7457 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7458 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7459 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 7460 | did, vport->port_state, ndlp->nlp_flag); |
| 7461 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7462 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7463 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7464 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7465 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7466 | break; |
| 7467 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7468 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 7469 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7470 | break; |
| 7471 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7472 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7473 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 7474 | did, vport->port_state, ndlp->nlp_flag); |
| 7475 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7476 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7477 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7478 | break; |
| 7479 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7480 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7481 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 7482 | did, vport->port_state, ndlp->nlp_flag); |
| 7483 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7484 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7485 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7486 | break; |
| 7487 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7488 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7489 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 7490 | did, vport->port_state, ndlp->nlp_flag); |
| 7491 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7492 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7493 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7494 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7495 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7496 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7497 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 7498 | did, vport->port_state, ndlp->nlp_flag); |
| 7499 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7500 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7501 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7502 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7503 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7504 | break; |
| 7505 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7506 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7507 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7508 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7509 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7510 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 7511 | did, vport->port_state, ndlp->nlp_flag); |
| 7512 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7513 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7514 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7515 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7516 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7517 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7518 | case ELS_CMD_RLS: |
| 7519 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7520 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 7521 | did, vport->port_state, ndlp->nlp_flag); |
| 7522 | |
| 7523 | phba->fc_stat.elsRcvRLS++; |
| 7524 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 7525 | if (newnode) |
| 7526 | lpfc_nlp_put(ndlp); |
| 7527 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7528 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7529 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7530 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 7531 | did, vport->port_state, ndlp->nlp_flag); |
| 7532 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7533 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7534 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7535 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7536 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7537 | break; |
| 7538 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7539 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7540 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 7541 | did, vport->port_state, ndlp->nlp_flag); |
| 7542 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7543 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7544 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7545 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7546 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7547 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7548 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7549 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7550 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 7551 | did, vport->port_state, ndlp->nlp_flag); |
| 7552 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7553 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7554 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7555 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7556 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7557 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7558 | case ELS_CMD_RTV: |
| 7559 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7560 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 7561 | did, vport->port_state, ndlp->nlp_flag); |
| 7562 | phba->fc_stat.elsRcvRTV++; |
| 7563 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 7564 | if (newnode) |
| 7565 | lpfc_nlp_put(ndlp); |
| 7566 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7567 | case ELS_CMD_RRQ: |
| 7568 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7569 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 7570 | did, vport->port_state, ndlp->nlp_flag); |
| 7571 | |
| 7572 | phba->fc_stat.elsRcvRRQ++; |
| 7573 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 7574 | if (newnode) |
| 7575 | lpfc_nlp_put(ndlp); |
| 7576 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7577 | case ELS_CMD_ECHO: |
| 7578 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7579 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 7580 | did, vport->port_state, ndlp->nlp_flag); |
| 7581 | |
| 7582 | phba->fc_stat.elsRcvECHO++; |
| 7583 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 7584 | if (newnode) |
| 7585 | lpfc_nlp_put(ndlp); |
| 7586 | break; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7587 | case ELS_CMD_REC: |
| 7588 | /* receive this due to exchange closed */ |
| 7589 | rjt_err = LSRJT_UNABLE_TPC; |
| 7590 | rjt_exp = LSEXP_INVALID_OX_RX; |
| 7591 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7592 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7593 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 7594 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 7595 | cmd, did, vport->port_state); |
| 7596 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7597 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7598 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7599 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7600 | |
| 7601 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7602 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7603 | "0115 Unknown ELS command x%x " |
| 7604 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 7605 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7606 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7607 | break; |
| 7608 | } |
| 7609 | |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame^] | 7610 | lsrjt: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7611 | /* check if need to LS_RJT received ELS cmd */ |
| 7612 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7613 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7614 | stat.un.b.lsRjtRsnCode = rjt_err; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 7615 | stat.un.b.lsRjtRsnCodeExp = rjt_exp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7616 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 7617 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7618 | } |
| 7619 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7620 | lpfc_nlp_put(elsiocb->context1); |
| 7621 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7622 | return; |
| 7623 | |
| 7624 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7625 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7626 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7627 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7628 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7629 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7630 | phba->fc_stat.elsRcvDrop++; |
| 7631 | } |
| 7632 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7633 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7634 | * 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] | 7635 | * @phba: pointer to lpfc hba data structure. |
| 7636 | * @pring: pointer to a SLI ring. |
| 7637 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 7638 | * |
| 7639 | * This routine is used to process an unsolicited event received from a SLI |
| 7640 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 7641 | * associated with the unsolicited event is done by invoking the routine |
| 7642 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 7643 | * SLI ring on which the unsolicited event was received. |
| 7644 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7645 | void |
| 7646 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 7647 | struct lpfc_iocbq *elsiocb) |
| 7648 | { |
| 7649 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7650 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7651 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7652 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 7653 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7654 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7655 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7656 | elsiocb->context2 = NULL; |
| 7657 | elsiocb->context3 = NULL; |
| 7658 | |
| 7659 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 7660 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 7661 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 7662 | (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 7663 | IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7664 | phba->fc_stat.NoRcvBuf++; |
| 7665 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7666 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 7667 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7668 | return; |
| 7669 | } |
| 7670 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7671 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 7672 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 7673 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 7674 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 7675 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7676 | else |
| 7677 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7678 | icmd->unsli3.rcvsli3.vpi); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7679 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7680 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7681 | /* If there are no BDEs associated |
| 7682 | * with this IOCB, there is nothing to do. |
| 7683 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7684 | if (icmd->ulpBdeCount == 0) |
| 7685 | return; |
| 7686 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7687 | /* type of ELS cmd is first 32bit word |
| 7688 | * in packet |
| 7689 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7690 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7691 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7692 | } else { |
| 7693 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 7694 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7695 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 7696 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7697 | } |
| 7698 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7699 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 7700 | /* |
| 7701 | * The different unsolicited event handlers would tell us |
| 7702 | * if they are done with "mp" by setting context2 to NULL. |
| 7703 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7704 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7705 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 7706 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7707 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7708 | |
| 7709 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7710 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7711 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7712 | elsiocb->context2 = bdeBuf2; |
| 7713 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7714 | /* free mp if we are done with it */ |
| 7715 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7716 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 7717 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7718 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7719 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7720 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7721 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7722 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7723 | * 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] | 7724 | * @phba: pointer to lpfc hba data structure. |
| 7725 | * @vport: pointer to a virtual N_Port data structure. |
| 7726 | * |
| 7727 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 7728 | * State Change Request (SCR) for a @vport. This routine will create an |
| 7729 | * ndlp for the Name Server associated to the @vport if such node does |
| 7730 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 7731 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 7732 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 7733 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 7734 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7735 | void |
| 7736 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 7737 | { |
| 7738 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7739 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7740 | |
| 7741 | /* |
| 7742 | * If lpfc_delay_discovery parameter is set and the clean address |
| 7743 | * bit is cleared and fc fabric parameters chenged, delay FC NPort |
| 7744 | * discovery. |
| 7745 | */ |
| 7746 | spin_lock_irq(shost->host_lock); |
| 7747 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 7748 | spin_unlock_irq(shost->host_lock); |
James Smart | 1877570 | 2013-04-17 20:19:25 -0400 | [diff] [blame] | 7749 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 7750 | "3334 Delay fc port discovery for %d seconds\n", |
| 7751 | phba->fc_ratov); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7752 | mod_timer(&vport->delayed_disc_tmo, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7753 | jiffies + msecs_to_jiffies(1000 * phba->fc_ratov)); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7754 | return; |
| 7755 | } |
| 7756 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7757 | |
| 7758 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 7759 | if (!ndlp) { |
| 7760 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 7761 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7762 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7763 | lpfc_disc_start(vport); |
| 7764 | return; |
| 7765 | } |
| 7766 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7767 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7768 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7769 | return; |
| 7770 | } |
| 7771 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7772 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 7773 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 7774 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7775 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7776 | lpfc_disc_start(vport); |
| 7777 | return; |
| 7778 | } |
| 7779 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 7780 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7781 | "0348 NameServer login: node freed\n"); |
| 7782 | return; |
| 7783 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7784 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7785 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7786 | |
| 7787 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 7788 | |
| 7789 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 7790 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7791 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7792 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7793 | return; |
| 7794 | } |
| 7795 | |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 7796 | if (vport->cfg_fdmi_on & LPFC_FDMI_SUPPORT) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7797 | /* If this is the first time, allocate an ndlp and initialize |
| 7798 | * it. Otherwise, make sure the node is enabled and then do the |
| 7799 | * login. |
| 7800 | */ |
| 7801 | ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID); |
| 7802 | if (!ndlp_fdmi) { |
| 7803 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 7804 | GFP_KERNEL); |
| 7805 | if (ndlp_fdmi) { |
| 7806 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 7807 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
| 7808 | } else |
| 7809 | return; |
| 7810 | } |
| 7811 | if (!NLP_CHK_NODE_ACT(ndlp_fdmi)) |
| 7812 | ndlp_fdmi = lpfc_enable_node(vport, |
| 7813 | ndlp_fdmi, |
| 7814 | NLP_STE_NPR_NODE); |
| 7815 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7816 | if (ndlp_fdmi) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7817 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7818 | NLP_STE_PLOGI_ISSUE); |
| 7819 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7820 | } |
| 7821 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7822 | } |
| 7823 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7824 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7825 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7826 | * @phba: pointer to lpfc hba data structure. |
| 7827 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 7828 | * |
| 7829 | * This routine is the completion callback function to register new vport |
| 7830 | * mailbox command. If the new vport mailbox command completes successfully, |
| 7831 | * the fabric registration login shall be performed on physical port (the |
| 7832 | * new vport created is actually a physical port, with VPI 0) or the port |
| 7833 | * login to Name Server for State Change Request (SCR) will be performed |
| 7834 | * on virtual port (real virtual port, with VPI greater than 0). |
| 7835 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7836 | static void |
| 7837 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 7838 | { |
| 7839 | struct lpfc_vport *vport = pmb->vport; |
| 7840 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7841 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 7842 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7843 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7844 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7845 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7846 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7847 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7848 | |
| 7849 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7850 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 7851 | "0915 Register VPI failed : Status: x%x" |
| 7852 | " upd bit: x%x \n", mb->mbxStatus, |
| 7853 | mb->un.varRegVpi.upd); |
| 7854 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 7855 | mb->un.varRegVpi.upd) |
| 7856 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7857 | |
| 7858 | switch (mb->mbxStatus) { |
| 7859 | case 0x11: /* unsupported feature */ |
| 7860 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7861 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7862 | /* giving up on vport registration */ |
| 7863 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 7864 | spin_lock_irq(shost->host_lock); |
| 7865 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 7866 | spin_unlock_irq(shost->host_lock); |
| 7867 | lpfc_can_disctmo(vport); |
| 7868 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7869 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 7870 | case 0x20: |
| 7871 | spin_lock_irq(shost->host_lock); |
| 7872 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 7873 | spin_unlock_irq(shost->host_lock); |
| 7874 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 7875 | pmb->vport = vport; |
| 7876 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 7877 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 7878 | MBX_NOWAIT); |
| 7879 | if (rc == MBX_NOT_FINISHED) { |
| 7880 | lpfc_printf_vlog(vport, |
| 7881 | KERN_ERR, LOG_MBOX, |
| 7882 | "2732 Failed to issue INIT_VPI" |
| 7883 | " mailbox command\n"); |
| 7884 | } else { |
| 7885 | lpfc_nlp_put(ndlp); |
| 7886 | return; |
| 7887 | } |
| 7888 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7889 | default: |
| 7890 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 7891 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7892 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7893 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7894 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7895 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7896 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 7897 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 7898 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7899 | lpfc_issue_init_vfi(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7900 | else |
| 7901 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7902 | break; |
| 7903 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7904 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7905 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 7906 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7907 | spin_unlock_irq(shost->host_lock); |
| 7908 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7909 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 7910 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7911 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7912 | /* |
| 7913 | * If the physical port is instantiated using |
| 7914 | * FDISC, do not start vport discovery. |
| 7915 | */ |
| 7916 | if (vport->port_state != LPFC_FDISC) |
| 7917 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7918 | lpfc_do_scr_ns_plogi(phba, vport); |
| 7919 | } |
| 7920 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7921 | lpfc_do_scr_ns_plogi(phba, vport); |
| 7922 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 7923 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7924 | /* Now, we decrement the ndlp reference count held for this |
| 7925 | * callback function |
| 7926 | */ |
| 7927 | lpfc_nlp_put(ndlp); |
| 7928 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7929 | mempool_free(pmb, phba->mbox_mem_pool); |
| 7930 | return; |
| 7931 | } |
| 7932 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7933 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7934 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7935 | * @phba: pointer to lpfc hba data structure. |
| 7936 | * @vport: pointer to a host virtual N_Port data structure. |
| 7937 | * @ndlp: pointer to a node-list data structure. |
| 7938 | * |
| 7939 | * This routine registers the @vport as a new virtual port with a HBA. |
| 7940 | * It is done through a registering vpi mailbox command. |
| 7941 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7942 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7943 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 7944 | struct lpfc_nodelist *ndlp) |
| 7945 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7946 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7947 | LPFC_MBOXQ_t *mbox; |
| 7948 | |
| 7949 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7950 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7951 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7952 | mbox->vport = vport; |
| 7953 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 7954 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7955 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7956 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7957 | /* mailbox command not success, decrement ndlp |
| 7958 | * reference count for this command |
| 7959 | */ |
| 7960 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7961 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7962 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7963 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 7964 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7965 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7966 | } |
| 7967 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7968 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 7969 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7970 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7971 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7972 | return; |
| 7973 | |
| 7974 | mbox_err_exit: |
| 7975 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 7976 | spin_lock_irq(shost->host_lock); |
| 7977 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 7978 | spin_unlock_irq(shost->host_lock); |
| 7979 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7980 | } |
| 7981 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7982 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7983 | * 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] | 7984 | * @phba: pointer to lpfc hba data structure. |
| 7985 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7986 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7987 | **/ |
| 7988 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7989 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7990 | { |
| 7991 | struct lpfc_vport **vports; |
| 7992 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7993 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7994 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7995 | |
| 7996 | /* Treat this failure as linkdown for all vports */ |
| 7997 | link_state = phba->link_state; |
| 7998 | lpfc_linkdown(phba); |
| 7999 | phba->link_state = link_state; |
| 8000 | |
| 8001 | vports = lpfc_create_vport_work_array(phba); |
| 8002 | |
| 8003 | if (vports) { |
| 8004 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 8005 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 8006 | if (ndlp) |
| 8007 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 8008 | lpfc_els_flush_cmd(vports[i]); |
| 8009 | } |
| 8010 | lpfc_destroy_vport_work_array(phba, vports); |
| 8011 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8012 | } |
| 8013 | |
| 8014 | /** |
| 8015 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 8016 | * @phba: pointer to lpfc hba data structure. |
| 8017 | * |
| 8018 | * This routine abort all pending discovery commands and |
| 8019 | * start a timer to retry FLOGI for the physical port |
| 8020 | * discovery. |
| 8021 | **/ |
| 8022 | void |
| 8023 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 8024 | { |
| 8025 | struct lpfc_nodelist *ndlp; |
| 8026 | struct Scsi_Host *shost; |
| 8027 | |
| 8028 | /* Cancel the all vports retry delay retry timers */ |
| 8029 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8030 | |
| 8031 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 8032 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 8033 | if (!ndlp) |
| 8034 | return; |
| 8035 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8036 | shost = lpfc_shost_from_vport(phba->pport); |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8037 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000)); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8038 | spin_lock_irq(shost->host_lock); |
| 8039 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 8040 | spin_unlock_irq(shost->host_lock); |
| 8041 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 8042 | phba->pport->port_state = LPFC_FLOGI; |
| 8043 | return; |
| 8044 | } |
| 8045 | |
| 8046 | /** |
| 8047 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 8048 | * @phba: pointer to lpfc hba data structure. |
| 8049 | * @cmdiocb: pointer to FDISC command iocb. |
| 8050 | * @rspiocb: pointer to FDISC response iocb. |
| 8051 | * |
| 8052 | * This routine checks if a FLOGI is reguired for FDISC |
| 8053 | * to succeed. |
| 8054 | **/ |
| 8055 | static int |
| 8056 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 8057 | struct lpfc_iocbq *cmdiocb, |
| 8058 | struct lpfc_iocbq *rspiocb) |
| 8059 | { |
| 8060 | |
| 8061 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 8062 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 8063 | return 0; |
| 8064 | else |
| 8065 | return 1; |
| 8066 | } |
| 8067 | |
| 8068 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8069 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8070 | * @phba: pointer to lpfc hba data structure. |
| 8071 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8072 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8073 | * |
| 8074 | * This routine is the completion callback function to a Fabric Discover |
| 8075 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 8076 | * single threaded, each FDISC completion callback function will reset |
| 8077 | * the discovery timer for all vports such that the timers will not get |
| 8078 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 8079 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 8080 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 8081 | * assigned to the vport has been changed with the completion of the FDISC |
| 8082 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 8083 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 8084 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 8085 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 8086 | * Server for State Change Request (SCR). |
| 8087 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8088 | static void |
| 8089 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8090 | struct lpfc_iocbq *rspiocb) |
| 8091 | { |
| 8092 | struct lpfc_vport *vport = cmdiocb->vport; |
| 8093 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8094 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 8095 | struct lpfc_nodelist *np; |
| 8096 | struct lpfc_nodelist *next_np; |
| 8097 | IOCB_t *irsp = &rspiocb->iocb; |
| 8098 | struct lpfc_iocbq *piocb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8099 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 8100 | struct serv_parm *sp; |
| 8101 | uint8_t fabric_param_changed; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8102 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8103 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8104 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 8105 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 8106 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8107 | /* Since all FDISCs are being single threaded, we |
| 8108 | * must reset the discovery timer for ALL vports |
| 8109 | * waiting to send FDISC when one completes. |
| 8110 | */ |
| 8111 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 8112 | lpfc_set_disctmo(piocb->vport); |
| 8113 | } |
| 8114 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8115 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8116 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 8117 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 8118 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8119 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8120 | |
| 8121 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 8122 | lpfc_retry_pport_discovery(phba); |
| 8123 | goto out; |
| 8124 | } |
| 8125 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8126 | /* Check for retry */ |
| 8127 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 8128 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8129 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8130 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8131 | "0126 FDISC failed. (x%x/x%x)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8132 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8133 | goto fdisc_failed; |
| 8134 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8135 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 8136 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8137 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8138 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8139 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8140 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 8141 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8142 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8143 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 8144 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8145 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 8146 | if (!prsp) |
| 8147 | goto out; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8148 | sp = prsp->virt + sizeof(uint32_t); |
| 8149 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 8150 | memcpy(&vport->fabric_portname, &sp->portName, |
| 8151 | sizeof(struct lpfc_name)); |
| 8152 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 8153 | sizeof(struct lpfc_name)); |
| 8154 | if (fabric_param_changed && |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8155 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 8156 | /* If our NportID changed, we need to ensure all |
| 8157 | * remaining NPORTs get unreg_login'ed so we can |
| 8158 | * issue unreg_vpi. |
| 8159 | */ |
| 8160 | list_for_each_entry_safe(np, next_np, |
| 8161 | &vport->fc_nodes, nlp_listp) { |
| 8162 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 8163 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 8164 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 8165 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8166 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8167 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8168 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8169 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8170 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 8171 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8172 | |
| 8173 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8174 | lpfc_sli4_unreg_all_rpis(vport); |
| 8175 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8176 | lpfc_mbx_unreg_vpi(vport); |
| 8177 | spin_lock_irq(shost->host_lock); |
| 8178 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8179 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8180 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 8181 | else |
| 8182 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8183 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 8184 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 8185 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 8186 | /* |
| 8187 | * Driver needs to re-reg VPI in order for f/w |
| 8188 | * to update the MAC address. |
| 8189 | */ |
| 8190 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 8191 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8192 | } |
| 8193 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 8194 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 8195 | lpfc_issue_init_vpi(vport); |
| 8196 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8197 | lpfc_register_new_vport(phba, vport, ndlp); |
| 8198 | else |
| 8199 | lpfc_do_scr_ns_plogi(phba, vport); |
| 8200 | goto out; |
| 8201 | fdisc_failed: |
James Smart | c84163d | 2015-05-21 13:55:22 -0400 | [diff] [blame] | 8202 | if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS) |
| 8203 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8204 | /* Cancel discovery timer */ |
| 8205 | lpfc_can_disctmo(vport); |
| 8206 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8207 | out: |
| 8208 | lpfc_els_free_iocb(phba, cmdiocb); |
| 8209 | } |
| 8210 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8211 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8212 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8213 | * @vport: pointer to a virtual N_Port data structure. |
| 8214 | * @ndlp: pointer to a node-list data structure. |
| 8215 | * @retry: number of retries to the command IOCB. |
| 8216 | * |
| 8217 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 8218 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 8219 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 8220 | * IOCB will be sent off HBA at any given time. |
| 8221 | * |
| 8222 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 8223 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 8224 | * will be stored into the context1 field of the IOCB for the completion |
| 8225 | * callback function to the FDISC ELS command. |
| 8226 | * |
| 8227 | * Return code |
| 8228 | * 0 - Successfully issued fdisc iocb command |
| 8229 | * 1 - Failed to issue fdisc iocb command |
| 8230 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8231 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8232 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 8233 | uint8_t retry) |
| 8234 | { |
| 8235 | struct lpfc_hba *phba = vport->phba; |
| 8236 | IOCB_t *icmd; |
| 8237 | struct lpfc_iocbq *elsiocb; |
| 8238 | struct serv_parm *sp; |
| 8239 | uint8_t *pcmd; |
| 8240 | uint16_t cmdsize; |
| 8241 | int did = ndlp->nlp_DID; |
| 8242 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8243 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8244 | vport->port_state = LPFC_FDISC; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8245 | vport->fc_myDID = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8246 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 8247 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 8248 | ELS_CMD_FDISC); |
| 8249 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8250 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8251 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8252 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8253 | return 1; |
| 8254 | } |
| 8255 | |
| 8256 | icmd = &elsiocb->iocb; |
| 8257 | icmd->un.elsreq64.myID = 0; |
| 8258 | icmd->un.elsreq64.fl = 1; |
| 8259 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 8260 | /* |
| 8261 | * SLI3 ports require a different context type value than SLI4. |
| 8262 | * Catch SLI3 ports here and override the prep. |
| 8263 | */ |
| 8264 | if (phba->sli_rev == LPFC_SLI_REV3) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8265 | icmd->ulpCt_h = 1; |
| 8266 | icmd->ulpCt_l = 0; |
| 8267 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8268 | |
| 8269 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 8270 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 8271 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 8272 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 8273 | sp = (struct serv_parm *) pcmd; |
| 8274 | /* Setup CSPs accordingly for Fabric */ |
| 8275 | sp->cmn.e_d_tov = 0; |
| 8276 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 8277 | sp->cmn.virtual_fabric_support = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8278 | sp->cls1.classValid = 0; |
| 8279 | sp->cls2.seqDelivery = 1; |
| 8280 | sp->cls3.seqDelivery = 1; |
| 8281 | |
| 8282 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 8283 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 8284 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 8285 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 8286 | memcpy(pcmd, &vport->fc_portname, 8); |
| 8287 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 8288 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 8289 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 8290 | |
| 8291 | lpfc_set_disctmo(vport); |
| 8292 | |
| 8293 | phba->fc_stat.elsXmitFDISC++; |
| 8294 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 8295 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8296 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8297 | "Issue FDISC: did:x%x", |
| 8298 | did, 0, 0); |
| 8299 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8300 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 8301 | if (rc == IOCB_ERROR) { |
| 8302 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8303 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8304 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 8305 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8306 | return 1; |
| 8307 | } |
| 8308 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8309 | return 0; |
| 8310 | } |
| 8311 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8312 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8313 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8314 | * @phba: pointer to lpfc hba data structure. |
| 8315 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8316 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8317 | * |
| 8318 | * This routine is the completion callback function to the issuing of a LOGO |
| 8319 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 8320 | * reference count held on ndlp for this completion function, indicating that |
| 8321 | * the reference to the ndlp is no long needed. Note that the |
| 8322 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 8323 | * callback function and an additional explicit ndlp reference decrementation |
| 8324 | * will trigger the actual release of the ndlp. |
| 8325 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8326 | static void |
| 8327 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8328 | struct lpfc_iocbq *rspiocb) |
| 8329 | { |
| 8330 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8331 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8332 | struct lpfc_nodelist *ndlp; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8333 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8334 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8335 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8336 | irsp = &rspiocb->iocb; |
| 8337 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8338 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 8339 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8340 | |
| 8341 | lpfc_els_free_iocb(phba, cmdiocb); |
| 8342 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8343 | |
| 8344 | /* Trigger the release of the ndlp after logo */ |
| 8345 | lpfc_nlp_put(ndlp); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8346 | |
| 8347 | /* NPIV LOGO completes to NPort <nlp_DID> */ |
| 8348 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8349 | "2928 NPIV LOGO completes to NPort x%x " |
| 8350 | "Data: x%x x%x x%x x%x\n", |
| 8351 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 8352 | irsp->ulpTimeout, vport->num_disc_nodes); |
| 8353 | |
| 8354 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 8355 | spin_lock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 8356 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8357 | vport->fc_flag &= ~FC_FABRIC; |
| 8358 | spin_unlock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 8359 | lpfc_can_disctmo(vport); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 8360 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8361 | } |
| 8362 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8363 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8364 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8365 | * @vport: pointer to a virtual N_Port data structure. |
| 8366 | * @ndlp: pointer to a node-list data structure. |
| 8367 | * |
| 8368 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 8369 | * |
| 8370 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 8371 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 8372 | * will be stored into the context1 field of the IOCB for the completion |
| 8373 | * callback function to the LOGO ELS command. |
| 8374 | * |
| 8375 | * Return codes |
| 8376 | * 0 - Successfully issued logo off the @vport |
| 8377 | * 1 - Failed to issue logo off the @vport |
| 8378 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8379 | int |
| 8380 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 8381 | { |
| 8382 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8383 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8384 | struct lpfc_iocbq *elsiocb; |
| 8385 | uint8_t *pcmd; |
| 8386 | uint16_t cmdsize; |
| 8387 | |
| 8388 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 8389 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 8390 | ELS_CMD_LOGO); |
| 8391 | if (!elsiocb) |
| 8392 | return 1; |
| 8393 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8394 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 8395 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 8396 | pcmd += sizeof(uint32_t); |
| 8397 | |
| 8398 | /* Fill in LOGO payload */ |
| 8399 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 8400 | pcmd += sizeof(uint32_t); |
| 8401 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 8402 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8403 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 8404 | "Issue LOGO npiv did:x%x flg:x%x", |
| 8405 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 8406 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8407 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 8408 | spin_lock_irq(shost->host_lock); |
| 8409 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 8410 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8411 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 8412 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8413 | spin_lock_irq(shost->host_lock); |
| 8414 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 8415 | spin_unlock_irq(shost->host_lock); |
| 8416 | lpfc_els_free_iocb(phba, elsiocb); |
| 8417 | return 1; |
| 8418 | } |
| 8419 | return 0; |
| 8420 | } |
| 8421 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8422 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8423 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8424 | * @ptr: holder for the timer function associated data. |
| 8425 | * |
| 8426 | * This routine is invoked by the fabric iocb block timer after |
| 8427 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 8428 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 8429 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 8430 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 8431 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 8432 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8433 | void |
| 8434 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 8435 | { |
| 8436 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 8437 | unsigned long iflags; |
| 8438 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8439 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8440 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 8441 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 8442 | if (!tmo_posted) |
| 8443 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 8444 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 8445 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8446 | if (!tmo_posted) |
| 8447 | lpfc_worker_wake_up(phba); |
| 8448 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8449 | } |
| 8450 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8451 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8452 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8453 | * @phba: pointer to lpfc hba data structure. |
| 8454 | * |
| 8455 | * This routine issues one fabric iocb from the driver internal list to |
| 8456 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 8457 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 8458 | * remove one pending fabric iocb from the driver internal list and invokes |
| 8459 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 8460 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8461 | static void |
| 8462 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 8463 | { |
| 8464 | struct lpfc_iocbq *iocb; |
| 8465 | unsigned long iflags; |
| 8466 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8467 | IOCB_t *cmd; |
| 8468 | |
| 8469 | repeat: |
| 8470 | iocb = NULL; |
| 8471 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8472 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8473 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 8474 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 8475 | list); |
| 8476 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8477 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8478 | atomic_inc(&phba->fabric_iocb_count); |
| 8479 | } |
| 8480 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8481 | if (iocb) { |
| 8482 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 8483 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 8484 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 8485 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8486 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 8487 | "Fabric sched1: ste:x%x", |
| 8488 | iocb->vport->port_state, 0, 0); |
| 8489 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8490 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8491 | |
| 8492 | if (ret == IOCB_ERROR) { |
| 8493 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 8494 | iocb->fabric_iocb_cmpl = NULL; |
| 8495 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 8496 | cmd = &iocb->iocb; |
| 8497 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 8498 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 8499 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 8500 | |
| 8501 | atomic_dec(&phba->fabric_iocb_count); |
| 8502 | goto repeat; |
| 8503 | } |
| 8504 | } |
| 8505 | |
| 8506 | return; |
| 8507 | } |
| 8508 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8509 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8510 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8511 | * @phba: pointer to lpfc hba data structure. |
| 8512 | * |
| 8513 | * This routine unblocks the issuing fabric iocb command. The function |
| 8514 | * will clear the fabric iocb block bit and then invoke the routine |
| 8515 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 8516 | * from the driver internal fabric iocb list. |
| 8517 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8518 | void |
| 8519 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 8520 | { |
| 8521 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 8522 | |
| 8523 | lpfc_resume_fabric_iocbs(phba); |
| 8524 | return; |
| 8525 | } |
| 8526 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8527 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8528 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8529 | * @phba: pointer to lpfc hba data structure. |
| 8530 | * |
| 8531 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 8532 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 8533 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 8534 | * fabric iocb will be issued out of the HBA. |
| 8535 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8536 | static void |
| 8537 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 8538 | { |
| 8539 | int blocked; |
| 8540 | |
| 8541 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8542 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8543 | if (!blocked) |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8544 | mod_timer(&phba->fabric_block_timer, |
| 8545 | jiffies + msecs_to_jiffies(100)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8546 | |
| 8547 | return; |
| 8548 | } |
| 8549 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8550 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8551 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8552 | * @phba: pointer to lpfc hba data structure. |
| 8553 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 8554 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 8555 | * |
| 8556 | * This routine is the callback function that is put to the fabric iocb's |
| 8557 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 8558 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 8559 | * function first restores and invokes the original iocb's callback function |
| 8560 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 8561 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 8562 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8563 | static void |
| 8564 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 8565 | struct lpfc_iocbq *rspiocb) |
| 8566 | { |
| 8567 | struct ls_rjt stat; |
| 8568 | |
| 8569 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 8570 | BUG(); |
| 8571 | |
| 8572 | switch (rspiocb->iocb.ulpStatus) { |
| 8573 | case IOSTAT_NPORT_RJT: |
| 8574 | case IOSTAT_FABRIC_RJT: |
| 8575 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 8576 | lpfc_block_fabric_iocbs(phba); |
| 8577 | } |
| 8578 | break; |
| 8579 | |
| 8580 | case IOSTAT_NPORT_BSY: |
| 8581 | case IOSTAT_FABRIC_BSY: |
| 8582 | lpfc_block_fabric_iocbs(phba); |
| 8583 | break; |
| 8584 | |
| 8585 | case IOSTAT_LS_RJT: |
| 8586 | stat.un.lsRjtError = |
| 8587 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 8588 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 8589 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 8590 | lpfc_block_fabric_iocbs(phba); |
| 8591 | break; |
| 8592 | } |
| 8593 | |
| 8594 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 8595 | BUG(); |
| 8596 | |
| 8597 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 8598 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 8599 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 8600 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 8601 | |
| 8602 | atomic_dec(&phba->fabric_iocb_count); |
| 8603 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8604 | /* Post any pending iocbs to HBA */ |
| 8605 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8606 | } |
| 8607 | } |
| 8608 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8609 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8610 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8611 | * @phba: pointer to lpfc hba data structure. |
| 8612 | * @iocb: pointer to lpfc command iocb data structure. |
| 8613 | * |
| 8614 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 8615 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 8616 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 8617 | * any given time. As such, this function will first check to see whether there |
| 8618 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 8619 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 8620 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 8621 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 8622 | * |
| 8623 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 8624 | * order. The problem is caused by the construction of the "ready" boolen does |
| 8625 | * not include the condition that the internal fabric IOCB list is empty. As |
| 8626 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 8627 | * ahead of the fabric IOCBs in the internal list. |
| 8628 | * |
| 8629 | * Return code |
| 8630 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 8631 | * IOCB_ERROR - failed to issue fabric iocb |
| 8632 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8633 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8634 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 8635 | { |
| 8636 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8637 | int ready; |
| 8638 | int ret; |
| 8639 | |
| 8640 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 8641 | BUG(); |
| 8642 | |
| 8643 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8644 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 8645 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 8646 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 8647 | if (ready) |
| 8648 | /* Increment fabric iocb count to hold the position */ |
| 8649 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8650 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8651 | if (ready) { |
| 8652 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 8653 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 8654 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 8655 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8656 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 8657 | "Fabric sched2: ste:x%x", |
| 8658 | iocb->vport->port_state, 0, 0); |
| 8659 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8660 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8661 | |
| 8662 | if (ret == IOCB_ERROR) { |
| 8663 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 8664 | iocb->fabric_iocb_cmpl = NULL; |
| 8665 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 8666 | atomic_dec(&phba->fabric_iocb_count); |
| 8667 | } |
| 8668 | } else { |
| 8669 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8670 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 8671 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8672 | ret = IOCB_SUCCESS; |
| 8673 | } |
| 8674 | return ret; |
| 8675 | } |
| 8676 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8677 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8678 | * 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] | 8679 | * @vport: pointer to a virtual N_Port data structure. |
| 8680 | * |
| 8681 | * This routine aborts all the IOCBs associated with a @vport from the |
| 8682 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 8683 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 8684 | * list, removes each IOCB associated with the @vport off the list, set the |
| 8685 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 8686 | * associated with the IOCB. |
| 8687 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8688 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8689 | { |
| 8690 | LIST_HEAD(completions); |
| 8691 | struct lpfc_hba *phba = vport->phba; |
| 8692 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8693 | |
| 8694 | spin_lock_irq(&phba->hbalock); |
| 8695 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 8696 | list) { |
| 8697 | |
| 8698 | if (piocb->vport != vport) |
| 8699 | continue; |
| 8700 | |
| 8701 | list_move_tail(&piocb->list, &completions); |
| 8702 | } |
| 8703 | spin_unlock_irq(&phba->hbalock); |
| 8704 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8705 | /* Cancel all the IOCBs from the completions list */ |
| 8706 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8707 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 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_nport - Abort a ndlp's iocbs from driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8712 | * @ndlp: pointer to a node-list data structure. |
| 8713 | * |
| 8714 | * This routine aborts all the IOCBs associated with an @ndlp 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 @ndlp off the list, set the |
| 8718 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 8719 | * associated with the IOCB. |
| 8720 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8721 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 8722 | { |
| 8723 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8724 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8725 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 8726 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8727 | |
| 8728 | spin_lock_irq(&phba->hbalock); |
| 8729 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 8730 | list) { |
| 8731 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 8732 | |
| 8733 | list_move_tail(&piocb->list, &completions); |
| 8734 | } |
| 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_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8745 | * @phba: pointer to lpfc hba data structure. |
| 8746 | * |
| 8747 | * This routine aborts all the IOCBs currently on the driver internal |
| 8748 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 8749 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 8750 | * list, removes IOCBs off the list, set the status feild to |
| 8751 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 8752 | * the IOCB. |
| 8753 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8754 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 8755 | { |
| 8756 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8757 | |
| 8758 | spin_lock_irq(&phba->hbalock); |
| 8759 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 8760 | spin_unlock_irq(&phba->hbalock); |
| 8761 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8762 | /* Cancel all the IOCBs from the completions list */ |
| 8763 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8764 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8765 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8766 | |
| 8767 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 8768 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport |
| 8769 | * @vport: pointer to lpfc vport data structure. |
| 8770 | * |
| 8771 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 8772 | * for an ndlp on removal. |
| 8773 | **/ |
| 8774 | void |
| 8775 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) |
| 8776 | { |
| 8777 | struct lpfc_hba *phba = vport->phba; |
| 8778 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 8779 | unsigned long iflag = 0; |
| 8780 | |
| 8781 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8782 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
| 8783 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 8784 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 8785 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) |
| 8786 | sglq_entry->ndlp = NULL; |
| 8787 | } |
| 8788 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 8789 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8790 | return; |
| 8791 | } |
| 8792 | |
| 8793 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8794 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 8795 | * @phba: pointer to lpfc hba data structure. |
| 8796 | * @axri: pointer to the els xri abort wcqe structure. |
| 8797 | * |
| 8798 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 8799 | * ELS aborted xri. |
| 8800 | **/ |
| 8801 | void |
| 8802 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 8803 | struct sli4_wcqe_xri_aborted *axri) |
| 8804 | { |
| 8805 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 8806 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8807 | uint16_t lxri = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 8808 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8809 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 8810 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 8811 | struct lpfc_nodelist *ndlp; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 8812 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8813 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8814 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8815 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8816 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 8817 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 8818 | if (sglq_entry->sli4_xritag == xri) { |
| 8819 | list_del(&sglq_entry->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 8820 | ndlp = sglq_entry->ndlp; |
| 8821 | sglq_entry->ndlp = NULL; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 8822 | spin_lock(&pring->ring_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8823 | list_add_tail(&sglq_entry->list, |
| 8824 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8825 | sglq_entry->state = SGL_FREED; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 8826 | spin_unlock(&pring->ring_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8827 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8828 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 8829 | lpfc_set_rrq_active(phba, ndlp, |
| 8830 | sglq_entry->sli4_lxritag, |
| 8831 | rxid, 1); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 8832 | |
| 8833 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 8834 | if (!(list_empty(&pring->txq))) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 8835 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8836 | return; |
| 8837 | } |
| 8838 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8839 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8840 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 8841 | if (lxri == NO_XRI) { |
| 8842 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8843 | return; |
| 8844 | } |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 8845 | spin_lock(&pring->ring_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8846 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8847 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 8848 | spin_unlock(&pring->ring_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8849 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8850 | return; |
| 8851 | } |
| 8852 | sglq_entry->state = SGL_XRI_ABORTED; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 8853 | spin_unlock(&pring->ring_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8854 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8855 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8856 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 8857 | |
| 8858 | /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. |
| 8859 | * @vport: pointer to virtual port object. |
| 8860 | * @ndlp: nodelist pointer for the impacted node. |
| 8861 | * |
| 8862 | * The driver calls this routine in response to an SLI4 XRI ABORT CQE |
| 8863 | * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, |
| 8864 | * the driver is required to send a LOGO to the remote node before it |
| 8865 | * attempts to recover its login to the remote node. |
| 8866 | */ |
| 8867 | void |
| 8868 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 8869 | struct lpfc_nodelist *ndlp) |
| 8870 | { |
| 8871 | struct Scsi_Host *shost; |
| 8872 | struct lpfc_hba *phba; |
| 8873 | unsigned long flags = 0; |
| 8874 | |
| 8875 | shost = lpfc_shost_from_vport(vport); |
| 8876 | phba = vport->phba; |
| 8877 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 8878 | lpfc_printf_log(phba, KERN_INFO, |
| 8879 | LOG_SLI, "3093 No rport recovery needed. " |
| 8880 | "rport in state 0x%x\n", ndlp->nlp_state); |
| 8881 | return; |
| 8882 | } |
| 8883 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8884 | "3094 Start rport recovery on shost id 0x%x " |
| 8885 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 8886 | "flags 0x%x\n", |
| 8887 | shost->host_no, ndlp->nlp_DID, |
| 8888 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 8889 | ndlp->nlp_flag); |
| 8890 | /* |
| 8891 | * The rport is not responding. Remove the FCP-2 flag to prevent |
| 8892 | * an ADISC in the follow-up recovery code. |
| 8893 | */ |
| 8894 | spin_lock_irqsave(shost->host_lock, flags); |
| 8895 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 8896 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 8897 | lpfc_issue_els_logo(vport, ndlp, 0); |
| 8898 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
| 8899 | } |
| 8900 | |