| 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 | d8e93df | 2009-05-22 14:53:05 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2009 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 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 92 | ha_copy = readl(phba->HAregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 93 | |
| 94 | if (!(ha_copy & HA_LATT)) |
| 95 | return 0; |
| 96 | |
| 97 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 98 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 99 | "0237 Pending Link Event during " |
| 100 | "Discovery: State x%x\n", |
| 101 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 102 | |
| 103 | /* CLEAR_LA should re-enable link attention events and |
| 104 | * we should then imediately take a LATT event. The |
| 105 | * LATT processing should call lpfc_linkdown() which |
| 106 | * will cleanup any left over in-progress discovery |
| 107 | * events. |
| 108 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 109 | spin_lock_irq(shost->host_lock); |
| 110 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 111 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 112 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 113 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 114 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 115 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 116 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 117 | } |
| 118 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 119 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 120 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 121 | * @vport: pointer to a host virtual N_Port data structure. |
| 122 | * @expectRsp: flag indicating whether response is expected. |
| 123 | * @cmdSize: size of the ELS command. |
| 124 | * @retry: number of retries to the command IOCB when it fails. |
| 125 | * @ndlp: pointer to a node-list data structure. |
| 126 | * @did: destination identifier. |
| 127 | * @elscmd: the ELS command code. |
| 128 | * |
| 129 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 130 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 131 | * passed into the routine for discovery state machine to issue an Extended |
| 132 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 133 | * and preparation routine that is used by all the discovery state machine |
| 134 | * routines and the ELS command-specific fields will be later set up by |
| 135 | * the individual discovery machine routines after calling this routine |
| 136 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 137 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 138 | * payload and response payload (if expected). The reference count on the |
| 139 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 140 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 141 | * reference for the command's callback function to access later. |
| 142 | * |
| 143 | * Return code |
| 144 | * Pointer to the newly allocated/prepared els iocb data structure |
| 145 | * NULL - when els iocb data structure allocation/preparation failed |
| 146 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 147 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 148 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 149 | uint16_t cmdSize, uint8_t retry, |
| 150 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 151 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 152 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 153 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 154 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 155 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 156 | struct ulp_bde64 *bpl; |
| 157 | IOCB_t *icmd; |
| 158 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 159 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 160 | if (!lpfc_is_link_up(phba)) |
| 161 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 162 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 164 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 165 | |
| 166 | if (elsiocb == NULL) |
| 167 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 168 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 169 | /* |
| 170 | * If this command is for fabric controller and HBA running |
| 171 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. |
| 172 | */ |
| 173 | if ((did == Fabric_DID) && |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 174 | (phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 175 | ((elscmd == ELS_CMD_FLOGI) || |
| 176 | (elscmd == ELS_CMD_FDISC) || |
| 177 | (elscmd == ELS_CMD_LOGO))) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 178 | switch (elscmd) { |
| 179 | case ELS_CMD_FLOGI: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 180 | elsiocb->iocb_flag |= |
| 181 | ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 182 | & LPFC_FIP_ELS_ID_MASK); |
| 183 | break; |
| 184 | case ELS_CMD_FDISC: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 185 | elsiocb->iocb_flag |= |
| 186 | ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 187 | & LPFC_FIP_ELS_ID_MASK); |
| 188 | break; |
| 189 | case ELS_CMD_LOGO: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 190 | elsiocb->iocb_flag |= |
| 191 | ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 192 | & LPFC_FIP_ELS_ID_MASK); |
| 193 | break; |
| 194 | } |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 195 | else |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 196 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 197 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 198 | icmd = &elsiocb->iocb; |
| 199 | |
| 200 | /* fill in BDEs for command */ |
| 201 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 202 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 203 | if (pcmd) |
| 204 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 205 | if (!pcmd || !pcmd->virt) |
| 206 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 207 | |
| 208 | INIT_LIST_HEAD(&pcmd->list); |
| 209 | |
| 210 | /* Allocate buffer for response payload */ |
| 211 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 212 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 213 | if (prsp) |
| 214 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 215 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 216 | if (!prsp || !prsp->virt) |
| 217 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 218 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 219 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 220 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 221 | |
| 222 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 223 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 224 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 225 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 226 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 227 | if (!pbuflist || !pbuflist->virt) |
| 228 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 229 | |
| 230 | INIT_LIST_HEAD(&pbuflist->list); |
| 231 | |
| 232 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 233 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 234 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 235 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 236 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 237 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 238 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 239 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 240 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 241 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 242 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 243 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 244 | icmd->ulpBdeCount = 1; |
| 245 | icmd->ulpLe = 1; |
| 246 | icmd->ulpClass = CLASS3; |
| 247 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 248 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 249 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 250 | |
| 251 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 252 | icmd->ulpContext = vport->vpi + phba->vpi_base; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 253 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 254 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 255 | if (elscmd == ELS_CMD_ECHO) |
| 256 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 257 | else |
| 258 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 259 | } |
| 260 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 261 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 262 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 263 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 264 | bpl->tus.f.bdeSize = cmdSize; |
| 265 | bpl->tus.f.bdeFlags = 0; |
| 266 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 267 | |
| 268 | if (expectRsp) { |
| 269 | bpl++; |
| 270 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 271 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 272 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 273 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 274 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 275 | } |
| 276 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 277 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 278 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 279 | if (!elsiocb->context1) |
| 280 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 281 | elsiocb->context2 = pcmd; |
| 282 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 283 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 284 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 285 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 286 | |
| 287 | if (prsp) { |
| 288 | list_add(&prsp->list, &pcmd->list); |
| 289 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 290 | if (expectRsp) { |
| 291 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 292 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 293 | "0116 Xmit ELS command x%x to remote " |
| 294 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 295 | elscmd, did, elsiocb->iotag, |
| 296 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 297 | } else { |
| 298 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 299 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 300 | "0117 Xmit ELS response x%x to remote " |
| 301 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 302 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 303 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 304 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 305 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 306 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 307 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 308 | if (expectRsp) |
| 309 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 310 | kfree(pbuflist); |
| 311 | |
| 312 | els_iocb_free_prsp_exit: |
| 313 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 314 | kfree(prsp); |
| 315 | |
| 316 | els_iocb_free_pcmb_exit: |
| 317 | kfree(pcmd); |
| 318 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 319 | return NULL; |
| 320 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 321 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 322 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 323 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 324 | * @vport: pointer to a host virtual N_Port data structure. |
| 325 | * |
| 326 | * This routine issues a fabric registration login for a @vport. An |
| 327 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 328 | * The routine invokes two mailbox commands to carry out fabric registration |
| 329 | * login through the HBA firmware: the first mailbox command requests the |
| 330 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 331 | * command requests the HBA to perform the actual fabric registration login |
| 332 | * with the @vport. |
| 333 | * |
| 334 | * Return code |
| 335 | * 0 - successfully issued fabric registration login for @vport |
| 336 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 337 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 338 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 339 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 340 | { |
| 341 | struct lpfc_hba *phba = vport->phba; |
| 342 | LPFC_MBOXQ_t *mbox; |
| 343 | struct lpfc_dmabuf *mp; |
| 344 | struct lpfc_nodelist *ndlp; |
| 345 | struct serv_parm *sp; |
| 346 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 347 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 348 | |
| 349 | sp = &phba->fc_fabparam; |
| 350 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 351 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 352 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 353 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 354 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 355 | |
| 356 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 357 | if (!mbox) { |
| 358 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 359 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 360 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 361 | |
| 362 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 363 | lpfc_config_link(phba, mbox); |
| 364 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 365 | mbox->vport = vport; |
| 366 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 367 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 368 | if (rc == MBX_NOT_FINISHED) { |
| 369 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 370 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 371 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 372 | |
| 373 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 374 | if (!mbox) { |
| 375 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 376 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 377 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 378 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 379 | if (rc) { |
| 380 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 381 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 382 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 383 | |
| 384 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 385 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 386 | /* increment the reference count on ndlp to hold reference |
| 387 | * for the callback routine. |
| 388 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 389 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 390 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 391 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 392 | if (rc == MBX_NOT_FINISHED) { |
| 393 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 394 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 395 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 396 | |
| 397 | return 0; |
| 398 | |
| 399 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 400 | /* decrement the reference count on ndlp just incremented |
| 401 | * for the failed mbox command. |
| 402 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 403 | lpfc_nlp_put(ndlp); |
| 404 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 405 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 406 | kfree(mp); |
| 407 | fail_free_mbox: |
| 408 | mempool_free(mbox, phba->mbox_mem_pool); |
| 409 | |
| 410 | fail: |
| 411 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 412 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 413 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 414 | return -ENXIO; |
| 415 | } |
| 416 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 417 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 418 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 419 | * @vport: pointer to a host virtual N_Port data structure. |
| 420 | * |
| 421 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
| 422 | * the @vport. This mailbox command is necessary for FCoE only. |
| 423 | * |
| 424 | * Return code |
| 425 | * 0 - successfully issued REG_VFI for @vport |
| 426 | * A failure code otherwise. |
| 427 | **/ |
| 428 | static int |
| 429 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 430 | { |
| 431 | struct lpfc_hba *phba = vport->phba; |
| 432 | LPFC_MBOXQ_t *mboxq; |
| 433 | struct lpfc_nodelist *ndlp; |
| 434 | struct serv_parm *sp; |
| 435 | struct lpfc_dmabuf *dmabuf; |
| 436 | int rc = 0; |
| 437 | |
| 438 | sp = &phba->fc_fabparam; |
| 439 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 440 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 441 | rc = -ENODEV; |
| 442 | goto fail; |
| 443 | } |
| 444 | |
| 445 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 446 | if (!dmabuf) { |
| 447 | rc = -ENOMEM; |
| 448 | goto fail; |
| 449 | } |
| 450 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 451 | if (!dmabuf->virt) { |
| 452 | rc = -ENOMEM; |
| 453 | goto fail_free_dmabuf; |
| 454 | } |
| 455 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 456 | if (!mboxq) { |
| 457 | rc = -ENOMEM; |
| 458 | goto fail_free_coherent; |
| 459 | } |
| 460 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 461 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 462 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 463 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 464 | mboxq->vport = vport; |
| 465 | mboxq->context1 = dmabuf; |
| 466 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 467 | if (rc == MBX_NOT_FINISHED) { |
| 468 | rc = -ENXIO; |
| 469 | goto fail_free_mbox; |
| 470 | } |
| 471 | return 0; |
| 472 | |
| 473 | fail_free_mbox: |
| 474 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 475 | fail_free_coherent: |
| 476 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 477 | fail_free_dmabuf: |
| 478 | kfree(dmabuf); |
| 479 | fail: |
| 480 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 481 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 482 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 483 | return rc; |
| 484 | } |
| 485 | |
| 486 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 487 | * 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] | 488 | * @vport: pointer to a host virtual N_Port data structure. |
| 489 | * @ndlp: pointer to a node-list data structure. |
| 490 | * @sp: pointer to service parameter data structure. |
| 491 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 492 | * |
| 493 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 494 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 495 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 496 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 497 | * @vport against the previously assigned N_Port ID. If it is different from |
| 498 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 499 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 500 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 501 | * is invoked to register login to the fabric. |
| 502 | * |
| 503 | * Return code |
| 504 | * 0 - Success (currently, always return 0) |
| 505 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 506 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 507 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 508 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 509 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 510 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 511 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 512 | struct lpfc_nodelist *np; |
| 513 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 515 | spin_lock_irq(shost->host_lock); |
| 516 | vport->fc_flag |= FC_FABRIC; |
| 517 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 518 | |
| 519 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 520 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 521 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 522 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 523 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 524 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 525 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 526 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 527 | spin_lock_irq(shost->host_lock); |
| 528 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 529 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 530 | } |
| 531 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 532 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 533 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 534 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 535 | ndlp->nlp_class_sup = 0; |
| 536 | if (sp->cls1.classValid) |
| 537 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 538 | if (sp->cls2.classValid) |
| 539 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 540 | if (sp->cls3.classValid) |
| 541 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 542 | if (sp->cls4.classValid) |
| 543 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 544 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 545 | sp->cmn.bbRcvSizeLsb; |
| 546 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 547 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 548 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 549 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 550 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 551 | LOG_ELS | LOG_VPORT, |
| 552 | "1816 FLOGI NPIV supported, " |
| 553 | "response data 0x%x\n", |
| 554 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 555 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 556 | } else { |
| 557 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 558 | to call reg_vnpid atleast for the physcial host */ |
| 559 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 560 | LOG_ELS | LOG_VPORT, |
| 561 | "1817 Fabric does not support NPIV " |
| 562 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 563 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 568 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 569 | |
| 570 | /* If our NportID changed, we need to ensure all |
| 571 | * remaining NPORTs get unreg_login'ed. |
| 572 | */ |
| 573 | list_for_each_entry_safe(np, next_np, |
| 574 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 575 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 576 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 577 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 578 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 579 | continue; |
| 580 | spin_lock_irq(shost->host_lock); |
| 581 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 582 | spin_unlock_irq(shost->host_lock); |
| 583 | lpfc_unreg_rpi(vport, np); |
| 584 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 585 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 586 | |
| 587 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 588 | lpfc_sli4_unreg_all_rpis(vport); |
| 589 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 590 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 591 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 592 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 593 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 594 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 595 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 596 | /* |
| 597 | * If VPI is unreged, driver need to do INIT_VPI |
| 598 | * before re-registering |
| 599 | */ |
| 600 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 601 | spin_lock_irq(shost->host_lock); |
| 602 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 603 | spin_unlock_irq(shost->host_lock); |
| 604 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 605 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 606 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 607 | /* |
| 608 | * Driver needs to re-reg VPI in order for f/w |
| 609 | * to update the MAC address. |
| 610 | */ |
| 611 | lpfc_register_new_vport(phba, vport, ndlp); |
| 612 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 613 | } |
| 614 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 615 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 616 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 617 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 618 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 619 | lpfc_register_new_vport(phba, vport, ndlp); |
| 620 | else |
| 621 | lpfc_issue_fabric_reglogin(vport); |
| 622 | } else { |
| 623 | ndlp->nlp_type |= NLP_FABRIC; |
| 624 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 625 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 626 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 627 | lpfc_start_fdiscs(phba); |
| 628 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 629 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 630 | lpfc_issue_init_vpi(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 631 | else |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 632 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 633 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 634 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 635 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 636 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 637 | * 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] | 638 | * @vport: pointer to a host virtual N_Port data structure. |
| 639 | * @ndlp: pointer to a node-list data structure. |
| 640 | * @sp: pointer to service parameter data structure. |
| 641 | * |
| 642 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 643 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 644 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 645 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 646 | * the received N_Port Name lexicographically, this node shall assign local |
| 647 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 648 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 649 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 650 | * N_Port IDs. |
| 651 | * |
| 652 | * Return code |
| 653 | * 0 - Success |
| 654 | * -ENXIO - Fail |
| 655 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 656 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 657 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 658 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 659 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 660 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 661 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 662 | LPFC_MBOXQ_t *mbox; |
| 663 | int rc; |
| 664 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 665 | spin_lock_irq(shost->host_lock); |
| 666 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 667 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 668 | |
| 669 | phba->fc_edtov = FF_DEF_EDTOV; |
| 670 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 671 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 672 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 673 | if (rc >= 0) { |
| 674 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 675 | spin_lock_irq(shost->host_lock); |
| 676 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 677 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 678 | |
| 679 | /* |
| 680 | * N_Port ID cannot be 0, set our to LocalID the other |
| 681 | * side will be RemoteID. |
| 682 | */ |
| 683 | |
| 684 | /* not equal */ |
| 685 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 686 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 687 | |
| 688 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 689 | if (!mbox) |
| 690 | goto fail; |
| 691 | |
| 692 | lpfc_config_link(phba, mbox); |
| 693 | |
| 694 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 695 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 696 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 697 | if (rc == MBX_NOT_FINISHED) { |
| 698 | mempool_free(mbox, phba->mbox_mem_pool); |
| 699 | goto fail; |
| 700 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 701 | /* Decrement ndlp reference count indicating that ndlp can be |
| 702 | * safely released when other references to it are done. |
| 703 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 704 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 705 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 706 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 707 | if (!ndlp) { |
| 708 | /* |
| 709 | * Cannot find existing Fabric ndlp, so allocate a |
| 710 | * new one |
| 711 | */ |
| 712 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 713 | if (!ndlp) |
| 714 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 715 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 716 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 717 | ndlp = lpfc_enable_node(vport, ndlp, |
| 718 | NLP_STE_UNUSED_NODE); |
| 719 | if(!ndlp) |
| 720 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 724 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 725 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 726 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 727 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 728 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 729 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 730 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 731 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 732 | } else |
| 733 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 734 | * count indicating that ndlp can be released when other |
| 735 | * references to it are done. |
| 736 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 737 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 738 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 739 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 740 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 741 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 742 | spin_lock_irq(shost->host_lock); |
| 743 | vport->fc_flag |= FC_PT2PT; |
| 744 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 745 | |
| 746 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 747 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 748 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 749 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 750 | return -ENXIO; |
| 751 | } |
| 752 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 753 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 754 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 755 | * @phba: pointer to lpfc hba data structure. |
| 756 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 757 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 758 | * |
| 759 | * This routine is the top-level completion callback function for issuing |
| 760 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 761 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 762 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 763 | * returning 1), the command IOCB will be released and function returned. |
| 764 | * If the retry attempt has been given up (possibly reach the maximum |
| 765 | * number of retries), one additional decrement of ndlp reference shall be |
| 766 | * invoked before going out after releasing the command IOCB. This will |
| 767 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 768 | * invoke one decrement of ndlp reference count). If no error reported in |
| 769 | * the IOCB status, the command Port ID field is used to determine whether |
| 770 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 771 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 772 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 773 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 774 | * specific topology completion conditions. |
| 775 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 776 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 777 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 778 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 779 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 780 | struct lpfc_vport *vport = cmdiocb->vport; |
| 781 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 782 | IOCB_t *irsp = &rspiocb->iocb; |
| 783 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 784 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 785 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 786 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 787 | int rc; |
| 788 | |
| 789 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 790 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 791 | /* One additional decrement on node reference count to |
| 792 | * trigger the release of the node |
| 793 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 794 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 795 | goto out; |
| 796 | } |
| 797 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 798 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 799 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 800 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 801 | vport->port_state); |
| 802 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 803 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 804 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 805 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 806 | * due to new FCF discovery |
| 807 | */ |
| 808 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 809 | (phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 810 | (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) && |
| 811 | (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 812 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 813 | "2611 FLOGI failed on FCF (x%x), " |
| 814 | "status:x%x/x%x, tmo:x%x, perform " |
| 815 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 816 | phba->fcf.current_rec.fcf_indx, |
| 817 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 818 | irsp->ulpTimeout); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 819 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 820 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 821 | if (rc) |
| 822 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 823 | } |
| 824 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 825 | /* FLOGI failure */ |
| 826 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 827 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 828 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 829 | irsp->ulpTimeout); |
| 830 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 831 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 832 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 833 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 834 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 835 | /* FLOGI failure */ |
| 836 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 837 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 838 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 839 | irsp->ulpTimeout); |
| 840 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 841 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 842 | spin_lock_irq(shost->host_lock); |
| 843 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 844 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 845 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 846 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 847 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 848 | * alpa map would take too long otherwise. |
| 849 | */ |
| 850 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 851 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 852 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 853 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
| 854 | (vport->fc_prevDID != vport->fc_myDID))) { |
| 855 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 856 | lpfc_sli4_unreg_all_rpis(vport); |
| 857 | lpfc_issue_reg_vfi(vport); |
| 858 | lpfc_nlp_put(ndlp); |
| 859 | goto out; |
| 860 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 861 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 862 | goto flogifail; |
| 863 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 864 | spin_lock_irq(shost->host_lock); |
| 865 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 866 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 867 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 868 | |
| 869 | /* |
| 870 | * The FLogI succeeded. Sync the data for the CPU before |
| 871 | * accessing it. |
| 872 | */ |
| 873 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 874 | |
| 875 | sp = prsp->virt + sizeof(uint32_t); |
| 876 | |
| 877 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 878 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 879 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 880 | "Data: x%x x%x x%x x%x\n", |
| 881 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 882 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 883 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 884 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 885 | /* |
| 886 | * If Common Service Parameters indicate Nport |
| 887 | * we are point to point, if Fport we are Fabric. |
| 888 | */ |
| 889 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 890 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 891 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 892 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 893 | else { |
| 894 | lpfc_printf_vlog(vport, KERN_ERR, |
| 895 | LOG_FIP | LOG_ELS, |
| 896 | "2831 FLOGI response with cleared Fabric " |
| 897 | "bit fcf_index 0x%x " |
| 898 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 899 | "Fabric Name " |
| 900 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 901 | phba->fcf.current_rec.fcf_indx, |
| 902 | phba->fcf.current_rec.switch_name[0], |
| 903 | phba->fcf.current_rec.switch_name[1], |
| 904 | phba->fcf.current_rec.switch_name[2], |
| 905 | phba->fcf.current_rec.switch_name[3], |
| 906 | phba->fcf.current_rec.switch_name[4], |
| 907 | phba->fcf.current_rec.switch_name[5], |
| 908 | phba->fcf.current_rec.switch_name[6], |
| 909 | phba->fcf.current_rec.switch_name[7], |
| 910 | phba->fcf.current_rec.fabric_name[0], |
| 911 | phba->fcf.current_rec.fabric_name[1], |
| 912 | phba->fcf.current_rec.fabric_name[2], |
| 913 | phba->fcf.current_rec.fabric_name[3], |
| 914 | phba->fcf.current_rec.fabric_name[4], |
| 915 | phba->fcf.current_rec.fabric_name[5], |
| 916 | phba->fcf.current_rec.fabric_name[6], |
| 917 | phba->fcf.current_rec.fabric_name[7]); |
| 918 | lpfc_nlp_put(ndlp); |
| 919 | spin_lock_irq(&phba->hbalock); |
| 920 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 921 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 922 | spin_unlock_irq(&phba->hbalock); |
| 923 | goto out; |
| 924 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 925 | if (!rc) { |
| 926 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 927 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 928 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 929 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 930 | "2769 FLOGI to FCF (x%x) " |
| 931 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 932 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 933 | spin_lock_irq(&phba->hbalock); |
| 934 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 935 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 936 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 937 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 938 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 942 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 943 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 944 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 945 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 946 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 947 | |
| 948 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 949 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 950 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 951 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 952 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 953 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 954 | /* If FLOGI failed enable link interrupt. */ |
| 955 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 956 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 957 | out: |
| 958 | lpfc_els_free_iocb(phba, cmdiocb); |
| 959 | } |
| 960 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 961 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 962 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 963 | * @vport: pointer to a host virtual N_Port data structure. |
| 964 | * @ndlp: pointer to a node-list data structure. |
| 965 | * @retry: number of retries to the command IOCB. |
| 966 | * |
| 967 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 968 | * for a @vport. The initiator service parameters are put into the payload |
| 969 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 970 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 971 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 972 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 973 | * |
| 974 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 975 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 976 | * will be stored into the context1 field of the IOCB for the completion |
| 977 | * callback function to the FLOGI ELS command. |
| 978 | * |
| 979 | * Return code |
| 980 | * 0 - successfully issued flogi iocb for @vport |
| 981 | * 1 - failed to issue flogi iocb for @vport |
| 982 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 983 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 984 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 985 | uint8_t retry) |
| 986 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 987 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 988 | struct serv_parm *sp; |
| 989 | IOCB_t *icmd; |
| 990 | struct lpfc_iocbq *elsiocb; |
| 991 | struct lpfc_sli_ring *pring; |
| 992 | uint8_t *pcmd; |
| 993 | uint16_t cmdsize; |
| 994 | uint32_t tmo; |
| 995 | int rc; |
| 996 | |
| 997 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 998 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 999 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1000 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1001 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1002 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1003 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1004 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1005 | |
| 1006 | icmd = &elsiocb->iocb; |
| 1007 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1008 | |
| 1009 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1010 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1011 | pcmd += sizeof(uint32_t); |
| 1012 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1013 | sp = (struct serv_parm *) pcmd; |
| 1014 | |
| 1015 | /* Setup CSPs accordingly for Fabric */ |
| 1016 | sp->cmn.e_d_tov = 0; |
| 1017 | sp->cmn.w2.r_a_tov = 0; |
| 1018 | sp->cls1.classValid = 0; |
| 1019 | sp->cls2.seqDelivery = 1; |
| 1020 | sp->cls3.seqDelivery = 1; |
| 1021 | if (sp->cmn.fcphLow < FC_PH3) |
| 1022 | sp->cmn.fcphLow = FC_PH3; |
| 1023 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1024 | sp->cmn.fcphHigh = FC_PH3; |
| 1025 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1026 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1027 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1028 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1029 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1030 | /* Set the fcfi to the fcfi we registered with */ |
| 1031 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1032 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1033 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1034 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1035 | icmd->ulpCt_h = 1; |
| 1036 | icmd->ulpCt_l = 0; |
| 1037 | } |
| 1038 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 1039 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1040 | icmd->un.elsreq64.myID = 0; |
| 1041 | icmd->un.elsreq64.fl = 1; |
| 1042 | } |
| 1043 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1044 | tmo = phba->fc_ratov; |
| 1045 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1046 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1047 | phba->fc_ratov = tmo; |
| 1048 | |
| 1049 | phba->fc_stat.elsXmitFLOGI++; |
| 1050 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1051 | |
| 1052 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1053 | "Issue FLOGI: opt:x%x", |
| 1054 | phba->sli3_options, 0, 0); |
| 1055 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1056 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1057 | if (rc == IOCB_ERROR) { |
| 1058 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1059 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1060 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1061 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1062 | } |
| 1063 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1064 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1065 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1066 | * @phba: pointer to lpfc hba data structure. |
| 1067 | * |
| 1068 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1069 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1070 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1071 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1072 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1073 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1074 | * |
| 1075 | * Return code |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1076 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1077 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1078 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1079 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1080 | { |
| 1081 | struct lpfc_sli_ring *pring; |
| 1082 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1083 | struct lpfc_nodelist *ndlp; |
| 1084 | IOCB_t *icmd; |
| 1085 | |
| 1086 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1087 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1088 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1089 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1090 | |
| 1091 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1092 | |
| 1093 | /* |
| 1094 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1095 | * searching for. |
| 1096 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1097 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1098 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1099 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1100 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 1101 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1102 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1103 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1104 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1105 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1106 | } |
| 1107 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1108 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1109 | |
| 1110 | return 0; |
| 1111 | } |
| 1112 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1113 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1114 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1115 | * @vport: pointer to a host virtual N_Port data structure. |
| 1116 | * |
| 1117 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1118 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1119 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1120 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1121 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1122 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1123 | * @vport. |
| 1124 | * |
| 1125 | * Return code |
| 1126 | * 0 - failed to issue initial flogi for @vport |
| 1127 | * 1 - successfully issued initial flogi for @vport |
| 1128 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1129 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1130 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1131 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1132 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1133 | struct lpfc_nodelist *ndlp; |
| 1134 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1135 | vport->port_state = LPFC_FLOGI; |
| 1136 | lpfc_set_disctmo(vport); |
| 1137 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1138 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1139 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1140 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1141 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1142 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1143 | if (!ndlp) |
| 1144 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1145 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1146 | /* Set the node type */ |
| 1147 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1148 | /* Put ndlp onto node list */ |
| 1149 | lpfc_enqueue_node(vport, ndlp); |
| 1150 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1151 | /* re-setup ndlp without removing from node list */ |
| 1152 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1153 | if (!ndlp) |
| 1154 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1155 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1156 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1157 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1158 | /* This decrement of reference count to node shall kick off |
| 1159 | * the release of the node. |
| 1160 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1161 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1162 | return 0; |
| 1163 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1164 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1165 | } |
| 1166 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1167 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1168 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1169 | * @vport: pointer to a host virtual N_Port data structure. |
| 1170 | * |
| 1171 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1172 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1173 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1174 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1175 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1176 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1177 | * @vport. |
| 1178 | * |
| 1179 | * Return code |
| 1180 | * 0 - failed to issue initial fdisc for @vport |
| 1181 | * 1 - successfully issued initial fdisc for @vport |
| 1182 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1183 | int |
| 1184 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1185 | { |
| 1186 | struct lpfc_hba *phba = vport->phba; |
| 1187 | struct lpfc_nodelist *ndlp; |
| 1188 | |
| 1189 | /* First look for the Fabric ndlp */ |
| 1190 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1191 | if (!ndlp) { |
| 1192 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1193 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1194 | if (!ndlp) |
| 1195 | return 0; |
| 1196 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1197 | /* Put ndlp onto node list */ |
| 1198 | lpfc_enqueue_node(vport, ndlp); |
| 1199 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1200 | /* re-setup ndlp without removing from node list */ |
| 1201 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1202 | if (!ndlp) |
| 1203 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1204 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1205 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1206 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1207 | /* decrement node reference count to trigger the release of |
| 1208 | * the node. |
| 1209 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1210 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1211 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1212 | } |
| 1213 | return 1; |
| 1214 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1215 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1216 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1217 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1218 | * @vport: pointer to a host virtual N_Port data structure. |
| 1219 | * |
| 1220 | * This routine checks whether there are more remaining Port Logins |
| 1221 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1222 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1223 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1224 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1225 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1226 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1227 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1228 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1229 | { |
| 1230 | int sentplogi; |
| 1231 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1232 | if (vport->num_disc_nodes) |
| 1233 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1234 | |
| 1235 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1236 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1237 | "0232 Continue discovery with %d PLOGIs to go " |
| 1238 | "Data: x%x x%x x%x\n", |
| 1239 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1240 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1241 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1242 | if (vport->fc_flag & FC_NLP_MORE) |
| 1243 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1244 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1245 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1246 | return; |
| 1247 | } |
| 1248 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1249 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1250 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1251 | * @phba: pointer to lpfc hba data structure. |
| 1252 | * @prsp: pointer to response IOCB payload. |
| 1253 | * @ndlp: pointer to a node-list data structure. |
| 1254 | * |
| 1255 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1256 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1257 | * The following cases are considered N_Port confirmed: |
| 1258 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1259 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1260 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1261 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1262 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1263 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1264 | * on that node to release the RPI associated with the node; 2) if there is |
| 1265 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1266 | * into, a new node shall be allocated (or activated). In either case, the |
| 1267 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1268 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1269 | * its pointer returned as the confirmed node. |
| 1270 | * |
| 1271 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1272 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1273 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1274 | * into an inactive state on the vport node list and the vport node list |
| 1275 | * management algorithm does not allow two node with a same DID. |
| 1276 | * |
| 1277 | * Return code |
| 1278 | * pointer to the PLOGI N_Port @ndlp |
| 1279 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1280 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1281 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1282 | struct lpfc_nodelist *ndlp) |
| 1283 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1284 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1285 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1286 | struct lpfc_rport_data *rdata; |
| 1287 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1288 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1289 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1290 | uint32_t rc, keepDID = 0; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1291 | int put_node; |
| 1292 | int put_rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1293 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1294 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1295 | * by WWPN. Just return the ndlp that was given to us. |
| 1296 | */ |
| 1297 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1298 | return ndlp; |
| 1299 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1300 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1301 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1302 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1303 | /* 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] | 1304 | * we have for that ndlp. If not, we have some work to do. |
| 1305 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1306 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1307 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1308 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1309 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1310 | |
| 1311 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1312 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1313 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1314 | if (!rc) |
| 1315 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1316 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1317 | if (!new_ndlp) |
| 1318 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1319 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1320 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1321 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1322 | sizeof(struct lpfc_name)); |
| 1323 | if (!rc) |
| 1324 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1325 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1326 | NLP_STE_UNUSED_NODE); |
| 1327 | if (!new_ndlp) |
| 1328 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1329 | keepDID = new_ndlp->nlp_DID; |
| 1330 | } else |
| 1331 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1332 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1333 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1334 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1335 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1336 | |
| 1337 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1338 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1339 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1340 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1341 | /* 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] | 1342 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1343 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1344 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1345 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1346 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1347 | * to put ndlp on UNUSED list and try to free it. |
| 1348 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1349 | |
| 1350 | /* Fix up the rport accordingly */ |
| 1351 | rport = ndlp->rport; |
| 1352 | if (rport) { |
| 1353 | rdata = rport->dd_data; |
| 1354 | if (rdata->pnode == ndlp) { |
| 1355 | lpfc_nlp_put(ndlp); |
| 1356 | ndlp->rport = NULL; |
| 1357 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1358 | new_ndlp->rport = rport; |
| 1359 | } |
| 1360 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1361 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1362 | /* We shall actually free the ndlp with both nlp_DID and |
| 1363 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1364 | * nodelist never to be used. |
| 1365 | */ |
| 1366 | if (ndlp->nlp_DID == 0) { |
| 1367 | spin_lock_irq(&phba->ndlp_lock); |
| 1368 | NLP_SET_FREE_REQ(ndlp); |
| 1369 | spin_unlock_irq(&phba->ndlp_lock); |
| 1370 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1371 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1372 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1373 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1374 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1375 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1376 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1377 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1378 | /* Two ndlps cannot have the same did */ |
| 1379 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1380 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1381 | /* Since we are swapping the ndlp passed in with the new one |
| 1382 | * and the did has already been swapped, copy over the |
| 1383 | * state and names. |
| 1384 | */ |
| 1385 | memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname, |
| 1386 | sizeof(struct lpfc_name)); |
| 1387 | memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename, |
| 1388 | sizeof(struct lpfc_name)); |
| 1389 | new_ndlp->nlp_state = ndlp->nlp_state; |
| 1390 | /* Fix up the rport accordingly */ |
| 1391 | rport = ndlp->rport; |
| 1392 | if (rport) { |
| 1393 | rdata = rport->dd_data; |
| 1394 | put_node = rdata->pnode != NULL; |
| 1395 | put_rport = ndlp->rport != NULL; |
| 1396 | rdata->pnode = NULL; |
| 1397 | ndlp->rport = NULL; |
| 1398 | if (put_node) |
| 1399 | lpfc_nlp_put(ndlp); |
| 1400 | if (put_rport) |
| 1401 | put_device(&rport->dev); |
| 1402 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1403 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1404 | return new_ndlp; |
| 1405 | } |
| 1406 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1407 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1408 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1409 | * @vport: pointer to a host virtual N_Port data structure. |
| 1410 | * |
| 1411 | * This routine checks whether more Registration State Change |
| 1412 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1413 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1414 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1415 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1416 | * handling the RSCNs. |
| 1417 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1418 | void |
| 1419 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1420 | { |
| 1421 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1422 | |
| 1423 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1424 | /* |
| 1425 | * Check to see if more RSCNs came in while we were |
| 1426 | * processing this one. |
| 1427 | */ |
| 1428 | if (vport->fc_rscn_id_cnt || |
| 1429 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1430 | lpfc_els_handle_rscn(vport); |
| 1431 | else { |
| 1432 | spin_lock_irq(shost->host_lock); |
| 1433 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1434 | spin_unlock_irq(shost->host_lock); |
| 1435 | } |
| 1436 | } |
| 1437 | } |
| 1438 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1439 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1440 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1441 | * @phba: pointer to lpfc hba data structure. |
| 1442 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1443 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1444 | * |
| 1445 | * This routine is the completion callback function for issuing the Port |
| 1446 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1447 | * ndlp on the vport node list that matches the remote node ID from the |
| 1448 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1449 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1450 | * checked for error conditons. If there is error status reported, PLOGI |
| 1451 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1452 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1453 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1454 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1455 | * there are additional N_Port nodes with the vport that need to perform |
| 1456 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1457 | * PLOGIs. |
| 1458 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1459 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1460 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1461 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1462 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1463 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1464 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1465 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1466 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1467 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1468 | int disc, rc, did, type; |
| 1469 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1470 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1471 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1472 | |
| 1473 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1474 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1475 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1476 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1477 | irsp->un.elsreq64.remoteID); |
| 1478 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1479 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1480 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1481 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1482 | "0136 PLOGI completes to NPort x%x " |
| 1483 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1484 | irsp->un.elsreq64.remoteID, |
| 1485 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1486 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1487 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1488 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1489 | |
| 1490 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1491 | * is being used during discovery. |
| 1492 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1493 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1494 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1495 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1496 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | rc = 0; |
| 1498 | |
| 1499 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1500 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1501 | "0102 PLOGI completes to NPort x%x " |
| 1502 | "Data: x%x x%x x%x x%x x%x\n", |
| 1503 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1504 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1505 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1506 | if (lpfc_els_chk_latt(vport)) { |
| 1507 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1508 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1509 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1510 | goto out; |
| 1511 | } |
| 1512 | |
| 1513 | /* ndlp could be freed in DSM, save these values now */ |
| 1514 | type = ndlp->nlp_type; |
| 1515 | did = ndlp->nlp_DID; |
| 1516 | |
| 1517 | if (irsp->ulpStatus) { |
| 1518 | /* Check for retry */ |
| 1519 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1520 | /* ELS command is being retried */ |
| 1521 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1522 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1523 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1524 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1525 | } |
| 1526 | goto out; |
| 1527 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1528 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1529 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1530 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1531 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1532 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1533 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1534 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1535 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1536 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1537 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1538 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1539 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1540 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1541 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1542 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1543 | } else { |
| 1544 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1545 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1546 | cmdiocb->context2)->list.next, |
| 1547 | struct lpfc_dmabuf, list); |
| 1548 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1549 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1550 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1551 | } |
| 1552 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1553 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1554 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1555 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1556 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1557 | if (vport->num_disc_nodes == 0) { |
| 1558 | spin_lock_irq(shost->host_lock); |
| 1559 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1560 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1561 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1562 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1563 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | out: |
| 1568 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1569 | return; |
| 1570 | } |
| 1571 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1572 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1573 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1574 | * @vport: pointer to a host virtual N_Port data structure. |
| 1575 | * @did: destination port identifier. |
| 1576 | * @retry: number of retries to the command IOCB. |
| 1577 | * |
| 1578 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1579 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1580 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1581 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1582 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1583 | * |
| 1584 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1585 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1586 | * will be stored into the context1 field of the IOCB for the completion |
| 1587 | * callback function to the PLOGI ELS command. |
| 1588 | * |
| 1589 | * Return code |
| 1590 | * 0 - Successfully issued a plogi for @vport |
| 1591 | * 1 - failed to issue a plogi for @vport |
| 1592 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1593 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1594 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1595 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1596 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1597 | struct serv_parm *sp; |
| 1598 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1599 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1600 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1601 | struct lpfc_sli *psli; |
| 1602 | uint8_t *pcmd; |
| 1603 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1604 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1605 | |
| 1606 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1607 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1608 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1609 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1610 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1611 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1612 | /* 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] | 1613 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1614 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1615 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1616 | if (!elsiocb) |
| 1617 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1618 | |
| 1619 | icmd = &elsiocb->iocb; |
| 1620 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1621 | |
| 1622 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1623 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1624 | pcmd += sizeof(uint32_t); |
| 1625 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | sp = (struct serv_parm *) pcmd; |
| 1627 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1628 | /* |
| 1629 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 1630 | * to device on remote loops work. |
| 1631 | */ |
| 1632 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 1633 | sp->cmn.altBbCredit = 1; |
| 1634 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1635 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1636 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1637 | |
| 1638 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1639 | sp->cmn.fcphHigh = FC_PH3; |
| 1640 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1641 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1642 | "Issue PLOGI: did:x%x", |
| 1643 | did, 0, 0); |
| 1644 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1645 | phba->fc_stat.elsXmitPLOGI++; |
| 1646 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1647 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1648 | |
| 1649 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1650 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1651 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1652 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1653 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1654 | } |
| 1655 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1656 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1657 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1658 | * @phba: pointer to lpfc hba data structure. |
| 1659 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1660 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1661 | * |
| 1662 | * This routine is the completion callback function for a Process Login |
| 1663 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1664 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1665 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1666 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1667 | * ndlp to mark the PRLI completion. |
| 1668 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1669 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1670 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1671 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1672 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1673 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1674 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1675 | IOCB_t *irsp; |
| 1676 | struct lpfc_sli *psli; |
| 1677 | struct lpfc_nodelist *ndlp; |
| 1678 | |
| 1679 | psli = &phba->sli; |
| 1680 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1681 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1682 | |
| 1683 | irsp = &(rspiocb->iocb); |
| 1684 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1685 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1686 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1687 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1688 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1689 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1690 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1691 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1692 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1693 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1694 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1695 | "0103 PRLI completes to NPort x%x " |
| 1696 | "Data: x%x x%x x%x x%x\n", |
| 1697 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1698 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1699 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1700 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1701 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1702 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1703 | goto out; |
| 1704 | |
| 1705 | if (irsp->ulpStatus) { |
| 1706 | /* Check for retry */ |
| 1707 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1708 | /* ELS command is being retried */ |
| 1709 | goto out; |
| 1710 | } |
| 1711 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1712 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1713 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 1714 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1715 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1716 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1717 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1718 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1719 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1720 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1721 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1722 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1723 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1724 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1725 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1726 | out: |
| 1727 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1728 | return; |
| 1729 | } |
| 1730 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1731 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1732 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1733 | * @vport: pointer to a host virtual N_Port data structure. |
| 1734 | * @ndlp: pointer to a node-list data structure. |
| 1735 | * @retry: number of retries to the command IOCB. |
| 1736 | * |
| 1737 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1738 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1739 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1740 | * is put to the IOCB completion callback func field before invoking the |
| 1741 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1742 | * |
| 1743 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1744 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1745 | * will be stored into the context1 field of the IOCB for the completion |
| 1746 | * callback function to the PRLI ELS command. |
| 1747 | * |
| 1748 | * Return code |
| 1749 | * 0 - successfully issued prli iocb command for @vport |
| 1750 | * 1 - failed to issue prli iocb command for @vport |
| 1751 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1752 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1753 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1754 | uint8_t retry) |
| 1755 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1756 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1757 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1758 | PRLI *npr; |
| 1759 | IOCB_t *icmd; |
| 1760 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1761 | uint8_t *pcmd; |
| 1762 | uint16_t cmdsize; |
| 1763 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1764 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1765 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1766 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1767 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1768 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1769 | |
| 1770 | icmd = &elsiocb->iocb; |
| 1771 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1772 | |
| 1773 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1774 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1775 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1776 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1777 | |
| 1778 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1779 | npr = (PRLI *) pcmd; |
| 1780 | /* |
| 1781 | * If our firmware version is 3.20 or later, |
| 1782 | * set the following bits for FC-TAPE support. |
| 1783 | */ |
| 1784 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1785 | npr->ConfmComplAllowed = 1; |
| 1786 | npr->Retry = 1; |
| 1787 | npr->TaskRetryIdReq = 1; |
| 1788 | } |
| 1789 | npr->estabImagePair = 1; |
| 1790 | npr->readXferRdyDis = 1; |
| 1791 | |
| 1792 | /* For FCP support */ |
| 1793 | npr->prliType = PRLI_FCP_TYPE; |
| 1794 | npr->initiatorFunc = 1; |
| 1795 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1796 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1797 | "Issue PRLI: did:x%x", |
| 1798 | ndlp->nlp_DID, 0, 0); |
| 1799 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1800 | phba->fc_stat.elsXmitPRLI++; |
| 1801 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1802 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1803 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1804 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1805 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1806 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1807 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1808 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1809 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1810 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1811 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1812 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1813 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1814 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1815 | } |
| 1816 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1817 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1818 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1819 | * @vport: pointer to a host virtual N_Port data structure. |
| 1820 | * |
| 1821 | * This routine performs Registration State Change Notification (RSCN) |
| 1822 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1823 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1824 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1825 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1826 | * invoked to check and handle possible more RSCN came in during the period |
| 1827 | * of processing the current ones. |
| 1828 | **/ |
| 1829 | static void |
| 1830 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1831 | { |
| 1832 | lpfc_can_disctmo(vport); |
| 1833 | |
| 1834 | /* RSCN discovery */ |
| 1835 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1836 | if (vport->fc_npr_cnt) |
| 1837 | if (lpfc_els_disc_plogi(vport)) |
| 1838 | return; |
| 1839 | |
| 1840 | lpfc_end_rscn(vport); |
| 1841 | } |
| 1842 | |
| 1843 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1844 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1845 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1846 | * |
| 1847 | * This function is called when the final ADISC is completed during discovery. |
| 1848 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1849 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1850 | * discovery. |
| 1851 | * This function is called with no locks held. |
| 1852 | **/ |
| 1853 | static void |
| 1854 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1855 | { |
| 1856 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1857 | struct lpfc_hba *phba = vport->phba; |
| 1858 | |
| 1859 | /* |
| 1860 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1861 | * and continue discovery. |
| 1862 | */ |
| 1863 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1864 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1865 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1866 | lpfc_issue_reg_vpi(phba, vport); |
| 1867 | return; |
| 1868 | } |
| 1869 | /* |
| 1870 | * For SLI2, we need to set port_state to READY |
| 1871 | * and continue discovery. |
| 1872 | */ |
| 1873 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1874 | /* If we get here, there is nothing to ADISC */ |
| 1875 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1876 | lpfc_issue_clear_la(phba, vport); |
| 1877 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1878 | vport->num_disc_nodes = 0; |
| 1879 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1880 | if (vport->fc_npr_cnt) |
| 1881 | lpfc_els_disc_plogi(vport); |
| 1882 | if (!vport->num_disc_nodes) { |
| 1883 | spin_lock_irq(shost->host_lock); |
| 1884 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1885 | spin_unlock_irq(shost->host_lock); |
| 1886 | lpfc_can_disctmo(vport); |
| 1887 | lpfc_end_rscn(vport); |
| 1888 | } |
| 1889 | } |
| 1890 | vport->port_state = LPFC_VPORT_READY; |
| 1891 | } else |
| 1892 | lpfc_rscn_disc(vport); |
| 1893 | } |
| 1894 | |
| 1895 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1896 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1897 | * @vport: pointer to a host virtual N_Port data structure. |
| 1898 | * |
| 1899 | * This routine determines whether there are more ndlps on a @vport |
| 1900 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1901 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1902 | * remaining nodes which need to have ADISC sent. |
| 1903 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1904 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1905 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1906 | { |
| 1907 | int sentadisc; |
| 1908 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1909 | if (vport->num_disc_nodes) |
| 1910 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1911 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1912 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1913 | "0210 Continue discovery with %d ADISCs to go " |
| 1914 | "Data: x%x x%x x%x\n", |
| 1915 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1916 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1917 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1918 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1919 | lpfc_set_disctmo(vport); |
| 1920 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1921 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1922 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1923 | if (!vport->num_disc_nodes) |
| 1924 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1925 | return; |
| 1926 | } |
| 1927 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1928 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1929 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1930 | * @phba: pointer to lpfc hba data structure. |
| 1931 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1932 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1933 | * |
| 1934 | * This routine is the completion function for issuing the Address Discover |
| 1935 | * (ADISC) command. It first checks to see whether link went down during |
| 1936 | * the discovery process. If so, the node will be marked as node port |
| 1937 | * recovery for issuing discover IOCB by the link attention handler and |
| 1938 | * exit. Otherwise, the response status is checked. If error was reported |
| 1939 | * in the response status, the ADISC command shall be retried by invoking |
| 1940 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1941 | * the response status, the state machine is invoked to set transition |
| 1942 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1943 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1944 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1945 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1946 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1947 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1948 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1949 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1950 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1951 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1952 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1953 | |
| 1954 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1955 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1956 | |
| 1957 | irsp = &(rspiocb->iocb); |
| 1958 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1959 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1960 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1961 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1962 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1963 | ndlp->nlp_DID); |
| 1964 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1965 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1966 | * is being used during discovery. |
| 1967 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1968 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1969 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1970 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1971 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1972 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1973 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1974 | "0104 ADISC completes to NPort x%x " |
| 1975 | "Data: x%x x%x x%x x%x x%x\n", |
| 1976 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1977 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1978 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1979 | if (lpfc_els_chk_latt(vport)) { |
| 1980 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1981 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1982 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1983 | goto out; |
| 1984 | } |
| 1985 | |
| 1986 | if (irsp->ulpStatus) { |
| 1987 | /* Check for retry */ |
| 1988 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1989 | /* ELS command is being retried */ |
| 1990 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1991 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1992 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1993 | spin_unlock_irq(shost->host_lock); |
| 1994 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1995 | } |
| 1996 | goto out; |
| 1997 | } |
| 1998 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1999 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2000 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2001 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2002 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2003 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2004 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2005 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2006 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2007 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2008 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2009 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2010 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2011 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2012 | /* Check to see if there are more ADISCs to be sent */ |
| 2013 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2014 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2015 | out: |
| 2016 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2017 | return; |
| 2018 | } |
| 2019 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2020 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2021 | * 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] | 2022 | * @vport: pointer to a virtual N_Port data structure. |
| 2023 | * @ndlp: pointer to a node-list data structure. |
| 2024 | * @retry: number of retries to the command IOCB. |
| 2025 | * |
| 2026 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2027 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2028 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2029 | * to issue the ADISC ELS command. |
| 2030 | * |
| 2031 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2032 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2033 | * will be stored into the context1 field of the IOCB for the completion |
| 2034 | * callback function to the ADISC ELS command. |
| 2035 | * |
| 2036 | * Return code |
| 2037 | * 0 - successfully issued adisc |
| 2038 | * 1 - failed to issue adisc |
| 2039 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2040 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2041 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2042 | uint8_t retry) |
| 2043 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2044 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2045 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2046 | ADISC *ap; |
| 2047 | IOCB_t *icmd; |
| 2048 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2049 | uint8_t *pcmd; |
| 2050 | uint16_t cmdsize; |
| 2051 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2052 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2053 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2054 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2055 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2056 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2057 | |
| 2058 | icmd = &elsiocb->iocb; |
| 2059 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2060 | |
| 2061 | /* For ADISC request, remainder of payload is service parameters */ |
| 2062 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2063 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2064 | |
| 2065 | /* Fill in ADISC payload */ |
| 2066 | ap = (ADISC *) pcmd; |
| 2067 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2068 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2069 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2070 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2071 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2072 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2073 | "Issue ADISC: did:x%x", |
| 2074 | ndlp->nlp_DID, 0, 0); |
| 2075 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | phba->fc_stat.elsXmitADISC++; |
| 2077 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2078 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2079 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2080 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2081 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2082 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2083 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2084 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2085 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2086 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2087 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2088 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2089 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2090 | } |
| 2091 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2092 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2093 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2094 | * @phba: pointer to lpfc hba data structure. |
| 2095 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2096 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2097 | * |
| 2098 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2099 | * command. If no error status was reported from the LOGO response, the |
| 2100 | * state machine of the associated ndlp shall be invoked for transition with |
| 2101 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2102 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2103 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2105 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2106 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2107 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2108 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2109 | struct lpfc_vport *vport = ndlp->vport; |
| 2110 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2111 | IOCB_t *irsp; |
| 2112 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2113 | |
| 2114 | psli = &phba->sli; |
| 2115 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2116 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2117 | |
| 2118 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2119 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2121 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2123 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2124 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2125 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2126 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2127 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2128 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2129 | "0105 LOGO completes to NPort x%x " |
| 2130 | "Data: x%x x%x x%x x%x\n", |
| 2131 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2132 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2134 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | goto out; |
| 2136 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2137 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2138 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2139 | * which should abort all outstanding IOs. |
| 2140 | */ |
| 2141 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2142 | NLP_EVT_DEVICE_RM); |
| 2143 | goto out; |
| 2144 | } |
| 2145 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | if (irsp->ulpStatus) { |
| 2147 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2148 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2149 | /* ELS command is being retried */ |
| 2150 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2151 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2152 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2153 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2154 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2155 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2156 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2157 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2158 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2159 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2160 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2161 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2162 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2163 | /* Good status, call state machine. |
| 2164 | * This will unregister the rpi if needed. |
| 2165 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2166 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2167 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2168 | out: |
| 2169 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2170 | return; |
| 2171 | } |
| 2172 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2173 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2174 | * 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] | 2175 | * @vport: pointer to a virtual N_Port data structure. |
| 2176 | * @ndlp: pointer to a node-list data structure. |
| 2177 | * @retry: number of retries to the command IOCB. |
| 2178 | * |
| 2179 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2180 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2181 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2182 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2183 | * |
| 2184 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2185 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2186 | * will be stored into the context1 field of the IOCB for the completion |
| 2187 | * callback function to the LOGO ELS command. |
| 2188 | * |
| 2189 | * Return code |
| 2190 | * 0 - successfully issued logo |
| 2191 | * 1 - failed to issue logo |
| 2192 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2193 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2194 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2195 | uint8_t retry) |
| 2196 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2197 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2198 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2199 | IOCB_t *icmd; |
| 2200 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2201 | uint8_t *pcmd; |
| 2202 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2203 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2204 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2205 | spin_lock_irq(shost->host_lock); |
| 2206 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2207 | spin_unlock_irq(shost->host_lock); |
| 2208 | return 0; |
| 2209 | } |
| 2210 | spin_unlock_irq(shost->host_lock); |
| 2211 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2212 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2213 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2214 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2215 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2216 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2217 | |
| 2218 | icmd = &elsiocb->iocb; |
| 2219 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2220 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2221 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2222 | |
| 2223 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2224 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2225 | pcmd += sizeof(uint32_t); |
| 2226 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2227 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2228 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2229 | "Issue LOGO: did:x%x", |
| 2230 | ndlp->nlp_DID, 0, 0); |
| 2231 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2232 | phba->fc_stat.elsXmitLOGO++; |
| 2233 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2234 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2235 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2236 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2237 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2238 | |
| 2239 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2240 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2241 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2242 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2243 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2244 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2245 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2246 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2247 | } |
| 2248 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2249 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2250 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2251 | * @phba: pointer to lpfc hba data structure. |
| 2252 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2253 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2254 | * |
| 2255 | * This routine is a generic completion callback function for ELS commands. |
| 2256 | * Specifically, it is the callback function which does not need to perform |
| 2257 | * any command specific operations. It is currently used by the ELS command |
| 2258 | * issuing routines for the ELS State Change Request (SCR), |
| 2259 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2260 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2261 | * certain debug loggings, this callback function simply invokes the |
| 2262 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2263 | * discovery process. |
| 2264 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2265 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2266 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2267 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2268 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2269 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2270 | IOCB_t *irsp; |
| 2271 | |
| 2272 | irsp = &rspiocb->iocb; |
| 2273 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2274 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2275 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2276 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2277 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2278 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2279 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2280 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2281 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2282 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2283 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2284 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2285 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2286 | return; |
| 2287 | } |
| 2288 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2289 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2290 | * 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] | 2291 | * @vport: pointer to a host virtual N_Port data structure. |
| 2292 | * @nportid: N_Port identifier to the remote node. |
| 2293 | * @retry: number of retries to the command IOCB. |
| 2294 | * |
| 2295 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2296 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2297 | * first search the @vport node list to find the matching ndlp. If no such |
| 2298 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2299 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2300 | * routine is invoked to send the SCR IOCB. |
| 2301 | * |
| 2302 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2303 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2304 | * will be stored into the context1 field of the IOCB for the completion |
| 2305 | * callback function to the SCR ELS command. |
| 2306 | * |
| 2307 | * Return code |
| 2308 | * 0 - Successfully issued scr command |
| 2309 | * 1 - Failed to issue scr command |
| 2310 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2311 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2312 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2313 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2314 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 | IOCB_t *icmd; |
| 2316 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2317 | struct lpfc_sli *psli; |
| 2318 | uint8_t *pcmd; |
| 2319 | uint16_t cmdsize; |
| 2320 | struct lpfc_nodelist *ndlp; |
| 2321 | |
| 2322 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2323 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2324 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2325 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2326 | if (!ndlp) { |
| 2327 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2328 | if (!ndlp) |
| 2329 | return 1; |
| 2330 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2331 | lpfc_enqueue_node(vport, ndlp); |
| 2332 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2333 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2334 | if (!ndlp) |
| 2335 | return 1; |
| 2336 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2337 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2338 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2339 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2340 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2341 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2342 | /* This will trigger the release of the node just |
| 2343 | * allocated |
| 2344 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2345 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2346 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | icmd = &elsiocb->iocb; |
| 2350 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2351 | |
| 2352 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2353 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2354 | |
| 2355 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2356 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2357 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2358 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2359 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2360 | "Issue SCR: did:x%x", |
| 2361 | ndlp->nlp_DID, 0, 0); |
| 2362 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | phba->fc_stat.elsXmitSCR++; |
| 2364 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2365 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2366 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2367 | /* The additional lpfc_nlp_put will cause the following |
| 2368 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2369 | * the node. |
| 2370 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2371 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2372 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2373 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2375 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2376 | * trigger the release of node. |
| 2377 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2378 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2379 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2380 | } |
| 2381 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2382 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2383 | * 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] | 2384 | * @vport: pointer to a host virtual N_Port data structure. |
| 2385 | * @nportid: N_Port identifier to the remote node. |
| 2386 | * @retry: number of retries to the command IOCB. |
| 2387 | * |
| 2388 | * This routine issues a Fibre Channel Address Resolution Response |
| 2389 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2390 | * is passed into the function. It first search the @vport node list to find |
| 2391 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2392 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2393 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2394 | * |
| 2395 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2396 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2397 | * will be stored into the context1 field of the IOCB for the completion |
| 2398 | * callback function to the PARPR ELS command. |
| 2399 | * |
| 2400 | * Return code |
| 2401 | * 0 - Successfully issued farpr command |
| 2402 | * 1 - Failed to issue farpr command |
| 2403 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2405 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2407 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2408 | IOCB_t *icmd; |
| 2409 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2410 | struct lpfc_sli *psli; |
| 2411 | FARP *fp; |
| 2412 | uint8_t *pcmd; |
| 2413 | uint32_t *lp; |
| 2414 | uint16_t cmdsize; |
| 2415 | struct lpfc_nodelist *ondlp; |
| 2416 | struct lpfc_nodelist *ndlp; |
| 2417 | |
| 2418 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2419 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2420 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2421 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2422 | if (!ndlp) { |
| 2423 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2424 | if (!ndlp) |
| 2425 | return 1; |
| 2426 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2427 | lpfc_enqueue_node(vport, ndlp); |
| 2428 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2429 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2430 | if (!ndlp) |
| 2431 | return 1; |
| 2432 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2433 | |
| 2434 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2435 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2436 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2437 | /* This will trigger the release of the node just |
| 2438 | * allocated |
| 2439 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2440 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2441 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | icmd = &elsiocb->iocb; |
| 2445 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2446 | |
| 2447 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2448 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2449 | |
| 2450 | /* Fill in FARPR payload */ |
| 2451 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2452 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2453 | lp = (uint32_t *) pcmd; |
| 2454 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2455 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2456 | fp->Rflags = 0; |
| 2457 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2458 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2459 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2460 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2461 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2462 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2463 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2464 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2465 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2466 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2467 | } |
| 2468 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2469 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2470 | "Issue FARPR: did:x%x", |
| 2471 | ndlp->nlp_DID, 0, 0); |
| 2472 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2473 | phba->fc_stat.elsXmitFARPR++; |
| 2474 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2475 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2476 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2477 | /* The additional lpfc_nlp_put will cause the following |
| 2478 | * lpfc_els_free_iocb routine to trigger the release of |
| 2479 | * the node. |
| 2480 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2481 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2482 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2483 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2484 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2485 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2486 | * trigger the release of the node. |
| 2487 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2488 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2489 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2490 | } |
| 2491 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2492 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2493 | * 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] | 2494 | * @vport: pointer to a host virtual N_Port data structure. |
| 2495 | * @nlp: pointer to a node-list data structure. |
| 2496 | * |
| 2497 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2498 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2499 | * removes the ELS retry event if it presents. In addition, if the |
| 2500 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2501 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2502 | * ADISC. |
| 2503 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2504 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2505 | 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] | 2506 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2507 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2508 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2509 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2510 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2511 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2512 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2513 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2514 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2515 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2516 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2517 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2518 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2519 | /* Decrement nlp reference count held for the delayed retry */ |
| 2520 | evtp = &nlp->els_retry_evt; |
| 2521 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2522 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2523 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2524 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2525 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2526 | spin_unlock_irq(shost->host_lock); |
| 2527 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2528 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2529 | /* Check if there are more ADISCs to be sent */ |
| 2530 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2531 | } else { |
| 2532 | /* Check if there are more PLOGIs to be sent */ |
| 2533 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2534 | if (vport->num_disc_nodes == 0) { |
| 2535 | spin_lock_irq(shost->host_lock); |
| 2536 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2537 | spin_unlock_irq(shost->host_lock); |
| 2538 | lpfc_can_disctmo(vport); |
| 2539 | lpfc_end_rscn(vport); |
| 2540 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2541 | } |
| 2542 | } |
| 2543 | } |
| 2544 | return; |
| 2545 | } |
| 2546 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2547 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2548 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2549 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2550 | * |
| 2551 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2552 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2553 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2554 | * adds the delayed events to the HBA work list and invokes the |
| 2555 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2556 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2557 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2558 | * reference to ndlp will still be available when the worker thread gets |
| 2559 | * to the event associated with the ndlp. |
| 2560 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2561 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2562 | lpfc_els_retry_delay(unsigned long ptr) |
| 2563 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2564 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2565 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2566 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2567 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2568 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2569 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2570 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2571 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2572 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2573 | return; |
| 2574 | } |
| 2575 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2576 | /* We need to hold the node by incrementing the reference |
| 2577 | * count until the queued work is done |
| 2578 | */ |
| 2579 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2580 | if (evtp->evt_arg1) { |
| 2581 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2582 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2583 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2584 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2585 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2586 | return; |
| 2587 | } |
| 2588 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2589 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2590 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2591 | * @ndlp: pointer to a node-list data structure. |
| 2592 | * |
| 2593 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2594 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2595 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2596 | * function according to the delayed ELS command to retry the command. |
| 2597 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2598 | void |
| 2599 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2600 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2601 | struct lpfc_vport *vport = ndlp->vport; |
| 2602 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2603 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2604 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2605 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2606 | did = ndlp->nlp_DID; |
| 2607 | cmd = ndlp->nlp_last_elscmd; |
| 2608 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | |
| 2610 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2611 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2612 | return; |
| 2613 | } |
| 2614 | |
| 2615 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2616 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2617 | /* |
| 2618 | * If a discovery event readded nlp_delayfunc after timer |
| 2619 | * firing and before processing the timer, cancel the |
| 2620 | * nlp_delayfunc. |
| 2621 | */ |
| 2622 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2623 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2624 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | |
| 2626 | switch (cmd) { |
| 2627 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2628 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2629 | break; |
| 2630 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2631 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2632 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2633 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2634 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2635 | break; |
| 2636 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2637 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2638 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2639 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2640 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | break; |
| 2642 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2643 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2644 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2645 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2646 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2647 | break; |
| 2648 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2649 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2650 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2651 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2652 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2653 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2654 | case ELS_CMD_FDISC: |
| 2655 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2656 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2657 | } |
| 2658 | return; |
| 2659 | } |
| 2660 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2661 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2662 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2663 | * @phba: pointer to lpfc hba data structure. |
| 2664 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2665 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2666 | * |
| 2667 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2668 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2669 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2670 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2671 | * returned error status, it makes the decision whether a retry shall be |
| 2672 | * issued for the command, and whether a retry shall be made immediately or |
| 2673 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2674 | * is called to retry the command. In the later case, the ELS command shall |
| 2675 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2676 | * ndlp for the delayed command issusing. |
| 2677 | * |
| 2678 | * Return code |
| 2679 | * 0 - No retry of els command is made |
| 2680 | * 1 - Immediate or delayed retry of els command is made |
| 2681 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2683 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2684 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2685 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2686 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2687 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2688 | IOCB_t *irsp = &rspiocb->iocb; |
| 2689 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2690 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2691 | uint32_t *elscmd; |
| 2692 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2693 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2694 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2695 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2696 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2697 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2698 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2699 | /* Note: context2 may be 0 for internal driver abort |
| 2700 | * of delays ELS command. |
| 2701 | */ |
| 2702 | |
| 2703 | if (pcmd && pcmd->virt) { |
| 2704 | elscmd = (uint32_t *) (pcmd->virt); |
| 2705 | cmd = *elscmd++; |
| 2706 | } |
| 2707 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2708 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2709 | did = ndlp->nlp_DID; |
| 2710 | else { |
| 2711 | /* We should only hit this case for retrying PLOGI */ |
| 2712 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2713 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2714 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2715 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2716 | return 1; |
| 2717 | } |
| 2718 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2719 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2720 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2721 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2722 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2723 | switch (irsp->ulpStatus) { |
| 2724 | case IOSTAT_FCP_RSP_ERROR: |
| 2725 | case IOSTAT_REMOTE_STOP: |
| 2726 | break; |
| 2727 | |
| 2728 | case IOSTAT_LOCAL_REJECT: |
| 2729 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2730 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2731 | if (cmd == ELS_CMD_FLOGI) { |
| 2732 | if (PCI_DEVICE_ID_HORNET == |
| 2733 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 2734 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2735 | phba->pport->fc_myDID = 0; |
| 2736 | phba->alpa_map[0] = 0; |
| 2737 | phba->alpa_map[1] = 0; |
| 2738 | } |
| 2739 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2740 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2741 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | retry = 1; |
| 2743 | break; |
| 2744 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2745 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2746 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2747 | "0124 Retry illegal cmd x%x " |
| 2748 | "retry:x%x delay:x%x\n", |
| 2749 | cmd, cmdiocb->retry, delay); |
| 2750 | retry = 1; |
| 2751 | /* All command's retry policy */ |
| 2752 | maxretry = 8; |
| 2753 | if (cmdiocb->retry > 2) |
| 2754 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2755 | break; |
| 2756 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2757 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2758 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2759 | retry = 1; |
| 2760 | if (cmdiocb->retry > 100) |
| 2761 | delay = 100; |
| 2762 | maxretry = 250; |
| 2763 | break; |
| 2764 | |
| 2765 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2766 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2767 | retry = 1; |
| 2768 | break; |
| 2769 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2770 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2771 | case IOERR_INVALID_RPI: |
| 2772 | retry = 1; |
| 2773 | break; |
| 2774 | } |
| 2775 | break; |
| 2776 | |
| 2777 | case IOSTAT_NPORT_RJT: |
| 2778 | case IOSTAT_FABRIC_RJT: |
| 2779 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2780 | retry = 1; |
| 2781 | break; |
| 2782 | } |
| 2783 | break; |
| 2784 | |
| 2785 | case IOSTAT_NPORT_BSY: |
| 2786 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2787 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2788 | retry = 1; |
| 2789 | break; |
| 2790 | |
| 2791 | case IOSTAT_LS_RJT: |
| 2792 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2793 | /* Added for Vendor specifc support |
| 2794 | * Just keep retrying for these Rsn / Exp codes |
| 2795 | */ |
| 2796 | switch (stat.un.b.lsRjtRsnCode) { |
| 2797 | case LSRJT_UNABLE_TPC: |
| 2798 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2799 | LSEXP_CMD_IN_PROGRESS) { |
| 2800 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2801 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2802 | maxretry = 48; |
| 2803 | } |
| 2804 | retry = 1; |
| 2805 | break; |
| 2806 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 2807 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2808 | LSEXP_CANT_GIVE_DATA) { |
| 2809 | if (cmd == ELS_CMD_PLOGI) { |
| 2810 | delay = 1000; |
| 2811 | maxretry = 48; |
| 2812 | } |
| 2813 | retry = 1; |
| 2814 | break; |
| 2815 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2816 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2817 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2818 | maxretry = lpfc_max_els_tries + 1; |
| 2819 | retry = 1; |
| 2820 | break; |
| 2821 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2822 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2823 | (cmd == ELS_CMD_FDISC) && |
| 2824 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2825 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2826 | "0125 FDISC Failed (x%x). " |
| 2827 | "Fabric out of resources\n", |
| 2828 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2829 | lpfc_vport_set_state(vport, |
| 2830 | FC_VPORT_NO_FABRIC_RSCS); |
| 2831 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2832 | break; |
| 2833 | |
| 2834 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2835 | if ((cmd == ELS_CMD_PLOGI) || |
| 2836 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2837 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2838 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2839 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2840 | /* FDISC retry policy */ |
| 2841 | maxretry = 48; |
| 2842 | if (cmdiocb->retry >= 32) |
| 2843 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2844 | } |
| 2845 | retry = 1; |
| 2846 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2847 | |
| 2848 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2849 | /* There are some cases where switches return this |
| 2850 | * error when they are not ready and should be returning |
| 2851 | * Logical Busy. We should delay every time. |
| 2852 | */ |
| 2853 | if (cmd == ELS_CMD_FDISC && |
| 2854 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2855 | maxretry = 3; |
| 2856 | delay = 1000; |
| 2857 | retry = 1; |
| 2858 | break; |
| 2859 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2860 | case LSRJT_PROTOCOL_ERR: |
| 2861 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2862 | (cmd == ELS_CMD_FDISC) && |
| 2863 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2864 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2865 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2866 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2867 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2868 | "Fabric Detected Bad WWN\n", |
| 2869 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2870 | lpfc_vport_set_state(vport, |
| 2871 | FC_VPORT_FABRIC_REJ_WWN); |
| 2872 | } |
| 2873 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2874 | } |
| 2875 | break; |
| 2876 | |
| 2877 | case IOSTAT_INTERMED_RSP: |
| 2878 | case IOSTAT_BA_RJT: |
| 2879 | break; |
| 2880 | |
| 2881 | default: |
| 2882 | break; |
| 2883 | } |
| 2884 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2885 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2886 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2887 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2888 | if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 2889 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2890 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2891 | /* FLOGI retry policy */ |
| 2892 | retry = 1; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2893 | /* retry forever */ |
| 2894 | maxretry = 0; |
| 2895 | if (cmdiocb->retry >= 100) |
| 2896 | delay = 5000; |
| 2897 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2898 | delay = 1000; |
| 2899 | } |
| 2900 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2901 | cmdiocb->retry++; |
| 2902 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2903 | phba->fc_stat.elsRetryExceeded++; |
| 2904 | retry = 0; |
| 2905 | } |
| 2906 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2907 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2908 | retry = 0; |
| 2909 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2910 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 2911 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 2912 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 2913 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 2914 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2915 | "2849 Stop retry ELS command " |
| 2916 | "x%x to remote NPORT x%x, " |
| 2917 | "Data: x%x x%x\n", cmd, did, |
| 2918 | cmdiocb->retry, delay); |
| 2919 | return 0; |
| 2920 | } |
| 2921 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2922 | |
| 2923 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2924 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2925 | "0107 Retry ELS command x%x to remote " |
| 2926 | "NPORT x%x Data: x%x x%x\n", |
| 2927 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2928 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2929 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2930 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2931 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2932 | /* Don't reset timer for no resources */ |
| 2933 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2934 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2935 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2936 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2937 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2941 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2942 | phba->fc_stat.elsDelayRetry++; |
| 2943 | ndlp->nlp_retry = cmdiocb->retry; |
| 2944 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2945 | /* delay is specified in milliseconds */ |
| 2946 | mod_timer(&ndlp->nlp_delayfunc, |
| 2947 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2948 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2949 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2950 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2951 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2952 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2953 | if (cmd == ELS_CMD_PRLI) |
| 2954 | lpfc_nlp_set_state(vport, ndlp, |
| 2955 | NLP_STE_REG_LOGIN_ISSUE); |
| 2956 | else |
| 2957 | lpfc_nlp_set_state(vport, ndlp, |
| 2958 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2959 | ndlp->nlp_last_elscmd = cmd; |
| 2960 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2961 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2962 | } |
| 2963 | switch (cmd) { |
| 2964 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2965 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2966 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2967 | case ELS_CMD_FDISC: |
| 2968 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2969 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2970 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2971 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2972 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2973 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2974 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2975 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2976 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2977 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2978 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2979 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2980 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2981 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2982 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2984 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2985 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2986 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2987 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2988 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2989 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2990 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2991 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2992 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2993 | } |
| 2994 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2995 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2996 | if (logerr) { |
| 2997 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2998 | "0137 No retry ELS command x%x to remote " |
| 2999 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 3000 | cmd, did, irsp->ulpStatus, |
| 3001 | irsp->un.ulpWord[4]); |
| 3002 | } |
| 3003 | else { |
| 3004 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3005 | "0108 No retry ELS command x%x to remote " |
| 3006 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 3007 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 3008 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3009 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3010 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3011 | } |
| 3012 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3013 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3014 | * 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] | 3015 | * @phba: pointer to lpfc hba data structure. |
| 3016 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3017 | * |
| 3018 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3019 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3020 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3021 | * response of the command IOCB. If so, it will be released before releasing |
| 3022 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3023 | * |
| 3024 | * Return code |
| 3025 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3026 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3027 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3028 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3029 | { |
| 3030 | struct lpfc_dmabuf *buf_ptr; |
| 3031 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3032 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3033 | if (!list_empty(&buf_ptr1->list)) { |
| 3034 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3035 | struct lpfc_dmabuf, |
| 3036 | list); |
| 3037 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3038 | kfree(buf_ptr); |
| 3039 | } |
| 3040 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3041 | kfree(buf_ptr1); |
| 3042 | return 0; |
| 3043 | } |
| 3044 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3045 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3046 | * 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] | 3047 | * @phba: pointer to lpfc hba data structure. |
| 3048 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3049 | * |
| 3050 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3051 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3052 | * pool. |
| 3053 | * |
| 3054 | * Return code |
| 3055 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3056 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3057 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3058 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3059 | { |
| 3060 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3061 | kfree(buf_ptr); |
| 3062 | return 0; |
| 3063 | } |
| 3064 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3065 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3066 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3067 | * @phba: pointer to lpfc hba data structure. |
| 3068 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3069 | * |
| 3070 | * This routine frees a command IOCB and its associated resources. The |
| 3071 | * command IOCB data structure contains the reference to various associated |
| 3072 | * resources, these fields must be set to NULL if the associated reference |
| 3073 | * not present: |
| 3074 | * context1 - reference to ndlp |
| 3075 | * context2 - reference to cmd |
| 3076 | * context2->next - reference to rsp |
| 3077 | * context3 - reference to bpl |
| 3078 | * |
| 3079 | * It first properly decrements the reference count held on ndlp for the |
| 3080 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3081 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3082 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3083 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3084 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3085 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3086 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3087 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3088 | * |
| 3089 | * Return code |
| 3090 | * 0 - Success (currently, always return 0) |
| 3091 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3092 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3093 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3094 | { |
| 3095 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3096 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3098 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3099 | if (ndlp) { |
| 3100 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3101 | lpfc_nlp_put(ndlp); |
| 3102 | |
| 3103 | /* If the ndlp is not being used by another discovery |
| 3104 | * thread, free it. |
| 3105 | */ |
| 3106 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3107 | /* If ndlp is being used by another discovery |
| 3108 | * thread, just clear NLP_DEFER_RM |
| 3109 | */ |
| 3110 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3111 | } |
| 3112 | } |
| 3113 | else |
| 3114 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3115 | elsiocb->context1 = NULL; |
| 3116 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3117 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3118 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3119 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3120 | /* Firmware could still be in progress of DMAing |
| 3121 | * payload, so don't free data buffer till after |
| 3122 | * a hbeat. |
| 3123 | */ |
| 3124 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3125 | buf_ptr = elsiocb->context2; |
| 3126 | elsiocb->context2 = NULL; |
| 3127 | if (buf_ptr) { |
| 3128 | buf_ptr1 = NULL; |
| 3129 | spin_lock_irq(&phba->hbalock); |
| 3130 | if (!list_empty(&buf_ptr->list)) { |
| 3131 | list_remove_head(&buf_ptr->list, |
| 3132 | buf_ptr1, struct lpfc_dmabuf, |
| 3133 | list); |
| 3134 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3135 | list_add_tail(&buf_ptr1->list, |
| 3136 | &phba->elsbuf); |
| 3137 | phba->elsbuf_cnt++; |
| 3138 | } |
| 3139 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3140 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3141 | phba->elsbuf_cnt++; |
| 3142 | spin_unlock_irq(&phba->hbalock); |
| 3143 | } |
| 3144 | } else { |
| 3145 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3146 | lpfc_els_free_data(phba, buf_ptr1); |
| 3147 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3148 | } |
| 3149 | |
| 3150 | if (elsiocb->context3) { |
| 3151 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3152 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3153 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3154 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3155 | return 0; |
| 3156 | } |
| 3157 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3158 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3159 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3160 | * @phba: pointer to lpfc hba data structure. |
| 3161 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3162 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3163 | * |
| 3164 | * This routine is the completion callback function to the Logout (LOGO) |
| 3165 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3166 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3167 | * release the ndlp if it has the last reference remaining (reference count |
| 3168 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3169 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3170 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3171 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3172 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3173 | * IOCB data structure. |
| 3174 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3175 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3176 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3177 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3178 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3179 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3180 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3181 | IOCB_t *irsp; |
| 3182 | |
| 3183 | irsp = &rspiocb->iocb; |
| 3184 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3185 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3186 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3187 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3188 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3189 | "0109 ACC to LOGO completes to NPort x%x " |
| 3190 | "Data: x%x x%x x%x\n", |
| 3191 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3192 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3193 | |
| 3194 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3195 | /* NPort Recovery mode or node is just allocated */ |
| 3196 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3197 | /* If the ndlp is being used by another discovery |
| 3198 | * thread, just unregister the RPI. |
| 3199 | */ |
| 3200 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3201 | } else { |
| 3202 | /* Indicate the node has already released, should |
| 3203 | * not reference to it from within lpfc_els_free_iocb. |
| 3204 | */ |
| 3205 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3206 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3207 | } |
| 3208 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3209 | return; |
| 3210 | } |
| 3211 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3212 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3213 | * 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] | 3214 | * @phba: pointer to lpfc hba data structure. |
| 3215 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3216 | * |
| 3217 | * This routine is the completion callback function for unregister default |
| 3218 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3219 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3220 | * decrements the ndlp reference count held for this completion callback |
| 3221 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3222 | * whether there is only one reference left on the ndlp. If so, it will |
| 3223 | * perform one more decrement and trigger the release of the ndlp. |
| 3224 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3225 | void |
| 3226 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3227 | { |
| 3228 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3229 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3230 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3231 | /* |
| 3232 | * This routine is used to register and unregister in previous SLI |
| 3233 | * modes. |
| 3234 | */ |
| 3235 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
| 3236 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 3237 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
| 3238 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3239 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3240 | pmb->context2 = NULL; |
| 3241 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3242 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3243 | kfree(mp); |
| 3244 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3245 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3246 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3247 | /* This is the end of the default RPI cleanup logic for this |
| 3248 | * ndlp. If no other discovery threads are using this ndlp. |
| 3249 | * we should free all resources associated with it. |
| 3250 | */ |
| 3251 | lpfc_nlp_not_used(ndlp); |
| 3252 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3253 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3254 | return; |
| 3255 | } |
| 3256 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3257 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3258 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3259 | * @phba: pointer to lpfc hba data structure. |
| 3260 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3261 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3262 | * |
| 3263 | * This routine is the completion callback function for ELS Response IOCB |
| 3264 | * command. In normal case, this callback function just properly sets the |
| 3265 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3266 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3267 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3268 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3269 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3270 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3271 | * are currently referring it. |
| 3272 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3273 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3274 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3275 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3276 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3277 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3278 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3279 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3280 | IOCB_t *irsp; |
| 3281 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3282 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3283 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3284 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3285 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3286 | irsp = &rspiocb->iocb; |
| 3287 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3288 | if (cmdiocb->context_un.mbox) |
| 3289 | mbox = cmdiocb->context_un.mbox; |
| 3290 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3291 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3292 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3293 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3294 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3295 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3296 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3297 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3298 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3299 | */ |
| 3300 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3301 | ls_rjt = 1; |
| 3302 | } |
| 3303 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3304 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3305 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3306 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3307 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3308 | if (mp) { |
| 3309 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3310 | kfree(mp); |
| 3311 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3312 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3313 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3314 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3315 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3316 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3317 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3318 | /* Indicate the node has already released, |
| 3319 | * should not reference to it from within |
| 3320 | * the routine lpfc_els_free_iocb. |
| 3321 | */ |
| 3322 | cmdiocb->context1 = NULL; |
| 3323 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3324 | goto out; |
| 3325 | } |
| 3326 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3327 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3328 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3329 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3330 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3331 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3332 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3333 | "0110 ELS response tag x%x completes " |
| 3334 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3335 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3336 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3337 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3338 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3339 | if (mbox) { |
| 3340 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3341 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3342 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3343 | /* Increment reference count to ndlp to hold the |
| 3344 | * reference to ndlp for the callback function. |
| 3345 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3346 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3347 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3348 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3349 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3350 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3351 | } |
| 3352 | else { |
| 3353 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3354 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3355 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3356 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3357 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3358 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3359 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3360 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3361 | else |
| 3362 | /* Decrement the ndlp reference count we |
| 3363 | * set for this failed mailbox command. |
| 3364 | */ |
| 3365 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3366 | |
| 3367 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3368 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3369 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3370 | "Data: x%x x%x x%x\n", |
| 3371 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3372 | ndlp->nlp_rpi); |
| 3373 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3374 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3375 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3376 | /* Indicate node has already been released, |
| 3377 | * should not reference to it from within |
| 3378 | * the routine lpfc_els_free_iocb. |
| 3379 | */ |
| 3380 | cmdiocb->context1 = NULL; |
| 3381 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3382 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3383 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3384 | if (!lpfc_error_lost_link(irsp) && |
| 3385 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3386 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3387 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3388 | /* Indicate node has already been |
| 3389 | * released, should not reference |
| 3390 | * to it from within the routine |
| 3391 | * lpfc_els_free_iocb. |
| 3392 | */ |
| 3393 | cmdiocb->context1 = NULL; |
| 3394 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3395 | } |
| 3396 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3397 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3398 | if (mp) { |
| 3399 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3400 | kfree(mp); |
| 3401 | } |
| 3402 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3403 | } |
| 3404 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3405 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3406 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3407 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3408 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3409 | |
| 3410 | /* If the node is not being used by another discovery thread, |
| 3411 | * and we are sending a reject, we are done with it. |
| 3412 | * Release driver reference count here and free associated |
| 3413 | * resources. |
| 3414 | */ |
| 3415 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3416 | if (lpfc_nlp_not_used(ndlp)) |
| 3417 | /* Indicate node has already been released, |
| 3418 | * should not reference to it from within |
| 3419 | * the routine lpfc_els_free_iocb. |
| 3420 | */ |
| 3421 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3422 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3423 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | lpfc_els_free_iocb(phba, cmdiocb); |
| 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_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3430 | * @vport: pointer to a host virtual N_Port data structure. |
| 3431 | * @flag: the els command code to be accepted. |
| 3432 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3433 | * @ndlp: pointer to a node-list data structure. |
| 3434 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3435 | * |
| 3436 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3437 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3438 | * specific ACC response command to be issued and invokes the |
| 3439 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3440 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3441 | * field of the IOCB for the completion callback function to issue the |
| 3442 | * mailbox command to the HBA later when callback is invoked. |
| 3443 | * |
| 3444 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3445 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3446 | * will be stored into the context1 field of the IOCB for the completion |
| 3447 | * callback function to the corresponding response ELS IOCB command. |
| 3448 | * |
| 3449 | * Return code |
| 3450 | * 0 - Successfully issued acc response |
| 3451 | * 1 - Failed to issue acc response |
| 3452 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3454 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3455 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3456 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3457 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3458 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3459 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | IOCB_t *icmd; |
| 3461 | IOCB_t *oldcmd; |
| 3462 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3463 | struct lpfc_sli *psli; |
| 3464 | uint8_t *pcmd; |
| 3465 | uint16_t cmdsize; |
| 3466 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3467 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3468 | |
| 3469 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3470 | oldcmd = &oldiocb->iocb; |
| 3471 | |
| 3472 | switch (flag) { |
| 3473 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3474 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3475 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3476 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3477 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3478 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3479 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3480 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3481 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3482 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3483 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | icmd = &elsiocb->iocb; |
| 3485 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3486 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3487 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3488 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3489 | |
| 3490 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3491 | "Issue ACC: did:x%x flg:x%x", |
| 3492 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3493 | break; |
| 3494 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3495 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3496 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3497 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3498 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3499 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3500 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3501 | icmd = &elsiocb->iocb; |
| 3502 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3503 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3504 | |
| 3505 | if (mbox) |
| 3506 | elsiocb->context_un.mbox = mbox; |
| 3507 | |
| 3508 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3509 | pcmd += sizeof(uint32_t); |
| 3510 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3511 | |
| 3512 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3513 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3514 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3515 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3516 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3517 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3518 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3519 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3520 | if (!elsiocb) |
| 3521 | return 1; |
| 3522 | |
| 3523 | icmd = &elsiocb->iocb; |
| 3524 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3525 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3526 | |
| 3527 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3528 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3529 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3530 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3531 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3532 | |
| 3533 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3534 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3535 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3536 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3537 | default: |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3538 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3539 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3541 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3542 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3543 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3544 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3545 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3546 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3547 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3548 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3549 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3550 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3551 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3552 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3553 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3557 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3558 | if (rc == IOCB_ERROR) { |
| 3559 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3560 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3561 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3562 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3563 | } |
| 3564 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3565 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3566 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3567 | * @vport: pointer to a virtual N_Port data structure. |
| 3568 | * @rejectError: |
| 3569 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3570 | * @ndlp: pointer to a node-list data structure. |
| 3571 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3572 | * |
| 3573 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3574 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3575 | * context_un.mbox field of the IOCB for the completion callback function |
| 3576 | * to issue to the HBA later. |
| 3577 | * |
| 3578 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3579 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3580 | * will be stored into the context1 field of the IOCB for the completion |
| 3581 | * callback function to the reject response ELS IOCB command. |
| 3582 | * |
| 3583 | * Return code |
| 3584 | * 0 - Successfully issued reject response |
| 3585 | * 1 - Failed to issue reject response |
| 3586 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3587 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3588 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3589 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3590 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3592 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3593 | IOCB_t *icmd; |
| 3594 | IOCB_t *oldcmd; |
| 3595 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3596 | struct lpfc_sli *psli; |
| 3597 | uint8_t *pcmd; |
| 3598 | uint16_t cmdsize; |
| 3599 | int rc; |
| 3600 | |
| 3601 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3602 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3603 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3604 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3605 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3606 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3607 | |
| 3608 | icmd = &elsiocb->iocb; |
| 3609 | oldcmd = &oldiocb->iocb; |
| 3610 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3611 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3612 | |
| 3613 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3614 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3615 | *((uint32_t *) (pcmd)) = rejectError; |
| 3616 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3617 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3618 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3619 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3620 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3621 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3622 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3623 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3624 | "rpi x%x\n", |
| 3625 | rejectError, elsiocb->iotag, |
| 3626 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3627 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3628 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3629 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3630 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3631 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3632 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3633 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3634 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3635 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3636 | if (rc == IOCB_ERROR) { |
| 3637 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3638 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3639 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3640 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3641 | } |
| 3642 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3643 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3644 | * lpfc_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] | 3645 | * @vport: pointer to a virtual N_Port data structure. |
| 3646 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3647 | * @ndlp: pointer to a node-list data structure. |
| 3648 | * |
| 3649 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3650 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3651 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3652 | * |
| 3653 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3654 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3655 | * will be stored into the context1 field of the IOCB for the completion |
| 3656 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3657 | * |
| 3658 | * Return code |
| 3659 | * 0 - Successfully issued acc adisc response |
| 3660 | * 1 - Failed to issue adisc acc response |
| 3661 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3662 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3663 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3664 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3665 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3666 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3667 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3668 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3669 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3670 | uint8_t *pcmd; |
| 3671 | uint16_t cmdsize; |
| 3672 | int rc; |
| 3673 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3674 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3675 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3676 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3677 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3678 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3679 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3680 | icmd = &elsiocb->iocb; |
| 3681 | oldcmd = &oldiocb->iocb; |
| 3682 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3683 | |
| 3684 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3685 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3686 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3687 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3688 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3689 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3690 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3691 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3692 | |
| 3693 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3694 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3695 | |
| 3696 | ap = (ADISC *) (pcmd); |
| 3697 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3698 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3699 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3700 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3701 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3702 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3703 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3704 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3705 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3706 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3707 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3708 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3709 | if (rc == IOCB_ERROR) { |
| 3710 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3711 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3712 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3713 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3714 | } |
| 3715 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3716 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3717 | * 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] | 3718 | * @vport: pointer to a virtual N_Port data structure. |
| 3719 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3720 | * @ndlp: pointer to a node-list data structure. |
| 3721 | * |
| 3722 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3723 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3724 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3725 | * |
| 3726 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3727 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3728 | * will be stored into the context1 field of the IOCB for the completion |
| 3729 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3730 | * |
| 3731 | * Return code |
| 3732 | * 0 - Successfully issued acc prli response |
| 3733 | * 1 - Failed to issue acc prli response |
| 3734 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3735 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3736 | 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] | 3737 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3738 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3739 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3740 | PRLI *npr; |
| 3741 | lpfc_vpd_t *vpd; |
| 3742 | IOCB_t *icmd; |
| 3743 | IOCB_t *oldcmd; |
| 3744 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3745 | struct lpfc_sli *psli; |
| 3746 | uint8_t *pcmd; |
| 3747 | uint16_t cmdsize; |
| 3748 | int rc; |
| 3749 | |
| 3750 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3751 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3752 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3753 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3754 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3755 | if (!elsiocb) |
| 3756 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3757 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3758 | icmd = &elsiocb->iocb; |
| 3759 | oldcmd = &oldiocb->iocb; |
| 3760 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3761 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3762 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3763 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3764 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3765 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3766 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3767 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3768 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3769 | |
| 3770 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3771 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3772 | |
| 3773 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3774 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3775 | |
| 3776 | npr = (PRLI *) pcmd; |
| 3777 | vpd = &phba->vpd; |
| 3778 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3779 | * If the remote port is a target and our firmware version is 3.20 or |
| 3780 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3781 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3782 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3783 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3784 | npr->ConfmComplAllowed = 1; |
| 3785 | npr->Retry = 1; |
| 3786 | npr->TaskRetryIdReq = 1; |
| 3787 | } |
| 3788 | |
| 3789 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3790 | npr->estabImagePair = 1; |
| 3791 | npr->readXferRdyDis = 1; |
| 3792 | npr->ConfmComplAllowed = 1; |
| 3793 | |
| 3794 | npr->prliType = PRLI_FCP_TYPE; |
| 3795 | npr->initiatorFunc = 1; |
| 3796 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3797 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3798 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3799 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3800 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3802 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3803 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3804 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3805 | if (rc == IOCB_ERROR) { |
| 3806 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3807 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3808 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3809 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3810 | } |
| 3811 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3812 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3813 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3814 | * @vport: pointer to a virtual N_Port data structure. |
| 3815 | * @format: rnid command format. |
| 3816 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3817 | * @ndlp: pointer to a node-list data structure. |
| 3818 | * |
| 3819 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3820 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3821 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3822 | * issue the response. Note that this command does not need to hold the ndlp |
| 3823 | * reference count for the callback. So, the ndlp reference count taken by |
| 3824 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3825 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3826 | * there is no ndlp reference available. |
| 3827 | * |
| 3828 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3829 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3830 | * will be stored into the context1 field of the IOCB for the completion |
| 3831 | * callback function. However, for the RNID Accept Response ELS command, |
| 3832 | * this is undone later by this routine after the IOCB is allocated. |
| 3833 | * |
| 3834 | * Return code |
| 3835 | * 0 - Successfully issued acc rnid response |
| 3836 | * 1 - Failed to issue acc rnid response |
| 3837 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3838 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3839 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3840 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3841 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3842 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3843 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3844 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3845 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3846 | struct lpfc_sli *psli; |
| 3847 | uint8_t *pcmd; |
| 3848 | uint16_t cmdsize; |
| 3849 | int rc; |
| 3850 | |
| 3851 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3852 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3853 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3854 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3855 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3856 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3857 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3858 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3859 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3860 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3861 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3862 | icmd = &elsiocb->iocb; |
| 3863 | oldcmd = &oldiocb->iocb; |
| 3864 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3865 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3866 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3867 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3868 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3869 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3870 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3871 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3872 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3873 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3874 | rn = (RNID *) (pcmd); |
| 3875 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3876 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3877 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3878 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3879 | switch (format) { |
| 3880 | case 0: |
| 3881 | rn->SpecificLen = 0; |
| 3882 | break; |
| 3883 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3884 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3885 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3886 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3887 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3888 | rn->un.topologyDisc.physPort = 0; |
| 3889 | rn->un.topologyDisc.attachedNodes = 0; |
| 3890 | break; |
| 3891 | default: |
| 3892 | rn->CommonLen = 0; |
| 3893 | rn->SpecificLen = 0; |
| 3894 | break; |
| 3895 | } |
| 3896 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3897 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3898 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3899 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3900 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3901 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3902 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3903 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3904 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3905 | * it could be freed */ |
| 3906 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3907 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3908 | if (rc == IOCB_ERROR) { |
| 3909 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3910 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3911 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3912 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3913 | } |
| 3914 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3915 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 3916 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 3917 | * @vport: pointer to a virtual N_Port data structure. |
| 3918 | * @data: pointer to echo data to return in the accept. |
| 3919 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3920 | * @ndlp: pointer to a node-list data structure. |
| 3921 | * |
| 3922 | * Return code |
| 3923 | * 0 - Successfully issued acc echo response |
| 3924 | * 1 - Failed to issue acc echo response |
| 3925 | **/ |
| 3926 | static int |
| 3927 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 3928 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 3929 | { |
| 3930 | struct lpfc_hba *phba = vport->phba; |
| 3931 | struct lpfc_iocbq *elsiocb; |
| 3932 | struct lpfc_sli *psli; |
| 3933 | uint8_t *pcmd; |
| 3934 | uint16_t cmdsize; |
| 3935 | int rc; |
| 3936 | |
| 3937 | psli = &phba->sli; |
| 3938 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 3939 | |
| 3940 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3941 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 3942 | if (!elsiocb) |
| 3943 | return 1; |
| 3944 | |
| 3945 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */ |
| 3946 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 3947 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3948 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 3949 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 3950 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3951 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 3952 | pcmd += sizeof(uint32_t); |
| 3953 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 3954 | |
| 3955 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3956 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 3957 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3958 | |
| 3959 | phba->fc_stat.elsXmitACC++; |
| 3960 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 3961 | lpfc_nlp_put(ndlp); |
| 3962 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3963 | * it could be freed */ |
| 3964 | |
| 3965 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 3966 | if (rc == IOCB_ERROR) { |
| 3967 | lpfc_els_free_iocb(phba, elsiocb); |
| 3968 | return 1; |
| 3969 | } |
| 3970 | return 0; |
| 3971 | } |
| 3972 | |
| 3973 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3974 | * 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] | 3975 | * @vport: pointer to a host virtual N_Port data structure. |
| 3976 | * |
| 3977 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3978 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3979 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3980 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3981 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3982 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3983 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3984 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3985 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3986 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3987 | * no more ADISC need to be sent. |
| 3988 | * |
| 3989 | * Return code |
| 3990 | * The number of N_Ports with adisc issued. |
| 3991 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3992 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3993 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3994 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3995 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3996 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3997 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3998 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3999 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4000 | 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] | 4001 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4002 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4003 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4004 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4005 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4006 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4007 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4008 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4009 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4010 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4011 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4012 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4013 | vport->num_disc_nodes++; |
| 4014 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4015 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4016 | spin_lock_irq(shost->host_lock); |
| 4017 | vport->fc_flag |= FC_NLP_MORE; |
| 4018 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4019 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4020 | } |
| 4021 | } |
| 4022 | } |
| 4023 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4024 | spin_lock_irq(shost->host_lock); |
| 4025 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4026 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4027 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4028 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4029 | } |
| 4030 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4031 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4032 | * 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] | 4033 | * @vport: pointer to a host virtual N_Port data structure. |
| 4034 | * |
| 4035 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4036 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4037 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4038 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4039 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4040 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4041 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4042 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4043 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4044 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4045 | * PLOGI need to be sent. |
| 4046 | * |
| 4047 | * Return code |
| 4048 | * The number of N_Ports with plogi issued. |
| 4049 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4050 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4051 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4052 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4053 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4054 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4055 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4056 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4057 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4058 | 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] | 4059 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4060 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4061 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4062 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4063 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4064 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 4065 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4066 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4067 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4068 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4069 | vport->num_disc_nodes++; |
| 4070 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4071 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4072 | spin_lock_irq(shost->host_lock); |
| 4073 | vport->fc_flag |= FC_NLP_MORE; |
| 4074 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4075 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | } |
| 4077 | } |
| 4078 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4079 | if (sentplogi) { |
| 4080 | lpfc_set_disctmo(vport); |
| 4081 | } |
| 4082 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4083 | spin_lock_irq(shost->host_lock); |
| 4084 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4085 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4086 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4087 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4088 | } |
| 4089 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4090 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4091 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4092 | * @vport: pointer to a host virtual N_Port data structure. |
| 4093 | * |
| 4094 | * This routine cleans up any Registration State Change Notification |
| 4095 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 4096 | * @vport together with the host_lock is used to prevent multiple thread |
| 4097 | * trying to access the RSCN array on a same @vport at the same time. |
| 4098 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4099 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4100 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4101 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4102 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4103 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | int i; |
| 4105 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4106 | spin_lock_irq(shost->host_lock); |
| 4107 | if (vport->fc_rscn_flush) { |
| 4108 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4109 | spin_unlock_irq(shost->host_lock); |
| 4110 | return; |
| 4111 | } |
| 4112 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 4113 | vport->fc_rscn_flush = 1; |
| 4114 | spin_unlock_irq(shost->host_lock); |
| 4115 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4116 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4117 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4118 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4119 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4120 | spin_lock_irq(shost->host_lock); |
| 4121 | vport->fc_rscn_id_cnt = 0; |
| 4122 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 4123 | spin_unlock_irq(shost->host_lock); |
| 4124 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4125 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 4126 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4127 | } |
| 4128 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4129 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4130 | * 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] | 4131 | * @vport: pointer to a host virtual N_Port data structure. |
| 4132 | * @did: remote destination port identifier. |
| 4133 | * |
| 4134 | * This routine checks whether there is any pending Registration State |
| 4135 | * Configuration Notification (RSCN) to a @did on @vport. |
| 4136 | * |
| 4137 | * Return code |
| 4138 | * None zero - The @did matched with a pending rscn |
| 4139 | * 0 - not able to match @did with a pending rscn |
| 4140 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4141 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4142 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4143 | { |
| 4144 | D_ID ns_did; |
| 4145 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4146 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4147 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4148 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4149 | |
| 4150 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4151 | |
| 4152 | /* Never match fabric nodes for RSCNs */ |
| 4153 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4154 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4155 | |
| 4156 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4157 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4158 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4159 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4160 | spin_lock_irq(shost->host_lock); |
| 4161 | if (vport->fc_rscn_flush) { |
| 4162 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4163 | spin_unlock_irq(shost->host_lock); |
| 4164 | return 0; |
| 4165 | } |
| 4166 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4167 | vport->fc_rscn_flush = 1; |
| 4168 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4169 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4170 | lp = vport->fc_rscn_id_list[i]->virt; |
| 4171 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4172 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4173 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4174 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 4175 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4176 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 4177 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4178 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4179 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 4180 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4181 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4182 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4183 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4184 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4185 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4186 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4187 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4188 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4189 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4190 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4191 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4192 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4193 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4194 | } |
| 4195 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4196 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4197 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4198 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4199 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4200 | return_did_out: |
| 4201 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4202 | vport->fc_rscn_flush = 0; |
| 4203 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4204 | } |
| 4205 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4206 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4207 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4208 | * @vport: pointer to a host virtual N_Port data structure. |
| 4209 | * |
| 4210 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 4211 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 4212 | * State Change Notification). |
| 4213 | * |
| 4214 | * Return code |
| 4215 | * 0 - Successful (currently alway return 0) |
| 4216 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4217 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4218 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4219 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4220 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4221 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4222 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4223 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4224 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4225 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4226 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4227 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4228 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4229 | NLP_EVT_DEVICE_RECOVERY); |
| 4230 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4231 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4232 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4233 | } |
| 4234 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4235 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4236 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4237 | * @vport: pointer to a host virtual N_Port data structure. |
| 4238 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4239 | * |
| 4240 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4241 | * applications. |
| 4242 | */ |
| 4243 | static void |
| 4244 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4245 | struct lpfc_iocbq *cmdiocb) |
| 4246 | { |
| 4247 | struct lpfc_dmabuf *pcmd; |
| 4248 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4249 | uint32_t *payload_ptr; |
| 4250 | uint32_t payload_len; |
| 4251 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4252 | |
| 4253 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4254 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4255 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4256 | |
| 4257 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4258 | payload_len, GFP_KERNEL); |
| 4259 | if (!rscn_event_data) { |
| 4260 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4261 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4262 | return; |
| 4263 | } |
| 4264 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4265 | rscn_event_data->payload_length = payload_len; |
| 4266 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4267 | payload_len); |
| 4268 | |
| 4269 | fc_host_post_vendor_event(shost, |
| 4270 | fc_get_event_number(), |
| 4271 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4272 | (char *)rscn_event_data, |
| 4273 | LPFC_NL_VENDOR_ID); |
| 4274 | |
| 4275 | kfree(rscn_event_data); |
| 4276 | } |
| 4277 | |
| 4278 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4279 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4280 | * @vport: pointer to a host virtual N_Port data structure. |
| 4281 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4282 | * @ndlp: pointer to a node-list data structure. |
| 4283 | * |
| 4284 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4285 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4286 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4287 | * discover state machine is about to begin discovery, it just accepts the |
| 4288 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4289 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4290 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4291 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4292 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4293 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4294 | * routine is invoked to handle the RSCN event. |
| 4295 | * |
| 4296 | * Return code |
| 4297 | * 0 - Just sent the acc response |
| 4298 | * 1 - Sent the acc response and waited for name server completion |
| 4299 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4300 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4301 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4302 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4303 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4304 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4305 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4306 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4307 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4308 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4309 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4310 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4311 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4312 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4313 | |
| 4314 | icmd = &cmdiocb->iocb; |
| 4315 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4316 | lp = (uint32_t *) pcmd->virt; |
| 4317 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4318 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4319 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4320 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4321 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4322 | "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] | 4323 | vport->fc_flag, payload_len, *lp, |
| 4324 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4325 | |
| 4326 | /* Send an RSCN event to the management application */ |
| 4327 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4328 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4329 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4330 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4331 | FCH_EVT_RSCN, lp[i]); |
| 4332 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4333 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4334 | * Discovery processing will satisfy it. |
| 4335 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4336 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4337 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4338 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4339 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4340 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4341 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4342 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4343 | } |
| 4344 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4345 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4346 | * just ACC and ignore it. |
| 4347 | */ |
| 4348 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4349 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4350 | i = payload_len; |
| 4351 | datap = lp; |
| 4352 | while (i > 0) { |
| 4353 | nportid = *datap++; |
| 4354 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4355 | i -= sizeof(uint32_t); |
| 4356 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4357 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4358 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4359 | } |
| 4360 | if (rscn_id == hba_id) { |
| 4361 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4362 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4363 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4364 | "Data: x%x x%x x%x x%x\n", |
| 4365 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4366 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4367 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4368 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4369 | ndlp->nlp_DID, vport->port_state, |
| 4370 | ndlp->nlp_flag); |
| 4371 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4372 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4373 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4374 | return 0; |
| 4375 | } |
| 4376 | } |
| 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 */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4381 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4382 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4383 | /* Send back ACC */ |
| 4384 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4385 | return 0; |
| 4386 | } |
| 4387 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4388 | vport->fc_rscn_flush = 1; |
| 4389 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4390 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4391 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4392 | /* If we are already processing an RSCN, save the received |
| 4393 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4394 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4395 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4396 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4397 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4398 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4399 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4400 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4401 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4402 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4403 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4404 | vport->fc_flag |= FC_RSCN_MODE; |
| 4405 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4406 | if (rscn_cnt) { |
| 4407 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4408 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4409 | } |
| 4410 | if ((rscn_cnt) && |
| 4411 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4412 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4413 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4414 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4415 | payload_len); |
| 4416 | } else { |
| 4417 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4418 | vport->fc_rscn_id_cnt++; |
| 4419 | /* If we zero, cmdiocb->context2, the calling |
| 4420 | * routine will not try to free it. |
| 4421 | */ |
| 4422 | cmdiocb->context2 = NULL; |
| 4423 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4424 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4425 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4426 | "0235 Deferred RSCN " |
| 4427 | "Data: x%x x%x x%x\n", |
| 4428 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4429 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4430 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4431 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4432 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4433 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4434 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4435 | "0234 ReDiscovery RSCN " |
| 4436 | "Data: x%x x%x x%x\n", |
| 4437 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4438 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4439 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4440 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4441 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4442 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4443 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4444 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4445 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4446 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4447 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4448 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4449 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4450 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4451 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4452 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4453 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4454 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4455 | spin_lock_irq(shost->host_lock); |
| 4456 | vport->fc_flag |= FC_RSCN_MODE; |
| 4457 | spin_unlock_irq(shost->host_lock); |
| 4458 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4459 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4460 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4461 | /* |
| 4462 | * If we zero, cmdiocb->context2, the calling routine will |
| 4463 | * not try to free it. |
| 4464 | */ |
| 4465 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4466 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4467 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4468 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4469 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4470 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4471 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4472 | } |
| 4473 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4474 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4475 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4476 | * @vport: pointer to a host virtual N_Port data structure. |
| 4477 | * |
| 4478 | * This routine handles the Registration State Configuration Notification |
| 4479 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4480 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4481 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4482 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4483 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4484 | * RSCN activities with the @vport. |
| 4485 | * |
| 4486 | * Return code |
| 4487 | * 0 - Cleaned up rscn on the @vport |
| 4488 | * 1 - Wait for plogi to name server before proceed |
| 4489 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4490 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4491 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4492 | { |
| 4493 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4494 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4495 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4496 | /* Ignore RSCN if the port is being torn down. */ |
| 4497 | if (vport->load_flag & FC_UNLOADING) { |
| 4498 | lpfc_els_flush_rscn(vport); |
| 4499 | return 0; |
| 4500 | } |
| 4501 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4502 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4503 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4504 | |
| 4505 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4506 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4507 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4508 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4509 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4510 | |
| 4511 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4512 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4513 | vport->num_disc_nodes = 0; |
| 4514 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4515 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4516 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4517 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4518 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4519 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4520 | /* Wait for NameServer query cmpl before we can |
| 4521 | continue */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4522 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4523 | } else { |
| 4524 | /* If login to NameServer does not exist, issue one */ |
| 4525 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4526 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4527 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4528 | /* Wait for NameServer login cmpl before we can |
| 4529 | continue */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4530 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4531 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4532 | if (ndlp) { |
| 4533 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4534 | NLP_STE_PLOGI_ISSUE); |
| 4535 | if (!ndlp) { |
| 4536 | lpfc_els_flush_rscn(vport); |
| 4537 | return 0; |
| 4538 | } |
| 4539 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4540 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4541 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4542 | if (!ndlp) { |
| 4543 | lpfc_els_flush_rscn(vport); |
| 4544 | return 0; |
| 4545 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4546 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4547 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4548 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4549 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4550 | ndlp->nlp_type |= NLP_FABRIC; |
| 4551 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4552 | /* Wait for NameServer login cmpl before we can |
| 4553 | * continue |
| 4554 | */ |
| 4555 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4556 | } |
| 4557 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4558 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4559 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4560 | } |
| 4561 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4562 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4563 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4564 | * @vport: pointer to a host virtual N_Port data structure. |
| 4565 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4566 | * @ndlp: pointer to a node-list data structure. |
| 4567 | * |
| 4568 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4569 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4570 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4571 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4572 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4573 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4574 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4575 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4576 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4577 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4578 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4579 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4580 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4581 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4582 | * |
| 4583 | * Return code |
| 4584 | * 0 - Successfully processed the unsolicited flogi |
| 4585 | * 1 - Failed to process the unsolicited flogi |
| 4586 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4587 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4588 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4589 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4590 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4591 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4592 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4593 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4594 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4595 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4596 | struct serv_parm *sp; |
| 4597 | LPFC_MBOXQ_t *mbox; |
| 4598 | struct ls_rjt stat; |
| 4599 | uint32_t cmd, did; |
| 4600 | int rc; |
| 4601 | |
| 4602 | cmd = *lp++; |
| 4603 | sp = (struct serv_parm *) lp; |
| 4604 | |
| 4605 | /* FLOGI received */ |
| 4606 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4607 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4608 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 4609 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4610 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4611 | did = icmd->un.elsreq64.remoteID; |
| 4612 | |
| 4613 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4614 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4615 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4616 | "0113 An FLOGI ELS command x%x was " |
| 4617 | "received from DID x%x in Loop Mode\n", |
| 4618 | cmd, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4619 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4620 | } |
| 4621 | |
| 4622 | did = Fabric_DID; |
| 4623 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4624 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4625 | /* For a FLOGI we accept, then if our portname is greater |
| 4626 | * then the remote portname we initiate Nport login. |
| 4627 | */ |
| 4628 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4629 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4630 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4631 | |
| 4632 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4633 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4634 | if (!mbox) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4635 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4636 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4637 | lpfc_linkdown(phba); |
| 4638 | lpfc_init_link(phba, mbox, |
| 4639 | phba->cfg_topology, |
| 4640 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4641 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4642 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4643 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4644 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4645 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4646 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4647 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4648 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4649 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4650 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4651 | spin_lock_irq(shost->host_lock); |
| 4652 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4653 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4654 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4655 | spin_lock_irq(shost->host_lock); |
| 4656 | vport->fc_flag |= FC_PT2PT; |
| 4657 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4658 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4659 | } else { |
| 4660 | /* Reject this request because invalid parameters */ |
| 4661 | stat.un.b.lsRjtRsvd0 = 0; |
| 4662 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4663 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4664 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4665 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4666 | NULL); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4667 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4671 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4672 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4673 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4674 | } |
| 4675 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4676 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4677 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4678 | * @vport: pointer to a host virtual N_Port data structure. |
| 4679 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4680 | * @ndlp: pointer to a node-list data structure. |
| 4681 | * |
| 4682 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4683 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4684 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4685 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4686 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4687 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4688 | * |
| 4689 | * Return code |
| 4690 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4691 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4692 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4693 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4694 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4695 | { |
| 4696 | struct lpfc_dmabuf *pcmd; |
| 4697 | uint32_t *lp; |
| 4698 | IOCB_t *icmd; |
| 4699 | RNID *rn; |
| 4700 | struct ls_rjt stat; |
| 4701 | uint32_t cmd, did; |
| 4702 | |
| 4703 | icmd = &cmdiocb->iocb; |
| 4704 | did = icmd->un.elsreq64.remoteID; |
| 4705 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4706 | lp = (uint32_t *) pcmd->virt; |
| 4707 | |
| 4708 | cmd = *lp++; |
| 4709 | rn = (RNID *) lp; |
| 4710 | |
| 4711 | /* RNID received */ |
| 4712 | |
| 4713 | switch (rn->Format) { |
| 4714 | case 0: |
| 4715 | case RNID_TOPOLOGY_DISC: |
| 4716 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4717 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4718 | break; |
| 4719 | default: |
| 4720 | /* Reject this request because format not supported */ |
| 4721 | stat.un.b.lsRjtRsvd0 = 0; |
| 4722 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4723 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4724 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4725 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4726 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4727 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4728 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4729 | } |
| 4730 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4731 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4732 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 4733 | * @vport: pointer to a host virtual N_Port data structure. |
| 4734 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4735 | * @ndlp: pointer to a node-list data structure. |
| 4736 | * |
| 4737 | * Return code |
| 4738 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 4739 | **/ |
| 4740 | static int |
| 4741 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4742 | struct lpfc_nodelist *ndlp) |
| 4743 | { |
| 4744 | uint8_t *pcmd; |
| 4745 | |
| 4746 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 4747 | |
| 4748 | /* skip over first word of echo command to find echo data */ |
| 4749 | pcmd += sizeof(uint32_t); |
| 4750 | |
| 4751 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 4752 | return 0; |
| 4753 | } |
| 4754 | |
| 4755 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4756 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4757 | * @vport: pointer to a host virtual N_Port data structure. |
| 4758 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4759 | * @ndlp: pointer to a node-list data structure. |
| 4760 | * |
| 4761 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4762 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4763 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4764 | * |
| 4765 | * Return code |
| 4766 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4767 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4768 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4769 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4770 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4771 | { |
| 4772 | struct ls_rjt stat; |
| 4773 | |
| 4774 | /* For now, unconditionally reject this command */ |
| 4775 | stat.un.b.lsRjtRsvd0 = 0; |
| 4776 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4777 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4778 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4779 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4780 | return 0; |
| 4781 | } |
| 4782 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4783 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4784 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 4785 | * @vport: pointer to a host virtual N_Port data structure. |
| 4786 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4787 | * @ndlp: pointer to a node-list data structure. |
| 4788 | * |
| 4789 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 4790 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 4791 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 4792 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 4793 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 4794 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 4795 | * command request" and reason code explanation "Invalid Originator |
| 4796 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 4797 | * RRQ from the target. |
| 4798 | **/ |
| 4799 | static void |
| 4800 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4801 | struct lpfc_nodelist *ndlp) |
| 4802 | { |
| 4803 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| 4804 | } |
| 4805 | |
| 4806 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4807 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 4808 | * @phba: pointer to lpfc hba data structure. |
| 4809 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4810 | * |
| 4811 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4812 | * mailbox command. This callback function is to actually send the Accept |
| 4813 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4814 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4815 | * mailbox command, constructs the RPS response with the link statistics |
| 4816 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4817 | * response to the RPS. |
| 4818 | * |
| 4819 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4820 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4821 | * will be stored into the context1 field of the IOCB for the completion |
| 4822 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4823 | * |
| 4824 | **/ |
| 4825 | static void |
| 4826 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4827 | { |
| 4828 | MAILBOX_t *mb; |
| 4829 | IOCB_t *icmd; |
| 4830 | struct RLS_RSP *rls_rsp; |
| 4831 | uint8_t *pcmd; |
| 4832 | struct lpfc_iocbq *elsiocb; |
| 4833 | struct lpfc_nodelist *ndlp; |
| 4834 | uint16_t xri; |
| 4835 | uint32_t cmdsize; |
| 4836 | |
| 4837 | mb = &pmb->u.mb; |
| 4838 | |
| 4839 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4840 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
| 4841 | pmb->context1 = NULL; |
| 4842 | pmb->context2 = NULL; |
| 4843 | |
| 4844 | if (mb->mbxStatus) { |
| 4845 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4846 | return; |
| 4847 | } |
| 4848 | |
| 4849 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
| 4850 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4851 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4852 | lpfc_max_els_tries, ndlp, |
| 4853 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4854 | |
| 4855 | /* Decrement the ndlp reference count from previous mbox command */ |
| 4856 | lpfc_nlp_put(ndlp); |
| 4857 | |
| 4858 | if (!elsiocb) |
| 4859 | return; |
| 4860 | |
| 4861 | icmd = &elsiocb->iocb; |
| 4862 | icmd->ulpContext = xri; |
| 4863 | |
| 4864 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4865 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4866 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 4867 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 4868 | |
| 4869 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4870 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4871 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4872 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4873 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4874 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
| 4875 | |
| 4876 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 4877 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4878 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 4879 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4880 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4881 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4882 | ndlp->nlp_rpi); |
| 4883 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 4884 | phba->fc_stat.elsXmitACC++; |
| 4885 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 4886 | lpfc_els_free_iocb(phba, elsiocb); |
| 4887 | } |
| 4888 | |
| 4889 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4890 | * 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] | 4891 | * @phba: pointer to lpfc hba data structure. |
| 4892 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4893 | * |
| 4894 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4895 | * mailbox command. This callback function is to actually send the Accept |
| 4896 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4897 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4898 | * mailbox command, constructs the RPS response with the link statistics |
| 4899 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4900 | * response to the RPS. |
| 4901 | * |
| 4902 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4903 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4904 | * will be stored into the context1 field of the IOCB for the completion |
| 4905 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4906 | * |
| 4907 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4908 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4909 | 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] | 4910 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4911 | MAILBOX_t *mb; |
| 4912 | IOCB_t *icmd; |
| 4913 | RPS_RSP *rps_rsp; |
| 4914 | uint8_t *pcmd; |
| 4915 | struct lpfc_iocbq *elsiocb; |
| 4916 | struct lpfc_nodelist *ndlp; |
| 4917 | uint16_t xri, status; |
| 4918 | uint32_t cmdsize; |
| 4919 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4920 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4921 | |
| 4922 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4923 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4924 | pmb->context1 = NULL; |
| 4925 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4926 | |
| 4927 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4928 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4929 | return; |
| 4930 | } |
| 4931 | |
| 4932 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4933 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4934 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4935 | lpfc_max_els_tries, ndlp, |
| 4936 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4937 | |
| 4938 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4939 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4940 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4941 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4942 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4943 | |
| 4944 | icmd = &elsiocb->iocb; |
| 4945 | icmd->ulpContext = xri; |
| 4946 | |
| 4947 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4948 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4949 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4950 | rps_rsp = (RPS_RSP *)pcmd; |
| 4951 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 4952 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4953 | status = 0x10; |
| 4954 | else |
| 4955 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4956 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4957 | status |= 0x4; |
| 4958 | |
| 4959 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4960 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4961 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4962 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4963 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4964 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4965 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4966 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4967 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4968 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4969 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4970 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4971 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4972 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4973 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4974 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4975 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4976 | 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] | 4977 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4978 | return; |
| 4979 | } |
| 4980 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4981 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4982 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 4983 | * @vport: pointer to a host virtual N_Port data structure. |
| 4984 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4985 | * @ndlp: pointer to a node-list data structure. |
| 4986 | * |
| 4987 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 4988 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4989 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4990 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 4991 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4992 | * for reading the HBA link statistics. It is for the callback function, |
| 4993 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4994 | * to actually sending out RPL Accept (ACC) response. |
| 4995 | * |
| 4996 | * Return codes |
| 4997 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 4998 | **/ |
| 4999 | static int |
| 5000 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5001 | struct lpfc_nodelist *ndlp) |
| 5002 | { |
| 5003 | struct lpfc_hba *phba = vport->phba; |
| 5004 | LPFC_MBOXQ_t *mbox; |
| 5005 | struct lpfc_dmabuf *pcmd; |
| 5006 | struct ls_rjt stat; |
| 5007 | |
| 5008 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5009 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5010 | /* reject the unsolicited RPS request and done with it */ |
| 5011 | goto reject_out; |
| 5012 | |
| 5013 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5014 | |
| 5015 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5016 | if (mbox) { |
| 5017 | lpfc_read_lnk_stat(phba, mbox); |
| 5018 | mbox->context1 = |
| 5019 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
| 5020 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5021 | mbox->vport = vport; |
| 5022 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 5023 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 5024 | != MBX_NOT_FINISHED) |
| 5025 | /* Mbox completion will send ELS Response */ |
| 5026 | return 0; |
| 5027 | /* Decrement reference count used for the failed mbox |
| 5028 | * command. |
| 5029 | */ |
| 5030 | lpfc_nlp_put(ndlp); |
| 5031 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5032 | } |
| 5033 | reject_out: |
| 5034 | /* issue rejection response */ |
| 5035 | stat.un.b.lsRjtRsvd0 = 0; |
| 5036 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5037 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5038 | stat.un.b.vendorUnique = 0; |
| 5039 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5040 | return 0; |
| 5041 | } |
| 5042 | |
| 5043 | /** |
| 5044 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 5045 | * @vport: pointer to a host virtual N_Port data structure. |
| 5046 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5047 | * @ndlp: pointer to a node-list data structure. |
| 5048 | * |
| 5049 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 5050 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5051 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5052 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 5053 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 5054 | * Value (RTV) unsolicited IOCB event. |
| 5055 | * |
| 5056 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5057 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5058 | * will be stored into the context1 field of the IOCB for the completion |
| 5059 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5060 | * |
| 5061 | * Return codes |
| 5062 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 5063 | **/ |
| 5064 | static int |
| 5065 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5066 | struct lpfc_nodelist *ndlp) |
| 5067 | { |
| 5068 | struct lpfc_hba *phba = vport->phba; |
| 5069 | struct ls_rjt stat; |
| 5070 | struct RTV_RSP *rtv_rsp; |
| 5071 | uint8_t *pcmd; |
| 5072 | struct lpfc_iocbq *elsiocb; |
| 5073 | uint32_t cmdsize; |
| 5074 | |
| 5075 | |
| 5076 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5077 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5078 | /* reject the unsolicited RPS request and done with it */ |
| 5079 | goto reject_out; |
| 5080 | |
| 5081 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 5082 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5083 | lpfc_max_els_tries, ndlp, |
| 5084 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5085 | |
| 5086 | if (!elsiocb) |
| 5087 | return 1; |
| 5088 | |
| 5089 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5090 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5091 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 5092 | |
| 5093 | /* use the command's xri in the response */ |
| 5094 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; |
| 5095 | |
| 5096 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 5097 | |
| 5098 | /* populate RTV payload */ |
| 5099 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 5100 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 5101 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 5102 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 5103 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 5104 | |
| 5105 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 5106 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5107 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 5108 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 5109 | "Data: x%x x%x x%x\n", |
| 5110 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5111 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5112 | ndlp->nlp_rpi, |
| 5113 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 5114 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5115 | phba->fc_stat.elsXmitACC++; |
| 5116 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 5117 | lpfc_els_free_iocb(phba, elsiocb); |
| 5118 | return 0; |
| 5119 | |
| 5120 | reject_out: |
| 5121 | /* issue rejection response */ |
| 5122 | stat.un.b.lsRjtRsvd0 = 0; |
| 5123 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5124 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5125 | stat.un.b.vendorUnique = 0; |
| 5126 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5127 | return 0; |
| 5128 | } |
| 5129 | |
| 5130 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5131 | * @vport: pointer to a host virtual N_Port data structure. |
| 5132 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5133 | * @ndlp: pointer to a node-list data structure. |
| 5134 | * |
| 5135 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 5136 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5137 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5138 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 5139 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 5140 | * for reading the HBA link statistics. It is for the callback function, |
| 5141 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 5142 | * to actually sending out RPS Accept (ACC) response. |
| 5143 | * |
| 5144 | * Return codes |
| 5145 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 5146 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5147 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5148 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5149 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5150 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5151 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5152 | uint32_t *lp; |
| 5153 | uint8_t flag; |
| 5154 | LPFC_MBOXQ_t *mbox; |
| 5155 | struct lpfc_dmabuf *pcmd; |
| 5156 | RPS *rps; |
| 5157 | struct ls_rjt stat; |
| 5158 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5159 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5160 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5161 | /* reject the unsolicited RPS request and done with it */ |
| 5162 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5163 | |
| 5164 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5165 | lp = (uint32_t *) pcmd->virt; |
| 5166 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 5167 | rps = (RPS *) lp; |
| 5168 | |
| 5169 | if ((flag == 0) || |
| 5170 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5171 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5172 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5173 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5174 | printk("Fix me....\n"); |
| 5175 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5176 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5177 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5178 | lpfc_read_lnk_stat(phba, mbox); |
| 5179 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5180 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5181 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5182 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5183 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5184 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5185 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5186 | /* Mbox completion will send ELS Response */ |
| 5187 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5188 | /* Decrement reference count used for the failed mbox |
| 5189 | * command. |
| 5190 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5191 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5192 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5193 | } |
| 5194 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5195 | |
| 5196 | reject_out: |
| 5197 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5198 | stat.un.b.lsRjtRsvd0 = 0; |
| 5199 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5200 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5201 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5202 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5203 | return 0; |
| 5204 | } |
| 5205 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5206 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5207 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5208 | * @vport: pointer to a host virtual N_Port data structure. |
| 5209 | * @cmdsize: size of the ELS command. |
| 5210 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5211 | * @ndlp: pointer to a node-list data structure. |
| 5212 | * |
| 5213 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 5214 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 5215 | * |
| 5216 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5217 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5218 | * will be stored into the context1 field of the IOCB for the completion |
| 5219 | * callback function to the RPL Accept Response ELS command. |
| 5220 | * |
| 5221 | * Return code |
| 5222 | * 0 - Successfully issued ACC RPL ELS command |
| 5223 | * 1 - Failed to issue ACC RPL ELS command |
| 5224 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5225 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5226 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 5227 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5228 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5229 | struct lpfc_hba *phba = vport->phba; |
| 5230 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5231 | RPL_RSP rpl_rsp; |
| 5232 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5233 | uint8_t *pcmd; |
| 5234 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5235 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5236 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5237 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5238 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5239 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5240 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5241 | icmd = &elsiocb->iocb; |
| 5242 | oldcmd = &oldiocb->iocb; |
| 5243 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 5244 | |
| 5245 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5246 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5247 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5248 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 5249 | pcmd += sizeof(uint16_t); |
| 5250 | |
| 5251 | /* Setup the RPL ACC payload */ |
| 5252 | rpl_rsp.listLen = be32_to_cpu(1); |
| 5253 | rpl_rsp.index = 0; |
| 5254 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5255 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 5256 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5257 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5258 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5259 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5260 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5261 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 5262 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 5263 | "rpi x%x\n", |
| 5264 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5265 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5266 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5267 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5268 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5269 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 5270 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5271 | lpfc_els_free_iocb(phba, elsiocb); |
| 5272 | return 1; |
| 5273 | } |
| 5274 | return 0; |
| 5275 | } |
| 5276 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5277 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5278 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5279 | * @vport: pointer to a host virtual N_Port data structure. |
| 5280 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5281 | * @ndlp: pointer to a node-list data structure. |
| 5282 | * |
| 5283 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 5284 | * unsolicited event. It first checks the remote port state. If the remote |
| 5285 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 5286 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 5287 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 5288 | * to accept the RPL. |
| 5289 | * |
| 5290 | * Return code |
| 5291 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 5292 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5293 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5294 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5295 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5296 | { |
| 5297 | struct lpfc_dmabuf *pcmd; |
| 5298 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5299 | uint32_t maxsize; |
| 5300 | uint16_t cmdsize; |
| 5301 | RPL *rpl; |
| 5302 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5303 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5304 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5305 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5306 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5307 | stat.un.b.lsRjtRsvd0 = 0; |
| 5308 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5309 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5310 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5311 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5312 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5313 | /* rejected the unsolicited RPL request and done with it */ |
| 5314 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5315 | } |
| 5316 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5317 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5318 | lp = (uint32_t *) pcmd->virt; |
| 5319 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5320 | maxsize = be32_to_cpu(rpl->maxsize); |
| 5321 | |
| 5322 | /* We support only one port */ |
| 5323 | if ((rpl->index == 0) && |
| 5324 | ((maxsize == 0) || |
| 5325 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 5326 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5327 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5328 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 5329 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5330 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5331 | |
| 5332 | return 0; |
| 5333 | } |
| 5334 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5335 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5336 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5337 | * @vport: pointer to a virtual N_Port data structure. |
| 5338 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5339 | * @ndlp: pointer to a node-list data structure. |
| 5340 | * |
| 5341 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5342 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 5343 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 5344 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 5345 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 5346 | * remote PortName is compared against the FC PortName stored in the @vport |
| 5347 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 5348 | * compared against the FC NodeName stored in the @vport data structure. |
| 5349 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 5350 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 5351 | * invoked to send out FARP Response to the remote node. Before sending the |
| 5352 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 5353 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 5354 | * routine is invoked to log into the remote port first. |
| 5355 | * |
| 5356 | * Return code |
| 5357 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 5358 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5359 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5360 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5361 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5362 | { |
| 5363 | struct lpfc_dmabuf *pcmd; |
| 5364 | uint32_t *lp; |
| 5365 | IOCB_t *icmd; |
| 5366 | FARP *fp; |
| 5367 | uint32_t cmd, cnt, did; |
| 5368 | |
| 5369 | icmd = &cmdiocb->iocb; |
| 5370 | did = icmd->un.elsreq64.remoteID; |
| 5371 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5372 | lp = (uint32_t *) pcmd->virt; |
| 5373 | |
| 5374 | cmd = *lp++; |
| 5375 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5376 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5377 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5378 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5379 | /* We will only support match on WWPN or WWNN */ |
| 5380 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5381 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | cnt = 0; |
| 5385 | /* If this FARP command is searching for my portname */ |
| 5386 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5387 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5388 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5389 | cnt = 1; |
| 5390 | } |
| 5391 | |
| 5392 | /* If this FARP command is searching for my nodename */ |
| 5393 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5394 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5395 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5396 | cnt = 1; |
| 5397 | } |
| 5398 | |
| 5399 | if (cnt) { |
| 5400 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 5401 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 5402 | /* Log back into the node before sending the FARP. */ |
| 5403 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5404 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5405 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 5406 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5407 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5411 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 5412 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5413 | } |
| 5414 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5415 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5416 | } |
| 5417 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5418 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5419 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5420 | * @vport: pointer to a host virtual N_Port data structure. |
| 5421 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5422 | * @ndlp: pointer to a node-list data structure. |
| 5423 | * |
| 5424 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5425 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 5426 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 5427 | * the FARP response request. |
| 5428 | * |
| 5429 | * Return code |
| 5430 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 5431 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5432 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5433 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5434 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5435 | { |
| 5436 | struct lpfc_dmabuf *pcmd; |
| 5437 | uint32_t *lp; |
| 5438 | IOCB_t *icmd; |
| 5439 | uint32_t cmd, did; |
| 5440 | |
| 5441 | icmd = &cmdiocb->iocb; |
| 5442 | did = icmd->un.elsreq64.remoteID; |
| 5443 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5444 | lp = (uint32_t *) pcmd->virt; |
| 5445 | |
| 5446 | cmd = *lp++; |
| 5447 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5448 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5449 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5450 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5451 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5452 | |
| 5453 | return 0; |
| 5454 | } |
| 5455 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5456 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5457 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5458 | * @vport: pointer to a host virtual N_Port data structure. |
| 5459 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5460 | * @fan_ndlp: pointer to a node-list data structure. |
| 5461 | * |
| 5462 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 5463 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 5464 | * only be processed on a physical port (i.e., the @vport represents the |
| 5465 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 5466 | * compared against those in the phba data structure. If any of those is |
| 5467 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 5468 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 5469 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 5470 | * is invoked to register login to the fabric. |
| 5471 | * |
| 5472 | * Return code |
| 5473 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 5474 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5475 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5476 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5477 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5478 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5479 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5480 | uint32_t *lp; |
| 5481 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5482 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5483 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 5484 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 5485 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5486 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5487 | if ((vport == phba->pport) && |
| 5488 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5489 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5490 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5491 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5492 | sizeof(struct lpfc_name)))) { |
| 5493 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 5494 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5495 | } else { |
| 5496 | /* FAN verified - skip FLOGI */ |
| 5497 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5498 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5499 | lpfc_issue_fabric_reglogin(vport); |
| 5500 | else |
| 5501 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5502 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5503 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5504 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5505 | } |
| 5506 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5507 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5508 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5509 | * @ptr: holder for the timer function associated data. |
| 5510 | * |
| 5511 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5512 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5513 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5514 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5515 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5516 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5517 | void |
| 5518 | lpfc_els_timeout(unsigned long ptr) |
| 5519 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5520 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5521 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5522 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5523 | unsigned long iflag; |
| 5524 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5525 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5526 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5527 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5528 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5529 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5530 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5531 | if (!tmo_posted) |
| 5532 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5533 | return; |
| 5534 | } |
| 5535 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5536 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5537 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5538 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5539 | * @vport: pointer to a virtual N_Port data structure. |
| 5540 | * |
| 5541 | * This routine is the actual handler function that processes an ELS timeout |
| 5542 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5543 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5544 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5545 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5546 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5547 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5548 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5549 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5550 | struct lpfc_sli_ring *pring; |
| 5551 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5552 | IOCB_t *cmd = NULL; |
| 5553 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5554 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5555 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5556 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5557 | LIST_HEAD(txcmplq_completions); |
| 5558 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5559 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5560 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5561 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5562 | |
| 5563 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5564 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5565 | spin_lock_irq(&phba->hbalock); |
| 5566 | list_splice_init(&pring->txcmplq, &txcmplq_completions); |
| 5567 | spin_unlock_irq(&phba->hbalock); |
| 5568 | |
| 5569 | list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5570 | cmd = &piocb->iocb; |
| 5571 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5572 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5573 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5574 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5575 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5576 | |
| 5577 | if (piocb->vport != vport) |
| 5578 | continue; |
| 5579 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5580 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5581 | if (pcmd) |
| 5582 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5583 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5584 | if (els_command == ELS_CMD_FARP || |
| 5585 | els_command == ELS_CMD_FARPR || |
| 5586 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5587 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5588 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5589 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5590 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5591 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5592 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5593 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5594 | continue; |
| 5595 | } |
| 5596 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5597 | remote_ID = 0xffffffff; |
| 5598 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5599 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5600 | else { |
| 5601 | struct lpfc_nodelist *ndlp; |
| 5602 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5603 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5604 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5605 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5606 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5607 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5608 | spin_lock_irq(&phba->hbalock); |
| 5609 | list_splice(&txcmplq_completions, &pring->txcmplq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5610 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5611 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5612 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 5613 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5614 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5615 | "x%x\n", els_command, |
| 5616 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 5617 | spin_lock_irq(&phba->hbalock); |
| 5618 | list_del_init(&piocb->dlist); |
| 5619 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5620 | spin_unlock_irq(&phba->hbalock); |
| 5621 | } |
| 5622 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5623 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5624 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5625 | } |
| 5626 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5627 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5628 | * 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] | 5629 | * @vport: pointer to a host virtual N_Port data structure. |
| 5630 | * |
| 5631 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5632 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5633 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5634 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5635 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5636 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5637 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5638 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5639 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5640 | * completion queue IOCB that is associated with the @vport and is not |
| 5641 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5642 | * part of the discovery state machine) out to HBA by invoking the |
| 5643 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5644 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5645 | * the IOCBs are aborted when this function returns. |
| 5646 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5647 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5648 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5649 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5650 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5651 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5652 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5653 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5654 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5655 | |
| 5656 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5657 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5658 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5659 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5660 | cmd = &piocb->iocb; |
| 5661 | |
| 5662 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5663 | continue; |
| 5664 | } |
| 5665 | |
| 5666 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5667 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5668 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5669 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5670 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5671 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5672 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5673 | if (piocb->vport != vport) |
| 5674 | continue; |
| 5675 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5676 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5677 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5678 | } |
| 5679 | |
| 5680 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5681 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5682 | continue; |
| 5683 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5684 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5685 | if (piocb->vport != vport) |
| 5686 | continue; |
| 5687 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5688 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5689 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5690 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5691 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5692 | /* Cancell all the IOCBs from the completions list */ |
| 5693 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5694 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5695 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5696 | return; |
| 5697 | } |
| 5698 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5699 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5700 | * 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] | 5701 | * @phba: pointer to lpfc hba data structure. |
| 5702 | * |
| 5703 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5704 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5705 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5706 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5707 | * the IOCBs with the completion callback function associated, the callback |
| 5708 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5709 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5710 | * callback function associated, the IOCB will simply be released. Finally, |
| 5711 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5712 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5713 | * management plane IOCBs that are not part of the discovery state machine) |
| 5714 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5715 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5716 | void |
| 5717 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5718 | { |
| 5719 | LIST_HEAD(completions); |
| 5720 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5721 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5722 | IOCB_t *cmd = NULL; |
| 5723 | |
| 5724 | lpfc_fabric_abort_hba(phba); |
| 5725 | spin_lock_irq(&phba->hbalock); |
| 5726 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5727 | cmd = &piocb->iocb; |
| 5728 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5729 | continue; |
| 5730 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5731 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5732 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5733 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5734 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5735 | continue; |
| 5736 | list_move_tail(&piocb->list, &completions); |
| 5737 | pring->txq_cnt--; |
| 5738 | } |
| 5739 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5740 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5741 | continue; |
| 5742 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5743 | } |
| 5744 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5745 | |
| 5746 | /* Cancel all the IOCBs from the completions list */ |
| 5747 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5748 | IOERR_SLI_ABORTED); |
| 5749 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5750 | return; |
| 5751 | } |
| 5752 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5753 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5754 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5755 | * @phba: Pointer to hba context object. |
| 5756 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5757 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5758 | * |
| 5759 | * This function sends an event when there is an ELS command |
| 5760 | * failure. |
| 5761 | **/ |
| 5762 | void |
| 5763 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5764 | struct lpfc_iocbq *cmdiocbp, |
| 5765 | struct lpfc_iocbq *rspiocbp) |
| 5766 | { |
| 5767 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5768 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5769 | struct lpfc_lsrjt_event lsrjt_event; |
| 5770 | struct lpfc_fabric_event_header fabric_event; |
| 5771 | struct ls_rjt stat; |
| 5772 | struct lpfc_nodelist *ndlp; |
| 5773 | uint32_t *pcmd; |
| 5774 | |
| 5775 | ndlp = cmdiocbp->context1; |
| 5776 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5777 | return; |
| 5778 | |
| 5779 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5780 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5781 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5782 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5783 | sizeof(struct lpfc_name)); |
| 5784 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5785 | sizeof(struct lpfc_name)); |
| 5786 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5787 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 5788 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5789 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5790 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5791 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5792 | fc_host_post_vendor_event(shost, |
| 5793 | fc_get_event_number(), |
| 5794 | sizeof(lsrjt_event), |
| 5795 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5796 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5797 | return; |
| 5798 | } |
| 5799 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5800 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5801 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5802 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5803 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5804 | else |
| 5805 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5806 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5807 | sizeof(struct lpfc_name)); |
| 5808 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5809 | sizeof(struct lpfc_name)); |
| 5810 | fc_host_post_vendor_event(shost, |
| 5811 | fc_get_event_number(), |
| 5812 | sizeof(fabric_event), |
| 5813 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5814 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5815 | return; |
| 5816 | } |
| 5817 | |
| 5818 | } |
| 5819 | |
| 5820 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5821 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5822 | * @vport: Pointer to vport object. |
| 5823 | * @ndlp: Pointer FC node object. |
| 5824 | * @cmd: ELS command code. |
| 5825 | * |
| 5826 | * This function posts an event when there is an incoming |
| 5827 | * unsolicited ELS command. |
| 5828 | **/ |
| 5829 | static void |
| 5830 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5831 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5832 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5833 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5834 | struct lpfc_els_event_header *els_data = NULL; |
| 5835 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5836 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5837 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5838 | if (*payload == ELS_CMD_LOGO) { |
| 5839 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5840 | if (!logo_data) { |
| 5841 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5842 | "0148 Failed to allocate memory " |
| 5843 | "for LOGO event\n"); |
| 5844 | return; |
| 5845 | } |
| 5846 | els_data = &logo_data->header; |
| 5847 | } else { |
| 5848 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5849 | GFP_KERNEL); |
| 5850 | if (!els_data) { |
| 5851 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5852 | "0149 Failed to allocate memory " |
| 5853 | "for ELS event\n"); |
| 5854 | return; |
| 5855 | } |
| 5856 | } |
| 5857 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5858 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5859 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5860 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5861 | break; |
| 5862 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5863 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5864 | break; |
| 5865 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5866 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5867 | break; |
| 5868 | case ELS_CMD_LOGO: |
| 5869 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5870 | /* Copy the WWPN in the LOGO payload */ |
| 5871 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5872 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5873 | break; |
| 5874 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5875 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5876 | return; |
| 5877 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5878 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5879 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5880 | if (*payload == ELS_CMD_LOGO) { |
| 5881 | fc_host_post_vendor_event(shost, |
| 5882 | fc_get_event_number(), |
| 5883 | sizeof(struct lpfc_logo_event), |
| 5884 | (char *)logo_data, |
| 5885 | LPFC_NL_VENDOR_ID); |
| 5886 | kfree(logo_data); |
| 5887 | } else { |
| 5888 | fc_host_post_vendor_event(shost, |
| 5889 | fc_get_event_number(), |
| 5890 | sizeof(struct lpfc_els_event_header), |
| 5891 | (char *)els_data, |
| 5892 | LPFC_NL_VENDOR_ID); |
| 5893 | kfree(els_data); |
| 5894 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5895 | |
| 5896 | return; |
| 5897 | } |
| 5898 | |
| 5899 | |
| 5900 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5901 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5902 | * @phba: pointer to lpfc hba data structure. |
| 5903 | * @pring: pointer to a SLI ring. |
| 5904 | * @vport: pointer to a host virtual N_Port data structure. |
| 5905 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5906 | * |
| 5907 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5908 | * event. It first determines whether there is an existing ndlp that matches |
| 5909 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5910 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5911 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5912 | * of the discovery state machine. |
| 5913 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5914 | static void |
| 5915 | 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] | 5916 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5917 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5918 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5919 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5920 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5921 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5922 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5923 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5924 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5925 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5926 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5927 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5928 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5929 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5930 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5931 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5932 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5933 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5934 | did = icmd->un.rcvels.remoteID; |
| 5935 | if (icmd->ulpStatus) { |
| 5936 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5937 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5938 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5939 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5940 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5941 | |
| 5942 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5943 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5944 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5945 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5946 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5947 | if (vport->load_flag & FC_UNLOADING) |
| 5948 | goto dropit; |
| 5949 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5950 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5951 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5952 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5953 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5954 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5955 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5956 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5957 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5958 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5959 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5960 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5961 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5962 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5963 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5964 | NLP_STE_UNUSED_NODE); |
| 5965 | if (!ndlp) |
| 5966 | goto dropit; |
| 5967 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5968 | newnode = 1; |
| 5969 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5970 | ndlp->nlp_type |= NLP_FABRIC; |
| 5971 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5972 | /* This is similar to the new node path */ |
| 5973 | ndlp = lpfc_nlp_get(ndlp); |
| 5974 | if (!ndlp) |
| 5975 | goto dropit; |
| 5976 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5977 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5978 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5979 | |
| 5980 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5981 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5982 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5983 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5984 | |
| 5985 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5986 | cmd &= ELS_CMD_MASK; |
| 5987 | } |
| 5988 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5989 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5990 | "0112 ELS command x%x received from NPORT x%x " |
| 5991 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5992 | switch (cmd) { |
| 5993 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5994 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5995 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5996 | did, vport->port_state, ndlp->nlp_flag); |
| 5997 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5998 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5999 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 6000 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6001 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6002 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 6003 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 6004 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 6005 | rjt_err = LSRJT_UNABLE_TPC; |
| 6006 | break; |
| 6007 | } |
| 6008 | /* We get here, and drop thru, if we are PT2PT with |
| 6009 | * another NPort and the other side has initiated |
| 6010 | * the PLOGI before responding to our FLOGI. |
| 6011 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6012 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6013 | |
| 6014 | shost = lpfc_shost_from_vport(vport); |
| 6015 | spin_lock_irq(shost->host_lock); |
| 6016 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 6017 | spin_unlock_irq(shost->host_lock); |
| 6018 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6019 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6020 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6021 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6022 | break; |
| 6023 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6024 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6025 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 6026 | did, vport->port_state, ndlp->nlp_flag); |
| 6027 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6028 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6029 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6030 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6031 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6032 | break; |
| 6033 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6034 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6035 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 6036 | did, vport->port_state, ndlp->nlp_flag); |
| 6037 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6038 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6039 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6040 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6041 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6042 | break; |
| 6043 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6044 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6045 | break; |
| 6046 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6047 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6048 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 6049 | did, vport->port_state, ndlp->nlp_flag); |
| 6050 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6051 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6052 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6053 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6054 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6055 | break; |
| 6056 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6057 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6058 | break; |
| 6059 | case ELS_CMD_RSCN: |
| 6060 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6061 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6062 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6063 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6064 | break; |
| 6065 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6066 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6067 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 6068 | did, vport->port_state, ndlp->nlp_flag); |
| 6069 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6070 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6071 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6072 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6073 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6074 | break; |
| 6075 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6076 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6077 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6078 | break; |
| 6079 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6080 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6081 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 6082 | did, vport->port_state, ndlp->nlp_flag); |
| 6083 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6084 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6085 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6086 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6087 | break; |
| 6088 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6089 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6090 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6091 | break; |
| 6092 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6093 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6094 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 6095 | did, vport->port_state, ndlp->nlp_flag); |
| 6096 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6097 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6098 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6099 | break; |
| 6100 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6101 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6102 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 6103 | did, vport->port_state, ndlp->nlp_flag); |
| 6104 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6105 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6106 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6107 | break; |
| 6108 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6109 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6110 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 6111 | did, vport->port_state, ndlp->nlp_flag); |
| 6112 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6113 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6114 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6115 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6116 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6117 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6118 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 6119 | did, vport->port_state, ndlp->nlp_flag); |
| 6120 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6121 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6122 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6123 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6124 | break; |
| 6125 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6126 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6127 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6128 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6129 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6130 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 6131 | did, vport->port_state, ndlp->nlp_flag); |
| 6132 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6133 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6134 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6135 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6136 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6137 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6138 | case ELS_CMD_RLS: |
| 6139 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6140 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 6141 | did, vport->port_state, ndlp->nlp_flag); |
| 6142 | |
| 6143 | phba->fc_stat.elsRcvRLS++; |
| 6144 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 6145 | if (newnode) |
| 6146 | lpfc_nlp_put(ndlp); |
| 6147 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6148 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6149 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6150 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 6151 | did, vport->port_state, ndlp->nlp_flag); |
| 6152 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6153 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6154 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6155 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6156 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6157 | break; |
| 6158 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6159 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6160 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 6161 | did, vport->port_state, ndlp->nlp_flag); |
| 6162 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6163 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6164 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6165 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6166 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6167 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6168 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6169 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6170 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 6171 | did, vport->port_state, ndlp->nlp_flag); |
| 6172 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6173 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6174 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6175 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6176 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6177 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6178 | case ELS_CMD_RTV: |
| 6179 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6180 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 6181 | did, vport->port_state, ndlp->nlp_flag); |
| 6182 | phba->fc_stat.elsRcvRTV++; |
| 6183 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 6184 | if (newnode) |
| 6185 | lpfc_nlp_put(ndlp); |
| 6186 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6187 | case ELS_CMD_RRQ: |
| 6188 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6189 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 6190 | did, vport->port_state, ndlp->nlp_flag); |
| 6191 | |
| 6192 | phba->fc_stat.elsRcvRRQ++; |
| 6193 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 6194 | if (newnode) |
| 6195 | lpfc_nlp_put(ndlp); |
| 6196 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6197 | case ELS_CMD_ECHO: |
| 6198 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6199 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 6200 | did, vport->port_state, ndlp->nlp_flag); |
| 6201 | |
| 6202 | phba->fc_stat.elsRcvECHO++; |
| 6203 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 6204 | if (newnode) |
| 6205 | lpfc_nlp_put(ndlp); |
| 6206 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6207 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6208 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6209 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 6210 | cmd, did, vport->port_state); |
| 6211 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6212 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6213 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6214 | |
| 6215 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6216 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6217 | "0115 Unknown ELS command x%x " |
| 6218 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6219 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6220 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6221 | break; |
| 6222 | } |
| 6223 | |
| 6224 | /* check if need to LS_RJT received ELS cmd */ |
| 6225 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6226 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6227 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 6228 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6229 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 6230 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6231 | } |
| 6232 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6233 | lpfc_nlp_put(elsiocb->context1); |
| 6234 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6235 | return; |
| 6236 | |
| 6237 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6238 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6239 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6240 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6241 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6242 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6243 | phba->fc_stat.elsRcvDrop++; |
| 6244 | } |
| 6245 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6246 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6247 | * 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] | 6248 | * @phba: pointer to lpfc hba data structure. |
| 6249 | * @vpi: host virtual N_Port identifier. |
| 6250 | * |
| 6251 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 6252 | * @vpi. The function walks the HBA's vport list and returns the address |
| 6253 | * of the vport with the matching @vpi. |
| 6254 | * |
| 6255 | * Return code |
| 6256 | * NULL - No vport with the matching @vpi found |
| 6257 | * Otherwise - Address to the vport with the matching @vpi. |
| 6258 | **/ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6259 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6260 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 6261 | { |
| 6262 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6263 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6264 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6265 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6266 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6267 | if (vport->vpi == vpi) { |
| 6268 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6269 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6270 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6271 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6272 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6273 | return NULL; |
| 6274 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6275 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6276 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6277 | * 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] | 6278 | * @phba: pointer to lpfc hba data structure. |
| 6279 | * @pring: pointer to a SLI ring. |
| 6280 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 6281 | * |
| 6282 | * This routine is used to process an unsolicited event received from a SLI |
| 6283 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 6284 | * associated with the unsolicited event is done by invoking the routine |
| 6285 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 6286 | * SLI ring on which the unsolicited event was received. |
| 6287 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6288 | void |
| 6289 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 6290 | struct lpfc_iocbq *elsiocb) |
| 6291 | { |
| 6292 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6293 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6294 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6295 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 6296 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6297 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6298 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6299 | elsiocb->context2 = NULL; |
| 6300 | elsiocb->context3 = NULL; |
| 6301 | |
| 6302 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 6303 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 6304 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 6305 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6306 | phba->fc_stat.NoRcvBuf++; |
| 6307 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6308 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6309 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6310 | return; |
| 6311 | } |
| 6312 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6313 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 6314 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 6315 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 6316 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 6317 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6318 | else |
| 6319 | vport = lpfc_find_vport_by_vpid(phba, |
| 6320 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6321 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6322 | /* If there are no BDEs associated |
| 6323 | * with this IOCB, there is nothing to do. |
| 6324 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6325 | if (icmd->ulpBdeCount == 0) |
| 6326 | return; |
| 6327 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6328 | /* type of ELS cmd is first 32bit word |
| 6329 | * in packet |
| 6330 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6331 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6332 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6333 | } else { |
| 6334 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 6335 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6336 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 6337 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6338 | } |
| 6339 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6340 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 6341 | /* |
| 6342 | * The different unsolicited event handlers would tell us |
| 6343 | * if they are done with "mp" by setting context2 to NULL. |
| 6344 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6345 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6346 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 6347 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6348 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6349 | |
| 6350 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6351 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6352 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6353 | elsiocb->context2 = bdeBuf2; |
| 6354 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6355 | /* free mp if we are done with it */ |
| 6356 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6357 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 6358 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6359 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6360 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6361 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6362 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6363 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6364 | * 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] | 6365 | * @phba: pointer to lpfc hba data structure. |
| 6366 | * @vport: pointer to a virtual N_Port data structure. |
| 6367 | * |
| 6368 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 6369 | * State Change Request (SCR) for a @vport. This routine will create an |
| 6370 | * ndlp for the Name Server associated to the @vport if such node does |
| 6371 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 6372 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 6373 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 6374 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 6375 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6376 | void |
| 6377 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 6378 | { |
| 6379 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 6380 | |
| 6381 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 6382 | if (!ndlp) { |
| 6383 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 6384 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 6385 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6386 | lpfc_disc_start(vport); |
| 6387 | return; |
| 6388 | } |
| 6389 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6390 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6391 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6392 | return; |
| 6393 | } |
| 6394 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6395 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 6396 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 6397 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 6398 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6399 | lpfc_disc_start(vport); |
| 6400 | return; |
| 6401 | } |
| 6402 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6403 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6404 | "0348 NameServer login: node freed\n"); |
| 6405 | return; |
| 6406 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6407 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6408 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6409 | |
| 6410 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 6411 | |
| 6412 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 6413 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6414 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6415 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6416 | return; |
| 6417 | } |
| 6418 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6419 | if (vport->cfg_fdmi_on) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6420 | /* If this is the first time, allocate an ndlp and initialize |
| 6421 | * it. Otherwise, make sure the node is enabled and then do the |
| 6422 | * login. |
| 6423 | */ |
| 6424 | ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID); |
| 6425 | if (!ndlp_fdmi) { |
| 6426 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 6427 | GFP_KERNEL); |
| 6428 | if (ndlp_fdmi) { |
| 6429 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 6430 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
| 6431 | } else |
| 6432 | return; |
| 6433 | } |
| 6434 | if (!NLP_CHK_NODE_ACT(ndlp_fdmi)) |
| 6435 | ndlp_fdmi = lpfc_enable_node(vport, |
| 6436 | ndlp_fdmi, |
| 6437 | NLP_STE_NPR_NODE); |
| 6438 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6439 | if (ndlp_fdmi) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6440 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6441 | NLP_STE_PLOGI_ISSUE); |
| 6442 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6443 | } |
| 6444 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6445 | } |
| 6446 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6447 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6448 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6449 | * @phba: pointer to lpfc hba data structure. |
| 6450 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6451 | * |
| 6452 | * This routine is the completion callback function to register new vport |
| 6453 | * mailbox command. If the new vport mailbox command completes successfully, |
| 6454 | * the fabric registration login shall be performed on physical port (the |
| 6455 | * new vport created is actually a physical port, with VPI 0) or the port |
| 6456 | * login to Name Server for State Change Request (SCR) will be performed |
| 6457 | * on virtual port (real virtual port, with VPI greater than 0). |
| 6458 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6459 | static void |
| 6460 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6461 | { |
| 6462 | struct lpfc_vport *vport = pmb->vport; |
| 6463 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6464 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6465 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6466 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6467 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6468 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6469 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6470 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6471 | |
| 6472 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6473 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6474 | "0915 Register VPI failed : Status: x%x" |
| 6475 | " upd bit: x%x \n", mb->mbxStatus, |
| 6476 | mb->un.varRegVpi.upd); |
| 6477 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 6478 | mb->un.varRegVpi.upd) |
| 6479 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6480 | |
| 6481 | switch (mb->mbxStatus) { |
| 6482 | case 0x11: /* unsupported feature */ |
| 6483 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6484 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6485 | /* giving up on vport registration */ |
| 6486 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6487 | spin_lock_irq(shost->host_lock); |
| 6488 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6489 | spin_unlock_irq(shost->host_lock); |
| 6490 | lpfc_can_disctmo(vport); |
| 6491 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6492 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 6493 | case 0x20: |
| 6494 | spin_lock_irq(shost->host_lock); |
| 6495 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6496 | spin_unlock_irq(shost->host_lock); |
| 6497 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 6498 | pmb->vport = vport; |
| 6499 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 6500 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 6501 | MBX_NOWAIT); |
| 6502 | if (rc == MBX_NOT_FINISHED) { |
| 6503 | lpfc_printf_vlog(vport, |
| 6504 | KERN_ERR, LOG_MBOX, |
| 6505 | "2732 Failed to issue INIT_VPI" |
| 6506 | " mailbox command\n"); |
| 6507 | } else { |
| 6508 | lpfc_nlp_put(ndlp); |
| 6509 | return; |
| 6510 | } |
| 6511 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6512 | default: |
| 6513 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6514 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6515 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6516 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6517 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6518 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6519 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6520 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 6521 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 6522 | lpfc_issue_init_vfi(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6523 | else |
| 6524 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6525 | break; |
| 6526 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6527 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6528 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 6529 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6530 | spin_unlock_irq(shost->host_lock); |
| 6531 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6532 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6533 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6534 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6535 | /* |
| 6536 | * If the physical port is instantiated using |
| 6537 | * FDISC, do not start vport discovery. |
| 6538 | */ |
| 6539 | if (vport->port_state != LPFC_FDISC) |
| 6540 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6541 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6542 | } |
| 6543 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6544 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6545 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6546 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6547 | /* Now, we decrement the ndlp reference count held for this |
| 6548 | * callback function |
| 6549 | */ |
| 6550 | lpfc_nlp_put(ndlp); |
| 6551 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6552 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6553 | return; |
| 6554 | } |
| 6555 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6556 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6557 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6558 | * @phba: pointer to lpfc hba data structure. |
| 6559 | * @vport: pointer to a host virtual N_Port data structure. |
| 6560 | * @ndlp: pointer to a node-list data structure. |
| 6561 | * |
| 6562 | * This routine registers the @vport as a new virtual port with a HBA. |
| 6563 | * It is done through a registering vpi mailbox command. |
| 6564 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6565 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6566 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 6567 | struct lpfc_nodelist *ndlp) |
| 6568 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6569 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6570 | LPFC_MBOXQ_t *mbox; |
| 6571 | |
| 6572 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6573 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6574 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6575 | mbox->vport = vport; |
| 6576 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6577 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6578 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6579 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6580 | /* mailbox command not success, decrement ndlp |
| 6581 | * reference count for this command |
| 6582 | */ |
| 6583 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6584 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6585 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6586 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6587 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6588 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6589 | } |
| 6590 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6591 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6592 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6593 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6594 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6595 | return; |
| 6596 | |
| 6597 | mbox_err_exit: |
| 6598 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6599 | spin_lock_irq(shost->host_lock); |
| 6600 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 6601 | spin_unlock_irq(shost->host_lock); |
| 6602 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6603 | } |
| 6604 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6605 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6606 | * 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] | 6607 | * @phba: pointer to lpfc hba data structure. |
| 6608 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6609 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6610 | **/ |
| 6611 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6612 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6613 | { |
| 6614 | struct lpfc_vport **vports; |
| 6615 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6616 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6617 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6618 | |
| 6619 | /* Treat this failure as linkdown for all vports */ |
| 6620 | link_state = phba->link_state; |
| 6621 | lpfc_linkdown(phba); |
| 6622 | phba->link_state = link_state; |
| 6623 | |
| 6624 | vports = lpfc_create_vport_work_array(phba); |
| 6625 | |
| 6626 | if (vports) { |
| 6627 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6628 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6629 | if (ndlp) |
| 6630 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 6631 | lpfc_els_flush_cmd(vports[i]); |
| 6632 | } |
| 6633 | lpfc_destroy_vport_work_array(phba, vports); |
| 6634 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6635 | } |
| 6636 | |
| 6637 | /** |
| 6638 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 6639 | * @phba: pointer to lpfc hba data structure. |
| 6640 | * |
| 6641 | * This routine abort all pending discovery commands and |
| 6642 | * start a timer to retry FLOGI for the physical port |
| 6643 | * discovery. |
| 6644 | **/ |
| 6645 | void |
| 6646 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 6647 | { |
| 6648 | struct lpfc_nodelist *ndlp; |
| 6649 | struct Scsi_Host *shost; |
| 6650 | |
| 6651 | /* Cancel the all vports retry delay retry timers */ |
| 6652 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6653 | |
| 6654 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 6655 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6656 | if (!ndlp) |
| 6657 | return; |
| 6658 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6659 | shost = lpfc_shost_from_vport(phba->pport); |
| 6660 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 6661 | spin_lock_irq(shost->host_lock); |
| 6662 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 6663 | spin_unlock_irq(shost->host_lock); |
| 6664 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 6665 | phba->pport->port_state = LPFC_FLOGI; |
| 6666 | return; |
| 6667 | } |
| 6668 | |
| 6669 | /** |
| 6670 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 6671 | * @phba: pointer to lpfc hba data structure. |
| 6672 | * @cmdiocb: pointer to FDISC command iocb. |
| 6673 | * @rspiocb: pointer to FDISC response iocb. |
| 6674 | * |
| 6675 | * This routine checks if a FLOGI is reguired for FDISC |
| 6676 | * to succeed. |
| 6677 | **/ |
| 6678 | static int |
| 6679 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 6680 | struct lpfc_iocbq *cmdiocb, |
| 6681 | struct lpfc_iocbq *rspiocb) |
| 6682 | { |
| 6683 | |
| 6684 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 6685 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 6686 | return 0; |
| 6687 | else |
| 6688 | return 1; |
| 6689 | } |
| 6690 | |
| 6691 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6692 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6693 | * @phba: pointer to lpfc hba data structure. |
| 6694 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6695 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6696 | * |
| 6697 | * This routine is the completion callback function to a Fabric Discover |
| 6698 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 6699 | * single threaded, each FDISC completion callback function will reset |
| 6700 | * the discovery timer for all vports such that the timers will not get |
| 6701 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 6702 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 6703 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 6704 | * assigned to the vport has been changed with the completion of the FDISC |
| 6705 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 6706 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 6707 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 6708 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 6709 | * Server for State Change Request (SCR). |
| 6710 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6711 | static void |
| 6712 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6713 | struct lpfc_iocbq *rspiocb) |
| 6714 | { |
| 6715 | struct lpfc_vport *vport = cmdiocb->vport; |
| 6716 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6717 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 6718 | struct lpfc_nodelist *np; |
| 6719 | struct lpfc_nodelist *next_np; |
| 6720 | IOCB_t *irsp = &rspiocb->iocb; |
| 6721 | struct lpfc_iocbq *piocb; |
| 6722 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6723 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6724 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 6725 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 6726 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6727 | /* Since all FDISCs are being single threaded, we |
| 6728 | * must reset the discovery timer for ALL vports |
| 6729 | * waiting to send FDISC when one completes. |
| 6730 | */ |
| 6731 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 6732 | lpfc_set_disctmo(piocb->vport); |
| 6733 | } |
| 6734 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6735 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6736 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6737 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6738 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6739 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6740 | |
| 6741 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 6742 | lpfc_retry_pport_discovery(phba); |
| 6743 | goto out; |
| 6744 | } |
| 6745 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6746 | /* Check for retry */ |
| 6747 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6748 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6749 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6750 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6751 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6752 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6753 | goto fdisc_failed; |
| 6754 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6755 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6756 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6757 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6758 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame^] | 6759 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6760 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6761 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6762 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6763 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6764 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6765 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6766 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6767 | /* If our NportID changed, we need to ensure all |
| 6768 | * remaining NPORTs get unreg_login'ed so we can |
| 6769 | * issue unreg_vpi. |
| 6770 | */ |
| 6771 | list_for_each_entry_safe(np, next_np, |
| 6772 | &vport->fc_nodes, nlp_listp) { |
| 6773 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6774 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6775 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6776 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6777 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6778 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6779 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6780 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6781 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6782 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6783 | |
| 6784 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6785 | lpfc_sli4_unreg_all_rpis(vport); |
| 6786 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6787 | lpfc_mbx_unreg_vpi(vport); |
| 6788 | spin_lock_irq(shost->host_lock); |
| 6789 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6790 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6791 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6792 | else |
| 6793 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6794 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6795 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 6796 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6797 | /* |
| 6798 | * Driver needs to re-reg VPI in order for f/w |
| 6799 | * to update the MAC address. |
| 6800 | */ |
| 6801 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 6802 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6803 | } |
| 6804 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6805 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 6806 | lpfc_issue_init_vpi(vport); |
| 6807 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6808 | lpfc_register_new_vport(phba, vport, ndlp); |
| 6809 | else |
| 6810 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6811 | goto out; |
| 6812 | fdisc_failed: |
| 6813 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6814 | /* Cancel discovery timer */ |
| 6815 | lpfc_can_disctmo(vport); |
| 6816 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6817 | out: |
| 6818 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6819 | } |
| 6820 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6821 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6822 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6823 | * @vport: pointer to a virtual N_Port data structure. |
| 6824 | * @ndlp: pointer to a node-list data structure. |
| 6825 | * @retry: number of retries to the command IOCB. |
| 6826 | * |
| 6827 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6828 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6829 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6830 | * IOCB will be sent off HBA at any given time. |
| 6831 | * |
| 6832 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6833 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6834 | * will be stored into the context1 field of the IOCB for the completion |
| 6835 | * callback function to the FDISC ELS command. |
| 6836 | * |
| 6837 | * Return code |
| 6838 | * 0 - Successfully issued fdisc iocb command |
| 6839 | * 1 - Failed to issue fdisc iocb command |
| 6840 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6841 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6842 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6843 | uint8_t retry) |
| 6844 | { |
| 6845 | struct lpfc_hba *phba = vport->phba; |
| 6846 | IOCB_t *icmd; |
| 6847 | struct lpfc_iocbq *elsiocb; |
| 6848 | struct serv_parm *sp; |
| 6849 | uint8_t *pcmd; |
| 6850 | uint16_t cmdsize; |
| 6851 | int did = ndlp->nlp_DID; |
| 6852 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6853 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6854 | vport->port_state = LPFC_FDISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6855 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6856 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6857 | ELS_CMD_FDISC); |
| 6858 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6859 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6860 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6861 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6862 | return 1; |
| 6863 | } |
| 6864 | |
| 6865 | icmd = &elsiocb->iocb; |
| 6866 | icmd->un.elsreq64.myID = 0; |
| 6867 | icmd->un.elsreq64.fl = 1; |
| 6868 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6869 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 6870 | /* FDISC needs to be 1 for WQE VPI */ |
| 6871 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 6872 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 6873 | /* Set the ulpContext to the vpi */ |
| 6874 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 6875 | } else { |
| 6876 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6877 | icmd->ulpCt_h = 1; |
| 6878 | icmd->ulpCt_l = 0; |
| 6879 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6880 | |
| 6881 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6882 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6883 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6884 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6885 | sp = (struct serv_parm *) pcmd; |
| 6886 | /* Setup CSPs accordingly for Fabric */ |
| 6887 | sp->cmn.e_d_tov = 0; |
| 6888 | sp->cmn.w2.r_a_tov = 0; |
| 6889 | sp->cls1.classValid = 0; |
| 6890 | sp->cls2.seqDelivery = 1; |
| 6891 | sp->cls3.seqDelivery = 1; |
| 6892 | |
| 6893 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6894 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6895 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6896 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6897 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6898 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6899 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6900 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6901 | |
| 6902 | lpfc_set_disctmo(vport); |
| 6903 | |
| 6904 | phba->fc_stat.elsXmitFDISC++; |
| 6905 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6906 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6907 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6908 | "Issue FDISC: did:x%x", |
| 6909 | did, 0, 0); |
| 6910 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6911 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6912 | if (rc == IOCB_ERROR) { |
| 6913 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6914 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6915 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6916 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6917 | return 1; |
| 6918 | } |
| 6919 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6920 | return 0; |
| 6921 | } |
| 6922 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6923 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6924 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6925 | * @phba: pointer to lpfc hba data structure. |
| 6926 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6927 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6928 | * |
| 6929 | * This routine is the completion callback function to the issuing of a LOGO |
| 6930 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6931 | * reference count held on ndlp for this completion function, indicating that |
| 6932 | * the reference to the ndlp is no long needed. Note that the |
| 6933 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6934 | * callback function and an additional explicit ndlp reference decrementation |
| 6935 | * will trigger the actual release of the ndlp. |
| 6936 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6937 | static void |
| 6938 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6939 | struct lpfc_iocbq *rspiocb) |
| 6940 | { |
| 6941 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6942 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6943 | struct lpfc_nodelist *ndlp; |
| 6944 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6945 | |
| 6946 | irsp = &rspiocb->iocb; |
| 6947 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6948 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6949 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6950 | |
| 6951 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6952 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6953 | |
| 6954 | /* Trigger the release of the ndlp after logo */ |
| 6955 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6956 | } |
| 6957 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6958 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6959 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6960 | * @vport: pointer to a virtual N_Port data structure. |
| 6961 | * @ndlp: pointer to a node-list data structure. |
| 6962 | * |
| 6963 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6964 | * |
| 6965 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6966 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6967 | * will be stored into the context1 field of the IOCB for the completion |
| 6968 | * callback function to the LOGO ELS command. |
| 6969 | * |
| 6970 | * Return codes |
| 6971 | * 0 - Successfully issued logo off the @vport |
| 6972 | * 1 - Failed to issue logo off the @vport |
| 6973 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6974 | int |
| 6975 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6976 | { |
| 6977 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6978 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6979 | IOCB_t *icmd; |
| 6980 | struct lpfc_iocbq *elsiocb; |
| 6981 | uint8_t *pcmd; |
| 6982 | uint16_t cmdsize; |
| 6983 | |
| 6984 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6985 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6986 | ELS_CMD_LOGO); |
| 6987 | if (!elsiocb) |
| 6988 | return 1; |
| 6989 | |
| 6990 | icmd = &elsiocb->iocb; |
| 6991 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6992 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6993 | pcmd += sizeof(uint32_t); |
| 6994 | |
| 6995 | /* Fill in LOGO payload */ |
| 6996 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6997 | pcmd += sizeof(uint32_t); |
| 6998 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6999 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7000 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7001 | "Issue LOGO npiv did:x%x flg:x%x", |
| 7002 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 7003 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7004 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 7005 | spin_lock_irq(shost->host_lock); |
| 7006 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 7007 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7008 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 7009 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7010 | spin_lock_irq(shost->host_lock); |
| 7011 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 7012 | spin_unlock_irq(shost->host_lock); |
| 7013 | lpfc_els_free_iocb(phba, elsiocb); |
| 7014 | return 1; |
| 7015 | } |
| 7016 | return 0; |
| 7017 | } |
| 7018 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7019 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7020 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7021 | * @ptr: holder for the timer function associated data. |
| 7022 | * |
| 7023 | * This routine is invoked by the fabric iocb block timer after |
| 7024 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 7025 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 7026 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 7027 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 7028 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 7029 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7030 | void |
| 7031 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 7032 | { |
| 7033 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 7034 | unsigned long iflags; |
| 7035 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7036 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7037 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 7038 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 7039 | if (!tmo_posted) |
| 7040 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 7041 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 7042 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7043 | if (!tmo_posted) |
| 7044 | lpfc_worker_wake_up(phba); |
| 7045 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7046 | } |
| 7047 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7048 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7049 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7050 | * @phba: pointer to lpfc hba data structure. |
| 7051 | * |
| 7052 | * This routine issues one fabric iocb from the driver internal list to |
| 7053 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 7054 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 7055 | * remove one pending fabric iocb from the driver internal list and invokes |
| 7056 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 7057 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7058 | static void |
| 7059 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 7060 | { |
| 7061 | struct lpfc_iocbq *iocb; |
| 7062 | unsigned long iflags; |
| 7063 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7064 | IOCB_t *cmd; |
| 7065 | |
| 7066 | repeat: |
| 7067 | iocb = NULL; |
| 7068 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7069 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7070 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 7071 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 7072 | list); |
| 7073 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7074 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7075 | atomic_inc(&phba->fabric_iocb_count); |
| 7076 | } |
| 7077 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7078 | if (iocb) { |
| 7079 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7080 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7081 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7082 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7083 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7084 | "Fabric sched1: ste:x%x", |
| 7085 | iocb->vport->port_state, 0, 0); |
| 7086 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7087 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7088 | |
| 7089 | if (ret == IOCB_ERROR) { |
| 7090 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7091 | iocb->fabric_iocb_cmpl = NULL; |
| 7092 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7093 | cmd = &iocb->iocb; |
| 7094 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 7095 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 7096 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 7097 | |
| 7098 | atomic_dec(&phba->fabric_iocb_count); |
| 7099 | goto repeat; |
| 7100 | } |
| 7101 | } |
| 7102 | |
| 7103 | return; |
| 7104 | } |
| 7105 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7106 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7107 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7108 | * @phba: pointer to lpfc hba data structure. |
| 7109 | * |
| 7110 | * This routine unblocks the issuing fabric iocb command. The function |
| 7111 | * will clear the fabric iocb block bit and then invoke the routine |
| 7112 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 7113 | * from the driver internal fabric iocb list. |
| 7114 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7115 | void |
| 7116 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 7117 | { |
| 7118 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7119 | |
| 7120 | lpfc_resume_fabric_iocbs(phba); |
| 7121 | return; |
| 7122 | } |
| 7123 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7124 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7125 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7126 | * @phba: pointer to lpfc hba data structure. |
| 7127 | * |
| 7128 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 7129 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 7130 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 7131 | * fabric iocb will be issued out of the HBA. |
| 7132 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7133 | static void |
| 7134 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 7135 | { |
| 7136 | int blocked; |
| 7137 | |
| 7138 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7139 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7140 | if (!blocked) |
| 7141 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 7142 | |
| 7143 | return; |
| 7144 | } |
| 7145 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7146 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7147 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7148 | * @phba: pointer to lpfc hba data structure. |
| 7149 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7150 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7151 | * |
| 7152 | * This routine is the callback function that is put to the fabric iocb's |
| 7153 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 7154 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 7155 | * function first restores and invokes the original iocb's callback function |
| 7156 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 7157 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 7158 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7159 | static void |
| 7160 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7161 | struct lpfc_iocbq *rspiocb) |
| 7162 | { |
| 7163 | struct ls_rjt stat; |
| 7164 | |
| 7165 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 7166 | BUG(); |
| 7167 | |
| 7168 | switch (rspiocb->iocb.ulpStatus) { |
| 7169 | case IOSTAT_NPORT_RJT: |
| 7170 | case IOSTAT_FABRIC_RJT: |
| 7171 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 7172 | lpfc_block_fabric_iocbs(phba); |
| 7173 | } |
| 7174 | break; |
| 7175 | |
| 7176 | case IOSTAT_NPORT_BSY: |
| 7177 | case IOSTAT_FABRIC_BSY: |
| 7178 | lpfc_block_fabric_iocbs(phba); |
| 7179 | break; |
| 7180 | |
| 7181 | case IOSTAT_LS_RJT: |
| 7182 | stat.un.lsRjtError = |
| 7183 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 7184 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 7185 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 7186 | lpfc_block_fabric_iocbs(phba); |
| 7187 | break; |
| 7188 | } |
| 7189 | |
| 7190 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 7191 | BUG(); |
| 7192 | |
| 7193 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 7194 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 7195 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7196 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 7197 | |
| 7198 | atomic_dec(&phba->fabric_iocb_count); |
| 7199 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7200 | /* Post any pending iocbs to HBA */ |
| 7201 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7202 | } |
| 7203 | } |
| 7204 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7205 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7206 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7207 | * @phba: pointer to lpfc hba data structure. |
| 7208 | * @iocb: pointer to lpfc command iocb data structure. |
| 7209 | * |
| 7210 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 7211 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 7212 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 7213 | * any given time. As such, this function will first check to see whether there |
| 7214 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 7215 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 7216 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 7217 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 7218 | * |
| 7219 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 7220 | * order. The problem is caused by the construction of the "ready" boolen does |
| 7221 | * not include the condition that the internal fabric IOCB list is empty. As |
| 7222 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 7223 | * ahead of the fabric IOCBs in the internal list. |
| 7224 | * |
| 7225 | * Return code |
| 7226 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 7227 | * IOCB_ERROR - failed to issue fabric iocb |
| 7228 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7229 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7230 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 7231 | { |
| 7232 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7233 | int ready; |
| 7234 | int ret; |
| 7235 | |
| 7236 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 7237 | BUG(); |
| 7238 | |
| 7239 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7240 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 7241 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7242 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7243 | if (ready) |
| 7244 | /* Increment fabric iocb count to hold the position */ |
| 7245 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7246 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7247 | if (ready) { |
| 7248 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7249 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7250 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7251 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7252 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7253 | "Fabric sched2: ste:x%x", |
| 7254 | iocb->vport->port_state, 0, 0); |
| 7255 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7256 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7257 | |
| 7258 | if (ret == IOCB_ERROR) { |
| 7259 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7260 | iocb->fabric_iocb_cmpl = NULL; |
| 7261 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7262 | atomic_dec(&phba->fabric_iocb_count); |
| 7263 | } |
| 7264 | } else { |
| 7265 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7266 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 7267 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7268 | ret = IOCB_SUCCESS; |
| 7269 | } |
| 7270 | return ret; |
| 7271 | } |
| 7272 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7273 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7274 | * 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] | 7275 | * @vport: pointer to a virtual N_Port data structure. |
| 7276 | * |
| 7277 | * This routine aborts all the IOCBs associated with a @vport from the |
| 7278 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7279 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7280 | * list, removes each IOCB associated with the @vport off the list, set the |
| 7281 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7282 | * associated with the IOCB. |
| 7283 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7284 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7285 | { |
| 7286 | LIST_HEAD(completions); |
| 7287 | struct lpfc_hba *phba = vport->phba; |
| 7288 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7289 | |
| 7290 | spin_lock_irq(&phba->hbalock); |
| 7291 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7292 | list) { |
| 7293 | |
| 7294 | if (piocb->vport != vport) |
| 7295 | continue; |
| 7296 | |
| 7297 | list_move_tail(&piocb->list, &completions); |
| 7298 | } |
| 7299 | spin_unlock_irq(&phba->hbalock); |
| 7300 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7301 | /* Cancel all the IOCBs from the completions list */ |
| 7302 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7303 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7304 | } |
| 7305 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7306 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7307 | * 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] | 7308 | * @ndlp: pointer to a node-list data structure. |
| 7309 | * |
| 7310 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 7311 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7312 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7313 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 7314 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7315 | * associated with the IOCB. |
| 7316 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7317 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 7318 | { |
| 7319 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7320 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7321 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7322 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7323 | |
| 7324 | spin_lock_irq(&phba->hbalock); |
| 7325 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7326 | list) { |
| 7327 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 7328 | |
| 7329 | list_move_tail(&piocb->list, &completions); |
| 7330 | } |
| 7331 | } |
| 7332 | spin_unlock_irq(&phba->hbalock); |
| 7333 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7334 | /* Cancel all the IOCBs from the completions list */ |
| 7335 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7336 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7337 | } |
| 7338 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7339 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7340 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7341 | * @phba: pointer to lpfc hba data structure. |
| 7342 | * |
| 7343 | * This routine aborts all the IOCBs currently on the driver internal |
| 7344 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 7345 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 7346 | * list, removes IOCBs off the list, set the status feild to |
| 7347 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 7348 | * the IOCB. |
| 7349 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7350 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 7351 | { |
| 7352 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7353 | |
| 7354 | spin_lock_irq(&phba->hbalock); |
| 7355 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 7356 | spin_unlock_irq(&phba->hbalock); |
| 7357 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7358 | /* Cancel all the IOCBs from the completions list */ |
| 7359 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7360 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7361 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7362 | |
| 7363 | /** |
| 7364 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 7365 | * @phba: pointer to lpfc hba data structure. |
| 7366 | * @axri: pointer to the els xri abort wcqe structure. |
| 7367 | * |
| 7368 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 7369 | * ELS aborted xri. |
| 7370 | **/ |
| 7371 | void |
| 7372 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 7373 | struct sli4_wcqe_xri_aborted *axri) |
| 7374 | { |
| 7375 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 7376 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7377 | unsigned long iflag = 0; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7378 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7379 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7380 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7381 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7382 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 7383 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 7384 | if (sglq_entry->sli4_xritag == xri) { |
| 7385 | list_del(&sglq_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7386 | list_add_tail(&sglq_entry->list, |
| 7387 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7388 | sglq_entry->state = SGL_FREED; |
| 7389 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7390 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7391 | |
| 7392 | /* Check if TXQ queue needs to be serviced */ |
| 7393 | if (pring->txq_cnt) |
| 7394 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7395 | return; |
| 7396 | } |
| 7397 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7398 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 7399 | sglq_entry = __lpfc_get_active_sglq(phba, xri); |
| 7400 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
| 7401 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7402 | return; |
| 7403 | } |
| 7404 | sglq_entry->state = SGL_XRI_ABORTED; |
| 7405 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7406 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7407 | } |