| 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 | 92c13f2 | 2013-05-31 17:05:45 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2013 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; |
| 460 | struct serv_parm *sp; |
| 461 | struct lpfc_dmabuf *dmabuf; |
| 462 | int rc = 0; |
| 463 | |
| 464 | sp = &phba->fc_fabparam; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 465 | /* 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] | 466 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 467 | !(phba->link_flag & LS_LOOPBACK_MODE) && |
| 468 | !(vport->fc_flag & FC_PT2PT)) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 469 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 470 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 471 | rc = -ENODEV; |
| 472 | goto fail; |
| 473 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 477 | if (!dmabuf) { |
| 478 | rc = -ENOMEM; |
| 479 | goto fail; |
| 480 | } |
| 481 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 482 | if (!dmabuf->virt) { |
| 483 | rc = -ENOMEM; |
| 484 | goto fail_free_dmabuf; |
| 485 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 486 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 487 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 488 | if (!mboxq) { |
| 489 | rc = -ENOMEM; |
| 490 | goto fail_free_coherent; |
| 491 | } |
| 492 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 493 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 494 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 495 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 496 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 497 | mboxq->vport = vport; |
| 498 | mboxq->context1 = dmabuf; |
| 499 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 500 | if (rc == MBX_NOT_FINISHED) { |
| 501 | rc = -ENXIO; |
| 502 | goto fail_free_mbox; |
| 503 | } |
| 504 | return 0; |
| 505 | |
| 506 | fail_free_mbox: |
| 507 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 508 | fail_free_coherent: |
| 509 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 510 | fail_free_dmabuf: |
| 511 | kfree(dmabuf); |
| 512 | fail: |
| 513 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 514 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 515 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 516 | return rc; |
| 517 | } |
| 518 | |
| 519 | /** |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 520 | * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login |
| 521 | * @vport: pointer to a host virtual N_Port data structure. |
| 522 | * |
| 523 | * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for |
| 524 | * the @vport. This mailbox command is necessary for SLI4 port only. |
| 525 | * |
| 526 | * Return code |
| 527 | * 0 - successfully issued REG_VFI for @vport |
| 528 | * A failure code otherwise. |
| 529 | **/ |
| 530 | int |
| 531 | lpfc_issue_unreg_vfi(struct lpfc_vport *vport) |
| 532 | { |
| 533 | struct lpfc_hba *phba = vport->phba; |
| 534 | struct Scsi_Host *shost; |
| 535 | LPFC_MBOXQ_t *mboxq; |
| 536 | int rc; |
| 537 | |
| 538 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 539 | if (!mboxq) { |
| 540 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 541 | "2556 UNREG_VFI mbox allocation failed" |
| 542 | "HBA state x%x\n", phba->pport->port_state); |
| 543 | return -ENOMEM; |
| 544 | } |
| 545 | |
| 546 | lpfc_unreg_vfi(mboxq, vport); |
| 547 | mboxq->vport = vport; |
| 548 | mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl; |
| 549 | |
| 550 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 551 | if (rc == MBX_NOT_FINISHED) { |
| 552 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 553 | "2557 UNREG_VFI issue mbox failed rc x%x " |
| 554 | "HBA state x%x\n", |
| 555 | rc, phba->pport->port_state); |
| 556 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 557 | return -EIO; |
| 558 | } |
| 559 | |
| 560 | shost = lpfc_shost_from_vport(vport); |
| 561 | spin_lock_irq(shost->host_lock); |
| 562 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 563 | spin_unlock_irq(shost->host_lock); |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | /** |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 568 | * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean. |
| 569 | * @vport: pointer to a host virtual N_Port data structure. |
| 570 | * @sp: pointer to service parameter data structure. |
| 571 | * |
| 572 | * This routine is called from FLOGI/FDISC completion handler functions. |
| 573 | * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric |
| 574 | * node nodename is changed in the completion service parameter else return |
| 575 | * 0. This function also set flag in the vport data structure to delay |
| 576 | * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit |
| 577 | * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric |
| 578 | * node nodename is changed in the completion service parameter. |
| 579 | * |
| 580 | * Return code |
| 581 | * 0 - FCID and Fabric Nodename and Fabric portname is not changed. |
| 582 | * 1 - FCID or Fabric Nodename or Fabric portname is changed. |
| 583 | * |
| 584 | **/ |
| 585 | static uint8_t |
| 586 | lpfc_check_clean_addr_bit(struct lpfc_vport *vport, |
| 587 | struct serv_parm *sp) |
| 588 | { |
| 589 | uint8_t fabric_param_changed = 0; |
| 590 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 591 | |
| 592 | if ((vport->fc_prevDID != vport->fc_myDID) || |
| 593 | memcmp(&vport->fabric_portname, &sp->portName, |
| 594 | sizeof(struct lpfc_name)) || |
| 595 | memcmp(&vport->fabric_nodename, &sp->nodeName, |
| 596 | sizeof(struct lpfc_name))) |
| 597 | fabric_param_changed = 1; |
| 598 | |
| 599 | /* |
| 600 | * Word 1 Bit 31 in common service parameter is overloaded. |
| 601 | * Word 1 Bit 31 in FLOGI request is multiple NPort request |
| 602 | * Word 1 Bit 31 in FLOGI response is clean address bit |
| 603 | * |
| 604 | * If fabric parameter is changed and clean address bit is |
| 605 | * cleared delay nport discovery if |
| 606 | * - vport->fc_prevDID != 0 (not initial discovery) OR |
| 607 | * - lpfc_delay_discovery module parameter is set. |
| 608 | */ |
| 609 | if (fabric_param_changed && !sp->cmn.clean_address_bit && |
| 610 | (vport->fc_prevDID || lpfc_delay_discovery)) { |
| 611 | spin_lock_irq(shost->host_lock); |
| 612 | vport->fc_flag |= FC_DISC_DELAYED; |
| 613 | spin_unlock_irq(shost->host_lock); |
| 614 | } |
| 615 | |
| 616 | return fabric_param_changed; |
| 617 | } |
| 618 | |
| 619 | |
| 620 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 621 | * 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] | 622 | * @vport: pointer to a host virtual N_Port data structure. |
| 623 | * @ndlp: pointer to a node-list data structure. |
| 624 | * @sp: pointer to service parameter data structure. |
| 625 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 626 | * |
| 627 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 628 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 629 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 630 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 631 | * @vport against the previously assigned N_Port ID. If it is different from |
| 632 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 633 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 634 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 635 | * is invoked to register login to the fabric. |
| 636 | * |
| 637 | * Return code |
| 638 | * 0 - Success (currently, always return 0) |
| 639 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 640 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 641 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 642 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 643 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 644 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 645 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 646 | struct lpfc_nodelist *np; |
| 647 | struct lpfc_nodelist *next_np; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 648 | uint8_t fabric_param_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 649 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 650 | spin_lock_irq(shost->host_lock); |
| 651 | vport->fc_flag |= FC_FABRIC; |
| 652 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 653 | |
| 654 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 655 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 656 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 657 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 658 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 659 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 660 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 661 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 662 | spin_lock_irq(shost->host_lock); |
| 663 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 664 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 665 | } |
| 666 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 667 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 668 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 669 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 670 | ndlp->nlp_class_sup = 0; |
| 671 | if (sp->cls1.classValid) |
| 672 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 673 | if (sp->cls2.classValid) |
| 674 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 675 | if (sp->cls3.classValid) |
| 676 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 677 | if (sp->cls4.classValid) |
| 678 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 679 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 680 | sp->cmn.bbRcvSizeLsb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 681 | |
| 682 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 683 | memcpy(&vport->fabric_portname, &sp->portName, |
| 684 | sizeof(struct lpfc_name)); |
| 685 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 686 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 687 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 688 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 689 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 690 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 691 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 692 | LOG_ELS | LOG_VPORT, |
| 693 | "1816 FLOGI NPIV supported, " |
| 694 | "response data 0x%x\n", |
| 695 | sp->cmn.response_multiple_NPort); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 696 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 697 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 698 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 699 | } else { |
| 700 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 701 | to call reg_vnpid atleast for the physcial host */ |
| 702 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 703 | LOG_ELS | LOG_VPORT, |
| 704 | "1817 Fabric does not support NPIV " |
| 705 | "- configuring single port mode.\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 706 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 707 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 708 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 712 | /* |
| 713 | * For FC we need to do some special processing because of the SLI |
| 714 | * Port's default settings of the Common Service Parameters. |
| 715 | */ |
| 716 | if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) { |
| 717 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
| 718 | if ((phba->sli_rev == LPFC_SLI_REV4) && fabric_param_changed) |
| 719 | lpfc_unregister_fcf_prep(phba); |
| 720 | |
| 721 | /* This should just update the VFI CSPs*/ |
| 722 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 723 | lpfc_issue_reg_vfi(vport); |
| 724 | } |
| 725 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 726 | if (fabric_param_changed && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 727 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 728 | |
| 729 | /* If our NportID changed, we need to ensure all |
| 730 | * remaining NPORTs get unreg_login'ed. |
| 731 | */ |
| 732 | list_for_each_entry_safe(np, next_np, |
| 733 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 734 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 735 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 736 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 737 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 738 | continue; |
| 739 | spin_lock_irq(shost->host_lock); |
| 740 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 741 | spin_unlock_irq(shost->host_lock); |
| 742 | lpfc_unreg_rpi(vport, np); |
| 743 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 744 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 745 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 746 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 747 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 748 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 749 | spin_lock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 750 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 751 | spin_unlock_irq(shost->host_lock); |
| 752 | } |
James Smart | 27aa1b7 | 2012-05-09 21:18:49 -0400 | [diff] [blame] | 753 | |
| 754 | /* |
| 755 | * For SLI3 and SLI4, the VPI needs to be reregistered in |
| 756 | * response to this fabric parameter change event. |
| 757 | */ |
| 758 | spin_lock_irq(shost->host_lock); |
| 759 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 760 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 761 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 762 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 763 | /* |
| 764 | * Driver needs to re-reg VPI in order for f/w |
| 765 | * to update the MAC address. |
| 766 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 767 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 768 | lpfc_register_new_vport(phba, vport, ndlp); |
| 769 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 770 | } |
| 771 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 772 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 773 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 774 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 775 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 776 | lpfc_register_new_vport(phba, vport, ndlp); |
| 777 | else |
| 778 | lpfc_issue_fabric_reglogin(vport); |
| 779 | } else { |
| 780 | ndlp->nlp_type |= NLP_FABRIC; |
| 781 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 782 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 783 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 784 | lpfc_start_fdiscs(phba); |
| 785 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 786 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 787 | lpfc_issue_init_vpi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 788 | else { |
| 789 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 790 | "3135 Need register VFI: (x%x/%x)\n", |
| 791 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 792 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 793 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 794 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 795 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 796 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 797 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 798 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 799 | * 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] | 800 | * @vport: pointer to a host virtual N_Port data structure. |
| 801 | * @ndlp: pointer to a node-list data structure. |
| 802 | * @sp: pointer to service parameter data structure. |
| 803 | * |
| 804 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 805 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 806 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 807 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 808 | * the received N_Port Name lexicographically, this node shall assign local |
| 809 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 810 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 811 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 812 | * N_Port IDs. |
| 813 | * |
| 814 | * Return code |
| 815 | * 0 - Success |
| 816 | * -ENXIO - Fail |
| 817 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 818 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 819 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 820 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 821 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 822 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 823 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 824 | LPFC_MBOXQ_t *mbox; |
| 825 | int rc; |
| 826 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 827 | spin_lock_irq(shost->host_lock); |
| 828 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 829 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 830 | |
| 831 | phba->fc_edtov = FF_DEF_EDTOV; |
| 832 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 833 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 834 | sizeof(vport->fc_portname)); |
James Smart | 2eb6862 | 2012-09-29 11:32:27 -0400 | [diff] [blame] | 835 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 836 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 837 | if (rc >= 0) { |
| 838 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 839 | spin_lock_irq(shost->host_lock); |
| 840 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 841 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 842 | |
| 843 | /* |
| 844 | * N_Port ID cannot be 0, set our to LocalID the other |
| 845 | * side will be RemoteID. |
| 846 | */ |
| 847 | |
| 848 | /* not equal */ |
| 849 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 850 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 851 | |
| 852 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 853 | if (!mbox) |
| 854 | goto fail; |
| 855 | |
| 856 | lpfc_config_link(phba, mbox); |
| 857 | |
| 858 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 859 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 860 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 861 | if (rc == MBX_NOT_FINISHED) { |
| 862 | mempool_free(mbox, phba->mbox_mem_pool); |
| 863 | goto fail; |
| 864 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 865 | |
| 866 | /* |
| 867 | * For SLI4, the VFI/VPI are registered AFTER the |
| 868 | * Nport with the higher WWPN sends the PLOGI with |
| 869 | * an assigned NPortId. |
| 870 | */ |
| 871 | |
| 872 | /* not equal */ |
| 873 | if ((phba->sli_rev == LPFC_SLI_REV4) && rc) |
| 874 | lpfc_issue_reg_vfi(vport); |
| 875 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 876 | /* Decrement ndlp reference count indicating that ndlp can be |
| 877 | * safely released when other references to it are done. |
| 878 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 879 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 880 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 881 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 882 | if (!ndlp) { |
| 883 | /* |
| 884 | * Cannot find existing Fabric ndlp, so allocate a |
| 885 | * new one |
| 886 | */ |
| 887 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 888 | if (!ndlp) |
| 889 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 890 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 891 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 892 | ndlp = lpfc_enable_node(vport, ndlp, |
| 893 | NLP_STE_UNUSED_NODE); |
| 894 | if(!ndlp) |
| 895 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 899 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 900 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 901 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 902 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 903 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 904 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 905 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 906 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 907 | } else |
| 908 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 909 | * count indicating that ndlp can be released when other |
| 910 | * references to it are done. |
| 911 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 912 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 913 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 914 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 915 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 916 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 917 | spin_lock_irq(shost->host_lock); |
| 918 | vport->fc_flag |= FC_PT2PT; |
| 919 | spin_unlock_irq(shost->host_lock); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 920 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
| 921 | if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) { |
| 922 | lpfc_unregister_fcf_prep(phba); |
| 923 | |
| 924 | /* The FC_VFI_REGISTERED flag will get clear in the cmpl |
| 925 | * handler for unreg_vfi, but if we don't force the |
| 926 | * FC_VFI_REGISTERED flag then the reg_vfi mailbox could be |
| 927 | * built with the update bit set instead of just the vp bit to |
| 928 | * change the Nport ID. We need to have the vp set and the |
| 929 | * Upd cleared on topology changes. |
| 930 | */ |
| 931 | spin_lock_irq(shost->host_lock); |
| 932 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 933 | spin_unlock_irq(shost->host_lock); |
| 934 | phba->fc_topology_changed = 0; |
| 935 | lpfc_issue_reg_vfi(vport); |
| 936 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 937 | |
| 938 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 939 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 940 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 941 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 942 | return -ENXIO; |
| 943 | } |
| 944 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 945 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 946 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 947 | * @phba: pointer to lpfc hba data structure. |
| 948 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 949 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 950 | * |
| 951 | * This routine is the top-level completion callback function for issuing |
| 952 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 953 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 954 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 955 | * returning 1), the command IOCB will be released and function returned. |
| 956 | * If the retry attempt has been given up (possibly reach the maximum |
| 957 | * number of retries), one additional decrement of ndlp reference shall be |
| 958 | * invoked before going out after releasing the command IOCB. This will |
| 959 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 960 | * invoke one decrement of ndlp reference count). If no error reported in |
| 961 | * the IOCB status, the command Port ID field is used to determine whether |
| 962 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 963 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 964 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 965 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 966 | * specific topology completion conditions. |
| 967 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 968 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 969 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 970 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 971 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 972 | struct lpfc_vport *vport = cmdiocb->vport; |
| 973 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 974 | IOCB_t *irsp = &rspiocb->iocb; |
| 975 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 976 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 977 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 978 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 979 | int rc; |
| 980 | |
| 981 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 982 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 983 | /* One additional decrement on node reference count to |
| 984 | * trigger the release of the node |
| 985 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 986 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 987 | goto out; |
| 988 | } |
| 989 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 990 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 991 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 992 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 993 | vport->port_state); |
| 994 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 995 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 996 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 997 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 998 | * due to new FCF discovery |
| 999 | */ |
| 1000 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1001 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 1002 | if (phba->link_state < LPFC_LINK_UP) |
| 1003 | goto stop_rr_fcf_flogi; |
| 1004 | if ((phba->fcoe_cvl_eventtag_attn == |
| 1005 | phba->fcoe_cvl_eventtag) && |
| 1006 | (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1007 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1008 | IOERR_SLI_ABORTED)) |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1009 | goto stop_rr_fcf_flogi; |
| 1010 | else |
| 1011 | phba->fcoe_cvl_eventtag_attn = |
| 1012 | phba->fcoe_cvl_eventtag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1013 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1014 | "2611 FLOGI failed on FCF (x%x), " |
| 1015 | "status:x%x/x%x, tmo:x%x, perform " |
| 1016 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1017 | phba->fcf.current_rec.fcf_indx, |
| 1018 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1019 | irsp->ulpTimeout); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1020 | lpfc_sli4_set_fcf_flogi_fail(phba, |
| 1021 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1022 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1023 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 1024 | if (rc) |
| 1025 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1026 | } |
| 1027 | |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1028 | stop_rr_fcf_flogi: |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1029 | /* FLOGI failure */ |
| 1030 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1031 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 1032 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1033 | irsp->ulpTimeout); |
| 1034 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1035 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1036 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1037 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1038 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1039 | /* FLOGI failure */ |
| 1040 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1041 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 1042 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1043 | irsp->ulpTimeout); |
| 1044 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1045 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1046 | spin_lock_irq(shost->host_lock); |
| 1047 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 1048 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1049 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1050 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1051 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 1052 | * alpa map would take too long otherwise. |
| 1053 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1054 | if (phba->alpa_map[0] == 0) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1055 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1056 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1057 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1058 | (vport->fc_prevDID != vport->fc_myDID) || |
| 1059 | phba->fc_topology_changed)) { |
| 1060 | if (vport->fc_flag & FC_VFI_REGISTERED) { |
| 1061 | if (phba->fc_topology_changed) { |
| 1062 | lpfc_unregister_fcf_prep(phba); |
| 1063 | spin_lock_irq(shost->host_lock); |
| 1064 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 1065 | spin_unlock_irq(shost->host_lock); |
| 1066 | phba->fc_topology_changed = 0; |
| 1067 | } else { |
| 1068 | lpfc_sli4_unreg_all_rpis(vport); |
| 1069 | } |
| 1070 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1071 | lpfc_issue_reg_vfi(vport); |
| 1072 | lpfc_nlp_put(ndlp); |
| 1073 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1074 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1075 | goto flogifail; |
| 1076 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1077 | spin_lock_irq(shost->host_lock); |
| 1078 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 1079 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1080 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1081 | |
| 1082 | /* |
| 1083 | * The FLogI succeeded. Sync the data for the CPU before |
| 1084 | * accessing it. |
| 1085 | */ |
| 1086 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 1087 | |
| 1088 | sp = prsp->virt + sizeof(uint32_t); |
| 1089 | |
| 1090 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1091 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 1092 | "0101 FLOGI completes successfully, I/O tag:x%x, " |
| 1093 | "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] | 1094 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1095 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution, |
| 1096 | vport->port_state, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1097 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1098 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1099 | /* |
| 1100 | * If Common Service Parameters indicate Nport |
| 1101 | * we are point to point, if Fport we are Fabric. |
| 1102 | */ |
| 1103 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1104 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1105 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1106 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1107 | else { |
| 1108 | lpfc_printf_vlog(vport, KERN_ERR, |
| 1109 | LOG_FIP | LOG_ELS, |
| 1110 | "2831 FLOGI response with cleared Fabric " |
| 1111 | "bit fcf_index 0x%x " |
| 1112 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 1113 | "Fabric Name " |
| 1114 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 1115 | phba->fcf.current_rec.fcf_indx, |
| 1116 | phba->fcf.current_rec.switch_name[0], |
| 1117 | phba->fcf.current_rec.switch_name[1], |
| 1118 | phba->fcf.current_rec.switch_name[2], |
| 1119 | phba->fcf.current_rec.switch_name[3], |
| 1120 | phba->fcf.current_rec.switch_name[4], |
| 1121 | phba->fcf.current_rec.switch_name[5], |
| 1122 | phba->fcf.current_rec.switch_name[6], |
| 1123 | phba->fcf.current_rec.switch_name[7], |
| 1124 | phba->fcf.current_rec.fabric_name[0], |
| 1125 | phba->fcf.current_rec.fabric_name[1], |
| 1126 | phba->fcf.current_rec.fabric_name[2], |
| 1127 | phba->fcf.current_rec.fabric_name[3], |
| 1128 | phba->fcf.current_rec.fabric_name[4], |
| 1129 | phba->fcf.current_rec.fabric_name[5], |
| 1130 | phba->fcf.current_rec.fabric_name[6], |
| 1131 | phba->fcf.current_rec.fabric_name[7]); |
| 1132 | lpfc_nlp_put(ndlp); |
| 1133 | spin_lock_irq(&phba->hbalock); |
| 1134 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1135 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1136 | spin_unlock_irq(&phba->hbalock); |
| 1137 | goto out; |
| 1138 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1139 | if (!rc) { |
| 1140 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1141 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 1142 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 1143 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1144 | "2769 FLOGI to FCF (x%x) " |
| 1145 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1146 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1147 | spin_lock_irq(&phba->hbalock); |
| 1148 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1149 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1150 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1151 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1152 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1156 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1157 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1158 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1159 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1160 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1161 | |
| 1162 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1163 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1164 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1165 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1166 | IOERR_SLI_ABORTED) && |
| 1167 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1168 | IOERR_SLI_DOWN))) && |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1169 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 1170 | /* If FLOGI failed enable link interrupt. */ |
| 1171 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1172 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1173 | out: |
| 1174 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1175 | } |
| 1176 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1177 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1178 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1179 | * @vport: pointer to a host virtual N_Port data structure. |
| 1180 | * @ndlp: pointer to a node-list data structure. |
| 1181 | * @retry: number of retries to the command IOCB. |
| 1182 | * |
| 1183 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 1184 | * for a @vport. The initiator service parameters are put into the payload |
| 1185 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 1186 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 1187 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 1188 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 1189 | * |
| 1190 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1191 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1192 | * will be stored into the context1 field of the IOCB for the completion |
| 1193 | * callback function to the FLOGI ELS command. |
| 1194 | * |
| 1195 | * Return code |
| 1196 | * 0 - successfully issued flogi iocb for @vport |
| 1197 | * 1 - failed to issue flogi iocb for @vport |
| 1198 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1199 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1200 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1201 | uint8_t retry) |
| 1202 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1203 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1204 | struct serv_parm *sp; |
| 1205 | IOCB_t *icmd; |
| 1206 | struct lpfc_iocbq *elsiocb; |
| 1207 | struct lpfc_sli_ring *pring; |
| 1208 | uint8_t *pcmd; |
| 1209 | uint16_t cmdsize; |
| 1210 | uint32_t tmo; |
| 1211 | int rc; |
| 1212 | |
| 1213 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1214 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1215 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1216 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1217 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1218 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1219 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1220 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1221 | |
| 1222 | icmd = &elsiocb->iocb; |
| 1223 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1224 | |
| 1225 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1226 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1227 | pcmd += sizeof(uint32_t); |
| 1228 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1229 | sp = (struct serv_parm *) pcmd; |
| 1230 | |
| 1231 | /* Setup CSPs accordingly for Fabric */ |
| 1232 | sp->cmn.e_d_tov = 0; |
| 1233 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 1234 | sp->cmn.virtual_fabric_support = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1235 | sp->cls1.classValid = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1236 | if (sp->cmn.fcphLow < FC_PH3) |
| 1237 | sp->cmn.fcphLow = FC_PH3; |
| 1238 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1239 | sp->cmn.fcphHigh = FC_PH3; |
| 1240 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 1241 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1242 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1243 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 1244 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1245 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1246 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1247 | /* Set the fcfi to the fcfi we registered with */ |
| 1248 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1249 | } |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1250 | /* Can't do SLI4 class2 without support sequence coalescing */ |
| 1251 | sp->cls2.classValid = 0; |
| 1252 | sp->cls2.seqDelivery = 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1253 | } else { |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1254 | /* Historical, setting sequential-delivery bit for SLI3 */ |
| 1255 | sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; |
| 1256 | sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1257 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 1258 | sp->cmn.request_multiple_Nport = 1; |
| 1259 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1260 | icmd->ulpCt_h = 1; |
| 1261 | icmd->ulpCt_l = 0; |
| 1262 | } else |
| 1263 | sp->cmn.request_multiple_Nport = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1264 | } |
| 1265 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1266 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1267 | icmd->un.elsreq64.myID = 0; |
| 1268 | icmd->un.elsreq64.fl = 1; |
| 1269 | } |
| 1270 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1271 | tmo = phba->fc_ratov; |
| 1272 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1273 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1274 | phba->fc_ratov = tmo; |
| 1275 | |
| 1276 | phba->fc_stat.elsXmitFLOGI++; |
| 1277 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1278 | |
| 1279 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1280 | "Issue FLOGI: opt:x%x", |
| 1281 | phba->sli3_options, 0, 0); |
| 1282 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1283 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1284 | if (rc == IOCB_ERROR) { |
| 1285 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1286 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1287 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1288 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1289 | } |
| 1290 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1291 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1292 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1293 | * @phba: pointer to lpfc hba data structure. |
| 1294 | * |
| 1295 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1296 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1297 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1298 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1299 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1300 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1301 | * |
| 1302 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1303 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1304 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1305 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1306 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1307 | { |
| 1308 | struct lpfc_sli_ring *pring; |
| 1309 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1310 | struct lpfc_nodelist *ndlp; |
| 1311 | IOCB_t *icmd; |
| 1312 | |
| 1313 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1314 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1315 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1316 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1317 | |
| 1318 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1319 | |
| 1320 | /* |
| 1321 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1322 | * searching for. |
| 1323 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1324 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1325 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1326 | icmd = &iocb->iocb; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1327 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1328 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1329 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1330 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1331 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1332 | } |
| 1333 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1334 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | |
| 1336 | return 0; |
| 1337 | } |
| 1338 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1339 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1340 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1341 | * @vport: pointer to a host virtual N_Port data structure. |
| 1342 | * |
| 1343 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1344 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1345 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1346 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1347 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1348 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1349 | * @vport. |
| 1350 | * |
| 1351 | * Return code |
| 1352 | * 0 - failed to issue initial flogi for @vport |
| 1353 | * 1 - successfully issued initial flogi for @vport |
| 1354 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1355 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1356 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1357 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1358 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1359 | struct lpfc_nodelist *ndlp; |
| 1360 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1361 | vport->port_state = LPFC_FLOGI; |
| 1362 | lpfc_set_disctmo(vport); |
| 1363 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1364 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1365 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1366 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1367 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1368 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1369 | if (!ndlp) |
| 1370 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1371 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1372 | /* Set the node type */ |
| 1373 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1374 | /* Put ndlp onto node list */ |
| 1375 | lpfc_enqueue_node(vport, ndlp); |
| 1376 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1377 | /* re-setup ndlp without removing from node list */ |
| 1378 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1379 | if (!ndlp) |
| 1380 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1381 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1382 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1383 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1384 | /* This decrement of reference count to node shall kick off |
| 1385 | * the release of the node. |
| 1386 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1387 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1388 | return 0; |
| 1389 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1390 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1391 | } |
| 1392 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1393 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1394 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1395 | * @vport: pointer to a host virtual N_Port data structure. |
| 1396 | * |
| 1397 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1398 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1399 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1400 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1401 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1402 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1403 | * @vport. |
| 1404 | * |
| 1405 | * Return code |
| 1406 | * 0 - failed to issue initial fdisc for @vport |
| 1407 | * 1 - successfully issued initial fdisc for @vport |
| 1408 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1409 | int |
| 1410 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1411 | { |
| 1412 | struct lpfc_hba *phba = vport->phba; |
| 1413 | struct lpfc_nodelist *ndlp; |
| 1414 | |
| 1415 | /* First look for the Fabric ndlp */ |
| 1416 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1417 | if (!ndlp) { |
| 1418 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1419 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1420 | if (!ndlp) |
| 1421 | return 0; |
| 1422 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1423 | /* Put ndlp onto node list */ |
| 1424 | lpfc_enqueue_node(vport, ndlp); |
| 1425 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1426 | /* re-setup ndlp without removing from node list */ |
| 1427 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1428 | if (!ndlp) |
| 1429 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1430 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1431 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1432 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1433 | /* decrement node reference count to trigger the release of |
| 1434 | * the node. |
| 1435 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1436 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1437 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1438 | } |
| 1439 | return 1; |
| 1440 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1441 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1442 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1443 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1444 | * @vport: pointer to a host virtual N_Port data structure. |
| 1445 | * |
| 1446 | * This routine checks whether there are more remaining Port Logins |
| 1447 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1448 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1449 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1450 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1451 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1452 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1453 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1454 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1455 | { |
| 1456 | int sentplogi; |
| 1457 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1458 | if (vport->num_disc_nodes) |
| 1459 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1460 | |
| 1461 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1462 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1463 | "0232 Continue discovery with %d PLOGIs to go " |
| 1464 | "Data: x%x x%x x%x\n", |
| 1465 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1466 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1467 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1468 | if (vport->fc_flag & FC_NLP_MORE) |
| 1469 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1470 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1471 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1472 | return; |
| 1473 | } |
| 1474 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1475 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1476 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1477 | * @phba: pointer to lpfc hba data structure. |
| 1478 | * @prsp: pointer to response IOCB payload. |
| 1479 | * @ndlp: pointer to a node-list data structure. |
| 1480 | * |
| 1481 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1482 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1483 | * The following cases are considered N_Port confirmed: |
| 1484 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1485 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1486 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1487 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1488 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1489 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1490 | * on that node to release the RPI associated with the node; 2) if there is |
| 1491 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1492 | * into, a new node shall be allocated (or activated). In either case, the |
| 1493 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1494 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1495 | * its pointer returned as the confirmed node. |
| 1496 | * |
| 1497 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1498 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1499 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1500 | * into an inactive state on the vport node list and the vport node list |
| 1501 | * management algorithm does not allow two node with a same DID. |
| 1502 | * |
| 1503 | * Return code |
| 1504 | * pointer to the PLOGI N_Port @ndlp |
| 1505 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1506 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1507 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1508 | struct lpfc_nodelist *ndlp) |
| 1509 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1510 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1511 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1512 | struct lpfc_rport_data *rdata; |
| 1513 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1514 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1515 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1516 | uint32_t rc, keepDID = 0; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1517 | int put_node; |
| 1518 | int put_rport; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1519 | struct lpfc_node_rrqs rrq; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1520 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1521 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1522 | * by WWPN. Just return the ndlp that was given to us. |
| 1523 | */ |
| 1524 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1525 | return ndlp; |
| 1526 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1527 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1528 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1529 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1530 | /* 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] | 1531 | * we have for that ndlp. If not, we have some work to do. |
| 1532 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1533 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1534 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1535 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1536 | return ndlp; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1537 | memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1538 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1539 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1540 | "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n", |
| 1541 | ndlp, ndlp->nlp_DID, new_ndlp); |
| 1542 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1543 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1544 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1545 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1546 | if (!rc) |
| 1547 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1548 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1549 | if (!new_ndlp) |
| 1550 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1551 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1552 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1553 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1554 | sizeof(struct lpfc_name)); |
| 1555 | if (!rc) |
| 1556 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1557 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1558 | NLP_STE_UNUSED_NODE); |
| 1559 | if (!new_ndlp) |
| 1560 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1561 | keepDID = new_ndlp->nlp_DID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1562 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1563 | memcpy(&rrq.xri_bitmap, |
| 1564 | &new_ndlp->active_rrqs.xri_bitmap, |
| 1565 | sizeof(new_ndlp->active_rrqs.xri_bitmap)); |
| 1566 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1567 | keepDID = new_ndlp->nlp_DID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1568 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1569 | memcpy(&rrq.xri_bitmap, |
| 1570 | &new_ndlp->active_rrqs.xri_bitmap, |
| 1571 | sizeof(new_ndlp->active_rrqs.xri_bitmap)); |
| 1572 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1573 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1574 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1575 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1576 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1577 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1578 | memcpy(new_ndlp->active_rrqs.xri_bitmap, |
| 1579 | &ndlp->active_rrqs.xri_bitmap, |
| 1580 | sizeof(ndlp->active_rrqs.xri_bitmap)); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1581 | |
| 1582 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1583 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1584 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1585 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1586 | /* Set state will put new_ndlp on to node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1587 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1588 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1589 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1590 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1591 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1592 | * to put ndlp on UNUSED list and try to free it. |
| 1593 | */ |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1594 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1595 | "3179 PLOGI confirm NEW: %x %x\n", |
| 1596 | new_ndlp->nlp_DID, keepDID); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1597 | |
| 1598 | /* Fix up the rport accordingly */ |
| 1599 | rport = ndlp->rport; |
| 1600 | if (rport) { |
| 1601 | rdata = rport->dd_data; |
| 1602 | if (rdata->pnode == ndlp) { |
| 1603 | lpfc_nlp_put(ndlp); |
| 1604 | ndlp->rport = NULL; |
| 1605 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1606 | new_ndlp->rport = rport; |
| 1607 | } |
| 1608 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1609 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1610 | /* We shall actually free the ndlp with both nlp_DID and |
| 1611 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1612 | * nodelist never to be used. |
| 1613 | */ |
| 1614 | if (ndlp->nlp_DID == 0) { |
| 1615 | spin_lock_irq(&phba->ndlp_lock); |
| 1616 | NLP_SET_FREE_REQ(ndlp); |
| 1617 | spin_unlock_irq(&phba->ndlp_lock); |
| 1618 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1619 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1620 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1621 | ndlp->nlp_DID = keepDID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1622 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1623 | memcpy(&ndlp->active_rrqs.xri_bitmap, |
| 1624 | &rrq.xri_bitmap, |
| 1625 | sizeof(ndlp->active_rrqs.xri_bitmap)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1626 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1627 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1628 | else { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1629 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1630 | "3180 PLOGI confirm SWAP: %x %x\n", |
| 1631 | new_ndlp->nlp_DID, keepDID); |
| 1632 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1633 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1634 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1635 | /* Two ndlps cannot have the same did */ |
| 1636 | ndlp->nlp_DID = keepDID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1637 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1638 | memcpy(&ndlp->active_rrqs.xri_bitmap, |
| 1639 | &rrq.xri_bitmap, |
| 1640 | sizeof(ndlp->active_rrqs.xri_bitmap)); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1641 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1642 | /* Since we are swapping the ndlp passed in with the new one |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1643 | * and the did has already been swapped, copy over state. |
| 1644 | * The new WWNs are already in new_ndlp since thats what |
| 1645 | * we looked it up by in the begining of this routine. |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1646 | */ |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1647 | new_ndlp->nlp_state = ndlp->nlp_state; |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1648 | |
| 1649 | /* Since we are switching over to the new_ndlp, the old |
| 1650 | * ndlp should be put in the NPR state, unless we have |
| 1651 | * already started re-discovery on it. |
| 1652 | */ |
| 1653 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 1654 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
| 1655 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 1656 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1657 | /* Fix up the rport accordingly */ |
| 1658 | rport = ndlp->rport; |
| 1659 | if (rport) { |
| 1660 | rdata = rport->dd_data; |
| 1661 | put_node = rdata->pnode != NULL; |
| 1662 | put_rport = ndlp->rport != NULL; |
| 1663 | rdata->pnode = NULL; |
| 1664 | ndlp->rport = NULL; |
| 1665 | if (put_node) |
| 1666 | lpfc_nlp_put(ndlp); |
| 1667 | if (put_rport) |
| 1668 | put_device(&rport->dev); |
| 1669 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1670 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1671 | return new_ndlp; |
| 1672 | } |
| 1673 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1674 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1675 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1676 | * @vport: pointer to a host virtual N_Port data structure. |
| 1677 | * |
| 1678 | * This routine checks whether more Registration State Change |
| 1679 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1680 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1681 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1682 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1683 | * handling the RSCNs. |
| 1684 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1685 | void |
| 1686 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1687 | { |
| 1688 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1689 | |
| 1690 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1691 | /* |
| 1692 | * Check to see if more RSCNs came in while we were |
| 1693 | * processing this one. |
| 1694 | */ |
| 1695 | if (vport->fc_rscn_id_cnt || |
| 1696 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1697 | lpfc_els_handle_rscn(vport); |
| 1698 | else { |
| 1699 | spin_lock_irq(shost->host_lock); |
| 1700 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1701 | spin_unlock_irq(shost->host_lock); |
| 1702 | } |
| 1703 | } |
| 1704 | } |
| 1705 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1706 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1707 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. |
| 1708 | * @phba: pointer to lpfc hba data structure. |
| 1709 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1710 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1711 | * |
| 1712 | * This routine will call the clear rrq function to free the rrq and |
| 1713 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not |
| 1714 | * exist then the clear_rrq is still called because the rrq needs to |
| 1715 | * be freed. |
| 1716 | **/ |
| 1717 | |
| 1718 | static void |
| 1719 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1720 | struct lpfc_iocbq *rspiocb) |
| 1721 | { |
| 1722 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1723 | IOCB_t *irsp; |
| 1724 | struct lpfc_nodelist *ndlp; |
| 1725 | struct lpfc_node_rrq *rrq; |
| 1726 | |
| 1727 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1728 | rrq = cmdiocb->context_un.rrq; |
| 1729 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1730 | |
| 1731 | irsp = &rspiocb->iocb; |
| 1732 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1733 | "RRQ cmpl: status:x%x/x%x did:x%x", |
| 1734 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1735 | irsp->un.elsreq64.remoteID); |
| 1736 | |
| 1737 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
| 1738 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { |
| 1739 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1740 | "2882 RRQ completes to NPort x%x " |
| 1741 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1742 | irsp->un.elsreq64.remoteID, |
| 1743 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1744 | irsp->ulpIoTag); |
| 1745 | goto out; |
| 1746 | } |
| 1747 | |
| 1748 | /* rrq completes to NPort <nlp_DID> */ |
| 1749 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1750 | "2880 RRQ completes to NPort x%x " |
| 1751 | "Data: x%x x%x x%x x%x x%x\n", |
| 1752 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1753 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); |
| 1754 | |
| 1755 | if (irsp->ulpStatus) { |
| 1756 | /* Check for retry */ |
| 1757 | /* RRQ failed Don't print the vport to vport rjts */ |
| 1758 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1759 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1760 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1761 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1762 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1763 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", |
| 1764 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1765 | irsp->un.ulpWord[4]); |
| 1766 | } |
| 1767 | out: |
| 1768 | if (rrq) |
| 1769 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1770 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1771 | return; |
| 1772 | } |
| 1773 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1774 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1775 | * @phba: pointer to lpfc hba data structure. |
| 1776 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1777 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1778 | * |
| 1779 | * This routine is the completion callback function for issuing the Port |
| 1780 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1781 | * 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] | 1782 | * 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] | 1783 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1784 | * checked for error conditons. If there is error status reported, PLOGI |
| 1785 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1786 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1787 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1788 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1789 | * there are additional N_Port nodes with the vport that need to perform |
| 1790 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1791 | * PLOGIs. |
| 1792 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1793 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1794 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1795 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1796 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1797 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1798 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1799 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1800 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1801 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1802 | int disc, rc, did, type; |
| 1803 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1804 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1805 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1806 | |
| 1807 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1808 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1809 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1810 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1811 | irsp->un.elsreq64.remoteID); |
| 1812 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1813 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1814 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1815 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1816 | "0136 PLOGI completes to NPort x%x " |
| 1817 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1818 | irsp->un.elsreq64.remoteID, |
| 1819 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1820 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1821 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1822 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1823 | |
| 1824 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1825 | * is being used during discovery. |
| 1826 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1827 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1828 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1829 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1830 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1831 | rc = 0; |
| 1832 | |
| 1833 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1834 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1835 | "0102 PLOGI completes to NPort x%x " |
| 1836 | "Data: x%x x%x x%x x%x x%x\n", |
| 1837 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1838 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1839 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1840 | if (lpfc_els_chk_latt(vport)) { |
| 1841 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1842 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1843 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1844 | goto out; |
| 1845 | } |
| 1846 | |
| 1847 | /* ndlp could be freed in DSM, save these values now */ |
| 1848 | type = ndlp->nlp_type; |
| 1849 | did = ndlp->nlp_DID; |
| 1850 | |
| 1851 | if (irsp->ulpStatus) { |
| 1852 | /* Check for retry */ |
| 1853 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1854 | /* ELS command is being retried */ |
| 1855 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1856 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1857 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1858 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1859 | } |
| 1860 | goto out; |
| 1861 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1862 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1863 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1864 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1865 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1866 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1867 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1868 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1869 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1870 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1871 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1872 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1873 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1874 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1875 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1876 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1877 | } else { |
| 1878 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1879 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1880 | cmdiocb->context2)->list.next, |
| 1881 | struct lpfc_dmabuf, list); |
| 1882 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1883 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1884 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1885 | } |
| 1886 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1887 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1888 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1889 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1890 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1891 | if (vport->num_disc_nodes == 0) { |
| 1892 | spin_lock_irq(shost->host_lock); |
| 1893 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1894 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1895 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1896 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1897 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | out: |
| 1902 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1903 | return; |
| 1904 | } |
| 1905 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1906 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1907 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1908 | * @vport: pointer to a host virtual N_Port data structure. |
| 1909 | * @did: destination port identifier. |
| 1910 | * @retry: number of retries to the command IOCB. |
| 1911 | * |
| 1912 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1913 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1914 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1915 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1916 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1917 | * |
| 1918 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1919 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1920 | * will be stored into the context1 field of the IOCB for the completion |
| 1921 | * callback function to the PLOGI ELS command. |
| 1922 | * |
| 1923 | * Return code |
| 1924 | * 0 - Successfully issued a plogi for @vport |
| 1925 | * 1 - failed to issue a plogi for @vport |
| 1926 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1927 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1928 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1929 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1930 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | struct serv_parm *sp; |
| 1932 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1933 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1934 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1935 | struct lpfc_sli *psli; |
| 1936 | uint8_t *pcmd; |
| 1937 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1938 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1939 | |
| 1940 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1941 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1942 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1943 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1944 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1945 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1946 | /* 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] | 1947 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1948 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1949 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1950 | if (!elsiocb) |
| 1951 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1952 | |
| 1953 | icmd = &elsiocb->iocb; |
| 1954 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1955 | |
| 1956 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1957 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1958 | pcmd += sizeof(uint32_t); |
| 1959 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | sp = (struct serv_parm *) pcmd; |
| 1961 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1962 | /* |
| 1963 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 1964 | * to device on remote loops work. |
| 1965 | */ |
| 1966 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 1967 | sp->cmn.altBbCredit = 1; |
| 1968 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1969 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1970 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1971 | |
| 1972 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1973 | sp->cmn.fcphHigh = FC_PH3; |
| 1974 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1975 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1976 | "Issue PLOGI: did:x%x", |
| 1977 | did, 0, 0); |
| 1978 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1979 | phba->fc_stat.elsXmitPLOGI++; |
| 1980 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1981 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1982 | |
| 1983 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1984 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1985 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1987 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1988 | } |
| 1989 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1990 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1991 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1992 | * @phba: pointer to lpfc hba data structure. |
| 1993 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1994 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1995 | * |
| 1996 | * This routine is the completion callback function for a Process Login |
| 1997 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1998 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1999 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 2000 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 2001 | * ndlp to mark the PRLI completion. |
| 2002 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2003 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2004 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2005 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2007 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2008 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2009 | IOCB_t *irsp; |
| 2010 | struct lpfc_sli *psli; |
| 2011 | struct lpfc_nodelist *ndlp; |
| 2012 | |
| 2013 | psli = &phba->sli; |
| 2014 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2015 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2016 | |
| 2017 | irsp = &(rspiocb->iocb); |
| 2018 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2019 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2020 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2021 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2022 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2023 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2024 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 2025 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2026 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2027 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2028 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2029 | "0103 PRLI completes to NPort x%x " |
| 2030 | "Data: x%x x%x x%x x%x\n", |
| 2031 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2032 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2033 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2034 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2035 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2036 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | goto out; |
| 2038 | |
| 2039 | if (irsp->ulpStatus) { |
| 2040 | /* Check for retry */ |
| 2041 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2042 | /* ELS command is being retried */ |
| 2043 | goto out; |
| 2044 | } |
| 2045 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2046 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2047 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 2048 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2049 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2050 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2051 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2052 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2053 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2054 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2055 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2056 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2057 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2058 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2059 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2060 | out: |
| 2061 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2062 | return; |
| 2063 | } |
| 2064 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2065 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2066 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2067 | * @vport: pointer to a host virtual N_Port data structure. |
| 2068 | * @ndlp: pointer to a node-list data structure. |
| 2069 | * @retry: number of retries to the command IOCB. |
| 2070 | * |
| 2071 | * This routine issues a Process Login (PRLI) ELS command for the |
| 2072 | * @vport. The PRLI service parameters are set up in the payload of the |
| 2073 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 2074 | * is put to the IOCB completion callback func field before invoking the |
| 2075 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 2076 | * |
| 2077 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2078 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2079 | * will be stored into the context1 field of the IOCB for the completion |
| 2080 | * callback function to the PRLI ELS command. |
| 2081 | * |
| 2082 | * Return code |
| 2083 | * 0 - successfully issued prli iocb command for @vport |
| 2084 | * 1 - failed to issue prli iocb command for @vport |
| 2085 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2086 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2087 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2088 | uint8_t retry) |
| 2089 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2090 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2091 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | PRLI *npr; |
| 2093 | IOCB_t *icmd; |
| 2094 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | uint8_t *pcmd; |
| 2096 | uint16_t cmdsize; |
| 2097 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2098 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2099 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2100 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2101 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2102 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | |
| 2104 | icmd = &elsiocb->iocb; |
| 2105 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2106 | |
| 2107 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2108 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2109 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2110 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2111 | |
| 2112 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 2113 | npr = (PRLI *) pcmd; |
| 2114 | /* |
| 2115 | * If our firmware version is 3.20 or later, |
| 2116 | * set the following bits for FC-TAPE support. |
| 2117 | */ |
| 2118 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 2119 | npr->ConfmComplAllowed = 1; |
| 2120 | npr->Retry = 1; |
| 2121 | npr->TaskRetryIdReq = 1; |
| 2122 | } |
| 2123 | npr->estabImagePair = 1; |
| 2124 | npr->readXferRdyDis = 1; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 2125 | if (vport->cfg_first_burst_size) |
| 2126 | npr->writeXferRdyDis = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2127 | |
| 2128 | /* For FCP support */ |
| 2129 | npr->prliType = PRLI_FCP_TYPE; |
| 2130 | npr->initiatorFunc = 1; |
| 2131 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2132 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2133 | "Issue PRLI: did:x%x", |
| 2134 | ndlp->nlp_DID, 0, 0); |
| 2135 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2136 | phba->fc_stat.elsXmitPRLI++; |
| 2137 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2138 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2140 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2141 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2142 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2143 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2144 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2145 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2147 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2148 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2149 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2150 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2151 | } |
| 2152 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2153 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2154 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2155 | * @vport: pointer to a host virtual N_Port data structure. |
| 2156 | * |
| 2157 | * This routine performs Registration State Change Notification (RSCN) |
| 2158 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 2159 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 2160 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 2161 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 2162 | * invoked to check and handle possible more RSCN came in during the period |
| 2163 | * of processing the current ones. |
| 2164 | **/ |
| 2165 | static void |
| 2166 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 2167 | { |
| 2168 | lpfc_can_disctmo(vport); |
| 2169 | |
| 2170 | /* RSCN discovery */ |
| 2171 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 2172 | if (vport->fc_npr_cnt) |
| 2173 | if (lpfc_els_disc_plogi(vport)) |
| 2174 | return; |
| 2175 | |
| 2176 | lpfc_end_rscn(vport); |
| 2177 | } |
| 2178 | |
| 2179 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2180 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2181 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 2182 | * |
| 2183 | * This function is called when the final ADISC is completed during discovery. |
| 2184 | * This function handles clearing link attention or issuing reg_vpi depending |
| 2185 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 2186 | * discovery. |
| 2187 | * This function is called with no locks held. |
| 2188 | **/ |
| 2189 | static void |
| 2190 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 2191 | { |
| 2192 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2193 | struct lpfc_hba *phba = vport->phba; |
| 2194 | |
| 2195 | /* |
| 2196 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 2197 | * and continue discovery. |
| 2198 | */ |
| 2199 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2200 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 2201 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2202 | lpfc_issue_reg_vpi(phba, vport); |
| 2203 | return; |
| 2204 | } |
| 2205 | /* |
| 2206 | * For SLI2, we need to set port_state to READY |
| 2207 | * and continue discovery. |
| 2208 | */ |
| 2209 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2210 | /* If we get here, there is nothing to ADISC */ |
| 2211 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 2212 | lpfc_issue_clear_la(phba, vport); |
| 2213 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 2214 | vport->num_disc_nodes = 0; |
| 2215 | /* go thru NPR list, issue ELS PLOGIs */ |
| 2216 | if (vport->fc_npr_cnt) |
| 2217 | lpfc_els_disc_plogi(vport); |
| 2218 | if (!vport->num_disc_nodes) { |
| 2219 | spin_lock_irq(shost->host_lock); |
| 2220 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2221 | spin_unlock_irq(shost->host_lock); |
| 2222 | lpfc_can_disctmo(vport); |
| 2223 | lpfc_end_rscn(vport); |
| 2224 | } |
| 2225 | } |
| 2226 | vport->port_state = LPFC_VPORT_READY; |
| 2227 | } else |
| 2228 | lpfc_rscn_disc(vport); |
| 2229 | } |
| 2230 | |
| 2231 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2232 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2233 | * @vport: pointer to a host virtual N_Port data structure. |
| 2234 | * |
| 2235 | * This routine determines whether there are more ndlps on a @vport |
| 2236 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 2237 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 2238 | * remaining nodes which need to have ADISC sent. |
| 2239 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2240 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2241 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2242 | { |
| 2243 | int sentadisc; |
| 2244 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2245 | if (vport->num_disc_nodes) |
| 2246 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2247 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2248 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2249 | "0210 Continue discovery with %d ADISCs to go " |
| 2250 | "Data: x%x x%x x%x\n", |
| 2251 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 2252 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2253 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2254 | if (vport->fc_flag & FC_NLP_MORE) { |
| 2255 | lpfc_set_disctmo(vport); |
| 2256 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 2257 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2258 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2259 | if (!vport->num_disc_nodes) |
| 2260 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2261 | return; |
| 2262 | } |
| 2263 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2264 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2265 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2266 | * @phba: pointer to lpfc hba data structure. |
| 2267 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2268 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2269 | * |
| 2270 | * This routine is the completion function for issuing the Address Discover |
| 2271 | * (ADISC) command. It first checks to see whether link went down during |
| 2272 | * the discovery process. If so, the node will be marked as node port |
| 2273 | * recovery for issuing discover IOCB by the link attention handler and |
| 2274 | * exit. Otherwise, the response status is checked. If error was reported |
| 2275 | * in the response status, the ADISC command shall be retried by invoking |
| 2276 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 2277 | * the response status, the state machine is invoked to set transition |
| 2278 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 2279 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2280 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2281 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2282 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2283 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2284 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2285 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2286 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2287 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2288 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2289 | |
| 2290 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2291 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2292 | |
| 2293 | irsp = &(rspiocb->iocb); |
| 2294 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2295 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2296 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2297 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 2298 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2299 | ndlp->nlp_DID); |
| 2300 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2301 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2302 | * is being used during discovery. |
| 2303 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2304 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2305 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2306 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2307 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2309 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2310 | "0104 ADISC completes to NPort x%x " |
| 2311 | "Data: x%x x%x x%x x%x x%x\n", |
| 2312 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2313 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2314 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2315 | if (lpfc_els_chk_latt(vport)) { |
| 2316 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2317 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2318 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2319 | goto out; |
| 2320 | } |
| 2321 | |
| 2322 | if (irsp->ulpStatus) { |
| 2323 | /* Check for retry */ |
| 2324 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2325 | /* ELS command is being retried */ |
| 2326 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2327 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2328 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2329 | spin_unlock_irq(shost->host_lock); |
| 2330 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2331 | } |
| 2332 | goto out; |
| 2333 | } |
| 2334 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2335 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2336 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2337 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2338 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2339 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2340 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2341 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2342 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2343 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2344 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2345 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2346 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2347 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2348 | /* Check to see if there are more ADISCs to be sent */ |
| 2349 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2350 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2351 | out: |
| 2352 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2353 | return; |
| 2354 | } |
| 2355 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2356 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2357 | * 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] | 2358 | * @vport: pointer to a virtual N_Port data structure. |
| 2359 | * @ndlp: pointer to a node-list data structure. |
| 2360 | * @retry: number of retries to the command IOCB. |
| 2361 | * |
| 2362 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2363 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2364 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2365 | * to issue the ADISC ELS command. |
| 2366 | * |
| 2367 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2368 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2369 | * will be stored into the context1 field of the IOCB for the completion |
| 2370 | * callback function to the ADISC ELS command. |
| 2371 | * |
| 2372 | * Return code |
| 2373 | * 0 - successfully issued adisc |
| 2374 | * 1 - failed to issue adisc |
| 2375 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2376 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2377 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2378 | uint8_t retry) |
| 2379 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2380 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2381 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2382 | ADISC *ap; |
| 2383 | IOCB_t *icmd; |
| 2384 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2385 | uint8_t *pcmd; |
| 2386 | uint16_t cmdsize; |
| 2387 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2388 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2389 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2390 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2391 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2392 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2393 | |
| 2394 | icmd = &elsiocb->iocb; |
| 2395 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2396 | |
| 2397 | /* For ADISC request, remainder of payload is service parameters */ |
| 2398 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2399 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2400 | |
| 2401 | /* Fill in ADISC payload */ |
| 2402 | ap = (ADISC *) pcmd; |
| 2403 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2404 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2405 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2406 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2408 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2409 | "Issue ADISC: did:x%x", |
| 2410 | ndlp->nlp_DID, 0, 0); |
| 2411 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2412 | phba->fc_stat.elsXmitADISC++; |
| 2413 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2414 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2415 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2416 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2417 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2418 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2419 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2420 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2421 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2423 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2424 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2425 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2426 | } |
| 2427 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2428 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2429 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2430 | * @phba: pointer to lpfc hba data structure. |
| 2431 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2432 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2433 | * |
| 2434 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2435 | * command. If no error status was reported from the LOGO response, the |
| 2436 | * state machine of the associated ndlp shall be invoked for transition with |
| 2437 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2438 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2439 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2441 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2442 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2443 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2444 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2445 | struct lpfc_vport *vport = ndlp->vport; |
| 2446 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | IOCB_t *irsp; |
| 2448 | struct lpfc_sli *psli; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2449 | struct lpfcMboxq *mbox; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2450 | unsigned long flags; |
| 2451 | uint32_t skip_recovery = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2452 | |
| 2453 | psli = &phba->sli; |
| 2454 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2455 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2456 | |
| 2457 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2458 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2459 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2460 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2461 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2462 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2463 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2464 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2465 | ndlp->nlp_DID); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2466 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2467 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2468 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2469 | "0105 LOGO completes to NPort x%x " |
| 2470 | "Data: x%x x%x x%x x%x\n", |
| 2471 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2472 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2473 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2474 | if (lpfc_els_chk_latt(vport)) { |
| 2475 | skip_recovery = 1; |
| 2476 | goto out; |
| 2477 | } |
| 2478 | |
| 2479 | /* Check to see if link went down during discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2480 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2481 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2482 | * which should abort all outstanding IOs. |
| 2483 | */ |
| 2484 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2485 | NLP_EVT_DEVICE_RM); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2486 | skip_recovery = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2487 | goto out; |
| 2488 | } |
| 2489 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2490 | if (irsp->ulpStatus) { |
| 2491 | /* Check for retry */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2492 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2493 | /* ELS command is being retried */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2494 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2495 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2496 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2497 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2498 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2499 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2500 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2501 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2502 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2503 | if (lpfc_error_lost_link(irsp)) { |
| 2504 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2505 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2506 | } |
| 2507 | } |
| 2508 | |
| 2509 | /* Call state machine. This will unregister the rpi if needed. */ |
| 2510 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); |
| 2511 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2512 | out: |
| 2513 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2514 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ |
| 2515 | if ((vport->fc_flag & FC_PT2PT) && |
| 2516 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { |
| 2517 | phba->pport->fc_myDID = 0; |
| 2518 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2519 | if (mbox) { |
| 2520 | lpfc_config_link(phba, mbox); |
| 2521 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2522 | mbox->vport = vport; |
| 2523 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 2524 | MBX_NOT_FINISHED) { |
| 2525 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2526 | skip_recovery = 1; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2527 | } |
| 2528 | } |
| 2529 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2530 | |
| 2531 | /* |
| 2532 | * If the node is a target, the handling attempts to recover the port. |
| 2533 | * For any other port type, the rpi is unregistered as an implicit |
| 2534 | * LOGO. |
| 2535 | */ |
| 2536 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) { |
| 2537 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 2538 | spin_lock_irqsave(shost->host_lock, flags); |
| 2539 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 2540 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2541 | |
| 2542 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2543 | "3187 LOGO completes to NPort x%x: Start " |
| 2544 | "Recovery Data: x%x x%x x%x x%x\n", |
| 2545 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2546 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 2547 | vport->num_disc_nodes); |
| 2548 | lpfc_disc_start(vport); |
| 2549 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2550 | return; |
| 2551 | } |
| 2552 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2553 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2554 | * 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] | 2555 | * @vport: pointer to a virtual N_Port data structure. |
| 2556 | * @ndlp: pointer to a node-list data structure. |
| 2557 | * @retry: number of retries to the command IOCB. |
| 2558 | * |
| 2559 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2560 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2561 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2562 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2563 | * |
| 2564 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2565 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2566 | * will be stored into the context1 field of the IOCB for the completion |
| 2567 | * callback function to the LOGO ELS command. |
| 2568 | * |
| 2569 | * Return code |
| 2570 | * 0 - successfully issued logo |
| 2571 | * 1 - failed to issue logo |
| 2572 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2573 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2574 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2575 | uint8_t retry) |
| 2576 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2577 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2578 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2579 | IOCB_t *icmd; |
| 2580 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2581 | uint8_t *pcmd; |
| 2582 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2583 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2584 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2585 | spin_lock_irq(shost->host_lock); |
| 2586 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2587 | spin_unlock_irq(shost->host_lock); |
| 2588 | return 0; |
| 2589 | } |
| 2590 | spin_unlock_irq(shost->host_lock); |
| 2591 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2592 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2593 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2594 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2595 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2596 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2597 | |
| 2598 | icmd = &elsiocb->iocb; |
| 2599 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2600 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2601 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2602 | |
| 2603 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2604 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2605 | pcmd += sizeof(uint32_t); |
| 2606 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2607 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2608 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2609 | "Issue LOGO: did:x%x", |
| 2610 | ndlp->nlp_DID, 0, 0); |
| 2611 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2612 | /* |
| 2613 | * If we are issuing a LOGO, we may try to recover the remote NPort |
| 2614 | * by issuing a PLOGI later. Even though we issue ELS cmds by the |
| 2615 | * VPI, if we have a valid RPI, and that RPI gets unreg'ed while |
| 2616 | * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI |
| 2617 | * for that ELS cmd. To avoid this situation, lets get rid of the |
| 2618 | * RPI right now, before any ELS cmds are sent. |
| 2619 | */ |
| 2620 | spin_lock_irq(shost->host_lock); |
| 2621 | ndlp->nlp_flag |= NLP_ISSUE_LOGO; |
| 2622 | spin_unlock_irq(shost->host_lock); |
| 2623 | if (lpfc_unreg_rpi(vport, ndlp)) { |
| 2624 | lpfc_els_free_iocb(phba, elsiocb); |
| 2625 | return 0; |
| 2626 | } |
| 2627 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2628 | phba->fc_stat.elsXmitLOGO++; |
| 2629 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2630 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2631 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2632 | ndlp->nlp_flag &= ~NLP_ISSUE_LOGO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2633 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2634 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2635 | |
| 2636 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2637 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2638 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2639 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2640 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2641 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2642 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2643 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2644 | } |
| 2645 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2646 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2647 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2648 | * @phba: pointer to lpfc hba data structure. |
| 2649 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2650 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2651 | * |
| 2652 | * This routine is a generic completion callback function for ELS commands. |
| 2653 | * Specifically, it is the callback function which does not need to perform |
| 2654 | * any command specific operations. It is currently used by the ELS command |
| 2655 | * issuing routines for the ELS State Change Request (SCR), |
| 2656 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2657 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2658 | * certain debug loggings, this callback function simply invokes the |
| 2659 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2660 | * discovery process. |
| 2661 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2663 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2664 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2665 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2666 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2667 | IOCB_t *irsp; |
| 2668 | |
| 2669 | irsp = &rspiocb->iocb; |
| 2670 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2671 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2672 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2673 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2674 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2675 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2676 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2677 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2678 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2679 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2680 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2681 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2683 | return; |
| 2684 | } |
| 2685 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2686 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2687 | * 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] | 2688 | * @vport: pointer to a host virtual N_Port data structure. |
| 2689 | * @nportid: N_Port identifier to the remote node. |
| 2690 | * @retry: number of retries to the command IOCB. |
| 2691 | * |
| 2692 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2693 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2694 | * first search the @vport node list to find the matching ndlp. If no such |
| 2695 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2696 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2697 | * routine is invoked to send the SCR IOCB. |
| 2698 | * |
| 2699 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2700 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2701 | * will be stored into the context1 field of the IOCB for the completion |
| 2702 | * callback function to the SCR ELS command. |
| 2703 | * |
| 2704 | * Return code |
| 2705 | * 0 - Successfully issued scr command |
| 2706 | * 1 - Failed to issue scr command |
| 2707 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2708 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2709 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2710 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2711 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2712 | IOCB_t *icmd; |
| 2713 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2714 | struct lpfc_sli *psli; |
| 2715 | uint8_t *pcmd; |
| 2716 | uint16_t cmdsize; |
| 2717 | struct lpfc_nodelist *ndlp; |
| 2718 | |
| 2719 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2720 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2721 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2722 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2723 | if (!ndlp) { |
| 2724 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2725 | if (!ndlp) |
| 2726 | return 1; |
| 2727 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2728 | lpfc_enqueue_node(vport, ndlp); |
| 2729 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2730 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2731 | if (!ndlp) |
| 2732 | return 1; |
| 2733 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2734 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2735 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2736 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2737 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2738 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2739 | /* This will trigger the release of the node just |
| 2740 | * allocated |
| 2741 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2742 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2743 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | icmd = &elsiocb->iocb; |
| 2747 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2748 | |
| 2749 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2750 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2751 | |
| 2752 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2753 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2754 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2755 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2756 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2757 | "Issue SCR: did:x%x", |
| 2758 | ndlp->nlp_DID, 0, 0); |
| 2759 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2760 | phba->fc_stat.elsXmitSCR++; |
| 2761 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2762 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2763 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2764 | /* The additional lpfc_nlp_put will cause the following |
| 2765 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2766 | * the node. |
| 2767 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2768 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2769 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2770 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2771 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2772 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2773 | * trigger the release of node. |
| 2774 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2775 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2776 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2777 | } |
| 2778 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2779 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2780 | * 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] | 2781 | * @vport: pointer to a host virtual N_Port data structure. |
| 2782 | * @nportid: N_Port identifier to the remote node. |
| 2783 | * @retry: number of retries to the command IOCB. |
| 2784 | * |
| 2785 | * This routine issues a Fibre Channel Address Resolution Response |
| 2786 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2787 | * is passed into the function. It first search the @vport node list to find |
| 2788 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2789 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2790 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2791 | * |
| 2792 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2793 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2794 | * will be stored into the context1 field of the IOCB for the completion |
| 2795 | * callback function to the PARPR ELS command. |
| 2796 | * |
| 2797 | * Return code |
| 2798 | * 0 - Successfully issued farpr command |
| 2799 | * 1 - Failed to issue farpr command |
| 2800 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2801 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2802 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2803 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2804 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2805 | IOCB_t *icmd; |
| 2806 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2807 | struct lpfc_sli *psli; |
| 2808 | FARP *fp; |
| 2809 | uint8_t *pcmd; |
| 2810 | uint32_t *lp; |
| 2811 | uint16_t cmdsize; |
| 2812 | struct lpfc_nodelist *ondlp; |
| 2813 | struct lpfc_nodelist *ndlp; |
| 2814 | |
| 2815 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2816 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2818 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2819 | if (!ndlp) { |
| 2820 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2821 | if (!ndlp) |
| 2822 | return 1; |
| 2823 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2824 | lpfc_enqueue_node(vport, ndlp); |
| 2825 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2826 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2827 | if (!ndlp) |
| 2828 | return 1; |
| 2829 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2830 | |
| 2831 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2832 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2833 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2834 | /* This will trigger the release of the node just |
| 2835 | * allocated |
| 2836 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2837 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2838 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | icmd = &elsiocb->iocb; |
| 2842 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2843 | |
| 2844 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2845 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2846 | |
| 2847 | /* Fill in FARPR payload */ |
| 2848 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2849 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2850 | lp = (uint32_t *) pcmd; |
| 2851 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2852 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2853 | fp->Rflags = 0; |
| 2854 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2855 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2856 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2857 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2858 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2859 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2860 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2861 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2862 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2863 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2864 | } |
| 2865 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2866 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2867 | "Issue FARPR: did:x%x", |
| 2868 | ndlp->nlp_DID, 0, 0); |
| 2869 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2870 | phba->fc_stat.elsXmitFARPR++; |
| 2871 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2872 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2873 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2874 | /* The additional lpfc_nlp_put will cause the following |
| 2875 | * lpfc_els_free_iocb routine to trigger the release of |
| 2876 | * the node. |
| 2877 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2878 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2879 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2880 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2881 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2882 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2883 | * trigger the release of the node. |
| 2884 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2885 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2886 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2887 | } |
| 2888 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2889 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2890 | * 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] | 2891 | * @vport: pointer to a host virtual N_Port data structure. |
| 2892 | * @nlp: pointer to a node-list data structure. |
| 2893 | * |
| 2894 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2895 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2896 | * removes the ELS retry event if it presents. In addition, if the |
| 2897 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2898 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2899 | * ADISC. |
| 2900 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2901 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2902 | 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] | 2903 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2904 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2905 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2906 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2907 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2908 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2909 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2910 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2911 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2912 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2913 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2914 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2915 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2916 | /* Decrement nlp reference count held for the delayed retry */ |
| 2917 | evtp = &nlp->els_retry_evt; |
| 2918 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2919 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2920 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2921 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2922 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2923 | spin_unlock_irq(shost->host_lock); |
| 2924 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2925 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2926 | /* Check if there are more ADISCs to be sent */ |
| 2927 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2928 | } else { |
| 2929 | /* Check if there are more PLOGIs to be sent */ |
| 2930 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2931 | if (vport->num_disc_nodes == 0) { |
| 2932 | spin_lock_irq(shost->host_lock); |
| 2933 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2934 | spin_unlock_irq(shost->host_lock); |
| 2935 | lpfc_can_disctmo(vport); |
| 2936 | lpfc_end_rscn(vport); |
| 2937 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2938 | } |
| 2939 | } |
| 2940 | } |
| 2941 | return; |
| 2942 | } |
| 2943 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2944 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2945 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2946 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2947 | * |
| 2948 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2949 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2950 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2951 | * adds the delayed events to the HBA work list and invokes the |
| 2952 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2953 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2954 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2955 | * reference to ndlp will still be available when the worker thread gets |
| 2956 | * to the event associated with the ndlp. |
| 2957 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2958 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2959 | lpfc_els_retry_delay(unsigned long ptr) |
| 2960 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2961 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2962 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2963 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2964 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2965 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2966 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2967 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2968 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2969 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2970 | return; |
| 2971 | } |
| 2972 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2973 | /* We need to hold the node by incrementing the reference |
| 2974 | * count until the queued work is done |
| 2975 | */ |
| 2976 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2977 | if (evtp->evt_arg1) { |
| 2978 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2979 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2980 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2981 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2982 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | return; |
| 2984 | } |
| 2985 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2986 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2987 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2988 | * @ndlp: pointer to a node-list data structure. |
| 2989 | * |
| 2990 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2991 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2992 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2993 | * function according to the delayed ELS command to retry the command. |
| 2994 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2995 | void |
| 2996 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2997 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2998 | struct lpfc_vport *vport = ndlp->vport; |
| 2999 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3000 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3001 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3002 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3003 | did = ndlp->nlp_DID; |
| 3004 | cmd = ndlp->nlp_last_elscmd; |
| 3005 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3006 | |
| 3007 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3008 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3009 | return; |
| 3010 | } |
| 3011 | |
| 3012 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3013 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 3014 | /* |
| 3015 | * If a discovery event readded nlp_delayfunc after timer |
| 3016 | * firing and before processing the timer, cancel the |
| 3017 | * nlp_delayfunc. |
| 3018 | */ |
| 3019 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3020 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3021 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3022 | |
| 3023 | switch (cmd) { |
| 3024 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3025 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3026 | break; |
| 3027 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3028 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3029 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3030 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3031 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3032 | break; |
| 3033 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3034 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3035 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3036 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3037 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3038 | break; |
| 3039 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3040 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3041 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3042 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3043 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3044 | break; |
| 3045 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3046 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3047 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3048 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3049 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3050 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3051 | case ELS_CMD_FDISC: |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3052 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
| 3053 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3054 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3055 | } |
| 3056 | return; |
| 3057 | } |
| 3058 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3059 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3060 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3061 | * @phba: pointer to lpfc hba data structure. |
| 3062 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3063 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3064 | * |
| 3065 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 3066 | * failed. The following ELS IOCBs use this function for retrying the command |
| 3067 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 3068 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 3069 | * returned error status, it makes the decision whether a retry shall be |
| 3070 | * issued for the command, and whether a retry shall be made immediately or |
| 3071 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 3072 | * is called to retry the command. In the later case, the ELS command shall |
| 3073 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 3074 | * ndlp for the delayed command issusing. |
| 3075 | * |
| 3076 | * Return code |
| 3077 | * 0 - No retry of els command is made |
| 3078 | * 1 - Immediate or delayed retry of els command is made |
| 3079 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3080 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3081 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3082 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3083 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3084 | struct lpfc_vport *vport = cmdiocb->vport; |
| 3085 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3086 | IOCB_t *irsp = &rspiocb->iocb; |
| 3087 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3088 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3089 | uint32_t *elscmd; |
| 3090 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3091 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3092 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3093 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3094 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3095 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3096 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | /* Note: context2 may be 0 for internal driver abort |
| 3098 | * of delays ELS command. |
| 3099 | */ |
| 3100 | |
| 3101 | if (pcmd && pcmd->virt) { |
| 3102 | elscmd = (uint32_t *) (pcmd->virt); |
| 3103 | cmd = *elscmd++; |
| 3104 | } |
| 3105 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3106 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3107 | did = ndlp->nlp_DID; |
| 3108 | else { |
| 3109 | /* We should only hit this case for retrying PLOGI */ |
| 3110 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3111 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3112 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 3113 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3114 | return 1; |
| 3115 | } |
| 3116 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3117 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3118 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 3119 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 3120 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3121 | switch (irsp->ulpStatus) { |
| 3122 | case IOSTAT_FCP_RSP_ERROR: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3123 | break; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3124 | case IOSTAT_REMOTE_STOP: |
| 3125 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3126 | /* This IO was aborted by the target, we don't |
| 3127 | * know the rxid and because we did not send the |
| 3128 | * ABTS we cannot generate and RRQ. |
| 3129 | */ |
| 3130 | lpfc_set_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 3131 | cmdiocb->sli4_lxritag, 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3132 | } |
| 3133 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3134 | case IOSTAT_LOCAL_REJECT: |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3135 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3136 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3137 | if (cmd == ELS_CMD_FLOGI) { |
| 3138 | if (PCI_DEVICE_ID_HORNET == |
| 3139 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3140 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3141 | phba->pport->fc_myDID = 0; |
| 3142 | phba->alpa_map[0] = 0; |
| 3143 | phba->alpa_map[1] = 0; |
| 3144 | } |
| 3145 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3146 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3147 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3148 | retry = 1; |
| 3149 | break; |
| 3150 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3151 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3152 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3153 | "0124 Retry illegal cmd x%x " |
| 3154 | "retry:x%x delay:x%x\n", |
| 3155 | cmd, cmdiocb->retry, delay); |
| 3156 | retry = 1; |
| 3157 | /* All command's retry policy */ |
| 3158 | maxretry = 8; |
| 3159 | if (cmdiocb->retry > 2) |
| 3160 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3161 | break; |
| 3162 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3163 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3164 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3165 | retry = 1; |
| 3166 | if (cmdiocb->retry > 100) |
| 3167 | delay = 100; |
| 3168 | maxretry = 250; |
| 3169 | break; |
| 3170 | |
| 3171 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3172 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3173 | retry = 1; |
| 3174 | break; |
| 3175 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3176 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3177 | case IOERR_INVALID_RPI: |
James Smart | 5b5b36a | 2013-01-03 15:43:19 -0500 | [diff] [blame] | 3178 | if (cmd == ELS_CMD_PLOGI && |
| 3179 | did == NameServer_DID) { |
| 3180 | /* Continue forever if plogi to */ |
| 3181 | /* the nameserver fails */ |
| 3182 | maxretry = 0; |
| 3183 | delay = 100; |
| 3184 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3185 | retry = 1; |
| 3186 | break; |
| 3187 | } |
| 3188 | break; |
| 3189 | |
| 3190 | case IOSTAT_NPORT_RJT: |
| 3191 | case IOSTAT_FABRIC_RJT: |
| 3192 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 3193 | retry = 1; |
| 3194 | break; |
| 3195 | } |
| 3196 | break; |
| 3197 | |
| 3198 | case IOSTAT_NPORT_BSY: |
| 3199 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3200 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3201 | retry = 1; |
| 3202 | break; |
| 3203 | |
| 3204 | case IOSTAT_LS_RJT: |
| 3205 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 3206 | /* Added for Vendor specifc support |
| 3207 | * Just keep retrying for these Rsn / Exp codes |
| 3208 | */ |
| 3209 | switch (stat.un.b.lsRjtRsnCode) { |
| 3210 | case LSRJT_UNABLE_TPC: |
| 3211 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3212 | LSEXP_CMD_IN_PROGRESS) { |
| 3213 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3214 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3215 | maxretry = 48; |
| 3216 | } |
| 3217 | retry = 1; |
| 3218 | break; |
| 3219 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3220 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3221 | LSEXP_CANT_GIVE_DATA) { |
| 3222 | if (cmd == ELS_CMD_PLOGI) { |
| 3223 | delay = 1000; |
| 3224 | maxretry = 48; |
| 3225 | } |
| 3226 | retry = 1; |
| 3227 | break; |
| 3228 | } |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 3229 | if ((cmd == ELS_CMD_PLOGI) || |
| 3230 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3231 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3232 | maxretry = lpfc_max_els_tries + 1; |
| 3233 | retry = 1; |
| 3234 | break; |
| 3235 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3236 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3237 | (cmd == ELS_CMD_FDISC) && |
| 3238 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3239 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3240 | "0125 FDISC Failed (x%x). " |
| 3241 | "Fabric out of resources\n", |
| 3242 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3243 | lpfc_vport_set_state(vport, |
| 3244 | FC_VPORT_NO_FABRIC_RSCS); |
| 3245 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3246 | break; |
| 3247 | |
| 3248 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3249 | if ((cmd == ELS_CMD_PLOGI) || |
| 3250 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3251 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3252 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3253 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3254 | /* FDISC retry policy */ |
| 3255 | maxretry = 48; |
| 3256 | if (cmdiocb->retry >= 32) |
| 3257 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3258 | } |
| 3259 | retry = 1; |
| 3260 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3261 | |
| 3262 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3263 | /* There are some cases where switches return this |
| 3264 | * error when they are not ready and should be returning |
| 3265 | * Logical Busy. We should delay every time. |
| 3266 | */ |
| 3267 | if (cmd == ELS_CMD_FDISC && |
| 3268 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 3269 | maxretry = 3; |
| 3270 | delay = 1000; |
| 3271 | retry = 1; |
| 3272 | break; |
| 3273 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3274 | case LSRJT_PROTOCOL_ERR: |
| 3275 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3276 | (cmd == ELS_CMD_FDISC) && |
| 3277 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 3278 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 3279 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3280 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3281 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3282 | "Fabric Detected Bad WWN\n", |
| 3283 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3284 | lpfc_vport_set_state(vport, |
| 3285 | FC_VPORT_FABRIC_REJ_WWN); |
| 3286 | } |
| 3287 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3288 | } |
| 3289 | break; |
| 3290 | |
| 3291 | case IOSTAT_INTERMED_RSP: |
| 3292 | case IOSTAT_BA_RJT: |
| 3293 | break; |
| 3294 | |
| 3295 | default: |
| 3296 | break; |
| 3297 | } |
| 3298 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3299 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3300 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3301 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3302 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3303 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 3304 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3305 | /* FLOGI retry policy */ |
| 3306 | retry = 1; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3307 | /* retry FLOGI forever */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3308 | maxretry = 0; |
| 3309 | if (cmdiocb->retry >= 100) |
| 3310 | delay = 5000; |
| 3311 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3312 | delay = 1000; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3313 | } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) { |
| 3314 | /* retry FDISCs every second up to devloss */ |
| 3315 | retry = 1; |
| 3316 | maxretry = vport->cfg_devloss_tmo; |
| 3317 | delay = 1000; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3318 | } |
| 3319 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3320 | cmdiocb->retry++; |
| 3321 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3322 | phba->fc_stat.elsRetryExceeded++; |
| 3323 | retry = 0; |
| 3324 | } |
| 3325 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3326 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 3327 | retry = 0; |
| 3328 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3329 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3330 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 3331 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 3332 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 3333 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3334 | "2849 Stop retry ELS command " |
| 3335 | "x%x to remote NPORT x%x, " |
| 3336 | "Data: x%x x%x\n", cmd, did, |
| 3337 | cmdiocb->retry, delay); |
| 3338 | return 0; |
| 3339 | } |
| 3340 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | |
| 3342 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3343 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3344 | "0107 Retry ELS command x%x to remote " |
| 3345 | "NPORT x%x Data: x%x x%x\n", |
| 3346 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3347 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3348 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 3349 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3350 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 3351 | IOERR_NO_RESOURCES))) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3352 | /* Don't reset timer for no resources */ |
| 3353 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3354 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3355 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3356 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3357 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3361 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3362 | phba->fc_stat.elsDelayRetry++; |
| 3363 | ndlp->nlp_retry = cmdiocb->retry; |
| 3364 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3365 | /* delay is specified in milliseconds */ |
| 3366 | mod_timer(&ndlp->nlp_delayfunc, |
| 3367 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3368 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3369 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3370 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3371 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3372 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3373 | if (cmd == ELS_CMD_PRLI) |
| 3374 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 3375 | NLP_STE_PRLI_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3376 | else |
| 3377 | lpfc_nlp_set_state(vport, ndlp, |
| 3378 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3379 | ndlp->nlp_last_elscmd = cmd; |
| 3380 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3381 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3382 | } |
| 3383 | switch (cmd) { |
| 3384 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3385 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3386 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3387 | case ELS_CMD_FDISC: |
| 3388 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 3389 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3390 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3391 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3392 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3393 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3394 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3395 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3396 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3397 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3398 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -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, NLP_STE_ADISC_ISSUE); |
| 3401 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3402 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3403 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3404 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3405 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 3406 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3407 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3409 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3410 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3411 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3412 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3413 | } |
| 3414 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3415 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3416 | if (logerr) { |
| 3417 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3418 | "0137 No retry ELS command x%x to remote " |
| 3419 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 3420 | cmd, did, irsp->ulpStatus, |
| 3421 | irsp->un.ulpWord[4]); |
| 3422 | } |
| 3423 | else { |
| 3424 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3425 | "0108 No retry ELS command x%x to remote " |
| 3426 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 3427 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 3428 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3429 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3430 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3431 | } |
| 3432 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3433 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3434 | * 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] | 3435 | * @phba: pointer to lpfc hba data structure. |
| 3436 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3437 | * |
| 3438 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3439 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3440 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3441 | * response of the command IOCB. If so, it will be released before releasing |
| 3442 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3443 | * |
| 3444 | * Return code |
| 3445 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3446 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3447 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3448 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3449 | { |
| 3450 | struct lpfc_dmabuf *buf_ptr; |
| 3451 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3452 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3453 | if (!list_empty(&buf_ptr1->list)) { |
| 3454 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3455 | struct lpfc_dmabuf, |
| 3456 | list); |
| 3457 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3458 | kfree(buf_ptr); |
| 3459 | } |
| 3460 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3461 | kfree(buf_ptr1); |
| 3462 | return 0; |
| 3463 | } |
| 3464 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3465 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3466 | * 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] | 3467 | * @phba: pointer to lpfc hba data structure. |
| 3468 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3469 | * |
| 3470 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3471 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3472 | * pool. |
| 3473 | * |
| 3474 | * Return code |
| 3475 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3476 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3477 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3478 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3479 | { |
| 3480 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3481 | kfree(buf_ptr); |
| 3482 | return 0; |
| 3483 | } |
| 3484 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3485 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3486 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3487 | * @phba: pointer to lpfc hba data structure. |
| 3488 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3489 | * |
| 3490 | * This routine frees a command IOCB and its associated resources. The |
| 3491 | * command IOCB data structure contains the reference to various associated |
| 3492 | * resources, these fields must be set to NULL if the associated reference |
| 3493 | * not present: |
| 3494 | * context1 - reference to ndlp |
| 3495 | * context2 - reference to cmd |
| 3496 | * context2->next - reference to rsp |
| 3497 | * context3 - reference to bpl |
| 3498 | * |
| 3499 | * It first properly decrements the reference count held on ndlp for the |
| 3500 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3501 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3502 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3503 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3504 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3505 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3506 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3507 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3508 | * |
| 3509 | * Return code |
| 3510 | * 0 - Success (currently, always return 0) |
| 3511 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3512 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3513 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3514 | { |
| 3515 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3516 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3517 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3518 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3519 | if (ndlp) { |
| 3520 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3521 | lpfc_nlp_put(ndlp); |
| 3522 | |
| 3523 | /* If the ndlp is not being used by another discovery |
| 3524 | * thread, free it. |
| 3525 | */ |
| 3526 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3527 | /* If ndlp is being used by another discovery |
| 3528 | * thread, just clear NLP_DEFER_RM |
| 3529 | */ |
| 3530 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3531 | } |
| 3532 | } |
| 3533 | else |
| 3534 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3535 | elsiocb->context1 = NULL; |
| 3536 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3537 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3538 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3539 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3540 | /* Firmware could still be in progress of DMAing |
| 3541 | * payload, so don't free data buffer till after |
| 3542 | * a hbeat. |
| 3543 | */ |
| 3544 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3545 | buf_ptr = elsiocb->context2; |
| 3546 | elsiocb->context2 = NULL; |
| 3547 | if (buf_ptr) { |
| 3548 | buf_ptr1 = NULL; |
| 3549 | spin_lock_irq(&phba->hbalock); |
| 3550 | if (!list_empty(&buf_ptr->list)) { |
| 3551 | list_remove_head(&buf_ptr->list, |
| 3552 | buf_ptr1, struct lpfc_dmabuf, |
| 3553 | list); |
| 3554 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3555 | list_add_tail(&buf_ptr1->list, |
| 3556 | &phba->elsbuf); |
| 3557 | phba->elsbuf_cnt++; |
| 3558 | } |
| 3559 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3560 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3561 | phba->elsbuf_cnt++; |
| 3562 | spin_unlock_irq(&phba->hbalock); |
| 3563 | } |
| 3564 | } else { |
| 3565 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3566 | lpfc_els_free_data(phba, buf_ptr1); |
| 3567 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | } |
| 3569 | |
| 3570 | if (elsiocb->context3) { |
| 3571 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3572 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3573 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3574 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3575 | return 0; |
| 3576 | } |
| 3577 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3578 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3579 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3580 | * @phba: pointer to lpfc hba data structure. |
| 3581 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3582 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3583 | * |
| 3584 | * This routine is the completion callback function to the Logout (LOGO) |
| 3585 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3586 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3587 | * release the ndlp if it has the last reference remaining (reference count |
| 3588 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3589 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3590 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3591 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3592 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3593 | * IOCB data structure. |
| 3594 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3595 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3596 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3597 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3598 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3599 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3600 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3601 | IOCB_t *irsp; |
| 3602 | |
| 3603 | irsp = &rspiocb->iocb; |
| 3604 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3605 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3606 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3607 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3608 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3609 | "0109 ACC to LOGO completes to NPort x%x " |
| 3610 | "Data: x%x x%x x%x\n", |
| 3611 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3612 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3613 | |
| 3614 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3615 | /* NPort Recovery mode or node is just allocated */ |
| 3616 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3617 | /* If the ndlp is being used by another discovery |
| 3618 | * thread, just unregister the RPI. |
| 3619 | */ |
| 3620 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3621 | } else { |
| 3622 | /* Indicate the node has already released, should |
| 3623 | * not reference to it from within lpfc_els_free_iocb. |
| 3624 | */ |
| 3625 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3626 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3627 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3628 | |
| 3629 | /* |
| 3630 | * 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] | 3631 | * At this point, the driver is done so release the IOCB |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3632 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3634 | |
| 3635 | /* |
| 3636 | * Remove the ndlp reference if it's a fabric node that has |
| 3637 | * sent us an unsolicted LOGO. |
| 3638 | */ |
| 3639 | if (ndlp->nlp_type & NLP_FABRIC) |
| 3640 | lpfc_nlp_put(ndlp); |
| 3641 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3642 | return; |
| 3643 | } |
| 3644 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3645 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3646 | * 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] | 3647 | * @phba: pointer to lpfc hba data structure. |
| 3648 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3649 | * |
| 3650 | * This routine is the completion callback function for unregister default |
| 3651 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3652 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3653 | * decrements the ndlp reference count held for this completion callback |
| 3654 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3655 | * whether there is only one reference left on the ndlp. If so, it will |
| 3656 | * perform one more decrement and trigger the release of the ndlp. |
| 3657 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3658 | void |
| 3659 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3660 | { |
| 3661 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3662 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3663 | |
| 3664 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3665 | pmb->context2 = NULL; |
| 3666 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3667 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3668 | kfree(mp); |
| 3669 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3670 | if (ndlp) { |
| 3671 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 3672 | lpfc_nlp_put(ndlp); |
| 3673 | /* This is the end of the default RPI cleanup logic for |
| 3674 | * this ndlp. If no other discovery threads are using |
| 3675 | * this ndlp, free all resources associated with it. |
| 3676 | */ |
| 3677 | lpfc_nlp_not_used(ndlp); |
| 3678 | } else { |
| 3679 | lpfc_drop_node(ndlp->vport, ndlp); |
| 3680 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3681 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3682 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3683 | return; |
| 3684 | } |
| 3685 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3686 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3687 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3688 | * @phba: pointer to lpfc hba data structure. |
| 3689 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3690 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3691 | * |
| 3692 | * This routine is the completion callback function for ELS Response IOCB |
| 3693 | * command. In normal case, this callback function just properly sets the |
| 3694 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3695 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3696 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3697 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3698 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3699 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3700 | * are currently referring it. |
| 3701 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3702 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3703 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3704 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3705 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3706 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3707 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3708 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3709 | IOCB_t *irsp; |
| 3710 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3711 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3712 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3713 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3714 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3715 | irsp = &rspiocb->iocb; |
| 3716 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3717 | if (cmdiocb->context_un.mbox) |
| 3718 | mbox = cmdiocb->context_un.mbox; |
| 3719 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3720 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3721 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3722 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3723 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3724 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3725 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3726 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3727 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3728 | */ |
| 3729 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3730 | ls_rjt = 1; |
| 3731 | } |
| 3732 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3733 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3734 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3735 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3736 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3737 | if (mp) { |
| 3738 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3739 | kfree(mp); |
| 3740 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3741 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3742 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3743 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3744 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3745 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3746 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3747 | /* Indicate the node has already released, |
| 3748 | * should not reference to it from within |
| 3749 | * the routine lpfc_els_free_iocb. |
| 3750 | */ |
| 3751 | cmdiocb->context1 = NULL; |
| 3752 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3753 | goto out; |
| 3754 | } |
| 3755 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3756 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3757 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3758 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3759 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3760 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3761 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3762 | "0110 ELS response tag x%x completes " |
| 3763 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3764 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3765 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3766 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3767 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3768 | if (mbox) { |
| 3769 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3770 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3771 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3772 | /* Increment reference count to ndlp to hold the |
| 3773 | * reference to ndlp for the callback function. |
| 3774 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3775 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3776 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3777 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3778 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3779 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3780 | } |
| 3781 | else { |
| 3782 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3783 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3784 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3785 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3786 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3787 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3788 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3790 | else |
| 3791 | /* Decrement the ndlp reference count we |
| 3792 | * set for this failed mailbox command. |
| 3793 | */ |
| 3794 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3795 | |
| 3796 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3797 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3798 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3799 | "Data: x%x x%x x%x\n", |
| 3800 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3801 | ndlp->nlp_rpi); |
| 3802 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3803 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3804 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3805 | /* Indicate node has already been released, |
| 3806 | * should not reference to it from within |
| 3807 | * the routine lpfc_els_free_iocb. |
| 3808 | */ |
| 3809 | cmdiocb->context1 = NULL; |
| 3810 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3811 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3812 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3813 | if (!lpfc_error_lost_link(irsp) && |
| 3814 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3815 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3816 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3817 | /* Indicate node has already been |
| 3818 | * released, should not reference |
| 3819 | * to it from within the routine |
| 3820 | * lpfc_els_free_iocb. |
| 3821 | */ |
| 3822 | cmdiocb->context1 = NULL; |
| 3823 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3824 | } |
| 3825 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3826 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3827 | if (mp) { |
| 3828 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3829 | kfree(mp); |
| 3830 | } |
| 3831 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3832 | } |
| 3833 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3834 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3835 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3836 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3837 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3838 | |
| 3839 | /* If the node is not being used by another discovery thread, |
| 3840 | * and we are sending a reject, we are done with it. |
| 3841 | * Release driver reference count here and free associated |
| 3842 | * resources. |
| 3843 | */ |
| 3844 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3845 | if (lpfc_nlp_not_used(ndlp)) |
| 3846 | /* Indicate node has already been released, |
| 3847 | * should not reference to it from within |
| 3848 | * the routine lpfc_els_free_iocb. |
| 3849 | */ |
| 3850 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3851 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3852 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3853 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3854 | return; |
| 3855 | } |
| 3856 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3857 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3858 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3859 | * @vport: pointer to a host virtual N_Port data structure. |
| 3860 | * @flag: the els command code to be accepted. |
| 3861 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3862 | * @ndlp: pointer to a node-list data structure. |
| 3863 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3864 | * |
| 3865 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3866 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3867 | * specific ACC response command to be issued and invokes the |
| 3868 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3869 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3870 | * field of the IOCB for the completion callback function to issue the |
| 3871 | * mailbox command to the HBA later when callback is invoked. |
| 3872 | * |
| 3873 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3874 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3875 | * will be stored into the context1 field of the IOCB for the completion |
| 3876 | * callback function to the corresponding response ELS IOCB command. |
| 3877 | * |
| 3878 | * Return code |
| 3879 | * 0 - Successfully issued acc response |
| 3880 | * 1 - Failed to issue acc response |
| 3881 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3882 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3883 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3884 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3885 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3886 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3887 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3888 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3889 | IOCB_t *icmd; |
| 3890 | IOCB_t *oldcmd; |
| 3891 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3892 | struct lpfc_sli *psli; |
| 3893 | uint8_t *pcmd; |
| 3894 | uint16_t cmdsize; |
| 3895 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3896 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3897 | |
| 3898 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | oldcmd = &oldiocb->iocb; |
| 3900 | |
| 3901 | switch (flag) { |
| 3902 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3903 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3904 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3905 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3906 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3907 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3908 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3909 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3910 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3911 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3912 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3913 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3914 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3915 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3916 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3917 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3918 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3919 | |
| 3920 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3921 | "Issue ACC: did:x%x flg:x%x", |
| 3922 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3923 | break; |
| 3924 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3925 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3926 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3927 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3928 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3929 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3930 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3931 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3932 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3933 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3934 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3935 | |
| 3936 | if (mbox) |
| 3937 | elsiocb->context_un.mbox = mbox; |
| 3938 | |
| 3939 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3940 | pcmd += sizeof(uint32_t); |
| 3941 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3942 | |
| 3943 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3944 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3945 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3946 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3947 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3948 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3949 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3950 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3951 | if (!elsiocb) |
| 3952 | return 1; |
| 3953 | |
| 3954 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3955 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3956 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3957 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3958 | |
| 3959 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3960 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3961 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3962 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3963 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3964 | |
| 3965 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3966 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3967 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3968 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3969 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3970 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3971 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3972 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3973 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3974 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 3975 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x " |
| 3976 | "fc_flag x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3977 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3978 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 3979 | ndlp->nlp_rpi, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3980 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3981 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3982 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3983 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3984 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3985 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3986 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3987 | } |
| 3988 | |
| 3989 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3990 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3991 | if (rc == IOCB_ERROR) { |
| 3992 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3993 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3994 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3995 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3996 | } |
| 3997 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3998 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3999 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4000 | * @vport: pointer to a virtual N_Port data structure. |
| 4001 | * @rejectError: |
| 4002 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4003 | * @ndlp: pointer to a node-list data structure. |
| 4004 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4005 | * |
| 4006 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 4007 | * command. If a @mbox pointer is passed in, it will be put into the |
| 4008 | * context_un.mbox field of the IOCB for the completion callback function |
| 4009 | * to issue to the HBA later. |
| 4010 | * |
| 4011 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4012 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4013 | * will be stored into the context1 field of the IOCB for the completion |
| 4014 | * callback function to the reject response ELS IOCB command. |
| 4015 | * |
| 4016 | * Return code |
| 4017 | * 0 - Successfully issued reject response |
| 4018 | * 1 - Failed to issue reject response |
| 4019 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4020 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4021 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4022 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 4023 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4024 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4025 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4026 | IOCB_t *icmd; |
| 4027 | IOCB_t *oldcmd; |
| 4028 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4029 | struct lpfc_sli *psli; |
| 4030 | uint8_t *pcmd; |
| 4031 | uint16_t cmdsize; |
| 4032 | int rc; |
| 4033 | |
| 4034 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4035 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4036 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4037 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4038 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4039 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4040 | |
| 4041 | icmd = &elsiocb->iocb; |
| 4042 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4043 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4044 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4045 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4046 | |
| 4047 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4048 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4049 | *((uint32_t *) (pcmd)) = rejectError; |
| 4050 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4051 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4052 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4053 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4054 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4055 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4056 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 4057 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4058 | "rpi x%x\n", |
| 4059 | rejectError, elsiocb->iotag, |
| 4060 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 4061 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4062 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4063 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 4064 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 4065 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4066 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4067 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4068 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4069 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4070 | if (rc == IOCB_ERROR) { |
| 4071 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4072 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4073 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4074 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4075 | } |
| 4076 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4077 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4078 | * 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] | 4079 | * @vport: pointer to a virtual N_Port data structure. |
| 4080 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4081 | * @ndlp: pointer to a node-list data structure. |
| 4082 | * |
| 4083 | * This routine prepares and issues an Accept (ACC) response to Address |
| 4084 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 4085 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4086 | * |
| 4087 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4088 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4089 | * will be stored into the context1 field of the IOCB for the completion |
| 4090 | * callback function to the ADISC Accept response ELS IOCB command. |
| 4091 | * |
| 4092 | * Return code |
| 4093 | * 0 - Successfully issued acc adisc response |
| 4094 | * 1 - Failed to issue adisc acc response |
| 4095 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4096 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4097 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 4098 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4099 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4100 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4101 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4102 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4103 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | uint8_t *pcmd; |
| 4105 | uint16_t cmdsize; |
| 4106 | int rc; |
| 4107 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4108 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4109 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4110 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4111 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4112 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4113 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4114 | icmd = &elsiocb->iocb; |
| 4115 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4116 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4117 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4118 | |
| 4119 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4120 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4121 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 4122 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 4123 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4124 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4125 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4126 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4127 | |
| 4128 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4129 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4130 | |
| 4131 | ap = (ADISC *) (pcmd); |
| 4132 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4133 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4134 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4135 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4136 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4137 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4138 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 4139 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4140 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4141 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4142 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4143 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4144 | if (rc == IOCB_ERROR) { |
| 4145 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4146 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4147 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4148 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4149 | } |
| 4150 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4151 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4152 | * 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] | 4153 | * @vport: pointer to a virtual N_Port data structure. |
| 4154 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4155 | * @ndlp: pointer to a node-list data structure. |
| 4156 | * |
| 4157 | * This routine prepares and issues an Accept (ACC) response to Process |
| 4158 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 4159 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4160 | * |
| 4161 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4162 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4163 | * will be stored into the context1 field of the IOCB for the completion |
| 4164 | * callback function to the PRLI Accept response ELS IOCB command. |
| 4165 | * |
| 4166 | * Return code |
| 4167 | * 0 - Successfully issued acc prli response |
| 4168 | * 1 - Failed to issue acc prli response |
| 4169 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4170 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4171 | 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] | 4172 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4173 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4174 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | PRLI *npr; |
| 4176 | lpfc_vpd_t *vpd; |
| 4177 | IOCB_t *icmd; |
| 4178 | IOCB_t *oldcmd; |
| 4179 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4180 | struct lpfc_sli *psli; |
| 4181 | uint8_t *pcmd; |
| 4182 | uint16_t cmdsize; |
| 4183 | int rc; |
| 4184 | |
| 4185 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4186 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4187 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4188 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4189 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4190 | if (!elsiocb) |
| 4191 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4192 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4193 | icmd = &elsiocb->iocb; |
| 4194 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4195 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4196 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4197 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4198 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4199 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4200 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 4201 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4202 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4203 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4204 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4205 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4206 | |
| 4207 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4208 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4209 | |
| 4210 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4211 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4212 | |
| 4213 | npr = (PRLI *) pcmd; |
| 4214 | vpd = &phba->vpd; |
| 4215 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4216 | * If the remote port is a target and our firmware version is 3.20 or |
| 4217 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4218 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4219 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 4220 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4221 | npr->ConfmComplAllowed = 1; |
| 4222 | npr->Retry = 1; |
| 4223 | npr->TaskRetryIdReq = 1; |
| 4224 | } |
| 4225 | |
| 4226 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 4227 | npr->estabImagePair = 1; |
| 4228 | npr->readXferRdyDis = 1; |
| 4229 | npr->ConfmComplAllowed = 1; |
| 4230 | |
| 4231 | npr->prliType = PRLI_FCP_TYPE; |
| 4232 | npr->initiatorFunc = 1; |
| 4233 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4234 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4235 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 4236 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4237 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4238 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4239 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4240 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4241 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4242 | if (rc == IOCB_ERROR) { |
| 4243 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4244 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4245 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4246 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4247 | } |
| 4248 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4249 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4250 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4251 | * @vport: pointer to a virtual N_Port data structure. |
| 4252 | * @format: rnid command format. |
| 4253 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4254 | * @ndlp: pointer to a node-list data structure. |
| 4255 | * |
| 4256 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 4257 | * (ACC) response. It constructs the RNID ACC response command according to |
| 4258 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 4259 | * issue the response. Note that this command does not need to hold the ndlp |
| 4260 | * reference count for the callback. So, the ndlp reference count taken by |
| 4261 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 4262 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 4263 | * there is no ndlp reference available. |
| 4264 | * |
| 4265 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4266 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4267 | * will be stored into the context1 field of the IOCB for the completion |
| 4268 | * callback function. However, for the RNID Accept Response ELS command, |
| 4269 | * this is undone later by this routine after the IOCB is allocated. |
| 4270 | * |
| 4271 | * Return code |
| 4272 | * 0 - Successfully issued acc rnid response |
| 4273 | * 1 - Failed to issue acc rnid response |
| 4274 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4275 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4276 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4277 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4278 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4279 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4280 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4281 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4283 | struct lpfc_sli *psli; |
| 4284 | uint8_t *pcmd; |
| 4285 | uint16_t cmdsize; |
| 4286 | int rc; |
| 4287 | |
| 4288 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4289 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 4290 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4291 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4292 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4293 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4294 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4295 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4296 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4297 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4298 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4299 | icmd = &elsiocb->iocb; |
| 4300 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4301 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4302 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4303 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4304 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4305 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4306 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 4307 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4308 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4309 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4310 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4312 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4313 | rn = (RNID *) (pcmd); |
| 4314 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4315 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 4316 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4317 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4318 | switch (format) { |
| 4319 | case 0: |
| 4320 | rn->SpecificLen = 0; |
| 4321 | break; |
| 4322 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4323 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4324 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4325 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4326 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 4327 | rn->un.topologyDisc.physPort = 0; |
| 4328 | rn->un.topologyDisc.attachedNodes = 0; |
| 4329 | break; |
| 4330 | default: |
| 4331 | rn->CommonLen = 0; |
| 4332 | rn->SpecificLen = 0; |
| 4333 | break; |
| 4334 | } |
| 4335 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4336 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4337 | "Issue ACC RNID: did:x%x flg:x%x", |
| 4338 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4339 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4340 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4341 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4342 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4343 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | if (rc == IOCB_ERROR) { |
| 4345 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4346 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4347 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4348 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4349 | } |
| 4350 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4351 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4352 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. |
| 4353 | * @vport: pointer to a virtual N_Port data structure. |
| 4354 | * @iocb: pointer to the lpfc command iocb data structure. |
| 4355 | * @ndlp: pointer to a node-list data structure. |
| 4356 | * |
| 4357 | * Return |
| 4358 | **/ |
| 4359 | static void |
| 4360 | lpfc_els_clear_rrq(struct lpfc_vport *vport, |
| 4361 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
| 4362 | { |
| 4363 | struct lpfc_hba *phba = vport->phba; |
| 4364 | uint8_t *pcmd; |
| 4365 | struct RRQ *rrq; |
| 4366 | uint16_t rxid; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4367 | uint16_t xri; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4368 | struct lpfc_node_rrq *prrq; |
| 4369 | |
| 4370 | |
| 4371 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); |
| 4372 | pcmd += sizeof(uint32_t); |
| 4373 | rrq = (struct RRQ *)pcmd; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4374 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4375 | rxid = bf_get(rrq_rxid, rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4376 | |
| 4377 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4378 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" |
| 4379 | " x%x x%x\n", |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4380 | be32_to_cpu(bf_get(rrq_did, rrq)), |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4381 | bf_get(rrq_oxid, rrq), |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4382 | rxid, |
| 4383 | iocb->iotag, iocb->iocb.ulpContext); |
| 4384 | |
| 4385 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4386 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", |
| 4387 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4388 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4389 | xri = bf_get(rrq_oxid, rrq); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4390 | else |
| 4391 | xri = rxid; |
| 4392 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4393 | if (prrq) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4394 | lpfc_clr_rrq_active(phba, xri, prrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4395 | return; |
| 4396 | } |
| 4397 | |
| 4398 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4399 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 4400 | * @vport: pointer to a virtual N_Port data structure. |
| 4401 | * @data: pointer to echo data to return in the accept. |
| 4402 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4403 | * @ndlp: pointer to a node-list data structure. |
| 4404 | * |
| 4405 | * Return code |
| 4406 | * 0 - Successfully issued acc echo response |
| 4407 | * 1 - Failed to issue acc echo response |
| 4408 | **/ |
| 4409 | static int |
| 4410 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 4411 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 4412 | { |
| 4413 | struct lpfc_hba *phba = vport->phba; |
| 4414 | struct lpfc_iocbq *elsiocb; |
| 4415 | struct lpfc_sli *psli; |
| 4416 | uint8_t *pcmd; |
| 4417 | uint16_t cmdsize; |
| 4418 | int rc; |
| 4419 | |
| 4420 | psli = &phba->sli; |
| 4421 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 4422 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4423 | /* The accumulated length can exceed the BPL_SIZE. For |
| 4424 | * now, use this as the limit |
| 4425 | */ |
| 4426 | if (cmdsize > LPFC_BPL_SIZE) |
| 4427 | cmdsize = LPFC_BPL_SIZE; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4428 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4429 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4430 | if (!elsiocb) |
| 4431 | return 1; |
| 4432 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4433 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 4434 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; |
| 4435 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4436 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 4437 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4438 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 4439 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 4440 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4441 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4442 | pcmd += sizeof(uint32_t); |
| 4443 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 4444 | |
| 4445 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4446 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 4447 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4448 | |
| 4449 | phba->fc_stat.elsXmitACC++; |
| 4450 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4451 | |
| 4452 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4453 | if (rc == IOCB_ERROR) { |
| 4454 | lpfc_els_free_iocb(phba, elsiocb); |
| 4455 | return 1; |
| 4456 | } |
| 4457 | return 0; |
| 4458 | } |
| 4459 | |
| 4460 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4461 | * 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] | 4462 | * @vport: pointer to a host virtual N_Port data structure. |
| 4463 | * |
| 4464 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 4465 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 4466 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 4467 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 4468 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 4469 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 4470 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 4471 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 4472 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 4473 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 4474 | * no more ADISC need to be sent. |
| 4475 | * |
| 4476 | * Return code |
| 4477 | * The number of N_Ports with adisc issued. |
| 4478 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4479 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4480 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4481 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4482 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4483 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4484 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4485 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4486 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4487 | 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] | 4488 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4489 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4490 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4491 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4492 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4493 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4494 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4495 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4496 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4497 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4498 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4499 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4500 | vport->num_disc_nodes++; |
| 4501 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4502 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4503 | spin_lock_irq(shost->host_lock); |
| 4504 | vport->fc_flag |= FC_NLP_MORE; |
| 4505 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4506 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4507 | } |
| 4508 | } |
| 4509 | } |
| 4510 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4511 | spin_lock_irq(shost->host_lock); |
| 4512 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4513 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4514 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4515 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4516 | } |
| 4517 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4518 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4519 | * 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] | 4520 | * @vport: pointer to a host virtual N_Port data structure. |
| 4521 | * |
| 4522 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4523 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4524 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4525 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4526 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4527 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4528 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4529 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4530 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4531 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4532 | * PLOGI need to be sent. |
| 4533 | * |
| 4534 | * Return code |
| 4535 | * The number of N_Ports with plogi issued. |
| 4536 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4537 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4538 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4539 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4540 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4541 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4542 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4543 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4544 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4545 | 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] | 4546 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4547 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4548 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4549 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4550 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4551 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 4552 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4553 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4554 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4555 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4556 | vport->num_disc_nodes++; |
| 4557 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4558 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4559 | spin_lock_irq(shost->host_lock); |
| 4560 | vport->fc_flag |= FC_NLP_MORE; |
| 4561 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4562 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4563 | } |
| 4564 | } |
| 4565 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4566 | if (sentplogi) { |
| 4567 | lpfc_set_disctmo(vport); |
| 4568 | } |
| 4569 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4570 | spin_lock_irq(shost->host_lock); |
| 4571 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4572 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4573 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4574 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4575 | } |
| 4576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4577 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4578 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4579 | * @vport: pointer to a host virtual N_Port data structure. |
| 4580 | * |
| 4581 | * This routine cleans up any Registration State Change Notification |
| 4582 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 4583 | * @vport together with the host_lock is used to prevent multiple thread |
| 4584 | * trying to access the RSCN array on a same @vport at the same time. |
| 4585 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4586 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4587 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4588 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4589 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4590 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4591 | int i; |
| 4592 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4593 | spin_lock_irq(shost->host_lock); |
| 4594 | if (vport->fc_rscn_flush) { |
| 4595 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4596 | spin_unlock_irq(shost->host_lock); |
| 4597 | return; |
| 4598 | } |
| 4599 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 4600 | vport->fc_rscn_flush = 1; |
| 4601 | spin_unlock_irq(shost->host_lock); |
| 4602 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4603 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4604 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4605 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4606 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4607 | spin_lock_irq(shost->host_lock); |
| 4608 | vport->fc_rscn_id_cnt = 0; |
| 4609 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 4610 | spin_unlock_irq(shost->host_lock); |
| 4611 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4612 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 4613 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4614 | } |
| 4615 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4616 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4617 | * 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] | 4618 | * @vport: pointer to a host virtual N_Port data structure. |
| 4619 | * @did: remote destination port identifier. |
| 4620 | * |
| 4621 | * This routine checks whether there is any pending Registration State |
| 4622 | * Configuration Notification (RSCN) to a @did on @vport. |
| 4623 | * |
| 4624 | * Return code |
| 4625 | * None zero - The @did matched with a pending rscn |
| 4626 | * 0 - not able to match @did with a pending rscn |
| 4627 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4628 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4629 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4630 | { |
| 4631 | D_ID ns_did; |
| 4632 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4633 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4634 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4635 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4636 | |
| 4637 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4638 | |
| 4639 | /* Never match fabric nodes for RSCNs */ |
| 4640 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4641 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4642 | |
| 4643 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4644 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4645 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4646 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4647 | spin_lock_irq(shost->host_lock); |
| 4648 | if (vport->fc_rscn_flush) { |
| 4649 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4650 | spin_unlock_irq(shost->host_lock); |
| 4651 | return 0; |
| 4652 | } |
| 4653 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4654 | vport->fc_rscn_flush = 1; |
| 4655 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4656 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4657 | lp = vport->fc_rscn_id_list[i]->virt; |
| 4658 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4659 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4660 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4661 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 4662 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4663 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 4664 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4665 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4666 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 4667 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4668 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4669 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4670 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4671 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4672 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4673 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4674 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4675 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4676 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4677 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4678 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4679 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4680 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4681 | } |
| 4682 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4683 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4684 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4685 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4686 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4687 | return_did_out: |
| 4688 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4689 | vport->fc_rscn_flush = 0; |
| 4690 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4691 | } |
| 4692 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4693 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4694 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4695 | * @vport: pointer to a host virtual N_Port data structure. |
| 4696 | * |
| 4697 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 4698 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 4699 | * State Change Notification). |
| 4700 | * |
| 4701 | * Return code |
| 4702 | * 0 - Successful (currently alway return 0) |
| 4703 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4704 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4705 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4706 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4707 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4708 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4709 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4710 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4711 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4712 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4713 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4714 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4715 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4716 | NLP_EVT_DEVICE_RECOVERY); |
| 4717 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4718 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4719 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4720 | } |
| 4721 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4722 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4723 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4724 | * @vport: pointer to a host virtual N_Port data structure. |
| 4725 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4726 | * |
| 4727 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4728 | * applications. |
| 4729 | */ |
| 4730 | static void |
| 4731 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4732 | struct lpfc_iocbq *cmdiocb) |
| 4733 | { |
| 4734 | struct lpfc_dmabuf *pcmd; |
| 4735 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4736 | uint32_t *payload_ptr; |
| 4737 | uint32_t payload_len; |
| 4738 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4739 | |
| 4740 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4741 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4742 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4743 | |
| 4744 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4745 | payload_len, GFP_KERNEL); |
| 4746 | if (!rscn_event_data) { |
| 4747 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4748 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4749 | return; |
| 4750 | } |
| 4751 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4752 | rscn_event_data->payload_length = payload_len; |
| 4753 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4754 | payload_len); |
| 4755 | |
| 4756 | fc_host_post_vendor_event(shost, |
| 4757 | fc_get_event_number(), |
| 4758 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4759 | (char *)rscn_event_data, |
| 4760 | LPFC_NL_VENDOR_ID); |
| 4761 | |
| 4762 | kfree(rscn_event_data); |
| 4763 | } |
| 4764 | |
| 4765 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4766 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4767 | * @vport: pointer to a host virtual N_Port data structure. |
| 4768 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4769 | * @ndlp: pointer to a node-list data structure. |
| 4770 | * |
| 4771 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4772 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4773 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4774 | * discover state machine is about to begin discovery, it just accepts the |
| 4775 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4776 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4777 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4778 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4779 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4780 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4781 | * routine is invoked to handle the RSCN event. |
| 4782 | * |
| 4783 | * Return code |
| 4784 | * 0 - Just sent the acc response |
| 4785 | * 1 - Sent the acc response and waited for name server completion |
| 4786 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4787 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4788 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4789 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4790 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4791 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4792 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4793 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4794 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4795 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4796 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4797 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4798 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4799 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4800 | |
| 4801 | icmd = &cmdiocb->iocb; |
| 4802 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4803 | lp = (uint32_t *) pcmd->virt; |
| 4804 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4805 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4806 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4807 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4808 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4809 | "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] | 4810 | vport->fc_flag, payload_len, *lp, |
| 4811 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4812 | |
| 4813 | /* Send an RSCN event to the management application */ |
| 4814 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4815 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4816 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4817 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4818 | FCH_EVT_RSCN, lp[i]); |
| 4819 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4820 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4821 | * Discovery processing will satisfy it. |
| 4822 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4823 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4824 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4825 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4826 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4827 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4828 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4829 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4830 | } |
| 4831 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4832 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4833 | * just ACC and ignore it. |
| 4834 | */ |
| 4835 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4836 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4837 | i = payload_len; |
| 4838 | datap = lp; |
| 4839 | while (i > 0) { |
| 4840 | nportid = *datap++; |
| 4841 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4842 | i -= sizeof(uint32_t); |
| 4843 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4844 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4845 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4846 | } |
| 4847 | if (rscn_id == hba_id) { |
| 4848 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4849 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4850 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4851 | "Data: x%x x%x x%x x%x\n", |
| 4852 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4853 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4854 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4855 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4856 | ndlp->nlp_DID, vport->port_state, |
| 4857 | ndlp->nlp_flag); |
| 4858 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4859 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4860 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4861 | return 0; |
| 4862 | } |
| 4863 | } |
| 4864 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4865 | spin_lock_irq(shost->host_lock); |
| 4866 | if (vport->fc_rscn_flush) { |
| 4867 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4868 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4869 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4870 | /* Send back ACC */ |
| 4871 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4872 | return 0; |
| 4873 | } |
| 4874 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4875 | vport->fc_rscn_flush = 1; |
| 4876 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4877 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4878 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4879 | /* If we are already processing an RSCN, save the received |
| 4880 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4881 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4882 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4883 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4884 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4885 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4886 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4887 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4888 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4889 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4890 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4891 | vport->fc_flag |= FC_RSCN_MODE; |
| 4892 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4893 | if (rscn_cnt) { |
| 4894 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4895 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4896 | } |
| 4897 | if ((rscn_cnt) && |
| 4898 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4899 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4900 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4901 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4902 | payload_len); |
| 4903 | } else { |
| 4904 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4905 | vport->fc_rscn_id_cnt++; |
| 4906 | /* If we zero, cmdiocb->context2, the calling |
| 4907 | * routine will not try to free it. |
| 4908 | */ |
| 4909 | cmdiocb->context2 = NULL; |
| 4910 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4911 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4912 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4913 | "0235 Deferred RSCN " |
| 4914 | "Data: x%x x%x x%x\n", |
| 4915 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4916 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4917 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4918 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4919 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4920 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4921 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4922 | "0234 ReDiscovery RSCN " |
| 4923 | "Data: x%x x%x x%x\n", |
| 4924 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4925 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4926 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4927 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4928 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4929 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4930 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4931 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4932 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4933 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4934 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4935 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4936 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4937 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4938 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4939 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4940 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4941 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4942 | spin_lock_irq(shost->host_lock); |
| 4943 | vport->fc_flag |= FC_RSCN_MODE; |
| 4944 | spin_unlock_irq(shost->host_lock); |
| 4945 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4946 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4947 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4948 | /* |
| 4949 | * If we zero, cmdiocb->context2, the calling routine will |
| 4950 | * not try to free it. |
| 4951 | */ |
| 4952 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4953 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4954 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4955 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4956 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4957 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4958 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4959 | } |
| 4960 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4961 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4962 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4963 | * @vport: pointer to a host virtual N_Port data structure. |
| 4964 | * |
| 4965 | * This routine handles the Registration State Configuration Notification |
| 4966 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4967 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4968 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4969 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4970 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4971 | * RSCN activities with the @vport. |
| 4972 | * |
| 4973 | * Return code |
| 4974 | * 0 - Cleaned up rscn on the @vport |
| 4975 | * 1 - Wait for plogi to name server before proceed |
| 4976 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4977 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4978 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4979 | { |
| 4980 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4981 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4982 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4983 | /* Ignore RSCN if the port is being torn down. */ |
| 4984 | if (vport->load_flag & FC_UNLOADING) { |
| 4985 | lpfc_els_flush_rscn(vport); |
| 4986 | return 0; |
| 4987 | } |
| 4988 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4989 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4990 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4991 | |
| 4992 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4993 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4994 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4995 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4996 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4997 | |
| 4998 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4999 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5000 | vport->num_disc_nodes = 0; |
| 5001 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5002 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5003 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 5004 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5005 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5006 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5007 | /* Wait for NameServer query cmpl before we can |
| 5008 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5009 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5010 | } else { |
| 5011 | /* If login to NameServer does not exist, issue one */ |
| 5012 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5013 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5014 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5015 | /* Wait for NameServer login cmpl before we can |
| 5016 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5017 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5018 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5019 | if (ndlp) { |
| 5020 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5021 | NLP_STE_PLOGI_ISSUE); |
| 5022 | if (!ndlp) { |
| 5023 | lpfc_els_flush_rscn(vport); |
| 5024 | return 0; |
| 5025 | } |
| 5026 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5027 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5028 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5029 | if (!ndlp) { |
| 5030 | lpfc_els_flush_rscn(vport); |
| 5031 | return 0; |
| 5032 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5033 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5034 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5035 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5036 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5037 | ndlp->nlp_type |= NLP_FABRIC; |
| 5038 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 5039 | /* Wait for NameServer login cmpl before we can |
| 5040 | * continue |
| 5041 | */ |
| 5042 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5043 | } |
| 5044 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5045 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5046 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5047 | } |
| 5048 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5049 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5050 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5051 | * @vport: pointer to a host virtual N_Port data structure. |
| 5052 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5053 | * @ndlp: pointer to a node-list data structure. |
| 5054 | * |
| 5055 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 5056 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 5057 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 5058 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 5059 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 5060 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 5061 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 5062 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 5063 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 5064 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 5065 | * higher priority (as the winning port) and will initiate PLOGI and |
| 5066 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 5067 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 5068 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 5069 | * |
| 5070 | * Return code |
| 5071 | * 0 - Successfully processed the unsolicited flogi |
| 5072 | * 1 - Failed to process the unsolicited flogi |
| 5073 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5074 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5075 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5076 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5077 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5078 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5079 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5080 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5081 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 5082 | IOCB_t *icmd = &cmdiocb->iocb; |
| 5083 | struct serv_parm *sp; |
| 5084 | LPFC_MBOXQ_t *mbox; |
| 5085 | struct ls_rjt stat; |
| 5086 | uint32_t cmd, did; |
| 5087 | int rc; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5088 | uint32_t fc_flag = 0; |
| 5089 | uint32_t port_state = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5090 | |
| 5091 | cmd = *lp++; |
| 5092 | sp = (struct serv_parm *) lp; |
| 5093 | |
| 5094 | /* FLOGI received */ |
| 5095 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5096 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5097 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5098 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5099 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 5100 | did = icmd->un.elsreq64.remoteID; |
| 5101 | |
| 5102 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 5103 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5104 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5105 | "0113 An FLOGI ELS command x%x was " |
| 5106 | "received from DID x%x in Loop Mode\n", |
| 5107 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5108 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5109 | } |
| 5110 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 5111 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5112 | /* For a FLOGI we accept, then if our portname is greater |
| 5113 | * then the remote portname we initiate Nport login. |
| 5114 | */ |
| 5115 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5116 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5117 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5118 | |
| 5119 | if (!rc) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 5120 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5121 | mbox = mempool_alloc(phba->mbox_mem_pool, |
| 5122 | GFP_KERNEL); |
| 5123 | if (!mbox) |
| 5124 | return 1; |
| 5125 | lpfc_linkdown(phba); |
| 5126 | lpfc_init_link(phba, mbox, |
| 5127 | phba->cfg_topology, |
| 5128 | phba->cfg_link_speed); |
| 5129 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 5130 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5131 | mbox->vport = vport; |
| 5132 | rc = lpfc_sli_issue_mbox(phba, mbox, |
| 5133 | MBX_NOWAIT); |
| 5134 | lpfc_set_loopback_flag(phba); |
| 5135 | if (rc == MBX_NOT_FINISHED) |
| 5136 | mempool_free(mbox, phba->mbox_mem_pool); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5137 | return 1; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 5138 | } else { |
| 5139 | /* abort the flogi coming back to ourselves |
| 5140 | * due to external loopback on the port. |
| 5141 | */ |
| 5142 | lpfc_els_abort_flogi(phba); |
| 5143 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5144 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5145 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5146 | spin_lock_irq(shost->host_lock); |
| 5147 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 5148 | spin_unlock_irq(shost->host_lock); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5149 | |
| 5150 | /* If we have the high WWPN we can assign our own |
| 5151 | * myDID; otherwise, we have to WAIT for a PLOGI |
| 5152 | * from the remote NPort to find out what it |
| 5153 | * will be. |
| 5154 | */ |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 5155 | vport->fc_myDID = PT2PT_LocalID; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5156 | } else |
| 5157 | vport->fc_myDID = PT2PT_RemoteID; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5158 | |
| 5159 | /* |
| 5160 | * The vport state should go to LPFC_FLOGI only |
| 5161 | * AFTER we issue a FLOGI, not receive one. |
| 5162 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5163 | spin_lock_irq(shost->host_lock); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5164 | fc_flag = vport->fc_flag; |
| 5165 | port_state = vport->port_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5166 | vport->fc_flag |= FC_PT2PT; |
| 5167 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5168 | vport->port_state = LPFC_FLOGI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5169 | spin_unlock_irq(shost->host_lock); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5170 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5171 | "3311 Rcv Flogi PS x%x new PS x%x " |
| 5172 | "fc_flag x%x new fc_flag x%x\n", |
| 5173 | port_state, vport->port_state, |
| 5174 | fc_flag, vport->fc_flag); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5175 | |
| 5176 | /* |
| 5177 | * We temporarily set fc_myDID to make it look like we are |
| 5178 | * a Fabric. This is done just so we end up with the right |
| 5179 | * did / sid on the FLOGI ACC rsp. |
| 5180 | */ |
| 5181 | did = vport->fc_myDID; |
| 5182 | vport->fc_myDID = Fabric_DID; |
| 5183 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5184 | } else { |
| 5185 | /* Reject this request because invalid parameters */ |
| 5186 | stat.un.b.lsRjtRsvd0 = 0; |
| 5187 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5188 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 5189 | stat.un.b.vendorUnique = 0; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5190 | |
| 5191 | /* |
| 5192 | * We temporarily set fc_myDID to make it look like we are |
| 5193 | * a Fabric. This is done just so we end up with the right |
| 5194 | * did / sid on the FLOGI LS_RJT rsp. |
| 5195 | */ |
| 5196 | did = vport->fc_myDID; |
| 5197 | vport->fc_myDID = Fabric_DID; |
| 5198 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5199 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5200 | NULL); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5201 | |
| 5202 | /* Now lets put fc_myDID back to what its supposed to be */ |
| 5203 | vport->fc_myDID = did; |
| 5204 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5205 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5206 | } |
| 5207 | |
| 5208 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5209 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5210 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5211 | /* Now lets put fc_myDID back to what its supposed to be */ |
| 5212 | vport->fc_myDID = did; |
| 5213 | |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 5214 | if (!(vport->fc_flag & FC_PT2PT_PLOGI)) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5215 | |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 5216 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5217 | if (!mbox) |
| 5218 | goto fail; |
| 5219 | |
| 5220 | lpfc_config_link(phba, mbox); |
| 5221 | |
| 5222 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5223 | mbox->vport = vport; |
| 5224 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5225 | if (rc == MBX_NOT_FINISHED) { |
| 5226 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5227 | goto fail; |
| 5228 | } |
| 5229 | } |
| 5230 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5231 | return 0; |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 5232 | fail: |
| 5233 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5234 | } |
| 5235 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5236 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5237 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5238 | * @vport: pointer to a host virtual N_Port data structure. |
| 5239 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5240 | * @ndlp: pointer to a node-list data structure. |
| 5241 | * |
| 5242 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 5243 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 5244 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 5245 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 5246 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 5247 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 5248 | * |
| 5249 | * Return code |
| 5250 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 5251 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5252 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5253 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5254 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5255 | { |
| 5256 | struct lpfc_dmabuf *pcmd; |
| 5257 | uint32_t *lp; |
| 5258 | IOCB_t *icmd; |
| 5259 | RNID *rn; |
| 5260 | struct ls_rjt stat; |
| 5261 | uint32_t cmd, did; |
| 5262 | |
| 5263 | icmd = &cmdiocb->iocb; |
| 5264 | did = icmd->un.elsreq64.remoteID; |
| 5265 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5266 | lp = (uint32_t *) pcmd->virt; |
| 5267 | |
| 5268 | cmd = *lp++; |
| 5269 | rn = (RNID *) lp; |
| 5270 | |
| 5271 | /* RNID received */ |
| 5272 | |
| 5273 | switch (rn->Format) { |
| 5274 | case 0: |
| 5275 | case RNID_TOPOLOGY_DISC: |
| 5276 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5277 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5278 | break; |
| 5279 | default: |
| 5280 | /* Reject this request because format not supported */ |
| 5281 | stat.un.b.lsRjtRsvd0 = 0; |
| 5282 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5283 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5284 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5285 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5286 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5287 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5288 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5289 | } |
| 5290 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5291 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5292 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 5293 | * @vport: pointer to a host virtual N_Port data structure. |
| 5294 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5295 | * @ndlp: pointer to a node-list data structure. |
| 5296 | * |
| 5297 | * Return code |
| 5298 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 5299 | **/ |
| 5300 | static int |
| 5301 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5302 | struct lpfc_nodelist *ndlp) |
| 5303 | { |
| 5304 | uint8_t *pcmd; |
| 5305 | |
| 5306 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 5307 | |
| 5308 | /* skip over first word of echo command to find echo data */ |
| 5309 | pcmd += sizeof(uint32_t); |
| 5310 | |
| 5311 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 5312 | return 0; |
| 5313 | } |
| 5314 | |
| 5315 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5316 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5317 | * @vport: pointer to a host virtual N_Port data structure. |
| 5318 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5319 | * @ndlp: pointer to a node-list data structure. |
| 5320 | * |
| 5321 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 5322 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 5323 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 5324 | * |
| 5325 | * Return code |
| 5326 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 5327 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5328 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5329 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5330 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5331 | { |
| 5332 | struct ls_rjt stat; |
| 5333 | |
| 5334 | /* For now, unconditionally reject this command */ |
| 5335 | stat.un.b.lsRjtRsvd0 = 0; |
| 5336 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5337 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5338 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5339 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5340 | return 0; |
| 5341 | } |
| 5342 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5343 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5344 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 5345 | * @vport: pointer to a host virtual N_Port data structure. |
| 5346 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5347 | * @ndlp: pointer to a node-list data structure. |
| 5348 | * |
| 5349 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 5350 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 5351 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 5352 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 5353 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 5354 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 5355 | * command request" and reason code explanation "Invalid Originator |
| 5356 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 5357 | * RRQ from the target. |
| 5358 | **/ |
| 5359 | static void |
| 5360 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5361 | struct lpfc_nodelist *ndlp) |
| 5362 | { |
| 5363 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5364 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 5365 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5369 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 5370 | * @phba: pointer to lpfc hba data structure. |
| 5371 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5372 | * |
| 5373 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 5374 | * mailbox command. This callback function is to actually send the Accept |
| 5375 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 5376 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 5377 | * mailbox command, constructs the RPS response with the link statistics |
| 5378 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 5379 | * response to the RPS. |
| 5380 | * |
| 5381 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5382 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5383 | * will be stored into the context1 field of the IOCB for the completion |
| 5384 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5385 | * |
| 5386 | **/ |
| 5387 | static void |
| 5388 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5389 | { |
| 5390 | MAILBOX_t *mb; |
| 5391 | IOCB_t *icmd; |
| 5392 | struct RLS_RSP *rls_rsp; |
| 5393 | uint8_t *pcmd; |
| 5394 | struct lpfc_iocbq *elsiocb; |
| 5395 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5396 | uint16_t oxid; |
| 5397 | uint16_t rxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5398 | uint32_t cmdsize; |
| 5399 | |
| 5400 | mb = &pmb->u.mb; |
| 5401 | |
| 5402 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5403 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 5404 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5405 | pmb->context1 = NULL; |
| 5406 | pmb->context2 = NULL; |
| 5407 | |
| 5408 | if (mb->mbxStatus) { |
| 5409 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5410 | return; |
| 5411 | } |
| 5412 | |
| 5413 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5414 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5415 | lpfc_max_els_tries, ndlp, |
| 5416 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5417 | |
| 5418 | /* Decrement the ndlp reference count from previous mbox command */ |
| 5419 | lpfc_nlp_put(ndlp); |
| 5420 | |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 5421 | if (!elsiocb) { |
| 5422 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5423 | return; |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 5424 | } |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5425 | |
| 5426 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5427 | icmd->ulpContext = rxid; |
| 5428 | icmd->unsli3.rcvsli3.ox_id = oxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5429 | |
| 5430 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5431 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5432 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 5433 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 5434 | |
| 5435 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 5436 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 5437 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 5438 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 5439 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 5440 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 5441 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5442 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 5443 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5444 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 5445 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 5446 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5447 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5448 | ndlp->nlp_rpi); |
| 5449 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5450 | phba->fc_stat.elsXmitACC++; |
| 5451 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 5452 | lpfc_els_free_iocb(phba, elsiocb); |
| 5453 | } |
| 5454 | |
| 5455 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5456 | * 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] | 5457 | * @phba: pointer to lpfc hba data structure. |
| 5458 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5459 | * |
| 5460 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 5461 | * mailbox command. This callback function is to actually send the Accept |
| 5462 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 5463 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 5464 | * mailbox command, constructs the RPS response with the link statistics |
| 5465 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 5466 | * response to the RPS. |
| 5467 | * |
| 5468 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5469 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5470 | * will be stored into the context1 field of the IOCB for the completion |
| 5471 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5472 | * |
| 5473 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5474 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5475 | 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] | 5476 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5477 | MAILBOX_t *mb; |
| 5478 | IOCB_t *icmd; |
| 5479 | RPS_RSP *rps_rsp; |
| 5480 | uint8_t *pcmd; |
| 5481 | struct lpfc_iocbq *elsiocb; |
| 5482 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5483 | uint16_t status; |
| 5484 | uint16_t oxid; |
| 5485 | uint16_t rxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5486 | uint32_t cmdsize; |
| 5487 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5488 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5489 | |
| 5490 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5491 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 5492 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 5493 | pmb->context1 = NULL; |
| 5494 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5495 | |
| 5496 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5497 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5498 | return; |
| 5499 | } |
| 5500 | |
| 5501 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5502 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5503 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5504 | lpfc_max_els_tries, ndlp, |
| 5505 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5506 | |
| 5507 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5508 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5509 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5510 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5511 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5512 | |
| 5513 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5514 | icmd->ulpContext = rxid; |
| 5515 | icmd->unsli3.rcvsli3.ox_id = oxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5516 | |
| 5517 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5518 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5519 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5520 | rps_rsp = (RPS_RSP *)pcmd; |
| 5521 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5522 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5523 | status = 0x10; |
| 5524 | else |
| 5525 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5526 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5527 | status |= 0x4; |
| 5528 | |
| 5529 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5530 | rps_rsp->portStatus = cpu_to_be16(status); |
| 5531 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 5532 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 5533 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 5534 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 5535 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 5536 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5537 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5538 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5539 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 5540 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 5541 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5542 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5543 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5544 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5545 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5546 | 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] | 5547 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5548 | return; |
| 5549 | } |
| 5550 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5551 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5552 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 5553 | * @vport: pointer to a host virtual N_Port data structure. |
| 5554 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5555 | * @ndlp: pointer to a node-list data structure. |
| 5556 | * |
| 5557 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 5558 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5559 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5560 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 5561 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 5562 | * for reading the HBA link statistics. It is for the callback function, |
| 5563 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 5564 | * to actually sending out RPL Accept (ACC) response. |
| 5565 | * |
| 5566 | * Return codes |
| 5567 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 5568 | **/ |
| 5569 | static int |
| 5570 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5571 | struct lpfc_nodelist *ndlp) |
| 5572 | { |
| 5573 | struct lpfc_hba *phba = vport->phba; |
| 5574 | LPFC_MBOXQ_t *mbox; |
| 5575 | struct lpfc_dmabuf *pcmd; |
| 5576 | struct ls_rjt stat; |
| 5577 | |
| 5578 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5579 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5580 | /* reject the unsolicited RPS request and done with it */ |
| 5581 | goto reject_out; |
| 5582 | |
| 5583 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5584 | |
| 5585 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5586 | if (mbox) { |
| 5587 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5588 | mbox->context1 = (void *)((unsigned long) |
| 5589 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 5590 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5591 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5592 | mbox->vport = vport; |
| 5593 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 5594 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 5595 | != MBX_NOT_FINISHED) |
| 5596 | /* Mbox completion will send ELS Response */ |
| 5597 | return 0; |
| 5598 | /* Decrement reference count used for the failed mbox |
| 5599 | * command. |
| 5600 | */ |
| 5601 | lpfc_nlp_put(ndlp); |
| 5602 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5603 | } |
| 5604 | reject_out: |
| 5605 | /* issue rejection response */ |
| 5606 | stat.un.b.lsRjtRsvd0 = 0; |
| 5607 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5608 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5609 | stat.un.b.vendorUnique = 0; |
| 5610 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5611 | return 0; |
| 5612 | } |
| 5613 | |
| 5614 | /** |
| 5615 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 5616 | * @vport: pointer to a host virtual N_Port data structure. |
| 5617 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5618 | * @ndlp: pointer to a node-list data structure. |
| 5619 | * |
| 5620 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 5621 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5622 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5623 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 5624 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 5625 | * Value (RTV) unsolicited IOCB event. |
| 5626 | * |
| 5627 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5628 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5629 | * will be stored into the context1 field of the IOCB for the completion |
| 5630 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5631 | * |
| 5632 | * Return codes |
| 5633 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 5634 | **/ |
| 5635 | static int |
| 5636 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5637 | struct lpfc_nodelist *ndlp) |
| 5638 | { |
| 5639 | struct lpfc_hba *phba = vport->phba; |
| 5640 | struct ls_rjt stat; |
| 5641 | struct RTV_RSP *rtv_rsp; |
| 5642 | uint8_t *pcmd; |
| 5643 | struct lpfc_iocbq *elsiocb; |
| 5644 | uint32_t cmdsize; |
| 5645 | |
| 5646 | |
| 5647 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5648 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5649 | /* reject the unsolicited RPS request and done with it */ |
| 5650 | goto reject_out; |
| 5651 | |
| 5652 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 5653 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5654 | lpfc_max_els_tries, ndlp, |
| 5655 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5656 | |
| 5657 | if (!elsiocb) |
| 5658 | return 1; |
| 5659 | |
| 5660 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5661 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5662 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 5663 | |
| 5664 | /* use the command's xri in the response */ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5665 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 5666 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5667 | |
| 5668 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 5669 | |
| 5670 | /* populate RTV payload */ |
| 5671 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 5672 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 5673 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 5674 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 5675 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 5676 | |
| 5677 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 5678 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5679 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 5680 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 5681 | "Data: x%x x%x x%x\n", |
| 5682 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5683 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5684 | ndlp->nlp_rpi, |
| 5685 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 5686 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5687 | phba->fc_stat.elsXmitACC++; |
| 5688 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 5689 | lpfc_els_free_iocb(phba, elsiocb); |
| 5690 | return 0; |
| 5691 | |
| 5692 | reject_out: |
| 5693 | /* issue rejection response */ |
| 5694 | stat.un.b.lsRjtRsvd0 = 0; |
| 5695 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5696 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5697 | stat.un.b.vendorUnique = 0; |
| 5698 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5699 | return 0; |
| 5700 | } |
| 5701 | |
| 5702 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5703 | * @vport: pointer to a host virtual N_Port data structure. |
| 5704 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5705 | * @ndlp: pointer to a node-list data structure. |
| 5706 | * |
| 5707 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 5708 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5709 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5710 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 5711 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 5712 | * for reading the HBA link statistics. It is for the callback function, |
| 5713 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 5714 | * to actually sending out RPS Accept (ACC) response. |
| 5715 | * |
| 5716 | * Return codes |
| 5717 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 5718 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5719 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5720 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5721 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5722 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5723 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5724 | uint32_t *lp; |
| 5725 | uint8_t flag; |
| 5726 | LPFC_MBOXQ_t *mbox; |
| 5727 | struct lpfc_dmabuf *pcmd; |
| 5728 | RPS *rps; |
| 5729 | struct ls_rjt stat; |
| 5730 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5731 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5732 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5733 | /* reject the unsolicited RPS request and done with it */ |
| 5734 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5735 | |
| 5736 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5737 | lp = (uint32_t *) pcmd->virt; |
| 5738 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 5739 | rps = (RPS *) lp; |
| 5740 | |
| 5741 | if ((flag == 0) || |
| 5742 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5743 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5744 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5745 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5746 | printk("Fix me....\n"); |
| 5747 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5748 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5749 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5750 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5751 | mbox->context1 = (void *)((unsigned long) |
| 5752 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 5753 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5754 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5755 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5756 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5757 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5758 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5759 | /* Mbox completion will send ELS Response */ |
| 5760 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5761 | /* Decrement reference count used for the failed mbox |
| 5762 | * command. |
| 5763 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5764 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5765 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5766 | } |
| 5767 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5768 | |
| 5769 | reject_out: |
| 5770 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5771 | stat.un.b.lsRjtRsvd0 = 0; |
| 5772 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5773 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5774 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5775 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5776 | return 0; |
| 5777 | } |
| 5778 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5779 | /* lpfc_issue_els_rrq - Process an unsolicited rps iocb |
| 5780 | * @vport: pointer to a host virtual N_Port data structure. |
| 5781 | * @ndlp: pointer to a node-list data structure. |
| 5782 | * @did: DID of the target. |
| 5783 | * @rrq: Pointer to the rrq struct. |
| 5784 | * |
| 5785 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is |
| 5786 | * Successful the the completion handler will clear the RRQ. |
| 5787 | * |
| 5788 | * Return codes |
| 5789 | * 0 - Successfully sent rrq els iocb. |
| 5790 | * 1 - Failed to send rrq els iocb. |
| 5791 | **/ |
| 5792 | static int |
| 5793 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5794 | uint32_t did, struct lpfc_node_rrq *rrq) |
| 5795 | { |
| 5796 | struct lpfc_hba *phba = vport->phba; |
| 5797 | struct RRQ *els_rrq; |
| 5798 | IOCB_t *icmd; |
| 5799 | struct lpfc_iocbq *elsiocb; |
| 5800 | uint8_t *pcmd; |
| 5801 | uint16_t cmdsize; |
| 5802 | int ret; |
| 5803 | |
| 5804 | |
| 5805 | if (ndlp != rrq->ndlp) |
| 5806 | ndlp = rrq->ndlp; |
| 5807 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5808 | return 1; |
| 5809 | |
| 5810 | /* If ndlp is not NULL, we will bump the reference count on it */ |
| 5811 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); |
| 5812 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, |
| 5813 | ELS_CMD_RRQ); |
| 5814 | if (!elsiocb) |
| 5815 | return 1; |
| 5816 | |
| 5817 | icmd = &elsiocb->iocb; |
| 5818 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5819 | |
| 5820 | /* For RRQ request, remainder of payload is Exchange IDs */ |
| 5821 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; |
| 5822 | pcmd += sizeof(uint32_t); |
| 5823 | els_rrq = (struct RRQ *) pcmd; |
| 5824 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 5825 | 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] | 5826 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
| 5827 | bf_set(rrq_did, els_rrq, vport->fc_myDID); |
| 5828 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); |
| 5829 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); |
| 5830 | |
| 5831 | |
| 5832 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5833 | "Issue RRQ: did:x%x", |
| 5834 | did, rrq->xritag, rrq->rxid); |
| 5835 | elsiocb->context_un.rrq = rrq; |
| 5836 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; |
| 5837 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5838 | |
| 5839 | if (ret == IOCB_ERROR) { |
| 5840 | lpfc_els_free_iocb(phba, elsiocb); |
| 5841 | return 1; |
| 5842 | } |
| 5843 | return 0; |
| 5844 | } |
| 5845 | |
| 5846 | /** |
| 5847 | * lpfc_send_rrq - Sends ELS RRQ if needed. |
| 5848 | * @phba: pointer to lpfc hba data structure. |
| 5849 | * @rrq: pointer to the active rrq. |
| 5850 | * |
| 5851 | * This routine will call the lpfc_issue_els_rrq if the rrq is |
| 5852 | * still active for the xri. If this function returns a failure then |
| 5853 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. |
| 5854 | * |
| 5855 | * Returns 0 Success. |
| 5856 | * 1 Failure. |
| 5857 | **/ |
| 5858 | int |
| 5859 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) |
| 5860 | { |
| 5861 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, |
| 5862 | rrq->nlp_DID); |
| 5863 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) |
| 5864 | return lpfc_issue_els_rrq(rrq->vport, ndlp, |
| 5865 | rrq->nlp_DID, rrq); |
| 5866 | else |
| 5867 | return 1; |
| 5868 | } |
| 5869 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5870 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5871 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5872 | * @vport: pointer to a host virtual N_Port data structure. |
| 5873 | * @cmdsize: size of the ELS command. |
| 5874 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5875 | * @ndlp: pointer to a node-list data structure. |
| 5876 | * |
| 5877 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 5878 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 5879 | * |
| 5880 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5881 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5882 | * will be stored into the context1 field of the IOCB for the completion |
| 5883 | * callback function to the RPL Accept Response ELS command. |
| 5884 | * |
| 5885 | * Return code |
| 5886 | * 0 - Successfully issued ACC RPL ELS command |
| 5887 | * 1 - Failed to issue ACC RPL ELS command |
| 5888 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5889 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5890 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 5891 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5892 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5893 | struct lpfc_hba *phba = vport->phba; |
| 5894 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5895 | RPL_RSP rpl_rsp; |
| 5896 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5897 | uint8_t *pcmd; |
| 5898 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5899 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5900 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5901 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5902 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5903 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5904 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5905 | icmd = &elsiocb->iocb; |
| 5906 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5907 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 5908 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5909 | |
| 5910 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5911 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5912 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5913 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 5914 | pcmd += sizeof(uint16_t); |
| 5915 | |
| 5916 | /* Setup the RPL ACC payload */ |
| 5917 | rpl_rsp.listLen = be32_to_cpu(1); |
| 5918 | rpl_rsp.index = 0; |
| 5919 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5920 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 5921 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5922 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5923 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5924 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5925 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5926 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 5927 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 5928 | "rpi x%x\n", |
| 5929 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5930 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5931 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5932 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5933 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5934 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 5935 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5936 | lpfc_els_free_iocb(phba, elsiocb); |
| 5937 | return 1; |
| 5938 | } |
| 5939 | return 0; |
| 5940 | } |
| 5941 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5942 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5943 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5944 | * @vport: pointer to a host virtual N_Port data structure. |
| 5945 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5946 | * @ndlp: pointer to a node-list data structure. |
| 5947 | * |
| 5948 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 5949 | * unsolicited event. It first checks the remote port state. If the remote |
| 5950 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 5951 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 5952 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 5953 | * to accept the RPL. |
| 5954 | * |
| 5955 | * Return code |
| 5956 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 5957 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5958 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5959 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5960 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5961 | { |
| 5962 | struct lpfc_dmabuf *pcmd; |
| 5963 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5964 | uint32_t maxsize; |
| 5965 | uint16_t cmdsize; |
| 5966 | RPL *rpl; |
| 5967 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5968 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5969 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5970 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5971 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5972 | stat.un.b.lsRjtRsvd0 = 0; |
| 5973 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5974 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5975 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5976 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5977 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5978 | /* rejected the unsolicited RPL request and done with it */ |
| 5979 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5980 | } |
| 5981 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5982 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5983 | lp = (uint32_t *) pcmd->virt; |
| 5984 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5985 | maxsize = be32_to_cpu(rpl->maxsize); |
| 5986 | |
| 5987 | /* We support only one port */ |
| 5988 | if ((rpl->index == 0) && |
| 5989 | ((maxsize == 0) || |
| 5990 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 5991 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5992 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5993 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 5994 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5995 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5996 | |
| 5997 | return 0; |
| 5998 | } |
| 5999 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6000 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6001 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6002 | * @vport: pointer to a virtual N_Port data structure. |
| 6003 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6004 | * @ndlp: pointer to a node-list data structure. |
| 6005 | * |
| 6006 | * This routine processes Fibre Channel Address Resolution Protocol |
| 6007 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 6008 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 6009 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 6010 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 6011 | * remote PortName is compared against the FC PortName stored in the @vport |
| 6012 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 6013 | * compared against the FC NodeName stored in the @vport data structure. |
| 6014 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 6015 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 6016 | * invoked to send out FARP Response to the remote node. Before sending the |
| 6017 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 6018 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 6019 | * routine is invoked to log into the remote port first. |
| 6020 | * |
| 6021 | * Return code |
| 6022 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 6023 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6024 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6025 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6026 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6027 | { |
| 6028 | struct lpfc_dmabuf *pcmd; |
| 6029 | uint32_t *lp; |
| 6030 | IOCB_t *icmd; |
| 6031 | FARP *fp; |
| 6032 | uint32_t cmd, cnt, did; |
| 6033 | |
| 6034 | icmd = &cmdiocb->iocb; |
| 6035 | did = icmd->un.elsreq64.remoteID; |
| 6036 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6037 | lp = (uint32_t *) pcmd->virt; |
| 6038 | |
| 6039 | cmd = *lp++; |
| 6040 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6041 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6042 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6043 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6044 | /* We will only support match on WWPN or WWNN */ |
| 6045 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6046 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6047 | } |
| 6048 | |
| 6049 | cnt = 0; |
| 6050 | /* If this FARP command is searching for my portname */ |
| 6051 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6052 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6053 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6054 | cnt = 1; |
| 6055 | } |
| 6056 | |
| 6057 | /* If this FARP command is searching for my nodename */ |
| 6058 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6059 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6060 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6061 | cnt = 1; |
| 6062 | } |
| 6063 | |
| 6064 | if (cnt) { |
| 6065 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 6066 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 6067 | /* Log back into the node before sending the FARP. */ |
| 6068 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6069 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6070 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 6071 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6072 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6073 | } |
| 6074 | |
| 6075 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6076 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 6077 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6078 | } |
| 6079 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6080 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6081 | } |
| 6082 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6083 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6084 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6085 | * @vport: pointer to a host virtual N_Port data structure. |
| 6086 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6087 | * @ndlp: pointer to a node-list data structure. |
| 6088 | * |
| 6089 | * This routine processes Fibre Channel Address Resolution Protocol |
| 6090 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 6091 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 6092 | * the FARP response request. |
| 6093 | * |
| 6094 | * Return code |
| 6095 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 6096 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6097 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6098 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6099 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6100 | { |
| 6101 | struct lpfc_dmabuf *pcmd; |
| 6102 | uint32_t *lp; |
| 6103 | IOCB_t *icmd; |
| 6104 | uint32_t cmd, did; |
| 6105 | |
| 6106 | icmd = &cmdiocb->iocb; |
| 6107 | did = icmd->un.elsreq64.remoteID; |
| 6108 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6109 | lp = (uint32_t *) pcmd->virt; |
| 6110 | |
| 6111 | cmd = *lp++; |
| 6112 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6113 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6114 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6115 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6116 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6117 | |
| 6118 | return 0; |
| 6119 | } |
| 6120 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6121 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6122 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6123 | * @vport: pointer to a host virtual N_Port data structure. |
| 6124 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6125 | * @fan_ndlp: pointer to a node-list data structure. |
| 6126 | * |
| 6127 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 6128 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 6129 | * only be processed on a physical port (i.e., the @vport represents the |
| 6130 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 6131 | * compared against those in the phba data structure. If any of those is |
| 6132 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 6133 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 6134 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 6135 | * is invoked to register login to the fabric. |
| 6136 | * |
| 6137 | * Return code |
| 6138 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 6139 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6140 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6141 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6142 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6143 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6144 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6145 | uint32_t *lp; |
| 6146 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6147 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6148 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 6149 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 6150 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6151 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6152 | if ((vport == phba->pport) && |
| 6153 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6154 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6155 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 6156 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6157 | sizeof(struct lpfc_name)))) { |
| 6158 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6159 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6160 | } else { |
| 6161 | /* FAN verified - skip FLOGI */ |
| 6162 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6163 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6164 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6165 | else { |
| 6166 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6167 | "3138 Need register VFI: (x%x/%x)\n", |
| 6168 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6169 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6170 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6171 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6172 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6173 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6174 | } |
| 6175 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6176 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6177 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6178 | * @ptr: holder for the timer function associated data. |
| 6179 | * |
| 6180 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 6181 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 6182 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 6183 | * up the worker thread. It is for the worker thread to invoke the routine |
| 6184 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 6185 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6186 | void |
| 6187 | lpfc_els_timeout(unsigned long ptr) |
| 6188 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6189 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 6190 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6191 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6192 | unsigned long iflag; |
| 6193 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6194 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6195 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 6196 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6197 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6198 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6199 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6200 | if (!tmo_posted) |
| 6201 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6202 | return; |
| 6203 | } |
| 6204 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6205 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6206 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6207 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6208 | * @vport: pointer to a virtual N_Port data structure. |
| 6209 | * |
| 6210 | * This routine is the actual handler function that processes an ELS timeout |
| 6211 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 6212 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 6213 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 6214 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6215 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6216 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6217 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6218 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6219 | struct lpfc_sli_ring *pring; |
| 6220 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6221 | IOCB_t *cmd = NULL; |
| 6222 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6223 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6224 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6225 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6226 | LIST_HEAD(txcmplq_completions); |
| 6227 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6228 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6229 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6230 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 6231 | |
| 6232 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6233 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6234 | spin_lock_irq(&phba->hbalock); |
| 6235 | list_splice_init(&pring->txcmplq, &txcmplq_completions); |
| 6236 | spin_unlock_irq(&phba->hbalock); |
| 6237 | |
| 6238 | list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6239 | cmd = &piocb->iocb; |
| 6240 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6241 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 6242 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 6243 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6244 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6245 | |
| 6246 | if (piocb->vport != vport) |
| 6247 | continue; |
| 6248 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6249 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6250 | if (pcmd) |
| 6251 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6252 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6253 | if (els_command == ELS_CMD_FARP || |
| 6254 | els_command == ELS_CMD_FARPR || |
| 6255 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6256 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6258 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6259 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6260 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6261 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6262 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6263 | continue; |
| 6264 | } |
| 6265 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6266 | remote_ID = 0xffffffff; |
| 6267 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6268 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6269 | else { |
| 6270 | struct lpfc_nodelist *ndlp; |
| 6271 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6272 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6273 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6274 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6275 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6276 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6277 | spin_lock_irq(&phba->hbalock); |
| 6278 | list_splice(&txcmplq_completions, &pring->txcmplq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6279 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 6280 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6281 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 6282 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6283 | "0127 ELS timeout Data: x%x x%x x%x " |
| 6284 | "x%x\n", els_command, |
| 6285 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 6286 | spin_lock_irq(&phba->hbalock); |
| 6287 | list_del_init(&piocb->dlist); |
| 6288 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 6289 | spin_unlock_irq(&phba->hbalock); |
| 6290 | } |
| 6291 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 6292 | if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq)) |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6293 | mod_timer(&vport->els_tmofunc, |
| 6294 | jiffies + msecs_to_jiffies(1000 * timeout)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6295 | } |
| 6296 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6297 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6298 | * 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] | 6299 | * @vport: pointer to a host virtual N_Port data structure. |
| 6300 | * |
| 6301 | * This routine is used to clean up all the outstanding ELS commands on a |
| 6302 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 6303 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 6304 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 6305 | * the IOCBs with a non-NULL completion callback function, the callback |
| 6306 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 6307 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 6308 | * callback function, the IOCB will simply be released. Finally, it walks |
| 6309 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 6310 | * completion queue IOCB that is associated with the @vport and is not |
| 6311 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 6312 | * part of the discovery state machine) out to HBA by invoking the |
| 6313 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 6314 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 6315 | * the IOCBs are aborted when this function returns. |
| 6316 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6317 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6318 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6319 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 6320 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6321 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6322 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6323 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6324 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6325 | |
| 6326 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6327 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6328 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6329 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 6330 | cmd = &piocb->iocb; |
| 6331 | |
| 6332 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 6333 | continue; |
| 6334 | } |
| 6335 | |
| 6336 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6337 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 6338 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 6339 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 6340 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6341 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6342 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6343 | if (piocb->vport != vport) |
| 6344 | continue; |
| 6345 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 6346 | list_move_tail(&piocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6347 | } |
| 6348 | |
| 6349 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6350 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 6351 | continue; |
| 6352 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6353 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6354 | if (piocb->vport != vport) |
| 6355 | continue; |
| 6356 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 6357 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6358 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6359 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 6360 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6361 | /* Cancell all the IOCBs from the completions list */ |
| 6362 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6363 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 6364 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6365 | return; |
| 6366 | } |
| 6367 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6368 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6369 | * 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] | 6370 | * @phba: pointer to lpfc hba data structure. |
| 6371 | * |
| 6372 | * This routine is used to clean up all the outstanding ELS commands on a |
| 6373 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 6374 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 6375 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 6376 | * the IOCBs with the completion callback function associated, the callback |
| 6377 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 6378 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 6379 | * callback function associated, the IOCB will simply be released. Finally, |
| 6380 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 6381 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 6382 | * management plane IOCBs that are not part of the discovery state machine) |
| 6383 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 6384 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6385 | void |
| 6386 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 6387 | { |
| 6388 | LIST_HEAD(completions); |
| 6389 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6390 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6391 | IOCB_t *cmd = NULL; |
| 6392 | |
| 6393 | lpfc_fabric_abort_hba(phba); |
| 6394 | spin_lock_irq(&phba->hbalock); |
| 6395 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 6396 | cmd = &piocb->iocb; |
| 6397 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 6398 | continue; |
| 6399 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 6400 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 6401 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 6402 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 6403 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 6404 | continue; |
| 6405 | list_move_tail(&piocb->list, &completions); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6406 | } |
| 6407 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 6408 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 6409 | continue; |
| 6410 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 6411 | } |
| 6412 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6413 | |
| 6414 | /* Cancel all the IOCBs from the completions list */ |
| 6415 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6416 | IOERR_SLI_ABORTED); |
| 6417 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6418 | return; |
| 6419 | } |
| 6420 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6421 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6422 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6423 | * @phba: Pointer to hba context object. |
| 6424 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 6425 | * @rspiocbp: Pointer to response iocb which reported error. |
| 6426 | * |
| 6427 | * This function sends an event when there is an ELS command |
| 6428 | * failure. |
| 6429 | **/ |
| 6430 | void |
| 6431 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 6432 | struct lpfc_iocbq *cmdiocbp, |
| 6433 | struct lpfc_iocbq *rspiocbp) |
| 6434 | { |
| 6435 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 6436 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6437 | struct lpfc_lsrjt_event lsrjt_event; |
| 6438 | struct lpfc_fabric_event_header fabric_event; |
| 6439 | struct ls_rjt stat; |
| 6440 | struct lpfc_nodelist *ndlp; |
| 6441 | uint32_t *pcmd; |
| 6442 | |
| 6443 | ndlp = cmdiocbp->context1; |
| 6444 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 6445 | return; |
| 6446 | |
| 6447 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 6448 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 6449 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 6450 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 6451 | sizeof(struct lpfc_name)); |
| 6452 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 6453 | sizeof(struct lpfc_name)); |
| 6454 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 6455 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6456 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6457 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 6458 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 6459 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 6460 | fc_host_post_vendor_event(shost, |
| 6461 | fc_get_event_number(), |
| 6462 | sizeof(lsrjt_event), |
| 6463 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6464 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6465 | return; |
| 6466 | } |
| 6467 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 6468 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 6469 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 6470 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 6471 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 6472 | else |
| 6473 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 6474 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 6475 | sizeof(struct lpfc_name)); |
| 6476 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 6477 | sizeof(struct lpfc_name)); |
| 6478 | fc_host_post_vendor_event(shost, |
| 6479 | fc_get_event_number(), |
| 6480 | sizeof(fabric_event), |
| 6481 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6482 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6483 | return; |
| 6484 | } |
| 6485 | |
| 6486 | } |
| 6487 | |
| 6488 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6489 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6490 | * @vport: Pointer to vport object. |
| 6491 | * @ndlp: Pointer FC node object. |
| 6492 | * @cmd: ELS command code. |
| 6493 | * |
| 6494 | * This function posts an event when there is an incoming |
| 6495 | * unsolicited ELS command. |
| 6496 | **/ |
| 6497 | static void |
| 6498 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 6499 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6500 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6501 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6502 | struct lpfc_els_event_header *els_data = NULL; |
| 6503 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6504 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6505 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6506 | if (*payload == ELS_CMD_LOGO) { |
| 6507 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 6508 | if (!logo_data) { |
| 6509 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6510 | "0148 Failed to allocate memory " |
| 6511 | "for LOGO event\n"); |
| 6512 | return; |
| 6513 | } |
| 6514 | els_data = &logo_data->header; |
| 6515 | } else { |
| 6516 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 6517 | GFP_KERNEL); |
| 6518 | if (!els_data) { |
| 6519 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6520 | "0149 Failed to allocate memory " |
| 6521 | "for ELS event\n"); |
| 6522 | return; |
| 6523 | } |
| 6524 | } |
| 6525 | els_data->event_type = FC_REG_ELS_EVENT; |
| 6526 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6527 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6528 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6529 | break; |
| 6530 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6531 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6532 | break; |
| 6533 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6534 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 6535 | break; |
| 6536 | case ELS_CMD_LOGO: |
| 6537 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 6538 | /* Copy the WWPN in the LOGO payload */ |
| 6539 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 6540 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6541 | break; |
| 6542 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 6543 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6544 | return; |
| 6545 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6546 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 6547 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 6548 | if (*payload == ELS_CMD_LOGO) { |
| 6549 | fc_host_post_vendor_event(shost, |
| 6550 | fc_get_event_number(), |
| 6551 | sizeof(struct lpfc_logo_event), |
| 6552 | (char *)logo_data, |
| 6553 | LPFC_NL_VENDOR_ID); |
| 6554 | kfree(logo_data); |
| 6555 | } else { |
| 6556 | fc_host_post_vendor_event(shost, |
| 6557 | fc_get_event_number(), |
| 6558 | sizeof(struct lpfc_els_event_header), |
| 6559 | (char *)els_data, |
| 6560 | LPFC_NL_VENDOR_ID); |
| 6561 | kfree(els_data); |
| 6562 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6563 | |
| 6564 | return; |
| 6565 | } |
| 6566 | |
| 6567 | |
| 6568 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6569 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6570 | * @phba: pointer to lpfc hba data structure. |
| 6571 | * @pring: pointer to a SLI ring. |
| 6572 | * @vport: pointer to a host virtual N_Port data structure. |
| 6573 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 6574 | * |
| 6575 | * This routine is used for processing the IOCB associated with a unsolicited |
| 6576 | * event. It first determines whether there is an existing ndlp that matches |
| 6577 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 6578 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 6579 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 6580 | * of the discovery state machine. |
| 6581 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6582 | static void |
| 6583 | 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] | 6584 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6585 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6586 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6587 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6588 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6589 | uint32_t *payload; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 6590 | uint32_t cmd, did, newnode; |
| 6591 | uint8_t rjt_exp, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6592 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6593 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6594 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6595 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6596 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6597 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6598 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 6599 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6600 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6601 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6602 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6603 | did = icmd->un.rcvels.remoteID; |
| 6604 | if (icmd->ulpStatus) { |
| 6605 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6606 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 6607 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6608 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6609 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6610 | |
| 6611 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6612 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6613 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6614 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 6615 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6616 | if (vport->load_flag & FC_UNLOADING) |
| 6617 | goto dropit; |
| 6618 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 6619 | /* If NPort discovery is delayed drop incoming ELS */ |
| 6620 | if ((vport->fc_flag & FC_DISC_DELAYED) && |
| 6621 | (cmd != ELS_CMD_PLOGI)) |
| 6622 | goto dropit; |
| 6623 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6624 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6625 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6626 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6627 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6628 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6629 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6630 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6631 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6632 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6633 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6634 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6635 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6636 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 6637 | ndlp = lpfc_enable_node(vport, ndlp, |
| 6638 | NLP_STE_UNUSED_NODE); |
| 6639 | if (!ndlp) |
| 6640 | goto dropit; |
| 6641 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 6642 | newnode = 1; |
| 6643 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 6644 | ndlp->nlp_type |= NLP_FABRIC; |
| 6645 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 6646 | /* This is similar to the new node path */ |
| 6647 | ndlp = lpfc_nlp_get(ndlp); |
| 6648 | if (!ndlp) |
| 6649 | goto dropit; |
| 6650 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 6651 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6652 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6653 | |
| 6654 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6655 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6656 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6657 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6658 | |
| 6659 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 6660 | cmd &= ELS_CMD_MASK; |
| 6661 | } |
| 6662 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6663 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6664 | "0112 ELS command x%x received from NPORT x%x " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6665 | "Data: x%x x%x x%x x%x\n", |
| 6666 | cmd, did, vport->port_state, vport->fc_flag, |
| 6667 | vport->fc_myDID, vport->fc_prevDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6668 | switch (cmd) { |
| 6669 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6670 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6671 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 6672 | did, vport->port_state, ndlp->nlp_flag); |
| 6673 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6674 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6675 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6676 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 6677 | (phba->pport->fc_flag & FC_PT2PT)) { |
| 6678 | vport->fc_prevDID = vport->fc_myDID; |
| 6679 | /* Our DID needs to be updated before registering |
| 6680 | * the vfi. This is done in lpfc_rcv_plogi but |
| 6681 | * that is called after the reg_vfi. |
| 6682 | */ |
| 6683 | vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo; |
| 6684 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6685 | "3312 Remote port assigned DID x%x " |
| 6686 | "%x\n", vport->fc_myDID, |
| 6687 | vport->fc_prevDID); |
| 6688 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6689 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6690 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 6691 | |
| 6692 | /* If Nport discovery is delayed, reject PLOGIs */ |
| 6693 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 6694 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 6695 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 6696 | break; |
| 6697 | } |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6698 | shost = lpfc_shost_from_vport(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6699 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 6700 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 6701 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 6702 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 6703 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 6704 | break; |
| 6705 | } |
| 6706 | /* We get here, and drop thru, if we are PT2PT with |
| 6707 | * another NPort and the other side has initiated |
| 6708 | * the PLOGI before responding to our FLOGI. |
| 6709 | */ |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6710 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 6711 | (phba->fc_topology_changed || |
| 6712 | vport->fc_myDID != vport->fc_prevDID)) { |
| 6713 | lpfc_unregister_fcf_prep(phba); |
| 6714 | spin_lock_irq(shost->host_lock); |
| 6715 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 6716 | spin_unlock_irq(shost->host_lock); |
| 6717 | phba->fc_topology_changed = 0; |
| 6718 | lpfc_issue_reg_vfi(vport); |
| 6719 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6720 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6721 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6722 | spin_lock_irq(shost->host_lock); |
| 6723 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 6724 | spin_unlock_irq(shost->host_lock); |
| 6725 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6726 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6727 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6728 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6729 | break; |
| 6730 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6731 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6732 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 6733 | did, vport->port_state, ndlp->nlp_flag); |
| 6734 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6735 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6736 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6737 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6738 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6739 | break; |
| 6740 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6741 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6742 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 6743 | did, vport->port_state, ndlp->nlp_flag); |
| 6744 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6745 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6746 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6747 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6748 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 6749 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6750 | break; |
| 6751 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6752 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6753 | break; |
| 6754 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6755 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6756 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 6757 | did, vport->port_state, ndlp->nlp_flag); |
| 6758 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6759 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6760 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6761 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6762 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 6763 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6764 | break; |
| 6765 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6766 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6767 | break; |
| 6768 | case ELS_CMD_RSCN: |
| 6769 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6770 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6771 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6772 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6773 | break; |
| 6774 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6775 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6776 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 6777 | did, vport->port_state, ndlp->nlp_flag); |
| 6778 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6779 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6780 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6781 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6782 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 6783 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6784 | break; |
| 6785 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6786 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6787 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6788 | break; |
| 6789 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6790 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6791 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 6792 | did, vport->port_state, ndlp->nlp_flag); |
| 6793 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6794 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6795 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6796 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 6797 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6798 | break; |
| 6799 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6800 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6801 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6802 | break; |
| 6803 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6804 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6805 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 6806 | did, vport->port_state, ndlp->nlp_flag); |
| 6807 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6808 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6809 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6810 | break; |
| 6811 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6812 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6813 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 6814 | did, vport->port_state, ndlp->nlp_flag); |
| 6815 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6816 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6817 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6818 | break; |
| 6819 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6820 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6821 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 6822 | did, vport->port_state, ndlp->nlp_flag); |
| 6823 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6824 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6825 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6826 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6827 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6828 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6829 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 6830 | did, vport->port_state, ndlp->nlp_flag); |
| 6831 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6832 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6833 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6834 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 6835 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6836 | break; |
| 6837 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6838 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6839 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6840 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6841 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6842 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 6843 | did, vport->port_state, ndlp->nlp_flag); |
| 6844 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6845 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6846 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6847 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6848 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6849 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6850 | case ELS_CMD_RLS: |
| 6851 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6852 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 6853 | did, vport->port_state, ndlp->nlp_flag); |
| 6854 | |
| 6855 | phba->fc_stat.elsRcvRLS++; |
| 6856 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 6857 | if (newnode) |
| 6858 | lpfc_nlp_put(ndlp); |
| 6859 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6860 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6861 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6862 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 6863 | did, vport->port_state, ndlp->nlp_flag); |
| 6864 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6865 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6866 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6867 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6868 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6869 | break; |
| 6870 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6871 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6872 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 6873 | did, vport->port_state, ndlp->nlp_flag); |
| 6874 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6875 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6876 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6877 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6878 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6879 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6880 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6881 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6882 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 6883 | did, vport->port_state, ndlp->nlp_flag); |
| 6884 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6885 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6886 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6887 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6888 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6889 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6890 | case ELS_CMD_RTV: |
| 6891 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6892 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 6893 | did, vport->port_state, ndlp->nlp_flag); |
| 6894 | phba->fc_stat.elsRcvRTV++; |
| 6895 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 6896 | if (newnode) |
| 6897 | lpfc_nlp_put(ndlp); |
| 6898 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6899 | case ELS_CMD_RRQ: |
| 6900 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6901 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 6902 | did, vport->port_state, ndlp->nlp_flag); |
| 6903 | |
| 6904 | phba->fc_stat.elsRcvRRQ++; |
| 6905 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 6906 | if (newnode) |
| 6907 | lpfc_nlp_put(ndlp); |
| 6908 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6909 | case ELS_CMD_ECHO: |
| 6910 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6911 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 6912 | did, vport->port_state, ndlp->nlp_flag); |
| 6913 | |
| 6914 | phba->fc_stat.elsRcvECHO++; |
| 6915 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 6916 | if (newnode) |
| 6917 | lpfc_nlp_put(ndlp); |
| 6918 | break; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 6919 | case ELS_CMD_REC: |
| 6920 | /* receive this due to exchange closed */ |
| 6921 | rjt_err = LSRJT_UNABLE_TPC; |
| 6922 | rjt_exp = LSEXP_INVALID_OX_RX; |
| 6923 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6924 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6925 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6926 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 6927 | cmd, did, vport->port_state); |
| 6928 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6929 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6930 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 6931 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6932 | |
| 6933 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6934 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6935 | "0115 Unknown ELS command x%x " |
| 6936 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6937 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6938 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6939 | break; |
| 6940 | } |
| 6941 | |
| 6942 | /* check if need to LS_RJT received ELS cmd */ |
| 6943 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6944 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6945 | stat.un.b.lsRjtRsnCode = rjt_err; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 6946 | stat.un.b.lsRjtRsnCodeExp = rjt_exp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6947 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 6948 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6949 | } |
| 6950 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6951 | lpfc_nlp_put(elsiocb->context1); |
| 6952 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6953 | return; |
| 6954 | |
| 6955 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6956 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6957 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6958 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6959 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6960 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6961 | phba->fc_stat.elsRcvDrop++; |
| 6962 | } |
| 6963 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6964 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6965 | * 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] | 6966 | * @phba: pointer to lpfc hba data structure. |
| 6967 | * @pring: pointer to a SLI ring. |
| 6968 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 6969 | * |
| 6970 | * This routine is used to process an unsolicited event received from a SLI |
| 6971 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 6972 | * associated with the unsolicited event is done by invoking the routine |
| 6973 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 6974 | * SLI ring on which the unsolicited event was received. |
| 6975 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6976 | void |
| 6977 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 6978 | struct lpfc_iocbq *elsiocb) |
| 6979 | { |
| 6980 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6981 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6982 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6983 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 6984 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6985 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6986 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6987 | elsiocb->context2 = NULL; |
| 6988 | elsiocb->context3 = NULL; |
| 6989 | |
| 6990 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 6991 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 6992 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 6993 | (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 6994 | IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6995 | phba->fc_stat.NoRcvBuf++; |
| 6996 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6997 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6998 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6999 | return; |
| 7000 | } |
| 7001 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7002 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 7003 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 7004 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 7005 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 7006 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7007 | else |
| 7008 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7009 | icmd->unsli3.rcvsli3.vpi); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7010 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7011 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7012 | /* If there are no BDEs associated |
| 7013 | * with this IOCB, there is nothing to do. |
| 7014 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7015 | if (icmd->ulpBdeCount == 0) |
| 7016 | return; |
| 7017 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7018 | /* type of ELS cmd is first 32bit word |
| 7019 | * in packet |
| 7020 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7021 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7022 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7023 | } else { |
| 7024 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 7025 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7026 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 7027 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7028 | } |
| 7029 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7030 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 7031 | /* |
| 7032 | * The different unsolicited event handlers would tell us |
| 7033 | * if they are done with "mp" by setting context2 to NULL. |
| 7034 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7035 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7036 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 7037 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7038 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7039 | |
| 7040 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7041 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7042 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7043 | elsiocb->context2 = bdeBuf2; |
| 7044 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7045 | /* free mp if we are done with it */ |
| 7046 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7047 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 7048 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7049 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7050 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7051 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7052 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7053 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7054 | * 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] | 7055 | * @phba: pointer to lpfc hba data structure. |
| 7056 | * @vport: pointer to a virtual N_Port data structure. |
| 7057 | * |
| 7058 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 7059 | * State Change Request (SCR) for a @vport. This routine will create an |
| 7060 | * ndlp for the Name Server associated to the @vport if such node does |
| 7061 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 7062 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 7063 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 7064 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 7065 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7066 | void |
| 7067 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 7068 | { |
| 7069 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7070 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7071 | |
| 7072 | /* |
| 7073 | * If lpfc_delay_discovery parameter is set and the clean address |
| 7074 | * bit is cleared and fc fabric parameters chenged, delay FC NPort |
| 7075 | * discovery. |
| 7076 | */ |
| 7077 | spin_lock_irq(shost->host_lock); |
| 7078 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 7079 | spin_unlock_irq(shost->host_lock); |
James Smart | 1877570 | 2013-04-17 20:19:25 -0400 | [diff] [blame] | 7080 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 7081 | "3334 Delay fc port discovery for %d seconds\n", |
| 7082 | phba->fc_ratov); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7083 | mod_timer(&vport->delayed_disc_tmo, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7084 | jiffies + msecs_to_jiffies(1000 * phba->fc_ratov)); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7085 | return; |
| 7086 | } |
| 7087 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7088 | |
| 7089 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 7090 | if (!ndlp) { |
| 7091 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 7092 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7093 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7094 | lpfc_disc_start(vport); |
| 7095 | return; |
| 7096 | } |
| 7097 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7098 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7099 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7100 | return; |
| 7101 | } |
| 7102 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7103 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 7104 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 7105 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7106 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7107 | lpfc_disc_start(vport); |
| 7108 | return; |
| 7109 | } |
| 7110 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 7111 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7112 | "0348 NameServer login: node freed\n"); |
| 7113 | return; |
| 7114 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7115 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7116 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7117 | |
| 7118 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 7119 | |
| 7120 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 7121 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7122 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7123 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7124 | return; |
| 7125 | } |
| 7126 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 7127 | if (vport->cfg_fdmi_on) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7128 | /* If this is the first time, allocate an ndlp and initialize |
| 7129 | * it. Otherwise, make sure the node is enabled and then do the |
| 7130 | * login. |
| 7131 | */ |
| 7132 | ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID); |
| 7133 | if (!ndlp_fdmi) { |
| 7134 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 7135 | GFP_KERNEL); |
| 7136 | if (ndlp_fdmi) { |
| 7137 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 7138 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
| 7139 | } else |
| 7140 | return; |
| 7141 | } |
| 7142 | if (!NLP_CHK_NODE_ACT(ndlp_fdmi)) |
| 7143 | ndlp_fdmi = lpfc_enable_node(vport, |
| 7144 | ndlp_fdmi, |
| 7145 | NLP_STE_NPR_NODE); |
| 7146 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7147 | if (ndlp_fdmi) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7148 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7149 | NLP_STE_PLOGI_ISSUE); |
| 7150 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7151 | } |
| 7152 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7153 | } |
| 7154 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7155 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7156 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7157 | * @phba: pointer to lpfc hba data structure. |
| 7158 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 7159 | * |
| 7160 | * This routine is the completion callback function to register new vport |
| 7161 | * mailbox command. If the new vport mailbox command completes successfully, |
| 7162 | * the fabric registration login shall be performed on physical port (the |
| 7163 | * new vport created is actually a physical port, with VPI 0) or the port |
| 7164 | * login to Name Server for State Change Request (SCR) will be performed |
| 7165 | * on virtual port (real virtual port, with VPI greater than 0). |
| 7166 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7167 | static void |
| 7168 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 7169 | { |
| 7170 | struct lpfc_vport *vport = pmb->vport; |
| 7171 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7172 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 7173 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7174 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7175 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7176 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7177 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7178 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7179 | |
| 7180 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7181 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 7182 | "0915 Register VPI failed : Status: x%x" |
| 7183 | " upd bit: x%x \n", mb->mbxStatus, |
| 7184 | mb->un.varRegVpi.upd); |
| 7185 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 7186 | mb->un.varRegVpi.upd) |
| 7187 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7188 | |
| 7189 | switch (mb->mbxStatus) { |
| 7190 | case 0x11: /* unsupported feature */ |
| 7191 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7192 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7193 | /* giving up on vport registration */ |
| 7194 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 7195 | spin_lock_irq(shost->host_lock); |
| 7196 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 7197 | spin_unlock_irq(shost->host_lock); |
| 7198 | lpfc_can_disctmo(vport); |
| 7199 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7200 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 7201 | case 0x20: |
| 7202 | spin_lock_irq(shost->host_lock); |
| 7203 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 7204 | spin_unlock_irq(shost->host_lock); |
| 7205 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 7206 | pmb->vport = vport; |
| 7207 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 7208 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 7209 | MBX_NOWAIT); |
| 7210 | if (rc == MBX_NOT_FINISHED) { |
| 7211 | lpfc_printf_vlog(vport, |
| 7212 | KERN_ERR, LOG_MBOX, |
| 7213 | "2732 Failed to issue INIT_VPI" |
| 7214 | " mailbox command\n"); |
| 7215 | } else { |
| 7216 | lpfc_nlp_put(ndlp); |
| 7217 | return; |
| 7218 | } |
| 7219 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7220 | default: |
| 7221 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 7222 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7223 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7224 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7225 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7226 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7227 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 7228 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 7229 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7230 | lpfc_issue_init_vfi(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7231 | else |
| 7232 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7233 | break; |
| 7234 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7235 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7236 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 7237 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7238 | spin_unlock_irq(shost->host_lock); |
| 7239 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7240 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 7241 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7242 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7243 | /* |
| 7244 | * If the physical port is instantiated using |
| 7245 | * FDISC, do not start vport discovery. |
| 7246 | */ |
| 7247 | if (vport->port_state != LPFC_FDISC) |
| 7248 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7249 | lpfc_do_scr_ns_plogi(phba, vport); |
| 7250 | } |
| 7251 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7252 | lpfc_do_scr_ns_plogi(phba, vport); |
| 7253 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 7254 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7255 | /* Now, we decrement the ndlp reference count held for this |
| 7256 | * callback function |
| 7257 | */ |
| 7258 | lpfc_nlp_put(ndlp); |
| 7259 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7260 | mempool_free(pmb, phba->mbox_mem_pool); |
| 7261 | return; |
| 7262 | } |
| 7263 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7264 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7265 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7266 | * @phba: pointer to lpfc hba data structure. |
| 7267 | * @vport: pointer to a host virtual N_Port data structure. |
| 7268 | * @ndlp: pointer to a node-list data structure. |
| 7269 | * |
| 7270 | * This routine registers the @vport as a new virtual port with a HBA. |
| 7271 | * It is done through a registering vpi mailbox command. |
| 7272 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7273 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7274 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 7275 | struct lpfc_nodelist *ndlp) |
| 7276 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7277 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7278 | LPFC_MBOXQ_t *mbox; |
| 7279 | |
| 7280 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7281 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7282 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7283 | mbox->vport = vport; |
| 7284 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 7285 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7286 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7287 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7288 | /* mailbox command not success, decrement ndlp |
| 7289 | * reference count for this command |
| 7290 | */ |
| 7291 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7292 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7293 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7294 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 7295 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7296 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7297 | } |
| 7298 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7299 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 7300 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7301 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7302 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7303 | return; |
| 7304 | |
| 7305 | mbox_err_exit: |
| 7306 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 7307 | spin_lock_irq(shost->host_lock); |
| 7308 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 7309 | spin_unlock_irq(shost->host_lock); |
| 7310 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7311 | } |
| 7312 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7313 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7314 | * 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] | 7315 | * @phba: pointer to lpfc hba data structure. |
| 7316 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7317 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7318 | **/ |
| 7319 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7320 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7321 | { |
| 7322 | struct lpfc_vport **vports; |
| 7323 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7324 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7325 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7326 | |
| 7327 | /* Treat this failure as linkdown for all vports */ |
| 7328 | link_state = phba->link_state; |
| 7329 | lpfc_linkdown(phba); |
| 7330 | phba->link_state = link_state; |
| 7331 | |
| 7332 | vports = lpfc_create_vport_work_array(phba); |
| 7333 | |
| 7334 | if (vports) { |
| 7335 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 7336 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 7337 | if (ndlp) |
| 7338 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 7339 | lpfc_els_flush_cmd(vports[i]); |
| 7340 | } |
| 7341 | lpfc_destroy_vport_work_array(phba, vports); |
| 7342 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7343 | } |
| 7344 | |
| 7345 | /** |
| 7346 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 7347 | * @phba: pointer to lpfc hba data structure. |
| 7348 | * |
| 7349 | * This routine abort all pending discovery commands and |
| 7350 | * start a timer to retry FLOGI for the physical port |
| 7351 | * discovery. |
| 7352 | **/ |
| 7353 | void |
| 7354 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 7355 | { |
| 7356 | struct lpfc_nodelist *ndlp; |
| 7357 | struct Scsi_Host *shost; |
| 7358 | |
| 7359 | /* Cancel the all vports retry delay retry timers */ |
| 7360 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7361 | |
| 7362 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 7363 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 7364 | if (!ndlp) |
| 7365 | return; |
| 7366 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7367 | shost = lpfc_shost_from_vport(phba->pport); |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7368 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000)); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7369 | spin_lock_irq(shost->host_lock); |
| 7370 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 7371 | spin_unlock_irq(shost->host_lock); |
| 7372 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 7373 | phba->pport->port_state = LPFC_FLOGI; |
| 7374 | return; |
| 7375 | } |
| 7376 | |
| 7377 | /** |
| 7378 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 7379 | * @phba: pointer to lpfc hba data structure. |
| 7380 | * @cmdiocb: pointer to FDISC command iocb. |
| 7381 | * @rspiocb: pointer to FDISC response iocb. |
| 7382 | * |
| 7383 | * This routine checks if a FLOGI is reguired for FDISC |
| 7384 | * to succeed. |
| 7385 | **/ |
| 7386 | static int |
| 7387 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 7388 | struct lpfc_iocbq *cmdiocb, |
| 7389 | struct lpfc_iocbq *rspiocb) |
| 7390 | { |
| 7391 | |
| 7392 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 7393 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 7394 | return 0; |
| 7395 | else |
| 7396 | return 1; |
| 7397 | } |
| 7398 | |
| 7399 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7400 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7401 | * @phba: pointer to lpfc hba data structure. |
| 7402 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7403 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7404 | * |
| 7405 | * This routine is the completion callback function to a Fabric Discover |
| 7406 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 7407 | * single threaded, each FDISC completion callback function will reset |
| 7408 | * the discovery timer for all vports such that the timers will not get |
| 7409 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 7410 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 7411 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 7412 | * assigned to the vport has been changed with the completion of the FDISC |
| 7413 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 7414 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 7415 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 7416 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 7417 | * Server for State Change Request (SCR). |
| 7418 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7419 | static void |
| 7420 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7421 | struct lpfc_iocbq *rspiocb) |
| 7422 | { |
| 7423 | struct lpfc_vport *vport = cmdiocb->vport; |
| 7424 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7425 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 7426 | struct lpfc_nodelist *np; |
| 7427 | struct lpfc_nodelist *next_np; |
| 7428 | IOCB_t *irsp = &rspiocb->iocb; |
| 7429 | struct lpfc_iocbq *piocb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7430 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 7431 | struct serv_parm *sp; |
| 7432 | uint8_t fabric_param_changed; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7433 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7434 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7435 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 7436 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 7437 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7438 | /* Since all FDISCs are being single threaded, we |
| 7439 | * must reset the discovery timer for ALL vports |
| 7440 | * waiting to send FDISC when one completes. |
| 7441 | */ |
| 7442 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 7443 | lpfc_set_disctmo(piocb->vport); |
| 7444 | } |
| 7445 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7446 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7447 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 7448 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 7449 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7450 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7451 | |
| 7452 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 7453 | lpfc_retry_pport_discovery(phba); |
| 7454 | goto out; |
| 7455 | } |
| 7456 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7457 | /* Check for retry */ |
| 7458 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 7459 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7460 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7461 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7462 | "0126 FDISC failed. (x%x/x%x)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7463 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7464 | goto fdisc_failed; |
| 7465 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7466 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7467 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 7468 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7469 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7470 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7471 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 7472 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7473 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7474 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 7475 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7476 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 7477 | sp = prsp->virt + sizeof(uint32_t); |
| 7478 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 7479 | memcpy(&vport->fabric_portname, &sp->portName, |
| 7480 | sizeof(struct lpfc_name)); |
| 7481 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 7482 | sizeof(struct lpfc_name)); |
| 7483 | if (fabric_param_changed && |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7484 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 7485 | /* If our NportID changed, we need to ensure all |
| 7486 | * remaining NPORTs get unreg_login'ed so we can |
| 7487 | * issue unreg_vpi. |
| 7488 | */ |
| 7489 | list_for_each_entry_safe(np, next_np, |
| 7490 | &vport->fc_nodes, nlp_listp) { |
| 7491 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 7492 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 7493 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 7494 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7495 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7496 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7497 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7498 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7499 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 7500 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 7501 | |
| 7502 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7503 | lpfc_sli4_unreg_all_rpis(vport); |
| 7504 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7505 | lpfc_mbx_unreg_vpi(vport); |
| 7506 | spin_lock_irq(shost->host_lock); |
| 7507 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7508 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7509 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 7510 | else |
| 7511 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7512 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 7513 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 7514 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 7515 | /* |
| 7516 | * Driver needs to re-reg VPI in order for f/w |
| 7517 | * to update the MAC address. |
| 7518 | */ |
| 7519 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 7520 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7521 | } |
| 7522 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 7523 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 7524 | lpfc_issue_init_vpi(vport); |
| 7525 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7526 | lpfc_register_new_vport(phba, vport, ndlp); |
| 7527 | else |
| 7528 | lpfc_do_scr_ns_plogi(phba, vport); |
| 7529 | goto out; |
| 7530 | fdisc_failed: |
| 7531 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 7532 | /* Cancel discovery timer */ |
| 7533 | lpfc_can_disctmo(vport); |
| 7534 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7535 | out: |
| 7536 | lpfc_els_free_iocb(phba, cmdiocb); |
| 7537 | } |
| 7538 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7539 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7540 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7541 | * @vport: pointer to a virtual N_Port data structure. |
| 7542 | * @ndlp: pointer to a node-list data structure. |
| 7543 | * @retry: number of retries to the command IOCB. |
| 7544 | * |
| 7545 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 7546 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 7547 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 7548 | * IOCB will be sent off HBA at any given time. |
| 7549 | * |
| 7550 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7551 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7552 | * will be stored into the context1 field of the IOCB for the completion |
| 7553 | * callback function to the FDISC ELS command. |
| 7554 | * |
| 7555 | * Return code |
| 7556 | * 0 - Successfully issued fdisc iocb command |
| 7557 | * 1 - Failed to issue fdisc iocb command |
| 7558 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7559 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7560 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 7561 | uint8_t retry) |
| 7562 | { |
| 7563 | struct lpfc_hba *phba = vport->phba; |
| 7564 | IOCB_t *icmd; |
| 7565 | struct lpfc_iocbq *elsiocb; |
| 7566 | struct serv_parm *sp; |
| 7567 | uint8_t *pcmd; |
| 7568 | uint16_t cmdsize; |
| 7569 | int did = ndlp->nlp_DID; |
| 7570 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7571 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7572 | vport->port_state = LPFC_FDISC; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7573 | vport->fc_myDID = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7574 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 7575 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 7576 | ELS_CMD_FDISC); |
| 7577 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7578 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7579 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7580 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7581 | return 1; |
| 7582 | } |
| 7583 | |
| 7584 | icmd = &elsiocb->iocb; |
| 7585 | icmd->un.elsreq64.myID = 0; |
| 7586 | icmd->un.elsreq64.fl = 1; |
| 7587 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7588 | /* |
| 7589 | * SLI3 ports require a different context type value than SLI4. |
| 7590 | * Catch SLI3 ports here and override the prep. |
| 7591 | */ |
| 7592 | if (phba->sli_rev == LPFC_SLI_REV3) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7593 | icmd->ulpCt_h = 1; |
| 7594 | icmd->ulpCt_l = 0; |
| 7595 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7596 | |
| 7597 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7598 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 7599 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 7600 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 7601 | sp = (struct serv_parm *) pcmd; |
| 7602 | /* Setup CSPs accordingly for Fabric */ |
| 7603 | sp->cmn.e_d_tov = 0; |
| 7604 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 7605 | sp->cmn.virtual_fabric_support = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7606 | sp->cls1.classValid = 0; |
| 7607 | sp->cls2.seqDelivery = 1; |
| 7608 | sp->cls3.seqDelivery = 1; |
| 7609 | |
| 7610 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 7611 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 7612 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 7613 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 7614 | memcpy(pcmd, &vport->fc_portname, 8); |
| 7615 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 7616 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 7617 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 7618 | |
| 7619 | lpfc_set_disctmo(vport); |
| 7620 | |
| 7621 | phba->fc_stat.elsXmitFDISC++; |
| 7622 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 7623 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7624 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7625 | "Issue FDISC: did:x%x", |
| 7626 | did, 0, 0); |
| 7627 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7628 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 7629 | if (rc == IOCB_ERROR) { |
| 7630 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7631 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7632 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7633 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7634 | return 1; |
| 7635 | } |
| 7636 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7637 | return 0; |
| 7638 | } |
| 7639 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7640 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7641 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7642 | * @phba: pointer to lpfc hba data structure. |
| 7643 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7644 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7645 | * |
| 7646 | * This routine is the completion callback function to the issuing of a LOGO |
| 7647 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 7648 | * reference count held on ndlp for this completion function, indicating that |
| 7649 | * the reference to the ndlp is no long needed. Note that the |
| 7650 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 7651 | * callback function and an additional explicit ndlp reference decrementation |
| 7652 | * will trigger the actual release of the ndlp. |
| 7653 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7654 | static void |
| 7655 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7656 | struct lpfc_iocbq *rspiocb) |
| 7657 | { |
| 7658 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7659 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7660 | struct lpfc_nodelist *ndlp; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 7661 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7662 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 7663 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7664 | irsp = &rspiocb->iocb; |
| 7665 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7666 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 7667 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7668 | |
| 7669 | lpfc_els_free_iocb(phba, cmdiocb); |
| 7670 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7671 | |
| 7672 | /* Trigger the release of the ndlp after logo */ |
| 7673 | lpfc_nlp_put(ndlp); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 7674 | |
| 7675 | /* NPIV LOGO completes to NPort <nlp_DID> */ |
| 7676 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7677 | "2928 NPIV LOGO completes to NPort x%x " |
| 7678 | "Data: x%x x%x x%x x%x\n", |
| 7679 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 7680 | irsp->ulpTimeout, vport->num_disc_nodes); |
| 7681 | |
| 7682 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 7683 | spin_lock_irq(shost->host_lock); |
| 7684 | vport->fc_flag &= ~FC_FABRIC; |
| 7685 | spin_unlock_irq(shost->host_lock); |
| 7686 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7687 | } |
| 7688 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7689 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7690 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7691 | * @vport: pointer to a virtual N_Port data structure. |
| 7692 | * @ndlp: pointer to a node-list data structure. |
| 7693 | * |
| 7694 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 7695 | * |
| 7696 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7697 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7698 | * will be stored into the context1 field of the IOCB for the completion |
| 7699 | * callback function to the LOGO ELS command. |
| 7700 | * |
| 7701 | * Return codes |
| 7702 | * 0 - Successfully issued logo off the @vport |
| 7703 | * 1 - Failed to issue logo off the @vport |
| 7704 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7705 | int |
| 7706 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 7707 | { |
| 7708 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7709 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7710 | IOCB_t *icmd; |
| 7711 | struct lpfc_iocbq *elsiocb; |
| 7712 | uint8_t *pcmd; |
| 7713 | uint16_t cmdsize; |
| 7714 | |
| 7715 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 7716 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 7717 | ELS_CMD_LOGO); |
| 7718 | if (!elsiocb) |
| 7719 | return 1; |
| 7720 | |
| 7721 | icmd = &elsiocb->iocb; |
| 7722 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7723 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 7724 | pcmd += sizeof(uint32_t); |
| 7725 | |
| 7726 | /* Fill in LOGO payload */ |
| 7727 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 7728 | pcmd += sizeof(uint32_t); |
| 7729 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 7730 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7731 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7732 | "Issue LOGO npiv did:x%x flg:x%x", |
| 7733 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 7734 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7735 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 7736 | spin_lock_irq(shost->host_lock); |
| 7737 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 7738 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7739 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 7740 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7741 | spin_lock_irq(shost->host_lock); |
| 7742 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 7743 | spin_unlock_irq(shost->host_lock); |
| 7744 | lpfc_els_free_iocb(phba, elsiocb); |
| 7745 | return 1; |
| 7746 | } |
| 7747 | return 0; |
| 7748 | } |
| 7749 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7750 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7751 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7752 | * @ptr: holder for the timer function associated data. |
| 7753 | * |
| 7754 | * This routine is invoked by the fabric iocb block timer after |
| 7755 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 7756 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 7757 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 7758 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 7759 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 7760 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7761 | void |
| 7762 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 7763 | { |
| 7764 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 7765 | unsigned long iflags; |
| 7766 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7767 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7768 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 7769 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 7770 | if (!tmo_posted) |
| 7771 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 7772 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 7773 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7774 | if (!tmo_posted) |
| 7775 | lpfc_worker_wake_up(phba); |
| 7776 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7777 | } |
| 7778 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7779 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7780 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7781 | * @phba: pointer to lpfc hba data structure. |
| 7782 | * |
| 7783 | * This routine issues one fabric iocb from the driver internal list to |
| 7784 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 7785 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 7786 | * remove one pending fabric iocb from the driver internal list and invokes |
| 7787 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 7788 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7789 | static void |
| 7790 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 7791 | { |
| 7792 | struct lpfc_iocbq *iocb; |
| 7793 | unsigned long iflags; |
| 7794 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7795 | IOCB_t *cmd; |
| 7796 | |
| 7797 | repeat: |
| 7798 | iocb = NULL; |
| 7799 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7800 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7801 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 7802 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 7803 | list); |
| 7804 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7805 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7806 | atomic_inc(&phba->fabric_iocb_count); |
| 7807 | } |
| 7808 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7809 | if (iocb) { |
| 7810 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7811 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7812 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7813 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7814 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7815 | "Fabric sched1: ste:x%x", |
| 7816 | iocb->vport->port_state, 0, 0); |
| 7817 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7818 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7819 | |
| 7820 | if (ret == IOCB_ERROR) { |
| 7821 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7822 | iocb->fabric_iocb_cmpl = NULL; |
| 7823 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7824 | cmd = &iocb->iocb; |
| 7825 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 7826 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 7827 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 7828 | |
| 7829 | atomic_dec(&phba->fabric_iocb_count); |
| 7830 | goto repeat; |
| 7831 | } |
| 7832 | } |
| 7833 | |
| 7834 | return; |
| 7835 | } |
| 7836 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7837 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7838 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7839 | * @phba: pointer to lpfc hba data structure. |
| 7840 | * |
| 7841 | * This routine unblocks the issuing fabric iocb command. The function |
| 7842 | * will clear the fabric iocb block bit and then invoke the routine |
| 7843 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 7844 | * from the driver internal fabric iocb list. |
| 7845 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7846 | void |
| 7847 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 7848 | { |
| 7849 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7850 | |
| 7851 | lpfc_resume_fabric_iocbs(phba); |
| 7852 | return; |
| 7853 | } |
| 7854 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7855 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7856 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7857 | * @phba: pointer to lpfc hba data structure. |
| 7858 | * |
| 7859 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 7860 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 7861 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 7862 | * fabric iocb will be issued out of the HBA. |
| 7863 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7864 | static void |
| 7865 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 7866 | { |
| 7867 | int blocked; |
| 7868 | |
| 7869 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7870 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7871 | if (!blocked) |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7872 | mod_timer(&phba->fabric_block_timer, |
| 7873 | jiffies + msecs_to_jiffies(100)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7874 | |
| 7875 | return; |
| 7876 | } |
| 7877 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7878 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7879 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7880 | * @phba: pointer to lpfc hba data structure. |
| 7881 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7882 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7883 | * |
| 7884 | * This routine is the callback function that is put to the fabric iocb's |
| 7885 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 7886 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 7887 | * function first restores and invokes the original iocb's callback function |
| 7888 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 7889 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 7890 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7891 | static void |
| 7892 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7893 | struct lpfc_iocbq *rspiocb) |
| 7894 | { |
| 7895 | struct ls_rjt stat; |
| 7896 | |
| 7897 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 7898 | BUG(); |
| 7899 | |
| 7900 | switch (rspiocb->iocb.ulpStatus) { |
| 7901 | case IOSTAT_NPORT_RJT: |
| 7902 | case IOSTAT_FABRIC_RJT: |
| 7903 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 7904 | lpfc_block_fabric_iocbs(phba); |
| 7905 | } |
| 7906 | break; |
| 7907 | |
| 7908 | case IOSTAT_NPORT_BSY: |
| 7909 | case IOSTAT_FABRIC_BSY: |
| 7910 | lpfc_block_fabric_iocbs(phba); |
| 7911 | break; |
| 7912 | |
| 7913 | case IOSTAT_LS_RJT: |
| 7914 | stat.un.lsRjtError = |
| 7915 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 7916 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 7917 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 7918 | lpfc_block_fabric_iocbs(phba); |
| 7919 | break; |
| 7920 | } |
| 7921 | |
| 7922 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 7923 | BUG(); |
| 7924 | |
| 7925 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 7926 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 7927 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7928 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 7929 | |
| 7930 | atomic_dec(&phba->fabric_iocb_count); |
| 7931 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7932 | /* Post any pending iocbs to HBA */ |
| 7933 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7934 | } |
| 7935 | } |
| 7936 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7937 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7938 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7939 | * @phba: pointer to lpfc hba data structure. |
| 7940 | * @iocb: pointer to lpfc command iocb data structure. |
| 7941 | * |
| 7942 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 7943 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 7944 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 7945 | * any given time. As such, this function will first check to see whether there |
| 7946 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 7947 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 7948 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 7949 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 7950 | * |
| 7951 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 7952 | * order. The problem is caused by the construction of the "ready" boolen does |
| 7953 | * not include the condition that the internal fabric IOCB list is empty. As |
| 7954 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 7955 | * ahead of the fabric IOCBs in the internal list. |
| 7956 | * |
| 7957 | * Return code |
| 7958 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 7959 | * IOCB_ERROR - failed to issue fabric iocb |
| 7960 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7961 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7962 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 7963 | { |
| 7964 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7965 | int ready; |
| 7966 | int ret; |
| 7967 | |
| 7968 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 7969 | BUG(); |
| 7970 | |
| 7971 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7972 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 7973 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7974 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7975 | if (ready) |
| 7976 | /* Increment fabric iocb count to hold the position */ |
| 7977 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7978 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7979 | if (ready) { |
| 7980 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7981 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7982 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7983 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7984 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7985 | "Fabric sched2: ste:x%x", |
| 7986 | iocb->vport->port_state, 0, 0); |
| 7987 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7988 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7989 | |
| 7990 | if (ret == IOCB_ERROR) { |
| 7991 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7992 | iocb->fabric_iocb_cmpl = NULL; |
| 7993 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7994 | atomic_dec(&phba->fabric_iocb_count); |
| 7995 | } |
| 7996 | } else { |
| 7997 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7998 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 7999 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8000 | ret = IOCB_SUCCESS; |
| 8001 | } |
| 8002 | return ret; |
| 8003 | } |
| 8004 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8005 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8006 | * 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] | 8007 | * @vport: pointer to a virtual N_Port data structure. |
| 8008 | * |
| 8009 | * This routine aborts all the IOCBs associated with a @vport from the |
| 8010 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 8011 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 8012 | * list, removes each IOCB associated with the @vport off the list, set the |
| 8013 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 8014 | * associated with the IOCB. |
| 8015 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 8016 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8017 | { |
| 8018 | LIST_HEAD(completions); |
| 8019 | struct lpfc_hba *phba = vport->phba; |
| 8020 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8021 | |
| 8022 | spin_lock_irq(&phba->hbalock); |
| 8023 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 8024 | list) { |
| 8025 | |
| 8026 | if (piocb->vport != vport) |
| 8027 | continue; |
| 8028 | |
| 8029 | list_move_tail(&piocb->list, &completions); |
| 8030 | } |
| 8031 | spin_unlock_irq(&phba->hbalock); |
| 8032 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8033 | /* Cancel all the IOCBs from the completions list */ |
| 8034 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8035 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8036 | } |
| 8037 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8038 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8039 | * 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] | 8040 | * @ndlp: pointer to a node-list data structure. |
| 8041 | * |
| 8042 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 8043 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 8044 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 8045 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 8046 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 8047 | * associated with the IOCB. |
| 8048 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8049 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 8050 | { |
| 8051 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8052 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8053 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 8054 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8055 | |
| 8056 | spin_lock_irq(&phba->hbalock); |
| 8057 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 8058 | list) { |
| 8059 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 8060 | |
| 8061 | list_move_tail(&piocb->list, &completions); |
| 8062 | } |
| 8063 | } |
| 8064 | spin_unlock_irq(&phba->hbalock); |
| 8065 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8066 | /* Cancel all the IOCBs from the completions list */ |
| 8067 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8068 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8069 | } |
| 8070 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8071 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8072 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8073 | * @phba: pointer to lpfc hba data structure. |
| 8074 | * |
| 8075 | * This routine aborts all the IOCBs currently on the driver internal |
| 8076 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 8077 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 8078 | * list, removes IOCBs off the list, set the status feild to |
| 8079 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 8080 | * the IOCB. |
| 8081 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8082 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 8083 | { |
| 8084 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8085 | |
| 8086 | spin_lock_irq(&phba->hbalock); |
| 8087 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 8088 | spin_unlock_irq(&phba->hbalock); |
| 8089 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8090 | /* Cancel all the IOCBs from the completions list */ |
| 8091 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8092 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8093 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8094 | |
| 8095 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 8096 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport |
| 8097 | * @vport: pointer to lpfc vport data structure. |
| 8098 | * |
| 8099 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 8100 | * for an ndlp on removal. |
| 8101 | **/ |
| 8102 | void |
| 8103 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) |
| 8104 | { |
| 8105 | struct lpfc_hba *phba = vport->phba; |
| 8106 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 8107 | unsigned long iflag = 0; |
| 8108 | |
| 8109 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8110 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
| 8111 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 8112 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 8113 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) |
| 8114 | sglq_entry->ndlp = NULL; |
| 8115 | } |
| 8116 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 8117 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8118 | return; |
| 8119 | } |
| 8120 | |
| 8121 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8122 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 8123 | * @phba: pointer to lpfc hba data structure. |
| 8124 | * @axri: pointer to the els xri abort wcqe structure. |
| 8125 | * |
| 8126 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 8127 | * ELS aborted xri. |
| 8128 | **/ |
| 8129 | void |
| 8130 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 8131 | struct sli4_wcqe_xri_aborted *axri) |
| 8132 | { |
| 8133 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 8134 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8135 | uint16_t lxri = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 8136 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8137 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 8138 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 8139 | struct lpfc_nodelist *ndlp; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 8140 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8141 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8142 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8143 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8144 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 8145 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 8146 | if (sglq_entry->sli4_xritag == xri) { |
| 8147 | list_del(&sglq_entry->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 8148 | ndlp = sglq_entry->ndlp; |
| 8149 | sglq_entry->ndlp = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8150 | list_add_tail(&sglq_entry->list, |
| 8151 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8152 | sglq_entry->state = SGL_FREED; |
| 8153 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8154 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 8155 | lpfc_set_rrq_active(phba, ndlp, |
| 8156 | sglq_entry->sli4_lxritag, |
| 8157 | rxid, 1); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 8158 | |
| 8159 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 8160 | if (!(list_empty(&pring->txq))) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 8161 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8162 | return; |
| 8163 | } |
| 8164 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8165 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8166 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 8167 | if (lxri == NO_XRI) { |
| 8168 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8169 | return; |
| 8170 | } |
| 8171 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 8172 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
| 8173 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8174 | return; |
| 8175 | } |
| 8176 | sglq_entry->state = SGL_XRI_ABORTED; |
| 8177 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8178 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8179 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 8180 | |
| 8181 | /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. |
| 8182 | * @vport: pointer to virtual port object. |
| 8183 | * @ndlp: nodelist pointer for the impacted node. |
| 8184 | * |
| 8185 | * The driver calls this routine in response to an SLI4 XRI ABORT CQE |
| 8186 | * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, |
| 8187 | * the driver is required to send a LOGO to the remote node before it |
| 8188 | * attempts to recover its login to the remote node. |
| 8189 | */ |
| 8190 | void |
| 8191 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 8192 | struct lpfc_nodelist *ndlp) |
| 8193 | { |
| 8194 | struct Scsi_Host *shost; |
| 8195 | struct lpfc_hba *phba; |
| 8196 | unsigned long flags = 0; |
| 8197 | |
| 8198 | shost = lpfc_shost_from_vport(vport); |
| 8199 | phba = vport->phba; |
| 8200 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 8201 | lpfc_printf_log(phba, KERN_INFO, |
| 8202 | LOG_SLI, "3093 No rport recovery needed. " |
| 8203 | "rport in state 0x%x\n", ndlp->nlp_state); |
| 8204 | return; |
| 8205 | } |
| 8206 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8207 | "3094 Start rport recovery on shost id 0x%x " |
| 8208 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 8209 | "flags 0x%x\n", |
| 8210 | shost->host_no, ndlp->nlp_DID, |
| 8211 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 8212 | ndlp->nlp_flag); |
| 8213 | /* |
| 8214 | * The rport is not responding. Remove the FCP-2 flag to prevent |
| 8215 | * an ADISC in the follow-up recovery code. |
| 8216 | */ |
| 8217 | spin_lock_irqsave(shost->host_lock, flags); |
| 8218 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 8219 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 8220 | lpfc_issue_els_logo(vport, ndlp, 0); |
| 8221 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
| 8222 | } |
| 8223 | |