| 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 | c9f8735 | 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: |
| 180 | elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) |
| 181 | & LPFC_FIP_ELS_ID_MASK); |
| 182 | break; |
| 183 | case ELS_CMD_FDISC: |
| 184 | elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) |
| 185 | & LPFC_FIP_ELS_ID_MASK); |
| 186 | break; |
| 187 | case ELS_CMD_LOGO: |
| 188 | elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) |
| 189 | & LPFC_FIP_ELS_ID_MASK); |
| 190 | break; |
| 191 | } |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 192 | else |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 193 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 194 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 195 | icmd = &elsiocb->iocb; |
| 196 | |
| 197 | /* fill in BDEs for command */ |
| 198 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 199 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 200 | if (pcmd) |
| 201 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 202 | if (!pcmd || !pcmd->virt) |
| 203 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 204 | |
| 205 | INIT_LIST_HEAD(&pcmd->list); |
| 206 | |
| 207 | /* Allocate buffer for response payload */ |
| 208 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 209 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | if (prsp) |
| 211 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 212 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 213 | if (!prsp || !prsp->virt) |
| 214 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 216 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 217 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 218 | |
| 219 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 220 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 221 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 222 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 223 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 224 | if (!pbuflist || !pbuflist->virt) |
| 225 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 226 | |
| 227 | INIT_LIST_HEAD(&pbuflist->list); |
| 228 | |
| 229 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 230 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 231 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 232 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 233 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 234 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 235 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 236 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 238 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 240 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | icmd->ulpBdeCount = 1; |
| 242 | icmd->ulpLe = 1; |
| 243 | icmd->ulpClass = CLASS3; |
| 244 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 245 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 246 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 247 | |
| 248 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 249 | icmd->ulpContext = vport->vpi + phba->vpi_base; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 250 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 251 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 252 | if (elscmd == ELS_CMD_ECHO) |
| 253 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 254 | else |
| 255 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 256 | } |
| 257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 258 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 259 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 260 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 261 | bpl->tus.f.bdeSize = cmdSize; |
| 262 | bpl->tus.f.bdeFlags = 0; |
| 263 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 264 | |
| 265 | if (expectRsp) { |
| 266 | bpl++; |
| 267 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 268 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 269 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 270 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 271 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 272 | } |
| 273 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 274 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 275 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 276 | if (!elsiocb->context1) |
| 277 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 278 | elsiocb->context2 = pcmd; |
| 279 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 280 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 281 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 282 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 283 | |
| 284 | if (prsp) { |
| 285 | list_add(&prsp->list, &pcmd->list); |
| 286 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 287 | if (expectRsp) { |
| 288 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 289 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 290 | "0116 Xmit ELS command x%x to remote " |
| 291 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 292 | elscmd, did, elsiocb->iotag, |
| 293 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 294 | } else { |
| 295 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 296 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 297 | "0117 Xmit ELS response x%x to remote " |
| 298 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 299 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 300 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 301 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 302 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 303 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 304 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 305 | if (expectRsp) |
| 306 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 307 | kfree(pbuflist); |
| 308 | |
| 309 | els_iocb_free_prsp_exit: |
| 310 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 311 | kfree(prsp); |
| 312 | |
| 313 | els_iocb_free_pcmb_exit: |
| 314 | kfree(pcmd); |
| 315 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 316 | return NULL; |
| 317 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 318 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 319 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 320 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 321 | * @vport: pointer to a host virtual N_Port data structure. |
| 322 | * |
| 323 | * This routine issues a fabric registration login for a @vport. An |
| 324 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 325 | * The routine invokes two mailbox commands to carry out fabric registration |
| 326 | * login through the HBA firmware: the first mailbox command requests the |
| 327 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 328 | * command requests the HBA to perform the actual fabric registration login |
| 329 | * with the @vport. |
| 330 | * |
| 331 | * Return code |
| 332 | * 0 - successfully issued fabric registration login for @vport |
| 333 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 334 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 335 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 336 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 337 | { |
| 338 | struct lpfc_hba *phba = vport->phba; |
| 339 | LPFC_MBOXQ_t *mbox; |
| 340 | struct lpfc_dmabuf *mp; |
| 341 | struct lpfc_nodelist *ndlp; |
| 342 | struct serv_parm *sp; |
| 343 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 344 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 345 | |
| 346 | sp = &phba->fc_fabparam; |
| 347 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 348 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 349 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 350 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 351 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 352 | |
| 353 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 354 | if (!mbox) { |
| 355 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 356 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 357 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 358 | |
| 359 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 360 | lpfc_config_link(phba, mbox); |
| 361 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 362 | mbox->vport = vport; |
| 363 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 364 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 365 | if (rc == MBX_NOT_FINISHED) { |
| 366 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 367 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 368 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 369 | |
| 370 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 371 | if (!mbox) { |
| 372 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 373 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 374 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 375 | 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] | 376 | if (rc) { |
| 377 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 378 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 379 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 380 | |
| 381 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 382 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 383 | /* increment the reference count on ndlp to hold reference |
| 384 | * for the callback routine. |
| 385 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 386 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 387 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 388 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 389 | if (rc == MBX_NOT_FINISHED) { |
| 390 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 391 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 392 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 393 | |
| 394 | return 0; |
| 395 | |
| 396 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 397 | /* decrement the reference count on ndlp just incremented |
| 398 | * for the failed mbox command. |
| 399 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 400 | lpfc_nlp_put(ndlp); |
| 401 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 402 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 403 | kfree(mp); |
| 404 | fail_free_mbox: |
| 405 | mempool_free(mbox, phba->mbox_mem_pool); |
| 406 | |
| 407 | fail: |
| 408 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 409 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 410 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 411 | return -ENXIO; |
| 412 | } |
| 413 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 414 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 415 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 416 | * @vport: pointer to a host virtual N_Port data structure. |
| 417 | * |
| 418 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
| 419 | * the @vport. This mailbox command is necessary for FCoE only. |
| 420 | * |
| 421 | * Return code |
| 422 | * 0 - successfully issued REG_VFI for @vport |
| 423 | * A failure code otherwise. |
| 424 | **/ |
| 425 | static int |
| 426 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 427 | { |
| 428 | struct lpfc_hba *phba = vport->phba; |
| 429 | LPFC_MBOXQ_t *mboxq; |
| 430 | struct lpfc_nodelist *ndlp; |
| 431 | struct serv_parm *sp; |
| 432 | struct lpfc_dmabuf *dmabuf; |
| 433 | int rc = 0; |
| 434 | |
| 435 | sp = &phba->fc_fabparam; |
| 436 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 437 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 438 | rc = -ENODEV; |
| 439 | goto fail; |
| 440 | } |
| 441 | |
| 442 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 443 | if (!dmabuf) { |
| 444 | rc = -ENOMEM; |
| 445 | goto fail; |
| 446 | } |
| 447 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 448 | if (!dmabuf->virt) { |
| 449 | rc = -ENOMEM; |
| 450 | goto fail_free_dmabuf; |
| 451 | } |
| 452 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 453 | if (!mboxq) { |
| 454 | rc = -ENOMEM; |
| 455 | goto fail_free_coherent; |
| 456 | } |
| 457 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 458 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 459 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 460 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 461 | mboxq->vport = vport; |
| 462 | mboxq->context1 = dmabuf; |
| 463 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 464 | if (rc == MBX_NOT_FINISHED) { |
| 465 | rc = -ENXIO; |
| 466 | goto fail_free_mbox; |
| 467 | } |
| 468 | return 0; |
| 469 | |
| 470 | fail_free_mbox: |
| 471 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 472 | fail_free_coherent: |
| 473 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 474 | fail_free_dmabuf: |
| 475 | kfree(dmabuf); |
| 476 | fail: |
| 477 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 478 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 479 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 480 | return rc; |
| 481 | } |
| 482 | |
| 483 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 484 | * 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] | 485 | * @vport: pointer to a host virtual N_Port data structure. |
| 486 | * @ndlp: pointer to a node-list data structure. |
| 487 | * @sp: pointer to service parameter data structure. |
| 488 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 489 | * |
| 490 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 491 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 492 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 493 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 494 | * @vport against the previously assigned N_Port ID. If it is different from |
| 495 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 496 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 497 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 498 | * is invoked to register login to the fabric. |
| 499 | * |
| 500 | * Return code |
| 501 | * 0 - Success (currently, always return 0) |
| 502 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 503 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 504 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 505 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 506 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 507 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 508 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 509 | struct lpfc_nodelist *np; |
| 510 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 511 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 512 | spin_lock_irq(shost->host_lock); |
| 513 | vport->fc_flag |= FC_FABRIC; |
| 514 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 515 | |
| 516 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 517 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 518 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 519 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 520 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 521 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 522 | |
| 523 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 524 | spin_lock_irq(shost->host_lock); |
| 525 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 526 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 527 | } |
| 528 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 529 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 530 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 531 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 532 | ndlp->nlp_class_sup = 0; |
| 533 | if (sp->cls1.classValid) |
| 534 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 535 | if (sp->cls2.classValid) |
| 536 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 537 | if (sp->cls3.classValid) |
| 538 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 539 | if (sp->cls4.classValid) |
| 540 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 541 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 542 | sp->cmn.bbRcvSizeLsb; |
| 543 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 544 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 545 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 546 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 547 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 548 | LOG_ELS | LOG_VPORT, |
| 549 | "1816 FLOGI NPIV supported, " |
| 550 | "response data 0x%x\n", |
| 551 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 552 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 553 | } else { |
| 554 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 555 | to call reg_vnpid atleast for the physcial host */ |
| 556 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 557 | LOG_ELS | LOG_VPORT, |
| 558 | "1817 Fabric does not support NPIV " |
| 559 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 560 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 565 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 566 | |
| 567 | /* If our NportID changed, we need to ensure all |
| 568 | * remaining NPORTs get unreg_login'ed. |
| 569 | */ |
| 570 | list_for_each_entry_safe(np, next_np, |
| 571 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 572 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 573 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 574 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 575 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 576 | continue; |
| 577 | spin_lock_irq(shost->host_lock); |
| 578 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 579 | spin_unlock_irq(shost->host_lock); |
| 580 | lpfc_unreg_rpi(vport, np); |
| 581 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 582 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 583 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 584 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 585 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 586 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 587 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 588 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 589 | /* |
| 590 | * If VPI is unreged, driver need to do INIT_VPI |
| 591 | * before re-registering |
| 592 | */ |
| 593 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 594 | spin_lock_irq(shost->host_lock); |
| 595 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 596 | spin_unlock_irq(shost->host_lock); |
| 597 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 598 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 599 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 600 | /* |
| 601 | * Driver needs to re-reg VPI in order for f/w |
| 602 | * to update the MAC address. |
| 603 | */ |
| 604 | lpfc_register_new_vport(phba, vport, ndlp); |
| 605 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 606 | } |
| 607 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 608 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 609 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 610 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 611 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 612 | lpfc_register_new_vport(phba, vport, ndlp); |
| 613 | else |
| 614 | lpfc_issue_fabric_reglogin(vport); |
| 615 | } else { |
| 616 | ndlp->nlp_type |= NLP_FABRIC; |
| 617 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 618 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 619 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 620 | lpfc_start_fdiscs(phba); |
| 621 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 622 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 623 | lpfc_issue_init_vpi(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 624 | else |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 625 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 626 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 627 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 628 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 629 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 630 | * 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] | 631 | * @vport: pointer to a host virtual N_Port data structure. |
| 632 | * @ndlp: pointer to a node-list data structure. |
| 633 | * @sp: pointer to service parameter data structure. |
| 634 | * |
| 635 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 636 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 637 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 638 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 639 | * the received N_Port Name lexicographically, this node shall assign local |
| 640 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 641 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 642 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 643 | * N_Port IDs. |
| 644 | * |
| 645 | * Return code |
| 646 | * 0 - Success |
| 647 | * -ENXIO - Fail |
| 648 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 649 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 650 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 651 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 652 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 653 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 654 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 655 | LPFC_MBOXQ_t *mbox; |
| 656 | int rc; |
| 657 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 658 | spin_lock_irq(shost->host_lock); |
| 659 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 660 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 661 | |
| 662 | phba->fc_edtov = FF_DEF_EDTOV; |
| 663 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 664 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 665 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 666 | if (rc >= 0) { |
| 667 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 668 | spin_lock_irq(shost->host_lock); |
| 669 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 670 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 671 | |
| 672 | /* |
| 673 | * N_Port ID cannot be 0, set our to LocalID the other |
| 674 | * side will be RemoteID. |
| 675 | */ |
| 676 | |
| 677 | /* not equal */ |
| 678 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 679 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 680 | |
| 681 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 682 | if (!mbox) |
| 683 | goto fail; |
| 684 | |
| 685 | lpfc_config_link(phba, mbox); |
| 686 | |
| 687 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 688 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 689 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 690 | if (rc == MBX_NOT_FINISHED) { |
| 691 | mempool_free(mbox, phba->mbox_mem_pool); |
| 692 | goto fail; |
| 693 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 694 | /* Decrement ndlp reference count indicating that ndlp can be |
| 695 | * safely released when other references to it are done. |
| 696 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 697 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 698 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 699 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 700 | if (!ndlp) { |
| 701 | /* |
| 702 | * Cannot find existing Fabric ndlp, so allocate a |
| 703 | * new one |
| 704 | */ |
| 705 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 706 | if (!ndlp) |
| 707 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 708 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 709 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 710 | ndlp = lpfc_enable_node(vport, ndlp, |
| 711 | NLP_STE_UNUSED_NODE); |
| 712 | if(!ndlp) |
| 713 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 717 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 718 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 719 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 720 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 721 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 722 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 723 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 724 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 725 | } else |
| 726 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 727 | * count indicating that ndlp can be released when other |
| 728 | * references to it are done. |
| 729 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 730 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 731 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 732 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 733 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 734 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 735 | spin_lock_irq(shost->host_lock); |
| 736 | vport->fc_flag |= FC_PT2PT; |
| 737 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 738 | |
| 739 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 740 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 741 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 742 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 743 | return -ENXIO; |
| 744 | } |
| 745 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 746 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 747 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 748 | * @phba: pointer to lpfc hba data structure. |
| 749 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 750 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 751 | * |
| 752 | * This routine is the top-level completion callback function for issuing |
| 753 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 754 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 755 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 756 | * returning 1), the command IOCB will be released and function returned. |
| 757 | * If the retry attempt has been given up (possibly reach the maximum |
| 758 | * number of retries), one additional decrement of ndlp reference shall be |
| 759 | * invoked before going out after releasing the command IOCB. This will |
| 760 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 761 | * invoke one decrement of ndlp reference count). If no error reported in |
| 762 | * the IOCB status, the command Port ID field is used to determine whether |
| 763 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 764 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 765 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 766 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 767 | * specific topology completion conditions. |
| 768 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 769 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 770 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 771 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 772 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 773 | struct lpfc_vport *vport = cmdiocb->vport; |
| 774 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 775 | IOCB_t *irsp = &rspiocb->iocb; |
| 776 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 777 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 778 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 779 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 780 | int rc; |
| 781 | |
| 782 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 783 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 784 | /* One additional decrement on node reference count to |
| 785 | * trigger the release of the node |
| 786 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 787 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 788 | goto out; |
| 789 | } |
| 790 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 791 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 792 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 793 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 794 | vport->port_state); |
| 795 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 796 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 797 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame^] | 798 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 799 | * due to new FCF discovery |
| 800 | */ |
| 801 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 802 | (phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 803 | (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) && |
| 804 | (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 805 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame^] | 806 | "2611 FLOGI failed on FCF (x%x), " |
| 807 | "status:x%x/x%x, tmo:x%x, perform " |
| 808 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 809 | phba->fcf.current_rec.fcf_indx, |
| 810 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 811 | irsp->ulpTimeout); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 812 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame^] | 813 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 814 | if (rc) |
| 815 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 816 | } |
| 817 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 818 | /* FLOGI failure */ |
| 819 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 820 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 821 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 822 | irsp->ulpTimeout); |
| 823 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 824 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 825 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 826 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 827 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 828 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 829 | spin_lock_irq(shost->host_lock); |
| 830 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 831 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 832 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 833 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 834 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 835 | * alpa map would take too long otherwise. |
| 836 | */ |
| 837 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 838 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | /* FLOGI failure */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 842 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 843 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 844 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 845 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 846 | goto flogifail; |
| 847 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 848 | spin_lock_irq(shost->host_lock); |
| 849 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 850 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 851 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 852 | |
| 853 | /* |
| 854 | * The FLogI succeeded. Sync the data for the CPU before |
| 855 | * accessing it. |
| 856 | */ |
| 857 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 858 | |
| 859 | sp = prsp->virt + sizeof(uint32_t); |
| 860 | |
| 861 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 862 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 863 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 864 | "Data: x%x x%x x%x x%x\n", |
| 865 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 866 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 867 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 868 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 869 | /* |
| 870 | * If Common Service Parameters indicate Nport |
| 871 | * we are point to point, if Fport we are Fabric. |
| 872 | */ |
| 873 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 874 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 875 | else if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 876 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 877 | else { |
| 878 | lpfc_printf_vlog(vport, KERN_ERR, |
| 879 | LOG_FIP | LOG_ELS, |
| 880 | "2831 FLOGI response with cleared Fabric " |
| 881 | "bit fcf_index 0x%x " |
| 882 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 883 | "Fabric Name " |
| 884 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 885 | phba->fcf.current_rec.fcf_indx, |
| 886 | phba->fcf.current_rec.switch_name[0], |
| 887 | phba->fcf.current_rec.switch_name[1], |
| 888 | phba->fcf.current_rec.switch_name[2], |
| 889 | phba->fcf.current_rec.switch_name[3], |
| 890 | phba->fcf.current_rec.switch_name[4], |
| 891 | phba->fcf.current_rec.switch_name[5], |
| 892 | phba->fcf.current_rec.switch_name[6], |
| 893 | phba->fcf.current_rec.switch_name[7], |
| 894 | phba->fcf.current_rec.fabric_name[0], |
| 895 | phba->fcf.current_rec.fabric_name[1], |
| 896 | phba->fcf.current_rec.fabric_name[2], |
| 897 | phba->fcf.current_rec.fabric_name[3], |
| 898 | phba->fcf.current_rec.fabric_name[4], |
| 899 | phba->fcf.current_rec.fabric_name[5], |
| 900 | phba->fcf.current_rec.fabric_name[6], |
| 901 | phba->fcf.current_rec.fabric_name[7]); |
| 902 | lpfc_nlp_put(ndlp); |
| 903 | spin_lock_irq(&phba->hbalock); |
| 904 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame^] | 905 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 906 | spin_unlock_irq(&phba->hbalock); |
| 907 | goto out; |
| 908 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 909 | if (!rc) { |
| 910 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 911 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 912 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 913 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame^] | 914 | "2769 FLOGI to FCF (x%x) " |
| 915 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 916 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 917 | spin_lock_irq(&phba->hbalock); |
| 918 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame^] | 919 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 920 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 921 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 922 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 926 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 927 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 928 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 929 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 930 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 931 | |
| 932 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 933 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 934 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 935 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 936 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 937 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 938 | /* If FLOGI failed enable link interrupt. */ |
| 939 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 940 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 941 | out: |
| 942 | lpfc_els_free_iocb(phba, cmdiocb); |
| 943 | } |
| 944 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 945 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 946 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 947 | * @vport: pointer to a host virtual N_Port data structure. |
| 948 | * @ndlp: pointer to a node-list data structure. |
| 949 | * @retry: number of retries to the command IOCB. |
| 950 | * |
| 951 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 952 | * for a @vport. The initiator service parameters are put into the payload |
| 953 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 954 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 955 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 956 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 957 | * |
| 958 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 959 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 960 | * will be stored into the context1 field of the IOCB for the completion |
| 961 | * callback function to the FLOGI ELS command. |
| 962 | * |
| 963 | * Return code |
| 964 | * 0 - successfully issued flogi iocb for @vport |
| 965 | * 1 - failed to issue flogi iocb for @vport |
| 966 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 967 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 968 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 969 | uint8_t retry) |
| 970 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 971 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 972 | struct serv_parm *sp; |
| 973 | IOCB_t *icmd; |
| 974 | struct lpfc_iocbq *elsiocb; |
| 975 | struct lpfc_sli_ring *pring; |
| 976 | uint8_t *pcmd; |
| 977 | uint16_t cmdsize; |
| 978 | uint32_t tmo; |
| 979 | int rc; |
| 980 | |
| 981 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 982 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 983 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 984 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 985 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 986 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 987 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 988 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 989 | |
| 990 | icmd = &elsiocb->iocb; |
| 991 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 992 | |
| 993 | /* For FLOGI request, remainder of payload is service parameters */ |
| 994 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 995 | pcmd += sizeof(uint32_t); |
| 996 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 997 | sp = (struct serv_parm *) pcmd; |
| 998 | |
| 999 | /* Setup CSPs accordingly for Fabric */ |
| 1000 | sp->cmn.e_d_tov = 0; |
| 1001 | sp->cmn.w2.r_a_tov = 0; |
| 1002 | sp->cls1.classValid = 0; |
| 1003 | sp->cls2.seqDelivery = 1; |
| 1004 | sp->cls3.seqDelivery = 1; |
| 1005 | if (sp->cmn.fcphLow < FC_PH3) |
| 1006 | sp->cmn.fcphLow = FC_PH3; |
| 1007 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1008 | sp->cmn.fcphHigh = FC_PH3; |
| 1009 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1010 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1011 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1012 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1013 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1014 | /* Set the fcfi to the fcfi we registered with */ |
| 1015 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1016 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1017 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1018 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1019 | icmd->ulpCt_h = 1; |
| 1020 | icmd->ulpCt_l = 0; |
| 1021 | } |
| 1022 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1023 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 1024 | icmd->un.elsreq64.myID = 0; |
| 1025 | icmd->un.elsreq64.fl = 1; |
| 1026 | } |
| 1027 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1028 | tmo = phba->fc_ratov; |
| 1029 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1030 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1031 | phba->fc_ratov = tmo; |
| 1032 | |
| 1033 | phba->fc_stat.elsXmitFLOGI++; |
| 1034 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1035 | |
| 1036 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1037 | "Issue FLOGI: opt:x%x", |
| 1038 | phba->sli3_options, 0, 0); |
| 1039 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1040 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1041 | if (rc == IOCB_ERROR) { |
| 1042 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1043 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1044 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1045 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1046 | } |
| 1047 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1048 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1049 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1050 | * @phba: pointer to lpfc hba data structure. |
| 1051 | * |
| 1052 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1053 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1054 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1055 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1056 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1057 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1058 | * |
| 1059 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1060 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1061 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1062 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1063 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1064 | { |
| 1065 | struct lpfc_sli_ring *pring; |
| 1066 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1067 | struct lpfc_nodelist *ndlp; |
| 1068 | IOCB_t *icmd; |
| 1069 | |
| 1070 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1071 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1072 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1073 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1074 | |
| 1075 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1076 | |
| 1077 | /* |
| 1078 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1079 | * searching for. |
| 1080 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1081 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1082 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1083 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1084 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 1085 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1086 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1087 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1088 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1089 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1090 | } |
| 1091 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1092 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1093 | |
| 1094 | return 0; |
| 1095 | } |
| 1096 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1097 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1098 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1099 | * @vport: pointer to a host virtual N_Port data structure. |
| 1100 | * |
| 1101 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1102 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1103 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1104 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1105 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1106 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1107 | * @vport. |
| 1108 | * |
| 1109 | * Return code |
| 1110 | * 0 - failed to issue initial flogi for @vport |
| 1111 | * 1 - successfully issued initial flogi for @vport |
| 1112 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1113 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1114 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1115 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1116 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1117 | struct lpfc_nodelist *ndlp; |
| 1118 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1119 | vport->port_state = LPFC_FLOGI; |
| 1120 | lpfc_set_disctmo(vport); |
| 1121 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1122 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1123 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1124 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1125 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1126 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1127 | if (!ndlp) |
| 1128 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1129 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1130 | /* Set the node type */ |
| 1131 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1132 | /* Put ndlp onto node list */ |
| 1133 | lpfc_enqueue_node(vport, ndlp); |
| 1134 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1135 | /* re-setup ndlp without removing from node list */ |
| 1136 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1137 | if (!ndlp) |
| 1138 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1139 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1140 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1141 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1142 | /* This decrement of reference count to node shall kick off |
| 1143 | * the release of the node. |
| 1144 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1145 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1146 | return 0; |
| 1147 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1148 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1149 | } |
| 1150 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1151 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1152 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1153 | * @vport: pointer to a host virtual N_Port data structure. |
| 1154 | * |
| 1155 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1156 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1157 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1158 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1159 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1160 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1161 | * @vport. |
| 1162 | * |
| 1163 | * Return code |
| 1164 | * 0 - failed to issue initial fdisc for @vport |
| 1165 | * 1 - successfully issued initial fdisc for @vport |
| 1166 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1167 | int |
| 1168 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1169 | { |
| 1170 | struct lpfc_hba *phba = vport->phba; |
| 1171 | struct lpfc_nodelist *ndlp; |
| 1172 | |
| 1173 | /* First look for the Fabric ndlp */ |
| 1174 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1175 | if (!ndlp) { |
| 1176 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1177 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1178 | if (!ndlp) |
| 1179 | return 0; |
| 1180 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1181 | /* Put ndlp onto node list */ |
| 1182 | lpfc_enqueue_node(vport, ndlp); |
| 1183 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1184 | /* re-setup ndlp without removing from node list */ |
| 1185 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1186 | if (!ndlp) |
| 1187 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1188 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1189 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1190 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1191 | /* decrement node reference count to trigger the release of |
| 1192 | * the node. |
| 1193 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1194 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1195 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1196 | } |
| 1197 | return 1; |
| 1198 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1199 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1200 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1201 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1202 | * @vport: pointer to a host virtual N_Port data structure. |
| 1203 | * |
| 1204 | * This routine checks whether there are more remaining Port Logins |
| 1205 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1206 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1207 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1208 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1209 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1210 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1211 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1212 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1213 | { |
| 1214 | int sentplogi; |
| 1215 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1216 | if (vport->num_disc_nodes) |
| 1217 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1218 | |
| 1219 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1220 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1221 | "0232 Continue discovery with %d PLOGIs to go " |
| 1222 | "Data: x%x x%x x%x\n", |
| 1223 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1224 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1225 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1226 | if (vport->fc_flag & FC_NLP_MORE) |
| 1227 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1228 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1229 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1230 | return; |
| 1231 | } |
| 1232 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1233 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1234 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1235 | * @phba: pointer to lpfc hba data structure. |
| 1236 | * @prsp: pointer to response IOCB payload. |
| 1237 | * @ndlp: pointer to a node-list data structure. |
| 1238 | * |
| 1239 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1240 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1241 | * The following cases are considered N_Port confirmed: |
| 1242 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1243 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1244 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1245 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1246 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1247 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1248 | * on that node to release the RPI associated with the node; 2) if there is |
| 1249 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1250 | * into, a new node shall be allocated (or activated). In either case, the |
| 1251 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1252 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1253 | * its pointer returned as the confirmed node. |
| 1254 | * |
| 1255 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1256 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1257 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1258 | * into an inactive state on the vport node list and the vport node list |
| 1259 | * management algorithm does not allow two node with a same DID. |
| 1260 | * |
| 1261 | * Return code |
| 1262 | * pointer to the PLOGI N_Port @ndlp |
| 1263 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1264 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1265 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1266 | struct lpfc_nodelist *ndlp) |
| 1267 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1268 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1269 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1270 | struct lpfc_rport_data *rdata; |
| 1271 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1272 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1273 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1274 | uint32_t rc, keepDID = 0; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1275 | int put_node; |
| 1276 | int put_rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1277 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1278 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1279 | * by WWPN. Just return the ndlp that was given to us. |
| 1280 | */ |
| 1281 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1282 | return ndlp; |
| 1283 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1284 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1285 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1286 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1287 | /* 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] | 1288 | * we have for that ndlp. If not, we have some work to do. |
| 1289 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1290 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1291 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1292 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1293 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1294 | |
| 1295 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1296 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1297 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1298 | if (!rc) |
| 1299 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1300 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1301 | if (!new_ndlp) |
| 1302 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1303 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1304 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1305 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1306 | sizeof(struct lpfc_name)); |
| 1307 | if (!rc) |
| 1308 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1309 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1310 | NLP_STE_UNUSED_NODE); |
| 1311 | if (!new_ndlp) |
| 1312 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1313 | keepDID = new_ndlp->nlp_DID; |
| 1314 | } else |
| 1315 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1316 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1317 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1318 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1319 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1320 | |
| 1321 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1322 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1323 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1324 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1325 | /* 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] | 1326 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1327 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1328 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1329 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1330 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1331 | * to put ndlp on UNUSED list and try to free it. |
| 1332 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1333 | |
| 1334 | /* Fix up the rport accordingly */ |
| 1335 | rport = ndlp->rport; |
| 1336 | if (rport) { |
| 1337 | rdata = rport->dd_data; |
| 1338 | if (rdata->pnode == ndlp) { |
| 1339 | lpfc_nlp_put(ndlp); |
| 1340 | ndlp->rport = NULL; |
| 1341 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1342 | new_ndlp->rport = rport; |
| 1343 | } |
| 1344 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1345 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1346 | /* We shall actually free the ndlp with both nlp_DID and |
| 1347 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1348 | * nodelist never to be used. |
| 1349 | */ |
| 1350 | if (ndlp->nlp_DID == 0) { |
| 1351 | spin_lock_irq(&phba->ndlp_lock); |
| 1352 | NLP_SET_FREE_REQ(ndlp); |
| 1353 | spin_unlock_irq(&phba->ndlp_lock); |
| 1354 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1355 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1356 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1357 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1358 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1359 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1360 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1361 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1362 | /* Two ndlps cannot have the same did */ |
| 1363 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1364 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1365 | /* Since we are swapping the ndlp passed in with the new one |
| 1366 | * and the did has already been swapped, copy over the |
| 1367 | * state and names. |
| 1368 | */ |
| 1369 | memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname, |
| 1370 | sizeof(struct lpfc_name)); |
| 1371 | memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename, |
| 1372 | sizeof(struct lpfc_name)); |
| 1373 | new_ndlp->nlp_state = ndlp->nlp_state; |
| 1374 | /* Fix up the rport accordingly */ |
| 1375 | rport = ndlp->rport; |
| 1376 | if (rport) { |
| 1377 | rdata = rport->dd_data; |
| 1378 | put_node = rdata->pnode != NULL; |
| 1379 | put_rport = ndlp->rport != NULL; |
| 1380 | rdata->pnode = NULL; |
| 1381 | ndlp->rport = NULL; |
| 1382 | if (put_node) |
| 1383 | lpfc_nlp_put(ndlp); |
| 1384 | if (put_rport) |
| 1385 | put_device(&rport->dev); |
| 1386 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1387 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1388 | return new_ndlp; |
| 1389 | } |
| 1390 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1391 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1392 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1393 | * @vport: pointer to a host virtual N_Port data structure. |
| 1394 | * |
| 1395 | * This routine checks whether more Registration State Change |
| 1396 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1397 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1398 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1399 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1400 | * handling the RSCNs. |
| 1401 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1402 | void |
| 1403 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1404 | { |
| 1405 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1406 | |
| 1407 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1408 | /* |
| 1409 | * Check to see if more RSCNs came in while we were |
| 1410 | * processing this one. |
| 1411 | */ |
| 1412 | if (vport->fc_rscn_id_cnt || |
| 1413 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1414 | lpfc_els_handle_rscn(vport); |
| 1415 | else { |
| 1416 | spin_lock_irq(shost->host_lock); |
| 1417 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1418 | spin_unlock_irq(shost->host_lock); |
| 1419 | } |
| 1420 | } |
| 1421 | } |
| 1422 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1423 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1424 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1425 | * @phba: pointer to lpfc hba data structure. |
| 1426 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1427 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1428 | * |
| 1429 | * This routine is the completion callback function for issuing the Port |
| 1430 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1431 | * ndlp on the vport node list that matches the remote node ID from the |
| 1432 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1433 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1434 | * checked for error conditons. If there is error status reported, PLOGI |
| 1435 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1436 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1437 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1438 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1439 | * there are additional N_Port nodes with the vport that need to perform |
| 1440 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1441 | * PLOGIs. |
| 1442 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1443 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1444 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1445 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1446 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1447 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1448 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1449 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1450 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1451 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1452 | int disc, rc, did, type; |
| 1453 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1454 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1455 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1456 | |
| 1457 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1458 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1459 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1460 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1461 | irsp->un.elsreq64.remoteID); |
| 1462 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1463 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1464 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1465 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1466 | "0136 PLOGI completes to NPort x%x " |
| 1467 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1468 | irsp->un.elsreq64.remoteID, |
| 1469 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1470 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1471 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1472 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1473 | |
| 1474 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1475 | * is being used during discovery. |
| 1476 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1477 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1478 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1479 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1480 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1481 | rc = 0; |
| 1482 | |
| 1483 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1484 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1485 | "0102 PLOGI completes to NPort x%x " |
| 1486 | "Data: x%x x%x x%x x%x x%x\n", |
| 1487 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1488 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1489 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1490 | if (lpfc_els_chk_latt(vport)) { |
| 1491 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1492 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1493 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1494 | goto out; |
| 1495 | } |
| 1496 | |
| 1497 | /* ndlp could be freed in DSM, save these values now */ |
| 1498 | type = ndlp->nlp_type; |
| 1499 | did = ndlp->nlp_DID; |
| 1500 | |
| 1501 | if (irsp->ulpStatus) { |
| 1502 | /* Check for retry */ |
| 1503 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1504 | /* ELS command is being retried */ |
| 1505 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1506 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1507 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1508 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1509 | } |
| 1510 | goto out; |
| 1511 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1512 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1513 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1514 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1515 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1516 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1517 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1518 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1519 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1520 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1521 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1522 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1523 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1524 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1525 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1526 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1527 | } else { |
| 1528 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1529 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1530 | cmdiocb->context2)->list.next, |
| 1531 | struct lpfc_dmabuf, list); |
| 1532 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1533 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1534 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1535 | } |
| 1536 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1537 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1538 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1539 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1540 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1541 | if (vport->num_disc_nodes == 0) { |
| 1542 | spin_lock_irq(shost->host_lock); |
| 1543 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1544 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1545 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1546 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1547 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | out: |
| 1552 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1553 | return; |
| 1554 | } |
| 1555 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1556 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1557 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1558 | * @vport: pointer to a host virtual N_Port data structure. |
| 1559 | * @did: destination port identifier. |
| 1560 | * @retry: number of retries to the command IOCB. |
| 1561 | * |
| 1562 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1563 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1564 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1565 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1566 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1567 | * |
| 1568 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1569 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1570 | * will be stored into the context1 field of the IOCB for the completion |
| 1571 | * callback function to the PLOGI ELS command. |
| 1572 | * |
| 1573 | * Return code |
| 1574 | * 0 - Successfully issued a plogi for @vport |
| 1575 | * 1 - failed to issue a plogi for @vport |
| 1576 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1577 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1578 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1579 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1580 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1581 | struct serv_parm *sp; |
| 1582 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1583 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1584 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1585 | struct lpfc_sli *psli; |
| 1586 | uint8_t *pcmd; |
| 1587 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1588 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1589 | |
| 1590 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1591 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1592 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1593 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1594 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1595 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1596 | /* 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] | 1597 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1598 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1599 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1600 | if (!elsiocb) |
| 1601 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1602 | |
| 1603 | icmd = &elsiocb->iocb; |
| 1604 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1605 | |
| 1606 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1607 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1608 | pcmd += sizeof(uint32_t); |
| 1609 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1610 | sp = (struct serv_parm *) pcmd; |
| 1611 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1612 | /* |
| 1613 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 1614 | * to device on remote loops work. |
| 1615 | */ |
| 1616 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 1617 | sp->cmn.altBbCredit = 1; |
| 1618 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1619 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1620 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1621 | |
| 1622 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1623 | sp->cmn.fcphHigh = FC_PH3; |
| 1624 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1625 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1626 | "Issue PLOGI: did:x%x", |
| 1627 | did, 0, 0); |
| 1628 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1629 | phba->fc_stat.elsXmitPLOGI++; |
| 1630 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1631 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1632 | |
| 1633 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1634 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1635 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1636 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1637 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1638 | } |
| 1639 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1640 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1641 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1642 | * @phba: pointer to lpfc hba data structure. |
| 1643 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1644 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1645 | * |
| 1646 | * This routine is the completion callback function for a Process Login |
| 1647 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1648 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1649 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1650 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1651 | * ndlp to mark the PRLI completion. |
| 1652 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1653 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1654 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1655 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1656 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1657 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1658 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1659 | IOCB_t *irsp; |
| 1660 | struct lpfc_sli *psli; |
| 1661 | struct lpfc_nodelist *ndlp; |
| 1662 | |
| 1663 | psli = &phba->sli; |
| 1664 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1665 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1666 | |
| 1667 | irsp = &(rspiocb->iocb); |
| 1668 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1669 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1670 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1671 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1672 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1673 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1674 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1675 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1676 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1677 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1678 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1679 | "0103 PRLI completes to NPort x%x " |
| 1680 | "Data: x%x x%x x%x x%x\n", |
| 1681 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1682 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1683 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1684 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1685 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1686 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | goto out; |
| 1688 | |
| 1689 | if (irsp->ulpStatus) { |
| 1690 | /* Check for retry */ |
| 1691 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1692 | /* ELS command is being retried */ |
| 1693 | goto out; |
| 1694 | } |
| 1695 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1696 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1697 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 1698 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1699 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1700 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1701 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1702 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1703 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1704 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1705 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1706 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1707 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1708 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1709 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1710 | out: |
| 1711 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1712 | return; |
| 1713 | } |
| 1714 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1715 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1716 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1717 | * @vport: pointer to a host virtual N_Port data structure. |
| 1718 | * @ndlp: pointer to a node-list data structure. |
| 1719 | * @retry: number of retries to the command IOCB. |
| 1720 | * |
| 1721 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1722 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1723 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1724 | * is put to the IOCB completion callback func field before invoking the |
| 1725 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1726 | * |
| 1727 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1728 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1729 | * will be stored into the context1 field of the IOCB for the completion |
| 1730 | * callback function to the PRLI ELS command. |
| 1731 | * |
| 1732 | * Return code |
| 1733 | * 0 - successfully issued prli iocb command for @vport |
| 1734 | * 1 - failed to issue prli iocb command for @vport |
| 1735 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1736 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1737 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1738 | uint8_t retry) |
| 1739 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1740 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1741 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1742 | PRLI *npr; |
| 1743 | IOCB_t *icmd; |
| 1744 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1745 | uint8_t *pcmd; |
| 1746 | uint16_t cmdsize; |
| 1747 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1748 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1749 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1750 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1751 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1752 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1753 | |
| 1754 | icmd = &elsiocb->iocb; |
| 1755 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1756 | |
| 1757 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1758 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1759 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1760 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1761 | |
| 1762 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1763 | npr = (PRLI *) pcmd; |
| 1764 | /* |
| 1765 | * If our firmware version is 3.20 or later, |
| 1766 | * set the following bits for FC-TAPE support. |
| 1767 | */ |
| 1768 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1769 | npr->ConfmComplAllowed = 1; |
| 1770 | npr->Retry = 1; |
| 1771 | npr->TaskRetryIdReq = 1; |
| 1772 | } |
| 1773 | npr->estabImagePair = 1; |
| 1774 | npr->readXferRdyDis = 1; |
| 1775 | |
| 1776 | /* For FCP support */ |
| 1777 | npr->prliType = PRLI_FCP_TYPE; |
| 1778 | npr->initiatorFunc = 1; |
| 1779 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1780 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1781 | "Issue PRLI: did:x%x", |
| 1782 | ndlp->nlp_DID, 0, 0); |
| 1783 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1784 | phba->fc_stat.elsXmitPRLI++; |
| 1785 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1786 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1787 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1788 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1789 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1790 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1791 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1792 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1793 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1794 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1795 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1796 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1797 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1798 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1799 | } |
| 1800 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1801 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1802 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1803 | * @vport: pointer to a host virtual N_Port data structure. |
| 1804 | * |
| 1805 | * This routine performs Registration State Change Notification (RSCN) |
| 1806 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1807 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1808 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1809 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1810 | * invoked to check and handle possible more RSCN came in during the period |
| 1811 | * of processing the current ones. |
| 1812 | **/ |
| 1813 | static void |
| 1814 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1815 | { |
| 1816 | lpfc_can_disctmo(vport); |
| 1817 | |
| 1818 | /* RSCN discovery */ |
| 1819 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1820 | if (vport->fc_npr_cnt) |
| 1821 | if (lpfc_els_disc_plogi(vport)) |
| 1822 | return; |
| 1823 | |
| 1824 | lpfc_end_rscn(vport); |
| 1825 | } |
| 1826 | |
| 1827 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1828 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1829 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1830 | * |
| 1831 | * This function is called when the final ADISC is completed during discovery. |
| 1832 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1833 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1834 | * discovery. |
| 1835 | * This function is called with no locks held. |
| 1836 | **/ |
| 1837 | static void |
| 1838 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1839 | { |
| 1840 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1841 | struct lpfc_hba *phba = vport->phba; |
| 1842 | |
| 1843 | /* |
| 1844 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1845 | * and continue discovery. |
| 1846 | */ |
| 1847 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1848 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1849 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1850 | lpfc_issue_reg_vpi(phba, vport); |
| 1851 | return; |
| 1852 | } |
| 1853 | /* |
| 1854 | * For SLI2, we need to set port_state to READY |
| 1855 | * and continue discovery. |
| 1856 | */ |
| 1857 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1858 | /* If we get here, there is nothing to ADISC */ |
| 1859 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1860 | lpfc_issue_clear_la(phba, vport); |
| 1861 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1862 | vport->num_disc_nodes = 0; |
| 1863 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1864 | if (vport->fc_npr_cnt) |
| 1865 | lpfc_els_disc_plogi(vport); |
| 1866 | if (!vport->num_disc_nodes) { |
| 1867 | spin_lock_irq(shost->host_lock); |
| 1868 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1869 | spin_unlock_irq(shost->host_lock); |
| 1870 | lpfc_can_disctmo(vport); |
| 1871 | lpfc_end_rscn(vport); |
| 1872 | } |
| 1873 | } |
| 1874 | vport->port_state = LPFC_VPORT_READY; |
| 1875 | } else |
| 1876 | lpfc_rscn_disc(vport); |
| 1877 | } |
| 1878 | |
| 1879 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1880 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1881 | * @vport: pointer to a host virtual N_Port data structure. |
| 1882 | * |
| 1883 | * This routine determines whether there are more ndlps on a @vport |
| 1884 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1885 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1886 | * remaining nodes which need to have ADISC sent. |
| 1887 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1888 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1889 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1890 | { |
| 1891 | int sentadisc; |
| 1892 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1893 | if (vport->num_disc_nodes) |
| 1894 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1895 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1896 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1897 | "0210 Continue discovery with %d ADISCs to go " |
| 1898 | "Data: x%x x%x x%x\n", |
| 1899 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1900 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1901 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1902 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1903 | lpfc_set_disctmo(vport); |
| 1904 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1905 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1906 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1907 | if (!vport->num_disc_nodes) |
| 1908 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1909 | return; |
| 1910 | } |
| 1911 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1912 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1913 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1914 | * @phba: pointer to lpfc hba data structure. |
| 1915 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1916 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1917 | * |
| 1918 | * This routine is the completion function for issuing the Address Discover |
| 1919 | * (ADISC) command. It first checks to see whether link went down during |
| 1920 | * the discovery process. If so, the node will be marked as node port |
| 1921 | * recovery for issuing discover IOCB by the link attention handler and |
| 1922 | * exit. Otherwise, the response status is checked. If error was reported |
| 1923 | * in the response status, the ADISC command shall be retried by invoking |
| 1924 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1925 | * the response status, the state machine is invoked to set transition |
| 1926 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1927 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1928 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1929 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1930 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1932 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1933 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1934 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1935 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1936 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1937 | |
| 1938 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1939 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1940 | |
| 1941 | irsp = &(rspiocb->iocb); |
| 1942 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1943 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1944 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1945 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1946 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1947 | ndlp->nlp_DID); |
| 1948 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1949 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1950 | * is being used during discovery. |
| 1951 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1952 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1953 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1954 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1955 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1956 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1957 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1958 | "0104 ADISC completes to NPort x%x " |
| 1959 | "Data: x%x x%x x%x x%x x%x\n", |
| 1960 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1961 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1962 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1963 | if (lpfc_els_chk_latt(vport)) { |
| 1964 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1965 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1966 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1967 | goto out; |
| 1968 | } |
| 1969 | |
| 1970 | if (irsp->ulpStatus) { |
| 1971 | /* Check for retry */ |
| 1972 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1973 | /* ELS command is being retried */ |
| 1974 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1975 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1976 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1977 | spin_unlock_irq(shost->host_lock); |
| 1978 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1979 | } |
| 1980 | goto out; |
| 1981 | } |
| 1982 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1983 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1984 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 1985 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1986 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1987 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1988 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1989 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1990 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1991 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1992 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1993 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1995 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1996 | /* Check to see if there are more ADISCs to be sent */ |
| 1997 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1998 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | out: |
| 2000 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2001 | return; |
| 2002 | } |
| 2003 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2004 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2005 | * 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] | 2006 | * @vport: pointer to a virtual N_Port data structure. |
| 2007 | * @ndlp: pointer to a node-list data structure. |
| 2008 | * @retry: number of retries to the command IOCB. |
| 2009 | * |
| 2010 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2011 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2012 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2013 | * to issue the ADISC ELS command. |
| 2014 | * |
| 2015 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2016 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2017 | * will be stored into the context1 field of the IOCB for the completion |
| 2018 | * callback function to the ADISC ELS command. |
| 2019 | * |
| 2020 | * Return code |
| 2021 | * 0 - successfully issued adisc |
| 2022 | * 1 - failed to issue adisc |
| 2023 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2024 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2025 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2026 | uint8_t retry) |
| 2027 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2028 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2029 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2030 | ADISC *ap; |
| 2031 | IOCB_t *icmd; |
| 2032 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2033 | uint8_t *pcmd; |
| 2034 | uint16_t cmdsize; |
| 2035 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2036 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2037 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2038 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2039 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2040 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2041 | |
| 2042 | icmd = &elsiocb->iocb; |
| 2043 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2044 | |
| 2045 | /* For ADISC request, remainder of payload is service parameters */ |
| 2046 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2047 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2048 | |
| 2049 | /* Fill in ADISC payload */ |
| 2050 | ap = (ADISC *) pcmd; |
| 2051 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2052 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2053 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2054 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2055 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2056 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2057 | "Issue ADISC: did:x%x", |
| 2058 | ndlp->nlp_DID, 0, 0); |
| 2059 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2060 | phba->fc_stat.elsXmitADISC++; |
| 2061 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2062 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2064 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2065 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2066 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2067 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2068 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2069 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2070 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2071 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2072 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2073 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2074 | } |
| 2075 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2076 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2077 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2078 | * @phba: pointer to lpfc hba data structure. |
| 2079 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2080 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2081 | * |
| 2082 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2083 | * command. If no error status was reported from the LOGO response, the |
| 2084 | * state machine of the associated ndlp shall be invoked for transition with |
| 2085 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2086 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2087 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2088 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2089 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2090 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2091 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2092 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2093 | struct lpfc_vport *vport = ndlp->vport; |
| 2094 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | IOCB_t *irsp; |
| 2096 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2097 | |
| 2098 | psli = &phba->sli; |
| 2099 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2100 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2101 | |
| 2102 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2103 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2105 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2107 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2108 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2109 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2110 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2111 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2112 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2113 | "0105 LOGO completes to NPort x%x " |
| 2114 | "Data: x%x x%x x%x x%x\n", |
| 2115 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2116 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2117 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2118 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | goto out; |
| 2120 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2121 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2122 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2123 | * which should abort all outstanding IOs. |
| 2124 | */ |
| 2125 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2126 | NLP_EVT_DEVICE_RM); |
| 2127 | goto out; |
| 2128 | } |
| 2129 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2130 | if (irsp->ulpStatus) { |
| 2131 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2132 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | /* ELS command is being retried */ |
| 2134 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2136 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2137 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2138 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2139 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2140 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2141 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2142 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2143 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2144 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2145 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2146 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2147 | /* Good status, call state machine. |
| 2148 | * This will unregister the rpi if needed. |
| 2149 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2150 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2151 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2152 | out: |
| 2153 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2154 | return; |
| 2155 | } |
| 2156 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2157 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2158 | * 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] | 2159 | * @vport: pointer to a virtual N_Port data structure. |
| 2160 | * @ndlp: pointer to a node-list data structure. |
| 2161 | * @retry: number of retries to the command IOCB. |
| 2162 | * |
| 2163 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2164 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2165 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2166 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2167 | * |
| 2168 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2169 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2170 | * will be stored into the context1 field of the IOCB for the completion |
| 2171 | * callback function to the LOGO ELS command. |
| 2172 | * |
| 2173 | * Return code |
| 2174 | * 0 - successfully issued logo |
| 2175 | * 1 - failed to issue logo |
| 2176 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2177 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2178 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2179 | uint8_t retry) |
| 2180 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2181 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2182 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2183 | IOCB_t *icmd; |
| 2184 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2185 | uint8_t *pcmd; |
| 2186 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2187 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2188 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2189 | spin_lock_irq(shost->host_lock); |
| 2190 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2191 | spin_unlock_irq(shost->host_lock); |
| 2192 | return 0; |
| 2193 | } |
| 2194 | spin_unlock_irq(shost->host_lock); |
| 2195 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2196 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2197 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2198 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2199 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2200 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2201 | |
| 2202 | icmd = &elsiocb->iocb; |
| 2203 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2204 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2205 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2206 | |
| 2207 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2208 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2209 | pcmd += sizeof(uint32_t); |
| 2210 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2211 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2212 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2213 | "Issue LOGO: did:x%x", |
| 2214 | ndlp->nlp_DID, 0, 0); |
| 2215 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | phba->fc_stat.elsXmitLOGO++; |
| 2217 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2218 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2219 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2220 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2221 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2222 | |
| 2223 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2224 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2225 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2226 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2227 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2228 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2229 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2230 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | } |
| 2232 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2233 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2234 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2235 | * @phba: pointer to lpfc hba data structure. |
| 2236 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2237 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2238 | * |
| 2239 | * This routine is a generic completion callback function for ELS commands. |
| 2240 | * Specifically, it is the callback function which does not need to perform |
| 2241 | * any command specific operations. It is currently used by the ELS command |
| 2242 | * issuing routines for the ELS State Change Request (SCR), |
| 2243 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2244 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2245 | * certain debug loggings, this callback function simply invokes the |
| 2246 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2247 | * discovery process. |
| 2248 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2249 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2250 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2251 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2253 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2254 | IOCB_t *irsp; |
| 2255 | |
| 2256 | irsp = &rspiocb->iocb; |
| 2257 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2258 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2259 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2260 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2261 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2262 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2263 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2264 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2265 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2266 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2267 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2268 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2269 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2270 | return; |
| 2271 | } |
| 2272 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2273 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2274 | * 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] | 2275 | * @vport: pointer to a host virtual N_Port data structure. |
| 2276 | * @nportid: N_Port identifier to the remote node. |
| 2277 | * @retry: number of retries to the command IOCB. |
| 2278 | * |
| 2279 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2280 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2281 | * first search the @vport node list to find the matching ndlp. If no such |
| 2282 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2283 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2284 | * routine is invoked to send the SCR IOCB. |
| 2285 | * |
| 2286 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2287 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2288 | * will be stored into the context1 field of the IOCB for the completion |
| 2289 | * callback function to the SCR ELS command. |
| 2290 | * |
| 2291 | * Return code |
| 2292 | * 0 - Successfully issued scr command |
| 2293 | * 1 - Failed to issue scr command |
| 2294 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2295 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2296 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2297 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2298 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2299 | IOCB_t *icmd; |
| 2300 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2301 | struct lpfc_sli *psli; |
| 2302 | uint8_t *pcmd; |
| 2303 | uint16_t cmdsize; |
| 2304 | struct lpfc_nodelist *ndlp; |
| 2305 | |
| 2306 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2307 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2309 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2310 | if (!ndlp) { |
| 2311 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2312 | if (!ndlp) |
| 2313 | return 1; |
| 2314 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2315 | lpfc_enqueue_node(vport, ndlp); |
| 2316 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2317 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2318 | if (!ndlp) |
| 2319 | return 1; |
| 2320 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2321 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2322 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2323 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2324 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2325 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2326 | /* This will trigger the release of the node just |
| 2327 | * allocated |
| 2328 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2329 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2330 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | icmd = &elsiocb->iocb; |
| 2334 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2335 | |
| 2336 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2337 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2338 | |
| 2339 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2340 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2341 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2342 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2343 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2344 | "Issue SCR: did:x%x", |
| 2345 | ndlp->nlp_DID, 0, 0); |
| 2346 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2347 | phba->fc_stat.elsXmitSCR++; |
| 2348 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2349 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2350 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2351 | /* The additional lpfc_nlp_put will cause the following |
| 2352 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2353 | * the node. |
| 2354 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2355 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2356 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2357 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2358 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2359 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2360 | * trigger the release of node. |
| 2361 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2362 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2363 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2364 | } |
| 2365 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2366 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2367 | * 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] | 2368 | * @vport: pointer to a host virtual N_Port data structure. |
| 2369 | * @nportid: N_Port identifier to the remote node. |
| 2370 | * @retry: number of retries to the command IOCB. |
| 2371 | * |
| 2372 | * This routine issues a Fibre Channel Address Resolution Response |
| 2373 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2374 | * is passed into the function. It first search the @vport node list to find |
| 2375 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2376 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2377 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2378 | * |
| 2379 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2380 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2381 | * will be stored into the context1 field of the IOCB for the completion |
| 2382 | * callback function to the PARPR ELS command. |
| 2383 | * |
| 2384 | * Return code |
| 2385 | * 0 - Successfully issued farpr command |
| 2386 | * 1 - Failed to issue farpr command |
| 2387 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2388 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2389 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2390 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2391 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2392 | IOCB_t *icmd; |
| 2393 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2394 | struct lpfc_sli *psli; |
| 2395 | FARP *fp; |
| 2396 | uint8_t *pcmd; |
| 2397 | uint32_t *lp; |
| 2398 | uint16_t cmdsize; |
| 2399 | struct lpfc_nodelist *ondlp; |
| 2400 | struct lpfc_nodelist *ndlp; |
| 2401 | |
| 2402 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2403 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2405 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2406 | if (!ndlp) { |
| 2407 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2408 | if (!ndlp) |
| 2409 | return 1; |
| 2410 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2411 | lpfc_enqueue_node(vport, ndlp); |
| 2412 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2413 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2414 | if (!ndlp) |
| 2415 | return 1; |
| 2416 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2417 | |
| 2418 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2419 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2420 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2421 | /* This will trigger the release of the node just |
| 2422 | * allocated |
| 2423 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2424 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2425 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | icmd = &elsiocb->iocb; |
| 2429 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2430 | |
| 2431 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2432 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2433 | |
| 2434 | /* Fill in FARPR payload */ |
| 2435 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2436 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | lp = (uint32_t *) pcmd; |
| 2438 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2439 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | fp->Rflags = 0; |
| 2441 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2442 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2443 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2444 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2445 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2446 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2448 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2449 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2450 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2451 | } |
| 2452 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2453 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2454 | "Issue FARPR: did:x%x", |
| 2455 | ndlp->nlp_DID, 0, 0); |
| 2456 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2457 | phba->fc_stat.elsXmitFARPR++; |
| 2458 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2459 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2460 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2461 | /* The additional lpfc_nlp_put will cause the following |
| 2462 | * lpfc_els_free_iocb routine to trigger the release of |
| 2463 | * the node. |
| 2464 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2465 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2466 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2467 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2468 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2469 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2470 | * trigger the release of the node. |
| 2471 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2472 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2473 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2474 | } |
| 2475 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2476 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2477 | * 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] | 2478 | * @vport: pointer to a host virtual N_Port data structure. |
| 2479 | * @nlp: pointer to a node-list data structure. |
| 2480 | * |
| 2481 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2482 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2483 | * removes the ELS retry event if it presents. In addition, if the |
| 2484 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2485 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2486 | * ADISC. |
| 2487 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2488 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2489 | 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] | 2490 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2491 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2492 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2493 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2494 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2495 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2496 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2497 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2498 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2499 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2500 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2501 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2502 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2503 | /* Decrement nlp reference count held for the delayed retry */ |
| 2504 | evtp = &nlp->els_retry_evt; |
| 2505 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2506 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2507 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2508 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2509 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2510 | spin_unlock_irq(shost->host_lock); |
| 2511 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2512 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2513 | /* Check if there are more ADISCs to be sent */ |
| 2514 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2515 | } else { |
| 2516 | /* Check if there are more PLOGIs to be sent */ |
| 2517 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2518 | if (vport->num_disc_nodes == 0) { |
| 2519 | spin_lock_irq(shost->host_lock); |
| 2520 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2521 | spin_unlock_irq(shost->host_lock); |
| 2522 | lpfc_can_disctmo(vport); |
| 2523 | lpfc_end_rscn(vport); |
| 2524 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2525 | } |
| 2526 | } |
| 2527 | } |
| 2528 | return; |
| 2529 | } |
| 2530 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2531 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2532 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2533 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2534 | * |
| 2535 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2536 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2537 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2538 | * adds the delayed events to the HBA work list and invokes the |
| 2539 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2540 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2541 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2542 | * reference to ndlp will still be available when the worker thread gets |
| 2543 | * to the event associated with the ndlp. |
| 2544 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2545 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2546 | lpfc_els_retry_delay(unsigned long ptr) |
| 2547 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2548 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2549 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2550 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2551 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2552 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2553 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2554 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2555 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2556 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2557 | return; |
| 2558 | } |
| 2559 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2560 | /* We need to hold the node by incrementing the reference |
| 2561 | * count until the queued work is done |
| 2562 | */ |
| 2563 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2564 | if (evtp->evt_arg1) { |
| 2565 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2566 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2567 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2568 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2569 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2570 | return; |
| 2571 | } |
| 2572 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2573 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2574 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2575 | * @ndlp: pointer to a node-list data structure. |
| 2576 | * |
| 2577 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2578 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2579 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2580 | * function according to the delayed ELS command to retry the command. |
| 2581 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2582 | void |
| 2583 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2584 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2585 | struct lpfc_vport *vport = ndlp->vport; |
| 2586 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2587 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2588 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2589 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2590 | did = ndlp->nlp_DID; |
| 2591 | cmd = ndlp->nlp_last_elscmd; |
| 2592 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2593 | |
| 2594 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2595 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2596 | return; |
| 2597 | } |
| 2598 | |
| 2599 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2600 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2601 | /* |
| 2602 | * If a discovery event readded nlp_delayfunc after timer |
| 2603 | * firing and before processing the timer, cancel the |
| 2604 | * nlp_delayfunc. |
| 2605 | */ |
| 2606 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2607 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2608 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | |
| 2610 | switch (cmd) { |
| 2611 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2612 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2613 | break; |
| 2614 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2615 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2616 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2617 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2618 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2619 | break; |
| 2620 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2621 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2622 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2623 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2624 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | break; |
| 2626 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2627 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2628 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2629 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2630 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2631 | break; |
| 2632 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2633 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2634 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2635 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2636 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2637 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2638 | case ELS_CMD_FDISC: |
| 2639 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2640 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | } |
| 2642 | return; |
| 2643 | } |
| 2644 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2645 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2646 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2647 | * @phba: pointer to lpfc hba data structure. |
| 2648 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2649 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2650 | * |
| 2651 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2652 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2653 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2654 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2655 | * returned error status, it makes the decision whether a retry shall be |
| 2656 | * issued for the command, and whether a retry shall be made immediately or |
| 2657 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2658 | * is called to retry the command. In the later case, the ELS command shall |
| 2659 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2660 | * ndlp for the delayed command issusing. |
| 2661 | * |
| 2662 | * Return code |
| 2663 | * 0 - No retry of els command is made |
| 2664 | * 1 - Immediate or delayed retry of els command is made |
| 2665 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2666 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2667 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2668 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2669 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2670 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2671 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2672 | IOCB_t *irsp = &rspiocb->iocb; |
| 2673 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2674 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2675 | uint32_t *elscmd; |
| 2676 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2677 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2678 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2679 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2680 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2681 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2682 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2683 | /* Note: context2 may be 0 for internal driver abort |
| 2684 | * of delays ELS command. |
| 2685 | */ |
| 2686 | |
| 2687 | if (pcmd && pcmd->virt) { |
| 2688 | elscmd = (uint32_t *) (pcmd->virt); |
| 2689 | cmd = *elscmd++; |
| 2690 | } |
| 2691 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2692 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2693 | did = ndlp->nlp_DID; |
| 2694 | else { |
| 2695 | /* We should only hit this case for retrying PLOGI */ |
| 2696 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2697 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2698 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2699 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2700 | return 1; |
| 2701 | } |
| 2702 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2703 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2704 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2705 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2706 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2707 | switch (irsp->ulpStatus) { |
| 2708 | case IOSTAT_FCP_RSP_ERROR: |
| 2709 | case IOSTAT_REMOTE_STOP: |
| 2710 | break; |
| 2711 | |
| 2712 | case IOSTAT_LOCAL_REJECT: |
| 2713 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2714 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2715 | if (cmd == ELS_CMD_FLOGI) { |
| 2716 | if (PCI_DEVICE_ID_HORNET == |
| 2717 | phba->pcidev->device) { |
| 2718 | phba->fc_topology = TOPOLOGY_LOOP; |
| 2719 | phba->pport->fc_myDID = 0; |
| 2720 | phba->alpa_map[0] = 0; |
| 2721 | phba->alpa_map[1] = 0; |
| 2722 | } |
| 2723 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2724 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2725 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2726 | retry = 1; |
| 2727 | break; |
| 2728 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2729 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2730 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2731 | "0124 Retry illegal cmd x%x " |
| 2732 | "retry:x%x delay:x%x\n", |
| 2733 | cmd, cmdiocb->retry, delay); |
| 2734 | retry = 1; |
| 2735 | /* All command's retry policy */ |
| 2736 | maxretry = 8; |
| 2737 | if (cmdiocb->retry > 2) |
| 2738 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2739 | break; |
| 2740 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2742 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2743 | retry = 1; |
| 2744 | if (cmdiocb->retry > 100) |
| 2745 | delay = 100; |
| 2746 | maxretry = 250; |
| 2747 | break; |
| 2748 | |
| 2749 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2750 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2751 | retry = 1; |
| 2752 | break; |
| 2753 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2754 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2755 | case IOERR_INVALID_RPI: |
| 2756 | retry = 1; |
| 2757 | break; |
| 2758 | } |
| 2759 | break; |
| 2760 | |
| 2761 | case IOSTAT_NPORT_RJT: |
| 2762 | case IOSTAT_FABRIC_RJT: |
| 2763 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2764 | retry = 1; |
| 2765 | break; |
| 2766 | } |
| 2767 | break; |
| 2768 | |
| 2769 | case IOSTAT_NPORT_BSY: |
| 2770 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2771 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2772 | retry = 1; |
| 2773 | break; |
| 2774 | |
| 2775 | case IOSTAT_LS_RJT: |
| 2776 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2777 | /* Added for Vendor specifc support |
| 2778 | * Just keep retrying for these Rsn / Exp codes |
| 2779 | */ |
| 2780 | switch (stat.un.b.lsRjtRsnCode) { |
| 2781 | case LSRJT_UNABLE_TPC: |
| 2782 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2783 | LSEXP_CMD_IN_PROGRESS) { |
| 2784 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2785 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2786 | maxretry = 48; |
| 2787 | } |
| 2788 | retry = 1; |
| 2789 | break; |
| 2790 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 2791 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2792 | LSEXP_CANT_GIVE_DATA) { |
| 2793 | if (cmd == ELS_CMD_PLOGI) { |
| 2794 | delay = 1000; |
| 2795 | maxretry = 48; |
| 2796 | } |
| 2797 | retry = 1; |
| 2798 | break; |
| 2799 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 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 = lpfc_max_els_tries + 1; |
| 2803 | retry = 1; |
| 2804 | break; |
| 2805 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2806 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2807 | (cmd == ELS_CMD_FDISC) && |
| 2808 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2809 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2810 | "0125 FDISC Failed (x%x). " |
| 2811 | "Fabric out of resources\n", |
| 2812 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2813 | lpfc_vport_set_state(vport, |
| 2814 | FC_VPORT_NO_FABRIC_RSCS); |
| 2815 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2816 | break; |
| 2817 | |
| 2818 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2819 | if ((cmd == ELS_CMD_PLOGI) || |
| 2820 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2821 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2822 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2823 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2824 | /* FDISC retry policy */ |
| 2825 | maxretry = 48; |
| 2826 | if (cmdiocb->retry >= 32) |
| 2827 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2828 | } |
| 2829 | retry = 1; |
| 2830 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2831 | |
| 2832 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2833 | /* There are some cases where switches return this |
| 2834 | * error when they are not ready and should be returning |
| 2835 | * Logical Busy. We should delay every time. |
| 2836 | */ |
| 2837 | if (cmd == ELS_CMD_FDISC && |
| 2838 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2839 | maxretry = 3; |
| 2840 | delay = 1000; |
| 2841 | retry = 1; |
| 2842 | break; |
| 2843 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2844 | case LSRJT_PROTOCOL_ERR: |
| 2845 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2846 | (cmd == ELS_CMD_FDISC) && |
| 2847 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2848 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2849 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2850 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2851 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2852 | "Fabric Detected Bad WWN\n", |
| 2853 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2854 | lpfc_vport_set_state(vport, |
| 2855 | FC_VPORT_FABRIC_REJ_WWN); |
| 2856 | } |
| 2857 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2858 | } |
| 2859 | break; |
| 2860 | |
| 2861 | case IOSTAT_INTERMED_RSP: |
| 2862 | case IOSTAT_BA_RJT: |
| 2863 | break; |
| 2864 | |
| 2865 | default: |
| 2866 | break; |
| 2867 | } |
| 2868 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2869 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2870 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2871 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2872 | if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2873 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2874 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2875 | /* FLOGI retry policy */ |
| 2876 | retry = 1; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2877 | /* retry forever */ |
| 2878 | maxretry = 0; |
| 2879 | if (cmdiocb->retry >= 100) |
| 2880 | delay = 5000; |
| 2881 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2882 | delay = 1000; |
| 2883 | } |
| 2884 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2885 | cmdiocb->retry++; |
| 2886 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2887 | phba->fc_stat.elsRetryExceeded++; |
| 2888 | retry = 0; |
| 2889 | } |
| 2890 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2891 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2892 | retry = 0; |
| 2893 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2894 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 2895 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 2896 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 2897 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 2898 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2899 | "2849 Stop retry ELS command " |
| 2900 | "x%x to remote NPORT x%x, " |
| 2901 | "Data: x%x x%x\n", cmd, did, |
| 2902 | cmdiocb->retry, delay); |
| 2903 | return 0; |
| 2904 | } |
| 2905 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2906 | |
| 2907 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2908 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2909 | "0107 Retry ELS command x%x to remote " |
| 2910 | "NPORT x%x Data: x%x x%x\n", |
| 2911 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2912 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2913 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2914 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2915 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2916 | /* Don't reset timer for no resources */ |
| 2917 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2918 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2919 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2920 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2921 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2925 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2926 | phba->fc_stat.elsDelayRetry++; |
| 2927 | ndlp->nlp_retry = cmdiocb->retry; |
| 2928 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2929 | /* delay is specified in milliseconds */ |
| 2930 | mod_timer(&ndlp->nlp_delayfunc, |
| 2931 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2932 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2933 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2934 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2935 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2936 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2937 | if (cmd == ELS_CMD_PRLI) |
| 2938 | lpfc_nlp_set_state(vport, ndlp, |
| 2939 | NLP_STE_REG_LOGIN_ISSUE); |
| 2940 | else |
| 2941 | lpfc_nlp_set_state(vport, ndlp, |
| 2942 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2943 | ndlp->nlp_last_elscmd = cmd; |
| 2944 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2945 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2946 | } |
| 2947 | switch (cmd) { |
| 2948 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2949 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2950 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2951 | case ELS_CMD_FDISC: |
| 2952 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2953 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2954 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2955 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2956 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2957 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2958 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2959 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2960 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2961 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2962 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2963 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2964 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2965 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2966 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2967 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2968 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2969 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2970 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2971 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2972 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2973 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2974 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2975 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2976 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2977 | } |
| 2978 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2979 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2980 | if (logerr) { |
| 2981 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2982 | "0137 No retry ELS command x%x to remote " |
| 2983 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2984 | cmd, did, irsp->ulpStatus, |
| 2985 | irsp->un.ulpWord[4]); |
| 2986 | } |
| 2987 | else { |
| 2988 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2989 | "0108 No retry ELS command x%x to remote " |
| 2990 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2991 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2992 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2993 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2994 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2995 | } |
| 2996 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2997 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2998 | * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2999 | * @phba: pointer to lpfc hba data structure. |
| 3000 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3001 | * |
| 3002 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3003 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3004 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3005 | * response of the command IOCB. If so, it will be released before releasing |
| 3006 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3007 | * |
| 3008 | * Return code |
| 3009 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3010 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3011 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3012 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3013 | { |
| 3014 | struct lpfc_dmabuf *buf_ptr; |
| 3015 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3016 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3017 | if (!list_empty(&buf_ptr1->list)) { |
| 3018 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3019 | struct lpfc_dmabuf, |
| 3020 | list); |
| 3021 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3022 | kfree(buf_ptr); |
| 3023 | } |
| 3024 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3025 | kfree(buf_ptr1); |
| 3026 | return 0; |
| 3027 | } |
| 3028 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3029 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3030 | * 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] | 3031 | * @phba: pointer to lpfc hba data structure. |
| 3032 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3033 | * |
| 3034 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3035 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3036 | * pool. |
| 3037 | * |
| 3038 | * Return code |
| 3039 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3040 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3041 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3042 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3043 | { |
| 3044 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3045 | kfree(buf_ptr); |
| 3046 | return 0; |
| 3047 | } |
| 3048 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3049 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3050 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3051 | * @phba: pointer to lpfc hba data structure. |
| 3052 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3053 | * |
| 3054 | * This routine frees a command IOCB and its associated resources. The |
| 3055 | * command IOCB data structure contains the reference to various associated |
| 3056 | * resources, these fields must be set to NULL if the associated reference |
| 3057 | * not present: |
| 3058 | * context1 - reference to ndlp |
| 3059 | * context2 - reference to cmd |
| 3060 | * context2->next - reference to rsp |
| 3061 | * context3 - reference to bpl |
| 3062 | * |
| 3063 | * It first properly decrements the reference count held on ndlp for the |
| 3064 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3065 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3066 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3067 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3068 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3069 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3070 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3071 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3072 | * |
| 3073 | * Return code |
| 3074 | * 0 - Success (currently, always return 0) |
| 3075 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3076 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3077 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3078 | { |
| 3079 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3080 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3081 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3082 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3083 | if (ndlp) { |
| 3084 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3085 | lpfc_nlp_put(ndlp); |
| 3086 | |
| 3087 | /* If the ndlp is not being used by another discovery |
| 3088 | * thread, free it. |
| 3089 | */ |
| 3090 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3091 | /* If ndlp is being used by another discovery |
| 3092 | * thread, just clear NLP_DEFER_RM |
| 3093 | */ |
| 3094 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3095 | } |
| 3096 | } |
| 3097 | else |
| 3098 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3099 | elsiocb->context1 = NULL; |
| 3100 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3101 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3102 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3103 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3104 | /* Firmware could still be in progress of DMAing |
| 3105 | * payload, so don't free data buffer till after |
| 3106 | * a hbeat. |
| 3107 | */ |
| 3108 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3109 | buf_ptr = elsiocb->context2; |
| 3110 | elsiocb->context2 = NULL; |
| 3111 | if (buf_ptr) { |
| 3112 | buf_ptr1 = NULL; |
| 3113 | spin_lock_irq(&phba->hbalock); |
| 3114 | if (!list_empty(&buf_ptr->list)) { |
| 3115 | list_remove_head(&buf_ptr->list, |
| 3116 | buf_ptr1, struct lpfc_dmabuf, |
| 3117 | list); |
| 3118 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3119 | list_add_tail(&buf_ptr1->list, |
| 3120 | &phba->elsbuf); |
| 3121 | phba->elsbuf_cnt++; |
| 3122 | } |
| 3123 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3124 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3125 | phba->elsbuf_cnt++; |
| 3126 | spin_unlock_irq(&phba->hbalock); |
| 3127 | } |
| 3128 | } else { |
| 3129 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3130 | lpfc_els_free_data(phba, buf_ptr1); |
| 3131 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3132 | } |
| 3133 | |
| 3134 | if (elsiocb->context3) { |
| 3135 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3136 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3137 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3138 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3139 | return 0; |
| 3140 | } |
| 3141 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3142 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3143 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3144 | * @phba: pointer to lpfc hba data structure. |
| 3145 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3146 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3147 | * |
| 3148 | * This routine is the completion callback function to the Logout (LOGO) |
| 3149 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3150 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3151 | * release the ndlp if it has the last reference remaining (reference count |
| 3152 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3153 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3154 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3155 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3156 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3157 | * IOCB data structure. |
| 3158 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3159 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3160 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3161 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3162 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3163 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3164 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3165 | IOCB_t *irsp; |
| 3166 | |
| 3167 | irsp = &rspiocb->iocb; |
| 3168 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3169 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3170 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3171 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3172 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3173 | "0109 ACC to LOGO completes to NPort x%x " |
| 3174 | "Data: x%x x%x x%x\n", |
| 3175 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3176 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3177 | |
| 3178 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3179 | /* NPort Recovery mode or node is just allocated */ |
| 3180 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3181 | /* If the ndlp is being used by another discovery |
| 3182 | * thread, just unregister the RPI. |
| 3183 | */ |
| 3184 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3185 | } else { |
| 3186 | /* Indicate the node has already released, should |
| 3187 | * not reference to it from within lpfc_els_free_iocb. |
| 3188 | */ |
| 3189 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3190 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3191 | } |
| 3192 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3193 | return; |
| 3194 | } |
| 3195 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3196 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3197 | * 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] | 3198 | * @phba: pointer to lpfc hba data structure. |
| 3199 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3200 | * |
| 3201 | * This routine is the completion callback function for unregister default |
| 3202 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3203 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3204 | * decrements the ndlp reference count held for this completion callback |
| 3205 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3206 | * whether there is only one reference left on the ndlp. If so, it will |
| 3207 | * perform one more decrement and trigger the release of the ndlp. |
| 3208 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3209 | void |
| 3210 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3211 | { |
| 3212 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3213 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3214 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3215 | /* |
| 3216 | * This routine is used to register and unregister in previous SLI |
| 3217 | * modes. |
| 3218 | */ |
| 3219 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
| 3220 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 3221 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
| 3222 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3223 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3224 | pmb->context2 = NULL; |
| 3225 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3226 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3227 | kfree(mp); |
| 3228 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3229 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3230 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3231 | /* This is the end of the default RPI cleanup logic for this |
| 3232 | * ndlp. If no other discovery threads are using this ndlp. |
| 3233 | * we should free all resources associated with it. |
| 3234 | */ |
| 3235 | lpfc_nlp_not_used(ndlp); |
| 3236 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3237 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3238 | return; |
| 3239 | } |
| 3240 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3241 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3242 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3243 | * @phba: pointer to lpfc hba data structure. |
| 3244 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3245 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3246 | * |
| 3247 | * This routine is the completion callback function for ELS Response IOCB |
| 3248 | * command. In normal case, this callback function just properly sets the |
| 3249 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3250 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3251 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3252 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3253 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3254 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3255 | * are currently referring it. |
| 3256 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3257 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3258 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3259 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3260 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3261 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3262 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3263 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3264 | IOCB_t *irsp; |
| 3265 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3267 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3268 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3269 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3270 | irsp = &rspiocb->iocb; |
| 3271 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3272 | if (cmdiocb->context_un.mbox) |
| 3273 | mbox = cmdiocb->context_un.mbox; |
| 3274 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3275 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3276 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3277 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3278 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3279 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3280 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3281 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3282 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3283 | */ |
| 3284 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3285 | ls_rjt = 1; |
| 3286 | } |
| 3287 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3288 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3289 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3290 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3291 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3292 | if (mp) { |
| 3293 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3294 | kfree(mp); |
| 3295 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3296 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3297 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3298 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3299 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3300 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3301 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3302 | /* Indicate the node has already released, |
| 3303 | * should not reference to it from within |
| 3304 | * the routine lpfc_els_free_iocb. |
| 3305 | */ |
| 3306 | cmdiocb->context1 = NULL; |
| 3307 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3308 | goto out; |
| 3309 | } |
| 3310 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3311 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3312 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3313 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3314 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3315 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3316 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3317 | "0110 ELS response tag x%x completes " |
| 3318 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3319 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3320 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3321 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3322 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3323 | if (mbox) { |
| 3324 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3325 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3326 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3327 | /* Increment reference count to ndlp to hold the |
| 3328 | * reference to ndlp for the callback function. |
| 3329 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3330 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3331 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3332 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3333 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3334 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3335 | } |
| 3336 | else { |
| 3337 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3338 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3339 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3340 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3341 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3342 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3343 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3344 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3345 | else |
| 3346 | /* Decrement the ndlp reference count we |
| 3347 | * set for this failed mailbox command. |
| 3348 | */ |
| 3349 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3350 | |
| 3351 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3352 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3353 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3354 | "Data: x%x x%x x%x\n", |
| 3355 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3356 | ndlp->nlp_rpi); |
| 3357 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3358 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3359 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3360 | /* Indicate node has already been released, |
| 3361 | * should not reference to it from within |
| 3362 | * the routine lpfc_els_free_iocb. |
| 3363 | */ |
| 3364 | cmdiocb->context1 = NULL; |
| 3365 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3366 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3367 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3368 | if (!lpfc_error_lost_link(irsp) && |
| 3369 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3370 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3371 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3372 | /* Indicate node has already been |
| 3373 | * released, should not reference |
| 3374 | * to it from within the routine |
| 3375 | * lpfc_els_free_iocb. |
| 3376 | */ |
| 3377 | cmdiocb->context1 = NULL; |
| 3378 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3379 | } |
| 3380 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3381 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3382 | if (mp) { |
| 3383 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3384 | kfree(mp); |
| 3385 | } |
| 3386 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3387 | } |
| 3388 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3389 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3390 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3391 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3392 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3393 | |
| 3394 | /* If the node is not being used by another discovery thread, |
| 3395 | * and we are sending a reject, we are done with it. |
| 3396 | * Release driver reference count here and free associated |
| 3397 | * resources. |
| 3398 | */ |
| 3399 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3400 | if (lpfc_nlp_not_used(ndlp)) |
| 3401 | /* Indicate node has already been released, |
| 3402 | * should not reference to it from within |
| 3403 | * the routine lpfc_els_free_iocb. |
| 3404 | */ |
| 3405 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3407 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3409 | return; |
| 3410 | } |
| 3411 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3412 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3413 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3414 | * @vport: pointer to a host virtual N_Port data structure. |
| 3415 | * @flag: the els command code to be accepted. |
| 3416 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3417 | * @ndlp: pointer to a node-list data structure. |
| 3418 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3419 | * |
| 3420 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3421 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3422 | * specific ACC response command to be issued and invokes the |
| 3423 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3424 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3425 | * field of the IOCB for the completion callback function to issue the |
| 3426 | * mailbox command to the HBA later when callback is invoked. |
| 3427 | * |
| 3428 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3429 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3430 | * will be stored into the context1 field of the IOCB for the completion |
| 3431 | * callback function to the corresponding response ELS IOCB command. |
| 3432 | * |
| 3433 | * Return code |
| 3434 | * 0 - Successfully issued acc response |
| 3435 | * 1 - Failed to issue acc response |
| 3436 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3437 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3438 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3439 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3440 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3441 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3442 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3443 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3444 | IOCB_t *icmd; |
| 3445 | IOCB_t *oldcmd; |
| 3446 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3447 | struct lpfc_sli *psli; |
| 3448 | uint8_t *pcmd; |
| 3449 | uint16_t cmdsize; |
| 3450 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3451 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3452 | |
| 3453 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3454 | oldcmd = &oldiocb->iocb; |
| 3455 | |
| 3456 | switch (flag) { |
| 3457 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3458 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3459 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3460 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3461 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3462 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3463 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3464 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3465 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3467 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3468 | icmd = &elsiocb->iocb; |
| 3469 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3470 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3471 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3472 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3473 | |
| 3474 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3475 | "Issue ACC: did:x%x flg:x%x", |
| 3476 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3477 | break; |
| 3478 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3479 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3480 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3481 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3482 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3483 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3484 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3485 | icmd = &elsiocb->iocb; |
| 3486 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3487 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3488 | |
| 3489 | if (mbox) |
| 3490 | elsiocb->context_un.mbox = mbox; |
| 3491 | |
| 3492 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3493 | pcmd += sizeof(uint32_t); |
| 3494 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3495 | |
| 3496 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3497 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3498 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3499 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3500 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3501 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3502 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3503 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3504 | if (!elsiocb) |
| 3505 | return 1; |
| 3506 | |
| 3507 | icmd = &elsiocb->iocb; |
| 3508 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3509 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3510 | |
| 3511 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3512 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3513 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3514 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3515 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3516 | |
| 3517 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3518 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3519 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3520 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3521 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3522 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3523 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3524 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3525 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3526 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3527 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3528 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3529 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3530 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3531 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3532 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3533 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3534 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3535 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3536 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3537 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3541 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | if (rc == IOCB_ERROR) { |
| 3543 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3544 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3545 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3546 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3547 | } |
| 3548 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3549 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3550 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3551 | * @vport: pointer to a virtual N_Port data structure. |
| 3552 | * @rejectError: |
| 3553 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3554 | * @ndlp: pointer to a node-list data structure. |
| 3555 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3556 | * |
| 3557 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3558 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3559 | * context_un.mbox field of the IOCB for the completion callback function |
| 3560 | * to issue to the HBA later. |
| 3561 | * |
| 3562 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3563 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3564 | * will be stored into the context1 field of the IOCB for the completion |
| 3565 | * callback function to the reject response ELS IOCB command. |
| 3566 | * |
| 3567 | * Return code |
| 3568 | * 0 - Successfully issued reject response |
| 3569 | * 1 - Failed to issue reject response |
| 3570 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3571 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3572 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3573 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3574 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3575 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3576 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3577 | IOCB_t *icmd; |
| 3578 | IOCB_t *oldcmd; |
| 3579 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3580 | struct lpfc_sli *psli; |
| 3581 | uint8_t *pcmd; |
| 3582 | uint16_t cmdsize; |
| 3583 | int rc; |
| 3584 | |
| 3585 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3586 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3587 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3588 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3589 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3590 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | |
| 3592 | icmd = &elsiocb->iocb; |
| 3593 | oldcmd = &oldiocb->iocb; |
| 3594 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3595 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3596 | |
| 3597 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3598 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3599 | *((uint32_t *) (pcmd)) = rejectError; |
| 3600 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3601 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3602 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3603 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3604 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3605 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3606 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3607 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3608 | "rpi x%x\n", |
| 3609 | rejectError, elsiocb->iotag, |
| 3610 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3611 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3612 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3613 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3614 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3615 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3616 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3617 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3618 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3619 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3620 | if (rc == IOCB_ERROR) { |
| 3621 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3622 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3623 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3624 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3625 | } |
| 3626 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3627 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3628 | * 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] | 3629 | * @vport: pointer to a virtual N_Port data structure. |
| 3630 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3631 | * @ndlp: pointer to a node-list data structure. |
| 3632 | * |
| 3633 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3634 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3635 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3636 | * |
| 3637 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3638 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3639 | * will be stored into the context1 field of the IOCB for the completion |
| 3640 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3641 | * |
| 3642 | * Return code |
| 3643 | * 0 - Successfully issued acc adisc response |
| 3644 | * 1 - Failed to issue adisc acc response |
| 3645 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3646 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3647 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3648 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3649 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3650 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3651 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3652 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3653 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3654 | uint8_t *pcmd; |
| 3655 | uint16_t cmdsize; |
| 3656 | int rc; |
| 3657 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3658 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3659 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3660 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3661 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3662 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3663 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3664 | icmd = &elsiocb->iocb; |
| 3665 | oldcmd = &oldiocb->iocb; |
| 3666 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3667 | |
| 3668 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3669 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3670 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3671 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3672 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3673 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3674 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3675 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3676 | |
| 3677 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3678 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3679 | |
| 3680 | ap = (ADISC *) (pcmd); |
| 3681 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3682 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3683 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3684 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3685 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3686 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3687 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3688 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3689 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3690 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3691 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3692 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3693 | if (rc == IOCB_ERROR) { |
| 3694 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3695 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3696 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3697 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3698 | } |
| 3699 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3700 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3701 | * 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] | 3702 | * @vport: pointer to a virtual N_Port data structure. |
| 3703 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3704 | * @ndlp: pointer to a node-list data structure. |
| 3705 | * |
| 3706 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3707 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3708 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3709 | * |
| 3710 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3711 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3712 | * will be stored into the context1 field of the IOCB for the completion |
| 3713 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3714 | * |
| 3715 | * Return code |
| 3716 | * 0 - Successfully issued acc prli response |
| 3717 | * 1 - Failed to issue acc prli response |
| 3718 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3719 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3720 | 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] | 3721 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3722 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3723 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3724 | PRLI *npr; |
| 3725 | lpfc_vpd_t *vpd; |
| 3726 | IOCB_t *icmd; |
| 3727 | IOCB_t *oldcmd; |
| 3728 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3729 | struct lpfc_sli *psli; |
| 3730 | uint8_t *pcmd; |
| 3731 | uint16_t cmdsize; |
| 3732 | int rc; |
| 3733 | |
| 3734 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3735 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3736 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3737 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3738 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3739 | if (!elsiocb) |
| 3740 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3741 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3742 | icmd = &elsiocb->iocb; |
| 3743 | oldcmd = &oldiocb->iocb; |
| 3744 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3745 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3746 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3747 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3748 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3749 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3750 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3751 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3752 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3753 | |
| 3754 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3755 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3756 | |
| 3757 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3758 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3759 | |
| 3760 | npr = (PRLI *) pcmd; |
| 3761 | vpd = &phba->vpd; |
| 3762 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3763 | * If the remote port is a target and our firmware version is 3.20 or |
| 3764 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3765 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3766 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3767 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3768 | npr->ConfmComplAllowed = 1; |
| 3769 | npr->Retry = 1; |
| 3770 | npr->TaskRetryIdReq = 1; |
| 3771 | } |
| 3772 | |
| 3773 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3774 | npr->estabImagePair = 1; |
| 3775 | npr->readXferRdyDis = 1; |
| 3776 | npr->ConfmComplAllowed = 1; |
| 3777 | |
| 3778 | npr->prliType = PRLI_FCP_TYPE; |
| 3779 | npr->initiatorFunc = 1; |
| 3780 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3781 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3782 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3783 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3784 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3785 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3786 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3787 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3788 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | if (rc == IOCB_ERROR) { |
| 3790 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3791 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3792 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3793 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3794 | } |
| 3795 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3796 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3797 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3798 | * @vport: pointer to a virtual N_Port data structure. |
| 3799 | * @format: rnid command format. |
| 3800 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3801 | * @ndlp: pointer to a node-list data structure. |
| 3802 | * |
| 3803 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3804 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3805 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3806 | * issue the response. Note that this command does not need to hold the ndlp |
| 3807 | * reference count for the callback. So, the ndlp reference count taken by |
| 3808 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3809 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3810 | * there is no ndlp reference available. |
| 3811 | * |
| 3812 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3813 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3814 | * will be stored into the context1 field of the IOCB for the completion |
| 3815 | * callback function. However, for the RNID Accept Response ELS command, |
| 3816 | * this is undone later by this routine after the IOCB is allocated. |
| 3817 | * |
| 3818 | * Return code |
| 3819 | * 0 - Successfully issued acc rnid response |
| 3820 | * 1 - Failed to issue acc rnid response |
| 3821 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3822 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3823 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3824 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3825 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3826 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3827 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3828 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3829 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3830 | struct lpfc_sli *psli; |
| 3831 | uint8_t *pcmd; |
| 3832 | uint16_t cmdsize; |
| 3833 | int rc; |
| 3834 | |
| 3835 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3836 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3837 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3838 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3839 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3840 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3841 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3842 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3843 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3844 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3845 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3846 | icmd = &elsiocb->iocb; |
| 3847 | oldcmd = &oldiocb->iocb; |
| 3848 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3849 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3850 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3851 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3852 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3853 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3854 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3855 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3856 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3857 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3858 | rn = (RNID *) (pcmd); |
| 3859 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3860 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3861 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3862 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3863 | switch (format) { |
| 3864 | case 0: |
| 3865 | rn->SpecificLen = 0; |
| 3866 | break; |
| 3867 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3868 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3869 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3870 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3871 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3872 | rn->un.topologyDisc.physPort = 0; |
| 3873 | rn->un.topologyDisc.attachedNodes = 0; |
| 3874 | break; |
| 3875 | default: |
| 3876 | rn->CommonLen = 0; |
| 3877 | rn->SpecificLen = 0; |
| 3878 | break; |
| 3879 | } |
| 3880 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3881 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3882 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3883 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3884 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3885 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3886 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3887 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3888 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3889 | * it could be freed */ |
| 3890 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3891 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3892 | if (rc == IOCB_ERROR) { |
| 3893 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3894 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3895 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3896 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3897 | } |
| 3898 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3899 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 3900 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 3901 | * @vport: pointer to a virtual N_Port data structure. |
| 3902 | * @data: pointer to echo data to return in the accept. |
| 3903 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3904 | * @ndlp: pointer to a node-list data structure. |
| 3905 | * |
| 3906 | * Return code |
| 3907 | * 0 - Successfully issued acc echo response |
| 3908 | * 1 - Failed to issue acc echo response |
| 3909 | **/ |
| 3910 | static int |
| 3911 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 3912 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 3913 | { |
| 3914 | struct lpfc_hba *phba = vport->phba; |
| 3915 | struct lpfc_iocbq *elsiocb; |
| 3916 | struct lpfc_sli *psli; |
| 3917 | uint8_t *pcmd; |
| 3918 | uint16_t cmdsize; |
| 3919 | int rc; |
| 3920 | |
| 3921 | psli = &phba->sli; |
| 3922 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 3923 | |
| 3924 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3925 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 3926 | if (!elsiocb) |
| 3927 | return 1; |
| 3928 | |
| 3929 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */ |
| 3930 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 3931 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3932 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 3933 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 3934 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3935 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 3936 | pcmd += sizeof(uint32_t); |
| 3937 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 3938 | |
| 3939 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3940 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 3941 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3942 | |
| 3943 | phba->fc_stat.elsXmitACC++; |
| 3944 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 3945 | lpfc_nlp_put(ndlp); |
| 3946 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3947 | * it could be freed */ |
| 3948 | |
| 3949 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 3950 | if (rc == IOCB_ERROR) { |
| 3951 | lpfc_els_free_iocb(phba, elsiocb); |
| 3952 | return 1; |
| 3953 | } |
| 3954 | return 0; |
| 3955 | } |
| 3956 | |
| 3957 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3958 | * 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] | 3959 | * @vport: pointer to a host virtual N_Port data structure. |
| 3960 | * |
| 3961 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3962 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3963 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3964 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3965 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3966 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3967 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3968 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3969 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3970 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3971 | * no more ADISC need to be sent. |
| 3972 | * |
| 3973 | * Return code |
| 3974 | * The number of N_Ports with adisc issued. |
| 3975 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3976 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3977 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3978 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3979 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3980 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3981 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3982 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3983 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3984 | 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] | 3985 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3986 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3987 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3988 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3989 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3990 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3991 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3992 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3993 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3994 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3995 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3996 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3997 | vport->num_disc_nodes++; |
| 3998 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3999 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4000 | spin_lock_irq(shost->host_lock); |
| 4001 | vport->fc_flag |= FC_NLP_MORE; |
| 4002 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4003 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4004 | } |
| 4005 | } |
| 4006 | } |
| 4007 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4008 | spin_lock_irq(shost->host_lock); |
| 4009 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4010 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4011 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4012 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4013 | } |
| 4014 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4015 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4016 | * 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] | 4017 | * @vport: pointer to a host virtual N_Port data structure. |
| 4018 | * |
| 4019 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4020 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4021 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4022 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4023 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4024 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4025 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4026 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4027 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4028 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4029 | * PLOGI need to be sent. |
| 4030 | * |
| 4031 | * Return code |
| 4032 | * The number of N_Ports with plogi issued. |
| 4033 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4034 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4035 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4036 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4037 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4038 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4039 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4040 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4041 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4042 | 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] | 4043 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4044 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4045 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4046 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4047 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4048 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 4049 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4050 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4051 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4052 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4053 | vport->num_disc_nodes++; |
| 4054 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4055 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4056 | spin_lock_irq(shost->host_lock); |
| 4057 | vport->fc_flag |= FC_NLP_MORE; |
| 4058 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4059 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4060 | } |
| 4061 | } |
| 4062 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4063 | if (sentplogi) { |
| 4064 | lpfc_set_disctmo(vport); |
| 4065 | } |
| 4066 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4067 | spin_lock_irq(shost->host_lock); |
| 4068 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4069 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4070 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4071 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4072 | } |
| 4073 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4074 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4075 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4076 | * @vport: pointer to a host virtual N_Port data structure. |
| 4077 | * |
| 4078 | * This routine cleans up any Registration State Change Notification |
| 4079 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 4080 | * @vport together with the host_lock is used to prevent multiple thread |
| 4081 | * trying to access the RSCN array on a same @vport at the same time. |
| 4082 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4083 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4084 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4085 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4086 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4087 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4088 | int i; |
| 4089 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4090 | spin_lock_irq(shost->host_lock); |
| 4091 | if (vport->fc_rscn_flush) { |
| 4092 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4093 | spin_unlock_irq(shost->host_lock); |
| 4094 | return; |
| 4095 | } |
| 4096 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 4097 | vport->fc_rscn_flush = 1; |
| 4098 | spin_unlock_irq(shost->host_lock); |
| 4099 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4100 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4101 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4102 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4103 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4104 | spin_lock_irq(shost->host_lock); |
| 4105 | vport->fc_rscn_id_cnt = 0; |
| 4106 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 4107 | spin_unlock_irq(shost->host_lock); |
| 4108 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4109 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 4110 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4111 | } |
| 4112 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4113 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4114 | * 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] | 4115 | * @vport: pointer to a host virtual N_Port data structure. |
| 4116 | * @did: remote destination port identifier. |
| 4117 | * |
| 4118 | * This routine checks whether there is any pending Registration State |
| 4119 | * Configuration Notification (RSCN) to a @did on @vport. |
| 4120 | * |
| 4121 | * Return code |
| 4122 | * None zero - The @did matched with a pending rscn |
| 4123 | * 0 - not able to match @did with a pending rscn |
| 4124 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4125 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4126 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4127 | { |
| 4128 | D_ID ns_did; |
| 4129 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4130 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4131 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4132 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4133 | |
| 4134 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4135 | |
| 4136 | /* Never match fabric nodes for RSCNs */ |
| 4137 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4138 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4139 | |
| 4140 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4141 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4142 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4143 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4144 | spin_lock_irq(shost->host_lock); |
| 4145 | if (vport->fc_rscn_flush) { |
| 4146 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4147 | spin_unlock_irq(shost->host_lock); |
| 4148 | return 0; |
| 4149 | } |
| 4150 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4151 | vport->fc_rscn_flush = 1; |
| 4152 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4153 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4154 | lp = vport->fc_rscn_id_list[i]->virt; |
| 4155 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4156 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4157 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4158 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 4159 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4160 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 4161 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4162 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4163 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 4164 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4165 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4166 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4167 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4169 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4170 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4171 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4172 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4173 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4174 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4176 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4177 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4178 | } |
| 4179 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4180 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4181 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4182 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4183 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4184 | return_did_out: |
| 4185 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4186 | vport->fc_rscn_flush = 0; |
| 4187 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4188 | } |
| 4189 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4190 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4191 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4192 | * @vport: pointer to a host virtual N_Port data structure. |
| 4193 | * |
| 4194 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 4195 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 4196 | * State Change Notification). |
| 4197 | * |
| 4198 | * Return code |
| 4199 | * 0 - Successful (currently alway return 0) |
| 4200 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4201 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4202 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4203 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4204 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4205 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4206 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4207 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4208 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4209 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4210 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4211 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4212 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4213 | NLP_EVT_DEVICE_RECOVERY); |
| 4214 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4215 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4216 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4217 | } |
| 4218 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4219 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4220 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4221 | * @vport: pointer to a host virtual N_Port data structure. |
| 4222 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4223 | * |
| 4224 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4225 | * applications. |
| 4226 | */ |
| 4227 | static void |
| 4228 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4229 | struct lpfc_iocbq *cmdiocb) |
| 4230 | { |
| 4231 | struct lpfc_dmabuf *pcmd; |
| 4232 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4233 | uint32_t *payload_ptr; |
| 4234 | uint32_t payload_len; |
| 4235 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4236 | |
| 4237 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4238 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4239 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4240 | |
| 4241 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4242 | payload_len, GFP_KERNEL); |
| 4243 | if (!rscn_event_data) { |
| 4244 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4245 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4246 | return; |
| 4247 | } |
| 4248 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4249 | rscn_event_data->payload_length = payload_len; |
| 4250 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4251 | payload_len); |
| 4252 | |
| 4253 | fc_host_post_vendor_event(shost, |
| 4254 | fc_get_event_number(), |
| 4255 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4256 | (char *)rscn_event_data, |
| 4257 | LPFC_NL_VENDOR_ID); |
| 4258 | |
| 4259 | kfree(rscn_event_data); |
| 4260 | } |
| 4261 | |
| 4262 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4263 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4264 | * @vport: pointer to a host virtual N_Port data structure. |
| 4265 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4266 | * @ndlp: pointer to a node-list data structure. |
| 4267 | * |
| 4268 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4269 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4270 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4271 | * discover state machine is about to begin discovery, it just accepts the |
| 4272 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4273 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4274 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4275 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4276 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4277 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4278 | * routine is invoked to handle the RSCN event. |
| 4279 | * |
| 4280 | * Return code |
| 4281 | * 0 - Just sent the acc response |
| 4282 | * 1 - Sent the acc response and waited for name server completion |
| 4283 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4284 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4285 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4286 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4287 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4288 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4289 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4290 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4291 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4292 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4293 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4294 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4295 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4296 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4297 | |
| 4298 | icmd = &cmdiocb->iocb; |
| 4299 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4300 | lp = (uint32_t *) pcmd->virt; |
| 4301 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4302 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4303 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4304 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4305 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4306 | "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] | 4307 | vport->fc_flag, payload_len, *lp, |
| 4308 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4309 | |
| 4310 | /* Send an RSCN event to the management application */ |
| 4311 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4312 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4313 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4314 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4315 | FCH_EVT_RSCN, lp[i]); |
| 4316 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4317 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4318 | * Discovery processing will satisfy it. |
| 4319 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4320 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4321 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4322 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4323 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4324 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4325 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4326 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4327 | } |
| 4328 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4329 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4330 | * just ACC and ignore it. |
| 4331 | */ |
| 4332 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4333 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4334 | i = payload_len; |
| 4335 | datap = lp; |
| 4336 | while (i > 0) { |
| 4337 | nportid = *datap++; |
| 4338 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4339 | i -= sizeof(uint32_t); |
| 4340 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4341 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4342 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4343 | } |
| 4344 | if (rscn_id == hba_id) { |
| 4345 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4346 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4347 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4348 | "Data: x%x x%x x%x x%x\n", |
| 4349 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4350 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4351 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4352 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4353 | ndlp->nlp_DID, vport->port_state, |
| 4354 | ndlp->nlp_flag); |
| 4355 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4356 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4357 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4358 | return 0; |
| 4359 | } |
| 4360 | } |
| 4361 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4362 | spin_lock_irq(shost->host_lock); |
| 4363 | if (vport->fc_rscn_flush) { |
| 4364 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4365 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4366 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4367 | /* Send back ACC */ |
| 4368 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4369 | return 0; |
| 4370 | } |
| 4371 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4372 | vport->fc_rscn_flush = 1; |
| 4373 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4374 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4375 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4376 | /* If we are already processing an RSCN, save the received |
| 4377 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4378 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4379 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4380 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4381 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4382 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4383 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4384 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4385 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4386 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4387 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4388 | vport->fc_flag |= FC_RSCN_MODE; |
| 4389 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4390 | if (rscn_cnt) { |
| 4391 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4392 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4393 | } |
| 4394 | if ((rscn_cnt) && |
| 4395 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4396 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4397 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4398 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4399 | payload_len); |
| 4400 | } else { |
| 4401 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4402 | vport->fc_rscn_id_cnt++; |
| 4403 | /* If we zero, cmdiocb->context2, the calling |
| 4404 | * routine will not try to free it. |
| 4405 | */ |
| 4406 | cmdiocb->context2 = NULL; |
| 4407 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4408 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4409 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4410 | "0235 Deferred RSCN " |
| 4411 | "Data: x%x x%x x%x\n", |
| 4412 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4413 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4414 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4415 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4416 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4417 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4418 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4419 | "0234 ReDiscovery RSCN " |
| 4420 | "Data: x%x x%x x%x\n", |
| 4421 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4422 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4423 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4424 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4425 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4426 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4427 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4428 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4429 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4430 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4431 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4432 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4433 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4434 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4435 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4436 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4437 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4438 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4439 | spin_lock_irq(shost->host_lock); |
| 4440 | vport->fc_flag |= FC_RSCN_MODE; |
| 4441 | spin_unlock_irq(shost->host_lock); |
| 4442 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4443 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4444 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4445 | /* |
| 4446 | * If we zero, cmdiocb->context2, the calling routine will |
| 4447 | * not try to free it. |
| 4448 | */ |
| 4449 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4450 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4451 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4452 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4453 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4454 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4455 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4456 | } |
| 4457 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4458 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4459 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4460 | * @vport: pointer to a host virtual N_Port data structure. |
| 4461 | * |
| 4462 | * This routine handles the Registration State Configuration Notification |
| 4463 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4464 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4465 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4466 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4467 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4468 | * RSCN activities with the @vport. |
| 4469 | * |
| 4470 | * Return code |
| 4471 | * 0 - Cleaned up rscn on the @vport |
| 4472 | * 1 - Wait for plogi to name server before proceed |
| 4473 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4474 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4475 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4476 | { |
| 4477 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4478 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4479 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4480 | /* Ignore RSCN if the port is being torn down. */ |
| 4481 | if (vport->load_flag & FC_UNLOADING) { |
| 4482 | lpfc_els_flush_rscn(vport); |
| 4483 | return 0; |
| 4484 | } |
| 4485 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4486 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4487 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4488 | |
| 4489 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4490 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4491 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4492 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4493 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4494 | |
| 4495 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4496 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4497 | vport->num_disc_nodes = 0; |
| 4498 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4499 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4500 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4501 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4502 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4503 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4504 | /* Wait for NameServer query cmpl before we can |
| 4505 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4506 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4507 | } else { |
| 4508 | /* If login to NameServer does not exist, issue one */ |
| 4509 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4510 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4511 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4512 | /* Wait for NameServer login cmpl before we can |
| 4513 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4514 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4515 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4516 | if (ndlp) { |
| 4517 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4518 | NLP_STE_PLOGI_ISSUE); |
| 4519 | if (!ndlp) { |
| 4520 | lpfc_els_flush_rscn(vport); |
| 4521 | return 0; |
| 4522 | } |
| 4523 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4524 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4525 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4526 | if (!ndlp) { |
| 4527 | lpfc_els_flush_rscn(vport); |
| 4528 | return 0; |
| 4529 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4530 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4531 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4532 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4533 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4534 | ndlp->nlp_type |= NLP_FABRIC; |
| 4535 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4536 | /* Wait for NameServer login cmpl before we can |
| 4537 | * continue |
| 4538 | */ |
| 4539 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4540 | } |
| 4541 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4542 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4543 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4544 | } |
| 4545 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4546 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4547 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4548 | * @vport: pointer to a host virtual N_Port data structure. |
| 4549 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4550 | * @ndlp: pointer to a node-list data structure. |
| 4551 | * |
| 4552 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4553 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4554 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4555 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4556 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4557 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4558 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4559 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4560 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4561 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4562 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4563 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4564 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4565 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4566 | * |
| 4567 | * Return code |
| 4568 | * 0 - Successfully processed the unsolicited flogi |
| 4569 | * 1 - Failed to process the unsolicited flogi |
| 4570 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4571 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4572 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4573 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4574 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4575 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4576 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4577 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4578 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4579 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4580 | struct serv_parm *sp; |
| 4581 | LPFC_MBOXQ_t *mbox; |
| 4582 | struct ls_rjt stat; |
| 4583 | uint32_t cmd, did; |
| 4584 | int rc; |
| 4585 | |
| 4586 | cmd = *lp++; |
| 4587 | sp = (struct serv_parm *) lp; |
| 4588 | |
| 4589 | /* FLOGI received */ |
| 4590 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4591 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4592 | |
| 4593 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4594 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4595 | did = icmd->un.elsreq64.remoteID; |
| 4596 | |
| 4597 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4598 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4599 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4600 | "0113 An FLOGI ELS command x%x was " |
| 4601 | "received from DID x%x in Loop Mode\n", |
| 4602 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4603 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4604 | } |
| 4605 | |
| 4606 | did = Fabric_DID; |
| 4607 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4608 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4609 | /* For a FLOGI we accept, then if our portname is greater |
| 4610 | * then the remote portname we initiate Nport login. |
| 4611 | */ |
| 4612 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4613 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4614 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4615 | |
| 4616 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4617 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4618 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4619 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4620 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4621 | lpfc_linkdown(phba); |
| 4622 | lpfc_init_link(phba, mbox, |
| 4623 | phba->cfg_topology, |
| 4624 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4625 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4626 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4627 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4628 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4629 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4630 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4631 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4632 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4633 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4634 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4635 | spin_lock_irq(shost->host_lock); |
| 4636 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4637 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4638 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4639 | spin_lock_irq(shost->host_lock); |
| 4640 | vport->fc_flag |= FC_PT2PT; |
| 4641 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4642 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4643 | } else { |
| 4644 | /* Reject this request because invalid parameters */ |
| 4645 | stat.un.b.lsRjtRsvd0 = 0; |
| 4646 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4647 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4648 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4649 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4650 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4651 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4655 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4656 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4657 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4658 | } |
| 4659 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4660 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4661 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4662 | * @vport: pointer to a host virtual N_Port data structure. |
| 4663 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4664 | * @ndlp: pointer to a node-list data structure. |
| 4665 | * |
| 4666 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4667 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4668 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4669 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4670 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4671 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4672 | * |
| 4673 | * Return code |
| 4674 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4675 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4676 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4677 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4678 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4679 | { |
| 4680 | struct lpfc_dmabuf *pcmd; |
| 4681 | uint32_t *lp; |
| 4682 | IOCB_t *icmd; |
| 4683 | RNID *rn; |
| 4684 | struct ls_rjt stat; |
| 4685 | uint32_t cmd, did; |
| 4686 | |
| 4687 | icmd = &cmdiocb->iocb; |
| 4688 | did = icmd->un.elsreq64.remoteID; |
| 4689 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4690 | lp = (uint32_t *) pcmd->virt; |
| 4691 | |
| 4692 | cmd = *lp++; |
| 4693 | rn = (RNID *) lp; |
| 4694 | |
| 4695 | /* RNID received */ |
| 4696 | |
| 4697 | switch (rn->Format) { |
| 4698 | case 0: |
| 4699 | case RNID_TOPOLOGY_DISC: |
| 4700 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4701 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4702 | break; |
| 4703 | default: |
| 4704 | /* Reject this request because format not supported */ |
| 4705 | stat.un.b.lsRjtRsvd0 = 0; |
| 4706 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4707 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4708 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4709 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4710 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4711 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4712 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4713 | } |
| 4714 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4715 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4716 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 4717 | * @vport: pointer to a host virtual N_Port data structure. |
| 4718 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4719 | * @ndlp: pointer to a node-list data structure. |
| 4720 | * |
| 4721 | * Return code |
| 4722 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 4723 | **/ |
| 4724 | static int |
| 4725 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4726 | struct lpfc_nodelist *ndlp) |
| 4727 | { |
| 4728 | uint8_t *pcmd; |
| 4729 | |
| 4730 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 4731 | |
| 4732 | /* skip over first word of echo command to find echo data */ |
| 4733 | pcmd += sizeof(uint32_t); |
| 4734 | |
| 4735 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 4736 | return 0; |
| 4737 | } |
| 4738 | |
| 4739 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4740 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4741 | * @vport: pointer to a host virtual N_Port data structure. |
| 4742 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4743 | * @ndlp: pointer to a node-list data structure. |
| 4744 | * |
| 4745 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4746 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4747 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4748 | * |
| 4749 | * Return code |
| 4750 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4751 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4752 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4753 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4754 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4755 | { |
| 4756 | struct ls_rjt stat; |
| 4757 | |
| 4758 | /* For now, unconditionally reject this command */ |
| 4759 | stat.un.b.lsRjtRsvd0 = 0; |
| 4760 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4761 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4762 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4763 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4764 | return 0; |
| 4765 | } |
| 4766 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4767 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4768 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 4769 | * @vport: pointer to a host virtual N_Port data structure. |
| 4770 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4771 | * @ndlp: pointer to a node-list data structure. |
| 4772 | * |
| 4773 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 4774 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 4775 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 4776 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 4777 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 4778 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 4779 | * command request" and reason code explanation "Invalid Originator |
| 4780 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 4781 | * RRQ from the target. |
| 4782 | **/ |
| 4783 | static void |
| 4784 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4785 | struct lpfc_nodelist *ndlp) |
| 4786 | { |
| 4787 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| 4788 | } |
| 4789 | |
| 4790 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4791 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 4792 | * @phba: pointer to lpfc hba data structure. |
| 4793 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4794 | * |
| 4795 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4796 | * mailbox command. This callback function is to actually send the Accept |
| 4797 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4798 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4799 | * mailbox command, constructs the RPS response with the link statistics |
| 4800 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4801 | * response to the RPS. |
| 4802 | * |
| 4803 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4804 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4805 | * will be stored into the context1 field of the IOCB for the completion |
| 4806 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4807 | * |
| 4808 | **/ |
| 4809 | static void |
| 4810 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4811 | { |
| 4812 | MAILBOX_t *mb; |
| 4813 | IOCB_t *icmd; |
| 4814 | struct RLS_RSP *rls_rsp; |
| 4815 | uint8_t *pcmd; |
| 4816 | struct lpfc_iocbq *elsiocb; |
| 4817 | struct lpfc_nodelist *ndlp; |
| 4818 | uint16_t xri; |
| 4819 | uint32_t cmdsize; |
| 4820 | |
| 4821 | mb = &pmb->u.mb; |
| 4822 | |
| 4823 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4824 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
| 4825 | pmb->context1 = NULL; |
| 4826 | pmb->context2 = NULL; |
| 4827 | |
| 4828 | if (mb->mbxStatus) { |
| 4829 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4830 | return; |
| 4831 | } |
| 4832 | |
| 4833 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
| 4834 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4835 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4836 | lpfc_max_els_tries, ndlp, |
| 4837 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4838 | |
| 4839 | /* Decrement the ndlp reference count from previous mbox command */ |
| 4840 | lpfc_nlp_put(ndlp); |
| 4841 | |
| 4842 | if (!elsiocb) |
| 4843 | return; |
| 4844 | |
| 4845 | icmd = &elsiocb->iocb; |
| 4846 | icmd->ulpContext = xri; |
| 4847 | |
| 4848 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4849 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4850 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 4851 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 4852 | |
| 4853 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4854 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4855 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4856 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4857 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4858 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
| 4859 | |
| 4860 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 4861 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4862 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 4863 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4864 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4865 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4866 | ndlp->nlp_rpi); |
| 4867 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 4868 | phba->fc_stat.elsXmitACC++; |
| 4869 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 4870 | lpfc_els_free_iocb(phba, elsiocb); |
| 4871 | } |
| 4872 | |
| 4873 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4874 | * 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] | 4875 | * @phba: pointer to lpfc hba data structure. |
| 4876 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4877 | * |
| 4878 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4879 | * mailbox command. This callback function is to actually send the Accept |
| 4880 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4881 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4882 | * mailbox command, constructs the RPS response with the link statistics |
| 4883 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4884 | * response to the RPS. |
| 4885 | * |
| 4886 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4887 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4888 | * will be stored into the context1 field of the IOCB for the completion |
| 4889 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4890 | * |
| 4891 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4892 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4893 | 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] | 4894 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4895 | MAILBOX_t *mb; |
| 4896 | IOCB_t *icmd; |
| 4897 | RPS_RSP *rps_rsp; |
| 4898 | uint8_t *pcmd; |
| 4899 | struct lpfc_iocbq *elsiocb; |
| 4900 | struct lpfc_nodelist *ndlp; |
| 4901 | uint16_t xri, status; |
| 4902 | uint32_t cmdsize; |
| 4903 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4904 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4905 | |
| 4906 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4907 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4908 | pmb->context1 = NULL; |
| 4909 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4910 | |
| 4911 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4912 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4913 | return; |
| 4914 | } |
| 4915 | |
| 4916 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4917 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4918 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4919 | lpfc_max_els_tries, ndlp, |
| 4920 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4921 | |
| 4922 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4923 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4924 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4925 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4926 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4927 | |
| 4928 | icmd = &elsiocb->iocb; |
| 4929 | icmd->ulpContext = xri; |
| 4930 | |
| 4931 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4932 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4933 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4934 | rps_rsp = (RPS_RSP *)pcmd; |
| 4935 | |
| 4936 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4937 | status = 0x10; |
| 4938 | else |
| 4939 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4940 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4941 | status |= 0x4; |
| 4942 | |
| 4943 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4944 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4945 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4946 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4947 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4948 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4949 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4950 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4951 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4952 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4953 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4954 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4955 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4956 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4957 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4958 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4959 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4960 | 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] | 4961 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4962 | return; |
| 4963 | } |
| 4964 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4965 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4966 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 4967 | * @vport: pointer to a host virtual N_Port data structure. |
| 4968 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4969 | * @ndlp: pointer to a node-list data structure. |
| 4970 | * |
| 4971 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 4972 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4973 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4974 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 4975 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4976 | * for reading the HBA link statistics. It is for the callback function, |
| 4977 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4978 | * to actually sending out RPL Accept (ACC) response. |
| 4979 | * |
| 4980 | * Return codes |
| 4981 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 4982 | **/ |
| 4983 | static int |
| 4984 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4985 | struct lpfc_nodelist *ndlp) |
| 4986 | { |
| 4987 | struct lpfc_hba *phba = vport->phba; |
| 4988 | LPFC_MBOXQ_t *mbox; |
| 4989 | struct lpfc_dmabuf *pcmd; |
| 4990 | struct ls_rjt stat; |
| 4991 | |
| 4992 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4993 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4994 | /* reject the unsolicited RPS request and done with it */ |
| 4995 | goto reject_out; |
| 4996 | |
| 4997 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4998 | |
| 4999 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5000 | if (mbox) { |
| 5001 | lpfc_read_lnk_stat(phba, mbox); |
| 5002 | mbox->context1 = |
| 5003 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
| 5004 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5005 | mbox->vport = vport; |
| 5006 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 5007 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 5008 | != MBX_NOT_FINISHED) |
| 5009 | /* Mbox completion will send ELS Response */ |
| 5010 | return 0; |
| 5011 | /* Decrement reference count used for the failed mbox |
| 5012 | * command. |
| 5013 | */ |
| 5014 | lpfc_nlp_put(ndlp); |
| 5015 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5016 | } |
| 5017 | reject_out: |
| 5018 | /* issue rejection response */ |
| 5019 | stat.un.b.lsRjtRsvd0 = 0; |
| 5020 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5021 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5022 | stat.un.b.vendorUnique = 0; |
| 5023 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5024 | return 0; |
| 5025 | } |
| 5026 | |
| 5027 | /** |
| 5028 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 5029 | * @vport: pointer to a host virtual N_Port data structure. |
| 5030 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5031 | * @ndlp: pointer to a node-list data structure. |
| 5032 | * |
| 5033 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 5034 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5035 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5036 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 5037 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 5038 | * Value (RTV) unsolicited IOCB event. |
| 5039 | * |
| 5040 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5041 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5042 | * will be stored into the context1 field of the IOCB for the completion |
| 5043 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5044 | * |
| 5045 | * Return codes |
| 5046 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 5047 | **/ |
| 5048 | static int |
| 5049 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5050 | struct lpfc_nodelist *ndlp) |
| 5051 | { |
| 5052 | struct lpfc_hba *phba = vport->phba; |
| 5053 | struct ls_rjt stat; |
| 5054 | struct RTV_RSP *rtv_rsp; |
| 5055 | uint8_t *pcmd; |
| 5056 | struct lpfc_iocbq *elsiocb; |
| 5057 | uint32_t cmdsize; |
| 5058 | |
| 5059 | |
| 5060 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5061 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5062 | /* reject the unsolicited RPS request and done with it */ |
| 5063 | goto reject_out; |
| 5064 | |
| 5065 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 5066 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5067 | lpfc_max_els_tries, ndlp, |
| 5068 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5069 | |
| 5070 | if (!elsiocb) |
| 5071 | return 1; |
| 5072 | |
| 5073 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5074 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5075 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 5076 | |
| 5077 | /* use the command's xri in the response */ |
| 5078 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; |
| 5079 | |
| 5080 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 5081 | |
| 5082 | /* populate RTV payload */ |
| 5083 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 5084 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 5085 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 5086 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 5087 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 5088 | |
| 5089 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 5090 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5091 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 5092 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 5093 | "Data: x%x x%x x%x\n", |
| 5094 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5095 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5096 | ndlp->nlp_rpi, |
| 5097 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 5098 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5099 | phba->fc_stat.elsXmitACC++; |
| 5100 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 5101 | lpfc_els_free_iocb(phba, elsiocb); |
| 5102 | return 0; |
| 5103 | |
| 5104 | reject_out: |
| 5105 | /* issue rejection response */ |
| 5106 | stat.un.b.lsRjtRsvd0 = 0; |
| 5107 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5108 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5109 | stat.un.b.vendorUnique = 0; |
| 5110 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5111 | return 0; |
| 5112 | } |
| 5113 | |
| 5114 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5115 | * @vport: pointer to a host virtual N_Port data structure. |
| 5116 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5117 | * @ndlp: pointer to a node-list data structure. |
| 5118 | * |
| 5119 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 5120 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5121 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5122 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 5123 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 5124 | * for reading the HBA link statistics. It is for the callback function, |
| 5125 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 5126 | * to actually sending out RPS Accept (ACC) response. |
| 5127 | * |
| 5128 | * Return codes |
| 5129 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 5130 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5131 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5132 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5133 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5134 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5135 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5136 | uint32_t *lp; |
| 5137 | uint8_t flag; |
| 5138 | LPFC_MBOXQ_t *mbox; |
| 5139 | struct lpfc_dmabuf *pcmd; |
| 5140 | RPS *rps; |
| 5141 | struct ls_rjt stat; |
| 5142 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5143 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5144 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5145 | /* reject the unsolicited RPS request and done with it */ |
| 5146 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5147 | |
| 5148 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5149 | lp = (uint32_t *) pcmd->virt; |
| 5150 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 5151 | rps = (RPS *) lp; |
| 5152 | |
| 5153 | if ((flag == 0) || |
| 5154 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5155 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5156 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5157 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5158 | printk("Fix me....\n"); |
| 5159 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5160 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5161 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5162 | lpfc_read_lnk_stat(phba, mbox); |
| 5163 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5164 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5165 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5166 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5167 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5168 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5169 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5170 | /* Mbox completion will send ELS Response */ |
| 5171 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5172 | /* Decrement reference count used for the failed mbox |
| 5173 | * command. |
| 5174 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5175 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5176 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5177 | } |
| 5178 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5179 | |
| 5180 | reject_out: |
| 5181 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5182 | stat.un.b.lsRjtRsvd0 = 0; |
| 5183 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5184 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5185 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5186 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5187 | return 0; |
| 5188 | } |
| 5189 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5190 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5191 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5192 | * @vport: pointer to a host virtual N_Port data structure. |
| 5193 | * @cmdsize: size of the ELS command. |
| 5194 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5195 | * @ndlp: pointer to a node-list data structure. |
| 5196 | * |
| 5197 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 5198 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 5199 | * |
| 5200 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5201 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5202 | * will be stored into the context1 field of the IOCB for the completion |
| 5203 | * callback function to the RPL Accept Response ELS command. |
| 5204 | * |
| 5205 | * Return code |
| 5206 | * 0 - Successfully issued ACC RPL ELS command |
| 5207 | * 1 - Failed to issue ACC RPL ELS command |
| 5208 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5209 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5210 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 5211 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5212 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5213 | struct lpfc_hba *phba = vport->phba; |
| 5214 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5215 | RPL_RSP rpl_rsp; |
| 5216 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5217 | uint8_t *pcmd; |
| 5218 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5219 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5220 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5221 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5222 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5223 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5224 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5225 | icmd = &elsiocb->iocb; |
| 5226 | oldcmd = &oldiocb->iocb; |
| 5227 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 5228 | |
| 5229 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5230 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5231 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5232 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 5233 | pcmd += sizeof(uint16_t); |
| 5234 | |
| 5235 | /* Setup the RPL ACC payload */ |
| 5236 | rpl_rsp.listLen = be32_to_cpu(1); |
| 5237 | rpl_rsp.index = 0; |
| 5238 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5239 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 5240 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5241 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5242 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5243 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5244 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5245 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 5246 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 5247 | "rpi x%x\n", |
| 5248 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5249 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5250 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5251 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5252 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5253 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 5254 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5255 | lpfc_els_free_iocb(phba, elsiocb); |
| 5256 | return 1; |
| 5257 | } |
| 5258 | return 0; |
| 5259 | } |
| 5260 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5261 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5262 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5263 | * @vport: pointer to a host virtual N_Port data structure. |
| 5264 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5265 | * @ndlp: pointer to a node-list data structure. |
| 5266 | * |
| 5267 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 5268 | * unsolicited event. It first checks the remote port state. If the remote |
| 5269 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 5270 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 5271 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 5272 | * to accept the RPL. |
| 5273 | * |
| 5274 | * Return code |
| 5275 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 5276 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5277 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5278 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5279 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5280 | { |
| 5281 | struct lpfc_dmabuf *pcmd; |
| 5282 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5283 | uint32_t maxsize; |
| 5284 | uint16_t cmdsize; |
| 5285 | RPL *rpl; |
| 5286 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5287 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5288 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5289 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5290 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5291 | stat.un.b.lsRjtRsvd0 = 0; |
| 5292 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5293 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5294 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5295 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5296 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5297 | /* rejected the unsolicited RPL request and done with it */ |
| 5298 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5299 | } |
| 5300 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5301 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5302 | lp = (uint32_t *) pcmd->virt; |
| 5303 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5304 | maxsize = be32_to_cpu(rpl->maxsize); |
| 5305 | |
| 5306 | /* We support only one port */ |
| 5307 | if ((rpl->index == 0) && |
| 5308 | ((maxsize == 0) || |
| 5309 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 5310 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5311 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5312 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 5313 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5314 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5315 | |
| 5316 | return 0; |
| 5317 | } |
| 5318 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5319 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5320 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5321 | * @vport: pointer to a virtual N_Port data structure. |
| 5322 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5323 | * @ndlp: pointer to a node-list data structure. |
| 5324 | * |
| 5325 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5326 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 5327 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 5328 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 5329 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 5330 | * remote PortName is compared against the FC PortName stored in the @vport |
| 5331 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 5332 | * compared against the FC NodeName stored in the @vport data structure. |
| 5333 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 5334 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 5335 | * invoked to send out FARP Response to the remote node. Before sending the |
| 5336 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 5337 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 5338 | * routine is invoked to log into the remote port first. |
| 5339 | * |
| 5340 | * Return code |
| 5341 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 5342 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5343 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5344 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5345 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5346 | { |
| 5347 | struct lpfc_dmabuf *pcmd; |
| 5348 | uint32_t *lp; |
| 5349 | IOCB_t *icmd; |
| 5350 | FARP *fp; |
| 5351 | uint32_t cmd, cnt, did; |
| 5352 | |
| 5353 | icmd = &cmdiocb->iocb; |
| 5354 | did = icmd->un.elsreq64.remoteID; |
| 5355 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5356 | lp = (uint32_t *) pcmd->virt; |
| 5357 | |
| 5358 | cmd = *lp++; |
| 5359 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5360 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5361 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5362 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5363 | /* We will only support match on WWPN or WWNN */ |
| 5364 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5365 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | cnt = 0; |
| 5369 | /* If this FARP command is searching for my portname */ |
| 5370 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5371 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5372 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5373 | cnt = 1; |
| 5374 | } |
| 5375 | |
| 5376 | /* If this FARP command is searching for my nodename */ |
| 5377 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5378 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5379 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5380 | cnt = 1; |
| 5381 | } |
| 5382 | |
| 5383 | if (cnt) { |
| 5384 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 5385 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 5386 | /* Log back into the node before sending the FARP. */ |
| 5387 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5388 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5389 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 5390 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5391 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5392 | } |
| 5393 | |
| 5394 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5395 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 5396 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5397 | } |
| 5398 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5399 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5400 | } |
| 5401 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5402 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5403 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5404 | * @vport: pointer to a host virtual N_Port data structure. |
| 5405 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5406 | * @ndlp: pointer to a node-list data structure. |
| 5407 | * |
| 5408 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5409 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 5410 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 5411 | * the FARP response request. |
| 5412 | * |
| 5413 | * Return code |
| 5414 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 5415 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5416 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5417 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5418 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5419 | { |
| 5420 | struct lpfc_dmabuf *pcmd; |
| 5421 | uint32_t *lp; |
| 5422 | IOCB_t *icmd; |
| 5423 | uint32_t cmd, did; |
| 5424 | |
| 5425 | icmd = &cmdiocb->iocb; |
| 5426 | did = icmd->un.elsreq64.remoteID; |
| 5427 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5428 | lp = (uint32_t *) pcmd->virt; |
| 5429 | |
| 5430 | cmd = *lp++; |
| 5431 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5432 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5433 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5434 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5435 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5436 | |
| 5437 | return 0; |
| 5438 | } |
| 5439 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5440 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5441 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5442 | * @vport: pointer to a host virtual N_Port data structure. |
| 5443 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5444 | * @fan_ndlp: pointer to a node-list data structure. |
| 5445 | * |
| 5446 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 5447 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 5448 | * only be processed on a physical port (i.e., the @vport represents the |
| 5449 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 5450 | * compared against those in the phba data structure. If any of those is |
| 5451 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 5452 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 5453 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 5454 | * is invoked to register login to the fabric. |
| 5455 | * |
| 5456 | * Return code |
| 5457 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 5458 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5459 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5460 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5461 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5462 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5463 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5464 | uint32_t *lp; |
| 5465 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5466 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5467 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 5468 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 5469 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5470 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5471 | if ((vport == phba->pport) && |
| 5472 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5473 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5474 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5475 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5476 | sizeof(struct lpfc_name)))) { |
| 5477 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5478 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5479 | } else { |
| 5480 | /* FAN verified - skip FLOGI */ |
| 5481 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5482 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5483 | lpfc_issue_fabric_reglogin(vport); |
| 5484 | else |
| 5485 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5486 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5487 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5488 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5489 | } |
| 5490 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5491 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5492 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5493 | * @ptr: holder for the timer function associated data. |
| 5494 | * |
| 5495 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5496 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5497 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5498 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5499 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5500 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5501 | void |
| 5502 | lpfc_els_timeout(unsigned long ptr) |
| 5503 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5504 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5505 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5506 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5507 | unsigned long iflag; |
| 5508 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5509 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5510 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5511 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5512 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5513 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5514 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5515 | if (!tmo_posted) |
| 5516 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5517 | return; |
| 5518 | } |
| 5519 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5520 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5521 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5522 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5523 | * @vport: pointer to a virtual N_Port data structure. |
| 5524 | * |
| 5525 | * This routine is the actual handler function that processes an ELS timeout |
| 5526 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5527 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5528 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5529 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5530 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5531 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5532 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5533 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5534 | struct lpfc_sli_ring *pring; |
| 5535 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5536 | IOCB_t *cmd = NULL; |
| 5537 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5538 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5539 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5540 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5541 | LIST_HEAD(txcmplq_completions); |
| 5542 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5543 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5544 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5545 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5546 | |
| 5547 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5548 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5549 | spin_lock_irq(&phba->hbalock); |
| 5550 | list_splice_init(&pring->txcmplq, &txcmplq_completions); |
| 5551 | spin_unlock_irq(&phba->hbalock); |
| 5552 | |
| 5553 | list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5554 | cmd = &piocb->iocb; |
| 5555 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5556 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5557 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5558 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5559 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5560 | |
| 5561 | if (piocb->vport != vport) |
| 5562 | continue; |
| 5563 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5564 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5565 | if (pcmd) |
| 5566 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5567 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5568 | if (els_command == ELS_CMD_FARP || |
| 5569 | els_command == ELS_CMD_FARPR || |
| 5570 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5571 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5572 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5573 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5574 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5575 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5576 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5577 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5578 | continue; |
| 5579 | } |
| 5580 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5581 | remote_ID = 0xffffffff; |
| 5582 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5583 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5584 | else { |
| 5585 | struct lpfc_nodelist *ndlp; |
| 5586 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5587 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5588 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5589 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5590 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5591 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5592 | spin_lock_irq(&phba->hbalock); |
| 5593 | list_splice(&txcmplq_completions, &pring->txcmplq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5594 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5595 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5596 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 5597 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5598 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5599 | "x%x\n", els_command, |
| 5600 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 5601 | spin_lock_irq(&phba->hbalock); |
| 5602 | list_del_init(&piocb->dlist); |
| 5603 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5604 | spin_unlock_irq(&phba->hbalock); |
| 5605 | } |
| 5606 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5607 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5608 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5609 | } |
| 5610 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5611 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5612 | * 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] | 5613 | * @vport: pointer to a host virtual N_Port data structure. |
| 5614 | * |
| 5615 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5616 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5617 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5618 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5619 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5620 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5621 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5622 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5623 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5624 | * completion queue IOCB that is associated with the @vport and is not |
| 5625 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5626 | * part of the discovery state machine) out to HBA by invoking the |
| 5627 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5628 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5629 | * the IOCBs are aborted when this function returns. |
| 5630 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5631 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5632 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5633 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5634 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5635 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5636 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5637 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5638 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5639 | |
| 5640 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5641 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5642 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5643 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5644 | cmd = &piocb->iocb; |
| 5645 | |
| 5646 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5647 | continue; |
| 5648 | } |
| 5649 | |
| 5650 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5651 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5652 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5653 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5654 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5655 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5656 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5657 | if (piocb->vport != vport) |
| 5658 | continue; |
| 5659 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5660 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5661 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5662 | } |
| 5663 | |
| 5664 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5665 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5666 | continue; |
| 5667 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5668 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5669 | if (piocb->vport != vport) |
| 5670 | continue; |
| 5671 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5672 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5673 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5674 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5675 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5676 | /* Cancell all the IOCBs from the completions list */ |
| 5677 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5678 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5679 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5680 | return; |
| 5681 | } |
| 5682 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5683 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5684 | * 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] | 5685 | * @phba: pointer to lpfc hba data structure. |
| 5686 | * |
| 5687 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5688 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5689 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5690 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5691 | * the IOCBs with the completion callback function associated, the callback |
| 5692 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5693 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5694 | * callback function associated, the IOCB will simply be released. Finally, |
| 5695 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5696 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5697 | * management plane IOCBs that are not part of the discovery state machine) |
| 5698 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5699 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5700 | void |
| 5701 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5702 | { |
| 5703 | LIST_HEAD(completions); |
| 5704 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5705 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5706 | IOCB_t *cmd = NULL; |
| 5707 | |
| 5708 | lpfc_fabric_abort_hba(phba); |
| 5709 | spin_lock_irq(&phba->hbalock); |
| 5710 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5711 | cmd = &piocb->iocb; |
| 5712 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5713 | continue; |
| 5714 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5715 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5716 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5717 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5718 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5719 | continue; |
| 5720 | list_move_tail(&piocb->list, &completions); |
| 5721 | pring->txq_cnt--; |
| 5722 | } |
| 5723 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5724 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5725 | continue; |
| 5726 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5727 | } |
| 5728 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5729 | |
| 5730 | /* Cancel all the IOCBs from the completions list */ |
| 5731 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5732 | IOERR_SLI_ABORTED); |
| 5733 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5734 | return; |
| 5735 | } |
| 5736 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5737 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5738 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5739 | * @phba: Pointer to hba context object. |
| 5740 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5741 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5742 | * |
| 5743 | * This function sends an event when there is an ELS command |
| 5744 | * failure. |
| 5745 | **/ |
| 5746 | void |
| 5747 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5748 | struct lpfc_iocbq *cmdiocbp, |
| 5749 | struct lpfc_iocbq *rspiocbp) |
| 5750 | { |
| 5751 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5752 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5753 | struct lpfc_lsrjt_event lsrjt_event; |
| 5754 | struct lpfc_fabric_event_header fabric_event; |
| 5755 | struct ls_rjt stat; |
| 5756 | struct lpfc_nodelist *ndlp; |
| 5757 | uint32_t *pcmd; |
| 5758 | |
| 5759 | ndlp = cmdiocbp->context1; |
| 5760 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5761 | return; |
| 5762 | |
| 5763 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5764 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5765 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5766 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5767 | sizeof(struct lpfc_name)); |
| 5768 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5769 | sizeof(struct lpfc_name)); |
| 5770 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5771 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 5772 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5773 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5774 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5775 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5776 | fc_host_post_vendor_event(shost, |
| 5777 | fc_get_event_number(), |
| 5778 | sizeof(lsrjt_event), |
| 5779 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5780 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5781 | return; |
| 5782 | } |
| 5783 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5784 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5785 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5786 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5787 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5788 | else |
| 5789 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5790 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5791 | sizeof(struct lpfc_name)); |
| 5792 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5793 | sizeof(struct lpfc_name)); |
| 5794 | fc_host_post_vendor_event(shost, |
| 5795 | fc_get_event_number(), |
| 5796 | sizeof(fabric_event), |
| 5797 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5798 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5799 | return; |
| 5800 | } |
| 5801 | |
| 5802 | } |
| 5803 | |
| 5804 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5805 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5806 | * @vport: Pointer to vport object. |
| 5807 | * @ndlp: Pointer FC node object. |
| 5808 | * @cmd: ELS command code. |
| 5809 | * |
| 5810 | * This function posts an event when there is an incoming |
| 5811 | * unsolicited ELS command. |
| 5812 | **/ |
| 5813 | static void |
| 5814 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5815 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5816 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5817 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5818 | struct lpfc_els_event_header *els_data = NULL; |
| 5819 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5820 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5821 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5822 | if (*payload == ELS_CMD_LOGO) { |
| 5823 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5824 | if (!logo_data) { |
| 5825 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5826 | "0148 Failed to allocate memory " |
| 5827 | "for LOGO event\n"); |
| 5828 | return; |
| 5829 | } |
| 5830 | els_data = &logo_data->header; |
| 5831 | } else { |
| 5832 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5833 | GFP_KERNEL); |
| 5834 | if (!els_data) { |
| 5835 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5836 | "0149 Failed to allocate memory " |
| 5837 | "for ELS event\n"); |
| 5838 | return; |
| 5839 | } |
| 5840 | } |
| 5841 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5842 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5843 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5844 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5845 | break; |
| 5846 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5847 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5848 | break; |
| 5849 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5850 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5851 | break; |
| 5852 | case ELS_CMD_LOGO: |
| 5853 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5854 | /* Copy the WWPN in the LOGO payload */ |
| 5855 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5856 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5857 | break; |
| 5858 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5859 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5860 | return; |
| 5861 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5862 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5863 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5864 | if (*payload == ELS_CMD_LOGO) { |
| 5865 | fc_host_post_vendor_event(shost, |
| 5866 | fc_get_event_number(), |
| 5867 | sizeof(struct lpfc_logo_event), |
| 5868 | (char *)logo_data, |
| 5869 | LPFC_NL_VENDOR_ID); |
| 5870 | kfree(logo_data); |
| 5871 | } else { |
| 5872 | fc_host_post_vendor_event(shost, |
| 5873 | fc_get_event_number(), |
| 5874 | sizeof(struct lpfc_els_event_header), |
| 5875 | (char *)els_data, |
| 5876 | LPFC_NL_VENDOR_ID); |
| 5877 | kfree(els_data); |
| 5878 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5879 | |
| 5880 | return; |
| 5881 | } |
| 5882 | |
| 5883 | |
| 5884 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5885 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5886 | * @phba: pointer to lpfc hba data structure. |
| 5887 | * @pring: pointer to a SLI ring. |
| 5888 | * @vport: pointer to a host virtual N_Port data structure. |
| 5889 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5890 | * |
| 5891 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5892 | * event. It first determines whether there is an existing ndlp that matches |
| 5893 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5894 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5895 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5896 | * of the discovery state machine. |
| 5897 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5898 | static void |
| 5899 | 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] | 5900 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5901 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5902 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5903 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5904 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5905 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5906 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5907 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5908 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5909 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5910 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5911 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5912 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5913 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5914 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5915 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5916 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5917 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5918 | did = icmd->un.rcvels.remoteID; |
| 5919 | if (icmd->ulpStatus) { |
| 5920 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5921 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5922 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5923 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5924 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5925 | |
| 5926 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5927 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5928 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5929 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5930 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5931 | if (vport->load_flag & FC_UNLOADING) |
| 5932 | goto dropit; |
| 5933 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5934 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5935 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5936 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5937 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5938 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5939 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5940 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5941 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5942 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5943 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5944 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5945 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5946 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5947 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5948 | NLP_STE_UNUSED_NODE); |
| 5949 | if (!ndlp) |
| 5950 | goto dropit; |
| 5951 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5952 | newnode = 1; |
| 5953 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5954 | ndlp->nlp_type |= NLP_FABRIC; |
| 5955 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5956 | /* This is similar to the new node path */ |
| 5957 | ndlp = lpfc_nlp_get(ndlp); |
| 5958 | if (!ndlp) |
| 5959 | goto dropit; |
| 5960 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5961 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5962 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5963 | |
| 5964 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5965 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5966 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5967 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5968 | |
| 5969 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5970 | cmd &= ELS_CMD_MASK; |
| 5971 | } |
| 5972 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5973 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5974 | "0112 ELS command x%x received from NPORT x%x " |
| 5975 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5976 | switch (cmd) { |
| 5977 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5978 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5979 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5980 | did, vport->port_state, ndlp->nlp_flag); |
| 5981 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5982 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5983 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5984 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5985 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5986 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5987 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5988 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5989 | rjt_err = LSRJT_UNABLE_TPC; |
| 5990 | break; |
| 5991 | } |
| 5992 | /* We get here, and drop thru, if we are PT2PT with |
| 5993 | * another NPort and the other side has initiated |
| 5994 | * the PLOGI before responding to our FLOGI. |
| 5995 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5996 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5997 | |
| 5998 | shost = lpfc_shost_from_vport(vport); |
| 5999 | spin_lock_irq(shost->host_lock); |
| 6000 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 6001 | spin_unlock_irq(shost->host_lock); |
| 6002 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6003 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6004 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6005 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6006 | break; |
| 6007 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6008 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6009 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 6010 | did, vport->port_state, ndlp->nlp_flag); |
| 6011 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6012 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6013 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6014 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6015 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6016 | break; |
| 6017 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6018 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6019 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 6020 | did, vport->port_state, ndlp->nlp_flag); |
| 6021 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6022 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6023 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6024 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6025 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6026 | break; |
| 6027 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6028 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6029 | break; |
| 6030 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6031 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6032 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 6033 | did, vport->port_state, ndlp->nlp_flag); |
| 6034 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6035 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6036 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6037 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6038 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6039 | break; |
| 6040 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6041 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6042 | break; |
| 6043 | case ELS_CMD_RSCN: |
| 6044 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6045 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6046 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6047 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6048 | break; |
| 6049 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6050 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6051 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 6052 | did, vport->port_state, ndlp->nlp_flag); |
| 6053 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6054 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6055 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6056 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6057 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6058 | break; |
| 6059 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6060 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6061 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6062 | break; |
| 6063 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6064 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6065 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 6066 | did, vport->port_state, ndlp->nlp_flag); |
| 6067 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6068 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6069 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6070 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6071 | break; |
| 6072 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6073 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6074 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6075 | break; |
| 6076 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6077 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6078 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 6079 | did, vport->port_state, ndlp->nlp_flag); |
| 6080 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6081 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6082 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6083 | break; |
| 6084 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6085 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6086 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 6087 | did, vport->port_state, ndlp->nlp_flag); |
| 6088 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6089 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6090 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6091 | break; |
| 6092 | case ELS_CMD_FAN: |
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 FAN: 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.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6098 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6099 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6100 | case ELS_CMD_PRLI: |
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 PRLI: 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.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6106 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6107 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6108 | break; |
| 6109 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6110 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6111 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6112 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6113 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6114 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 6115 | did, vport->port_state, ndlp->nlp_flag); |
| 6116 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6117 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6118 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6119 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6120 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6121 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6122 | case ELS_CMD_RLS: |
| 6123 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6124 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 6125 | did, vport->port_state, ndlp->nlp_flag); |
| 6126 | |
| 6127 | phba->fc_stat.elsRcvRLS++; |
| 6128 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 6129 | if (newnode) |
| 6130 | lpfc_nlp_put(ndlp); |
| 6131 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6132 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6133 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6134 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 6135 | did, vport->port_state, ndlp->nlp_flag); |
| 6136 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6137 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6138 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6139 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6140 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6141 | break; |
| 6142 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6143 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6144 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 6145 | did, vport->port_state, ndlp->nlp_flag); |
| 6146 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6147 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6148 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6149 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6150 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6151 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6152 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6153 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6154 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 6155 | did, vport->port_state, ndlp->nlp_flag); |
| 6156 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6157 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6158 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6159 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6160 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6161 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6162 | case ELS_CMD_RTV: |
| 6163 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6164 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 6165 | did, vport->port_state, ndlp->nlp_flag); |
| 6166 | phba->fc_stat.elsRcvRTV++; |
| 6167 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 6168 | if (newnode) |
| 6169 | lpfc_nlp_put(ndlp); |
| 6170 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6171 | case ELS_CMD_RRQ: |
| 6172 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6173 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 6174 | did, vport->port_state, ndlp->nlp_flag); |
| 6175 | |
| 6176 | phba->fc_stat.elsRcvRRQ++; |
| 6177 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 6178 | if (newnode) |
| 6179 | lpfc_nlp_put(ndlp); |
| 6180 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6181 | case ELS_CMD_ECHO: |
| 6182 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6183 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 6184 | did, vport->port_state, ndlp->nlp_flag); |
| 6185 | |
| 6186 | phba->fc_stat.elsRcvECHO++; |
| 6187 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 6188 | if (newnode) |
| 6189 | lpfc_nlp_put(ndlp); |
| 6190 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6191 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6192 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6193 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 6194 | cmd, did, vport->port_state); |
| 6195 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6196 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6197 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6198 | |
| 6199 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6200 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6201 | "0115 Unknown ELS command x%x " |
| 6202 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6203 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6204 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6205 | break; |
| 6206 | } |
| 6207 | |
| 6208 | /* check if need to LS_RJT received ELS cmd */ |
| 6209 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6210 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6211 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 6212 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6213 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 6214 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6215 | } |
| 6216 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6217 | lpfc_nlp_put(elsiocb->context1); |
| 6218 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6219 | return; |
| 6220 | |
| 6221 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6222 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6223 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6224 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6225 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6226 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6227 | phba->fc_stat.elsRcvDrop++; |
| 6228 | } |
| 6229 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6230 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6231 | * 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] | 6232 | * @phba: pointer to lpfc hba data structure. |
| 6233 | * @vpi: host virtual N_Port identifier. |
| 6234 | * |
| 6235 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 6236 | * @vpi. The function walks the HBA's vport list and returns the address |
| 6237 | * of the vport with the matching @vpi. |
| 6238 | * |
| 6239 | * Return code |
| 6240 | * NULL - No vport with the matching @vpi found |
| 6241 | * Otherwise - Address to the vport with the matching @vpi. |
| 6242 | **/ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6243 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6244 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 6245 | { |
| 6246 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6247 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6248 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6249 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6250 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6251 | if (vport->vpi == vpi) { |
| 6252 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6253 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6254 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6255 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6256 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6257 | return NULL; |
| 6258 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6259 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6260 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6261 | * 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] | 6262 | * @phba: pointer to lpfc hba data structure. |
| 6263 | * @pring: pointer to a SLI ring. |
| 6264 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 6265 | * |
| 6266 | * This routine is used to process an unsolicited event received from a SLI |
| 6267 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 6268 | * associated with the unsolicited event is done by invoking the routine |
| 6269 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 6270 | * SLI ring on which the unsolicited event was received. |
| 6271 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6272 | void |
| 6273 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 6274 | struct lpfc_iocbq *elsiocb) |
| 6275 | { |
| 6276 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6277 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6278 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6279 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 6280 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6281 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6282 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6283 | elsiocb->context2 = NULL; |
| 6284 | elsiocb->context3 = NULL; |
| 6285 | |
| 6286 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 6287 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 6288 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 6289 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6290 | phba->fc_stat.NoRcvBuf++; |
| 6291 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6292 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6293 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6294 | return; |
| 6295 | } |
| 6296 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6297 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 6298 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 6299 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 6300 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 6301 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6302 | else |
| 6303 | vport = lpfc_find_vport_by_vpid(phba, |
| 6304 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6305 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6306 | /* If there are no BDEs associated |
| 6307 | * with this IOCB, there is nothing to do. |
| 6308 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6309 | if (icmd->ulpBdeCount == 0) |
| 6310 | return; |
| 6311 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6312 | /* type of ELS cmd is first 32bit word |
| 6313 | * in packet |
| 6314 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6315 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6316 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6317 | } else { |
| 6318 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 6319 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6320 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 6321 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6322 | } |
| 6323 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6324 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 6325 | /* |
| 6326 | * The different unsolicited event handlers would tell us |
| 6327 | * if they are done with "mp" by setting context2 to NULL. |
| 6328 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6329 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6330 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 6331 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6332 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6333 | |
| 6334 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6335 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6336 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6337 | elsiocb->context2 = bdeBuf2; |
| 6338 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6339 | /* free mp if we are done with it */ |
| 6340 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6341 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 6342 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6343 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6344 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6345 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6346 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6347 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6348 | * 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] | 6349 | * @phba: pointer to lpfc hba data structure. |
| 6350 | * @vport: pointer to a virtual N_Port data structure. |
| 6351 | * |
| 6352 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 6353 | * State Change Request (SCR) for a @vport. This routine will create an |
| 6354 | * ndlp for the Name Server associated to the @vport if such node does |
| 6355 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 6356 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 6357 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 6358 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 6359 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6360 | void |
| 6361 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 6362 | { |
| 6363 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 6364 | |
| 6365 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 6366 | if (!ndlp) { |
| 6367 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 6368 | if (!ndlp) { |
| 6369 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 6370 | lpfc_disc_start(vport); |
| 6371 | return; |
| 6372 | } |
| 6373 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6374 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6375 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6376 | return; |
| 6377 | } |
| 6378 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6379 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 6380 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 6381 | if (!ndlp) { |
| 6382 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 6383 | lpfc_disc_start(vport); |
| 6384 | return; |
| 6385 | } |
| 6386 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6387 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6388 | "0348 NameServer login: node freed\n"); |
| 6389 | return; |
| 6390 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6391 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6392 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6393 | |
| 6394 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 6395 | |
| 6396 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 6397 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6398 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6399 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6400 | return; |
| 6401 | } |
| 6402 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6403 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6404 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 6405 | GFP_KERNEL); |
| 6406 | if (ndlp_fdmi) { |
| 6407 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 6408 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6409 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 6410 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6411 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 6412 | 0); |
| 6413 | } |
| 6414 | } |
| 6415 | return; |
| 6416 | } |
| 6417 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6418 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6419 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6420 | * @phba: pointer to lpfc hba data structure. |
| 6421 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6422 | * |
| 6423 | * This routine is the completion callback function to register new vport |
| 6424 | * mailbox command. If the new vport mailbox command completes successfully, |
| 6425 | * the fabric registration login shall be performed on physical port (the |
| 6426 | * new vport created is actually a physical port, with VPI 0) or the port |
| 6427 | * login to Name Server for State Change Request (SCR) will be performed |
| 6428 | * on virtual port (real virtual port, with VPI greater than 0). |
| 6429 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6430 | static void |
| 6431 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6432 | { |
| 6433 | struct lpfc_vport *vport = pmb->vport; |
| 6434 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6435 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6436 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6437 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6438 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6439 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6440 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6441 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6442 | |
| 6443 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6444 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6445 | "0915 Register VPI failed : Status: x%x" |
| 6446 | " upd bit: x%x \n", mb->mbxStatus, |
| 6447 | mb->un.varRegVpi.upd); |
| 6448 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 6449 | mb->un.varRegVpi.upd) |
| 6450 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6451 | |
| 6452 | switch (mb->mbxStatus) { |
| 6453 | case 0x11: /* unsupported feature */ |
| 6454 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6455 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6456 | /* giving up on vport registration */ |
| 6457 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6458 | spin_lock_irq(shost->host_lock); |
| 6459 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6460 | spin_unlock_irq(shost->host_lock); |
| 6461 | lpfc_can_disctmo(vport); |
| 6462 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6463 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 6464 | case 0x20: |
| 6465 | spin_lock_irq(shost->host_lock); |
| 6466 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6467 | spin_unlock_irq(shost->host_lock); |
| 6468 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 6469 | pmb->vport = vport; |
| 6470 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 6471 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 6472 | MBX_NOWAIT); |
| 6473 | if (rc == MBX_NOT_FINISHED) { |
| 6474 | lpfc_printf_vlog(vport, |
| 6475 | KERN_ERR, LOG_MBOX, |
| 6476 | "2732 Failed to issue INIT_VPI" |
| 6477 | " mailbox command\n"); |
| 6478 | } else { |
| 6479 | lpfc_nlp_put(ndlp); |
| 6480 | return; |
| 6481 | } |
| 6482 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6483 | default: |
| 6484 | /* Try to recover from this error */ |
| 6485 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6486 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6487 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6488 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6489 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 6490 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6491 | lpfc_initial_flogi(vport); |
| 6492 | else |
| 6493 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6494 | break; |
| 6495 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6496 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6497 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 6498 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6499 | spin_unlock_irq(shost->host_lock); |
| 6500 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6501 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6502 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6503 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6504 | /* |
| 6505 | * If the physical port is instantiated using |
| 6506 | * FDISC, do not start vport discovery. |
| 6507 | */ |
| 6508 | if (vport->port_state != LPFC_FDISC) |
| 6509 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6510 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6511 | } |
| 6512 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6513 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6514 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6515 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6516 | /* Now, we decrement the ndlp reference count held for this |
| 6517 | * callback function |
| 6518 | */ |
| 6519 | lpfc_nlp_put(ndlp); |
| 6520 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6521 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6522 | return; |
| 6523 | } |
| 6524 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6525 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6526 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6527 | * @phba: pointer to lpfc hba data structure. |
| 6528 | * @vport: pointer to a host virtual N_Port data structure. |
| 6529 | * @ndlp: pointer to a node-list data structure. |
| 6530 | * |
| 6531 | * This routine registers the @vport as a new virtual port with a HBA. |
| 6532 | * It is done through a registering vpi mailbox command. |
| 6533 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6534 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6535 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 6536 | struct lpfc_nodelist *ndlp) |
| 6537 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6538 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6539 | LPFC_MBOXQ_t *mbox; |
| 6540 | |
| 6541 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6542 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6543 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6544 | mbox->vport = vport; |
| 6545 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6546 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6547 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6548 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6549 | /* mailbox command not success, decrement ndlp |
| 6550 | * reference count for this command |
| 6551 | */ |
| 6552 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6553 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6554 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6555 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6556 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6557 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6558 | } |
| 6559 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6560 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6561 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6562 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6563 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6564 | return; |
| 6565 | |
| 6566 | mbox_err_exit: |
| 6567 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6568 | spin_lock_irq(shost->host_lock); |
| 6569 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 6570 | spin_unlock_irq(shost->host_lock); |
| 6571 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6572 | } |
| 6573 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6574 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6575 | * 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] | 6576 | * @phba: pointer to lpfc hba data structure. |
| 6577 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6578 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6579 | **/ |
| 6580 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6581 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6582 | { |
| 6583 | struct lpfc_vport **vports; |
| 6584 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6585 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6586 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6587 | |
| 6588 | /* Treat this failure as linkdown for all vports */ |
| 6589 | link_state = phba->link_state; |
| 6590 | lpfc_linkdown(phba); |
| 6591 | phba->link_state = link_state; |
| 6592 | |
| 6593 | vports = lpfc_create_vport_work_array(phba); |
| 6594 | |
| 6595 | if (vports) { |
| 6596 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6597 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6598 | if (ndlp) |
| 6599 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 6600 | lpfc_els_flush_cmd(vports[i]); |
| 6601 | } |
| 6602 | lpfc_destroy_vport_work_array(phba, vports); |
| 6603 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6604 | } |
| 6605 | |
| 6606 | /** |
| 6607 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 6608 | * @phba: pointer to lpfc hba data structure. |
| 6609 | * |
| 6610 | * This routine abort all pending discovery commands and |
| 6611 | * start a timer to retry FLOGI for the physical port |
| 6612 | * discovery. |
| 6613 | **/ |
| 6614 | void |
| 6615 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 6616 | { |
| 6617 | struct lpfc_nodelist *ndlp; |
| 6618 | struct Scsi_Host *shost; |
| 6619 | |
| 6620 | /* Cancel the all vports retry delay retry timers */ |
| 6621 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6622 | |
| 6623 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 6624 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6625 | if (!ndlp) |
| 6626 | return; |
| 6627 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6628 | shost = lpfc_shost_from_vport(phba->pport); |
| 6629 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 6630 | spin_lock_irq(shost->host_lock); |
| 6631 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 6632 | spin_unlock_irq(shost->host_lock); |
| 6633 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 6634 | phba->pport->port_state = LPFC_FLOGI; |
| 6635 | return; |
| 6636 | } |
| 6637 | |
| 6638 | /** |
| 6639 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 6640 | * @phba: pointer to lpfc hba data structure. |
| 6641 | * @cmdiocb: pointer to FDISC command iocb. |
| 6642 | * @rspiocb: pointer to FDISC response iocb. |
| 6643 | * |
| 6644 | * This routine checks if a FLOGI is reguired for FDISC |
| 6645 | * to succeed. |
| 6646 | **/ |
| 6647 | static int |
| 6648 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 6649 | struct lpfc_iocbq *cmdiocb, |
| 6650 | struct lpfc_iocbq *rspiocb) |
| 6651 | { |
| 6652 | |
| 6653 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 6654 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 6655 | return 0; |
| 6656 | else |
| 6657 | return 1; |
| 6658 | } |
| 6659 | |
| 6660 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6661 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6662 | * @phba: pointer to lpfc hba data structure. |
| 6663 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6664 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6665 | * |
| 6666 | * This routine is the completion callback function to a Fabric Discover |
| 6667 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 6668 | * single threaded, each FDISC completion callback function will reset |
| 6669 | * the discovery timer for all vports such that the timers will not get |
| 6670 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 6671 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 6672 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 6673 | * assigned to the vport has been changed with the completion of the FDISC |
| 6674 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 6675 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 6676 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 6677 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 6678 | * Server for State Change Request (SCR). |
| 6679 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6680 | static void |
| 6681 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6682 | struct lpfc_iocbq *rspiocb) |
| 6683 | { |
| 6684 | struct lpfc_vport *vport = cmdiocb->vport; |
| 6685 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6686 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 6687 | struct lpfc_nodelist *np; |
| 6688 | struct lpfc_nodelist *next_np; |
| 6689 | IOCB_t *irsp = &rspiocb->iocb; |
| 6690 | struct lpfc_iocbq *piocb; |
| 6691 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6692 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6693 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 6694 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 6695 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6696 | /* Since all FDISCs are being single threaded, we |
| 6697 | * must reset the discovery timer for ALL vports |
| 6698 | * waiting to send FDISC when one completes. |
| 6699 | */ |
| 6700 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 6701 | lpfc_set_disctmo(piocb->vport); |
| 6702 | } |
| 6703 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6704 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6705 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6706 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6707 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6708 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6709 | |
| 6710 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 6711 | lpfc_retry_pport_discovery(phba); |
| 6712 | goto out; |
| 6713 | } |
| 6714 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6715 | /* Check for retry */ |
| 6716 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6717 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6718 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6719 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6720 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6721 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6722 | goto fdisc_failed; |
| 6723 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6724 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6725 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6726 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6727 | vport->fc_flag |= FC_FABRIC; |
| 6728 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 6729 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6730 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6731 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6732 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6733 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6734 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6735 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6736 | /* If our NportID changed, we need to ensure all |
| 6737 | * remaining NPORTs get unreg_login'ed so we can |
| 6738 | * issue unreg_vpi. |
| 6739 | */ |
| 6740 | list_for_each_entry_safe(np, next_np, |
| 6741 | &vport->fc_nodes, nlp_listp) { |
| 6742 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6743 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6744 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6745 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6746 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6747 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6748 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6749 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6750 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6751 | lpfc_cleanup_pending_mbox(vport); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6752 | lpfc_mbx_unreg_vpi(vport); |
| 6753 | spin_lock_irq(shost->host_lock); |
| 6754 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6755 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6756 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6757 | else |
| 6758 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6759 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6760 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 6761 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6762 | /* |
| 6763 | * Driver needs to re-reg VPI in order for f/w |
| 6764 | * to update the MAC address. |
| 6765 | */ |
| 6766 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 6767 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6768 | } |
| 6769 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6770 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 6771 | lpfc_issue_init_vpi(vport); |
| 6772 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6773 | lpfc_register_new_vport(phba, vport, ndlp); |
| 6774 | else |
| 6775 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6776 | goto out; |
| 6777 | fdisc_failed: |
| 6778 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6779 | /* Cancel discovery timer */ |
| 6780 | lpfc_can_disctmo(vport); |
| 6781 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6782 | out: |
| 6783 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6784 | } |
| 6785 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6786 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6787 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6788 | * @vport: pointer to a virtual N_Port data structure. |
| 6789 | * @ndlp: pointer to a node-list data structure. |
| 6790 | * @retry: number of retries to the command IOCB. |
| 6791 | * |
| 6792 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6793 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6794 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6795 | * IOCB will be sent off HBA at any given time. |
| 6796 | * |
| 6797 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6798 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6799 | * will be stored into the context1 field of the IOCB for the completion |
| 6800 | * callback function to the FDISC ELS command. |
| 6801 | * |
| 6802 | * Return code |
| 6803 | * 0 - Successfully issued fdisc iocb command |
| 6804 | * 1 - Failed to issue fdisc iocb command |
| 6805 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6806 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6807 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6808 | uint8_t retry) |
| 6809 | { |
| 6810 | struct lpfc_hba *phba = vport->phba; |
| 6811 | IOCB_t *icmd; |
| 6812 | struct lpfc_iocbq *elsiocb; |
| 6813 | struct serv_parm *sp; |
| 6814 | uint8_t *pcmd; |
| 6815 | uint16_t cmdsize; |
| 6816 | int did = ndlp->nlp_DID; |
| 6817 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6818 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6819 | vport->port_state = LPFC_FDISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6820 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6821 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6822 | ELS_CMD_FDISC); |
| 6823 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6824 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6825 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6826 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6827 | return 1; |
| 6828 | } |
| 6829 | |
| 6830 | icmd = &elsiocb->iocb; |
| 6831 | icmd->un.elsreq64.myID = 0; |
| 6832 | icmd->un.elsreq64.fl = 1; |
| 6833 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6834 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 6835 | /* FDISC needs to be 1 for WQE VPI */ |
| 6836 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 6837 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 6838 | /* Set the ulpContext to the vpi */ |
| 6839 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 6840 | } else { |
| 6841 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6842 | icmd->ulpCt_h = 1; |
| 6843 | icmd->ulpCt_l = 0; |
| 6844 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6845 | |
| 6846 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6847 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6848 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6849 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6850 | sp = (struct serv_parm *) pcmd; |
| 6851 | /* Setup CSPs accordingly for Fabric */ |
| 6852 | sp->cmn.e_d_tov = 0; |
| 6853 | sp->cmn.w2.r_a_tov = 0; |
| 6854 | sp->cls1.classValid = 0; |
| 6855 | sp->cls2.seqDelivery = 1; |
| 6856 | sp->cls3.seqDelivery = 1; |
| 6857 | |
| 6858 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6859 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6860 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6861 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6862 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6863 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6864 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6865 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6866 | |
| 6867 | lpfc_set_disctmo(vport); |
| 6868 | |
| 6869 | phba->fc_stat.elsXmitFDISC++; |
| 6870 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6871 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6872 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6873 | "Issue FDISC: did:x%x", |
| 6874 | did, 0, 0); |
| 6875 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6876 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6877 | if (rc == IOCB_ERROR) { |
| 6878 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6879 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6880 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6881 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6882 | return 1; |
| 6883 | } |
| 6884 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6885 | return 0; |
| 6886 | } |
| 6887 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6888 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6889 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6890 | * @phba: pointer to lpfc hba data structure. |
| 6891 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6892 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6893 | * |
| 6894 | * This routine is the completion callback function to the issuing of a LOGO |
| 6895 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6896 | * reference count held on ndlp for this completion function, indicating that |
| 6897 | * the reference to the ndlp is no long needed. Note that the |
| 6898 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6899 | * callback function and an additional explicit ndlp reference decrementation |
| 6900 | * will trigger the actual release of the ndlp. |
| 6901 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6902 | static void |
| 6903 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6904 | struct lpfc_iocbq *rspiocb) |
| 6905 | { |
| 6906 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6907 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6908 | struct lpfc_nodelist *ndlp; |
| 6909 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6910 | |
| 6911 | irsp = &rspiocb->iocb; |
| 6912 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6913 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6914 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6915 | |
| 6916 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6917 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6918 | |
| 6919 | /* Trigger the release of the ndlp after logo */ |
| 6920 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 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_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6925 | * @vport: pointer to a virtual N_Port data structure. |
| 6926 | * @ndlp: pointer to a node-list data structure. |
| 6927 | * |
| 6928 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6929 | * |
| 6930 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6931 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6932 | * will be stored into the context1 field of the IOCB for the completion |
| 6933 | * callback function to the LOGO ELS command. |
| 6934 | * |
| 6935 | * Return codes |
| 6936 | * 0 - Successfully issued logo off the @vport |
| 6937 | * 1 - Failed to issue logo off the @vport |
| 6938 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6939 | int |
| 6940 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6941 | { |
| 6942 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6943 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6944 | IOCB_t *icmd; |
| 6945 | struct lpfc_iocbq *elsiocb; |
| 6946 | uint8_t *pcmd; |
| 6947 | uint16_t cmdsize; |
| 6948 | |
| 6949 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6950 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6951 | ELS_CMD_LOGO); |
| 6952 | if (!elsiocb) |
| 6953 | return 1; |
| 6954 | |
| 6955 | icmd = &elsiocb->iocb; |
| 6956 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6957 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6958 | pcmd += sizeof(uint32_t); |
| 6959 | |
| 6960 | /* Fill in LOGO payload */ |
| 6961 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6962 | pcmd += sizeof(uint32_t); |
| 6963 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6964 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6965 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6966 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6967 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6968 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6969 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6970 | spin_lock_irq(shost->host_lock); |
| 6971 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6972 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6973 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6974 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6975 | spin_lock_irq(shost->host_lock); |
| 6976 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6977 | spin_unlock_irq(shost->host_lock); |
| 6978 | lpfc_els_free_iocb(phba, elsiocb); |
| 6979 | return 1; |
| 6980 | } |
| 6981 | return 0; |
| 6982 | } |
| 6983 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6984 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6985 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6986 | * @ptr: holder for the timer function associated data. |
| 6987 | * |
| 6988 | * This routine is invoked by the fabric iocb block timer after |
| 6989 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6990 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6991 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6992 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6993 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6994 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6995 | void |
| 6996 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6997 | { |
| 6998 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6999 | unsigned long iflags; |
| 7000 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7001 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7002 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 7003 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 7004 | if (!tmo_posted) |
| 7005 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 7006 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 7007 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7008 | if (!tmo_posted) |
| 7009 | lpfc_worker_wake_up(phba); |
| 7010 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7011 | } |
| 7012 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7013 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7014 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7015 | * @phba: pointer to lpfc hba data structure. |
| 7016 | * |
| 7017 | * This routine issues one fabric iocb from the driver internal list to |
| 7018 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 7019 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 7020 | * remove one pending fabric iocb from the driver internal list and invokes |
| 7021 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 7022 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7023 | static void |
| 7024 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 7025 | { |
| 7026 | struct lpfc_iocbq *iocb; |
| 7027 | unsigned long iflags; |
| 7028 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7029 | IOCB_t *cmd; |
| 7030 | |
| 7031 | repeat: |
| 7032 | iocb = NULL; |
| 7033 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7034 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7035 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 7036 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 7037 | list); |
| 7038 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7039 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7040 | atomic_inc(&phba->fabric_iocb_count); |
| 7041 | } |
| 7042 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7043 | if (iocb) { |
| 7044 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7045 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7046 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7047 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7048 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7049 | "Fabric sched1: ste:x%x", |
| 7050 | iocb->vport->port_state, 0, 0); |
| 7051 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7052 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7053 | |
| 7054 | if (ret == IOCB_ERROR) { |
| 7055 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7056 | iocb->fabric_iocb_cmpl = NULL; |
| 7057 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7058 | cmd = &iocb->iocb; |
| 7059 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 7060 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 7061 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 7062 | |
| 7063 | atomic_dec(&phba->fabric_iocb_count); |
| 7064 | goto repeat; |
| 7065 | } |
| 7066 | } |
| 7067 | |
| 7068 | return; |
| 7069 | } |
| 7070 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7071 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7072 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7073 | * @phba: pointer to lpfc hba data structure. |
| 7074 | * |
| 7075 | * This routine unblocks the issuing fabric iocb command. The function |
| 7076 | * will clear the fabric iocb block bit and then invoke the routine |
| 7077 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 7078 | * from the driver internal fabric iocb list. |
| 7079 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7080 | void |
| 7081 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 7082 | { |
| 7083 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7084 | |
| 7085 | lpfc_resume_fabric_iocbs(phba); |
| 7086 | return; |
| 7087 | } |
| 7088 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7089 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7090 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7091 | * @phba: pointer to lpfc hba data structure. |
| 7092 | * |
| 7093 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 7094 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 7095 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 7096 | * fabric iocb will be issued out of the HBA. |
| 7097 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7098 | static void |
| 7099 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 7100 | { |
| 7101 | int blocked; |
| 7102 | |
| 7103 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7104 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7105 | if (!blocked) |
| 7106 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 7107 | |
| 7108 | return; |
| 7109 | } |
| 7110 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7111 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7112 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7113 | * @phba: pointer to lpfc hba data structure. |
| 7114 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7115 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7116 | * |
| 7117 | * This routine is the callback function that is put to the fabric iocb's |
| 7118 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 7119 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 7120 | * function first restores and invokes the original iocb's callback function |
| 7121 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 7122 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 7123 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7124 | static void |
| 7125 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7126 | struct lpfc_iocbq *rspiocb) |
| 7127 | { |
| 7128 | struct ls_rjt stat; |
| 7129 | |
| 7130 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 7131 | BUG(); |
| 7132 | |
| 7133 | switch (rspiocb->iocb.ulpStatus) { |
| 7134 | case IOSTAT_NPORT_RJT: |
| 7135 | case IOSTAT_FABRIC_RJT: |
| 7136 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 7137 | lpfc_block_fabric_iocbs(phba); |
| 7138 | } |
| 7139 | break; |
| 7140 | |
| 7141 | case IOSTAT_NPORT_BSY: |
| 7142 | case IOSTAT_FABRIC_BSY: |
| 7143 | lpfc_block_fabric_iocbs(phba); |
| 7144 | break; |
| 7145 | |
| 7146 | case IOSTAT_LS_RJT: |
| 7147 | stat.un.lsRjtError = |
| 7148 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 7149 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 7150 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 7151 | lpfc_block_fabric_iocbs(phba); |
| 7152 | break; |
| 7153 | } |
| 7154 | |
| 7155 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 7156 | BUG(); |
| 7157 | |
| 7158 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 7159 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 7160 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7161 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 7162 | |
| 7163 | atomic_dec(&phba->fabric_iocb_count); |
| 7164 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7165 | /* Post any pending iocbs to HBA */ |
| 7166 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7167 | } |
| 7168 | } |
| 7169 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7170 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7171 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7172 | * @phba: pointer to lpfc hba data structure. |
| 7173 | * @iocb: pointer to lpfc command iocb data structure. |
| 7174 | * |
| 7175 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 7176 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 7177 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 7178 | * any given time. As such, this function will first check to see whether there |
| 7179 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 7180 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 7181 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 7182 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 7183 | * |
| 7184 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 7185 | * order. The problem is caused by the construction of the "ready" boolen does |
| 7186 | * not include the condition that the internal fabric IOCB list is empty. As |
| 7187 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 7188 | * ahead of the fabric IOCBs in the internal list. |
| 7189 | * |
| 7190 | * Return code |
| 7191 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 7192 | * IOCB_ERROR - failed to issue fabric iocb |
| 7193 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7194 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7195 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 7196 | { |
| 7197 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7198 | int ready; |
| 7199 | int ret; |
| 7200 | |
| 7201 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 7202 | BUG(); |
| 7203 | |
| 7204 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7205 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 7206 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7207 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7208 | if (ready) |
| 7209 | /* Increment fabric iocb count to hold the position */ |
| 7210 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7211 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7212 | if (ready) { |
| 7213 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7214 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7215 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7216 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7217 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7218 | "Fabric sched2: ste:x%x", |
| 7219 | iocb->vport->port_state, 0, 0); |
| 7220 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7221 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7222 | |
| 7223 | if (ret == IOCB_ERROR) { |
| 7224 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7225 | iocb->fabric_iocb_cmpl = NULL; |
| 7226 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7227 | atomic_dec(&phba->fabric_iocb_count); |
| 7228 | } |
| 7229 | } else { |
| 7230 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7231 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 7232 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7233 | ret = IOCB_SUCCESS; |
| 7234 | } |
| 7235 | return ret; |
| 7236 | } |
| 7237 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7238 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7239 | * 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] | 7240 | * @vport: pointer to a virtual N_Port data structure. |
| 7241 | * |
| 7242 | * This routine aborts all the IOCBs associated with a @vport from the |
| 7243 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7244 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7245 | * list, removes each IOCB associated with the @vport off the list, set the |
| 7246 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7247 | * associated with the IOCB. |
| 7248 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7249 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7250 | { |
| 7251 | LIST_HEAD(completions); |
| 7252 | struct lpfc_hba *phba = vport->phba; |
| 7253 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7254 | |
| 7255 | spin_lock_irq(&phba->hbalock); |
| 7256 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7257 | list) { |
| 7258 | |
| 7259 | if (piocb->vport != vport) |
| 7260 | continue; |
| 7261 | |
| 7262 | list_move_tail(&piocb->list, &completions); |
| 7263 | } |
| 7264 | spin_unlock_irq(&phba->hbalock); |
| 7265 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7266 | /* Cancel all the IOCBs from the completions list */ |
| 7267 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7268 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7269 | } |
| 7270 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7271 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7272 | * 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] | 7273 | * @ndlp: pointer to a node-list data structure. |
| 7274 | * |
| 7275 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 7276 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7277 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7278 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 7279 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7280 | * associated with the IOCB. |
| 7281 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7282 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 7283 | { |
| 7284 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7285 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7286 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7287 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7288 | |
| 7289 | spin_lock_irq(&phba->hbalock); |
| 7290 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7291 | list) { |
| 7292 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 7293 | |
| 7294 | list_move_tail(&piocb->list, &completions); |
| 7295 | } |
| 7296 | } |
| 7297 | spin_unlock_irq(&phba->hbalock); |
| 7298 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7299 | /* Cancel all the IOCBs from the completions list */ |
| 7300 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7301 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7302 | } |
| 7303 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7304 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7305 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7306 | * @phba: pointer to lpfc hba data structure. |
| 7307 | * |
| 7308 | * This routine aborts all the IOCBs currently on the driver internal |
| 7309 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 7310 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 7311 | * list, removes IOCBs off the list, set the status feild to |
| 7312 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 7313 | * the IOCB. |
| 7314 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7315 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 7316 | { |
| 7317 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7318 | |
| 7319 | spin_lock_irq(&phba->hbalock); |
| 7320 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 7321 | spin_unlock_irq(&phba->hbalock); |
| 7322 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7323 | /* Cancel all the IOCBs from the completions list */ |
| 7324 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7325 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7326 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7327 | |
| 7328 | /** |
| 7329 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 7330 | * @phba: pointer to lpfc hba data structure. |
| 7331 | * @axri: pointer to the els xri abort wcqe structure. |
| 7332 | * |
| 7333 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 7334 | * ELS aborted xri. |
| 7335 | **/ |
| 7336 | void |
| 7337 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 7338 | struct sli4_wcqe_xri_aborted *axri) |
| 7339 | { |
| 7340 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 7341 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7342 | unsigned long iflag = 0; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7343 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7344 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7345 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7346 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7347 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 7348 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 7349 | if (sglq_entry->sli4_xritag == xri) { |
| 7350 | list_del(&sglq_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7351 | list_add_tail(&sglq_entry->list, |
| 7352 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7353 | sglq_entry->state = SGL_FREED; |
| 7354 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7355 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7356 | |
| 7357 | /* Check if TXQ queue needs to be serviced */ |
| 7358 | if (pring->txq_cnt) |
| 7359 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7360 | return; |
| 7361 | } |
| 7362 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7363 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 7364 | sglq_entry = __lpfc_get_active_sglq(phba, xri); |
| 7365 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
| 7366 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7367 | return; |
| 7368 | } |
| 7369 | sglq_entry->state = SGL_XRI_ABORTED; |
| 7370 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7371 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7372 | } |