| 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 | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2011 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 | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 32 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include "lpfc_hw.h" |
| 34 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 35 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 36 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | #include "lpfc_disc.h" |
| 38 | #include "lpfc_scsi.h" |
| 39 | #include "lpfc.h" |
| 40 | #include "lpfc_logmsg.h" |
| 41 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 42 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 43 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 | |
| 45 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, |
| 46 | struct lpfc_iocbq *); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 47 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
| 48 | struct lpfc_iocbq *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 49 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
| 50 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, |
| 51 | struct lpfc_nodelist *ndlp, uint8_t retry); |
| 52 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, |
| 53 | struct lpfc_iocbq *iocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 54 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 55 | static int lpfc_max_els_tries = 3; |
| 56 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 57 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 58 | * lpfc_els_chk_latt - Check host link attention event for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 59 | * @vport: pointer to a host virtual N_Port data structure. |
| 60 | * |
| 61 | * This routine checks whether there is an outstanding host link |
| 62 | * attention event during the discovery process with the @vport. It is done |
| 63 | * by reading the HBA's Host Attention (HA) register. If there is any host |
| 64 | * link attention events during this @vport's discovery process, the @vport |
| 65 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall |
| 66 | * be issued if the link state is not already in host link cleared state, |
| 67 | * and a return code shall indicate whether the host link attention event |
| 68 | * had happened. |
| 69 | * |
| 70 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport |
| 71 | * state in LPFC_VPORT_READY, the request for checking host link attention |
| 72 | * event will be ignored and a return code shall indicate no host link |
| 73 | * attention event had happened. |
| 74 | * |
| 75 | * Return codes |
| 76 | * 0 - no host link attention event happened |
| 77 | * 1 - host link attention event happened |
| 78 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 79 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 80 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 81 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 82 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 83 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 84 | uint32_t ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 85 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 86 | if (vport->port_state >= LPFC_VPORT_READY || |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 87 | phba->link_state == LPFC_LINK_DOWN || |
| 88 | phba->sli_rev > LPFC_SLI_REV3) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 89 | return 0; |
| 90 | |
| 91 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 92 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 93 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 94 | |
| 95 | if (!(ha_copy & HA_LATT)) |
| 96 | return 0; |
| 97 | |
| 98 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 99 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 100 | "0237 Pending Link Event during " |
| 101 | "Discovery: State x%x\n", |
| 102 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 103 | |
| 104 | /* CLEAR_LA should re-enable link attention events and |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame^] | 105 | * we should then immediately take a LATT event. The |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 106 | * LATT processing should call lpfc_linkdown() which |
| 107 | * will cleanup any left over in-progress discovery |
| 108 | * events. |
| 109 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 110 | spin_lock_irq(shost->host_lock); |
| 111 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 112 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 113 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 114 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 115 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 116 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 117 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | } |
| 119 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 120 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 121 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 122 | * @vport: pointer to a host virtual N_Port data structure. |
| 123 | * @expectRsp: flag indicating whether response is expected. |
| 124 | * @cmdSize: size of the ELS command. |
| 125 | * @retry: number of retries to the command IOCB when it fails. |
| 126 | * @ndlp: pointer to a node-list data structure. |
| 127 | * @did: destination identifier. |
| 128 | * @elscmd: the ELS command code. |
| 129 | * |
| 130 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 131 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 132 | * passed into the routine for discovery state machine to issue an Extended |
| 133 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 134 | * and preparation routine that is used by all the discovery state machine |
| 135 | * routines and the ELS command-specific fields will be later set up by |
| 136 | * the individual discovery machine routines after calling this routine |
| 137 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 138 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 139 | * payload and response payload (if expected). The reference count on the |
| 140 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 141 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 142 | * reference for the command's callback function to access later. |
| 143 | * |
| 144 | * Return code |
| 145 | * Pointer to the newly allocated/prepared els iocb data structure |
| 146 | * NULL - when els iocb data structure allocation/preparation failed |
| 147 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 148 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 149 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 150 | uint16_t cmdSize, uint8_t retry, |
| 151 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 152 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 153 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 154 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 155 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 156 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 157 | struct ulp_bde64 *bpl; |
| 158 | IOCB_t *icmd; |
| 159 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 160 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 161 | if (!lpfc_is_link_up(phba)) |
| 162 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 164 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 165 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 166 | |
| 167 | if (elsiocb == NULL) |
| 168 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 169 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 170 | /* |
| 171 | * If this command is for fabric controller and HBA running |
| 172 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. |
| 173 | */ |
| 174 | if ((did == Fabric_DID) && |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 175 | (phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 176 | ((elscmd == ELS_CMD_FLOGI) || |
| 177 | (elscmd == ELS_CMD_FDISC) || |
| 178 | (elscmd == ELS_CMD_LOGO))) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 179 | switch (elscmd) { |
| 180 | case ELS_CMD_FLOGI: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 181 | elsiocb->iocb_flag |= |
| 182 | ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 183 | & LPFC_FIP_ELS_ID_MASK); |
| 184 | break; |
| 185 | case ELS_CMD_FDISC: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 186 | elsiocb->iocb_flag |= |
| 187 | ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 188 | & LPFC_FIP_ELS_ID_MASK); |
| 189 | break; |
| 190 | case ELS_CMD_LOGO: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 191 | elsiocb->iocb_flag |= |
| 192 | ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 193 | & LPFC_FIP_ELS_ID_MASK); |
| 194 | break; |
| 195 | } |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 196 | else |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 197 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 198 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 199 | icmd = &elsiocb->iocb; |
| 200 | |
| 201 | /* fill in BDEs for command */ |
| 202 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 203 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 204 | if (pcmd) |
| 205 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 206 | if (!pcmd || !pcmd->virt) |
| 207 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 208 | |
| 209 | INIT_LIST_HEAD(&pcmd->list); |
| 210 | |
| 211 | /* Allocate buffer for response payload */ |
| 212 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 213 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 214 | if (prsp) |
| 215 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 216 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 217 | if (!prsp || !prsp->virt) |
| 218 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 219 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 220 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 221 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 222 | |
| 223 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 224 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 225 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 226 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 227 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 228 | if (!pbuflist || !pbuflist->virt) |
| 229 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 230 | |
| 231 | INIT_LIST_HEAD(&pbuflist->list); |
| 232 | |
| 233 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 234 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 235 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 236 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 238 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 240 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 242 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 243 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 244 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 245 | icmd->ulpBdeCount = 1; |
| 246 | icmd->ulpLe = 1; |
| 247 | icmd->ulpClass = CLASS3; |
| 248 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 249 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 250 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 251 | |
| 252 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 253 | icmd->ulpContext = vport->vpi + phba->vpi_base; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 254 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 255 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 256 | if (elscmd == ELS_CMD_ECHO) |
| 257 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 258 | else |
| 259 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 260 | } |
| 261 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 262 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 263 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 264 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 265 | bpl->tus.f.bdeSize = cmdSize; |
| 266 | bpl->tus.f.bdeFlags = 0; |
| 267 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 268 | |
| 269 | if (expectRsp) { |
| 270 | bpl++; |
| 271 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 272 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 273 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 274 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 275 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 276 | } |
| 277 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 278 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 279 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 280 | if (!elsiocb->context1) |
| 281 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 282 | elsiocb->context2 = pcmd; |
| 283 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 284 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 285 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 286 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 287 | |
| 288 | if (prsp) { |
| 289 | list_add(&prsp->list, &pcmd->list); |
| 290 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 291 | if (expectRsp) { |
| 292 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 293 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 294 | "0116 Xmit ELS command x%x to remote " |
| 295 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 296 | elscmd, did, elsiocb->iotag, |
| 297 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 298 | } else { |
| 299 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 300 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 301 | "0117 Xmit ELS response x%x to remote " |
| 302 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 303 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 304 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 305 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 306 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 307 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 308 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 309 | if (expectRsp) |
| 310 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 311 | kfree(pbuflist); |
| 312 | |
| 313 | els_iocb_free_prsp_exit: |
| 314 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 315 | kfree(prsp); |
| 316 | |
| 317 | els_iocb_free_pcmb_exit: |
| 318 | kfree(pcmd); |
| 319 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 320 | return NULL; |
| 321 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 322 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 323 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 324 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 325 | * @vport: pointer to a host virtual N_Port data structure. |
| 326 | * |
| 327 | * This routine issues a fabric registration login for a @vport. An |
| 328 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 329 | * The routine invokes two mailbox commands to carry out fabric registration |
| 330 | * login through the HBA firmware: the first mailbox command requests the |
| 331 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 332 | * command requests the HBA to perform the actual fabric registration login |
| 333 | * with the @vport. |
| 334 | * |
| 335 | * Return code |
| 336 | * 0 - successfully issued fabric registration login for @vport |
| 337 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 338 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 339 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 340 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 341 | { |
| 342 | struct lpfc_hba *phba = vport->phba; |
| 343 | LPFC_MBOXQ_t *mbox; |
| 344 | struct lpfc_dmabuf *mp; |
| 345 | struct lpfc_nodelist *ndlp; |
| 346 | struct serv_parm *sp; |
| 347 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 348 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 349 | |
| 350 | sp = &phba->fc_fabparam; |
| 351 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 352 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 353 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 354 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 355 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 356 | |
| 357 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 358 | if (!mbox) { |
| 359 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 360 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 361 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 362 | |
| 363 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 364 | lpfc_config_link(phba, mbox); |
| 365 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 366 | mbox->vport = vport; |
| 367 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 368 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 369 | if (rc == MBX_NOT_FINISHED) { |
| 370 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 371 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 372 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 373 | |
| 374 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 375 | if (!mbox) { |
| 376 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 377 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 378 | } |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 379 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
| 380 | ndlp->nlp_rpi); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 381 | if (rc) { |
| 382 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 383 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 384 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 385 | |
| 386 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 387 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 388 | /* increment the reference count on ndlp to hold reference |
| 389 | * for the callback routine. |
| 390 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 391 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 392 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 393 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 394 | if (rc == MBX_NOT_FINISHED) { |
| 395 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 396 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 397 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 398 | |
| 399 | return 0; |
| 400 | |
| 401 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 402 | /* decrement the reference count on ndlp just incremented |
| 403 | * for the failed mbox command. |
| 404 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 405 | lpfc_nlp_put(ndlp); |
| 406 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 407 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 408 | kfree(mp); |
| 409 | fail_free_mbox: |
| 410 | mempool_free(mbox, phba->mbox_mem_pool); |
| 411 | |
| 412 | fail: |
| 413 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 414 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 415 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 416 | return -ENXIO; |
| 417 | } |
| 418 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 419 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 420 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 421 | * @vport: pointer to a host virtual N_Port data structure. |
| 422 | * |
| 423 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
| 424 | * the @vport. This mailbox command is necessary for FCoE only. |
| 425 | * |
| 426 | * Return code |
| 427 | * 0 - successfully issued REG_VFI for @vport |
| 428 | * A failure code otherwise. |
| 429 | **/ |
| 430 | static int |
| 431 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 432 | { |
| 433 | struct lpfc_hba *phba = vport->phba; |
| 434 | LPFC_MBOXQ_t *mboxq; |
| 435 | struct lpfc_nodelist *ndlp; |
| 436 | struct serv_parm *sp; |
| 437 | struct lpfc_dmabuf *dmabuf; |
| 438 | int rc = 0; |
| 439 | |
| 440 | sp = &phba->fc_fabparam; |
| 441 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 442 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 443 | rc = -ENODEV; |
| 444 | goto fail; |
| 445 | } |
| 446 | |
| 447 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 448 | if (!dmabuf) { |
| 449 | rc = -ENOMEM; |
| 450 | goto fail; |
| 451 | } |
| 452 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 453 | if (!dmabuf->virt) { |
| 454 | rc = -ENOMEM; |
| 455 | goto fail_free_dmabuf; |
| 456 | } |
| 457 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 458 | if (!mboxq) { |
| 459 | rc = -ENOMEM; |
| 460 | goto fail_free_coherent; |
| 461 | } |
| 462 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 463 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 464 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 465 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 466 | mboxq->vport = vport; |
| 467 | mboxq->context1 = dmabuf; |
| 468 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 469 | if (rc == MBX_NOT_FINISHED) { |
| 470 | rc = -ENXIO; |
| 471 | goto fail_free_mbox; |
| 472 | } |
| 473 | return 0; |
| 474 | |
| 475 | fail_free_mbox: |
| 476 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 477 | fail_free_coherent: |
| 478 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 479 | fail_free_dmabuf: |
| 480 | kfree(dmabuf); |
| 481 | fail: |
| 482 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 483 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 484 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 485 | return rc; |
| 486 | } |
| 487 | |
| 488 | /** |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 489 | * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean. |
| 490 | * @vport: pointer to a host virtual N_Port data structure. |
| 491 | * @sp: pointer to service parameter data structure. |
| 492 | * |
| 493 | * This routine is called from FLOGI/FDISC completion handler functions. |
| 494 | * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric |
| 495 | * node nodename is changed in the completion service parameter else return |
| 496 | * 0. This function also set flag in the vport data structure to delay |
| 497 | * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit |
| 498 | * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric |
| 499 | * node nodename is changed in the completion service parameter. |
| 500 | * |
| 501 | * Return code |
| 502 | * 0 - FCID and Fabric Nodename and Fabric portname is not changed. |
| 503 | * 1 - FCID or Fabric Nodename or Fabric portname is changed. |
| 504 | * |
| 505 | **/ |
| 506 | static uint8_t |
| 507 | lpfc_check_clean_addr_bit(struct lpfc_vport *vport, |
| 508 | struct serv_parm *sp) |
| 509 | { |
| 510 | uint8_t fabric_param_changed = 0; |
| 511 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 512 | |
| 513 | if ((vport->fc_prevDID != vport->fc_myDID) || |
| 514 | memcmp(&vport->fabric_portname, &sp->portName, |
| 515 | sizeof(struct lpfc_name)) || |
| 516 | memcmp(&vport->fabric_nodename, &sp->nodeName, |
| 517 | sizeof(struct lpfc_name))) |
| 518 | fabric_param_changed = 1; |
| 519 | |
| 520 | /* |
| 521 | * Word 1 Bit 31 in common service parameter is overloaded. |
| 522 | * Word 1 Bit 31 in FLOGI request is multiple NPort request |
| 523 | * Word 1 Bit 31 in FLOGI response is clean address bit |
| 524 | * |
| 525 | * If fabric parameter is changed and clean address bit is |
| 526 | * cleared delay nport discovery if |
| 527 | * - vport->fc_prevDID != 0 (not initial discovery) OR |
| 528 | * - lpfc_delay_discovery module parameter is set. |
| 529 | */ |
| 530 | if (fabric_param_changed && !sp->cmn.clean_address_bit && |
| 531 | (vport->fc_prevDID || lpfc_delay_discovery)) { |
| 532 | spin_lock_irq(shost->host_lock); |
| 533 | vport->fc_flag |= FC_DISC_DELAYED; |
| 534 | spin_unlock_irq(shost->host_lock); |
| 535 | } |
| 536 | |
| 537 | return fabric_param_changed; |
| 538 | } |
| 539 | |
| 540 | |
| 541 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 542 | * 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] | 543 | * @vport: pointer to a host virtual N_Port data structure. |
| 544 | * @ndlp: pointer to a node-list data structure. |
| 545 | * @sp: pointer to service parameter data structure. |
| 546 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 547 | * |
| 548 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 549 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 550 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 551 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 552 | * @vport against the previously assigned N_Port ID. If it is different from |
| 553 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 554 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 555 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 556 | * is invoked to register login to the fabric. |
| 557 | * |
| 558 | * Return code |
| 559 | * 0 - Success (currently, always return 0) |
| 560 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 561 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 562 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 563 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 564 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 565 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 566 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 567 | struct lpfc_nodelist *np; |
| 568 | struct lpfc_nodelist *next_np; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 569 | uint8_t fabric_param_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 570 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 571 | spin_lock_irq(shost->host_lock); |
| 572 | vport->fc_flag |= FC_FABRIC; |
| 573 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 574 | |
| 575 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 576 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 577 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 578 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 579 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 580 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 581 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 582 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 583 | spin_lock_irq(shost->host_lock); |
| 584 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 585 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 586 | } |
| 587 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 588 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 589 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 590 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 591 | ndlp->nlp_class_sup = 0; |
| 592 | if (sp->cls1.classValid) |
| 593 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 594 | if (sp->cls2.classValid) |
| 595 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 596 | if (sp->cls3.classValid) |
| 597 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 598 | if (sp->cls4.classValid) |
| 599 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 600 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 601 | sp->cmn.bbRcvSizeLsb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 602 | |
| 603 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 604 | memcpy(&vport->fabric_portname, &sp->portName, |
| 605 | sizeof(struct lpfc_name)); |
| 606 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 607 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 608 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 609 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 610 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 611 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 612 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 613 | LOG_ELS | LOG_VPORT, |
| 614 | "1816 FLOGI NPIV supported, " |
| 615 | "response data 0x%x\n", |
| 616 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 617 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 618 | } else { |
| 619 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 620 | to call reg_vnpid atleast for the physcial host */ |
| 621 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 622 | LOG_ELS | LOG_VPORT, |
| 623 | "1817 Fabric does not support NPIV " |
| 624 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 625 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 626 | } |
| 627 | } |
| 628 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 629 | if (fabric_param_changed && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 630 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 631 | |
| 632 | /* If our NportID changed, we need to ensure all |
| 633 | * remaining NPORTs get unreg_login'ed. |
| 634 | */ |
| 635 | list_for_each_entry_safe(np, next_np, |
| 636 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 637 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 638 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 639 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 640 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 641 | continue; |
| 642 | spin_lock_irq(shost->host_lock); |
| 643 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 644 | spin_unlock_irq(shost->host_lock); |
| 645 | lpfc_unreg_rpi(vport, np); |
| 646 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 647 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 648 | |
| 649 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 650 | lpfc_sli4_unreg_all_rpis(vport); |
| 651 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 652 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 653 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 654 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 655 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 656 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 657 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 658 | /* |
| 659 | * If VPI is unreged, driver need to do INIT_VPI |
| 660 | * before re-registering |
| 661 | */ |
| 662 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 663 | spin_lock_irq(shost->host_lock); |
| 664 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 665 | spin_unlock_irq(shost->host_lock); |
| 666 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 667 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 668 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 669 | /* |
| 670 | * Driver needs to re-reg VPI in order for f/w |
| 671 | * to update the MAC address. |
| 672 | */ |
| 673 | lpfc_register_new_vport(phba, vport, ndlp); |
| 674 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 675 | } |
| 676 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 677 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 678 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 679 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 680 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 681 | lpfc_register_new_vport(phba, vport, ndlp); |
| 682 | else |
| 683 | lpfc_issue_fabric_reglogin(vport); |
| 684 | } else { |
| 685 | ndlp->nlp_type |= NLP_FABRIC; |
| 686 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 687 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 688 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 689 | lpfc_start_fdiscs(phba); |
| 690 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 691 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 692 | lpfc_issue_init_vpi(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 693 | else |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 694 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 695 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 696 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 697 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 698 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 699 | * 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] | 700 | * @vport: pointer to a host virtual N_Port data structure. |
| 701 | * @ndlp: pointer to a node-list data structure. |
| 702 | * @sp: pointer to service parameter data structure. |
| 703 | * |
| 704 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 705 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 706 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 707 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 708 | * the received N_Port Name lexicographically, this node shall assign local |
| 709 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 710 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 711 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 712 | * N_Port IDs. |
| 713 | * |
| 714 | * Return code |
| 715 | * 0 - Success |
| 716 | * -ENXIO - Fail |
| 717 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 718 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 719 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 720 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 721 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 722 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 723 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 724 | LPFC_MBOXQ_t *mbox; |
| 725 | int rc; |
| 726 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 727 | spin_lock_irq(shost->host_lock); |
| 728 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 729 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 730 | |
| 731 | phba->fc_edtov = FF_DEF_EDTOV; |
| 732 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 733 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 734 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 735 | if (rc >= 0) { |
| 736 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 737 | spin_lock_irq(shost->host_lock); |
| 738 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 739 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 740 | |
| 741 | /* |
| 742 | * N_Port ID cannot be 0, set our to LocalID the other |
| 743 | * side will be RemoteID. |
| 744 | */ |
| 745 | |
| 746 | /* not equal */ |
| 747 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 748 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 749 | |
| 750 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 751 | if (!mbox) |
| 752 | goto fail; |
| 753 | |
| 754 | lpfc_config_link(phba, mbox); |
| 755 | |
| 756 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 757 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 758 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 759 | if (rc == MBX_NOT_FINISHED) { |
| 760 | mempool_free(mbox, phba->mbox_mem_pool); |
| 761 | goto fail; |
| 762 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 763 | /* Decrement ndlp reference count indicating that ndlp can be |
| 764 | * safely released when other references to it are done. |
| 765 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 766 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 767 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 768 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 769 | if (!ndlp) { |
| 770 | /* |
| 771 | * Cannot find existing Fabric ndlp, so allocate a |
| 772 | * new one |
| 773 | */ |
| 774 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 775 | if (!ndlp) |
| 776 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 777 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 778 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 779 | ndlp = lpfc_enable_node(vport, ndlp, |
| 780 | NLP_STE_UNUSED_NODE); |
| 781 | if(!ndlp) |
| 782 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 786 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 787 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 788 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 789 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 790 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 791 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 792 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 793 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 794 | } else |
| 795 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 796 | * count indicating that ndlp can be released when other |
| 797 | * references to it are done. |
| 798 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 799 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 800 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 801 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 802 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 803 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 804 | spin_lock_irq(shost->host_lock); |
| 805 | vport->fc_flag |= FC_PT2PT; |
| 806 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 807 | |
| 808 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 809 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 810 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 811 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 812 | return -ENXIO; |
| 813 | } |
| 814 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 815 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 816 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 817 | * @phba: pointer to lpfc hba data structure. |
| 818 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 819 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 820 | * |
| 821 | * This routine is the top-level completion callback function for issuing |
| 822 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 823 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 824 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 825 | * returning 1), the command IOCB will be released and function returned. |
| 826 | * If the retry attempt has been given up (possibly reach the maximum |
| 827 | * number of retries), one additional decrement of ndlp reference shall be |
| 828 | * invoked before going out after releasing the command IOCB. This will |
| 829 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 830 | * invoke one decrement of ndlp reference count). If no error reported in |
| 831 | * the IOCB status, the command Port ID field is used to determine whether |
| 832 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 833 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 834 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 835 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 836 | * specific topology completion conditions. |
| 837 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 838 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 839 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 840 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 841 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 842 | struct lpfc_vport *vport = cmdiocb->vport; |
| 843 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | IOCB_t *irsp = &rspiocb->iocb; |
| 845 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 846 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 847 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 848 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 849 | int rc; |
| 850 | |
| 851 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 852 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 853 | /* One additional decrement on node reference count to |
| 854 | * trigger the release of the node |
| 855 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 856 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 857 | goto out; |
| 858 | } |
| 859 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 860 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 861 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 862 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 863 | vport->port_state); |
| 864 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 865 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 866 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 867 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 868 | * due to new FCF discovery |
| 869 | */ |
| 870 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 871 | (phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 872 | (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) && |
| 873 | (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 874 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 875 | "2611 FLOGI failed on FCF (x%x), " |
| 876 | "status:x%x/x%x, tmo:x%x, perform " |
| 877 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 878 | phba->fcf.current_rec.fcf_indx, |
| 879 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 880 | irsp->ulpTimeout); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 881 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 882 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 883 | if (rc) |
| 884 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 885 | } |
| 886 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 887 | /* FLOGI failure */ |
| 888 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 889 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 890 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 891 | irsp->ulpTimeout); |
| 892 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 893 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 894 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 895 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 896 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 897 | /* FLOGI failure */ |
| 898 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 899 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 900 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 901 | irsp->ulpTimeout); |
| 902 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 903 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 904 | spin_lock_irq(shost->host_lock); |
| 905 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 906 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 907 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 908 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 909 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 910 | * alpa map would take too long otherwise. |
| 911 | */ |
| 912 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 913 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 914 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 915 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
| 916 | (vport->fc_prevDID != vport->fc_myDID))) { |
| 917 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 918 | lpfc_sli4_unreg_all_rpis(vport); |
| 919 | lpfc_issue_reg_vfi(vport); |
| 920 | lpfc_nlp_put(ndlp); |
| 921 | goto out; |
| 922 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 923 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 924 | goto flogifail; |
| 925 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 926 | spin_lock_irq(shost->host_lock); |
| 927 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 928 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 929 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 930 | |
| 931 | /* |
| 932 | * The FLogI succeeded. Sync the data for the CPU before |
| 933 | * accessing it. |
| 934 | */ |
| 935 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 936 | |
| 937 | sp = prsp->virt + sizeof(uint32_t); |
| 938 | |
| 939 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 940 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 941 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 942 | "Data: x%x x%x x%x x%x\n", |
| 943 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 944 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 945 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 946 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 947 | /* |
| 948 | * If Common Service Parameters indicate Nport |
| 949 | * we are point to point, if Fport we are Fabric. |
| 950 | */ |
| 951 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 952 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 953 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 954 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 955 | else { |
| 956 | lpfc_printf_vlog(vport, KERN_ERR, |
| 957 | LOG_FIP | LOG_ELS, |
| 958 | "2831 FLOGI response with cleared Fabric " |
| 959 | "bit fcf_index 0x%x " |
| 960 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 961 | "Fabric Name " |
| 962 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 963 | phba->fcf.current_rec.fcf_indx, |
| 964 | phba->fcf.current_rec.switch_name[0], |
| 965 | phba->fcf.current_rec.switch_name[1], |
| 966 | phba->fcf.current_rec.switch_name[2], |
| 967 | phba->fcf.current_rec.switch_name[3], |
| 968 | phba->fcf.current_rec.switch_name[4], |
| 969 | phba->fcf.current_rec.switch_name[5], |
| 970 | phba->fcf.current_rec.switch_name[6], |
| 971 | phba->fcf.current_rec.switch_name[7], |
| 972 | phba->fcf.current_rec.fabric_name[0], |
| 973 | phba->fcf.current_rec.fabric_name[1], |
| 974 | phba->fcf.current_rec.fabric_name[2], |
| 975 | phba->fcf.current_rec.fabric_name[3], |
| 976 | phba->fcf.current_rec.fabric_name[4], |
| 977 | phba->fcf.current_rec.fabric_name[5], |
| 978 | phba->fcf.current_rec.fabric_name[6], |
| 979 | phba->fcf.current_rec.fabric_name[7]); |
| 980 | lpfc_nlp_put(ndlp); |
| 981 | spin_lock_irq(&phba->hbalock); |
| 982 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 983 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 984 | spin_unlock_irq(&phba->hbalock); |
| 985 | goto out; |
| 986 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 987 | if (!rc) { |
| 988 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 989 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 990 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 991 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 992 | "2769 FLOGI to FCF (x%x) " |
| 993 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 994 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 995 | spin_lock_irq(&phba->hbalock); |
| 996 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 997 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 998 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 999 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1000 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1004 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1005 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1006 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1007 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1008 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1009 | |
| 1010 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1011 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1012 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 1013 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 1014 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 1015 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 1016 | /* If FLOGI failed enable link interrupt. */ |
| 1017 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1018 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1019 | out: |
| 1020 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1021 | } |
| 1022 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1023 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1024 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1025 | * @vport: pointer to a host virtual N_Port data structure. |
| 1026 | * @ndlp: pointer to a node-list data structure. |
| 1027 | * @retry: number of retries to the command IOCB. |
| 1028 | * |
| 1029 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 1030 | * for a @vport. The initiator service parameters are put into the payload |
| 1031 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 1032 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 1033 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 1034 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 1035 | * |
| 1036 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1037 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1038 | * will be stored into the context1 field of the IOCB for the completion |
| 1039 | * callback function to the FLOGI ELS command. |
| 1040 | * |
| 1041 | * Return code |
| 1042 | * 0 - successfully issued flogi iocb for @vport |
| 1043 | * 1 - failed to issue flogi iocb for @vport |
| 1044 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1045 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1046 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1047 | uint8_t retry) |
| 1048 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1049 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1050 | struct serv_parm *sp; |
| 1051 | IOCB_t *icmd; |
| 1052 | struct lpfc_iocbq *elsiocb; |
| 1053 | struct lpfc_sli_ring *pring; |
| 1054 | uint8_t *pcmd; |
| 1055 | uint16_t cmdsize; |
| 1056 | uint32_t tmo; |
| 1057 | int rc; |
| 1058 | |
| 1059 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1060 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1061 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1062 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1063 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1064 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1065 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1066 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1067 | |
| 1068 | icmd = &elsiocb->iocb; |
| 1069 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1070 | |
| 1071 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1072 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1073 | pcmd += sizeof(uint32_t); |
| 1074 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1075 | sp = (struct serv_parm *) pcmd; |
| 1076 | |
| 1077 | /* Setup CSPs accordingly for Fabric */ |
| 1078 | sp->cmn.e_d_tov = 0; |
| 1079 | sp->cmn.w2.r_a_tov = 0; |
| 1080 | sp->cls1.classValid = 0; |
| 1081 | sp->cls2.seqDelivery = 1; |
| 1082 | sp->cls3.seqDelivery = 1; |
| 1083 | if (sp->cmn.fcphLow < FC_PH3) |
| 1084 | sp->cmn.fcphLow = FC_PH3; |
| 1085 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1086 | sp->cmn.fcphHigh = FC_PH3; |
| 1087 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 1088 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1089 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1090 | LPFC_SLI_INTF_IF_TYPE_0)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1091 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1092 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1093 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1094 | /* Set the fcfi to the fcfi we registered with */ |
| 1095 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1096 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1097 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1098 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1099 | icmd->ulpCt_h = 1; |
| 1100 | icmd->ulpCt_l = 0; |
| 1101 | } |
| 1102 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1103 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1104 | icmd->un.elsreq64.myID = 0; |
| 1105 | icmd->un.elsreq64.fl = 1; |
| 1106 | } |
| 1107 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1108 | tmo = phba->fc_ratov; |
| 1109 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1110 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1111 | phba->fc_ratov = tmo; |
| 1112 | |
| 1113 | phba->fc_stat.elsXmitFLOGI++; |
| 1114 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1115 | |
| 1116 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1117 | "Issue FLOGI: opt:x%x", |
| 1118 | phba->sli3_options, 0, 0); |
| 1119 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1120 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1121 | if (rc == IOCB_ERROR) { |
| 1122 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1123 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1124 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1125 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1126 | } |
| 1127 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1128 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1129 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1130 | * @phba: pointer to lpfc hba data structure. |
| 1131 | * |
| 1132 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1133 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1134 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1135 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1136 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1137 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1138 | * |
| 1139 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1140 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1141 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1142 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1143 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1144 | { |
| 1145 | struct lpfc_sli_ring *pring; |
| 1146 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1147 | struct lpfc_nodelist *ndlp; |
| 1148 | IOCB_t *icmd; |
| 1149 | |
| 1150 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1151 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1152 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1153 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1154 | |
| 1155 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1156 | |
| 1157 | /* |
| 1158 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1159 | * searching for. |
| 1160 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1161 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1162 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1163 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1164 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 1165 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1166 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1167 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1168 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1169 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1170 | } |
| 1171 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1172 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1173 | |
| 1174 | return 0; |
| 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_initial_flogi - Issue an initial fabric login 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 | * |
| 1181 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1182 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1183 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1184 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1185 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1186 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1187 | * @vport. |
| 1188 | * |
| 1189 | * Return code |
| 1190 | * 0 - failed to issue initial flogi for @vport |
| 1191 | * 1 - successfully issued initial flogi for @vport |
| 1192 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1193 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1194 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1195 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1196 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1197 | struct lpfc_nodelist *ndlp; |
| 1198 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1199 | vport->port_state = LPFC_FLOGI; |
| 1200 | lpfc_set_disctmo(vport); |
| 1201 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1202 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1203 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1204 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1205 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1206 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1207 | if (!ndlp) |
| 1208 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1209 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1210 | /* Set the node type */ |
| 1211 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1212 | /* Put ndlp onto node list */ |
| 1213 | lpfc_enqueue_node(vport, ndlp); |
| 1214 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1215 | /* re-setup ndlp without removing from node list */ |
| 1216 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1217 | if (!ndlp) |
| 1218 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1219 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1220 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1221 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1222 | /* This decrement of reference count to node shall kick off |
| 1223 | * the release of the node. |
| 1224 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1225 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1226 | return 0; |
| 1227 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1228 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1229 | } |
| 1230 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1231 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1232 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1233 | * @vport: pointer to a host virtual N_Port data structure. |
| 1234 | * |
| 1235 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1236 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1237 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1238 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1239 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1240 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1241 | * @vport. |
| 1242 | * |
| 1243 | * Return code |
| 1244 | * 0 - failed to issue initial fdisc for @vport |
| 1245 | * 1 - successfully issued initial fdisc for @vport |
| 1246 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1247 | int |
| 1248 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1249 | { |
| 1250 | struct lpfc_hba *phba = vport->phba; |
| 1251 | struct lpfc_nodelist *ndlp; |
| 1252 | |
| 1253 | /* First look for the Fabric ndlp */ |
| 1254 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1255 | if (!ndlp) { |
| 1256 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1257 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1258 | if (!ndlp) |
| 1259 | return 0; |
| 1260 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1261 | /* Put ndlp onto node list */ |
| 1262 | lpfc_enqueue_node(vport, ndlp); |
| 1263 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1264 | /* re-setup ndlp without removing from node list */ |
| 1265 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1266 | if (!ndlp) |
| 1267 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1268 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1269 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1270 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1271 | /* decrement node reference count to trigger the release of |
| 1272 | * the node. |
| 1273 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1274 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1275 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1276 | } |
| 1277 | return 1; |
| 1278 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1279 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1280 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1281 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1282 | * @vport: pointer to a host virtual N_Port data structure. |
| 1283 | * |
| 1284 | * This routine checks whether there are more remaining Port Logins |
| 1285 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1286 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1287 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1288 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1289 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1290 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1291 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1292 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1293 | { |
| 1294 | int sentplogi; |
| 1295 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1296 | if (vport->num_disc_nodes) |
| 1297 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1298 | |
| 1299 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1300 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1301 | "0232 Continue discovery with %d PLOGIs to go " |
| 1302 | "Data: x%x x%x x%x\n", |
| 1303 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1304 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1305 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1306 | if (vport->fc_flag & FC_NLP_MORE) |
| 1307 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1308 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1309 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1310 | return; |
| 1311 | } |
| 1312 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1313 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1314 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1315 | * @phba: pointer to lpfc hba data structure. |
| 1316 | * @prsp: pointer to response IOCB payload. |
| 1317 | * @ndlp: pointer to a node-list data structure. |
| 1318 | * |
| 1319 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1320 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1321 | * The following cases are considered N_Port confirmed: |
| 1322 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1323 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1324 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1325 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1326 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1327 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1328 | * on that node to release the RPI associated with the node; 2) if there is |
| 1329 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1330 | * into, a new node shall be allocated (or activated). In either case, the |
| 1331 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1332 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1333 | * its pointer returned as the confirmed node. |
| 1334 | * |
| 1335 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1336 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1337 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1338 | * into an inactive state on the vport node list and the vport node list |
| 1339 | * management algorithm does not allow two node with a same DID. |
| 1340 | * |
| 1341 | * Return code |
| 1342 | * pointer to the PLOGI N_Port @ndlp |
| 1343 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1344 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1345 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1346 | struct lpfc_nodelist *ndlp) |
| 1347 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1348 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1349 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1350 | struct lpfc_rport_data *rdata; |
| 1351 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1352 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1353 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1354 | uint32_t rc, keepDID = 0; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1355 | int put_node; |
| 1356 | int put_rport; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1357 | struct lpfc_node_rrqs rrq; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1358 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1359 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1360 | * by WWPN. Just return the ndlp that was given to us. |
| 1361 | */ |
| 1362 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1363 | return ndlp; |
| 1364 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1365 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1366 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1367 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1368 | /* 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] | 1369 | * we have for that ndlp. If not, we have some work to do. |
| 1370 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1371 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1372 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1373 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1374 | return ndlp; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1375 | memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1376 | |
| 1377 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1378 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1379 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1380 | if (!rc) |
| 1381 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1382 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1383 | if (!new_ndlp) |
| 1384 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1385 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1386 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1387 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1388 | sizeof(struct lpfc_name)); |
| 1389 | if (!rc) |
| 1390 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1391 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1392 | NLP_STE_UNUSED_NODE); |
| 1393 | if (!new_ndlp) |
| 1394 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1395 | keepDID = new_ndlp->nlp_DID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1396 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1397 | memcpy(&rrq.xri_bitmap, |
| 1398 | &new_ndlp->active_rrqs.xri_bitmap, |
| 1399 | sizeof(new_ndlp->active_rrqs.xri_bitmap)); |
| 1400 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1401 | keepDID = new_ndlp->nlp_DID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1402 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1403 | memcpy(&rrq.xri_bitmap, |
| 1404 | &new_ndlp->active_rrqs.xri_bitmap, |
| 1405 | sizeof(new_ndlp->active_rrqs.xri_bitmap)); |
| 1406 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1407 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1408 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1409 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1410 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1411 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1412 | memcpy(new_ndlp->active_rrqs.xri_bitmap, |
| 1413 | &ndlp->active_rrqs.xri_bitmap, |
| 1414 | sizeof(ndlp->active_rrqs.xri_bitmap)); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1415 | |
| 1416 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1417 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1418 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1419 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1420 | /* 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] | 1421 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1422 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1423 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1424 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1425 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1426 | * to put ndlp on UNUSED list and try to free it. |
| 1427 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1428 | |
| 1429 | /* Fix up the rport accordingly */ |
| 1430 | rport = ndlp->rport; |
| 1431 | if (rport) { |
| 1432 | rdata = rport->dd_data; |
| 1433 | if (rdata->pnode == ndlp) { |
| 1434 | lpfc_nlp_put(ndlp); |
| 1435 | ndlp->rport = NULL; |
| 1436 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1437 | new_ndlp->rport = rport; |
| 1438 | } |
| 1439 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1440 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1441 | /* We shall actually free the ndlp with both nlp_DID and |
| 1442 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1443 | * nodelist never to be used. |
| 1444 | */ |
| 1445 | if (ndlp->nlp_DID == 0) { |
| 1446 | spin_lock_irq(&phba->ndlp_lock); |
| 1447 | NLP_SET_FREE_REQ(ndlp); |
| 1448 | spin_unlock_irq(&phba->ndlp_lock); |
| 1449 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1450 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1451 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1452 | ndlp->nlp_DID = keepDID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1453 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1454 | memcpy(&ndlp->active_rrqs.xri_bitmap, |
| 1455 | &rrq.xri_bitmap, |
| 1456 | sizeof(ndlp->active_rrqs.xri_bitmap)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1457 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1458 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1459 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1460 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1461 | /* Two ndlps cannot have the same did */ |
| 1462 | ndlp->nlp_DID = keepDID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1463 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1464 | memcpy(&ndlp->active_rrqs.xri_bitmap, |
| 1465 | &rrq.xri_bitmap, |
| 1466 | sizeof(ndlp->active_rrqs.xri_bitmap)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1467 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1468 | /* Since we are swapping the ndlp passed in with the new one |
| 1469 | * and the did has already been swapped, copy over the |
| 1470 | * state and names. |
| 1471 | */ |
| 1472 | memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname, |
| 1473 | sizeof(struct lpfc_name)); |
| 1474 | memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename, |
| 1475 | sizeof(struct lpfc_name)); |
| 1476 | new_ndlp->nlp_state = ndlp->nlp_state; |
| 1477 | /* Fix up the rport accordingly */ |
| 1478 | rport = ndlp->rport; |
| 1479 | if (rport) { |
| 1480 | rdata = rport->dd_data; |
| 1481 | put_node = rdata->pnode != NULL; |
| 1482 | put_rport = ndlp->rport != NULL; |
| 1483 | rdata->pnode = NULL; |
| 1484 | ndlp->rport = NULL; |
| 1485 | if (put_node) |
| 1486 | lpfc_nlp_put(ndlp); |
| 1487 | if (put_rport) |
| 1488 | put_device(&rport->dev); |
| 1489 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1490 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1491 | return new_ndlp; |
| 1492 | } |
| 1493 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1494 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1495 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1496 | * @vport: pointer to a host virtual N_Port data structure. |
| 1497 | * |
| 1498 | * This routine checks whether more Registration State Change |
| 1499 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1500 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1501 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1502 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1503 | * handling the RSCNs. |
| 1504 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1505 | void |
| 1506 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1507 | { |
| 1508 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1509 | |
| 1510 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1511 | /* |
| 1512 | * Check to see if more RSCNs came in while we were |
| 1513 | * processing this one. |
| 1514 | */ |
| 1515 | if (vport->fc_rscn_id_cnt || |
| 1516 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1517 | lpfc_els_handle_rscn(vport); |
| 1518 | else { |
| 1519 | spin_lock_irq(shost->host_lock); |
| 1520 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1521 | spin_unlock_irq(shost->host_lock); |
| 1522 | } |
| 1523 | } |
| 1524 | } |
| 1525 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1526 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1527 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. |
| 1528 | * @phba: pointer to lpfc hba data structure. |
| 1529 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1530 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1531 | * |
| 1532 | * This routine will call the clear rrq function to free the rrq and |
| 1533 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not |
| 1534 | * exist then the clear_rrq is still called because the rrq needs to |
| 1535 | * be freed. |
| 1536 | **/ |
| 1537 | |
| 1538 | static void |
| 1539 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1540 | struct lpfc_iocbq *rspiocb) |
| 1541 | { |
| 1542 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1543 | IOCB_t *irsp; |
| 1544 | struct lpfc_nodelist *ndlp; |
| 1545 | struct lpfc_node_rrq *rrq; |
| 1546 | |
| 1547 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1548 | rrq = cmdiocb->context_un.rrq; |
| 1549 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1550 | |
| 1551 | irsp = &rspiocb->iocb; |
| 1552 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1553 | "RRQ cmpl: status:x%x/x%x did:x%x", |
| 1554 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1555 | irsp->un.elsreq64.remoteID); |
| 1556 | |
| 1557 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
| 1558 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { |
| 1559 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1560 | "2882 RRQ completes to NPort x%x " |
| 1561 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1562 | irsp->un.elsreq64.remoteID, |
| 1563 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1564 | irsp->ulpIoTag); |
| 1565 | goto out; |
| 1566 | } |
| 1567 | |
| 1568 | /* rrq completes to NPort <nlp_DID> */ |
| 1569 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1570 | "2880 RRQ completes to NPort x%x " |
| 1571 | "Data: x%x x%x x%x x%x x%x\n", |
| 1572 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1573 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); |
| 1574 | |
| 1575 | if (irsp->ulpStatus) { |
| 1576 | /* Check for retry */ |
| 1577 | /* RRQ failed Don't print the vport to vport rjts */ |
| 1578 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1579 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1580 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1581 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1582 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1583 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", |
| 1584 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1585 | irsp->un.ulpWord[4]); |
| 1586 | } |
| 1587 | out: |
| 1588 | if (rrq) |
| 1589 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1590 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1591 | return; |
| 1592 | } |
| 1593 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1594 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1595 | * @phba: pointer to lpfc hba data structure. |
| 1596 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1597 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1598 | * |
| 1599 | * This routine is the completion callback function for issuing the Port |
| 1600 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1601 | * 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^] | 1602 | * 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] | 1603 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1604 | * checked for error conditons. If there is error status reported, PLOGI |
| 1605 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1606 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1607 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1608 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1609 | * there are additional N_Port nodes with the vport that need to perform |
| 1610 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1611 | * PLOGIs. |
| 1612 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1613 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1614 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1615 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1616 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1617 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1618 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1619 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1620 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1621 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1622 | int disc, rc, did, type; |
| 1623 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1624 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1625 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1626 | |
| 1627 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1628 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1629 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1630 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1631 | irsp->un.elsreq64.remoteID); |
| 1632 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1633 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1634 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1635 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1636 | "0136 PLOGI completes to NPort x%x " |
| 1637 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1638 | irsp->un.elsreq64.remoteID, |
| 1639 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1640 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1641 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1642 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1643 | |
| 1644 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1645 | * is being used during discovery. |
| 1646 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1647 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1648 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1649 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1650 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1651 | rc = 0; |
| 1652 | |
| 1653 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1654 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1655 | "0102 PLOGI completes to NPort x%x " |
| 1656 | "Data: x%x x%x x%x x%x x%x\n", |
| 1657 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1658 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1659 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1660 | if (lpfc_els_chk_latt(vport)) { |
| 1661 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1662 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1663 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1664 | goto out; |
| 1665 | } |
| 1666 | |
| 1667 | /* ndlp could be freed in DSM, save these values now */ |
| 1668 | type = ndlp->nlp_type; |
| 1669 | did = ndlp->nlp_DID; |
| 1670 | |
| 1671 | if (irsp->ulpStatus) { |
| 1672 | /* Check for retry */ |
| 1673 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1674 | /* ELS command is being retried */ |
| 1675 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1676 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1677 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1678 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1679 | } |
| 1680 | goto out; |
| 1681 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1682 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1683 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1684 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1685 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1686 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1687 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1688 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1689 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1690 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1692 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1693 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1694 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1695 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1696 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1697 | } else { |
| 1698 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1699 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1700 | cmdiocb->context2)->list.next, |
| 1701 | struct lpfc_dmabuf, list); |
| 1702 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1703 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1704 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1705 | } |
| 1706 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1707 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1708 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1709 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1710 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1711 | if (vport->num_disc_nodes == 0) { |
| 1712 | spin_lock_irq(shost->host_lock); |
| 1713 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1714 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1715 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1716 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1717 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | out: |
| 1722 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1723 | return; |
| 1724 | } |
| 1725 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1726 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1727 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1728 | * @vport: pointer to a host virtual N_Port data structure. |
| 1729 | * @did: destination port identifier. |
| 1730 | * @retry: number of retries to the command IOCB. |
| 1731 | * |
| 1732 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1733 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1734 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1735 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1736 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1737 | * |
| 1738 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1739 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1740 | * will be stored into the context1 field of the IOCB for the completion |
| 1741 | * callback function to the PLOGI ELS command. |
| 1742 | * |
| 1743 | * Return code |
| 1744 | * 0 - Successfully issued a plogi for @vport |
| 1745 | * 1 - failed to issue a plogi for @vport |
| 1746 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1747 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1748 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1749 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1750 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1751 | struct serv_parm *sp; |
| 1752 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1753 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1754 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1755 | struct lpfc_sli *psli; |
| 1756 | uint8_t *pcmd; |
| 1757 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1758 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1759 | |
| 1760 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1761 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1762 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1763 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1764 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1765 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1766 | /* 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] | 1767 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1768 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1769 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1770 | if (!elsiocb) |
| 1771 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1772 | |
| 1773 | icmd = &elsiocb->iocb; |
| 1774 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1775 | |
| 1776 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1777 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1778 | pcmd += sizeof(uint32_t); |
| 1779 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1780 | sp = (struct serv_parm *) pcmd; |
| 1781 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1782 | /* |
| 1783 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 1784 | * to device on remote loops work. |
| 1785 | */ |
| 1786 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 1787 | sp->cmn.altBbCredit = 1; |
| 1788 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1789 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1790 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1791 | |
| 1792 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1793 | sp->cmn.fcphHigh = FC_PH3; |
| 1794 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1795 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1796 | "Issue PLOGI: did:x%x", |
| 1797 | did, 0, 0); |
| 1798 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1799 | phba->fc_stat.elsXmitPLOGI++; |
| 1800 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1801 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1802 | |
| 1803 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1804 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1805 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1806 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1807 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1808 | } |
| 1809 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1810 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1811 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1812 | * @phba: pointer to lpfc hba data structure. |
| 1813 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1814 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1815 | * |
| 1816 | * This routine is the completion callback function for a Process Login |
| 1817 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1818 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1819 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1820 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1821 | * ndlp to mark the PRLI completion. |
| 1822 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1823 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1824 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1825 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1826 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1827 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1828 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1829 | IOCB_t *irsp; |
| 1830 | struct lpfc_sli *psli; |
| 1831 | struct lpfc_nodelist *ndlp; |
| 1832 | |
| 1833 | psli = &phba->sli; |
| 1834 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1835 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1836 | |
| 1837 | irsp = &(rspiocb->iocb); |
| 1838 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1839 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1840 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1841 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1842 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1843 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1844 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1845 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1846 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1847 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1848 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1849 | "0103 PRLI completes to NPort x%x " |
| 1850 | "Data: x%x x%x x%x x%x\n", |
| 1851 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1852 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1853 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1854 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1855 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1856 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1857 | goto out; |
| 1858 | |
| 1859 | if (irsp->ulpStatus) { |
| 1860 | /* Check for retry */ |
| 1861 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1862 | /* ELS command is being retried */ |
| 1863 | goto out; |
| 1864 | } |
| 1865 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1866 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1867 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 1868 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1869 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1870 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1871 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1872 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1873 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1874 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1875 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1876 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1877 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1878 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1879 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1880 | out: |
| 1881 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1882 | return; |
| 1883 | } |
| 1884 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1885 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1886 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1887 | * @vport: pointer to a host virtual N_Port data structure. |
| 1888 | * @ndlp: pointer to a node-list data structure. |
| 1889 | * @retry: number of retries to the command IOCB. |
| 1890 | * |
| 1891 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1892 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1893 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1894 | * is put to the IOCB completion callback func field before invoking the |
| 1895 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1896 | * |
| 1897 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1898 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1899 | * will be stored into the context1 field of the IOCB for the completion |
| 1900 | * callback function to the PRLI ELS command. |
| 1901 | * |
| 1902 | * Return code |
| 1903 | * 0 - successfully issued prli iocb command for @vport |
| 1904 | * 1 - failed to issue prli iocb command for @vport |
| 1905 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1906 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1907 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | uint8_t retry) |
| 1909 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1910 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1911 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1912 | PRLI *npr; |
| 1913 | IOCB_t *icmd; |
| 1914 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1915 | uint8_t *pcmd; |
| 1916 | uint16_t cmdsize; |
| 1917 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1918 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1919 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1920 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1921 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1922 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1923 | |
| 1924 | icmd = &elsiocb->iocb; |
| 1925 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1926 | |
| 1927 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1928 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1929 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1930 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | |
| 1932 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1933 | npr = (PRLI *) pcmd; |
| 1934 | /* |
| 1935 | * If our firmware version is 3.20 or later, |
| 1936 | * set the following bits for FC-TAPE support. |
| 1937 | */ |
| 1938 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1939 | npr->ConfmComplAllowed = 1; |
| 1940 | npr->Retry = 1; |
| 1941 | npr->TaskRetryIdReq = 1; |
| 1942 | } |
| 1943 | npr->estabImagePair = 1; |
| 1944 | npr->readXferRdyDis = 1; |
| 1945 | |
| 1946 | /* For FCP support */ |
| 1947 | npr->prliType = PRLI_FCP_TYPE; |
| 1948 | npr->initiatorFunc = 1; |
| 1949 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1950 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1951 | "Issue PRLI: did:x%x", |
| 1952 | ndlp->nlp_DID, 0, 0); |
| 1953 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1954 | phba->fc_stat.elsXmitPRLI++; |
| 1955 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1956 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1957 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1958 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1959 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1960 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1961 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1962 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1963 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1964 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1965 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1966 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1967 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1968 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1969 | } |
| 1970 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1971 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1972 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1973 | * @vport: pointer to a host virtual N_Port data structure. |
| 1974 | * |
| 1975 | * This routine performs Registration State Change Notification (RSCN) |
| 1976 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1977 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1978 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1979 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1980 | * invoked to check and handle possible more RSCN came in during the period |
| 1981 | * of processing the current ones. |
| 1982 | **/ |
| 1983 | static void |
| 1984 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1985 | { |
| 1986 | lpfc_can_disctmo(vport); |
| 1987 | |
| 1988 | /* RSCN discovery */ |
| 1989 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1990 | if (vport->fc_npr_cnt) |
| 1991 | if (lpfc_els_disc_plogi(vport)) |
| 1992 | return; |
| 1993 | |
| 1994 | lpfc_end_rscn(vport); |
| 1995 | } |
| 1996 | |
| 1997 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1998 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1999 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 2000 | * |
| 2001 | * This function is called when the final ADISC is completed during discovery. |
| 2002 | * This function handles clearing link attention or issuing reg_vpi depending |
| 2003 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 2004 | * discovery. |
| 2005 | * This function is called with no locks held. |
| 2006 | **/ |
| 2007 | static void |
| 2008 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 2009 | { |
| 2010 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2011 | struct lpfc_hba *phba = vport->phba; |
| 2012 | |
| 2013 | /* |
| 2014 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 2015 | * and continue discovery. |
| 2016 | */ |
| 2017 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2018 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 2019 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2020 | lpfc_issue_reg_vpi(phba, vport); |
| 2021 | return; |
| 2022 | } |
| 2023 | /* |
| 2024 | * For SLI2, we need to set port_state to READY |
| 2025 | * and continue discovery. |
| 2026 | */ |
| 2027 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2028 | /* If we get here, there is nothing to ADISC */ |
| 2029 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 2030 | lpfc_issue_clear_la(phba, vport); |
| 2031 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 2032 | vport->num_disc_nodes = 0; |
| 2033 | /* go thru NPR list, issue ELS PLOGIs */ |
| 2034 | if (vport->fc_npr_cnt) |
| 2035 | lpfc_els_disc_plogi(vport); |
| 2036 | if (!vport->num_disc_nodes) { |
| 2037 | spin_lock_irq(shost->host_lock); |
| 2038 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2039 | spin_unlock_irq(shost->host_lock); |
| 2040 | lpfc_can_disctmo(vport); |
| 2041 | lpfc_end_rscn(vport); |
| 2042 | } |
| 2043 | } |
| 2044 | vport->port_state = LPFC_VPORT_READY; |
| 2045 | } else |
| 2046 | lpfc_rscn_disc(vport); |
| 2047 | } |
| 2048 | |
| 2049 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2050 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2051 | * @vport: pointer to a host virtual N_Port data structure. |
| 2052 | * |
| 2053 | * This routine determines whether there are more ndlps on a @vport |
| 2054 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 2055 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 2056 | * remaining nodes which need to have ADISC sent. |
| 2057 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2058 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2059 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2060 | { |
| 2061 | int sentadisc; |
| 2062 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2063 | if (vport->num_disc_nodes) |
| 2064 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2065 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2066 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2067 | "0210 Continue discovery with %d ADISCs to go " |
| 2068 | "Data: x%x x%x x%x\n", |
| 2069 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 2070 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2071 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2072 | if (vport->fc_flag & FC_NLP_MORE) { |
| 2073 | lpfc_set_disctmo(vport); |
| 2074 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 2075 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2077 | if (!vport->num_disc_nodes) |
| 2078 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2079 | return; |
| 2080 | } |
| 2081 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2082 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2083 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2084 | * @phba: pointer to lpfc hba data structure. |
| 2085 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2086 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2087 | * |
| 2088 | * This routine is the completion function for issuing the Address Discover |
| 2089 | * (ADISC) command. It first checks to see whether link went down during |
| 2090 | * the discovery process. If so, the node will be marked as node port |
| 2091 | * recovery for issuing discover IOCB by the link attention handler and |
| 2092 | * exit. Otherwise, the response status is checked. If error was reported |
| 2093 | * in the response status, the ADISC command shall be retried by invoking |
| 2094 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 2095 | * the response status, the state machine is invoked to set transition |
| 2096 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 2097 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2098 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2099 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2100 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2102 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2103 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2105 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2106 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2107 | |
| 2108 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2109 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2110 | |
| 2111 | irsp = &(rspiocb->iocb); |
| 2112 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2113 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2114 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2115 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 2116 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2117 | ndlp->nlp_DID); |
| 2118 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2120 | * is being used during discovery. |
| 2121 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2122 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2123 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2124 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2125 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2126 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2127 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2128 | "0104 ADISC completes to NPort x%x " |
| 2129 | "Data: x%x x%x x%x x%x x%x\n", |
| 2130 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2131 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2132 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2133 | if (lpfc_els_chk_latt(vport)) { |
| 2134 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2136 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | goto out; |
| 2138 | } |
| 2139 | |
| 2140 | if (irsp->ulpStatus) { |
| 2141 | /* Check for retry */ |
| 2142 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2143 | /* ELS command is being retried */ |
| 2144 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2145 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2147 | spin_unlock_irq(shost->host_lock); |
| 2148 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2149 | } |
| 2150 | goto out; |
| 2151 | } |
| 2152 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2153 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2154 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2155 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2156 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2157 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2158 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2159 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2160 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2161 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2163 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2164 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2165 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2166 | /* Check to see if there are more ADISCs to be sent */ |
| 2167 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2168 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | out: |
| 2170 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2171 | return; |
| 2172 | } |
| 2173 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2174 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2175 | * 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] | 2176 | * @vport: pointer to a virtual N_Port data structure. |
| 2177 | * @ndlp: pointer to a node-list data structure. |
| 2178 | * @retry: number of retries to the command IOCB. |
| 2179 | * |
| 2180 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2181 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2182 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2183 | * to issue the ADISC ELS command. |
| 2184 | * |
| 2185 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2186 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2187 | * will be stored into the context1 field of the IOCB for the completion |
| 2188 | * callback function to the ADISC ELS command. |
| 2189 | * |
| 2190 | * Return code |
| 2191 | * 0 - successfully issued adisc |
| 2192 | * 1 - failed to issue adisc |
| 2193 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2194 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2195 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | uint8_t retry) |
| 2197 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2198 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2199 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2200 | ADISC *ap; |
| 2201 | IOCB_t *icmd; |
| 2202 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2203 | uint8_t *pcmd; |
| 2204 | uint16_t cmdsize; |
| 2205 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2206 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2207 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2208 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2209 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2210 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2211 | |
| 2212 | icmd = &elsiocb->iocb; |
| 2213 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2214 | |
| 2215 | /* For ADISC request, remainder of payload is service parameters */ |
| 2216 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2217 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2218 | |
| 2219 | /* Fill in ADISC payload */ |
| 2220 | ap = (ADISC *) pcmd; |
| 2221 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2222 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2223 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2224 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2225 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2226 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2227 | "Issue ADISC: did:x%x", |
| 2228 | ndlp->nlp_DID, 0, 0); |
| 2229 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2230 | phba->fc_stat.elsXmitADISC++; |
| 2231 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2232 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2233 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2234 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2235 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2236 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2237 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2238 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2239 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2240 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2241 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2242 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2243 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2244 | } |
| 2245 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2246 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2247 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2248 | * @phba: pointer to lpfc hba data structure. |
| 2249 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2250 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2251 | * |
| 2252 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2253 | * command. If no error status was reported from the LOGO response, the |
| 2254 | * state machine of the associated ndlp shall be invoked for transition with |
| 2255 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2256 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2257 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2258 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2259 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2260 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2261 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2262 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2263 | struct lpfc_vport *vport = ndlp->vport; |
| 2264 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2265 | IOCB_t *irsp; |
| 2266 | struct lpfc_sli *psli; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2267 | struct lpfcMboxq *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2268 | |
| 2269 | psli = &phba->sli; |
| 2270 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2271 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2272 | |
| 2273 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2274 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2275 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2276 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2277 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2278 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2279 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2280 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2281 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2282 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2283 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2284 | "0105 LOGO completes to NPort x%x " |
| 2285 | "Data: x%x x%x x%x x%x\n", |
| 2286 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2287 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2288 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2289 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2290 | goto out; |
| 2291 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2292 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2293 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2294 | * which should abort all outstanding IOs. |
| 2295 | */ |
| 2296 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2297 | NLP_EVT_DEVICE_RM); |
| 2298 | goto out; |
| 2299 | } |
| 2300 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2301 | if (irsp->ulpStatus) { |
| 2302 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2303 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2304 | /* ELS command is being retried */ |
| 2305 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2306 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2307 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2308 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2309 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2310 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2311 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2312 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2313 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2314 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2315 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2316 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2317 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2318 | /* Good status, call state machine. |
| 2319 | * This will unregister the rpi if needed. |
| 2320 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2321 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2322 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2323 | out: |
| 2324 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2325 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ |
| 2326 | if ((vport->fc_flag & FC_PT2PT) && |
| 2327 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { |
| 2328 | phba->pport->fc_myDID = 0; |
| 2329 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2330 | if (mbox) { |
| 2331 | lpfc_config_link(phba, mbox); |
| 2332 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2333 | mbox->vport = vport; |
| 2334 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 2335 | MBX_NOT_FINISHED) { |
| 2336 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2337 | } |
| 2338 | } |
| 2339 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2340 | return; |
| 2341 | } |
| 2342 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2343 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2344 | * 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] | 2345 | * @vport: pointer to a virtual N_Port data structure. |
| 2346 | * @ndlp: pointer to a node-list data structure. |
| 2347 | * @retry: number of retries to the command IOCB. |
| 2348 | * |
| 2349 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2350 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2351 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2352 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2353 | * |
| 2354 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2355 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2356 | * will be stored into the context1 field of the IOCB for the completion |
| 2357 | * callback function to the LOGO ELS command. |
| 2358 | * |
| 2359 | * Return code |
| 2360 | * 0 - successfully issued logo |
| 2361 | * 1 - failed to issue logo |
| 2362 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2364 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2365 | uint8_t retry) |
| 2366 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2367 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2368 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | IOCB_t *icmd; |
| 2370 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2371 | uint8_t *pcmd; |
| 2372 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2373 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2375 | spin_lock_irq(shost->host_lock); |
| 2376 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2377 | spin_unlock_irq(shost->host_lock); |
| 2378 | return 0; |
| 2379 | } |
| 2380 | spin_unlock_irq(shost->host_lock); |
| 2381 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2382 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2383 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2384 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2385 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2386 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2387 | |
| 2388 | icmd = &elsiocb->iocb; |
| 2389 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2390 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2391 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2392 | |
| 2393 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2394 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2395 | pcmd += sizeof(uint32_t); |
| 2396 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2397 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2398 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2399 | "Issue LOGO: did:x%x", |
| 2400 | ndlp->nlp_DID, 0, 0); |
| 2401 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2402 | phba->fc_stat.elsXmitLOGO++; |
| 2403 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2404 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2405 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2406 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2407 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2408 | |
| 2409 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2410 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2411 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2412 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2413 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2414 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2415 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2416 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2417 | } |
| 2418 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2419 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2420 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2421 | * @phba: pointer to lpfc hba data structure. |
| 2422 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2423 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2424 | * |
| 2425 | * This routine is a generic completion callback function for ELS commands. |
| 2426 | * Specifically, it is the callback function which does not need to perform |
| 2427 | * any command specific operations. It is currently used by the ELS command |
| 2428 | * issuing routines for the ELS State Change Request (SCR), |
| 2429 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2430 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2431 | * certain debug loggings, this callback function simply invokes the |
| 2432 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2433 | * discovery process. |
| 2434 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2435 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2436 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2437 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2438 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2439 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | IOCB_t *irsp; |
| 2441 | |
| 2442 | irsp = &rspiocb->iocb; |
| 2443 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2444 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2445 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2446 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2447 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2448 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2449 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2450 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2451 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2452 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2453 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2454 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2455 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2456 | return; |
| 2457 | } |
| 2458 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2459 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2460 | * 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] | 2461 | * @vport: pointer to a host virtual N_Port data structure. |
| 2462 | * @nportid: N_Port identifier to the remote node. |
| 2463 | * @retry: number of retries to the command IOCB. |
| 2464 | * |
| 2465 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2466 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2467 | * first search the @vport node list to find the matching ndlp. If no such |
| 2468 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2469 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2470 | * routine is invoked to send the SCR IOCB. |
| 2471 | * |
| 2472 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2473 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2474 | * will be stored into the context1 field of the IOCB for the completion |
| 2475 | * callback function to the SCR ELS command. |
| 2476 | * |
| 2477 | * Return code |
| 2478 | * 0 - Successfully issued scr command |
| 2479 | * 1 - Failed to issue scr command |
| 2480 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2481 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2482 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2483 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2484 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2485 | IOCB_t *icmd; |
| 2486 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2487 | struct lpfc_sli *psli; |
| 2488 | uint8_t *pcmd; |
| 2489 | uint16_t cmdsize; |
| 2490 | struct lpfc_nodelist *ndlp; |
| 2491 | |
| 2492 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2493 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2494 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2495 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2496 | if (!ndlp) { |
| 2497 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2498 | if (!ndlp) |
| 2499 | return 1; |
| 2500 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2501 | lpfc_enqueue_node(vport, ndlp); |
| 2502 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2503 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2504 | if (!ndlp) |
| 2505 | return 1; |
| 2506 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2507 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2508 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2509 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2510 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2511 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2512 | /* This will trigger the release of the node just |
| 2513 | * allocated |
| 2514 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2515 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2516 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | icmd = &elsiocb->iocb; |
| 2520 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2521 | |
| 2522 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2523 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2524 | |
| 2525 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2526 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2527 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2528 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2529 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2530 | "Issue SCR: did:x%x", |
| 2531 | ndlp->nlp_DID, 0, 0); |
| 2532 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2533 | phba->fc_stat.elsXmitSCR++; |
| 2534 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2535 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2536 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2537 | /* The additional lpfc_nlp_put will cause the following |
| 2538 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2539 | * the node. |
| 2540 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2541 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2542 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2543 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2544 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2545 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2546 | * trigger the release of node. |
| 2547 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2548 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2549 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2550 | } |
| 2551 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2552 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2553 | * 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] | 2554 | * @vport: pointer to a host virtual N_Port data structure. |
| 2555 | * @nportid: N_Port identifier to the remote node. |
| 2556 | * @retry: number of retries to the command IOCB. |
| 2557 | * |
| 2558 | * This routine issues a Fibre Channel Address Resolution Response |
| 2559 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2560 | * is passed into the function. It first search the @vport node list to find |
| 2561 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2562 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2563 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2564 | * |
| 2565 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2566 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2567 | * will be stored into the context1 field of the IOCB for the completion |
| 2568 | * callback function to the PARPR ELS command. |
| 2569 | * |
| 2570 | * Return code |
| 2571 | * 0 - Successfully issued farpr command |
| 2572 | * 1 - Failed to issue farpr command |
| 2573 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2574 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2575 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2576 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2577 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2578 | IOCB_t *icmd; |
| 2579 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2580 | struct lpfc_sli *psli; |
| 2581 | FARP *fp; |
| 2582 | uint8_t *pcmd; |
| 2583 | uint32_t *lp; |
| 2584 | uint16_t cmdsize; |
| 2585 | struct lpfc_nodelist *ondlp; |
| 2586 | struct lpfc_nodelist *ndlp; |
| 2587 | |
| 2588 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2589 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2590 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2591 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2592 | if (!ndlp) { |
| 2593 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2594 | if (!ndlp) |
| 2595 | return 1; |
| 2596 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2597 | lpfc_enqueue_node(vport, ndlp); |
| 2598 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2599 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2600 | if (!ndlp) |
| 2601 | return 1; |
| 2602 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2603 | |
| 2604 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2605 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2606 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2607 | /* This will trigger the release of the node just |
| 2608 | * allocated |
| 2609 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2610 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2611 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | icmd = &elsiocb->iocb; |
| 2615 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2616 | |
| 2617 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2618 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2619 | |
| 2620 | /* Fill in FARPR payload */ |
| 2621 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2622 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2623 | lp = (uint32_t *) pcmd; |
| 2624 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2625 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2626 | fp->Rflags = 0; |
| 2627 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2628 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2629 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2630 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2631 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2632 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2633 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2634 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2635 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2636 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2637 | } |
| 2638 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2639 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2640 | "Issue FARPR: did:x%x", |
| 2641 | ndlp->nlp_DID, 0, 0); |
| 2642 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2643 | phba->fc_stat.elsXmitFARPR++; |
| 2644 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2645 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2646 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2647 | /* The additional lpfc_nlp_put will cause the following |
| 2648 | * lpfc_els_free_iocb routine to trigger the release of |
| 2649 | * the node. |
| 2650 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2651 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2652 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2653 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2654 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2655 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2656 | * trigger the release of the node. |
| 2657 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2658 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2659 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2660 | } |
| 2661 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2662 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2663 | * 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] | 2664 | * @vport: pointer to a host virtual N_Port data structure. |
| 2665 | * @nlp: pointer to a node-list data structure. |
| 2666 | * |
| 2667 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2668 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2669 | * removes the ELS retry event if it presents. In addition, if the |
| 2670 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2671 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2672 | * ADISC. |
| 2673 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2674 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2675 | 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] | 2676 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2677 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2678 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2679 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2680 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2681 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2682 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2683 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2684 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2685 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2686 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2687 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2688 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2689 | /* Decrement nlp reference count held for the delayed retry */ |
| 2690 | evtp = &nlp->els_retry_evt; |
| 2691 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2692 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2693 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2694 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2695 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2696 | spin_unlock_irq(shost->host_lock); |
| 2697 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2698 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2699 | /* Check if there are more ADISCs to be sent */ |
| 2700 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2701 | } else { |
| 2702 | /* Check if there are more PLOGIs to be sent */ |
| 2703 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2704 | if (vport->num_disc_nodes == 0) { |
| 2705 | spin_lock_irq(shost->host_lock); |
| 2706 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2707 | spin_unlock_irq(shost->host_lock); |
| 2708 | lpfc_can_disctmo(vport); |
| 2709 | lpfc_end_rscn(vport); |
| 2710 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2711 | } |
| 2712 | } |
| 2713 | } |
| 2714 | return; |
| 2715 | } |
| 2716 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2717 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2718 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2719 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2720 | * |
| 2721 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2722 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2723 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2724 | * adds the delayed events to the HBA work list and invokes the |
| 2725 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2726 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2727 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2728 | * reference to ndlp will still be available when the worker thread gets |
| 2729 | * to the event associated with the ndlp. |
| 2730 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2731 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2732 | lpfc_els_retry_delay(unsigned long ptr) |
| 2733 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2734 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2735 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2736 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2737 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2738 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2739 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2740 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2742 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2743 | return; |
| 2744 | } |
| 2745 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2746 | /* We need to hold the node by incrementing the reference |
| 2747 | * count until the queued work is done |
| 2748 | */ |
| 2749 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2750 | if (evtp->evt_arg1) { |
| 2751 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2752 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2753 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2754 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2755 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2756 | return; |
| 2757 | } |
| 2758 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2759 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2760 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2761 | * @ndlp: pointer to a node-list data structure. |
| 2762 | * |
| 2763 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2764 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2765 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2766 | * function according to the delayed ELS command to retry the command. |
| 2767 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2768 | void |
| 2769 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2770 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2771 | struct lpfc_vport *vport = ndlp->vport; |
| 2772 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2773 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2774 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2775 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2776 | did = ndlp->nlp_DID; |
| 2777 | cmd = ndlp->nlp_last_elscmd; |
| 2778 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2779 | |
| 2780 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2781 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2782 | return; |
| 2783 | } |
| 2784 | |
| 2785 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2786 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2787 | /* |
| 2788 | * If a discovery event readded nlp_delayfunc after timer |
| 2789 | * firing and before processing the timer, cancel the |
| 2790 | * nlp_delayfunc. |
| 2791 | */ |
| 2792 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2793 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2794 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2795 | |
| 2796 | switch (cmd) { |
| 2797 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2798 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2799 | break; |
| 2800 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2801 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2802 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2803 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2804 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2805 | break; |
| 2806 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2807 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2808 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2809 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2810 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2811 | break; |
| 2812 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2813 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2814 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2815 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2816 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | break; |
| 2818 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2819 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2820 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2821 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2822 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2823 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2824 | case ELS_CMD_FDISC: |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2825 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
| 2826 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2827 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2828 | } |
| 2829 | return; |
| 2830 | } |
| 2831 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2832 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2833 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2834 | * @phba: pointer to lpfc hba data structure. |
| 2835 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2836 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2837 | * |
| 2838 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2839 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2840 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2841 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2842 | * returned error status, it makes the decision whether a retry shall be |
| 2843 | * issued for the command, and whether a retry shall be made immediately or |
| 2844 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2845 | * is called to retry the command. In the later case, the ELS command shall |
| 2846 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2847 | * ndlp for the delayed command issusing. |
| 2848 | * |
| 2849 | * Return code |
| 2850 | * 0 - No retry of els command is made |
| 2851 | * 1 - Immediate or delayed retry of els command is made |
| 2852 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2853 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2854 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2855 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2856 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2857 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2858 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2859 | IOCB_t *irsp = &rspiocb->iocb; |
| 2860 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2861 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2862 | uint32_t *elscmd; |
| 2863 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2864 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2865 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2866 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2867 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2868 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2869 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2870 | /* Note: context2 may be 0 for internal driver abort |
| 2871 | * of delays ELS command. |
| 2872 | */ |
| 2873 | |
| 2874 | if (pcmd && pcmd->virt) { |
| 2875 | elscmd = (uint32_t *) (pcmd->virt); |
| 2876 | cmd = *elscmd++; |
| 2877 | } |
| 2878 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2879 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2880 | did = ndlp->nlp_DID; |
| 2881 | else { |
| 2882 | /* We should only hit this case for retrying PLOGI */ |
| 2883 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2884 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2885 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2886 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2887 | return 1; |
| 2888 | } |
| 2889 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2890 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2891 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2892 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2893 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2894 | switch (irsp->ulpStatus) { |
| 2895 | case IOSTAT_FCP_RSP_ERROR: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2896 | break; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2897 | case IOSTAT_REMOTE_STOP: |
| 2898 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2899 | /* This IO was aborted by the target, we don't |
| 2900 | * know the rxid and because we did not send the |
| 2901 | * ABTS we cannot generate and RRQ. |
| 2902 | */ |
| 2903 | lpfc_set_rrq_active(phba, ndlp, |
| 2904 | cmdiocb->sli4_xritag, 0, 0); |
| 2905 | } |
| 2906 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2907 | case IOSTAT_LOCAL_REJECT: |
| 2908 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2909 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2910 | if (cmd == ELS_CMD_FLOGI) { |
| 2911 | if (PCI_DEVICE_ID_HORNET == |
| 2912 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2913 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2914 | phba->pport->fc_myDID = 0; |
| 2915 | phba->alpa_map[0] = 0; |
| 2916 | phba->alpa_map[1] = 0; |
| 2917 | } |
| 2918 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2919 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2920 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2921 | retry = 1; |
| 2922 | break; |
| 2923 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2924 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2925 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2926 | "0124 Retry illegal cmd x%x " |
| 2927 | "retry:x%x delay:x%x\n", |
| 2928 | cmd, cmdiocb->retry, delay); |
| 2929 | retry = 1; |
| 2930 | /* All command's retry policy */ |
| 2931 | maxretry = 8; |
| 2932 | if (cmdiocb->retry > 2) |
| 2933 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2934 | break; |
| 2935 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2936 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2937 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2938 | retry = 1; |
| 2939 | if (cmdiocb->retry > 100) |
| 2940 | delay = 100; |
| 2941 | maxretry = 250; |
| 2942 | break; |
| 2943 | |
| 2944 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2945 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2946 | retry = 1; |
| 2947 | break; |
| 2948 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2949 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2950 | case IOERR_INVALID_RPI: |
| 2951 | retry = 1; |
| 2952 | break; |
| 2953 | } |
| 2954 | break; |
| 2955 | |
| 2956 | case IOSTAT_NPORT_RJT: |
| 2957 | case IOSTAT_FABRIC_RJT: |
| 2958 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2959 | retry = 1; |
| 2960 | break; |
| 2961 | } |
| 2962 | break; |
| 2963 | |
| 2964 | case IOSTAT_NPORT_BSY: |
| 2965 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2966 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2967 | retry = 1; |
| 2968 | break; |
| 2969 | |
| 2970 | case IOSTAT_LS_RJT: |
| 2971 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2972 | /* Added for Vendor specifc support |
| 2973 | * Just keep retrying for these Rsn / Exp codes |
| 2974 | */ |
| 2975 | switch (stat.un.b.lsRjtRsnCode) { |
| 2976 | case LSRJT_UNABLE_TPC: |
| 2977 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2978 | LSEXP_CMD_IN_PROGRESS) { |
| 2979 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2980 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2981 | maxretry = 48; |
| 2982 | } |
| 2983 | retry = 1; |
| 2984 | break; |
| 2985 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 2986 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2987 | LSEXP_CANT_GIVE_DATA) { |
| 2988 | if (cmd == ELS_CMD_PLOGI) { |
| 2989 | delay = 1000; |
| 2990 | maxretry = 48; |
| 2991 | } |
| 2992 | retry = 1; |
| 2993 | break; |
| 2994 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2995 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2996 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2997 | maxretry = lpfc_max_els_tries + 1; |
| 2998 | retry = 1; |
| 2999 | break; |
| 3000 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3001 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3002 | (cmd == ELS_CMD_FDISC) && |
| 3003 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3004 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3005 | "0125 FDISC Failed (x%x). " |
| 3006 | "Fabric out of resources\n", |
| 3007 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3008 | lpfc_vport_set_state(vport, |
| 3009 | FC_VPORT_NO_FABRIC_RSCS); |
| 3010 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3011 | break; |
| 3012 | |
| 3013 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3014 | if ((cmd == ELS_CMD_PLOGI) || |
| 3015 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3016 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3017 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3018 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3019 | /* FDISC retry policy */ |
| 3020 | maxretry = 48; |
| 3021 | if (cmdiocb->retry >= 32) |
| 3022 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3023 | } |
| 3024 | retry = 1; |
| 3025 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3026 | |
| 3027 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3028 | /* There are some cases where switches return this |
| 3029 | * error when they are not ready and should be returning |
| 3030 | * Logical Busy. We should delay every time. |
| 3031 | */ |
| 3032 | if (cmd == ELS_CMD_FDISC && |
| 3033 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 3034 | maxretry = 3; |
| 3035 | delay = 1000; |
| 3036 | retry = 1; |
| 3037 | break; |
| 3038 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3039 | case LSRJT_PROTOCOL_ERR: |
| 3040 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3041 | (cmd == ELS_CMD_FDISC) && |
| 3042 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 3043 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 3044 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3045 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3046 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3047 | "Fabric Detected Bad WWN\n", |
| 3048 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3049 | lpfc_vport_set_state(vport, |
| 3050 | FC_VPORT_FABRIC_REJ_WWN); |
| 3051 | } |
| 3052 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3053 | } |
| 3054 | break; |
| 3055 | |
| 3056 | case IOSTAT_INTERMED_RSP: |
| 3057 | case IOSTAT_BA_RJT: |
| 3058 | break; |
| 3059 | |
| 3060 | default: |
| 3061 | break; |
| 3062 | } |
| 3063 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3064 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3065 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3066 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3067 | if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3068 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 3069 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3070 | /* FLOGI retry policy */ |
| 3071 | retry = 1; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3072 | /* retry forever */ |
| 3073 | maxretry = 0; |
| 3074 | if (cmdiocb->retry >= 100) |
| 3075 | delay = 5000; |
| 3076 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3077 | delay = 1000; |
| 3078 | } |
| 3079 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3080 | cmdiocb->retry++; |
| 3081 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | phba->fc_stat.elsRetryExceeded++; |
| 3083 | retry = 0; |
| 3084 | } |
| 3085 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3086 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 3087 | retry = 0; |
| 3088 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3089 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3090 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 3091 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 3092 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 3093 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3094 | "2849 Stop retry ELS command " |
| 3095 | "x%x to remote NPORT x%x, " |
| 3096 | "Data: x%x x%x\n", cmd, did, |
| 3097 | cmdiocb->retry, delay); |
| 3098 | return 0; |
| 3099 | } |
| 3100 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3101 | |
| 3102 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3103 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3104 | "0107 Retry ELS command x%x to remote " |
| 3105 | "NPORT x%x Data: x%x x%x\n", |
| 3106 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3107 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3108 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 3109 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 3110 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 3111 | /* Don't reset timer for no resources */ |
| 3112 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3113 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3114 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3115 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3116 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3120 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3121 | phba->fc_stat.elsDelayRetry++; |
| 3122 | ndlp->nlp_retry = cmdiocb->retry; |
| 3123 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3124 | /* delay is specified in milliseconds */ |
| 3125 | mod_timer(&ndlp->nlp_delayfunc, |
| 3126 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3127 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3128 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3129 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3130 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3131 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3132 | if (cmd == ELS_CMD_PRLI) |
| 3133 | lpfc_nlp_set_state(vport, ndlp, |
| 3134 | NLP_STE_REG_LOGIN_ISSUE); |
| 3135 | else |
| 3136 | lpfc_nlp_set_state(vport, ndlp, |
| 3137 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3138 | ndlp->nlp_last_elscmd = cmd; |
| 3139 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3140 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3141 | } |
| 3142 | switch (cmd) { |
| 3143 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3144 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3145 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3146 | case ELS_CMD_FDISC: |
| 3147 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 3148 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3149 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3150 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3151 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3152 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3153 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3154 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3155 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3156 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3157 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3158 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3159 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3160 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3161 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3162 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3163 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3164 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 3165 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3166 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3167 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3168 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3169 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 3170 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3171 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3172 | } |
| 3173 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3174 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3175 | if (logerr) { |
| 3176 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3177 | "0137 No retry ELS command x%x to remote " |
| 3178 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 3179 | cmd, did, irsp->ulpStatus, |
| 3180 | irsp->un.ulpWord[4]); |
| 3181 | } |
| 3182 | else { |
| 3183 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3184 | "0108 No retry ELS command x%x to remote " |
| 3185 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 3186 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 3187 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3188 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3189 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3190 | } |
| 3191 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3192 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3193 | * 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] | 3194 | * @phba: pointer to lpfc hba data structure. |
| 3195 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3196 | * |
| 3197 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3198 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3199 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3200 | * response of the command IOCB. If so, it will be released before releasing |
| 3201 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3202 | * |
| 3203 | * Return code |
| 3204 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3205 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3206 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3207 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3208 | { |
| 3209 | struct lpfc_dmabuf *buf_ptr; |
| 3210 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3211 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3212 | if (!list_empty(&buf_ptr1->list)) { |
| 3213 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3214 | struct lpfc_dmabuf, |
| 3215 | list); |
| 3216 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3217 | kfree(buf_ptr); |
| 3218 | } |
| 3219 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3220 | kfree(buf_ptr1); |
| 3221 | return 0; |
| 3222 | } |
| 3223 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3224 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3225 | * 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] | 3226 | * @phba: pointer to lpfc hba data structure. |
| 3227 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3228 | * |
| 3229 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3230 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3231 | * pool. |
| 3232 | * |
| 3233 | * Return code |
| 3234 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3235 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3236 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3237 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3238 | { |
| 3239 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3240 | kfree(buf_ptr); |
| 3241 | return 0; |
| 3242 | } |
| 3243 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3244 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3245 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3246 | * @phba: pointer to lpfc hba data structure. |
| 3247 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3248 | * |
| 3249 | * This routine frees a command IOCB and its associated resources. The |
| 3250 | * command IOCB data structure contains the reference to various associated |
| 3251 | * resources, these fields must be set to NULL if the associated reference |
| 3252 | * not present: |
| 3253 | * context1 - reference to ndlp |
| 3254 | * context2 - reference to cmd |
| 3255 | * context2->next - reference to rsp |
| 3256 | * context3 - reference to bpl |
| 3257 | * |
| 3258 | * It first properly decrements the reference count held on ndlp for the |
| 3259 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3260 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3261 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3262 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3263 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3264 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3265 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3266 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3267 | * |
| 3268 | * Return code |
| 3269 | * 0 - Success (currently, always return 0) |
| 3270 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3271 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3272 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3273 | { |
| 3274 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3275 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3276 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3277 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3278 | if (ndlp) { |
| 3279 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3280 | lpfc_nlp_put(ndlp); |
| 3281 | |
| 3282 | /* If the ndlp is not being used by another discovery |
| 3283 | * thread, free it. |
| 3284 | */ |
| 3285 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3286 | /* If ndlp is being used by another discovery |
| 3287 | * thread, just clear NLP_DEFER_RM |
| 3288 | */ |
| 3289 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3290 | } |
| 3291 | } |
| 3292 | else |
| 3293 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3294 | elsiocb->context1 = NULL; |
| 3295 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3296 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3297 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3298 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3299 | /* Firmware could still be in progress of DMAing |
| 3300 | * payload, so don't free data buffer till after |
| 3301 | * a hbeat. |
| 3302 | */ |
| 3303 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3304 | buf_ptr = elsiocb->context2; |
| 3305 | elsiocb->context2 = NULL; |
| 3306 | if (buf_ptr) { |
| 3307 | buf_ptr1 = NULL; |
| 3308 | spin_lock_irq(&phba->hbalock); |
| 3309 | if (!list_empty(&buf_ptr->list)) { |
| 3310 | list_remove_head(&buf_ptr->list, |
| 3311 | buf_ptr1, struct lpfc_dmabuf, |
| 3312 | list); |
| 3313 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3314 | list_add_tail(&buf_ptr1->list, |
| 3315 | &phba->elsbuf); |
| 3316 | phba->elsbuf_cnt++; |
| 3317 | } |
| 3318 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3319 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3320 | phba->elsbuf_cnt++; |
| 3321 | spin_unlock_irq(&phba->hbalock); |
| 3322 | } |
| 3323 | } else { |
| 3324 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3325 | lpfc_els_free_data(phba, buf_ptr1); |
| 3326 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | if (elsiocb->context3) { |
| 3330 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3331 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3332 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3333 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3334 | return 0; |
| 3335 | } |
| 3336 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3337 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3338 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3339 | * @phba: pointer to lpfc hba data structure. |
| 3340 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3341 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3342 | * |
| 3343 | * This routine is the completion callback function to the Logout (LOGO) |
| 3344 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3345 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3346 | * release the ndlp if it has the last reference remaining (reference count |
| 3347 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3348 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3349 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3350 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3351 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3352 | * IOCB data structure. |
| 3353 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3354 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3355 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3356 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3357 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3358 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3359 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3360 | IOCB_t *irsp; |
| 3361 | |
| 3362 | irsp = &rspiocb->iocb; |
| 3363 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3364 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3365 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3366 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3367 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3368 | "0109 ACC to LOGO completes to NPort x%x " |
| 3369 | "Data: x%x x%x x%x\n", |
| 3370 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3371 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3372 | |
| 3373 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3374 | /* NPort Recovery mode or node is just allocated */ |
| 3375 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3376 | /* If the ndlp is being used by another discovery |
| 3377 | * thread, just unregister the RPI. |
| 3378 | */ |
| 3379 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3380 | } else { |
| 3381 | /* Indicate the node has already released, should |
| 3382 | * not reference to it from within lpfc_els_free_iocb. |
| 3383 | */ |
| 3384 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3385 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | } |
| 3387 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3388 | return; |
| 3389 | } |
| 3390 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3391 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3392 | * 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] | 3393 | * @phba: pointer to lpfc hba data structure. |
| 3394 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3395 | * |
| 3396 | * This routine is the completion callback function for unregister default |
| 3397 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3398 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3399 | * decrements the ndlp reference count held for this completion callback |
| 3400 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3401 | * whether there is only one reference left on the ndlp. If so, it will |
| 3402 | * perform one more decrement and trigger the release of the ndlp. |
| 3403 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3404 | void |
| 3405 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3406 | { |
| 3407 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3408 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3409 | |
| 3410 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3411 | pmb->context2 = NULL; |
| 3412 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3413 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3414 | kfree(mp); |
| 3415 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3416 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3417 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3418 | /* This is the end of the default RPI cleanup logic for this |
| 3419 | * ndlp. If no other discovery threads are using this ndlp. |
| 3420 | * we should free all resources associated with it. |
| 3421 | */ |
| 3422 | lpfc_nlp_not_used(ndlp); |
| 3423 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3424 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3425 | return; |
| 3426 | } |
| 3427 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3428 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3429 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3430 | * @phba: pointer to lpfc hba data structure. |
| 3431 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3432 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3433 | * |
| 3434 | * This routine is the completion callback function for ELS Response IOCB |
| 3435 | * command. In normal case, this callback function just properly sets the |
| 3436 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3437 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3438 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3439 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3440 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3441 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3442 | * are currently referring it. |
| 3443 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3444 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3445 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3446 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3447 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3448 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3449 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3450 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3451 | IOCB_t *irsp; |
| 3452 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3454 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3455 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3456 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3457 | irsp = &rspiocb->iocb; |
| 3458 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3459 | if (cmdiocb->context_un.mbox) |
| 3460 | mbox = cmdiocb->context_un.mbox; |
| 3461 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3462 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3463 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3464 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3465 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3466 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3467 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3468 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3469 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3470 | */ |
| 3471 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3472 | ls_rjt = 1; |
| 3473 | } |
| 3474 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3475 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3476 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3477 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3478 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3479 | if (mp) { |
| 3480 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3481 | kfree(mp); |
| 3482 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3483 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3485 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3486 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3487 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3488 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3489 | /* Indicate the node has already released, |
| 3490 | * should not reference to it from within |
| 3491 | * the routine lpfc_els_free_iocb. |
| 3492 | */ |
| 3493 | cmdiocb->context1 = NULL; |
| 3494 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3495 | goto out; |
| 3496 | } |
| 3497 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3498 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3499 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3500 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3501 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3502 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3503 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3504 | "0110 ELS response tag x%x completes " |
| 3505 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3506 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3507 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3508 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3509 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3510 | if (mbox) { |
| 3511 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3512 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3513 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3514 | /* Increment reference count to ndlp to hold the |
| 3515 | * reference to ndlp for the callback function. |
| 3516 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3517 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3518 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3519 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3520 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3521 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3522 | } |
| 3523 | else { |
| 3524 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3525 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3526 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3527 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3528 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3529 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3530 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3531 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3532 | else |
| 3533 | /* Decrement the ndlp reference count we |
| 3534 | * set for this failed mailbox command. |
| 3535 | */ |
| 3536 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3537 | |
| 3538 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3539 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3540 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3541 | "Data: x%x x%x x%x\n", |
| 3542 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3543 | ndlp->nlp_rpi); |
| 3544 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3545 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3546 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3547 | /* Indicate node has already been released, |
| 3548 | * should not reference to it from within |
| 3549 | * the routine lpfc_els_free_iocb. |
| 3550 | */ |
| 3551 | cmdiocb->context1 = NULL; |
| 3552 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3553 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3554 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3555 | if (!lpfc_error_lost_link(irsp) && |
| 3556 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3557 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3558 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3559 | /* Indicate node has already been |
| 3560 | * released, should not reference |
| 3561 | * to it from within the routine |
| 3562 | * lpfc_els_free_iocb. |
| 3563 | */ |
| 3564 | cmdiocb->context1 = NULL; |
| 3565 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3566 | } |
| 3567 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3568 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3569 | if (mp) { |
| 3570 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3571 | kfree(mp); |
| 3572 | } |
| 3573 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3574 | } |
| 3575 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3576 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3577 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3578 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3579 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3580 | |
| 3581 | /* If the node is not being used by another discovery thread, |
| 3582 | * and we are sending a reject, we are done with it. |
| 3583 | * Release driver reference count here and free associated |
| 3584 | * resources. |
| 3585 | */ |
| 3586 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3587 | if (lpfc_nlp_not_used(ndlp)) |
| 3588 | /* Indicate node has already been released, |
| 3589 | * should not reference to it from within |
| 3590 | * the routine lpfc_els_free_iocb. |
| 3591 | */ |
| 3592 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3593 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3594 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3595 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3596 | return; |
| 3597 | } |
| 3598 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3599 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3600 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3601 | * @vport: pointer to a host virtual N_Port data structure. |
| 3602 | * @flag: the els command code to be accepted. |
| 3603 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3604 | * @ndlp: pointer to a node-list data structure. |
| 3605 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3606 | * |
| 3607 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3608 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3609 | * specific ACC response command to be issued and invokes the |
| 3610 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3611 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3612 | * field of the IOCB for the completion callback function to issue the |
| 3613 | * mailbox command to the HBA later when callback is invoked. |
| 3614 | * |
| 3615 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3616 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3617 | * will be stored into the context1 field of the IOCB for the completion |
| 3618 | * callback function to the corresponding response ELS IOCB command. |
| 3619 | * |
| 3620 | * Return code |
| 3621 | * 0 - Successfully issued acc response |
| 3622 | * 1 - Failed to issue acc response |
| 3623 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3624 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3625 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3626 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3627 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3628 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3629 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3630 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3631 | IOCB_t *icmd; |
| 3632 | IOCB_t *oldcmd; |
| 3633 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3634 | struct lpfc_sli *psli; |
| 3635 | uint8_t *pcmd; |
| 3636 | uint16_t cmdsize; |
| 3637 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3638 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3639 | |
| 3640 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3641 | oldcmd = &oldiocb->iocb; |
| 3642 | |
| 3643 | switch (flag) { |
| 3644 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3645 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3646 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3647 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3648 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3649 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3650 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3651 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3652 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3653 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3654 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3655 | icmd = &elsiocb->iocb; |
| 3656 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3657 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3658 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3659 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3660 | |
| 3661 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3662 | "Issue ACC: did:x%x flg:x%x", |
| 3663 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3664 | break; |
| 3665 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3666 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3667 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3668 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3669 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3670 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3671 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3672 | icmd = &elsiocb->iocb; |
| 3673 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3674 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3675 | |
| 3676 | if (mbox) |
| 3677 | elsiocb->context_un.mbox = mbox; |
| 3678 | |
| 3679 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3680 | pcmd += sizeof(uint32_t); |
| 3681 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3682 | |
| 3683 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3684 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3685 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3686 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3687 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3688 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3689 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3690 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3691 | if (!elsiocb) |
| 3692 | return 1; |
| 3693 | |
| 3694 | icmd = &elsiocb->iocb; |
| 3695 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3696 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3697 | |
| 3698 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3699 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3700 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3701 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3702 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3703 | |
| 3704 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3705 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3706 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3707 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3708 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3709 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3710 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3711 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3712 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3713 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3714 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3715 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3716 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3717 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3718 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3719 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3720 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3721 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3722 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3723 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3724 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3725 | } |
| 3726 | |
| 3727 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3728 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3729 | if (rc == IOCB_ERROR) { |
| 3730 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3731 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3732 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3733 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3734 | } |
| 3735 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3736 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3737 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3738 | * @vport: pointer to a virtual N_Port data structure. |
| 3739 | * @rejectError: |
| 3740 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3741 | * @ndlp: pointer to a node-list data structure. |
| 3742 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3743 | * |
| 3744 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3745 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3746 | * context_un.mbox field of the IOCB for the completion callback function |
| 3747 | * to issue to the HBA later. |
| 3748 | * |
| 3749 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3750 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3751 | * will be stored into the context1 field of the IOCB for the completion |
| 3752 | * callback function to the reject response ELS IOCB command. |
| 3753 | * |
| 3754 | * Return code |
| 3755 | * 0 - Successfully issued reject response |
| 3756 | * 1 - Failed to issue reject response |
| 3757 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3758 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3759 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3760 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3761 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3762 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3763 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3764 | IOCB_t *icmd; |
| 3765 | IOCB_t *oldcmd; |
| 3766 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3767 | struct lpfc_sli *psli; |
| 3768 | uint8_t *pcmd; |
| 3769 | uint16_t cmdsize; |
| 3770 | int rc; |
| 3771 | |
| 3772 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3773 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3774 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3775 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3776 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3777 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3778 | |
| 3779 | icmd = &elsiocb->iocb; |
| 3780 | oldcmd = &oldiocb->iocb; |
| 3781 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3782 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3783 | |
| 3784 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3785 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3786 | *((uint32_t *) (pcmd)) = rejectError; |
| 3787 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3788 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3789 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3790 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3791 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3792 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3793 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3794 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3795 | "rpi x%x\n", |
| 3796 | rejectError, elsiocb->iotag, |
| 3797 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3798 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3799 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3800 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3801 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3802 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3803 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3804 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3805 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3806 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3807 | if (rc == IOCB_ERROR) { |
| 3808 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3809 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3810 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3811 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3812 | } |
| 3813 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3814 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3815 | * 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] | 3816 | * @vport: pointer to a virtual N_Port data structure. |
| 3817 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3818 | * @ndlp: pointer to a node-list data structure. |
| 3819 | * |
| 3820 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3821 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3822 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3823 | * |
| 3824 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3825 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3826 | * will be stored into the context1 field of the IOCB for the completion |
| 3827 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3828 | * |
| 3829 | * Return code |
| 3830 | * 0 - Successfully issued acc adisc response |
| 3831 | * 1 - Failed to issue adisc acc response |
| 3832 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3833 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3834 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3835 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3836 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3837 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3838 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3839 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3840 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3841 | uint8_t *pcmd; |
| 3842 | uint16_t cmdsize; |
| 3843 | int rc; |
| 3844 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3845 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3846 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3847 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3848 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3849 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3850 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3851 | icmd = &elsiocb->iocb; |
| 3852 | oldcmd = &oldiocb->iocb; |
| 3853 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3854 | |
| 3855 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3856 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3857 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3858 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3859 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3860 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3861 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3862 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3863 | |
| 3864 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3865 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3866 | |
| 3867 | ap = (ADISC *) (pcmd); |
| 3868 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3869 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3870 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3871 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3872 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3873 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3874 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3875 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3876 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3877 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3878 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3879 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3880 | if (rc == IOCB_ERROR) { |
| 3881 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3882 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3883 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3884 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3885 | } |
| 3886 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3887 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3888 | * 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] | 3889 | * @vport: pointer to a virtual N_Port data structure. |
| 3890 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3891 | * @ndlp: pointer to a node-list data structure. |
| 3892 | * |
| 3893 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3894 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3895 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3896 | * |
| 3897 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3898 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3899 | * will be stored into the context1 field of the IOCB for the completion |
| 3900 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3901 | * |
| 3902 | * Return code |
| 3903 | * 0 - Successfully issued acc prli response |
| 3904 | * 1 - Failed to issue acc prli response |
| 3905 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3906 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3907 | 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] | 3908 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3910 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3911 | PRLI *npr; |
| 3912 | lpfc_vpd_t *vpd; |
| 3913 | IOCB_t *icmd; |
| 3914 | IOCB_t *oldcmd; |
| 3915 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3916 | struct lpfc_sli *psli; |
| 3917 | uint8_t *pcmd; |
| 3918 | uint16_t cmdsize; |
| 3919 | int rc; |
| 3920 | |
| 3921 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3922 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3923 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3924 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3925 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3926 | if (!elsiocb) |
| 3927 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3928 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3929 | icmd = &elsiocb->iocb; |
| 3930 | oldcmd = &oldiocb->iocb; |
| 3931 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3932 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3933 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3934 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3935 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3936 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3937 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3938 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3939 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3940 | |
| 3941 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3942 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3943 | |
| 3944 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3945 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3946 | |
| 3947 | npr = (PRLI *) pcmd; |
| 3948 | vpd = &phba->vpd; |
| 3949 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3950 | * If the remote port is a target and our firmware version is 3.20 or |
| 3951 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3952 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3953 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3954 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3955 | npr->ConfmComplAllowed = 1; |
| 3956 | npr->Retry = 1; |
| 3957 | npr->TaskRetryIdReq = 1; |
| 3958 | } |
| 3959 | |
| 3960 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3961 | npr->estabImagePair = 1; |
| 3962 | npr->readXferRdyDis = 1; |
| 3963 | npr->ConfmComplAllowed = 1; |
| 3964 | |
| 3965 | npr->prliType = PRLI_FCP_TYPE; |
| 3966 | npr->initiatorFunc = 1; |
| 3967 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3968 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3969 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3970 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3971 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3972 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3973 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3974 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3975 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3976 | if (rc == IOCB_ERROR) { |
| 3977 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3978 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3979 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3980 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3981 | } |
| 3982 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3983 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3984 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3985 | * @vport: pointer to a virtual N_Port data structure. |
| 3986 | * @format: rnid command format. |
| 3987 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3988 | * @ndlp: pointer to a node-list data structure. |
| 3989 | * |
| 3990 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3991 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3992 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3993 | * issue the response. Note that this command does not need to hold the ndlp |
| 3994 | * reference count for the callback. So, the ndlp reference count taken by |
| 3995 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3996 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3997 | * there is no ndlp reference available. |
| 3998 | * |
| 3999 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4000 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4001 | * will be stored into the context1 field of the IOCB for the completion |
| 4002 | * callback function. However, for the RNID Accept Response ELS command, |
| 4003 | * this is undone later by this routine after the IOCB is allocated. |
| 4004 | * |
| 4005 | * Return code |
| 4006 | * 0 - Successfully issued acc rnid response |
| 4007 | * 1 - Failed to issue acc rnid response |
| 4008 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4009 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4010 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4011 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4012 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4013 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4014 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4015 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4016 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4017 | struct lpfc_sli *psli; |
| 4018 | uint8_t *pcmd; |
| 4019 | uint16_t cmdsize; |
| 4020 | int rc; |
| 4021 | |
| 4022 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4023 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 4024 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4025 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4026 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4027 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4028 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4029 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4030 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4031 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4032 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4033 | icmd = &elsiocb->iocb; |
| 4034 | oldcmd = &oldiocb->iocb; |
| 4035 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4036 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4037 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4038 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 4039 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4040 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4041 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4042 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4043 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4044 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4045 | rn = (RNID *) (pcmd); |
| 4046 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4047 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 4048 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4049 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4050 | switch (format) { |
| 4051 | case 0: |
| 4052 | rn->SpecificLen = 0; |
| 4053 | break; |
| 4054 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4055 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4056 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4057 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4058 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 4059 | rn->un.topologyDisc.physPort = 0; |
| 4060 | rn->un.topologyDisc.attachedNodes = 0; |
| 4061 | break; |
| 4062 | default: |
| 4063 | rn->CommonLen = 0; |
| 4064 | rn->SpecificLen = 0; |
| 4065 | break; |
| 4066 | } |
| 4067 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4068 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4069 | "Issue ACC RNID: did:x%x flg:x%x", |
| 4070 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4071 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4072 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4073 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4074 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4075 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 4076 | * it could be freed */ |
| 4077 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4078 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | if (rc == IOCB_ERROR) { |
| 4080 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4081 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4083 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4084 | } |
| 4085 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4086 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4087 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. |
| 4088 | * @vport: pointer to a virtual N_Port data structure. |
| 4089 | * @iocb: pointer to the lpfc command iocb data structure. |
| 4090 | * @ndlp: pointer to a node-list data structure. |
| 4091 | * |
| 4092 | * Return |
| 4093 | **/ |
| 4094 | static void |
| 4095 | lpfc_els_clear_rrq(struct lpfc_vport *vport, |
| 4096 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
| 4097 | { |
| 4098 | struct lpfc_hba *phba = vport->phba; |
| 4099 | uint8_t *pcmd; |
| 4100 | struct RRQ *rrq; |
| 4101 | uint16_t rxid; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4102 | uint16_t xri; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4103 | struct lpfc_node_rrq *prrq; |
| 4104 | |
| 4105 | |
| 4106 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); |
| 4107 | pcmd += sizeof(uint32_t); |
| 4108 | rrq = (struct RRQ *)pcmd; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4109 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
| 4110 | rxid = be16_to_cpu(bf_get(rrq_rxid, rrq)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4111 | |
| 4112 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4113 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" |
| 4114 | " x%x x%x\n", |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4115 | be32_to_cpu(bf_get(rrq_did, rrq)), |
| 4116 | be16_to_cpu(bf_get(rrq_oxid, rrq)), |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4117 | rxid, |
| 4118 | iocb->iotag, iocb->iocb.ulpContext); |
| 4119 | |
| 4120 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4121 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", |
| 4122 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4123 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
| 4124 | xri = be16_to_cpu(bf_get(rrq_oxid, rrq)); |
| 4125 | else |
| 4126 | xri = rxid; |
| 4127 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4128 | if (prrq) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4129 | lpfc_clr_rrq_active(phba, xri, prrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4130 | return; |
| 4131 | } |
| 4132 | |
| 4133 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4134 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 4135 | * @vport: pointer to a virtual N_Port data structure. |
| 4136 | * @data: pointer to echo data to return in the accept. |
| 4137 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4138 | * @ndlp: pointer to a node-list data structure. |
| 4139 | * |
| 4140 | * Return code |
| 4141 | * 0 - Successfully issued acc echo response |
| 4142 | * 1 - Failed to issue acc echo response |
| 4143 | **/ |
| 4144 | static int |
| 4145 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 4146 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 4147 | { |
| 4148 | struct lpfc_hba *phba = vport->phba; |
| 4149 | struct lpfc_iocbq *elsiocb; |
| 4150 | struct lpfc_sli *psli; |
| 4151 | uint8_t *pcmd; |
| 4152 | uint16_t cmdsize; |
| 4153 | int rc; |
| 4154 | |
| 4155 | psli = &phba->sli; |
| 4156 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 4157 | |
| 4158 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4159 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4160 | if (!elsiocb) |
| 4161 | return 1; |
| 4162 | |
| 4163 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */ |
| 4164 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 4165 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4166 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 4167 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 4168 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4169 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4170 | pcmd += sizeof(uint32_t); |
| 4171 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 4172 | |
| 4173 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4174 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 4175 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4176 | |
| 4177 | phba->fc_stat.elsXmitACC++; |
| 4178 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 4179 | lpfc_nlp_put(ndlp); |
| 4180 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 4181 | * it could be freed */ |
| 4182 | |
| 4183 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4184 | if (rc == IOCB_ERROR) { |
| 4185 | lpfc_els_free_iocb(phba, elsiocb); |
| 4186 | return 1; |
| 4187 | } |
| 4188 | return 0; |
| 4189 | } |
| 4190 | |
| 4191 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4192 | * 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] | 4193 | * @vport: pointer to a host virtual N_Port data structure. |
| 4194 | * |
| 4195 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 4196 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 4197 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 4198 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 4199 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 4200 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 4201 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 4202 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 4203 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 4204 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 4205 | * no more ADISC need to be sent. |
| 4206 | * |
| 4207 | * Return code |
| 4208 | * The number of N_Ports with adisc issued. |
| 4209 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4210 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4211 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4212 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4213 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4215 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4216 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4217 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4218 | 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] | 4219 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4220 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4221 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4222 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4223 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4224 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4225 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4226 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4227 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4228 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4229 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4230 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4231 | vport->num_disc_nodes++; |
| 4232 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4233 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4234 | spin_lock_irq(shost->host_lock); |
| 4235 | vport->fc_flag |= FC_NLP_MORE; |
| 4236 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4237 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4238 | } |
| 4239 | } |
| 4240 | } |
| 4241 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4242 | spin_lock_irq(shost->host_lock); |
| 4243 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4244 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4245 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4246 | return sentadisc; |
| 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_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] | 4251 | * @vport: pointer to a host virtual N_Port data structure. |
| 4252 | * |
| 4253 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4254 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4255 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4256 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4257 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4258 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4259 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4260 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4261 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4262 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4263 | * PLOGI need to be sent. |
| 4264 | * |
| 4265 | * Return code |
| 4266 | * The number of N_Ports with plogi issued. |
| 4267 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4268 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4269 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4270 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4271 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4272 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4273 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4274 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4275 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4276 | 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] | 4277 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4278 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4279 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4280 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4281 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4282 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 4283 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4284 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4285 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4286 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4287 | vport->num_disc_nodes++; |
| 4288 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4289 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4290 | spin_lock_irq(shost->host_lock); |
| 4291 | vport->fc_flag |= FC_NLP_MORE; |
| 4292 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4293 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4294 | } |
| 4295 | } |
| 4296 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4297 | if (sentplogi) { |
| 4298 | lpfc_set_disctmo(vport); |
| 4299 | } |
| 4300 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4301 | spin_lock_irq(shost->host_lock); |
| 4302 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4303 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4304 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4305 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4306 | } |
| 4307 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4308 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4309 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4310 | * @vport: pointer to a host virtual N_Port data structure. |
| 4311 | * |
| 4312 | * This routine cleans up any Registration State Change Notification |
| 4313 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 4314 | * @vport together with the host_lock is used to prevent multiple thread |
| 4315 | * trying to access the RSCN array on a same @vport at the same time. |
| 4316 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4317 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4318 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4319 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4320 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4321 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4322 | int i; |
| 4323 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4324 | spin_lock_irq(shost->host_lock); |
| 4325 | if (vport->fc_rscn_flush) { |
| 4326 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4327 | spin_unlock_irq(shost->host_lock); |
| 4328 | return; |
| 4329 | } |
| 4330 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 4331 | vport->fc_rscn_flush = 1; |
| 4332 | spin_unlock_irq(shost->host_lock); |
| 4333 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4334 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4335 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4336 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4337 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4338 | spin_lock_irq(shost->host_lock); |
| 4339 | vport->fc_rscn_id_cnt = 0; |
| 4340 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 4341 | spin_unlock_irq(shost->host_lock); |
| 4342 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4343 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 4344 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4345 | } |
| 4346 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4347 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4348 | * 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] | 4349 | * @vport: pointer to a host virtual N_Port data structure. |
| 4350 | * @did: remote destination port identifier. |
| 4351 | * |
| 4352 | * This routine checks whether there is any pending Registration State |
| 4353 | * Configuration Notification (RSCN) to a @did on @vport. |
| 4354 | * |
| 4355 | * Return code |
| 4356 | * None zero - The @did matched with a pending rscn |
| 4357 | * 0 - not able to match @did with a pending rscn |
| 4358 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4359 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4360 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4361 | { |
| 4362 | D_ID ns_did; |
| 4363 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4364 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4365 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4366 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4367 | |
| 4368 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4369 | |
| 4370 | /* Never match fabric nodes for RSCNs */ |
| 4371 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4372 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | |
| 4374 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4375 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4376 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4377 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4378 | spin_lock_irq(shost->host_lock); |
| 4379 | if (vport->fc_rscn_flush) { |
| 4380 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4381 | spin_unlock_irq(shost->host_lock); |
| 4382 | return 0; |
| 4383 | } |
| 4384 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4385 | vport->fc_rscn_flush = 1; |
| 4386 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4387 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4388 | lp = vport->fc_rscn_id_list[i]->virt; |
| 4389 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4390 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4391 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4392 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 4393 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4394 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 4395 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4396 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4397 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 4398 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4399 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4400 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4401 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4402 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4403 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4404 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4405 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4406 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4407 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4408 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4409 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4410 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4411 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4412 | } |
| 4413 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4414 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4415 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4416 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4417 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4418 | return_did_out: |
| 4419 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4420 | vport->fc_rscn_flush = 0; |
| 4421 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4422 | } |
| 4423 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4424 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4425 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4426 | * @vport: pointer to a host virtual N_Port data structure. |
| 4427 | * |
| 4428 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 4429 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 4430 | * State Change Notification). |
| 4431 | * |
| 4432 | * Return code |
| 4433 | * 0 - Successful (currently alway return 0) |
| 4434 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4435 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4436 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4437 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4438 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4439 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4440 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4441 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4442 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4443 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4444 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4445 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4446 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4447 | NLP_EVT_DEVICE_RECOVERY); |
| 4448 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4449 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4450 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4451 | } |
| 4452 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4453 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4454 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4455 | * @vport: pointer to a host virtual N_Port data structure. |
| 4456 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4457 | * |
| 4458 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4459 | * applications. |
| 4460 | */ |
| 4461 | static void |
| 4462 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4463 | struct lpfc_iocbq *cmdiocb) |
| 4464 | { |
| 4465 | struct lpfc_dmabuf *pcmd; |
| 4466 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4467 | uint32_t *payload_ptr; |
| 4468 | uint32_t payload_len; |
| 4469 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4470 | |
| 4471 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4472 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4473 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4474 | |
| 4475 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4476 | payload_len, GFP_KERNEL); |
| 4477 | if (!rscn_event_data) { |
| 4478 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4479 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4480 | return; |
| 4481 | } |
| 4482 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4483 | rscn_event_data->payload_length = payload_len; |
| 4484 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4485 | payload_len); |
| 4486 | |
| 4487 | fc_host_post_vendor_event(shost, |
| 4488 | fc_get_event_number(), |
| 4489 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4490 | (char *)rscn_event_data, |
| 4491 | LPFC_NL_VENDOR_ID); |
| 4492 | |
| 4493 | kfree(rscn_event_data); |
| 4494 | } |
| 4495 | |
| 4496 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4497 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4498 | * @vport: pointer to a host virtual N_Port data structure. |
| 4499 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4500 | * @ndlp: pointer to a node-list data structure. |
| 4501 | * |
| 4502 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4503 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4504 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4505 | * discover state machine is about to begin discovery, it just accepts the |
| 4506 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4507 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4508 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4509 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4510 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4511 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4512 | * routine is invoked to handle the RSCN event. |
| 4513 | * |
| 4514 | * Return code |
| 4515 | * 0 - Just sent the acc response |
| 4516 | * 1 - Sent the acc response and waited for name server completion |
| 4517 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4518 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4519 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4520 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4521 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4522 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4523 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4524 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4525 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4526 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4527 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4528 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4529 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4530 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4531 | |
| 4532 | icmd = &cmdiocb->iocb; |
| 4533 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4534 | lp = (uint32_t *) pcmd->virt; |
| 4535 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4536 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4537 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4538 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4539 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4540 | "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] | 4541 | vport->fc_flag, payload_len, *lp, |
| 4542 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4543 | |
| 4544 | /* Send an RSCN event to the management application */ |
| 4545 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4546 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4547 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4548 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4549 | FCH_EVT_RSCN, lp[i]); |
| 4550 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4551 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4552 | * Discovery processing will satisfy it. |
| 4553 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4554 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4555 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4556 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4557 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4558 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4559 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4560 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4561 | } |
| 4562 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4563 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4564 | * just ACC and ignore it. |
| 4565 | */ |
| 4566 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4567 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4568 | i = payload_len; |
| 4569 | datap = lp; |
| 4570 | while (i > 0) { |
| 4571 | nportid = *datap++; |
| 4572 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4573 | i -= sizeof(uint32_t); |
| 4574 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4575 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4576 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4577 | } |
| 4578 | if (rscn_id == hba_id) { |
| 4579 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4580 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4581 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4582 | "Data: x%x x%x x%x x%x\n", |
| 4583 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4584 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4585 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4586 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4587 | ndlp->nlp_DID, vport->port_state, |
| 4588 | ndlp->nlp_flag); |
| 4589 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4590 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4591 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4592 | return 0; |
| 4593 | } |
| 4594 | } |
| 4595 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4596 | spin_lock_irq(shost->host_lock); |
| 4597 | if (vport->fc_rscn_flush) { |
| 4598 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4599 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4600 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4601 | /* Send back ACC */ |
| 4602 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4603 | return 0; |
| 4604 | } |
| 4605 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4606 | vport->fc_rscn_flush = 1; |
| 4607 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4608 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4609 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4610 | /* If we are already processing an RSCN, save the received |
| 4611 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4612 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4613 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4614 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4615 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4616 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4617 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4618 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4619 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4620 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4621 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4622 | vport->fc_flag |= FC_RSCN_MODE; |
| 4623 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4624 | if (rscn_cnt) { |
| 4625 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4626 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4627 | } |
| 4628 | if ((rscn_cnt) && |
| 4629 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4630 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4631 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4632 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4633 | payload_len); |
| 4634 | } else { |
| 4635 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4636 | vport->fc_rscn_id_cnt++; |
| 4637 | /* If we zero, cmdiocb->context2, the calling |
| 4638 | * routine will not try to free it. |
| 4639 | */ |
| 4640 | cmdiocb->context2 = NULL; |
| 4641 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4642 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4643 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4644 | "0235 Deferred RSCN " |
| 4645 | "Data: x%x x%x x%x\n", |
| 4646 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4647 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4648 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4649 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4650 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4651 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4652 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4653 | "0234 ReDiscovery RSCN " |
| 4654 | "Data: x%x x%x x%x\n", |
| 4655 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4656 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4657 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4658 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4659 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4660 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4661 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4662 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4663 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4664 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4665 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4666 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4667 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4668 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4669 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4670 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4671 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4672 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4673 | spin_lock_irq(shost->host_lock); |
| 4674 | vport->fc_flag |= FC_RSCN_MODE; |
| 4675 | spin_unlock_irq(shost->host_lock); |
| 4676 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4677 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4678 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4679 | /* |
| 4680 | * If we zero, cmdiocb->context2, the calling routine will |
| 4681 | * not try to free it. |
| 4682 | */ |
| 4683 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4684 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4685 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4686 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4687 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4688 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4689 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4690 | } |
| 4691 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4692 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4693 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4694 | * @vport: pointer to a host virtual N_Port data structure. |
| 4695 | * |
| 4696 | * This routine handles the Registration State Configuration Notification |
| 4697 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4698 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4699 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4700 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4701 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4702 | * RSCN activities with the @vport. |
| 4703 | * |
| 4704 | * Return code |
| 4705 | * 0 - Cleaned up rscn on the @vport |
| 4706 | * 1 - Wait for plogi to name server before proceed |
| 4707 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4708 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4709 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4710 | { |
| 4711 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4712 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4713 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4714 | /* Ignore RSCN if the port is being torn down. */ |
| 4715 | if (vport->load_flag & FC_UNLOADING) { |
| 4716 | lpfc_els_flush_rscn(vport); |
| 4717 | return 0; |
| 4718 | } |
| 4719 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4720 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4721 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4722 | |
| 4723 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4724 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4725 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4726 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4727 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4728 | |
| 4729 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4730 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4731 | vport->num_disc_nodes = 0; |
| 4732 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4733 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4734 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4735 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4736 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4737 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4738 | /* Wait for NameServer query cmpl before we can |
| 4739 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4740 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4741 | } else { |
| 4742 | /* If login to NameServer does not exist, issue one */ |
| 4743 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4744 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4745 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4746 | /* Wait for NameServer login cmpl before we can |
| 4747 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4748 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4749 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4750 | if (ndlp) { |
| 4751 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4752 | NLP_STE_PLOGI_ISSUE); |
| 4753 | if (!ndlp) { |
| 4754 | lpfc_els_flush_rscn(vport); |
| 4755 | return 0; |
| 4756 | } |
| 4757 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4758 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4759 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4760 | if (!ndlp) { |
| 4761 | lpfc_els_flush_rscn(vport); |
| 4762 | return 0; |
| 4763 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4764 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4765 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4766 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4767 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4768 | ndlp->nlp_type |= NLP_FABRIC; |
| 4769 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4770 | /* Wait for NameServer login cmpl before we can |
| 4771 | * continue |
| 4772 | */ |
| 4773 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4774 | } |
| 4775 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4776 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4777 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4778 | } |
| 4779 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4780 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4781 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4782 | * @vport: pointer to a host virtual N_Port data structure. |
| 4783 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4784 | * @ndlp: pointer to a node-list data structure. |
| 4785 | * |
| 4786 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4787 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4788 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4789 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4790 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4791 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4792 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4793 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4794 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4795 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4796 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4797 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4798 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4799 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4800 | * |
| 4801 | * Return code |
| 4802 | * 0 - Successfully processed the unsolicited flogi |
| 4803 | * 1 - Failed to process the unsolicited flogi |
| 4804 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4805 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4806 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4807 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4808 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4809 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4810 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4811 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4812 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4813 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4814 | struct serv_parm *sp; |
| 4815 | LPFC_MBOXQ_t *mbox; |
| 4816 | struct ls_rjt stat; |
| 4817 | uint32_t cmd, did; |
| 4818 | int rc; |
| 4819 | |
| 4820 | cmd = *lp++; |
| 4821 | sp = (struct serv_parm *) lp; |
| 4822 | |
| 4823 | /* FLOGI received */ |
| 4824 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4825 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4826 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4827 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4828 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4829 | did = icmd->un.elsreq64.remoteID; |
| 4830 | |
| 4831 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4832 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4833 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4834 | "0113 An FLOGI ELS command x%x was " |
| 4835 | "received from DID x%x in Loop Mode\n", |
| 4836 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4837 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | did = Fabric_DID; |
| 4841 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4842 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4843 | /* For a FLOGI we accept, then if our portname is greater |
| 4844 | * then the remote portname we initiate Nport login. |
| 4845 | */ |
| 4846 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4847 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4848 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4849 | |
| 4850 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4851 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4852 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4853 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4854 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4855 | lpfc_linkdown(phba); |
| 4856 | lpfc_init_link(phba, mbox, |
| 4857 | phba->cfg_topology, |
| 4858 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4859 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4860 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4861 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4862 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4863 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4864 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4865 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4866 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4867 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4868 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4869 | spin_lock_irq(shost->host_lock); |
| 4870 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4871 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4872 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4873 | spin_lock_irq(shost->host_lock); |
| 4874 | vport->fc_flag |= FC_PT2PT; |
| 4875 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4876 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4877 | } else { |
| 4878 | /* Reject this request because invalid parameters */ |
| 4879 | stat.un.b.lsRjtRsvd0 = 0; |
| 4880 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4881 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4882 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4883 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4884 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4885 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4886 | } |
| 4887 | |
| 4888 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4889 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4890 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4891 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4892 | } |
| 4893 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4894 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4895 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4896 | * @vport: pointer to a host virtual N_Port data structure. |
| 4897 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4898 | * @ndlp: pointer to a node-list data structure. |
| 4899 | * |
| 4900 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4901 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4902 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4903 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4904 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4905 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4906 | * |
| 4907 | * Return code |
| 4908 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4909 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4910 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4911 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4912 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4913 | { |
| 4914 | struct lpfc_dmabuf *pcmd; |
| 4915 | uint32_t *lp; |
| 4916 | IOCB_t *icmd; |
| 4917 | RNID *rn; |
| 4918 | struct ls_rjt stat; |
| 4919 | uint32_t cmd, did; |
| 4920 | |
| 4921 | icmd = &cmdiocb->iocb; |
| 4922 | did = icmd->un.elsreq64.remoteID; |
| 4923 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4924 | lp = (uint32_t *) pcmd->virt; |
| 4925 | |
| 4926 | cmd = *lp++; |
| 4927 | rn = (RNID *) lp; |
| 4928 | |
| 4929 | /* RNID received */ |
| 4930 | |
| 4931 | switch (rn->Format) { |
| 4932 | case 0: |
| 4933 | case RNID_TOPOLOGY_DISC: |
| 4934 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4935 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4936 | break; |
| 4937 | default: |
| 4938 | /* Reject this request because format not supported */ |
| 4939 | stat.un.b.lsRjtRsvd0 = 0; |
| 4940 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4941 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4942 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4943 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4944 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4945 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4946 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4947 | } |
| 4948 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4949 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4950 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 4951 | * @vport: pointer to a host virtual N_Port data structure. |
| 4952 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4953 | * @ndlp: pointer to a node-list data structure. |
| 4954 | * |
| 4955 | * Return code |
| 4956 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 4957 | **/ |
| 4958 | static int |
| 4959 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4960 | struct lpfc_nodelist *ndlp) |
| 4961 | { |
| 4962 | uint8_t *pcmd; |
| 4963 | |
| 4964 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 4965 | |
| 4966 | /* skip over first word of echo command to find echo data */ |
| 4967 | pcmd += sizeof(uint32_t); |
| 4968 | |
| 4969 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 4970 | return 0; |
| 4971 | } |
| 4972 | |
| 4973 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4974 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4975 | * @vport: pointer to a host virtual N_Port data structure. |
| 4976 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4977 | * @ndlp: pointer to a node-list data structure. |
| 4978 | * |
| 4979 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4980 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4981 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4982 | * |
| 4983 | * Return code |
| 4984 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4985 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4986 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4987 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4988 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4989 | { |
| 4990 | struct ls_rjt stat; |
| 4991 | |
| 4992 | /* For now, unconditionally reject this command */ |
| 4993 | stat.un.b.lsRjtRsvd0 = 0; |
| 4994 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4995 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4996 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4997 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4998 | return 0; |
| 4999 | } |
| 5000 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5001 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5002 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 5003 | * @vport: pointer to a host virtual N_Port data structure. |
| 5004 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5005 | * @ndlp: pointer to a node-list data structure. |
| 5006 | * |
| 5007 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 5008 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 5009 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 5010 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 5011 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 5012 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 5013 | * command request" and reason code explanation "Invalid Originator |
| 5014 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 5015 | * RRQ from the target. |
| 5016 | **/ |
| 5017 | static void |
| 5018 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5019 | struct lpfc_nodelist *ndlp) |
| 5020 | { |
| 5021 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5022 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 5023 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5027 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 5028 | * @phba: pointer to lpfc hba data structure. |
| 5029 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5030 | * |
| 5031 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 5032 | * mailbox command. This callback function is to actually send the Accept |
| 5033 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 5034 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 5035 | * mailbox command, constructs the RPS response with the link statistics |
| 5036 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 5037 | * response to the RPS. |
| 5038 | * |
| 5039 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5040 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5041 | * will be stored into the context1 field of the IOCB for the completion |
| 5042 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5043 | * |
| 5044 | **/ |
| 5045 | static void |
| 5046 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5047 | { |
| 5048 | MAILBOX_t *mb; |
| 5049 | IOCB_t *icmd; |
| 5050 | struct RLS_RSP *rls_rsp; |
| 5051 | uint8_t *pcmd; |
| 5052 | struct lpfc_iocbq *elsiocb; |
| 5053 | struct lpfc_nodelist *ndlp; |
| 5054 | uint16_t xri; |
| 5055 | uint32_t cmdsize; |
| 5056 | |
| 5057 | mb = &pmb->u.mb; |
| 5058 | |
| 5059 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5060 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
| 5061 | pmb->context1 = NULL; |
| 5062 | pmb->context2 = NULL; |
| 5063 | |
| 5064 | if (mb->mbxStatus) { |
| 5065 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5066 | return; |
| 5067 | } |
| 5068 | |
| 5069 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
| 5070 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5071 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5072 | lpfc_max_els_tries, ndlp, |
| 5073 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5074 | |
| 5075 | /* Decrement the ndlp reference count from previous mbox command */ |
| 5076 | lpfc_nlp_put(ndlp); |
| 5077 | |
| 5078 | if (!elsiocb) |
| 5079 | return; |
| 5080 | |
| 5081 | icmd = &elsiocb->iocb; |
| 5082 | icmd->ulpContext = xri; |
| 5083 | |
| 5084 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5085 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5086 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 5087 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 5088 | |
| 5089 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 5090 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 5091 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 5092 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 5093 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 5094 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
| 5095 | |
| 5096 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 5097 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5098 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 5099 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 5100 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5101 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5102 | ndlp->nlp_rpi); |
| 5103 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5104 | phba->fc_stat.elsXmitACC++; |
| 5105 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 5106 | lpfc_els_free_iocb(phba, elsiocb); |
| 5107 | } |
| 5108 | |
| 5109 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5110 | * 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] | 5111 | * @phba: pointer to lpfc hba data structure. |
| 5112 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5113 | * |
| 5114 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 5115 | * mailbox command. This callback function is to actually send the Accept |
| 5116 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 5117 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 5118 | * mailbox command, constructs the RPS response with the link statistics |
| 5119 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 5120 | * response to the RPS. |
| 5121 | * |
| 5122 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5123 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5124 | * will be stored into the context1 field of the IOCB for the completion |
| 5125 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5126 | * |
| 5127 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5128 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5129 | 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] | 5130 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5131 | MAILBOX_t *mb; |
| 5132 | IOCB_t *icmd; |
| 5133 | RPS_RSP *rps_rsp; |
| 5134 | uint8_t *pcmd; |
| 5135 | struct lpfc_iocbq *elsiocb; |
| 5136 | struct lpfc_nodelist *ndlp; |
| 5137 | uint16_t xri, status; |
| 5138 | uint32_t cmdsize; |
| 5139 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5140 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5141 | |
| 5142 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5143 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 5144 | pmb->context1 = NULL; |
| 5145 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5146 | |
| 5147 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5148 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5149 | return; |
| 5150 | } |
| 5151 | |
| 5152 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5153 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5154 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5155 | lpfc_max_els_tries, ndlp, |
| 5156 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5157 | |
| 5158 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5159 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5160 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5161 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5162 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5163 | |
| 5164 | icmd = &elsiocb->iocb; |
| 5165 | icmd->ulpContext = xri; |
| 5166 | |
| 5167 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5168 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5169 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5170 | rps_rsp = (RPS_RSP *)pcmd; |
| 5171 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5172 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5173 | status = 0x10; |
| 5174 | else |
| 5175 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5176 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5177 | status |= 0x4; |
| 5178 | |
| 5179 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5180 | rps_rsp->portStatus = cpu_to_be16(status); |
| 5181 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 5182 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 5183 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 5184 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 5185 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 5186 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5187 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5188 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5189 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 5190 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 5191 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5192 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5193 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5194 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5195 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5196 | 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] | 5197 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5198 | return; |
| 5199 | } |
| 5200 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5201 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5202 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 5203 | * @vport: pointer to a host virtual N_Port data structure. |
| 5204 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5205 | * @ndlp: pointer to a node-list data structure. |
| 5206 | * |
| 5207 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 5208 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5209 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5210 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 5211 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 5212 | * for reading the HBA link statistics. It is for the callback function, |
| 5213 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 5214 | * to actually sending out RPL Accept (ACC) response. |
| 5215 | * |
| 5216 | * Return codes |
| 5217 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 5218 | **/ |
| 5219 | static int |
| 5220 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5221 | struct lpfc_nodelist *ndlp) |
| 5222 | { |
| 5223 | struct lpfc_hba *phba = vport->phba; |
| 5224 | LPFC_MBOXQ_t *mbox; |
| 5225 | struct lpfc_dmabuf *pcmd; |
| 5226 | struct ls_rjt stat; |
| 5227 | |
| 5228 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5229 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5230 | /* reject the unsolicited RPS request and done with it */ |
| 5231 | goto reject_out; |
| 5232 | |
| 5233 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5234 | |
| 5235 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5236 | if (mbox) { |
| 5237 | lpfc_read_lnk_stat(phba, mbox); |
| 5238 | mbox->context1 = |
| 5239 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
| 5240 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5241 | mbox->vport = vport; |
| 5242 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 5243 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 5244 | != MBX_NOT_FINISHED) |
| 5245 | /* Mbox completion will send ELS Response */ |
| 5246 | return 0; |
| 5247 | /* Decrement reference count used for the failed mbox |
| 5248 | * command. |
| 5249 | */ |
| 5250 | lpfc_nlp_put(ndlp); |
| 5251 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5252 | } |
| 5253 | reject_out: |
| 5254 | /* issue rejection response */ |
| 5255 | stat.un.b.lsRjtRsvd0 = 0; |
| 5256 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5257 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5258 | stat.un.b.vendorUnique = 0; |
| 5259 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5260 | return 0; |
| 5261 | } |
| 5262 | |
| 5263 | /** |
| 5264 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 5265 | * @vport: pointer to a host virtual N_Port data structure. |
| 5266 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5267 | * @ndlp: pointer to a node-list data structure. |
| 5268 | * |
| 5269 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 5270 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5271 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5272 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 5273 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 5274 | * Value (RTV) unsolicited IOCB event. |
| 5275 | * |
| 5276 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5277 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5278 | * will be stored into the context1 field of the IOCB for the completion |
| 5279 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5280 | * |
| 5281 | * Return codes |
| 5282 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 5283 | **/ |
| 5284 | static int |
| 5285 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5286 | struct lpfc_nodelist *ndlp) |
| 5287 | { |
| 5288 | struct lpfc_hba *phba = vport->phba; |
| 5289 | struct ls_rjt stat; |
| 5290 | struct RTV_RSP *rtv_rsp; |
| 5291 | uint8_t *pcmd; |
| 5292 | struct lpfc_iocbq *elsiocb; |
| 5293 | uint32_t cmdsize; |
| 5294 | |
| 5295 | |
| 5296 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5297 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5298 | /* reject the unsolicited RPS request and done with it */ |
| 5299 | goto reject_out; |
| 5300 | |
| 5301 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 5302 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5303 | lpfc_max_els_tries, ndlp, |
| 5304 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5305 | |
| 5306 | if (!elsiocb) |
| 5307 | return 1; |
| 5308 | |
| 5309 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5310 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5311 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 5312 | |
| 5313 | /* use the command's xri in the response */ |
| 5314 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; |
| 5315 | |
| 5316 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 5317 | |
| 5318 | /* populate RTV payload */ |
| 5319 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 5320 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 5321 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 5322 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 5323 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 5324 | |
| 5325 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 5326 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5327 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 5328 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 5329 | "Data: x%x x%x x%x\n", |
| 5330 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5331 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5332 | ndlp->nlp_rpi, |
| 5333 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 5334 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5335 | phba->fc_stat.elsXmitACC++; |
| 5336 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 5337 | lpfc_els_free_iocb(phba, elsiocb); |
| 5338 | return 0; |
| 5339 | |
| 5340 | reject_out: |
| 5341 | /* issue rejection response */ |
| 5342 | stat.un.b.lsRjtRsvd0 = 0; |
| 5343 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5344 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5345 | stat.un.b.vendorUnique = 0; |
| 5346 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5347 | return 0; |
| 5348 | } |
| 5349 | |
| 5350 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5351 | * @vport: pointer to a host virtual N_Port data structure. |
| 5352 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5353 | * @ndlp: pointer to a node-list data structure. |
| 5354 | * |
| 5355 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 5356 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5357 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5358 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 5359 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 5360 | * for reading the HBA link statistics. It is for the callback function, |
| 5361 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 5362 | * to actually sending out RPS Accept (ACC) response. |
| 5363 | * |
| 5364 | * Return codes |
| 5365 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 5366 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5367 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5368 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5369 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5370 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5371 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5372 | uint32_t *lp; |
| 5373 | uint8_t flag; |
| 5374 | LPFC_MBOXQ_t *mbox; |
| 5375 | struct lpfc_dmabuf *pcmd; |
| 5376 | RPS *rps; |
| 5377 | struct ls_rjt stat; |
| 5378 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5379 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5380 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5381 | /* reject the unsolicited RPS request and done with it */ |
| 5382 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5383 | |
| 5384 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5385 | lp = (uint32_t *) pcmd->virt; |
| 5386 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 5387 | rps = (RPS *) lp; |
| 5388 | |
| 5389 | if ((flag == 0) || |
| 5390 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5391 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5392 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5393 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5394 | printk("Fix me....\n"); |
| 5395 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5396 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5397 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5398 | lpfc_read_lnk_stat(phba, mbox); |
| 5399 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5400 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5401 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5402 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5403 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5404 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5405 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5406 | /* Mbox completion will send ELS Response */ |
| 5407 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5408 | /* Decrement reference count used for the failed mbox |
| 5409 | * command. |
| 5410 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5411 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5412 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5413 | } |
| 5414 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5415 | |
| 5416 | reject_out: |
| 5417 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5418 | stat.un.b.lsRjtRsvd0 = 0; |
| 5419 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5420 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5421 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5422 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5423 | return 0; |
| 5424 | } |
| 5425 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5426 | /* lpfc_issue_els_rrq - Process an unsolicited rps iocb |
| 5427 | * @vport: pointer to a host virtual N_Port data structure. |
| 5428 | * @ndlp: pointer to a node-list data structure. |
| 5429 | * @did: DID of the target. |
| 5430 | * @rrq: Pointer to the rrq struct. |
| 5431 | * |
| 5432 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is |
| 5433 | * Successful the the completion handler will clear the RRQ. |
| 5434 | * |
| 5435 | * Return codes |
| 5436 | * 0 - Successfully sent rrq els iocb. |
| 5437 | * 1 - Failed to send rrq els iocb. |
| 5438 | **/ |
| 5439 | static int |
| 5440 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5441 | uint32_t did, struct lpfc_node_rrq *rrq) |
| 5442 | { |
| 5443 | struct lpfc_hba *phba = vport->phba; |
| 5444 | struct RRQ *els_rrq; |
| 5445 | IOCB_t *icmd; |
| 5446 | struct lpfc_iocbq *elsiocb; |
| 5447 | uint8_t *pcmd; |
| 5448 | uint16_t cmdsize; |
| 5449 | int ret; |
| 5450 | |
| 5451 | |
| 5452 | if (ndlp != rrq->ndlp) |
| 5453 | ndlp = rrq->ndlp; |
| 5454 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5455 | return 1; |
| 5456 | |
| 5457 | /* If ndlp is not NULL, we will bump the reference count on it */ |
| 5458 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); |
| 5459 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, |
| 5460 | ELS_CMD_RRQ); |
| 5461 | if (!elsiocb) |
| 5462 | return 1; |
| 5463 | |
| 5464 | icmd = &elsiocb->iocb; |
| 5465 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5466 | |
| 5467 | /* For RRQ request, remainder of payload is Exchange IDs */ |
| 5468 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; |
| 5469 | pcmd += sizeof(uint32_t); |
| 5470 | els_rrq = (struct RRQ *) pcmd; |
| 5471 | |
| 5472 | bf_set(rrq_oxid, els_rrq, rrq->xritag); |
| 5473 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
| 5474 | bf_set(rrq_did, els_rrq, vport->fc_myDID); |
| 5475 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); |
| 5476 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); |
| 5477 | |
| 5478 | |
| 5479 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5480 | "Issue RRQ: did:x%x", |
| 5481 | did, rrq->xritag, rrq->rxid); |
| 5482 | elsiocb->context_un.rrq = rrq; |
| 5483 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; |
| 5484 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5485 | |
| 5486 | if (ret == IOCB_ERROR) { |
| 5487 | lpfc_els_free_iocb(phba, elsiocb); |
| 5488 | return 1; |
| 5489 | } |
| 5490 | return 0; |
| 5491 | } |
| 5492 | |
| 5493 | /** |
| 5494 | * lpfc_send_rrq - Sends ELS RRQ if needed. |
| 5495 | * @phba: pointer to lpfc hba data structure. |
| 5496 | * @rrq: pointer to the active rrq. |
| 5497 | * |
| 5498 | * This routine will call the lpfc_issue_els_rrq if the rrq is |
| 5499 | * still active for the xri. If this function returns a failure then |
| 5500 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. |
| 5501 | * |
| 5502 | * Returns 0 Success. |
| 5503 | * 1 Failure. |
| 5504 | **/ |
| 5505 | int |
| 5506 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) |
| 5507 | { |
| 5508 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, |
| 5509 | rrq->nlp_DID); |
| 5510 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) |
| 5511 | return lpfc_issue_els_rrq(rrq->vport, ndlp, |
| 5512 | rrq->nlp_DID, rrq); |
| 5513 | else |
| 5514 | return 1; |
| 5515 | } |
| 5516 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5517 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5518 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5519 | * @vport: pointer to a host virtual N_Port data structure. |
| 5520 | * @cmdsize: size of the ELS command. |
| 5521 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5522 | * @ndlp: pointer to a node-list data structure. |
| 5523 | * |
| 5524 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 5525 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 5526 | * |
| 5527 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5528 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5529 | * will be stored into the context1 field of the IOCB for the completion |
| 5530 | * callback function to the RPL Accept Response ELS command. |
| 5531 | * |
| 5532 | * Return code |
| 5533 | * 0 - Successfully issued ACC RPL ELS command |
| 5534 | * 1 - Failed to issue ACC RPL ELS command |
| 5535 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5536 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5537 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 5538 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5539 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5540 | struct lpfc_hba *phba = vport->phba; |
| 5541 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5542 | RPL_RSP rpl_rsp; |
| 5543 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5544 | uint8_t *pcmd; |
| 5545 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5546 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5547 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5548 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5549 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5550 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5551 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5552 | icmd = &elsiocb->iocb; |
| 5553 | oldcmd = &oldiocb->iocb; |
| 5554 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 5555 | |
| 5556 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5557 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5558 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5559 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 5560 | pcmd += sizeof(uint16_t); |
| 5561 | |
| 5562 | /* Setup the RPL ACC payload */ |
| 5563 | rpl_rsp.listLen = be32_to_cpu(1); |
| 5564 | rpl_rsp.index = 0; |
| 5565 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5566 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 5567 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5568 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5569 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5570 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5571 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5572 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 5573 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 5574 | "rpi x%x\n", |
| 5575 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5576 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5577 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5578 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5579 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5580 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 5581 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5582 | lpfc_els_free_iocb(phba, elsiocb); |
| 5583 | return 1; |
| 5584 | } |
| 5585 | return 0; |
| 5586 | } |
| 5587 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5588 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5589 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5590 | * @vport: pointer to a host virtual N_Port data structure. |
| 5591 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5592 | * @ndlp: pointer to a node-list data structure. |
| 5593 | * |
| 5594 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 5595 | * unsolicited event. It first checks the remote port state. If the remote |
| 5596 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 5597 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 5598 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 5599 | * to accept the RPL. |
| 5600 | * |
| 5601 | * Return code |
| 5602 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 5603 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5604 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5605 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5606 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5607 | { |
| 5608 | struct lpfc_dmabuf *pcmd; |
| 5609 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5610 | uint32_t maxsize; |
| 5611 | uint16_t cmdsize; |
| 5612 | RPL *rpl; |
| 5613 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5614 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5615 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5616 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5617 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5618 | stat.un.b.lsRjtRsvd0 = 0; |
| 5619 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5620 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5621 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5622 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5623 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5624 | /* rejected the unsolicited RPL request and done with it */ |
| 5625 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5626 | } |
| 5627 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5628 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5629 | lp = (uint32_t *) pcmd->virt; |
| 5630 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5631 | maxsize = be32_to_cpu(rpl->maxsize); |
| 5632 | |
| 5633 | /* We support only one port */ |
| 5634 | if ((rpl->index == 0) && |
| 5635 | ((maxsize == 0) || |
| 5636 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 5637 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5638 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5639 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 5640 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5641 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5642 | |
| 5643 | return 0; |
| 5644 | } |
| 5645 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5646 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5647 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5648 | * @vport: pointer to a virtual N_Port data structure. |
| 5649 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5650 | * @ndlp: pointer to a node-list data structure. |
| 5651 | * |
| 5652 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5653 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 5654 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 5655 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 5656 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 5657 | * remote PortName is compared against the FC PortName stored in the @vport |
| 5658 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 5659 | * compared against the FC NodeName stored in the @vport data structure. |
| 5660 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 5661 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 5662 | * invoked to send out FARP Response to the remote node. Before sending the |
| 5663 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 5664 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 5665 | * routine is invoked to log into the remote port first. |
| 5666 | * |
| 5667 | * Return code |
| 5668 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 5669 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5670 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5671 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5672 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5673 | { |
| 5674 | struct lpfc_dmabuf *pcmd; |
| 5675 | uint32_t *lp; |
| 5676 | IOCB_t *icmd; |
| 5677 | FARP *fp; |
| 5678 | uint32_t cmd, cnt, did; |
| 5679 | |
| 5680 | icmd = &cmdiocb->iocb; |
| 5681 | did = icmd->un.elsreq64.remoteID; |
| 5682 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5683 | lp = (uint32_t *) pcmd->virt; |
| 5684 | |
| 5685 | cmd = *lp++; |
| 5686 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5687 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5688 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5689 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5690 | /* We will only support match on WWPN or WWNN */ |
| 5691 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5692 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5693 | } |
| 5694 | |
| 5695 | cnt = 0; |
| 5696 | /* If this FARP command is searching for my portname */ |
| 5697 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5698 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5699 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5700 | cnt = 1; |
| 5701 | } |
| 5702 | |
| 5703 | /* If this FARP command is searching for my nodename */ |
| 5704 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5705 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5706 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5707 | cnt = 1; |
| 5708 | } |
| 5709 | |
| 5710 | if (cnt) { |
| 5711 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 5712 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 5713 | /* Log back into the node before sending the FARP. */ |
| 5714 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5715 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5716 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 5717 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5718 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5719 | } |
| 5720 | |
| 5721 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5722 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 5723 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5724 | } |
| 5725 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5726 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5727 | } |
| 5728 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5729 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5730 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5731 | * @vport: pointer to a host virtual N_Port data structure. |
| 5732 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5733 | * @ndlp: pointer to a node-list data structure. |
| 5734 | * |
| 5735 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5736 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 5737 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 5738 | * the FARP response request. |
| 5739 | * |
| 5740 | * Return code |
| 5741 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 5742 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5743 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5744 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5745 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5746 | { |
| 5747 | struct lpfc_dmabuf *pcmd; |
| 5748 | uint32_t *lp; |
| 5749 | IOCB_t *icmd; |
| 5750 | uint32_t cmd, did; |
| 5751 | |
| 5752 | icmd = &cmdiocb->iocb; |
| 5753 | did = icmd->un.elsreq64.remoteID; |
| 5754 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5755 | lp = (uint32_t *) pcmd->virt; |
| 5756 | |
| 5757 | cmd = *lp++; |
| 5758 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5759 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5760 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5761 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5762 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5763 | |
| 5764 | return 0; |
| 5765 | } |
| 5766 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5767 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5768 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5769 | * @vport: pointer to a host virtual N_Port data structure. |
| 5770 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5771 | * @fan_ndlp: pointer to a node-list data structure. |
| 5772 | * |
| 5773 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 5774 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 5775 | * only be processed on a physical port (i.e., the @vport represents the |
| 5776 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 5777 | * compared against those in the phba data structure. If any of those is |
| 5778 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 5779 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 5780 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 5781 | * is invoked to register login to the fabric. |
| 5782 | * |
| 5783 | * Return code |
| 5784 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 5785 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5786 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5787 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5788 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5789 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5790 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5791 | uint32_t *lp; |
| 5792 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5793 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5794 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 5795 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 5796 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5797 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5798 | if ((vport == phba->pport) && |
| 5799 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5800 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5801 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5802 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5803 | sizeof(struct lpfc_name)))) { |
| 5804 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5805 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5806 | } else { |
| 5807 | /* FAN verified - skip FLOGI */ |
| 5808 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5809 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5810 | lpfc_issue_fabric_reglogin(vport); |
| 5811 | else |
| 5812 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5813 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5814 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5815 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5816 | } |
| 5817 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5818 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5819 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5820 | * @ptr: holder for the timer function associated data. |
| 5821 | * |
| 5822 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5823 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5824 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5825 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5826 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5827 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5828 | void |
| 5829 | lpfc_els_timeout(unsigned long ptr) |
| 5830 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5831 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5832 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5833 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5834 | unsigned long iflag; |
| 5835 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5836 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5837 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5838 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5839 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5840 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5841 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5842 | if (!tmo_posted) |
| 5843 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5844 | return; |
| 5845 | } |
| 5846 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5847 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5848 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5849 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5850 | * @vport: pointer to a virtual N_Port data structure. |
| 5851 | * |
| 5852 | * This routine is the actual handler function that processes an ELS timeout |
| 5853 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5854 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5855 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5856 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5857 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5858 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5859 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5860 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5861 | struct lpfc_sli_ring *pring; |
| 5862 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5863 | IOCB_t *cmd = NULL; |
| 5864 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5865 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5866 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5867 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5868 | LIST_HEAD(txcmplq_completions); |
| 5869 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5870 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5871 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5872 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5873 | |
| 5874 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5875 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5876 | spin_lock_irq(&phba->hbalock); |
| 5877 | list_splice_init(&pring->txcmplq, &txcmplq_completions); |
| 5878 | spin_unlock_irq(&phba->hbalock); |
| 5879 | |
| 5880 | list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5881 | cmd = &piocb->iocb; |
| 5882 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5883 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5884 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5885 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5886 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5887 | |
| 5888 | if (piocb->vport != vport) |
| 5889 | continue; |
| 5890 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5891 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5892 | if (pcmd) |
| 5893 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5894 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5895 | if (els_command == ELS_CMD_FARP || |
| 5896 | els_command == ELS_CMD_FARPR || |
| 5897 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5898 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5899 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5900 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5901 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5902 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5903 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5904 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5905 | continue; |
| 5906 | } |
| 5907 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5908 | remote_ID = 0xffffffff; |
| 5909 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5910 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5911 | else { |
| 5912 | struct lpfc_nodelist *ndlp; |
| 5913 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5914 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5915 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5916 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5917 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5918 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5919 | spin_lock_irq(&phba->hbalock); |
| 5920 | list_splice(&txcmplq_completions, &pring->txcmplq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5921 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5922 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5923 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 5924 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5925 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5926 | "x%x\n", els_command, |
| 5927 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 5928 | spin_lock_irq(&phba->hbalock); |
| 5929 | list_del_init(&piocb->dlist); |
| 5930 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5931 | spin_unlock_irq(&phba->hbalock); |
| 5932 | } |
| 5933 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5934 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5935 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5936 | } |
| 5937 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5938 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5939 | * 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] | 5940 | * @vport: pointer to a host virtual N_Port data structure. |
| 5941 | * |
| 5942 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5943 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5944 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5945 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5946 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5947 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5948 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5949 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5950 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5951 | * completion queue IOCB that is associated with the @vport and is not |
| 5952 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5953 | * part of the discovery state machine) out to HBA by invoking the |
| 5954 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5955 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5956 | * the IOCBs are aborted when this function returns. |
| 5957 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5958 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5959 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5960 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5961 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5962 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5963 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5964 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5965 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5966 | |
| 5967 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5968 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5969 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5970 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5971 | cmd = &piocb->iocb; |
| 5972 | |
| 5973 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5974 | continue; |
| 5975 | } |
| 5976 | |
| 5977 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5978 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5979 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5980 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5981 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5982 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5983 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5984 | if (piocb->vport != vport) |
| 5985 | continue; |
| 5986 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5987 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5988 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5989 | } |
| 5990 | |
| 5991 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5992 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5993 | continue; |
| 5994 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5995 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5996 | if (piocb->vport != vport) |
| 5997 | continue; |
| 5998 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5999 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6000 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6001 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 6002 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6003 | /* Cancell all the IOCBs from the completions list */ |
| 6004 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6005 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 6006 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6007 | return; |
| 6008 | } |
| 6009 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6010 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6011 | * 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] | 6012 | * @phba: pointer to lpfc hba data structure. |
| 6013 | * |
| 6014 | * This routine is used to clean up all the outstanding ELS commands on a |
| 6015 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 6016 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 6017 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 6018 | * the IOCBs with the completion callback function associated, the callback |
| 6019 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 6020 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 6021 | * callback function associated, the IOCB will simply be released. Finally, |
| 6022 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 6023 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 6024 | * management plane IOCBs that are not part of the discovery state machine) |
| 6025 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 6026 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6027 | void |
| 6028 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 6029 | { |
| 6030 | LIST_HEAD(completions); |
| 6031 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6032 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6033 | IOCB_t *cmd = NULL; |
| 6034 | |
| 6035 | lpfc_fabric_abort_hba(phba); |
| 6036 | spin_lock_irq(&phba->hbalock); |
| 6037 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 6038 | cmd = &piocb->iocb; |
| 6039 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 6040 | continue; |
| 6041 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 6042 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 6043 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 6044 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 6045 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 6046 | continue; |
| 6047 | list_move_tail(&piocb->list, &completions); |
| 6048 | pring->txq_cnt--; |
| 6049 | } |
| 6050 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 6051 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 6052 | continue; |
| 6053 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 6054 | } |
| 6055 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6056 | |
| 6057 | /* Cancel all the IOCBs from the completions list */ |
| 6058 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6059 | IOERR_SLI_ABORTED); |
| 6060 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6061 | return; |
| 6062 | } |
| 6063 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6064 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6065 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6066 | * @phba: Pointer to hba context object. |
| 6067 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 6068 | * @rspiocbp: Pointer to response iocb which reported error. |
| 6069 | * |
| 6070 | * This function sends an event when there is an ELS command |
| 6071 | * failure. |
| 6072 | **/ |
| 6073 | void |
| 6074 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 6075 | struct lpfc_iocbq *cmdiocbp, |
| 6076 | struct lpfc_iocbq *rspiocbp) |
| 6077 | { |
| 6078 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 6079 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6080 | struct lpfc_lsrjt_event lsrjt_event; |
| 6081 | struct lpfc_fabric_event_header fabric_event; |
| 6082 | struct ls_rjt stat; |
| 6083 | struct lpfc_nodelist *ndlp; |
| 6084 | uint32_t *pcmd; |
| 6085 | |
| 6086 | ndlp = cmdiocbp->context1; |
| 6087 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 6088 | return; |
| 6089 | |
| 6090 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 6091 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 6092 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 6093 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 6094 | sizeof(struct lpfc_name)); |
| 6095 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 6096 | sizeof(struct lpfc_name)); |
| 6097 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 6098 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6099 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6100 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 6101 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 6102 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 6103 | fc_host_post_vendor_event(shost, |
| 6104 | fc_get_event_number(), |
| 6105 | sizeof(lsrjt_event), |
| 6106 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6107 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6108 | return; |
| 6109 | } |
| 6110 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 6111 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 6112 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 6113 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 6114 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 6115 | else |
| 6116 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 6117 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 6118 | sizeof(struct lpfc_name)); |
| 6119 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 6120 | sizeof(struct lpfc_name)); |
| 6121 | fc_host_post_vendor_event(shost, |
| 6122 | fc_get_event_number(), |
| 6123 | sizeof(fabric_event), |
| 6124 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6125 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6126 | return; |
| 6127 | } |
| 6128 | |
| 6129 | } |
| 6130 | |
| 6131 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6132 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6133 | * @vport: Pointer to vport object. |
| 6134 | * @ndlp: Pointer FC node object. |
| 6135 | * @cmd: ELS command code. |
| 6136 | * |
| 6137 | * This function posts an event when there is an incoming |
| 6138 | * unsolicited ELS command. |
| 6139 | **/ |
| 6140 | static void |
| 6141 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 6142 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6143 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6144 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6145 | struct lpfc_els_event_header *els_data = NULL; |
| 6146 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6147 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6148 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6149 | if (*payload == ELS_CMD_LOGO) { |
| 6150 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 6151 | if (!logo_data) { |
| 6152 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6153 | "0148 Failed to allocate memory " |
| 6154 | "for LOGO event\n"); |
| 6155 | return; |
| 6156 | } |
| 6157 | els_data = &logo_data->header; |
| 6158 | } else { |
| 6159 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 6160 | GFP_KERNEL); |
| 6161 | if (!els_data) { |
| 6162 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6163 | "0149 Failed to allocate memory " |
| 6164 | "for ELS event\n"); |
| 6165 | return; |
| 6166 | } |
| 6167 | } |
| 6168 | els_data->event_type = FC_REG_ELS_EVENT; |
| 6169 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6170 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6171 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6172 | break; |
| 6173 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6174 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6175 | break; |
| 6176 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6177 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 6178 | break; |
| 6179 | case ELS_CMD_LOGO: |
| 6180 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 6181 | /* Copy the WWPN in the LOGO payload */ |
| 6182 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 6183 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6184 | break; |
| 6185 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 6186 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6187 | return; |
| 6188 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6189 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 6190 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 6191 | if (*payload == ELS_CMD_LOGO) { |
| 6192 | fc_host_post_vendor_event(shost, |
| 6193 | fc_get_event_number(), |
| 6194 | sizeof(struct lpfc_logo_event), |
| 6195 | (char *)logo_data, |
| 6196 | LPFC_NL_VENDOR_ID); |
| 6197 | kfree(logo_data); |
| 6198 | } else { |
| 6199 | fc_host_post_vendor_event(shost, |
| 6200 | fc_get_event_number(), |
| 6201 | sizeof(struct lpfc_els_event_header), |
| 6202 | (char *)els_data, |
| 6203 | LPFC_NL_VENDOR_ID); |
| 6204 | kfree(els_data); |
| 6205 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6206 | |
| 6207 | return; |
| 6208 | } |
| 6209 | |
| 6210 | |
| 6211 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6212 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6213 | * @phba: pointer to lpfc hba data structure. |
| 6214 | * @pring: pointer to a SLI ring. |
| 6215 | * @vport: pointer to a host virtual N_Port data structure. |
| 6216 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 6217 | * |
| 6218 | * This routine is used for processing the IOCB associated with a unsolicited |
| 6219 | * event. It first determines whether there is an existing ndlp that matches |
| 6220 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 6221 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 6222 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 6223 | * of the discovery state machine. |
| 6224 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6225 | static void |
| 6226 | 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] | 6227 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6228 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6229 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6230 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6231 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6232 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6233 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6234 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6235 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6236 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6237 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6238 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6239 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6240 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 6241 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6242 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6243 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6244 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6245 | did = icmd->un.rcvels.remoteID; |
| 6246 | if (icmd->ulpStatus) { |
| 6247 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6248 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 6249 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6250 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6251 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6252 | |
| 6253 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6254 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6255 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6256 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 6257 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6258 | if (vport->load_flag & FC_UNLOADING) |
| 6259 | goto dropit; |
| 6260 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 6261 | /* If NPort discovery is delayed drop incoming ELS */ |
| 6262 | if ((vport->fc_flag & FC_DISC_DELAYED) && |
| 6263 | (cmd != ELS_CMD_PLOGI)) |
| 6264 | goto dropit; |
| 6265 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6266 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6267 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6268 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6269 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6270 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6271 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6272 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6273 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6274 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6275 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6276 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6277 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6278 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 6279 | ndlp = lpfc_enable_node(vport, ndlp, |
| 6280 | NLP_STE_UNUSED_NODE); |
| 6281 | if (!ndlp) |
| 6282 | goto dropit; |
| 6283 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 6284 | newnode = 1; |
| 6285 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 6286 | ndlp->nlp_type |= NLP_FABRIC; |
| 6287 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 6288 | /* This is similar to the new node path */ |
| 6289 | ndlp = lpfc_nlp_get(ndlp); |
| 6290 | if (!ndlp) |
| 6291 | goto dropit; |
| 6292 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 6293 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6294 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6295 | |
| 6296 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6297 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6298 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6299 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6300 | |
| 6301 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 6302 | cmd &= ELS_CMD_MASK; |
| 6303 | } |
| 6304 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6305 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6306 | "0112 ELS command x%x received from NPORT x%x " |
| 6307 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6308 | switch (cmd) { |
| 6309 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6310 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6311 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 6312 | did, vport->port_state, ndlp->nlp_flag); |
| 6313 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6314 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6315 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 6316 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6317 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 6318 | |
| 6319 | /* If Nport discovery is delayed, reject PLOGIs */ |
| 6320 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 6321 | rjt_err = LSRJT_UNABLE_TPC; |
| 6322 | break; |
| 6323 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6324 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 6325 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 6326 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 6327 | rjt_err = LSRJT_UNABLE_TPC; |
| 6328 | break; |
| 6329 | } |
| 6330 | /* We get here, and drop thru, if we are PT2PT with |
| 6331 | * another NPort and the other side has initiated |
| 6332 | * the PLOGI before responding to our FLOGI. |
| 6333 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6334 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6335 | |
| 6336 | shost = lpfc_shost_from_vport(vport); |
| 6337 | spin_lock_irq(shost->host_lock); |
| 6338 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 6339 | spin_unlock_irq(shost->host_lock); |
| 6340 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6341 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6342 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6343 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6344 | break; |
| 6345 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6346 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6347 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 6348 | did, vport->port_state, ndlp->nlp_flag); |
| 6349 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6350 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6351 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6352 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6353 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6354 | break; |
| 6355 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6356 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6357 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 6358 | did, vport->port_state, ndlp->nlp_flag); |
| 6359 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6360 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6361 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6362 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6363 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6364 | break; |
| 6365 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6366 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6367 | break; |
| 6368 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6369 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6370 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 6371 | did, vport->port_state, ndlp->nlp_flag); |
| 6372 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6373 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6374 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6375 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6376 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6377 | break; |
| 6378 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6379 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6380 | break; |
| 6381 | case ELS_CMD_RSCN: |
| 6382 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6383 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6384 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6385 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6386 | break; |
| 6387 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6388 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6389 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 6390 | did, vport->port_state, ndlp->nlp_flag); |
| 6391 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6392 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6393 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6394 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6395 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6396 | break; |
| 6397 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6398 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6399 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6400 | break; |
| 6401 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6402 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6403 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 6404 | did, vport->port_state, ndlp->nlp_flag); |
| 6405 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6406 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6407 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6408 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6409 | break; |
| 6410 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6411 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6412 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6413 | break; |
| 6414 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6415 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6416 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 6417 | did, vport->port_state, ndlp->nlp_flag); |
| 6418 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6419 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6420 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6421 | break; |
| 6422 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6423 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6424 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 6425 | did, vport->port_state, ndlp->nlp_flag); |
| 6426 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6427 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6428 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6429 | break; |
| 6430 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6431 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6432 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 6433 | did, vport->port_state, ndlp->nlp_flag); |
| 6434 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6435 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6436 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6437 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6438 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6439 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6440 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 6441 | did, vport->port_state, ndlp->nlp_flag); |
| 6442 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6443 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6444 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6445 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6446 | break; |
| 6447 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6448 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6449 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6450 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6451 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6452 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 6453 | did, vport->port_state, ndlp->nlp_flag); |
| 6454 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6455 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6456 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6457 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6458 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6459 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6460 | case ELS_CMD_RLS: |
| 6461 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6462 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 6463 | did, vport->port_state, ndlp->nlp_flag); |
| 6464 | |
| 6465 | phba->fc_stat.elsRcvRLS++; |
| 6466 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 6467 | if (newnode) |
| 6468 | lpfc_nlp_put(ndlp); |
| 6469 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6470 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6471 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6472 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 6473 | did, vport->port_state, ndlp->nlp_flag); |
| 6474 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6475 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6476 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6477 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6478 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6479 | break; |
| 6480 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6481 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6482 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 6483 | did, vport->port_state, ndlp->nlp_flag); |
| 6484 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6485 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6486 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6487 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6488 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6489 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6490 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6491 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6492 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 6493 | did, vport->port_state, ndlp->nlp_flag); |
| 6494 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6495 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6496 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6497 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6498 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6499 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6500 | case ELS_CMD_RTV: |
| 6501 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6502 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 6503 | did, vport->port_state, ndlp->nlp_flag); |
| 6504 | phba->fc_stat.elsRcvRTV++; |
| 6505 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 6506 | if (newnode) |
| 6507 | lpfc_nlp_put(ndlp); |
| 6508 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6509 | case ELS_CMD_RRQ: |
| 6510 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6511 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 6512 | did, vport->port_state, ndlp->nlp_flag); |
| 6513 | |
| 6514 | phba->fc_stat.elsRcvRRQ++; |
| 6515 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 6516 | if (newnode) |
| 6517 | lpfc_nlp_put(ndlp); |
| 6518 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6519 | case ELS_CMD_ECHO: |
| 6520 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6521 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 6522 | did, vport->port_state, ndlp->nlp_flag); |
| 6523 | |
| 6524 | phba->fc_stat.elsRcvECHO++; |
| 6525 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 6526 | if (newnode) |
| 6527 | lpfc_nlp_put(ndlp); |
| 6528 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6529 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6530 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6531 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 6532 | cmd, did, vport->port_state); |
| 6533 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6534 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6535 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6536 | |
| 6537 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6538 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6539 | "0115 Unknown ELS command x%x " |
| 6540 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6541 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6542 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6543 | break; |
| 6544 | } |
| 6545 | |
| 6546 | /* check if need to LS_RJT received ELS cmd */ |
| 6547 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6548 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6549 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 6550 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6551 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 6552 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6553 | } |
| 6554 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6555 | lpfc_nlp_put(elsiocb->context1); |
| 6556 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6557 | return; |
| 6558 | |
| 6559 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6560 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6561 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6562 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6563 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6564 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6565 | phba->fc_stat.elsRcvDrop++; |
| 6566 | } |
| 6567 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6568 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6569 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6570 | * @phba: pointer to lpfc hba data structure. |
| 6571 | * @vpi: host virtual N_Port identifier. |
| 6572 | * |
| 6573 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 6574 | * @vpi. The function walks the HBA's vport list and returns the address |
| 6575 | * of the vport with the matching @vpi. |
| 6576 | * |
| 6577 | * Return code |
| 6578 | * NULL - No vport with the matching @vpi found |
| 6579 | * Otherwise - Address to the vport with the matching @vpi. |
| 6580 | **/ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6581 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6582 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 6583 | { |
| 6584 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6585 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6586 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6587 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6588 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6589 | if (vport->vpi == vpi) { |
| 6590 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6591 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6592 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6593 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6594 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6595 | return NULL; |
| 6596 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6597 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6598 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6599 | * 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] | 6600 | * @phba: pointer to lpfc hba data structure. |
| 6601 | * @pring: pointer to a SLI ring. |
| 6602 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 6603 | * |
| 6604 | * This routine is used to process an unsolicited event received from a SLI |
| 6605 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 6606 | * associated with the unsolicited event is done by invoking the routine |
| 6607 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 6608 | * SLI ring on which the unsolicited event was received. |
| 6609 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6610 | void |
| 6611 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 6612 | struct lpfc_iocbq *elsiocb) |
| 6613 | { |
| 6614 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6615 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6616 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6617 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 6618 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6619 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6620 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6621 | elsiocb->context2 = NULL; |
| 6622 | elsiocb->context3 = NULL; |
| 6623 | |
| 6624 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 6625 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 6626 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 6627 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6628 | phba->fc_stat.NoRcvBuf++; |
| 6629 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6630 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6631 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6632 | return; |
| 6633 | } |
| 6634 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6635 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 6636 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 6637 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 6638 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 6639 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6640 | else |
| 6641 | vport = lpfc_find_vport_by_vpid(phba, |
| 6642 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6643 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6644 | /* If there are no BDEs associated |
| 6645 | * with this IOCB, there is nothing to do. |
| 6646 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6647 | if (icmd->ulpBdeCount == 0) |
| 6648 | return; |
| 6649 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6650 | /* type of ELS cmd is first 32bit word |
| 6651 | * in packet |
| 6652 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6653 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6654 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6655 | } else { |
| 6656 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 6657 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6658 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 6659 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6660 | } |
| 6661 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6662 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 6663 | /* |
| 6664 | * The different unsolicited event handlers would tell us |
| 6665 | * if they are done with "mp" by setting context2 to NULL. |
| 6666 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6667 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6668 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 6669 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6670 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6671 | |
| 6672 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6673 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6674 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6675 | elsiocb->context2 = bdeBuf2; |
| 6676 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6677 | /* free mp if we are done with it */ |
| 6678 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6679 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 6680 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6681 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6682 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6683 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6684 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6685 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6686 | * 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] | 6687 | * @phba: pointer to lpfc hba data structure. |
| 6688 | * @vport: pointer to a virtual N_Port data structure. |
| 6689 | * |
| 6690 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 6691 | * State Change Request (SCR) for a @vport. This routine will create an |
| 6692 | * ndlp for the Name Server associated to the @vport if such node does |
| 6693 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 6694 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 6695 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 6696 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 6697 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6698 | void |
| 6699 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 6700 | { |
| 6701 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 6702 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6703 | |
| 6704 | /* |
| 6705 | * If lpfc_delay_discovery parameter is set and the clean address |
| 6706 | * bit is cleared and fc fabric parameters chenged, delay FC NPort |
| 6707 | * discovery. |
| 6708 | */ |
| 6709 | spin_lock_irq(shost->host_lock); |
| 6710 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 6711 | spin_unlock_irq(shost->host_lock); |
| 6712 | mod_timer(&vport->delayed_disc_tmo, |
| 6713 | jiffies + HZ * phba->fc_ratov); |
| 6714 | return; |
| 6715 | } |
| 6716 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6717 | |
| 6718 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 6719 | if (!ndlp) { |
| 6720 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 6721 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6722 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6723 | lpfc_disc_start(vport); |
| 6724 | return; |
| 6725 | } |
| 6726 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6727 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6728 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6729 | return; |
| 6730 | } |
| 6731 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6732 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 6733 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 6734 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6735 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6736 | lpfc_disc_start(vport); |
| 6737 | return; |
| 6738 | } |
| 6739 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6740 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6741 | "0348 NameServer login: node freed\n"); |
| 6742 | return; |
| 6743 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6744 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6745 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6746 | |
| 6747 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 6748 | |
| 6749 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 6750 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6751 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6752 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6753 | return; |
| 6754 | } |
| 6755 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6756 | if (vport->cfg_fdmi_on) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6757 | /* If this is the first time, allocate an ndlp and initialize |
| 6758 | * it. Otherwise, make sure the node is enabled and then do the |
| 6759 | * login. |
| 6760 | */ |
| 6761 | ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID); |
| 6762 | if (!ndlp_fdmi) { |
| 6763 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 6764 | GFP_KERNEL); |
| 6765 | if (ndlp_fdmi) { |
| 6766 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 6767 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
| 6768 | } else |
| 6769 | return; |
| 6770 | } |
| 6771 | if (!NLP_CHK_NODE_ACT(ndlp_fdmi)) |
| 6772 | ndlp_fdmi = lpfc_enable_node(vport, |
| 6773 | ndlp_fdmi, |
| 6774 | NLP_STE_NPR_NODE); |
| 6775 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6776 | if (ndlp_fdmi) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6777 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6778 | NLP_STE_PLOGI_ISSUE); |
| 6779 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6780 | } |
| 6781 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6782 | } |
| 6783 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6784 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6785 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6786 | * @phba: pointer to lpfc hba data structure. |
| 6787 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6788 | * |
| 6789 | * This routine is the completion callback function to register new vport |
| 6790 | * mailbox command. If the new vport mailbox command completes successfully, |
| 6791 | * the fabric registration login shall be performed on physical port (the |
| 6792 | * new vport created is actually a physical port, with VPI 0) or the port |
| 6793 | * login to Name Server for State Change Request (SCR) will be performed |
| 6794 | * on virtual port (real virtual port, with VPI greater than 0). |
| 6795 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6796 | static void |
| 6797 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6798 | { |
| 6799 | struct lpfc_vport *vport = pmb->vport; |
| 6800 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6801 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6802 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6803 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6804 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6805 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6806 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6807 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6808 | |
| 6809 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6810 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6811 | "0915 Register VPI failed : Status: x%x" |
| 6812 | " upd bit: x%x \n", mb->mbxStatus, |
| 6813 | mb->un.varRegVpi.upd); |
| 6814 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 6815 | mb->un.varRegVpi.upd) |
| 6816 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6817 | |
| 6818 | switch (mb->mbxStatus) { |
| 6819 | case 0x11: /* unsupported feature */ |
| 6820 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6821 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6822 | /* giving up on vport registration */ |
| 6823 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6824 | spin_lock_irq(shost->host_lock); |
| 6825 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6826 | spin_unlock_irq(shost->host_lock); |
| 6827 | lpfc_can_disctmo(vport); |
| 6828 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6829 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 6830 | case 0x20: |
| 6831 | spin_lock_irq(shost->host_lock); |
| 6832 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6833 | spin_unlock_irq(shost->host_lock); |
| 6834 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 6835 | pmb->vport = vport; |
| 6836 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 6837 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 6838 | MBX_NOWAIT); |
| 6839 | if (rc == MBX_NOT_FINISHED) { |
| 6840 | lpfc_printf_vlog(vport, |
| 6841 | KERN_ERR, LOG_MBOX, |
| 6842 | "2732 Failed to issue INIT_VPI" |
| 6843 | " mailbox command\n"); |
| 6844 | } else { |
| 6845 | lpfc_nlp_put(ndlp); |
| 6846 | return; |
| 6847 | } |
| 6848 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6849 | default: |
| 6850 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6851 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6852 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6853 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6854 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6855 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6856 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6857 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 6858 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6859 | lpfc_issue_init_vfi(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6860 | else |
| 6861 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6862 | break; |
| 6863 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6864 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6865 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 6866 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6867 | spin_unlock_irq(shost->host_lock); |
| 6868 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6869 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6870 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6871 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6872 | /* |
| 6873 | * If the physical port is instantiated using |
| 6874 | * FDISC, do not start vport discovery. |
| 6875 | */ |
| 6876 | if (vport->port_state != LPFC_FDISC) |
| 6877 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6878 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6879 | } |
| 6880 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6881 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6882 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6883 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6884 | /* Now, we decrement the ndlp reference count held for this |
| 6885 | * callback function |
| 6886 | */ |
| 6887 | lpfc_nlp_put(ndlp); |
| 6888 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6889 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6890 | return; |
| 6891 | } |
| 6892 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6893 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6894 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6895 | * @phba: pointer to lpfc hba data structure. |
| 6896 | * @vport: pointer to a host virtual N_Port data structure. |
| 6897 | * @ndlp: pointer to a node-list data structure. |
| 6898 | * |
| 6899 | * This routine registers the @vport as a new virtual port with a HBA. |
| 6900 | * It is done through a registering vpi mailbox command. |
| 6901 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6902 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6903 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 6904 | struct lpfc_nodelist *ndlp) |
| 6905 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6906 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6907 | LPFC_MBOXQ_t *mbox; |
| 6908 | |
| 6909 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6910 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6911 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6912 | mbox->vport = vport; |
| 6913 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6914 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6915 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6916 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6917 | /* mailbox command not success, decrement ndlp |
| 6918 | * reference count for this command |
| 6919 | */ |
| 6920 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6921 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6922 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6923 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6924 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6925 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6926 | } |
| 6927 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6928 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6929 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6930 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6931 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6932 | return; |
| 6933 | |
| 6934 | mbox_err_exit: |
| 6935 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6936 | spin_lock_irq(shost->host_lock); |
| 6937 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 6938 | spin_unlock_irq(shost->host_lock); |
| 6939 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6940 | } |
| 6941 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6942 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6943 | * 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] | 6944 | * @phba: pointer to lpfc hba data structure. |
| 6945 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6946 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6947 | **/ |
| 6948 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6949 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6950 | { |
| 6951 | struct lpfc_vport **vports; |
| 6952 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6953 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6954 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6955 | |
| 6956 | /* Treat this failure as linkdown for all vports */ |
| 6957 | link_state = phba->link_state; |
| 6958 | lpfc_linkdown(phba); |
| 6959 | phba->link_state = link_state; |
| 6960 | |
| 6961 | vports = lpfc_create_vport_work_array(phba); |
| 6962 | |
| 6963 | if (vports) { |
| 6964 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6965 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6966 | if (ndlp) |
| 6967 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 6968 | lpfc_els_flush_cmd(vports[i]); |
| 6969 | } |
| 6970 | lpfc_destroy_vport_work_array(phba, vports); |
| 6971 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | /** |
| 6975 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 6976 | * @phba: pointer to lpfc hba data structure. |
| 6977 | * |
| 6978 | * This routine abort all pending discovery commands and |
| 6979 | * start a timer to retry FLOGI for the physical port |
| 6980 | * discovery. |
| 6981 | **/ |
| 6982 | void |
| 6983 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 6984 | { |
| 6985 | struct lpfc_nodelist *ndlp; |
| 6986 | struct Scsi_Host *shost; |
| 6987 | |
| 6988 | /* Cancel the all vports retry delay retry timers */ |
| 6989 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6990 | |
| 6991 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 6992 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6993 | if (!ndlp) |
| 6994 | return; |
| 6995 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6996 | shost = lpfc_shost_from_vport(phba->pport); |
| 6997 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 6998 | spin_lock_irq(shost->host_lock); |
| 6999 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 7000 | spin_unlock_irq(shost->host_lock); |
| 7001 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 7002 | phba->pport->port_state = LPFC_FLOGI; |
| 7003 | return; |
| 7004 | } |
| 7005 | |
| 7006 | /** |
| 7007 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 7008 | * @phba: pointer to lpfc hba data structure. |
| 7009 | * @cmdiocb: pointer to FDISC command iocb. |
| 7010 | * @rspiocb: pointer to FDISC response iocb. |
| 7011 | * |
| 7012 | * This routine checks if a FLOGI is reguired for FDISC |
| 7013 | * to succeed. |
| 7014 | **/ |
| 7015 | static int |
| 7016 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 7017 | struct lpfc_iocbq *cmdiocb, |
| 7018 | struct lpfc_iocbq *rspiocb) |
| 7019 | { |
| 7020 | |
| 7021 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 7022 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 7023 | return 0; |
| 7024 | else |
| 7025 | return 1; |
| 7026 | } |
| 7027 | |
| 7028 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7029 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7030 | * @phba: pointer to lpfc hba data structure. |
| 7031 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7032 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7033 | * |
| 7034 | * This routine is the completion callback function to a Fabric Discover |
| 7035 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 7036 | * single threaded, each FDISC completion callback function will reset |
| 7037 | * the discovery timer for all vports such that the timers will not get |
| 7038 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 7039 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 7040 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 7041 | * assigned to the vport has been changed with the completion of the FDISC |
| 7042 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 7043 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 7044 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 7045 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 7046 | * Server for State Change Request (SCR). |
| 7047 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7048 | static void |
| 7049 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7050 | struct lpfc_iocbq *rspiocb) |
| 7051 | { |
| 7052 | struct lpfc_vport *vport = cmdiocb->vport; |
| 7053 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7054 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 7055 | struct lpfc_nodelist *np; |
| 7056 | struct lpfc_nodelist *next_np; |
| 7057 | IOCB_t *irsp = &rspiocb->iocb; |
| 7058 | struct lpfc_iocbq *piocb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7059 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 7060 | struct serv_parm *sp; |
| 7061 | uint8_t fabric_param_changed; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7062 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7063 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7064 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 7065 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 7066 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7067 | /* Since all FDISCs are being single threaded, we |
| 7068 | * must reset the discovery timer for ALL vports |
| 7069 | * waiting to send FDISC when one completes. |
| 7070 | */ |
| 7071 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 7072 | lpfc_set_disctmo(piocb->vport); |
| 7073 | } |
| 7074 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7075 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7076 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 7077 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 7078 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7079 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7080 | |
| 7081 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 7082 | lpfc_retry_pport_discovery(phba); |
| 7083 | goto out; |
| 7084 | } |
| 7085 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7086 | /* Check for retry */ |
| 7087 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 7088 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7089 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7090 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7091 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7092 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7093 | goto fdisc_failed; |
| 7094 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7095 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7096 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 7097 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7098 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7099 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7100 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 7101 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7102 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7103 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 7104 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7105 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 7106 | sp = prsp->virt + sizeof(uint32_t); |
| 7107 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 7108 | memcpy(&vport->fabric_portname, &sp->portName, |
| 7109 | sizeof(struct lpfc_name)); |
| 7110 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 7111 | sizeof(struct lpfc_name)); |
| 7112 | if (fabric_param_changed && |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7113 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 7114 | /* If our NportID changed, we need to ensure all |
| 7115 | * remaining NPORTs get unreg_login'ed so we can |
| 7116 | * issue unreg_vpi. |
| 7117 | */ |
| 7118 | list_for_each_entry_safe(np, next_np, |
| 7119 | &vport->fc_nodes, nlp_listp) { |
| 7120 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 7121 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 7122 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 7123 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7124 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7125 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7126 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7127 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7128 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 7129 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 7130 | |
| 7131 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7132 | lpfc_sli4_unreg_all_rpis(vport); |
| 7133 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7134 | lpfc_mbx_unreg_vpi(vport); |
| 7135 | spin_lock_irq(shost->host_lock); |
| 7136 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7137 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7138 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 7139 | else |
| 7140 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7141 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 7142 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 7143 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 7144 | /* |
| 7145 | * Driver needs to re-reg VPI in order for f/w |
| 7146 | * to update the MAC address. |
| 7147 | */ |
| 7148 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 7149 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7150 | } |
| 7151 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 7152 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 7153 | lpfc_issue_init_vpi(vport); |
| 7154 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7155 | lpfc_register_new_vport(phba, vport, ndlp); |
| 7156 | else |
| 7157 | lpfc_do_scr_ns_plogi(phba, vport); |
| 7158 | goto out; |
| 7159 | fdisc_failed: |
| 7160 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 7161 | /* Cancel discovery timer */ |
| 7162 | lpfc_can_disctmo(vport); |
| 7163 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7164 | out: |
| 7165 | lpfc_els_free_iocb(phba, cmdiocb); |
| 7166 | } |
| 7167 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7168 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7169 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7170 | * @vport: pointer to a virtual N_Port data structure. |
| 7171 | * @ndlp: pointer to a node-list data structure. |
| 7172 | * @retry: number of retries to the command IOCB. |
| 7173 | * |
| 7174 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 7175 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 7176 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 7177 | * IOCB will be sent off HBA at any given time. |
| 7178 | * |
| 7179 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7180 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7181 | * will be stored into the context1 field of the IOCB for the completion |
| 7182 | * callback function to the FDISC ELS command. |
| 7183 | * |
| 7184 | * Return code |
| 7185 | * 0 - Successfully issued fdisc iocb command |
| 7186 | * 1 - Failed to issue fdisc iocb command |
| 7187 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7188 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7189 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 7190 | uint8_t retry) |
| 7191 | { |
| 7192 | struct lpfc_hba *phba = vport->phba; |
| 7193 | IOCB_t *icmd; |
| 7194 | struct lpfc_iocbq *elsiocb; |
| 7195 | struct serv_parm *sp; |
| 7196 | uint8_t *pcmd; |
| 7197 | uint16_t cmdsize; |
| 7198 | int did = ndlp->nlp_DID; |
| 7199 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7200 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7201 | vport->port_state = LPFC_FDISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7202 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 7203 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 7204 | ELS_CMD_FDISC); |
| 7205 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7206 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7207 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7208 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7209 | return 1; |
| 7210 | } |
| 7211 | |
| 7212 | icmd = &elsiocb->iocb; |
| 7213 | icmd->un.elsreq64.myID = 0; |
| 7214 | icmd->un.elsreq64.fl = 1; |
| 7215 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 7216 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 7217 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 7218 | LPFC_SLI_INTF_IF_TYPE_0)) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7219 | /* FDISC needs to be 1 for WQE VPI */ |
| 7220 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 7221 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 7222 | /* Set the ulpContext to the vpi */ |
| 7223 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 7224 | } else { |
| 7225 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 7226 | icmd->ulpCt_h = 1; |
| 7227 | icmd->ulpCt_l = 0; |
| 7228 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7229 | |
| 7230 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7231 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 7232 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 7233 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 7234 | sp = (struct serv_parm *) pcmd; |
| 7235 | /* Setup CSPs accordingly for Fabric */ |
| 7236 | sp->cmn.e_d_tov = 0; |
| 7237 | sp->cmn.w2.r_a_tov = 0; |
| 7238 | sp->cls1.classValid = 0; |
| 7239 | sp->cls2.seqDelivery = 1; |
| 7240 | sp->cls3.seqDelivery = 1; |
| 7241 | |
| 7242 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 7243 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 7244 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 7245 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 7246 | memcpy(pcmd, &vport->fc_portname, 8); |
| 7247 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 7248 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 7249 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 7250 | |
| 7251 | lpfc_set_disctmo(vport); |
| 7252 | |
| 7253 | phba->fc_stat.elsXmitFDISC++; |
| 7254 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 7255 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7256 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7257 | "Issue FDISC: did:x%x", |
| 7258 | did, 0, 0); |
| 7259 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7260 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 7261 | if (rc == IOCB_ERROR) { |
| 7262 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7263 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7264 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7265 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7266 | return 1; |
| 7267 | } |
| 7268 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7269 | return 0; |
| 7270 | } |
| 7271 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7272 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7273 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7274 | * @phba: pointer to lpfc hba data structure. |
| 7275 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7276 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7277 | * |
| 7278 | * This routine is the completion callback function to the issuing of a LOGO |
| 7279 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 7280 | * reference count held on ndlp for this completion function, indicating that |
| 7281 | * the reference to the ndlp is no long needed. Note that the |
| 7282 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 7283 | * callback function and an additional explicit ndlp reference decrementation |
| 7284 | * will trigger the actual release of the ndlp. |
| 7285 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7286 | static void |
| 7287 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7288 | struct lpfc_iocbq *rspiocb) |
| 7289 | { |
| 7290 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7291 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7292 | struct lpfc_nodelist *ndlp; |
| 7293 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7294 | |
| 7295 | irsp = &rspiocb->iocb; |
| 7296 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7297 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 7298 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7299 | |
| 7300 | lpfc_els_free_iocb(phba, cmdiocb); |
| 7301 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7302 | |
| 7303 | /* Trigger the release of the ndlp after logo */ |
| 7304 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7305 | } |
| 7306 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7307 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7308 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7309 | * @vport: pointer to a virtual N_Port data structure. |
| 7310 | * @ndlp: pointer to a node-list data structure. |
| 7311 | * |
| 7312 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 7313 | * |
| 7314 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7315 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7316 | * will be stored into the context1 field of the IOCB for the completion |
| 7317 | * callback function to the LOGO ELS command. |
| 7318 | * |
| 7319 | * Return codes |
| 7320 | * 0 - Successfully issued logo off the @vport |
| 7321 | * 1 - Failed to issue logo off the @vport |
| 7322 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7323 | int |
| 7324 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 7325 | { |
| 7326 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7327 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7328 | IOCB_t *icmd; |
| 7329 | struct lpfc_iocbq *elsiocb; |
| 7330 | uint8_t *pcmd; |
| 7331 | uint16_t cmdsize; |
| 7332 | |
| 7333 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 7334 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 7335 | ELS_CMD_LOGO); |
| 7336 | if (!elsiocb) |
| 7337 | return 1; |
| 7338 | |
| 7339 | icmd = &elsiocb->iocb; |
| 7340 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7341 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 7342 | pcmd += sizeof(uint32_t); |
| 7343 | |
| 7344 | /* Fill in LOGO payload */ |
| 7345 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 7346 | pcmd += sizeof(uint32_t); |
| 7347 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 7348 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7349 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7350 | "Issue LOGO npiv did:x%x flg:x%x", |
| 7351 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 7352 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7353 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 7354 | spin_lock_irq(shost->host_lock); |
| 7355 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 7356 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7357 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 7358 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7359 | spin_lock_irq(shost->host_lock); |
| 7360 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 7361 | spin_unlock_irq(shost->host_lock); |
| 7362 | lpfc_els_free_iocb(phba, elsiocb); |
| 7363 | return 1; |
| 7364 | } |
| 7365 | return 0; |
| 7366 | } |
| 7367 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7368 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7369 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7370 | * @ptr: holder for the timer function associated data. |
| 7371 | * |
| 7372 | * This routine is invoked by the fabric iocb block timer after |
| 7373 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 7374 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 7375 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 7376 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 7377 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 7378 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7379 | void |
| 7380 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 7381 | { |
| 7382 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 7383 | unsigned long iflags; |
| 7384 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7385 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7386 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 7387 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 7388 | if (!tmo_posted) |
| 7389 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 7390 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 7391 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7392 | if (!tmo_posted) |
| 7393 | lpfc_worker_wake_up(phba); |
| 7394 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7395 | } |
| 7396 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7397 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7398 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7399 | * @phba: pointer to lpfc hba data structure. |
| 7400 | * |
| 7401 | * This routine issues one fabric iocb from the driver internal list to |
| 7402 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 7403 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 7404 | * remove one pending fabric iocb from the driver internal list and invokes |
| 7405 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 7406 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7407 | static void |
| 7408 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 7409 | { |
| 7410 | struct lpfc_iocbq *iocb; |
| 7411 | unsigned long iflags; |
| 7412 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7413 | IOCB_t *cmd; |
| 7414 | |
| 7415 | repeat: |
| 7416 | iocb = NULL; |
| 7417 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7418 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7419 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 7420 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 7421 | list); |
| 7422 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7423 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7424 | atomic_inc(&phba->fabric_iocb_count); |
| 7425 | } |
| 7426 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7427 | if (iocb) { |
| 7428 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7429 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7430 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7431 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7432 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7433 | "Fabric sched1: ste:x%x", |
| 7434 | iocb->vport->port_state, 0, 0); |
| 7435 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7436 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7437 | |
| 7438 | if (ret == IOCB_ERROR) { |
| 7439 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7440 | iocb->fabric_iocb_cmpl = NULL; |
| 7441 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7442 | cmd = &iocb->iocb; |
| 7443 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 7444 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 7445 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 7446 | |
| 7447 | atomic_dec(&phba->fabric_iocb_count); |
| 7448 | goto repeat; |
| 7449 | } |
| 7450 | } |
| 7451 | |
| 7452 | return; |
| 7453 | } |
| 7454 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7455 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7456 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7457 | * @phba: pointer to lpfc hba data structure. |
| 7458 | * |
| 7459 | * This routine unblocks the issuing fabric iocb command. The function |
| 7460 | * will clear the fabric iocb block bit and then invoke the routine |
| 7461 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 7462 | * from the driver internal fabric iocb list. |
| 7463 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7464 | void |
| 7465 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 7466 | { |
| 7467 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7468 | |
| 7469 | lpfc_resume_fabric_iocbs(phba); |
| 7470 | return; |
| 7471 | } |
| 7472 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7473 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7474 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7475 | * @phba: pointer to lpfc hba data structure. |
| 7476 | * |
| 7477 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 7478 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 7479 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 7480 | * fabric iocb will be issued out of the HBA. |
| 7481 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7482 | static void |
| 7483 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 7484 | { |
| 7485 | int blocked; |
| 7486 | |
| 7487 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7488 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7489 | if (!blocked) |
| 7490 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 7491 | |
| 7492 | return; |
| 7493 | } |
| 7494 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7495 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7496 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7497 | * @phba: pointer to lpfc hba data structure. |
| 7498 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7499 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7500 | * |
| 7501 | * This routine is the callback function that is put to the fabric iocb's |
| 7502 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 7503 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 7504 | * function first restores and invokes the original iocb's callback function |
| 7505 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 7506 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 7507 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7508 | static void |
| 7509 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7510 | struct lpfc_iocbq *rspiocb) |
| 7511 | { |
| 7512 | struct ls_rjt stat; |
| 7513 | |
| 7514 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 7515 | BUG(); |
| 7516 | |
| 7517 | switch (rspiocb->iocb.ulpStatus) { |
| 7518 | case IOSTAT_NPORT_RJT: |
| 7519 | case IOSTAT_FABRIC_RJT: |
| 7520 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 7521 | lpfc_block_fabric_iocbs(phba); |
| 7522 | } |
| 7523 | break; |
| 7524 | |
| 7525 | case IOSTAT_NPORT_BSY: |
| 7526 | case IOSTAT_FABRIC_BSY: |
| 7527 | lpfc_block_fabric_iocbs(phba); |
| 7528 | break; |
| 7529 | |
| 7530 | case IOSTAT_LS_RJT: |
| 7531 | stat.un.lsRjtError = |
| 7532 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 7533 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 7534 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 7535 | lpfc_block_fabric_iocbs(phba); |
| 7536 | break; |
| 7537 | } |
| 7538 | |
| 7539 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 7540 | BUG(); |
| 7541 | |
| 7542 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 7543 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 7544 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7545 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 7546 | |
| 7547 | atomic_dec(&phba->fabric_iocb_count); |
| 7548 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7549 | /* Post any pending iocbs to HBA */ |
| 7550 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7551 | } |
| 7552 | } |
| 7553 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7554 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7555 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7556 | * @phba: pointer to lpfc hba data structure. |
| 7557 | * @iocb: pointer to lpfc command iocb data structure. |
| 7558 | * |
| 7559 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 7560 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 7561 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 7562 | * any given time. As such, this function will first check to see whether there |
| 7563 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 7564 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 7565 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 7566 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 7567 | * |
| 7568 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 7569 | * order. The problem is caused by the construction of the "ready" boolen does |
| 7570 | * not include the condition that the internal fabric IOCB list is empty. As |
| 7571 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 7572 | * ahead of the fabric IOCBs in the internal list. |
| 7573 | * |
| 7574 | * Return code |
| 7575 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 7576 | * IOCB_ERROR - failed to issue fabric iocb |
| 7577 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7578 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7579 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 7580 | { |
| 7581 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7582 | int ready; |
| 7583 | int ret; |
| 7584 | |
| 7585 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 7586 | BUG(); |
| 7587 | |
| 7588 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7589 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 7590 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7591 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7592 | if (ready) |
| 7593 | /* Increment fabric iocb count to hold the position */ |
| 7594 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7595 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7596 | if (ready) { |
| 7597 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7598 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7599 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7600 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7601 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7602 | "Fabric sched2: ste:x%x", |
| 7603 | iocb->vport->port_state, 0, 0); |
| 7604 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7605 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7606 | |
| 7607 | if (ret == IOCB_ERROR) { |
| 7608 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7609 | iocb->fabric_iocb_cmpl = NULL; |
| 7610 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7611 | atomic_dec(&phba->fabric_iocb_count); |
| 7612 | } |
| 7613 | } else { |
| 7614 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7615 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 7616 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7617 | ret = IOCB_SUCCESS; |
| 7618 | } |
| 7619 | return ret; |
| 7620 | } |
| 7621 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7622 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7623 | * 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] | 7624 | * @vport: pointer to a virtual N_Port data structure. |
| 7625 | * |
| 7626 | * This routine aborts all the IOCBs associated with a @vport from the |
| 7627 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7628 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7629 | * list, removes each IOCB associated with the @vport off the list, set the |
| 7630 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7631 | * associated with the IOCB. |
| 7632 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7633 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7634 | { |
| 7635 | LIST_HEAD(completions); |
| 7636 | struct lpfc_hba *phba = vport->phba; |
| 7637 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7638 | |
| 7639 | spin_lock_irq(&phba->hbalock); |
| 7640 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7641 | list) { |
| 7642 | |
| 7643 | if (piocb->vport != vport) |
| 7644 | continue; |
| 7645 | |
| 7646 | list_move_tail(&piocb->list, &completions); |
| 7647 | } |
| 7648 | spin_unlock_irq(&phba->hbalock); |
| 7649 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7650 | /* Cancel all the IOCBs from the completions list */ |
| 7651 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7652 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7653 | } |
| 7654 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7655 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7656 | * 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] | 7657 | * @ndlp: pointer to a node-list data structure. |
| 7658 | * |
| 7659 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 7660 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7661 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7662 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 7663 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7664 | * associated with the IOCB. |
| 7665 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7666 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 7667 | { |
| 7668 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7669 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7670 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7671 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7672 | |
| 7673 | spin_lock_irq(&phba->hbalock); |
| 7674 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7675 | list) { |
| 7676 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 7677 | |
| 7678 | list_move_tail(&piocb->list, &completions); |
| 7679 | } |
| 7680 | } |
| 7681 | spin_unlock_irq(&phba->hbalock); |
| 7682 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7683 | /* Cancel all the IOCBs from the completions list */ |
| 7684 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7685 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7686 | } |
| 7687 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7688 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7689 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7690 | * @phba: pointer to lpfc hba data structure. |
| 7691 | * |
| 7692 | * This routine aborts all the IOCBs currently on the driver internal |
| 7693 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 7694 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 7695 | * list, removes IOCBs off the list, set the status feild to |
| 7696 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 7697 | * the IOCB. |
| 7698 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7699 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 7700 | { |
| 7701 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7702 | |
| 7703 | spin_lock_irq(&phba->hbalock); |
| 7704 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 7705 | spin_unlock_irq(&phba->hbalock); |
| 7706 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7707 | /* Cancel all the IOCBs from the completions list */ |
| 7708 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7709 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7710 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7711 | |
| 7712 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 7713 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport |
| 7714 | * @vport: pointer to lpfc vport data structure. |
| 7715 | * |
| 7716 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 7717 | * for an ndlp on removal. |
| 7718 | **/ |
| 7719 | void |
| 7720 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) |
| 7721 | { |
| 7722 | struct lpfc_hba *phba = vport->phba; |
| 7723 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7724 | unsigned long iflag = 0; |
| 7725 | |
| 7726 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7727 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
| 7728 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 7729 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 7730 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) |
| 7731 | sglq_entry->ndlp = NULL; |
| 7732 | } |
| 7733 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 7734 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7735 | return; |
| 7736 | } |
| 7737 | |
| 7738 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7739 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 7740 | * @phba: pointer to lpfc hba data structure. |
| 7741 | * @axri: pointer to the els xri abort wcqe structure. |
| 7742 | * |
| 7743 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 7744 | * ELS aborted xri. |
| 7745 | **/ |
| 7746 | void |
| 7747 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 7748 | struct sli4_wcqe_xri_aborted *axri) |
| 7749 | { |
| 7750 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7751 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
| 7752 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7753 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7754 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7755 | struct lpfc_nodelist *ndlp; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7756 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7757 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7758 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7759 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7760 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 7761 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 7762 | if (sglq_entry->sli4_xritag == xri) { |
| 7763 | list_del(&sglq_entry->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7764 | ndlp = sglq_entry->ndlp; |
| 7765 | sglq_entry->ndlp = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7766 | list_add_tail(&sglq_entry->list, |
| 7767 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7768 | sglq_entry->state = SGL_FREED; |
| 7769 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7770 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7771 | lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7772 | |
| 7773 | /* Check if TXQ queue needs to be serviced */ |
| 7774 | if (pring->txq_cnt) |
| 7775 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7776 | return; |
| 7777 | } |
| 7778 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7779 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 7780 | sglq_entry = __lpfc_get_active_sglq(phba, xri); |
| 7781 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
| 7782 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7783 | return; |
| 7784 | } |
| 7785 | sglq_entry->state = SGL_XRI_ABORTED; |
| 7786 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7787 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7788 | } |