| 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 | |
| 520 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 521 | |
| 522 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 523 | spin_lock_irq(shost->host_lock); |
| 524 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 525 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 526 | } else { |
| 527 | /* |
| 528 | * If we are a N-port connected to a Fabric, fixup sparam's so |
| 529 | * logins to devices on remote loops work. |
| 530 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 531 | vport->fc_sparam.cmn.altBbCredit = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 532 | } |
| 533 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 534 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 535 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 536 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 537 | ndlp->nlp_class_sup = 0; |
| 538 | if (sp->cls1.classValid) |
| 539 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 540 | if (sp->cls2.classValid) |
| 541 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 542 | if (sp->cls3.classValid) |
| 543 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 544 | if (sp->cls4.classValid) |
| 545 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 546 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 547 | sp->cmn.bbRcvSizeLsb; |
| 548 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 549 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 550 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 551 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 552 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 553 | LOG_ELS | LOG_VPORT, |
| 554 | "1816 FLOGI NPIV supported, " |
| 555 | "response data 0x%x\n", |
| 556 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 557 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 558 | } else { |
| 559 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 560 | to call reg_vnpid atleast for the physcial host */ |
| 561 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 562 | LOG_ELS | LOG_VPORT, |
| 563 | "1817 Fabric does not support NPIV " |
| 564 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 565 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 570 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 571 | |
| 572 | /* If our NportID changed, we need to ensure all |
| 573 | * remaining NPORTs get unreg_login'ed. |
| 574 | */ |
| 575 | list_for_each_entry_safe(np, next_np, |
| 576 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 577 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 578 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 579 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 580 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 581 | continue; |
| 582 | spin_lock_irq(shost->host_lock); |
| 583 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 584 | spin_unlock_irq(shost->host_lock); |
| 585 | lpfc_unreg_rpi(vport, np); |
| 586 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 587 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 588 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 589 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 590 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 591 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 592 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 593 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 594 | /* |
| 595 | * If VPI is unreged, driver need to do INIT_VPI |
| 596 | * before re-registering |
| 597 | */ |
| 598 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 599 | spin_lock_irq(shost->host_lock); |
| 600 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 601 | spin_unlock_irq(shost->host_lock); |
| 602 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 603 | } |
| 604 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 605 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 606 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 607 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 608 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 609 | lpfc_register_new_vport(phba, vport, ndlp); |
| 610 | else |
| 611 | lpfc_issue_fabric_reglogin(vport); |
| 612 | } else { |
| 613 | ndlp->nlp_type |= NLP_FABRIC; |
| 614 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 615 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 616 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 617 | lpfc_start_fdiscs(phba); |
| 618 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 619 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 620 | lpfc_issue_init_vpi(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 621 | else |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 622 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 623 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 624 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 625 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 626 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 627 | * 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] | 628 | * @vport: pointer to a host virtual N_Port data structure. |
| 629 | * @ndlp: pointer to a node-list data structure. |
| 630 | * @sp: pointer to service parameter data structure. |
| 631 | * |
| 632 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 633 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 634 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 635 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 636 | * the received N_Port Name lexicographically, this node shall assign local |
| 637 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 638 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 639 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 640 | * N_Port IDs. |
| 641 | * |
| 642 | * Return code |
| 643 | * 0 - Success |
| 644 | * -ENXIO - Fail |
| 645 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 646 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 647 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 648 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 649 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 650 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 651 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 652 | LPFC_MBOXQ_t *mbox; |
| 653 | int rc; |
| 654 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 655 | spin_lock_irq(shost->host_lock); |
| 656 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 657 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 658 | |
| 659 | phba->fc_edtov = FF_DEF_EDTOV; |
| 660 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 661 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 662 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 663 | if (rc >= 0) { |
| 664 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 665 | spin_lock_irq(shost->host_lock); |
| 666 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 667 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 668 | |
| 669 | /* |
| 670 | * N_Port ID cannot be 0, set our to LocalID the other |
| 671 | * side will be RemoteID. |
| 672 | */ |
| 673 | |
| 674 | /* not equal */ |
| 675 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 676 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 677 | |
| 678 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 679 | if (!mbox) |
| 680 | goto fail; |
| 681 | |
| 682 | lpfc_config_link(phba, mbox); |
| 683 | |
| 684 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 685 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 686 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 687 | if (rc == MBX_NOT_FINISHED) { |
| 688 | mempool_free(mbox, phba->mbox_mem_pool); |
| 689 | goto fail; |
| 690 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 691 | /* Decrement ndlp reference count indicating that ndlp can be |
| 692 | * safely released when other references to it are done. |
| 693 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 694 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 695 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 696 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 697 | if (!ndlp) { |
| 698 | /* |
| 699 | * Cannot find existing Fabric ndlp, so allocate a |
| 700 | * new one |
| 701 | */ |
| 702 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 703 | if (!ndlp) |
| 704 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 705 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 706 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 707 | ndlp = lpfc_enable_node(vport, ndlp, |
| 708 | NLP_STE_UNUSED_NODE); |
| 709 | if(!ndlp) |
| 710 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 714 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 715 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 716 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 717 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 718 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 719 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 720 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 721 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 722 | } else |
| 723 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 724 | * count indicating that ndlp can be released when other |
| 725 | * references to it are done. |
| 726 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 727 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 728 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 729 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 730 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 731 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 732 | spin_lock_irq(shost->host_lock); |
| 733 | vport->fc_flag |= FC_PT2PT; |
| 734 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 735 | |
| 736 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 737 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 738 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 739 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 740 | return -ENXIO; |
| 741 | } |
| 742 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 743 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 744 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 745 | * @phba: pointer to lpfc hba data structure. |
| 746 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 747 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 748 | * |
| 749 | * This routine is the top-level completion callback function for issuing |
| 750 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 751 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 752 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 753 | * returning 1), the command IOCB will be released and function returned. |
| 754 | * If the retry attempt has been given up (possibly reach the maximum |
| 755 | * number of retries), one additional decrement of ndlp reference shall be |
| 756 | * invoked before going out after releasing the command IOCB. This will |
| 757 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 758 | * invoke one decrement of ndlp reference count). If no error reported in |
| 759 | * the IOCB status, the command Port ID field is used to determine whether |
| 760 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 761 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 762 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 763 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 764 | * specific topology completion conditions. |
| 765 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 766 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 767 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 768 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 769 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 770 | struct lpfc_vport *vport = cmdiocb->vport; |
| 771 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 772 | IOCB_t *irsp = &rspiocb->iocb; |
| 773 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 774 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 775 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 776 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 777 | int rc; |
| 778 | |
| 779 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 780 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 781 | /* One additional decrement on node reference count to |
| 782 | * trigger the release of the node |
| 783 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 784 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 785 | goto out; |
| 786 | } |
| 787 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 788 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 789 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 790 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 791 | vport->port_state); |
| 792 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 793 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 794 | /* |
| 795 | * In case of FIP mode, perform round robin FCF failover |
| 796 | * due to new FCF discovery |
| 797 | */ |
| 798 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
| 799 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 800 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 801 | "2611 FLOGI failed on registered " |
| 802 | "FCF record fcf_index:%d, trying " |
| 803 | "to perform round robin failover\n", |
| 804 | phba->fcf.current_rec.fcf_indx); |
| 805 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 806 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 807 | /* |
| 808 | * Exhausted the eligible FCF record list, |
| 809 | * fail through to retry FLOGI on current |
| 810 | * FCF record. |
| 811 | */ |
| 812 | lpfc_printf_log(phba, KERN_WARNING, |
| 813 | LOG_FIP | LOG_ELS, |
| 814 | "2760 FLOGI exhausted FCF " |
| 815 | "round robin failover list, " |
| 816 | "retry FLOGI on the current " |
| 817 | "registered FCF index:%d\n", |
| 818 | phba->fcf.current_rec.fcf_indx); |
| 819 | spin_lock_irq(&phba->hbalock); |
| 820 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 821 | spin_unlock_irq(&phba->hbalock); |
| 822 | } else { |
| 823 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, |
| 824 | fcf_index); |
| 825 | if (rc) { |
| 826 | lpfc_printf_log(phba, KERN_WARNING, |
| 827 | LOG_FIP | LOG_ELS, |
| 828 | "2761 FLOGI round " |
| 829 | "robin FCF failover " |
| 830 | "read FCF failed " |
| 831 | "rc:x%x, fcf_index:" |
| 832 | "%d\n", rc, |
| 833 | phba->fcf.current_rec.fcf_indx); |
| 834 | spin_lock_irq(&phba->hbalock); |
| 835 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 836 | spin_unlock_irq(&phba->hbalock); |
| 837 | } else |
| 838 | goto out; |
| 839 | } |
| 840 | } |
| 841 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 842 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 843 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 845 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 846 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 847 | spin_lock_irq(shost->host_lock); |
| 848 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 849 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 850 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 851 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 852 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 853 | * alpa map would take too long otherwise. |
| 854 | */ |
| 855 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 856 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | /* FLOGI failure */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 860 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 861 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 862 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 863 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 864 | goto flogifail; |
| 865 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 866 | spin_lock_irq(shost->host_lock); |
| 867 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 868 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 869 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 870 | |
| 871 | /* |
| 872 | * The FLogI succeeded. Sync the data for the CPU before |
| 873 | * accessing it. |
| 874 | */ |
| 875 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 876 | |
| 877 | sp = prsp->virt + sizeof(uint32_t); |
| 878 | |
| 879 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 880 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 881 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 882 | "Data: x%x x%x x%x x%x\n", |
| 883 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 884 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 885 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 886 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 887 | /* |
| 888 | * If Common Service Parameters indicate Nport |
| 889 | * we are point to point, if Fport we are Fabric. |
| 890 | */ |
| 891 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 892 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 893 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 894 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 895 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 896 | if (!rc) { |
| 897 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 898 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 899 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 900 | LOG_ELS, |
| 901 | "2769 FLOGI successful on FCF " |
| 902 | "record: current_fcf_index:" |
| 903 | "x%x, terminate FCF round " |
| 904 | "robin failover process\n", |
| 905 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 906 | spin_lock_irq(&phba->hbalock); |
| 907 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 908 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 909 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 910 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 914 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 915 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 916 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 917 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 918 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 919 | |
| 920 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 921 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 922 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 923 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 924 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 925 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 926 | /* If FLOGI failed enable link interrupt. */ |
| 927 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 928 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 929 | out: |
| 930 | lpfc_els_free_iocb(phba, cmdiocb); |
| 931 | } |
| 932 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 933 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 934 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 935 | * @vport: pointer to a host virtual N_Port data structure. |
| 936 | * @ndlp: pointer to a node-list data structure. |
| 937 | * @retry: number of retries to the command IOCB. |
| 938 | * |
| 939 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 940 | * for a @vport. The initiator service parameters are put into the payload |
| 941 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 942 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 943 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 944 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 945 | * |
| 946 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 947 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 948 | * will be stored into the context1 field of the IOCB for the completion |
| 949 | * callback function to the FLOGI ELS command. |
| 950 | * |
| 951 | * Return code |
| 952 | * 0 - successfully issued flogi iocb for @vport |
| 953 | * 1 - failed to issue flogi iocb for @vport |
| 954 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 955 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 956 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 957 | uint8_t retry) |
| 958 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 959 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 960 | struct serv_parm *sp; |
| 961 | IOCB_t *icmd; |
| 962 | struct lpfc_iocbq *elsiocb; |
| 963 | struct lpfc_sli_ring *pring; |
| 964 | uint8_t *pcmd; |
| 965 | uint16_t cmdsize; |
| 966 | uint32_t tmo; |
| 967 | int rc; |
| 968 | |
| 969 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 970 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 971 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 972 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 973 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 974 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 975 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 976 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 977 | |
| 978 | icmd = &elsiocb->iocb; |
| 979 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 980 | |
| 981 | /* For FLOGI request, remainder of payload is service parameters */ |
| 982 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 983 | pcmd += sizeof(uint32_t); |
| 984 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 985 | sp = (struct serv_parm *) pcmd; |
| 986 | |
| 987 | /* Setup CSPs accordingly for Fabric */ |
| 988 | sp->cmn.e_d_tov = 0; |
| 989 | sp->cmn.w2.r_a_tov = 0; |
| 990 | sp->cls1.classValid = 0; |
| 991 | sp->cls2.seqDelivery = 1; |
| 992 | sp->cls3.seqDelivery = 1; |
| 993 | if (sp->cmn.fcphLow < FC_PH3) |
| 994 | sp->cmn.fcphLow = FC_PH3; |
| 995 | if (sp->cmn.fcphHigh < FC_PH3) |
| 996 | sp->cmn.fcphHigh = FC_PH3; |
| 997 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 998 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 999 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1000 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1001 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1002 | /* Set the fcfi to the fcfi we registered with */ |
| 1003 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1004 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1005 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1006 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1007 | icmd->ulpCt_h = 1; |
| 1008 | icmd->ulpCt_l = 0; |
| 1009 | } |
| 1010 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1011 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 1012 | icmd->un.elsreq64.myID = 0; |
| 1013 | icmd->un.elsreq64.fl = 1; |
| 1014 | } |
| 1015 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1016 | tmo = phba->fc_ratov; |
| 1017 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1018 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1019 | phba->fc_ratov = tmo; |
| 1020 | |
| 1021 | phba->fc_stat.elsXmitFLOGI++; |
| 1022 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1023 | |
| 1024 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1025 | "Issue FLOGI: opt:x%x", |
| 1026 | phba->sli3_options, 0, 0); |
| 1027 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1028 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1029 | if (rc == IOCB_ERROR) { |
| 1030 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1031 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1032 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1033 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1034 | } |
| 1035 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1036 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1037 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1038 | * @phba: pointer to lpfc hba data structure. |
| 1039 | * |
| 1040 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1041 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1042 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1043 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1044 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1045 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1046 | * |
| 1047 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1048 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1049 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1050 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1051 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1052 | { |
| 1053 | struct lpfc_sli_ring *pring; |
| 1054 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1055 | struct lpfc_nodelist *ndlp; |
| 1056 | IOCB_t *icmd; |
| 1057 | |
| 1058 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1059 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1060 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1061 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1062 | |
| 1063 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1064 | |
| 1065 | /* |
| 1066 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1067 | * searching for. |
| 1068 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1069 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1070 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1071 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1072 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 1073 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1074 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1075 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1076 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1077 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1078 | } |
| 1079 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1080 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1081 | |
| 1082 | return 0; |
| 1083 | } |
| 1084 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1085 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1086 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1087 | * @vport: pointer to a host virtual N_Port data structure. |
| 1088 | * |
| 1089 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1090 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1091 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1092 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1093 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1094 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1095 | * @vport. |
| 1096 | * |
| 1097 | * Return code |
| 1098 | * 0 - failed to issue initial flogi for @vport |
| 1099 | * 1 - successfully issued initial flogi for @vport |
| 1100 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1101 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1102 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1103 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1104 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1105 | struct lpfc_nodelist *ndlp; |
| 1106 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1107 | vport->port_state = LPFC_FLOGI; |
| 1108 | lpfc_set_disctmo(vport); |
| 1109 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1110 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1111 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1112 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1113 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1114 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1115 | if (!ndlp) |
| 1116 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1117 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1118 | /* Set the node type */ |
| 1119 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1120 | /* Put ndlp onto node list */ |
| 1121 | lpfc_enqueue_node(vport, ndlp); |
| 1122 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1123 | /* re-setup ndlp without removing from node list */ |
| 1124 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1125 | if (!ndlp) |
| 1126 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1127 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1128 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1129 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1130 | /* This decrement of reference count to node shall kick off |
| 1131 | * the release of the node. |
| 1132 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1133 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1134 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1135 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1136 | } |
| 1137 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1138 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1139 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1140 | * @vport: pointer to a host virtual N_Port data structure. |
| 1141 | * |
| 1142 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1143 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1144 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1145 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1146 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1147 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1148 | * @vport. |
| 1149 | * |
| 1150 | * Return code |
| 1151 | * 0 - failed to issue initial fdisc for @vport |
| 1152 | * 1 - successfully issued initial fdisc for @vport |
| 1153 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1154 | int |
| 1155 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1156 | { |
| 1157 | struct lpfc_hba *phba = vport->phba; |
| 1158 | struct lpfc_nodelist *ndlp; |
| 1159 | |
| 1160 | /* First look for the Fabric ndlp */ |
| 1161 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1162 | if (!ndlp) { |
| 1163 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1164 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1165 | if (!ndlp) |
| 1166 | return 0; |
| 1167 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1168 | /* Put ndlp onto node list */ |
| 1169 | lpfc_enqueue_node(vport, ndlp); |
| 1170 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1171 | /* re-setup ndlp without removing from node list */ |
| 1172 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1173 | if (!ndlp) |
| 1174 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1175 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1176 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1177 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1178 | /* decrement node reference count to trigger the release of |
| 1179 | * the node. |
| 1180 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1181 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1182 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1183 | } |
| 1184 | return 1; |
| 1185 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1186 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1187 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1188 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1189 | * @vport: pointer to a host virtual N_Port data structure. |
| 1190 | * |
| 1191 | * This routine checks whether there are more remaining Port Logins |
| 1192 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1193 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1194 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1195 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1196 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1197 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1198 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1199 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1200 | { |
| 1201 | int sentplogi; |
| 1202 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1203 | if (vport->num_disc_nodes) |
| 1204 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1205 | |
| 1206 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1207 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1208 | "0232 Continue discovery with %d PLOGIs to go " |
| 1209 | "Data: x%x x%x x%x\n", |
| 1210 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1211 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1212 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1213 | if (vport->fc_flag & FC_NLP_MORE) |
| 1214 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1215 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1216 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1217 | return; |
| 1218 | } |
| 1219 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1220 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1221 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1222 | * @phba: pointer to lpfc hba data structure. |
| 1223 | * @prsp: pointer to response IOCB payload. |
| 1224 | * @ndlp: pointer to a node-list data structure. |
| 1225 | * |
| 1226 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1227 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1228 | * The following cases are considered N_Port confirmed: |
| 1229 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1230 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1231 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1232 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1233 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1234 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1235 | * on that node to release the RPI associated with the node; 2) if there is |
| 1236 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1237 | * into, a new node shall be allocated (or activated). In either case, the |
| 1238 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1239 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1240 | * its pointer returned as the confirmed node. |
| 1241 | * |
| 1242 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1243 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1244 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1245 | * into an inactive state on the vport node list and the vport node list |
| 1246 | * management algorithm does not allow two node with a same DID. |
| 1247 | * |
| 1248 | * Return code |
| 1249 | * pointer to the PLOGI N_Port @ndlp |
| 1250 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1251 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1252 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1253 | struct lpfc_nodelist *ndlp) |
| 1254 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1255 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1256 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1257 | struct lpfc_rport_data *rdata; |
| 1258 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1259 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1260 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1261 | uint32_t rc, keepDID = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1262 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1263 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1264 | * by WWPN. Just return the ndlp that was given to us. |
| 1265 | */ |
| 1266 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1267 | return ndlp; |
| 1268 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1269 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1270 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1271 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1272 | /* 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] | 1273 | * we have for that ndlp. If not, we have some work to do. |
| 1274 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1275 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1276 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1277 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1278 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1279 | |
| 1280 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1281 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1282 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1283 | if (!rc) |
| 1284 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1285 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1286 | if (!new_ndlp) |
| 1287 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1288 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1289 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1290 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1291 | sizeof(struct lpfc_name)); |
| 1292 | if (!rc) |
| 1293 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1294 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1295 | NLP_STE_UNUSED_NODE); |
| 1296 | if (!new_ndlp) |
| 1297 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1298 | keepDID = new_ndlp->nlp_DID; |
| 1299 | } else |
| 1300 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1301 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1302 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1303 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1304 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1305 | |
| 1306 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1307 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1308 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1309 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1310 | /* 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] | 1311 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1312 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1313 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1314 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1315 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1316 | * to put ndlp on UNUSED list and try to free it. |
| 1317 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1318 | |
| 1319 | /* Fix up the rport accordingly */ |
| 1320 | rport = ndlp->rport; |
| 1321 | if (rport) { |
| 1322 | rdata = rport->dd_data; |
| 1323 | if (rdata->pnode == ndlp) { |
| 1324 | lpfc_nlp_put(ndlp); |
| 1325 | ndlp->rport = NULL; |
| 1326 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1327 | new_ndlp->rport = rport; |
| 1328 | } |
| 1329 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1330 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1331 | /* We shall actually free the ndlp with both nlp_DID and |
| 1332 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1333 | * nodelist never to be used. |
| 1334 | */ |
| 1335 | if (ndlp->nlp_DID == 0) { |
| 1336 | spin_lock_irq(&phba->ndlp_lock); |
| 1337 | NLP_SET_FREE_REQ(ndlp); |
| 1338 | spin_unlock_irq(&phba->ndlp_lock); |
| 1339 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1340 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1341 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1342 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1343 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1344 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1345 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1346 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1347 | /* Two ndlps cannot have the same did */ |
| 1348 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1349 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1350 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1351 | return new_ndlp; |
| 1352 | } |
| 1353 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1354 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1355 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1356 | * @vport: pointer to a host virtual N_Port data structure. |
| 1357 | * |
| 1358 | * This routine checks whether more Registration State Change |
| 1359 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1360 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1361 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1362 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1363 | * handling the RSCNs. |
| 1364 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1365 | void |
| 1366 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1367 | { |
| 1368 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1369 | |
| 1370 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1371 | /* |
| 1372 | * Check to see if more RSCNs came in while we were |
| 1373 | * processing this one. |
| 1374 | */ |
| 1375 | if (vport->fc_rscn_id_cnt || |
| 1376 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1377 | lpfc_els_handle_rscn(vport); |
| 1378 | else { |
| 1379 | spin_lock_irq(shost->host_lock); |
| 1380 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1381 | spin_unlock_irq(shost->host_lock); |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1386 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1387 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1388 | * @phba: pointer to lpfc hba data structure. |
| 1389 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1390 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1391 | * |
| 1392 | * This routine is the completion callback function for issuing the Port |
| 1393 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1394 | * ndlp on the vport node list that matches the remote node ID from the |
| 1395 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1396 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1397 | * checked for error conditons. If there is error status reported, PLOGI |
| 1398 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1399 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1400 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1401 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1402 | * there are additional N_Port nodes with the vport that need to perform |
| 1403 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1404 | * PLOGIs. |
| 1405 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1406 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1407 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1408 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1409 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1410 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1411 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1412 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1413 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1414 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1415 | int disc, rc, did, type; |
| 1416 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1417 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1418 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1419 | |
| 1420 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1421 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1422 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1423 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1424 | irsp->un.elsreq64.remoteID); |
| 1425 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1426 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1427 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1428 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1429 | "0136 PLOGI completes to NPort x%x " |
| 1430 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1431 | irsp->un.elsreq64.remoteID, |
| 1432 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1433 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1434 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1435 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1436 | |
| 1437 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1438 | * is being used during discovery. |
| 1439 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1440 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1441 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1442 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1443 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1444 | rc = 0; |
| 1445 | |
| 1446 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1447 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1448 | "0102 PLOGI completes to NPort x%x " |
| 1449 | "Data: x%x x%x x%x x%x x%x\n", |
| 1450 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1451 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1452 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1453 | if (lpfc_els_chk_latt(vport)) { |
| 1454 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1455 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1456 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1457 | goto out; |
| 1458 | } |
| 1459 | |
| 1460 | /* ndlp could be freed in DSM, save these values now */ |
| 1461 | type = ndlp->nlp_type; |
| 1462 | did = ndlp->nlp_DID; |
| 1463 | |
| 1464 | if (irsp->ulpStatus) { |
| 1465 | /* Check for retry */ |
| 1466 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1467 | /* ELS command is being retried */ |
| 1468 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1469 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1470 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1471 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1472 | } |
| 1473 | goto out; |
| 1474 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1475 | /* PLOGI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1476 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1477 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1478 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1479 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1480 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1481 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1482 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1483 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1484 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1485 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1486 | } else { |
| 1487 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1488 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1489 | cmdiocb->context2)->list.next, |
| 1490 | struct lpfc_dmabuf, list); |
| 1491 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1492 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1493 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1494 | } |
| 1495 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1496 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1498 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1499 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1500 | if (vport->num_disc_nodes == 0) { |
| 1501 | spin_lock_irq(shost->host_lock); |
| 1502 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1503 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1504 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1505 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1506 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | out: |
| 1511 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1512 | return; |
| 1513 | } |
| 1514 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1515 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1516 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1517 | * @vport: pointer to a host virtual N_Port data structure. |
| 1518 | * @did: destination port identifier. |
| 1519 | * @retry: number of retries to the command IOCB. |
| 1520 | * |
| 1521 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1522 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1523 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1524 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1525 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1526 | * |
| 1527 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1528 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1529 | * will be stored into the context1 field of the IOCB for the completion |
| 1530 | * callback function to the PLOGI ELS command. |
| 1531 | * |
| 1532 | * Return code |
| 1533 | * 0 - Successfully issued a plogi for @vport |
| 1534 | * 1 - failed to issue a plogi for @vport |
| 1535 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1536 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1537 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1538 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1539 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1540 | struct serv_parm *sp; |
| 1541 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1542 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1543 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | struct lpfc_sli *psli; |
| 1545 | uint8_t *pcmd; |
| 1546 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1547 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1548 | |
| 1549 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1550 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1551 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1552 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1553 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1554 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1555 | /* 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] | 1556 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1557 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1558 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1559 | if (!elsiocb) |
| 1560 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1561 | |
| 1562 | icmd = &elsiocb->iocb; |
| 1563 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1564 | |
| 1565 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1566 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1567 | pcmd += sizeof(uint32_t); |
| 1568 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1569 | sp = (struct serv_parm *) pcmd; |
| 1570 | |
| 1571 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1572 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1573 | |
| 1574 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1575 | sp->cmn.fcphHigh = FC_PH3; |
| 1576 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1577 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1578 | "Issue PLOGI: did:x%x", |
| 1579 | did, 0, 0); |
| 1580 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1581 | phba->fc_stat.elsXmitPLOGI++; |
| 1582 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1583 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1584 | |
| 1585 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1586 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1587 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1588 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1589 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1590 | } |
| 1591 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1592 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1593 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1594 | * @phba: pointer to lpfc hba data structure. |
| 1595 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1596 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1597 | * |
| 1598 | * This routine is the completion callback function for a Process Login |
| 1599 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1600 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1601 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1602 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1603 | * ndlp to mark the PRLI completion. |
| 1604 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1605 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1606 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1607 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1608 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1609 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1610 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1611 | IOCB_t *irsp; |
| 1612 | struct lpfc_sli *psli; |
| 1613 | struct lpfc_nodelist *ndlp; |
| 1614 | |
| 1615 | psli = &phba->sli; |
| 1616 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1617 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1618 | |
| 1619 | irsp = &(rspiocb->iocb); |
| 1620 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1621 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1622 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1623 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 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 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1627 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1628 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1629 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1630 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1631 | "0103 PRLI completes to NPort x%x " |
| 1632 | "Data: x%x x%x x%x x%x\n", |
| 1633 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1634 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1635 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1636 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1637 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1638 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1639 | goto out; |
| 1640 | |
| 1641 | if (irsp->ulpStatus) { |
| 1642 | /* Check for retry */ |
| 1643 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1644 | /* ELS command is being retried */ |
| 1645 | goto out; |
| 1646 | } |
| 1647 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1648 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1649 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 1650 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1651 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1652 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1653 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1654 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1655 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1656 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1657 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1658 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1659 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1660 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1661 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1662 | out: |
| 1663 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1664 | return; |
| 1665 | } |
| 1666 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1667 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1668 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1669 | * @vport: pointer to a host virtual N_Port data structure. |
| 1670 | * @ndlp: pointer to a node-list data structure. |
| 1671 | * @retry: number of retries to the command IOCB. |
| 1672 | * |
| 1673 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1674 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1675 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1676 | * is put to the IOCB completion callback func field before invoking the |
| 1677 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1678 | * |
| 1679 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1680 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1681 | * will be stored into the context1 field of the IOCB for the completion |
| 1682 | * callback function to the PRLI ELS command. |
| 1683 | * |
| 1684 | * Return code |
| 1685 | * 0 - successfully issued prli iocb command for @vport |
| 1686 | * 1 - failed to issue prli iocb command for @vport |
| 1687 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1688 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1689 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1690 | uint8_t retry) |
| 1691 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1692 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1693 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1694 | PRLI *npr; |
| 1695 | IOCB_t *icmd; |
| 1696 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1697 | uint8_t *pcmd; |
| 1698 | uint16_t cmdsize; |
| 1699 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1700 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1701 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1702 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1703 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1704 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1705 | |
| 1706 | icmd = &elsiocb->iocb; |
| 1707 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1708 | |
| 1709 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1710 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1711 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1712 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1713 | |
| 1714 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1715 | npr = (PRLI *) pcmd; |
| 1716 | /* |
| 1717 | * If our firmware version is 3.20 or later, |
| 1718 | * set the following bits for FC-TAPE support. |
| 1719 | */ |
| 1720 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1721 | npr->ConfmComplAllowed = 1; |
| 1722 | npr->Retry = 1; |
| 1723 | npr->TaskRetryIdReq = 1; |
| 1724 | } |
| 1725 | npr->estabImagePair = 1; |
| 1726 | npr->readXferRdyDis = 1; |
| 1727 | |
| 1728 | /* For FCP support */ |
| 1729 | npr->prliType = PRLI_FCP_TYPE; |
| 1730 | npr->initiatorFunc = 1; |
| 1731 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1732 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1733 | "Issue PRLI: did:x%x", |
| 1734 | ndlp->nlp_DID, 0, 0); |
| 1735 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1736 | phba->fc_stat.elsXmitPRLI++; |
| 1737 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1738 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1739 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1740 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1741 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1742 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1743 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1744 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1745 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1746 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1747 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1749 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1750 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1751 | } |
| 1752 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1753 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1754 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1755 | * @vport: pointer to a host virtual N_Port data structure. |
| 1756 | * |
| 1757 | * This routine performs Registration State Change Notification (RSCN) |
| 1758 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1759 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1760 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1761 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1762 | * invoked to check and handle possible more RSCN came in during the period |
| 1763 | * of processing the current ones. |
| 1764 | **/ |
| 1765 | static void |
| 1766 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1767 | { |
| 1768 | lpfc_can_disctmo(vport); |
| 1769 | |
| 1770 | /* RSCN discovery */ |
| 1771 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1772 | if (vport->fc_npr_cnt) |
| 1773 | if (lpfc_els_disc_plogi(vport)) |
| 1774 | return; |
| 1775 | |
| 1776 | lpfc_end_rscn(vport); |
| 1777 | } |
| 1778 | |
| 1779 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1780 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1781 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1782 | * |
| 1783 | * This function is called when the final ADISC is completed during discovery. |
| 1784 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1785 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1786 | * discovery. |
| 1787 | * This function is called with no locks held. |
| 1788 | **/ |
| 1789 | static void |
| 1790 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1791 | { |
| 1792 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1793 | struct lpfc_hba *phba = vport->phba; |
| 1794 | |
| 1795 | /* |
| 1796 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1797 | * and continue discovery. |
| 1798 | */ |
| 1799 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1800 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1801 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1802 | lpfc_issue_reg_vpi(phba, vport); |
| 1803 | return; |
| 1804 | } |
| 1805 | /* |
| 1806 | * For SLI2, we need to set port_state to READY |
| 1807 | * and continue discovery. |
| 1808 | */ |
| 1809 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1810 | /* If we get here, there is nothing to ADISC */ |
| 1811 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1812 | lpfc_issue_clear_la(phba, vport); |
| 1813 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1814 | vport->num_disc_nodes = 0; |
| 1815 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1816 | if (vport->fc_npr_cnt) |
| 1817 | lpfc_els_disc_plogi(vport); |
| 1818 | if (!vport->num_disc_nodes) { |
| 1819 | spin_lock_irq(shost->host_lock); |
| 1820 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1821 | spin_unlock_irq(shost->host_lock); |
| 1822 | lpfc_can_disctmo(vport); |
| 1823 | lpfc_end_rscn(vport); |
| 1824 | } |
| 1825 | } |
| 1826 | vport->port_state = LPFC_VPORT_READY; |
| 1827 | } else |
| 1828 | lpfc_rscn_disc(vport); |
| 1829 | } |
| 1830 | |
| 1831 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1832 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1833 | * @vport: pointer to a host virtual N_Port data structure. |
| 1834 | * |
| 1835 | * This routine determines whether there are more ndlps on a @vport |
| 1836 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1837 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1838 | * remaining nodes which need to have ADISC sent. |
| 1839 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1840 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1841 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1842 | { |
| 1843 | int sentadisc; |
| 1844 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1845 | if (vport->num_disc_nodes) |
| 1846 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1847 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1848 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1849 | "0210 Continue discovery with %d ADISCs to go " |
| 1850 | "Data: x%x x%x x%x\n", |
| 1851 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1852 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1853 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1854 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1855 | lpfc_set_disctmo(vport); |
| 1856 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1857 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1858 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1859 | if (!vport->num_disc_nodes) |
| 1860 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1861 | return; |
| 1862 | } |
| 1863 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1864 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1865 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1866 | * @phba: pointer to lpfc hba data structure. |
| 1867 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1868 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1869 | * |
| 1870 | * This routine is the completion function for issuing the Address Discover |
| 1871 | * (ADISC) command. It first checks to see whether link went down during |
| 1872 | * the discovery process. If so, the node will be marked as node port |
| 1873 | * recovery for issuing discover IOCB by the link attention handler and |
| 1874 | * exit. Otherwise, the response status is checked. If error was reported |
| 1875 | * in the response status, the ADISC command shall be retried by invoking |
| 1876 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1877 | * the response status, the state machine is invoked to set transition |
| 1878 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1879 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1880 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1881 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1882 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1883 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1884 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1885 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1886 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1887 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1888 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1889 | |
| 1890 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1891 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1892 | |
| 1893 | irsp = &(rspiocb->iocb); |
| 1894 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1895 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1896 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1897 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1898 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1899 | ndlp->nlp_DID); |
| 1900 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1901 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1902 | * is being used during discovery. |
| 1903 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1904 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1905 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1906 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1907 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1909 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1910 | "0104 ADISC completes to NPort x%x " |
| 1911 | "Data: x%x x%x x%x x%x x%x\n", |
| 1912 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1913 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1914 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1915 | if (lpfc_els_chk_latt(vport)) { |
| 1916 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1917 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1918 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1919 | goto out; |
| 1920 | } |
| 1921 | |
| 1922 | if (irsp->ulpStatus) { |
| 1923 | /* Check for retry */ |
| 1924 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1925 | /* ELS command is being retried */ |
| 1926 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1927 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1928 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1929 | spin_unlock_irq(shost->host_lock); |
| 1930 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | } |
| 1932 | goto out; |
| 1933 | } |
| 1934 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1935 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1936 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 1937 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1938 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1939 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1940 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1941 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1942 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1943 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1944 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1945 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1946 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1947 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1948 | /* Check to see if there are more ADISCs to be sent */ |
| 1949 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1950 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1951 | out: |
| 1952 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1953 | return; |
| 1954 | } |
| 1955 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1956 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1957 | * 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] | 1958 | * @vport: pointer to a virtual N_Port data structure. |
| 1959 | * @ndlp: pointer to a node-list data structure. |
| 1960 | * @retry: number of retries to the command IOCB. |
| 1961 | * |
| 1962 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1963 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 1964 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 1965 | * to issue the ADISC ELS command. |
| 1966 | * |
| 1967 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1968 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1969 | * will be stored into the context1 field of the IOCB for the completion |
| 1970 | * callback function to the ADISC ELS command. |
| 1971 | * |
| 1972 | * Return code |
| 1973 | * 0 - successfully issued adisc |
| 1974 | * 1 - failed to issue adisc |
| 1975 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1976 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1977 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1978 | uint8_t retry) |
| 1979 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1980 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1981 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1982 | ADISC *ap; |
| 1983 | IOCB_t *icmd; |
| 1984 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1985 | uint8_t *pcmd; |
| 1986 | uint16_t cmdsize; |
| 1987 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1988 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1989 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1990 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1991 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1992 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1993 | |
| 1994 | icmd = &elsiocb->iocb; |
| 1995 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1996 | |
| 1997 | /* For ADISC request, remainder of payload is service parameters */ |
| 1998 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1999 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2000 | |
| 2001 | /* Fill in ADISC payload */ |
| 2002 | ap = (ADISC *) pcmd; |
| 2003 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2004 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2005 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2006 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2007 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2008 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2009 | "Issue ADISC: did:x%x", |
| 2010 | ndlp->nlp_DID, 0, 0); |
| 2011 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2012 | phba->fc_stat.elsXmitADISC++; |
| 2013 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2014 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2015 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2016 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2017 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2018 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2019 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2020 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2021 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2022 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2023 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2024 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2025 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2026 | } |
| 2027 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2028 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2029 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2030 | * @phba: pointer to lpfc hba data structure. |
| 2031 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2032 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2033 | * |
| 2034 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2035 | * command. If no error status was reported from the LOGO response, the |
| 2036 | * state machine of the associated ndlp shall be invoked for transition with |
| 2037 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2038 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2039 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2040 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2041 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2042 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2043 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2044 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2045 | struct lpfc_vport *vport = ndlp->vport; |
| 2046 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | IOCB_t *irsp; |
| 2048 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2049 | |
| 2050 | psli = &phba->sli; |
| 2051 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2052 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2053 | |
| 2054 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2055 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2056 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2057 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2058 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2059 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2060 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2061 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2062 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2064 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2065 | "0105 LOGO completes to NPort x%x " |
| 2066 | "Data: x%x x%x x%x x%x\n", |
| 2067 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2068 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2069 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2070 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2071 | goto out; |
| 2072 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2073 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2074 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2075 | * which should abort all outstanding IOs. |
| 2076 | */ |
| 2077 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2078 | NLP_EVT_DEVICE_RM); |
| 2079 | goto out; |
| 2080 | } |
| 2081 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2082 | if (irsp->ulpStatus) { |
| 2083 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2084 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2085 | /* ELS command is being retried */ |
| 2086 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2087 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2088 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2089 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2090 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2091 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2093 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2094 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2095 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2096 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2097 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2098 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2099 | /* Good status, call state machine. |
| 2100 | * This will unregister the rpi if needed. |
| 2101 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2102 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2103 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | out: |
| 2105 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2106 | return; |
| 2107 | } |
| 2108 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2109 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2110 | * 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] | 2111 | * @vport: pointer to a virtual N_Port data structure. |
| 2112 | * @ndlp: pointer to a node-list data structure. |
| 2113 | * @retry: number of retries to the command IOCB. |
| 2114 | * |
| 2115 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2116 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2117 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2118 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2119 | * |
| 2120 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2121 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2122 | * will be stored into the context1 field of the IOCB for the completion |
| 2123 | * callback function to the LOGO ELS command. |
| 2124 | * |
| 2125 | * Return code |
| 2126 | * 0 - successfully issued logo |
| 2127 | * 1 - failed to issue logo |
| 2128 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2129 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2130 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2131 | uint8_t retry) |
| 2132 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2133 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2134 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | IOCB_t *icmd; |
| 2136 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | uint8_t *pcmd; |
| 2138 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2139 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2140 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2141 | spin_lock_irq(shost->host_lock); |
| 2142 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2143 | spin_unlock_irq(shost->host_lock); |
| 2144 | return 0; |
| 2145 | } |
| 2146 | spin_unlock_irq(shost->host_lock); |
| 2147 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2148 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2149 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2150 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2151 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2152 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2153 | |
| 2154 | icmd = &elsiocb->iocb; |
| 2155 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2156 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2157 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2158 | |
| 2159 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2160 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2161 | pcmd += sizeof(uint32_t); |
| 2162 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2163 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2164 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2165 | "Issue LOGO: did:x%x", |
| 2166 | ndlp->nlp_DID, 0, 0); |
| 2167 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2168 | phba->fc_stat.elsXmitLOGO++; |
| 2169 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2170 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2171 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2172 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2173 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2174 | |
| 2175 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2176 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2177 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2178 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2179 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2180 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2181 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2182 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2183 | } |
| 2184 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2185 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2186 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2187 | * @phba: pointer to lpfc hba data structure. |
| 2188 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2189 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2190 | * |
| 2191 | * This routine is a generic completion callback function for ELS commands. |
| 2192 | * Specifically, it is the callback function which does not need to perform |
| 2193 | * any command specific operations. It is currently used by the ELS command |
| 2194 | * issuing routines for the ELS State Change Request (SCR), |
| 2195 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2196 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2197 | * certain debug loggings, this callback function simply invokes the |
| 2198 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2199 | * discovery process. |
| 2200 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2201 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2202 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2203 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2204 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2205 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2206 | IOCB_t *irsp; |
| 2207 | |
| 2208 | irsp = &rspiocb->iocb; |
| 2209 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2210 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2211 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2212 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2213 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2214 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2215 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2216 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2217 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2218 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2219 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2220 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2221 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2222 | return; |
| 2223 | } |
| 2224 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2225 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2226 | * 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] | 2227 | * @vport: pointer to a host virtual N_Port data structure. |
| 2228 | * @nportid: N_Port identifier to the remote node. |
| 2229 | * @retry: number of retries to the command IOCB. |
| 2230 | * |
| 2231 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2232 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2233 | * first search the @vport node list to find the matching ndlp. If no such |
| 2234 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2235 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2236 | * routine is invoked to send the SCR IOCB. |
| 2237 | * |
| 2238 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2239 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2240 | * will be stored into the context1 field of the IOCB for the completion |
| 2241 | * callback function to the SCR ELS command. |
| 2242 | * |
| 2243 | * Return code |
| 2244 | * 0 - Successfully issued scr command |
| 2245 | * 1 - Failed to issue scr command |
| 2246 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2247 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2248 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2249 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2250 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2251 | IOCB_t *icmd; |
| 2252 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2253 | struct lpfc_sli *psli; |
| 2254 | uint8_t *pcmd; |
| 2255 | uint16_t cmdsize; |
| 2256 | struct lpfc_nodelist *ndlp; |
| 2257 | |
| 2258 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2259 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2260 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2261 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2262 | if (!ndlp) { |
| 2263 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2264 | if (!ndlp) |
| 2265 | return 1; |
| 2266 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2267 | lpfc_enqueue_node(vport, ndlp); |
| 2268 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2269 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2270 | if (!ndlp) |
| 2271 | return 1; |
| 2272 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2274 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2275 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2276 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2277 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2278 | /* This will trigger the release of the node just |
| 2279 | * allocated |
| 2280 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2281 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2282 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | icmd = &elsiocb->iocb; |
| 2286 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2287 | |
| 2288 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2289 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2290 | |
| 2291 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2292 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2293 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2294 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2295 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2296 | "Issue SCR: did:x%x", |
| 2297 | ndlp->nlp_DID, 0, 0); |
| 2298 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2299 | phba->fc_stat.elsXmitSCR++; |
| 2300 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2301 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2302 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2303 | /* The additional lpfc_nlp_put will cause the following |
| 2304 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2305 | * the node. |
| 2306 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2307 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2309 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2311 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2312 | * trigger the release of node. |
| 2313 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2314 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2315 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2316 | } |
| 2317 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2318 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2319 | * 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] | 2320 | * @vport: pointer to a host virtual N_Port data structure. |
| 2321 | * @nportid: N_Port identifier to the remote node. |
| 2322 | * @retry: number of retries to the command IOCB. |
| 2323 | * |
| 2324 | * This routine issues a Fibre Channel Address Resolution Response |
| 2325 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2326 | * is passed into the function. It first search the @vport node list to find |
| 2327 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2328 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2329 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2330 | * |
| 2331 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2332 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2333 | * will be stored into the context1 field of the IOCB for the completion |
| 2334 | * callback function to the PARPR ELS command. |
| 2335 | * |
| 2336 | * Return code |
| 2337 | * 0 - Successfully issued farpr command |
| 2338 | * 1 - Failed to issue farpr command |
| 2339 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2340 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2341 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2342 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2343 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2344 | IOCB_t *icmd; |
| 2345 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2346 | struct lpfc_sli *psli; |
| 2347 | FARP *fp; |
| 2348 | uint8_t *pcmd; |
| 2349 | uint32_t *lp; |
| 2350 | uint16_t cmdsize; |
| 2351 | struct lpfc_nodelist *ondlp; |
| 2352 | struct lpfc_nodelist *ndlp; |
| 2353 | |
| 2354 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2355 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2356 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2357 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2358 | if (!ndlp) { |
| 2359 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2360 | if (!ndlp) |
| 2361 | return 1; |
| 2362 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2363 | lpfc_enqueue_node(vport, ndlp); |
| 2364 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2365 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2366 | if (!ndlp) |
| 2367 | return 1; |
| 2368 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2369 | |
| 2370 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2371 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2372 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2373 | /* This will trigger the release of the node just |
| 2374 | * allocated |
| 2375 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2376 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2377 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | icmd = &elsiocb->iocb; |
| 2381 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2382 | |
| 2383 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2384 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2385 | |
| 2386 | /* Fill in FARPR payload */ |
| 2387 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2388 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2389 | lp = (uint32_t *) pcmd; |
| 2390 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2391 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2392 | fp->Rflags = 0; |
| 2393 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2394 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2395 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2396 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2397 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2398 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2399 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2400 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2401 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2402 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2403 | } |
| 2404 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2405 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2406 | "Issue FARPR: did:x%x", |
| 2407 | ndlp->nlp_DID, 0, 0); |
| 2408 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2409 | phba->fc_stat.elsXmitFARPR++; |
| 2410 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2411 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2412 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2413 | /* The additional lpfc_nlp_put will cause the following |
| 2414 | * lpfc_els_free_iocb routine to trigger the release of |
| 2415 | * the node. |
| 2416 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2417 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2418 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2419 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2420 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2421 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2422 | * trigger the release of the node. |
| 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 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2426 | } |
| 2427 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2428 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2429 | * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2430 | * @vport: pointer to a host virtual N_Port data structure. |
| 2431 | * @nlp: pointer to a node-list data structure. |
| 2432 | * |
| 2433 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2434 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2435 | * removes the ELS retry event if it presents. In addition, if the |
| 2436 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2437 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2438 | * ADISC. |
| 2439 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2441 | 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] | 2442 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2443 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2444 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2445 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2446 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2447 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2448 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2449 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2450 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2451 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2452 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2453 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2454 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2455 | /* Decrement nlp reference count held for the delayed retry */ |
| 2456 | evtp = &nlp->els_retry_evt; |
| 2457 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2458 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2459 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2460 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2461 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2462 | spin_unlock_irq(shost->host_lock); |
| 2463 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2464 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2465 | /* Check if there are more ADISCs to be sent */ |
| 2466 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2467 | } else { |
| 2468 | /* Check if there are more PLOGIs to be sent */ |
| 2469 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2470 | if (vport->num_disc_nodes == 0) { |
| 2471 | spin_lock_irq(shost->host_lock); |
| 2472 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2473 | spin_unlock_irq(shost->host_lock); |
| 2474 | lpfc_can_disctmo(vport); |
| 2475 | lpfc_end_rscn(vport); |
| 2476 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2477 | } |
| 2478 | } |
| 2479 | } |
| 2480 | return; |
| 2481 | } |
| 2482 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2483 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2484 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2485 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2486 | * |
| 2487 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2488 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2489 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2490 | * adds the delayed events to the HBA work list and invokes the |
| 2491 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2492 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2493 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2494 | * reference to ndlp will still be available when the worker thread gets |
| 2495 | * to the event associated with the ndlp. |
| 2496 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2497 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2498 | lpfc_els_retry_delay(unsigned long ptr) |
| 2499 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2500 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2501 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2502 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2503 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2504 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2505 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2506 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2507 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2508 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2509 | return; |
| 2510 | } |
| 2511 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2512 | /* We need to hold the node by incrementing the reference |
| 2513 | * count until the queued work is done |
| 2514 | */ |
| 2515 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2516 | if (evtp->evt_arg1) { |
| 2517 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2518 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2519 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2520 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2521 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2522 | return; |
| 2523 | } |
| 2524 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2525 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2526 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2527 | * @ndlp: pointer to a node-list data structure. |
| 2528 | * |
| 2529 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2530 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2531 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2532 | * function according to the delayed ELS command to retry the command. |
| 2533 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2534 | void |
| 2535 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2536 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2537 | struct lpfc_vport *vport = ndlp->vport; |
| 2538 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2539 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2540 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2541 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2542 | did = ndlp->nlp_DID; |
| 2543 | cmd = ndlp->nlp_last_elscmd; |
| 2544 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2545 | |
| 2546 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2547 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2548 | return; |
| 2549 | } |
| 2550 | |
| 2551 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2552 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2553 | /* |
| 2554 | * If a discovery event readded nlp_delayfunc after timer |
| 2555 | * firing and before processing the timer, cancel the |
| 2556 | * nlp_delayfunc. |
| 2557 | */ |
| 2558 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2559 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2560 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2561 | |
| 2562 | switch (cmd) { |
| 2563 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2564 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2565 | break; |
| 2566 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2567 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2568 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2569 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2570 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2571 | break; |
| 2572 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2573 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2574 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2575 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2576 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2577 | break; |
| 2578 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2579 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2580 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2581 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2582 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2583 | break; |
| 2584 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2585 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2586 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2587 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2588 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2589 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2590 | case ELS_CMD_FDISC: |
| 2591 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2592 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2593 | } |
| 2594 | return; |
| 2595 | } |
| 2596 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2597 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2598 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2599 | * @phba: pointer to lpfc hba data structure. |
| 2600 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2601 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2602 | * |
| 2603 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2604 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2605 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2606 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2607 | * returned error status, it makes the decision whether a retry shall be |
| 2608 | * issued for the command, and whether a retry shall be made immediately or |
| 2609 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2610 | * is called to retry the command. In the later case, the ELS command shall |
| 2611 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2612 | * ndlp for the delayed command issusing. |
| 2613 | * |
| 2614 | * Return code |
| 2615 | * 0 - No retry of els command is made |
| 2616 | * 1 - Immediate or delayed retry of els command is made |
| 2617 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2618 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2619 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2620 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2622 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2623 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2624 | IOCB_t *irsp = &rspiocb->iocb; |
| 2625 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2626 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2627 | uint32_t *elscmd; |
| 2628 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2629 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2630 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2631 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2632 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2633 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2634 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2635 | /* Note: context2 may be 0 for internal driver abort |
| 2636 | * of delays ELS command. |
| 2637 | */ |
| 2638 | |
| 2639 | if (pcmd && pcmd->virt) { |
| 2640 | elscmd = (uint32_t *) (pcmd->virt); |
| 2641 | cmd = *elscmd++; |
| 2642 | } |
| 2643 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2644 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2645 | did = ndlp->nlp_DID; |
| 2646 | else { |
| 2647 | /* We should only hit this case for retrying PLOGI */ |
| 2648 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2649 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2650 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2651 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2652 | return 1; |
| 2653 | } |
| 2654 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2655 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2656 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2657 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2658 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2659 | switch (irsp->ulpStatus) { |
| 2660 | case IOSTAT_FCP_RSP_ERROR: |
| 2661 | case IOSTAT_REMOTE_STOP: |
| 2662 | break; |
| 2663 | |
| 2664 | case IOSTAT_LOCAL_REJECT: |
| 2665 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2666 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2667 | if (cmd == ELS_CMD_FLOGI) { |
| 2668 | if (PCI_DEVICE_ID_HORNET == |
| 2669 | phba->pcidev->device) { |
| 2670 | phba->fc_topology = TOPOLOGY_LOOP; |
| 2671 | phba->pport->fc_myDID = 0; |
| 2672 | phba->alpa_map[0] = 0; |
| 2673 | phba->alpa_map[1] = 0; |
| 2674 | } |
| 2675 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2676 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2677 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2678 | retry = 1; |
| 2679 | break; |
| 2680 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2681 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2682 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2683 | "0124 Retry illegal cmd x%x " |
| 2684 | "retry:x%x delay:x%x\n", |
| 2685 | cmd, cmdiocb->retry, delay); |
| 2686 | retry = 1; |
| 2687 | /* All command's retry policy */ |
| 2688 | maxretry = 8; |
| 2689 | if (cmdiocb->retry > 2) |
| 2690 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2691 | break; |
| 2692 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2693 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2694 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2695 | retry = 1; |
| 2696 | if (cmdiocb->retry > 100) |
| 2697 | delay = 100; |
| 2698 | maxretry = 250; |
| 2699 | break; |
| 2700 | |
| 2701 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2702 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2703 | retry = 1; |
| 2704 | break; |
| 2705 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2706 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2707 | case IOERR_INVALID_RPI: |
| 2708 | retry = 1; |
| 2709 | break; |
| 2710 | } |
| 2711 | break; |
| 2712 | |
| 2713 | case IOSTAT_NPORT_RJT: |
| 2714 | case IOSTAT_FABRIC_RJT: |
| 2715 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2716 | retry = 1; |
| 2717 | break; |
| 2718 | } |
| 2719 | break; |
| 2720 | |
| 2721 | case IOSTAT_NPORT_BSY: |
| 2722 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2723 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2724 | retry = 1; |
| 2725 | break; |
| 2726 | |
| 2727 | case IOSTAT_LS_RJT: |
| 2728 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2729 | /* Added for Vendor specifc support |
| 2730 | * Just keep retrying for these Rsn / Exp codes |
| 2731 | */ |
| 2732 | switch (stat.un.b.lsRjtRsnCode) { |
| 2733 | case LSRJT_UNABLE_TPC: |
| 2734 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2735 | LSEXP_CMD_IN_PROGRESS) { |
| 2736 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2737 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2738 | maxretry = 48; |
| 2739 | } |
| 2740 | retry = 1; |
| 2741 | break; |
| 2742 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame^] | 2743 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2744 | LSEXP_CANT_GIVE_DATA) { |
| 2745 | if (cmd == ELS_CMD_PLOGI) { |
| 2746 | delay = 1000; |
| 2747 | maxretry = 48; |
| 2748 | } |
| 2749 | retry = 1; |
| 2750 | break; |
| 2751 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2752 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2753 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2754 | maxretry = lpfc_max_els_tries + 1; |
| 2755 | retry = 1; |
| 2756 | break; |
| 2757 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2758 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2759 | (cmd == ELS_CMD_FDISC) && |
| 2760 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2761 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2762 | "0125 FDISC Failed (x%x). " |
| 2763 | "Fabric out of resources\n", |
| 2764 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2765 | lpfc_vport_set_state(vport, |
| 2766 | FC_VPORT_NO_FABRIC_RSCS); |
| 2767 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2768 | break; |
| 2769 | |
| 2770 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2771 | if ((cmd == ELS_CMD_PLOGI) || |
| 2772 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2773 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2774 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2775 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2776 | /* FDISC retry policy */ |
| 2777 | maxretry = 48; |
| 2778 | if (cmdiocb->retry >= 32) |
| 2779 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2780 | } |
| 2781 | retry = 1; |
| 2782 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2783 | |
| 2784 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2785 | /* There are some cases where switches return this |
| 2786 | * error when they are not ready and should be returning |
| 2787 | * Logical Busy. We should delay every time. |
| 2788 | */ |
| 2789 | if (cmd == ELS_CMD_FDISC && |
| 2790 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2791 | maxretry = 3; |
| 2792 | delay = 1000; |
| 2793 | retry = 1; |
| 2794 | break; |
| 2795 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2796 | case LSRJT_PROTOCOL_ERR: |
| 2797 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2798 | (cmd == ELS_CMD_FDISC) && |
| 2799 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2800 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2801 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2802 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2803 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2804 | "Fabric Detected Bad WWN\n", |
| 2805 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2806 | lpfc_vport_set_state(vport, |
| 2807 | FC_VPORT_FABRIC_REJ_WWN); |
| 2808 | } |
| 2809 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2810 | } |
| 2811 | break; |
| 2812 | |
| 2813 | case IOSTAT_INTERMED_RSP: |
| 2814 | case IOSTAT_BA_RJT: |
| 2815 | break; |
| 2816 | |
| 2817 | default: |
| 2818 | break; |
| 2819 | } |
| 2820 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2821 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2822 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2823 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2824 | if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2825 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2826 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2827 | /* FLOGI retry policy */ |
| 2828 | retry = 1; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2829 | /* retry forever */ |
| 2830 | maxretry = 0; |
| 2831 | if (cmdiocb->retry >= 100) |
| 2832 | delay = 5000; |
| 2833 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2834 | delay = 1000; |
| 2835 | } |
| 2836 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2837 | cmdiocb->retry++; |
| 2838 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2839 | phba->fc_stat.elsRetryExceeded++; |
| 2840 | retry = 0; |
| 2841 | } |
| 2842 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2843 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2844 | retry = 0; |
| 2845 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2846 | if (retry) { |
| 2847 | |
| 2848 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2849 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2850 | "0107 Retry ELS command x%x to remote " |
| 2851 | "NPORT x%x Data: x%x x%x\n", |
| 2852 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2853 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2854 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2855 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2856 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2857 | /* Don't reset timer for no resources */ |
| 2858 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2859 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2860 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2861 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2862 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2866 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2867 | phba->fc_stat.elsDelayRetry++; |
| 2868 | ndlp->nlp_retry = cmdiocb->retry; |
| 2869 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2870 | /* delay is specified in milliseconds */ |
| 2871 | mod_timer(&ndlp->nlp_delayfunc, |
| 2872 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2873 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2874 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2875 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2876 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2877 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2878 | if (cmd == ELS_CMD_PRLI) |
| 2879 | lpfc_nlp_set_state(vport, ndlp, |
| 2880 | NLP_STE_REG_LOGIN_ISSUE); |
| 2881 | else |
| 2882 | lpfc_nlp_set_state(vport, ndlp, |
| 2883 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2884 | ndlp->nlp_last_elscmd = cmd; |
| 2885 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2886 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2887 | } |
| 2888 | switch (cmd) { |
| 2889 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2890 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2891 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2892 | case ELS_CMD_FDISC: |
| 2893 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2894 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2895 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2896 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2897 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2898 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2899 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2900 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2901 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2902 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2903 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2904 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2905 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2906 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2907 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2908 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2909 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2910 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2911 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2912 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2913 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2914 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2915 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2916 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2917 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2918 | } |
| 2919 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2920 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2921 | if (logerr) { |
| 2922 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2923 | "0137 No retry ELS command x%x to remote " |
| 2924 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2925 | cmd, did, irsp->ulpStatus, |
| 2926 | irsp->un.ulpWord[4]); |
| 2927 | } |
| 2928 | else { |
| 2929 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2930 | "0108 No retry ELS command x%x to remote " |
| 2931 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2932 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2933 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2934 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2935 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2936 | } |
| 2937 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2938 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2939 | * 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] | 2940 | * @phba: pointer to lpfc hba data structure. |
| 2941 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 2942 | * |
| 2943 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 2944 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 2945 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 2946 | * response of the command IOCB. If so, it will be released before releasing |
| 2947 | * the lpfc DMA buffer associated with the IOCB itself. |
| 2948 | * |
| 2949 | * Return code |
| 2950 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2951 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2952 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2953 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2954 | { |
| 2955 | struct lpfc_dmabuf *buf_ptr; |
| 2956 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2957 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2958 | if (!list_empty(&buf_ptr1->list)) { |
| 2959 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2960 | struct lpfc_dmabuf, |
| 2961 | list); |
| 2962 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2963 | kfree(buf_ptr); |
| 2964 | } |
| 2965 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2966 | kfree(buf_ptr1); |
| 2967 | return 0; |
| 2968 | } |
| 2969 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2970 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2971 | * 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] | 2972 | * @phba: pointer to lpfc hba data structure. |
| 2973 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 2974 | * |
| 2975 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 2976 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 2977 | * pool. |
| 2978 | * |
| 2979 | * Return code |
| 2980 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2981 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2982 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2983 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2984 | { |
| 2985 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2986 | kfree(buf_ptr); |
| 2987 | return 0; |
| 2988 | } |
| 2989 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2990 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2991 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2992 | * @phba: pointer to lpfc hba data structure. |
| 2993 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 2994 | * |
| 2995 | * This routine frees a command IOCB and its associated resources. The |
| 2996 | * command IOCB data structure contains the reference to various associated |
| 2997 | * resources, these fields must be set to NULL if the associated reference |
| 2998 | * not present: |
| 2999 | * context1 - reference to ndlp |
| 3000 | * context2 - reference to cmd |
| 3001 | * context2->next - reference to rsp |
| 3002 | * context3 - reference to bpl |
| 3003 | * |
| 3004 | * It first properly decrements the reference count held on ndlp for the |
| 3005 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3006 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3007 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3008 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3009 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3010 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3011 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3012 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3013 | * |
| 3014 | * Return code |
| 3015 | * 0 - Success (currently, always return 0) |
| 3016 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3017 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3018 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3019 | { |
| 3020 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3021 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3022 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3023 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3024 | if (ndlp) { |
| 3025 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3026 | lpfc_nlp_put(ndlp); |
| 3027 | |
| 3028 | /* If the ndlp is not being used by another discovery |
| 3029 | * thread, free it. |
| 3030 | */ |
| 3031 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3032 | /* If ndlp is being used by another discovery |
| 3033 | * thread, just clear NLP_DEFER_RM |
| 3034 | */ |
| 3035 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3036 | } |
| 3037 | } |
| 3038 | else |
| 3039 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3040 | elsiocb->context1 = NULL; |
| 3041 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3042 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3043 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3044 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3045 | /* Firmware could still be in progress of DMAing |
| 3046 | * payload, so don't free data buffer till after |
| 3047 | * a hbeat. |
| 3048 | */ |
| 3049 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3050 | buf_ptr = elsiocb->context2; |
| 3051 | elsiocb->context2 = NULL; |
| 3052 | if (buf_ptr) { |
| 3053 | buf_ptr1 = NULL; |
| 3054 | spin_lock_irq(&phba->hbalock); |
| 3055 | if (!list_empty(&buf_ptr->list)) { |
| 3056 | list_remove_head(&buf_ptr->list, |
| 3057 | buf_ptr1, struct lpfc_dmabuf, |
| 3058 | list); |
| 3059 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3060 | list_add_tail(&buf_ptr1->list, |
| 3061 | &phba->elsbuf); |
| 3062 | phba->elsbuf_cnt++; |
| 3063 | } |
| 3064 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3065 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3066 | phba->elsbuf_cnt++; |
| 3067 | spin_unlock_irq(&phba->hbalock); |
| 3068 | } |
| 3069 | } else { |
| 3070 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3071 | lpfc_els_free_data(phba, buf_ptr1); |
| 3072 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3073 | } |
| 3074 | |
| 3075 | if (elsiocb->context3) { |
| 3076 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3077 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3078 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3079 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3080 | return 0; |
| 3081 | } |
| 3082 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3083 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3084 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3085 | * @phba: pointer to lpfc hba data structure. |
| 3086 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3087 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3088 | * |
| 3089 | * This routine is the completion callback function to the Logout (LOGO) |
| 3090 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3091 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3092 | * release the ndlp if it has the last reference remaining (reference count |
| 3093 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3094 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3095 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3096 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3097 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3098 | * IOCB data structure. |
| 3099 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3100 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3101 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3102 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3103 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3104 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3105 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3106 | IOCB_t *irsp; |
| 3107 | |
| 3108 | irsp = &rspiocb->iocb; |
| 3109 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3110 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3111 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3112 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3113 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3114 | "0109 ACC to LOGO completes to NPort x%x " |
| 3115 | "Data: x%x x%x x%x\n", |
| 3116 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3117 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3118 | |
| 3119 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3120 | /* NPort Recovery mode or node is just allocated */ |
| 3121 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3122 | /* If the ndlp is being used by another discovery |
| 3123 | * thread, just unregister the RPI. |
| 3124 | */ |
| 3125 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3126 | } else { |
| 3127 | /* Indicate the node has already released, should |
| 3128 | * not reference to it from within lpfc_els_free_iocb. |
| 3129 | */ |
| 3130 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3131 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3132 | } |
| 3133 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3134 | return; |
| 3135 | } |
| 3136 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3137 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3138 | * 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] | 3139 | * @phba: pointer to lpfc hba data structure. |
| 3140 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3141 | * |
| 3142 | * This routine is the completion callback function for unregister default |
| 3143 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3144 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3145 | * decrements the ndlp reference count held for this completion callback |
| 3146 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3147 | * whether there is only one reference left on the ndlp. If so, it will |
| 3148 | * perform one more decrement and trigger the release of the ndlp. |
| 3149 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3150 | void |
| 3151 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3152 | { |
| 3153 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3154 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3155 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3156 | /* |
| 3157 | * This routine is used to register and unregister in previous SLI |
| 3158 | * modes. |
| 3159 | */ |
| 3160 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
| 3161 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 3162 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
| 3163 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3164 | pmb->context1 = NULL; |
| 3165 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3166 | kfree(mp); |
| 3167 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3168 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3169 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3170 | /* This is the end of the default RPI cleanup logic for this |
| 3171 | * ndlp. If no other discovery threads are using this ndlp. |
| 3172 | * we should free all resources associated with it. |
| 3173 | */ |
| 3174 | lpfc_nlp_not_used(ndlp); |
| 3175 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3176 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3177 | return; |
| 3178 | } |
| 3179 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3180 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3181 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3182 | * @phba: pointer to lpfc hba data structure. |
| 3183 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3184 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3185 | * |
| 3186 | * This routine is the completion callback function for ELS Response IOCB |
| 3187 | * command. In normal case, this callback function just properly sets the |
| 3188 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3189 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3190 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3191 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3192 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3193 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3194 | * are currently referring it. |
| 3195 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3196 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3197 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3198 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3199 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3200 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3201 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3202 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3203 | IOCB_t *irsp; |
| 3204 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3205 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3206 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3207 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3208 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3209 | irsp = &rspiocb->iocb; |
| 3210 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3211 | if (cmdiocb->context_un.mbox) |
| 3212 | mbox = cmdiocb->context_un.mbox; |
| 3213 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3214 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3215 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3216 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3217 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3218 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3219 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3220 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3221 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3222 | */ |
| 3223 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3224 | ls_rjt = 1; |
| 3225 | } |
| 3226 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3227 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3228 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3229 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3230 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3231 | if (mp) { |
| 3232 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3233 | kfree(mp); |
| 3234 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3235 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3236 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3237 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3238 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3239 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3240 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3241 | /* Indicate the node has already released, |
| 3242 | * should not reference to it from within |
| 3243 | * the routine lpfc_els_free_iocb. |
| 3244 | */ |
| 3245 | cmdiocb->context1 = NULL; |
| 3246 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3247 | goto out; |
| 3248 | } |
| 3249 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3250 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3251 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3252 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3253 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3254 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3255 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3256 | "0110 ELS response tag x%x completes " |
| 3257 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3258 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3259 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3260 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3261 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3262 | if (mbox) { |
| 3263 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3264 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3265 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3266 | /* Increment reference count to ndlp to hold the |
| 3267 | * reference to ndlp for the callback function. |
| 3268 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3269 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3270 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3271 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3272 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3273 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3274 | } |
| 3275 | else { |
| 3276 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3277 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3278 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3279 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3280 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3281 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3282 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3283 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3284 | else |
| 3285 | /* Decrement the ndlp reference count we |
| 3286 | * set for this failed mailbox command. |
| 3287 | */ |
| 3288 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3289 | |
| 3290 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3291 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3292 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3293 | "Data: x%x x%x x%x\n", |
| 3294 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3295 | ndlp->nlp_rpi); |
| 3296 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3297 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3298 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3299 | /* Indicate node has already been released, |
| 3300 | * should not reference to it from within |
| 3301 | * the routine lpfc_els_free_iocb. |
| 3302 | */ |
| 3303 | cmdiocb->context1 = NULL; |
| 3304 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3305 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3306 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3307 | if (!lpfc_error_lost_link(irsp) && |
| 3308 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3309 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3310 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3311 | /* Indicate node has already been |
| 3312 | * released, should not reference |
| 3313 | * to it from within the routine |
| 3314 | * lpfc_els_free_iocb. |
| 3315 | */ |
| 3316 | cmdiocb->context1 = NULL; |
| 3317 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3318 | } |
| 3319 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3320 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3321 | if (mp) { |
| 3322 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3323 | kfree(mp); |
| 3324 | } |
| 3325 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3326 | } |
| 3327 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3328 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3329 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3330 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3331 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3332 | |
| 3333 | /* If the node is not being used by another discovery thread, |
| 3334 | * and we are sending a reject, we are done with it. |
| 3335 | * Release driver reference count here and free associated |
| 3336 | * resources. |
| 3337 | */ |
| 3338 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3339 | if (lpfc_nlp_not_used(ndlp)) |
| 3340 | /* Indicate node has already been released, |
| 3341 | * should not reference to it from within |
| 3342 | * the routine lpfc_els_free_iocb. |
| 3343 | */ |
| 3344 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3345 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3346 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3347 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3348 | return; |
| 3349 | } |
| 3350 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3351 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3352 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3353 | * @vport: pointer to a host virtual N_Port data structure. |
| 3354 | * @flag: the els command code to be accepted. |
| 3355 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3356 | * @ndlp: pointer to a node-list data structure. |
| 3357 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3358 | * |
| 3359 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3360 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3361 | * specific ACC response command to be issued and invokes the |
| 3362 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3363 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3364 | * field of the IOCB for the completion callback function to issue the |
| 3365 | * mailbox command to the HBA later when callback is invoked. |
| 3366 | * |
| 3367 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3368 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3369 | * will be stored into the context1 field of the IOCB for the completion |
| 3370 | * callback function to the corresponding response ELS IOCB command. |
| 3371 | * |
| 3372 | * Return code |
| 3373 | * 0 - Successfully issued acc response |
| 3374 | * 1 - Failed to issue acc response |
| 3375 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3377 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3378 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3379 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3380 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3381 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3382 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3383 | IOCB_t *icmd; |
| 3384 | IOCB_t *oldcmd; |
| 3385 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | struct lpfc_sli *psli; |
| 3387 | uint8_t *pcmd; |
| 3388 | uint16_t cmdsize; |
| 3389 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3390 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3391 | |
| 3392 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3393 | oldcmd = &oldiocb->iocb; |
| 3394 | |
| 3395 | switch (flag) { |
| 3396 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3397 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3398 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3399 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3400 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3401 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3402 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3403 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3404 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3406 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3407 | icmd = &elsiocb->iocb; |
| 3408 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3409 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3410 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3411 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3412 | |
| 3413 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3414 | "Issue ACC: did:x%x flg:x%x", |
| 3415 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3416 | break; |
| 3417 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3418 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3419 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3420 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3421 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3422 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3423 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | icmd = &elsiocb->iocb; |
| 3425 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3426 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3427 | |
| 3428 | if (mbox) |
| 3429 | elsiocb->context_un.mbox = mbox; |
| 3430 | |
| 3431 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3432 | pcmd += sizeof(uint32_t); |
| 3433 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3434 | |
| 3435 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3436 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3437 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3438 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3439 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3440 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3441 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3442 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3443 | if (!elsiocb) |
| 3444 | return 1; |
| 3445 | |
| 3446 | icmd = &elsiocb->iocb; |
| 3447 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3448 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3449 | |
| 3450 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3451 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3452 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3453 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3454 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3455 | |
| 3456 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3457 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3458 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3459 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3461 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3463 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3464 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3465 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3466 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3467 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3468 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3469 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3470 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3471 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3472 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3473 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3474 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3475 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3476 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3480 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3481 | if (rc == IOCB_ERROR) { |
| 3482 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3483 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3485 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3486 | } |
| 3487 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3488 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3489 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3490 | * @vport: pointer to a virtual N_Port data structure. |
| 3491 | * @rejectError: |
| 3492 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3493 | * @ndlp: pointer to a node-list data structure. |
| 3494 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3495 | * |
| 3496 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3497 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3498 | * context_un.mbox field of the IOCB for the completion callback function |
| 3499 | * to issue to the HBA later. |
| 3500 | * |
| 3501 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3502 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3503 | * will be stored into the context1 field of the IOCB for the completion |
| 3504 | * callback function to the reject response ELS IOCB command. |
| 3505 | * |
| 3506 | * Return code |
| 3507 | * 0 - Successfully issued reject response |
| 3508 | * 1 - Failed to issue reject response |
| 3509 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3510 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3511 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3512 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3513 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3514 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3515 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3516 | IOCB_t *icmd; |
| 3517 | IOCB_t *oldcmd; |
| 3518 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3519 | struct lpfc_sli *psli; |
| 3520 | uint8_t *pcmd; |
| 3521 | uint16_t cmdsize; |
| 3522 | int rc; |
| 3523 | |
| 3524 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3525 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3526 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3527 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3528 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3529 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3530 | |
| 3531 | icmd = &elsiocb->iocb; |
| 3532 | oldcmd = &oldiocb->iocb; |
| 3533 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3534 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3535 | |
| 3536 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3537 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3538 | *((uint32_t *) (pcmd)) = rejectError; |
| 3539 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3540 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3541 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3542 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3543 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3544 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3545 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3546 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3547 | "rpi x%x\n", |
| 3548 | rejectError, elsiocb->iotag, |
| 3549 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3550 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3551 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3552 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3553 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3554 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3555 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3556 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3557 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3558 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3559 | if (rc == IOCB_ERROR) { |
| 3560 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3561 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3562 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3563 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3564 | } |
| 3565 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3566 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3567 | * 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] | 3568 | * @vport: pointer to a virtual N_Port data structure. |
| 3569 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3570 | * @ndlp: pointer to a node-list data structure. |
| 3571 | * |
| 3572 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3573 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3574 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3575 | * |
| 3576 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3577 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3578 | * will be stored into the context1 field of the IOCB for the completion |
| 3579 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3580 | * |
| 3581 | * Return code |
| 3582 | * 0 - Successfully issued acc adisc response |
| 3583 | * 1 - Failed to issue adisc acc response |
| 3584 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3585 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3586 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3587 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3588 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3589 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3590 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3591 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3593 | uint8_t *pcmd; |
| 3594 | uint16_t cmdsize; |
| 3595 | int rc; |
| 3596 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3597 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3598 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3599 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3600 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3601 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3602 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3603 | icmd = &elsiocb->iocb; |
| 3604 | oldcmd = &oldiocb->iocb; |
| 3605 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3606 | |
| 3607 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3608 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3609 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3610 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3611 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3612 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3613 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3614 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3615 | |
| 3616 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3617 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3618 | |
| 3619 | ap = (ADISC *) (pcmd); |
| 3620 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3621 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3622 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3623 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3624 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3625 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3626 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3627 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3628 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3629 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3630 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3631 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3632 | if (rc == IOCB_ERROR) { |
| 3633 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3634 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3635 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3636 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3637 | } |
| 3638 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3639 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3640 | * 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] | 3641 | * @vport: pointer to a virtual N_Port data structure. |
| 3642 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3643 | * @ndlp: pointer to a node-list data structure. |
| 3644 | * |
| 3645 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3646 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3647 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3648 | * |
| 3649 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3650 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3651 | * will be stored into the context1 field of the IOCB for the completion |
| 3652 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3653 | * |
| 3654 | * Return code |
| 3655 | * 0 - Successfully issued acc prli response |
| 3656 | * 1 - Failed to issue acc prli response |
| 3657 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3658 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3659 | 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] | 3660 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3661 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3662 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3663 | PRLI *npr; |
| 3664 | lpfc_vpd_t *vpd; |
| 3665 | IOCB_t *icmd; |
| 3666 | IOCB_t *oldcmd; |
| 3667 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3668 | struct lpfc_sli *psli; |
| 3669 | uint8_t *pcmd; |
| 3670 | uint16_t cmdsize; |
| 3671 | int rc; |
| 3672 | |
| 3673 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3674 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3675 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3676 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3677 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3678 | if (!elsiocb) |
| 3679 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3680 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3681 | icmd = &elsiocb->iocb; |
| 3682 | oldcmd = &oldiocb->iocb; |
| 3683 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3684 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3685 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3686 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3687 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3688 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3689 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3690 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3691 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3692 | |
| 3693 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3694 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3695 | |
| 3696 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3697 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3698 | |
| 3699 | npr = (PRLI *) pcmd; |
| 3700 | vpd = &phba->vpd; |
| 3701 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3702 | * If the remote port is a target and our firmware version is 3.20 or |
| 3703 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3704 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3705 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3706 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3707 | npr->ConfmComplAllowed = 1; |
| 3708 | npr->Retry = 1; |
| 3709 | npr->TaskRetryIdReq = 1; |
| 3710 | } |
| 3711 | |
| 3712 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3713 | npr->estabImagePair = 1; |
| 3714 | npr->readXferRdyDis = 1; |
| 3715 | npr->ConfmComplAllowed = 1; |
| 3716 | |
| 3717 | npr->prliType = PRLI_FCP_TYPE; |
| 3718 | npr->initiatorFunc = 1; |
| 3719 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3720 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3721 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3722 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3723 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3724 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3725 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3726 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3727 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3728 | if (rc == IOCB_ERROR) { |
| 3729 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3730 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3731 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3732 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3733 | } |
| 3734 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3735 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3736 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3737 | * @vport: pointer to a virtual N_Port data structure. |
| 3738 | * @format: rnid command format. |
| 3739 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3740 | * @ndlp: pointer to a node-list data structure. |
| 3741 | * |
| 3742 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3743 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3744 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3745 | * issue the response. Note that this command does not need to hold the ndlp |
| 3746 | * reference count for the callback. So, the ndlp reference count taken by |
| 3747 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3748 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3749 | * there is no ndlp reference available. |
| 3750 | * |
| 3751 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3752 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3753 | * will be stored into the context1 field of the IOCB for the completion |
| 3754 | * callback function. However, for the RNID Accept Response ELS command, |
| 3755 | * this is undone later by this routine after the IOCB is allocated. |
| 3756 | * |
| 3757 | * Return code |
| 3758 | * 0 - Successfully issued acc rnid response |
| 3759 | * 1 - Failed to issue acc rnid response |
| 3760 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3761 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3762 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3763 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3764 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3765 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3767 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3768 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3769 | struct lpfc_sli *psli; |
| 3770 | uint8_t *pcmd; |
| 3771 | uint16_t cmdsize; |
| 3772 | int rc; |
| 3773 | |
| 3774 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3775 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3776 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3777 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3778 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3779 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3780 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3781 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3782 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3783 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3784 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3785 | icmd = &elsiocb->iocb; |
| 3786 | oldcmd = &oldiocb->iocb; |
| 3787 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3788 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3789 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3790 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3791 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3792 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3793 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3794 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3795 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3796 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3797 | rn = (RNID *) (pcmd); |
| 3798 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3799 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3800 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3801 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3802 | switch (format) { |
| 3803 | case 0: |
| 3804 | rn->SpecificLen = 0; |
| 3805 | break; |
| 3806 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3807 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3808 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3809 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3810 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3811 | rn->un.topologyDisc.physPort = 0; |
| 3812 | rn->un.topologyDisc.attachedNodes = 0; |
| 3813 | break; |
| 3814 | default: |
| 3815 | rn->CommonLen = 0; |
| 3816 | rn->SpecificLen = 0; |
| 3817 | break; |
| 3818 | } |
| 3819 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3820 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3821 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3822 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3823 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3824 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3825 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3826 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3827 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3828 | * it could be freed */ |
| 3829 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3830 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3831 | if (rc == IOCB_ERROR) { |
| 3832 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3833 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3835 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3836 | } |
| 3837 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3838 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3839 | * 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] | 3840 | * @vport: pointer to a host virtual N_Port data structure. |
| 3841 | * |
| 3842 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3843 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3844 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3845 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3846 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3847 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3848 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3849 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3850 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3851 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3852 | * no more ADISC need to be sent. |
| 3853 | * |
| 3854 | * Return code |
| 3855 | * The number of N_Ports with adisc issued. |
| 3856 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3857 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3858 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3859 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3860 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3861 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3862 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3863 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3864 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3865 | 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] | 3866 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3867 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3868 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3869 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3870 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3871 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3872 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3873 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3874 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3875 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3876 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3877 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3878 | vport->num_disc_nodes++; |
| 3879 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3880 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3881 | spin_lock_irq(shost->host_lock); |
| 3882 | vport->fc_flag |= FC_NLP_MORE; |
| 3883 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3884 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | } |
| 3888 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3889 | spin_lock_irq(shost->host_lock); |
| 3890 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3891 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3892 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3893 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3894 | } |
| 3895 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3896 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3897 | * 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] | 3898 | * @vport: pointer to a host virtual N_Port data structure. |
| 3899 | * |
| 3900 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3901 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3902 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3903 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3904 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3905 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3906 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3907 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3908 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3909 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3910 | * PLOGI need to be sent. |
| 3911 | * |
| 3912 | * Return code |
| 3913 | * The number of N_Ports with plogi issued. |
| 3914 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3915 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3916 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3917 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3918 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3919 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3920 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3921 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3922 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3923 | 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] | 3924 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3925 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3926 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3927 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3928 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3929 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3930 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3931 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3932 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3933 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3934 | vport->num_disc_nodes++; |
| 3935 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3936 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3937 | spin_lock_irq(shost->host_lock); |
| 3938 | vport->fc_flag |= FC_NLP_MORE; |
| 3939 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3940 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3941 | } |
| 3942 | } |
| 3943 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3944 | if (sentplogi) { |
| 3945 | lpfc_set_disctmo(vport); |
| 3946 | } |
| 3947 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3948 | spin_lock_irq(shost->host_lock); |
| 3949 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3950 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3951 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3952 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3953 | } |
| 3954 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3955 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3956 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3957 | * @vport: pointer to a host virtual N_Port data structure. |
| 3958 | * |
| 3959 | * This routine cleans up any Registration State Change Notification |
| 3960 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3961 | * @vport together with the host_lock is used to prevent multiple thread |
| 3962 | * trying to access the RSCN array on a same @vport at the same time. |
| 3963 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3964 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3965 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3966 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3967 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3968 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3969 | int i; |
| 3970 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3971 | spin_lock_irq(shost->host_lock); |
| 3972 | if (vport->fc_rscn_flush) { |
| 3973 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3974 | spin_unlock_irq(shost->host_lock); |
| 3975 | return; |
| 3976 | } |
| 3977 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 3978 | vport->fc_rscn_flush = 1; |
| 3979 | spin_unlock_irq(shost->host_lock); |
| 3980 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3981 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3982 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3983 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3984 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3985 | spin_lock_irq(shost->host_lock); |
| 3986 | vport->fc_rscn_id_cnt = 0; |
| 3987 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 3988 | spin_unlock_irq(shost->host_lock); |
| 3989 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3990 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 3991 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3992 | } |
| 3993 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3994 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3995 | * 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] | 3996 | * @vport: pointer to a host virtual N_Port data structure. |
| 3997 | * @did: remote destination port identifier. |
| 3998 | * |
| 3999 | * This routine checks whether there is any pending Registration State |
| 4000 | * Configuration Notification (RSCN) to a @did on @vport. |
| 4001 | * |
| 4002 | * Return code |
| 4003 | * None zero - The @did matched with a pending rscn |
| 4004 | * 0 - not able to match @did with a pending rscn |
| 4005 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4006 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4007 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4008 | { |
| 4009 | D_ID ns_did; |
| 4010 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4011 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4012 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4013 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4014 | |
| 4015 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4016 | |
| 4017 | /* Never match fabric nodes for RSCNs */ |
| 4018 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4019 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4020 | |
| 4021 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4022 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4023 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4024 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4025 | spin_lock_irq(shost->host_lock); |
| 4026 | if (vport->fc_rscn_flush) { |
| 4027 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4028 | spin_unlock_irq(shost->host_lock); |
| 4029 | return 0; |
| 4030 | } |
| 4031 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4032 | vport->fc_rscn_flush = 1; |
| 4033 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4034 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4035 | lp = vport->fc_rscn_id_list[i]->virt; |
| 4036 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4037 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4038 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4039 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 4040 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4041 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 4042 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4043 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4044 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 4045 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4046 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4047 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4048 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4049 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4050 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4051 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4052 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4053 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4054 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4055 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4056 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4057 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4058 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4059 | } |
| 4060 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4061 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4062 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4063 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4064 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4065 | return_did_out: |
| 4066 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4067 | vport->fc_rscn_flush = 0; |
| 4068 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4069 | } |
| 4070 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4071 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4072 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4073 | * @vport: pointer to a host virtual N_Port data structure. |
| 4074 | * |
| 4075 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 4076 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 4077 | * State Change Notification). |
| 4078 | * |
| 4079 | * Return code |
| 4080 | * 0 - Successful (currently alway return 0) |
| 4081 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4083 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4084 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4085 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4086 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4087 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4088 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4089 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4090 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4091 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4092 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4093 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4094 | NLP_EVT_DEVICE_RECOVERY); |
| 4095 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4096 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4097 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4098 | } |
| 4099 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4100 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4101 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4102 | * @vport: pointer to a host virtual N_Port data structure. |
| 4103 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4104 | * |
| 4105 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4106 | * applications. |
| 4107 | */ |
| 4108 | static void |
| 4109 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4110 | struct lpfc_iocbq *cmdiocb) |
| 4111 | { |
| 4112 | struct lpfc_dmabuf *pcmd; |
| 4113 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4114 | uint32_t *payload_ptr; |
| 4115 | uint32_t payload_len; |
| 4116 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4117 | |
| 4118 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4119 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4120 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4121 | |
| 4122 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4123 | payload_len, GFP_KERNEL); |
| 4124 | if (!rscn_event_data) { |
| 4125 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4126 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4127 | return; |
| 4128 | } |
| 4129 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4130 | rscn_event_data->payload_length = payload_len; |
| 4131 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4132 | payload_len); |
| 4133 | |
| 4134 | fc_host_post_vendor_event(shost, |
| 4135 | fc_get_event_number(), |
| 4136 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4137 | (char *)rscn_event_data, |
| 4138 | LPFC_NL_VENDOR_ID); |
| 4139 | |
| 4140 | kfree(rscn_event_data); |
| 4141 | } |
| 4142 | |
| 4143 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4144 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4145 | * @vport: pointer to a host virtual N_Port data structure. |
| 4146 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4147 | * @ndlp: pointer to a node-list data structure. |
| 4148 | * |
| 4149 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4150 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4151 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4152 | * discover state machine is about to begin discovery, it just accepts the |
| 4153 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4154 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4155 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4156 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4157 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4158 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4159 | * routine is invoked to handle the RSCN event. |
| 4160 | * |
| 4161 | * Return code |
| 4162 | * 0 - Just sent the acc response |
| 4163 | * 1 - Sent the acc response and waited for name server completion |
| 4164 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4165 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4166 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4167 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4169 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4170 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4171 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4172 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4173 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4174 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4175 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4176 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4177 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4178 | |
| 4179 | icmd = &cmdiocb->iocb; |
| 4180 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4181 | lp = (uint32_t *) pcmd->virt; |
| 4182 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4183 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4184 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4185 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4186 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4187 | "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] | 4188 | vport->fc_flag, payload_len, *lp, |
| 4189 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4190 | |
| 4191 | /* Send an RSCN event to the management application */ |
| 4192 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4193 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4194 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4195 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4196 | FCH_EVT_RSCN, lp[i]); |
| 4197 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4198 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4199 | * Discovery processing will satisfy it. |
| 4200 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4201 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4202 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4203 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4204 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4205 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4206 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4207 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4208 | } |
| 4209 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4210 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4211 | * just ACC and ignore it. |
| 4212 | */ |
| 4213 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4214 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4215 | i = payload_len; |
| 4216 | datap = lp; |
| 4217 | while (i > 0) { |
| 4218 | nportid = *datap++; |
| 4219 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4220 | i -= sizeof(uint32_t); |
| 4221 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4222 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4223 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4224 | } |
| 4225 | if (rscn_id == hba_id) { |
| 4226 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4227 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4228 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4229 | "Data: x%x x%x x%x x%x\n", |
| 4230 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4231 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4232 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4233 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4234 | ndlp->nlp_DID, vport->port_state, |
| 4235 | ndlp->nlp_flag); |
| 4236 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4237 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4238 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4239 | return 0; |
| 4240 | } |
| 4241 | } |
| 4242 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4243 | spin_lock_irq(shost->host_lock); |
| 4244 | if (vport->fc_rscn_flush) { |
| 4245 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4246 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4247 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4248 | /* Send back ACC */ |
| 4249 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4250 | return 0; |
| 4251 | } |
| 4252 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4253 | vport->fc_rscn_flush = 1; |
| 4254 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4255 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4256 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4257 | /* If we are already processing an RSCN, save the received |
| 4258 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4259 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4260 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4261 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4262 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4263 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4264 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4265 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4266 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4267 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4268 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4269 | vport->fc_flag |= FC_RSCN_MODE; |
| 4270 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4271 | if (rscn_cnt) { |
| 4272 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4273 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4274 | } |
| 4275 | if ((rscn_cnt) && |
| 4276 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4277 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4278 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4279 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4280 | payload_len); |
| 4281 | } else { |
| 4282 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4283 | vport->fc_rscn_id_cnt++; |
| 4284 | /* If we zero, cmdiocb->context2, the calling |
| 4285 | * routine will not try to free it. |
| 4286 | */ |
| 4287 | cmdiocb->context2 = NULL; |
| 4288 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4289 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4290 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4291 | "0235 Deferred RSCN " |
| 4292 | "Data: x%x x%x x%x\n", |
| 4293 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4294 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4295 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4296 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4297 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4298 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4299 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4300 | "0234 ReDiscovery RSCN " |
| 4301 | "Data: x%x x%x x%x\n", |
| 4302 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4303 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4304 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4305 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4306 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4307 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4308 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4309 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4310 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4311 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4312 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4313 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4314 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4315 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4316 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4317 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4318 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4319 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4320 | spin_lock_irq(shost->host_lock); |
| 4321 | vport->fc_flag |= FC_RSCN_MODE; |
| 4322 | spin_unlock_irq(shost->host_lock); |
| 4323 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4324 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4325 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4326 | /* |
| 4327 | * If we zero, cmdiocb->context2, the calling routine will |
| 4328 | * not try to free it. |
| 4329 | */ |
| 4330 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4331 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4332 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4333 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4334 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4335 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4336 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4337 | } |
| 4338 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4339 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4340 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4341 | * @vport: pointer to a host virtual N_Port data structure. |
| 4342 | * |
| 4343 | * This routine handles the Registration State Configuration Notification |
| 4344 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4345 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4346 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4347 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4348 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4349 | * RSCN activities with the @vport. |
| 4350 | * |
| 4351 | * Return code |
| 4352 | * 0 - Cleaned up rscn on the @vport |
| 4353 | * 1 - Wait for plogi to name server before proceed |
| 4354 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4355 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4356 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4357 | { |
| 4358 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4359 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4360 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4361 | /* Ignore RSCN if the port is being torn down. */ |
| 4362 | if (vport->load_flag & FC_UNLOADING) { |
| 4363 | lpfc_els_flush_rscn(vport); |
| 4364 | return 0; |
| 4365 | } |
| 4366 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4367 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4368 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4369 | |
| 4370 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4371 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4372 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4373 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4374 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4375 | |
| 4376 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4377 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4378 | vport->num_disc_nodes = 0; |
| 4379 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4380 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4381 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4382 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4383 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4384 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4385 | /* Wait for NameServer query cmpl before we can |
| 4386 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4387 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4388 | } else { |
| 4389 | /* If login to NameServer does not exist, issue one */ |
| 4390 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4391 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4392 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4393 | /* Wait for NameServer login cmpl before we can |
| 4394 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4395 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4396 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4397 | if (ndlp) { |
| 4398 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4399 | NLP_STE_PLOGI_ISSUE); |
| 4400 | if (!ndlp) { |
| 4401 | lpfc_els_flush_rscn(vport); |
| 4402 | return 0; |
| 4403 | } |
| 4404 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4405 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4406 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4407 | if (!ndlp) { |
| 4408 | lpfc_els_flush_rscn(vport); |
| 4409 | return 0; |
| 4410 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4411 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4412 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4413 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4414 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4415 | ndlp->nlp_type |= NLP_FABRIC; |
| 4416 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4417 | /* Wait for NameServer login cmpl before we can |
| 4418 | * continue |
| 4419 | */ |
| 4420 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4421 | } |
| 4422 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4423 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4424 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4425 | } |
| 4426 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4427 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4428 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4429 | * @vport: pointer to a host virtual N_Port data structure. |
| 4430 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4431 | * @ndlp: pointer to a node-list data structure. |
| 4432 | * |
| 4433 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4434 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4435 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4436 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4437 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4438 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4439 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4440 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4441 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4442 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4443 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4444 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4445 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4446 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4447 | * |
| 4448 | * Return code |
| 4449 | * 0 - Successfully processed the unsolicited flogi |
| 4450 | * 1 - Failed to process the unsolicited flogi |
| 4451 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4452 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4453 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4454 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4455 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4456 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4457 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4458 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4459 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4460 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4461 | struct serv_parm *sp; |
| 4462 | LPFC_MBOXQ_t *mbox; |
| 4463 | struct ls_rjt stat; |
| 4464 | uint32_t cmd, did; |
| 4465 | int rc; |
| 4466 | |
| 4467 | cmd = *lp++; |
| 4468 | sp = (struct serv_parm *) lp; |
| 4469 | |
| 4470 | /* FLOGI received */ |
| 4471 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4472 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4473 | |
| 4474 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4475 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4476 | did = icmd->un.elsreq64.remoteID; |
| 4477 | |
| 4478 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4479 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4480 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4481 | "0113 An FLOGI ELS command x%x was " |
| 4482 | "received from DID x%x in Loop Mode\n", |
| 4483 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4484 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4485 | } |
| 4486 | |
| 4487 | did = Fabric_DID; |
| 4488 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4489 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4490 | /* For a FLOGI we accept, then if our portname is greater |
| 4491 | * then the remote portname we initiate Nport login. |
| 4492 | */ |
| 4493 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4494 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4495 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4496 | |
| 4497 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4498 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4499 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4500 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4501 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4502 | lpfc_linkdown(phba); |
| 4503 | lpfc_init_link(phba, mbox, |
| 4504 | phba->cfg_topology, |
| 4505 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4506 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4507 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4508 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4509 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4510 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4511 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4512 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4513 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4514 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4515 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4516 | spin_lock_irq(shost->host_lock); |
| 4517 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4518 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4519 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4520 | spin_lock_irq(shost->host_lock); |
| 4521 | vport->fc_flag |= FC_PT2PT; |
| 4522 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4523 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4524 | } else { |
| 4525 | /* Reject this request because invalid parameters */ |
| 4526 | stat.un.b.lsRjtRsvd0 = 0; |
| 4527 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4528 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4529 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4530 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4531 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4532 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4536 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4537 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4538 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4539 | } |
| 4540 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4541 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4542 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4543 | * @vport: pointer to a host virtual N_Port data structure. |
| 4544 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4545 | * @ndlp: pointer to a node-list data structure. |
| 4546 | * |
| 4547 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4548 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4549 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4550 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4551 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4552 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4553 | * |
| 4554 | * Return code |
| 4555 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4556 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4557 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4558 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4559 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4560 | { |
| 4561 | struct lpfc_dmabuf *pcmd; |
| 4562 | uint32_t *lp; |
| 4563 | IOCB_t *icmd; |
| 4564 | RNID *rn; |
| 4565 | struct ls_rjt stat; |
| 4566 | uint32_t cmd, did; |
| 4567 | |
| 4568 | icmd = &cmdiocb->iocb; |
| 4569 | did = icmd->un.elsreq64.remoteID; |
| 4570 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4571 | lp = (uint32_t *) pcmd->virt; |
| 4572 | |
| 4573 | cmd = *lp++; |
| 4574 | rn = (RNID *) lp; |
| 4575 | |
| 4576 | /* RNID received */ |
| 4577 | |
| 4578 | switch (rn->Format) { |
| 4579 | case 0: |
| 4580 | case RNID_TOPOLOGY_DISC: |
| 4581 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4582 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4583 | break; |
| 4584 | default: |
| 4585 | /* Reject this request because format not supported */ |
| 4586 | stat.un.b.lsRjtRsvd0 = 0; |
| 4587 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4588 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4589 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4590 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4591 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4592 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4593 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4594 | } |
| 4595 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4596 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4597 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4598 | * @vport: pointer to a host virtual N_Port data structure. |
| 4599 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4600 | * @ndlp: pointer to a node-list data structure. |
| 4601 | * |
| 4602 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4603 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4604 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4605 | * |
| 4606 | * Return code |
| 4607 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4608 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4609 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4610 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4611 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4612 | { |
| 4613 | struct ls_rjt stat; |
| 4614 | |
| 4615 | /* For now, unconditionally reject this command */ |
| 4616 | stat.un.b.lsRjtRsvd0 = 0; |
| 4617 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4618 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4619 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4620 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4621 | return 0; |
| 4622 | } |
| 4623 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4624 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4625 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 4626 | * @vport: pointer to a host virtual N_Port data structure. |
| 4627 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4628 | * @ndlp: pointer to a node-list data structure. |
| 4629 | * |
| 4630 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 4631 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 4632 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 4633 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 4634 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 4635 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 4636 | * command request" and reason code explanation "Invalid Originator |
| 4637 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 4638 | * RRQ from the target. |
| 4639 | **/ |
| 4640 | static void |
| 4641 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4642 | struct lpfc_nodelist *ndlp) |
| 4643 | { |
| 4644 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| 4645 | } |
| 4646 | |
| 4647 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4648 | * 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] | 4649 | * @phba: pointer to lpfc hba data structure. |
| 4650 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4651 | * |
| 4652 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4653 | * mailbox command. This callback function is to actually send the Accept |
| 4654 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4655 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4656 | * mailbox command, constructs the RPS response with the link statistics |
| 4657 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4658 | * response to the RPS. |
| 4659 | * |
| 4660 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4661 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4662 | * will be stored into the context1 field of the IOCB for the completion |
| 4663 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4664 | * |
| 4665 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4666 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4667 | 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] | 4668 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4669 | MAILBOX_t *mb; |
| 4670 | IOCB_t *icmd; |
| 4671 | RPS_RSP *rps_rsp; |
| 4672 | uint8_t *pcmd; |
| 4673 | struct lpfc_iocbq *elsiocb; |
| 4674 | struct lpfc_nodelist *ndlp; |
| 4675 | uint16_t xri, status; |
| 4676 | uint32_t cmdsize; |
| 4677 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4678 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4679 | |
| 4680 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4681 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4682 | pmb->context1 = NULL; |
| 4683 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4684 | |
| 4685 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4686 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4687 | return; |
| 4688 | } |
| 4689 | |
| 4690 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4691 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4692 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4693 | lpfc_max_els_tries, ndlp, |
| 4694 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4695 | |
| 4696 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4697 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4698 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4699 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4700 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4701 | |
| 4702 | icmd = &elsiocb->iocb; |
| 4703 | icmd->ulpContext = xri; |
| 4704 | |
| 4705 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4706 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4707 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4708 | rps_rsp = (RPS_RSP *)pcmd; |
| 4709 | |
| 4710 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4711 | status = 0x10; |
| 4712 | else |
| 4713 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4714 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4715 | status |= 0x4; |
| 4716 | |
| 4717 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4718 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4719 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4720 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4721 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4722 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4723 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4724 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4725 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4726 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4727 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4728 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4729 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4730 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4731 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4732 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4733 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4734 | 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] | 4735 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4736 | return; |
| 4737 | } |
| 4738 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4739 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4740 | * lpfc_els_rcv_rps - Process an unsolicited rps 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 Read Port Status (RPS) IOCB received as an |
| 4746 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4747 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4748 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4749 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4750 | * for reading the HBA link statistics. It is for the callback function, |
| 4751 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4752 | * to actually sending out RPS Accept (ACC) response. |
| 4753 | * |
| 4754 | * Return codes |
| 4755 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4756 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4757 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4758 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4759 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4760 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4761 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4762 | uint32_t *lp; |
| 4763 | uint8_t flag; |
| 4764 | LPFC_MBOXQ_t *mbox; |
| 4765 | struct lpfc_dmabuf *pcmd; |
| 4766 | RPS *rps; |
| 4767 | struct ls_rjt stat; |
| 4768 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4769 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4770 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4771 | /* reject the unsolicited RPS request and done with it */ |
| 4772 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4773 | |
| 4774 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4775 | lp = (uint32_t *) pcmd->virt; |
| 4776 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4777 | rps = (RPS *) lp; |
| 4778 | |
| 4779 | if ((flag == 0) || |
| 4780 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4781 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4782 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4783 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4784 | printk("Fix me....\n"); |
| 4785 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4786 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4787 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4788 | lpfc_read_lnk_stat(phba, mbox); |
| 4789 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4790 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4791 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4792 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4793 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4794 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4795 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4796 | /* Mbox completion will send ELS Response */ |
| 4797 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4798 | /* Decrement reference count used for the failed mbox |
| 4799 | * command. |
| 4800 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4801 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4802 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4803 | } |
| 4804 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4805 | |
| 4806 | reject_out: |
| 4807 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4808 | stat.un.b.lsRjtRsvd0 = 0; |
| 4809 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4810 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4811 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4812 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4813 | return 0; |
| 4814 | } |
| 4815 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4816 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4817 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4818 | * @vport: pointer to a host virtual N_Port data structure. |
| 4819 | * @cmdsize: size of the ELS command. |
| 4820 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4821 | * @ndlp: pointer to a node-list data structure. |
| 4822 | * |
| 4823 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4824 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4825 | * |
| 4826 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4827 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4828 | * will be stored into the context1 field of the IOCB for the completion |
| 4829 | * callback function to the RPL Accept Response ELS command. |
| 4830 | * |
| 4831 | * Return code |
| 4832 | * 0 - Successfully issued ACC RPL ELS command |
| 4833 | * 1 - Failed to issue ACC RPL ELS command |
| 4834 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4835 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4836 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4837 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4838 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4839 | struct lpfc_hba *phba = vport->phba; |
| 4840 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4841 | RPL_RSP rpl_rsp; |
| 4842 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4843 | uint8_t *pcmd; |
| 4844 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4845 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4846 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4847 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4848 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4849 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4850 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4851 | icmd = &elsiocb->iocb; |
| 4852 | oldcmd = &oldiocb->iocb; |
| 4853 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4854 | |
| 4855 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4856 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4857 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4858 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4859 | pcmd += sizeof(uint16_t); |
| 4860 | |
| 4861 | /* Setup the RPL ACC payload */ |
| 4862 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4863 | rpl_rsp.index = 0; |
| 4864 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4865 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4866 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4867 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4868 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4869 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4870 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4871 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4872 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4873 | "rpi x%x\n", |
| 4874 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4875 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4876 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4877 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4878 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4879 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 4880 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4881 | lpfc_els_free_iocb(phba, elsiocb); |
| 4882 | return 1; |
| 4883 | } |
| 4884 | return 0; |
| 4885 | } |
| 4886 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4887 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4888 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4889 | * @vport: pointer to a host virtual N_Port data structure. |
| 4890 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4891 | * @ndlp: pointer to a node-list data structure. |
| 4892 | * |
| 4893 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4894 | * unsolicited event. It first checks the remote port state. If the remote |
| 4895 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4896 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4897 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4898 | * to accept the RPL. |
| 4899 | * |
| 4900 | * Return code |
| 4901 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4902 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4903 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4904 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4905 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4906 | { |
| 4907 | struct lpfc_dmabuf *pcmd; |
| 4908 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4909 | uint32_t maxsize; |
| 4910 | uint16_t cmdsize; |
| 4911 | RPL *rpl; |
| 4912 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4913 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4914 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4915 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4916 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4917 | stat.un.b.lsRjtRsvd0 = 0; |
| 4918 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4919 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4920 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4921 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4922 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4923 | /* rejected the unsolicited RPL request and done with it */ |
| 4924 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4925 | } |
| 4926 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4927 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4928 | lp = (uint32_t *) pcmd->virt; |
| 4929 | rpl = (RPL *) (lp + 1); |
| 4930 | |
| 4931 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4932 | |
| 4933 | /* We support only one port */ |
| 4934 | if ((rpl->index == 0) && |
| 4935 | ((maxsize == 0) || |
| 4936 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4937 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4938 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4939 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4940 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4941 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4942 | |
| 4943 | return 0; |
| 4944 | } |
| 4945 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4946 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4947 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4948 | * @vport: pointer to a virtual N_Port data structure. |
| 4949 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4950 | * @ndlp: pointer to a node-list data structure. |
| 4951 | * |
| 4952 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4953 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4954 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4955 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4956 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4957 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4958 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4959 | * compared against the FC NodeName stored in the @vport data structure. |
| 4960 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4961 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4962 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4963 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 4964 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 4965 | * routine is invoked to log into the remote port first. |
| 4966 | * |
| 4967 | * Return code |
| 4968 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 4969 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4970 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4971 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4972 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4973 | { |
| 4974 | struct lpfc_dmabuf *pcmd; |
| 4975 | uint32_t *lp; |
| 4976 | IOCB_t *icmd; |
| 4977 | FARP *fp; |
| 4978 | uint32_t cmd, cnt, did; |
| 4979 | |
| 4980 | icmd = &cmdiocb->iocb; |
| 4981 | did = icmd->un.elsreq64.remoteID; |
| 4982 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4983 | lp = (uint32_t *) pcmd->virt; |
| 4984 | |
| 4985 | cmd = *lp++; |
| 4986 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4987 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4988 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4989 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4990 | /* We will only support match on WWPN or WWNN */ |
| 4991 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4992 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4993 | } |
| 4994 | |
| 4995 | cnt = 0; |
| 4996 | /* If this FARP command is searching for my portname */ |
| 4997 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4998 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4999 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5000 | cnt = 1; |
| 5001 | } |
| 5002 | |
| 5003 | /* If this FARP command is searching for my nodename */ |
| 5004 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5005 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5006 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5007 | cnt = 1; |
| 5008 | } |
| 5009 | |
| 5010 | if (cnt) { |
| 5011 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 5012 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 5013 | /* Log back into the node before sending the FARP. */ |
| 5014 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5015 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5016 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 5017 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5018 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5022 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 5023 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5024 | } |
| 5025 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5026 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5027 | } |
| 5028 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5029 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5030 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5031 | * @vport: pointer to a host virtual N_Port data structure. |
| 5032 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5033 | * @ndlp: pointer to a node-list data structure. |
| 5034 | * |
| 5035 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5036 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 5037 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 5038 | * the FARP response request. |
| 5039 | * |
| 5040 | * Return code |
| 5041 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 5042 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5043 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5044 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5045 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5046 | { |
| 5047 | struct lpfc_dmabuf *pcmd; |
| 5048 | uint32_t *lp; |
| 5049 | IOCB_t *icmd; |
| 5050 | uint32_t cmd, did; |
| 5051 | |
| 5052 | icmd = &cmdiocb->iocb; |
| 5053 | did = icmd->un.elsreq64.remoteID; |
| 5054 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5055 | lp = (uint32_t *) pcmd->virt; |
| 5056 | |
| 5057 | cmd = *lp++; |
| 5058 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5059 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5060 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5061 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5062 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5063 | |
| 5064 | return 0; |
| 5065 | } |
| 5066 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5067 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5068 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5069 | * @vport: pointer to a host virtual N_Port data structure. |
| 5070 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5071 | * @fan_ndlp: pointer to a node-list data structure. |
| 5072 | * |
| 5073 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 5074 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 5075 | * only be processed on a physical port (i.e., the @vport represents the |
| 5076 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 5077 | * compared against those in the phba data structure. If any of those is |
| 5078 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 5079 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 5080 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 5081 | * is invoked to register login to the fabric. |
| 5082 | * |
| 5083 | * Return code |
| 5084 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 5085 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5086 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5087 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5088 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5089 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5090 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5091 | uint32_t *lp; |
| 5092 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5093 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5094 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 5095 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 5096 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5097 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5098 | if ((vport == phba->pport) && |
| 5099 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5100 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5101 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5102 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5103 | sizeof(struct lpfc_name)))) { |
| 5104 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5105 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5106 | } else { |
| 5107 | /* FAN verified - skip FLOGI */ |
| 5108 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5109 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5110 | lpfc_issue_fabric_reglogin(vport); |
| 5111 | else |
| 5112 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5113 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5114 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5115 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5116 | } |
| 5117 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5118 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5119 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5120 | * @ptr: holder for the timer function associated data. |
| 5121 | * |
| 5122 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5123 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5124 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5125 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5126 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5127 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5128 | void |
| 5129 | lpfc_els_timeout(unsigned long ptr) |
| 5130 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5131 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5132 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5133 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5134 | unsigned long iflag; |
| 5135 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5136 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5137 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5138 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5139 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5140 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5141 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5142 | if (!tmo_posted) |
| 5143 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5144 | return; |
| 5145 | } |
| 5146 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5147 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5148 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5149 | * @vport: pointer to a virtual N_Port data structure. |
| 5150 | * |
| 5151 | * This routine is the actual handler function that processes an ELS timeout |
| 5152 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5153 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5154 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5155 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5156 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5157 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5158 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5159 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5160 | struct lpfc_sli_ring *pring; |
| 5161 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5162 | IOCB_t *cmd = NULL; |
| 5163 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5164 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5165 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5166 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5167 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5168 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5169 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5170 | |
| 5171 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5172 | |
| 5173 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5174 | cmd = &piocb->iocb; |
| 5175 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5176 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5177 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5178 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5179 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5180 | |
| 5181 | if (piocb->vport != vport) |
| 5182 | continue; |
| 5183 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5184 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5185 | if (pcmd) |
| 5186 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5187 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5188 | if (els_command == ELS_CMD_FARP || |
| 5189 | els_command == ELS_CMD_FARPR || |
| 5190 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5191 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5192 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5193 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5194 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5195 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5196 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5197 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5198 | continue; |
| 5199 | } |
| 5200 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5201 | remote_ID = 0xffffffff; |
| 5202 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5203 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5204 | else { |
| 5205 | struct lpfc_nodelist *ndlp; |
| 5206 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5207 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5208 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5209 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5210 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5211 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5212 | "x%x\n", els_command, |
| 5213 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5214 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5215 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5216 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5217 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5218 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5219 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5220 | } |
| 5221 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5222 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5223 | * 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] | 5224 | * @vport: pointer to a host virtual N_Port data structure. |
| 5225 | * |
| 5226 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5227 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5228 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5229 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5230 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5231 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5232 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5233 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5234 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5235 | * completion queue IOCB that is associated with the @vport and is not |
| 5236 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5237 | * part of the discovery state machine) out to HBA by invoking the |
| 5238 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5239 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5240 | * the IOCBs are aborted when this function returns. |
| 5241 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5242 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5243 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5244 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5245 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5246 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5247 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5248 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5249 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5250 | |
| 5251 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5252 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5253 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5254 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5255 | cmd = &piocb->iocb; |
| 5256 | |
| 5257 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5258 | continue; |
| 5259 | } |
| 5260 | |
| 5261 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5262 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5263 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5264 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5265 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5266 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5267 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5268 | if (piocb->vport != vport) |
| 5269 | continue; |
| 5270 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5271 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5272 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5276 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5277 | continue; |
| 5278 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5279 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5280 | if (piocb->vport != vport) |
| 5281 | continue; |
| 5282 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5283 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5284 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5285 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5286 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5287 | /* Cancell all the IOCBs from the completions list */ |
| 5288 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5289 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5290 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5291 | return; |
| 5292 | } |
| 5293 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5294 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5295 | * 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] | 5296 | * @phba: pointer to lpfc hba data structure. |
| 5297 | * |
| 5298 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5299 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5300 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5301 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5302 | * the IOCBs with the completion callback function associated, the callback |
| 5303 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5304 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5305 | * callback function associated, the IOCB will simply be released. Finally, |
| 5306 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5307 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5308 | * management plane IOCBs that are not part of the discovery state machine) |
| 5309 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5310 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5311 | void |
| 5312 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5313 | { |
| 5314 | LIST_HEAD(completions); |
| 5315 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5316 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5317 | IOCB_t *cmd = NULL; |
| 5318 | |
| 5319 | lpfc_fabric_abort_hba(phba); |
| 5320 | spin_lock_irq(&phba->hbalock); |
| 5321 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5322 | cmd = &piocb->iocb; |
| 5323 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5324 | continue; |
| 5325 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5326 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5327 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5328 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5329 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5330 | continue; |
| 5331 | list_move_tail(&piocb->list, &completions); |
| 5332 | pring->txq_cnt--; |
| 5333 | } |
| 5334 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5335 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5336 | continue; |
| 5337 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5338 | } |
| 5339 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5340 | |
| 5341 | /* Cancel all the IOCBs from the completions list */ |
| 5342 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5343 | IOERR_SLI_ABORTED); |
| 5344 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5345 | return; |
| 5346 | } |
| 5347 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5348 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5349 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5350 | * @phba: Pointer to hba context object. |
| 5351 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5352 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5353 | * |
| 5354 | * This function sends an event when there is an ELS command |
| 5355 | * failure. |
| 5356 | **/ |
| 5357 | void |
| 5358 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5359 | struct lpfc_iocbq *cmdiocbp, |
| 5360 | struct lpfc_iocbq *rspiocbp) |
| 5361 | { |
| 5362 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5363 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5364 | struct lpfc_lsrjt_event lsrjt_event; |
| 5365 | struct lpfc_fabric_event_header fabric_event; |
| 5366 | struct ls_rjt stat; |
| 5367 | struct lpfc_nodelist *ndlp; |
| 5368 | uint32_t *pcmd; |
| 5369 | |
| 5370 | ndlp = cmdiocbp->context1; |
| 5371 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5372 | return; |
| 5373 | |
| 5374 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5375 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5376 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5377 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5378 | sizeof(struct lpfc_name)); |
| 5379 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5380 | sizeof(struct lpfc_name)); |
| 5381 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5382 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 5383 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5384 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5385 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5386 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5387 | fc_host_post_vendor_event(shost, |
| 5388 | fc_get_event_number(), |
| 5389 | sizeof(lsrjt_event), |
| 5390 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5391 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5392 | return; |
| 5393 | } |
| 5394 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5395 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5396 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5397 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5398 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5399 | else |
| 5400 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5401 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5402 | sizeof(struct lpfc_name)); |
| 5403 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5404 | sizeof(struct lpfc_name)); |
| 5405 | fc_host_post_vendor_event(shost, |
| 5406 | fc_get_event_number(), |
| 5407 | sizeof(fabric_event), |
| 5408 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5409 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5410 | return; |
| 5411 | } |
| 5412 | |
| 5413 | } |
| 5414 | |
| 5415 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5416 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5417 | * @vport: Pointer to vport object. |
| 5418 | * @ndlp: Pointer FC node object. |
| 5419 | * @cmd: ELS command code. |
| 5420 | * |
| 5421 | * This function posts an event when there is an incoming |
| 5422 | * unsolicited ELS command. |
| 5423 | **/ |
| 5424 | static void |
| 5425 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5426 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5427 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5428 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5429 | struct lpfc_els_event_header *els_data = NULL; |
| 5430 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5431 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5432 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5433 | if (*payload == ELS_CMD_LOGO) { |
| 5434 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5435 | if (!logo_data) { |
| 5436 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5437 | "0148 Failed to allocate memory " |
| 5438 | "for LOGO event\n"); |
| 5439 | return; |
| 5440 | } |
| 5441 | els_data = &logo_data->header; |
| 5442 | } else { |
| 5443 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5444 | GFP_KERNEL); |
| 5445 | if (!els_data) { |
| 5446 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5447 | "0149 Failed to allocate memory " |
| 5448 | "for ELS event\n"); |
| 5449 | return; |
| 5450 | } |
| 5451 | } |
| 5452 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5453 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5454 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5455 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5456 | break; |
| 5457 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5458 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5459 | break; |
| 5460 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5461 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5462 | break; |
| 5463 | case ELS_CMD_LOGO: |
| 5464 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5465 | /* Copy the WWPN in the LOGO payload */ |
| 5466 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5467 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5468 | break; |
| 5469 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5470 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5471 | return; |
| 5472 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5473 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5474 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5475 | if (*payload == ELS_CMD_LOGO) { |
| 5476 | fc_host_post_vendor_event(shost, |
| 5477 | fc_get_event_number(), |
| 5478 | sizeof(struct lpfc_logo_event), |
| 5479 | (char *)logo_data, |
| 5480 | LPFC_NL_VENDOR_ID); |
| 5481 | kfree(logo_data); |
| 5482 | } else { |
| 5483 | fc_host_post_vendor_event(shost, |
| 5484 | fc_get_event_number(), |
| 5485 | sizeof(struct lpfc_els_event_header), |
| 5486 | (char *)els_data, |
| 5487 | LPFC_NL_VENDOR_ID); |
| 5488 | kfree(els_data); |
| 5489 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5490 | |
| 5491 | return; |
| 5492 | } |
| 5493 | |
| 5494 | |
| 5495 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5496 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5497 | * @phba: pointer to lpfc hba data structure. |
| 5498 | * @pring: pointer to a SLI ring. |
| 5499 | * @vport: pointer to a host virtual N_Port data structure. |
| 5500 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5501 | * |
| 5502 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5503 | * event. It first determines whether there is an existing ndlp that matches |
| 5504 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5505 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5506 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5507 | * of the discovery state machine. |
| 5508 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5509 | static void |
| 5510 | 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] | 5511 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5512 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5513 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5514 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5515 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5516 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5517 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5518 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5519 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5520 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5521 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5522 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5523 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5524 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5525 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5526 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5527 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5528 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5529 | did = icmd->un.rcvels.remoteID; |
| 5530 | if (icmd->ulpStatus) { |
| 5531 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5532 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5533 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5534 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5535 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5536 | |
| 5537 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5538 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5539 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5540 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5541 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5542 | if (vport->load_flag & FC_UNLOADING) |
| 5543 | goto dropit; |
| 5544 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5545 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5546 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5547 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5548 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5549 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5550 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5551 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5552 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5553 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5554 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5555 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5556 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5557 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5558 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5559 | NLP_STE_UNUSED_NODE); |
| 5560 | if (!ndlp) |
| 5561 | goto dropit; |
| 5562 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5563 | newnode = 1; |
| 5564 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5565 | ndlp->nlp_type |= NLP_FABRIC; |
| 5566 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5567 | /* This is similar to the new node path */ |
| 5568 | ndlp = lpfc_nlp_get(ndlp); |
| 5569 | if (!ndlp) |
| 5570 | goto dropit; |
| 5571 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5572 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5573 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5574 | |
| 5575 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5576 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5577 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5578 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5579 | |
| 5580 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5581 | cmd &= ELS_CMD_MASK; |
| 5582 | } |
| 5583 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5584 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5585 | "0112 ELS command x%x received from NPORT x%x " |
| 5586 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5587 | switch (cmd) { |
| 5588 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5589 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5590 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5591 | did, vport->port_state, ndlp->nlp_flag); |
| 5592 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5593 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5594 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5595 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5596 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5597 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5598 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5599 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5600 | rjt_err = LSRJT_UNABLE_TPC; |
| 5601 | break; |
| 5602 | } |
| 5603 | /* We get here, and drop thru, if we are PT2PT with |
| 5604 | * another NPort and the other side has initiated |
| 5605 | * the PLOGI before responding to our FLOGI. |
| 5606 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5607 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5608 | |
| 5609 | shost = lpfc_shost_from_vport(vport); |
| 5610 | spin_lock_irq(shost->host_lock); |
| 5611 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5612 | spin_unlock_irq(shost->host_lock); |
| 5613 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5614 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5615 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5616 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5617 | break; |
| 5618 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5619 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5620 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 5621 | did, vport->port_state, ndlp->nlp_flag); |
| 5622 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5623 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5624 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5625 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5626 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5627 | break; |
| 5628 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5629 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5630 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5631 | did, vport->port_state, ndlp->nlp_flag); |
| 5632 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5633 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5634 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5635 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5636 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5637 | break; |
| 5638 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5639 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5640 | break; |
| 5641 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5642 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5643 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 5644 | did, vport->port_state, ndlp->nlp_flag); |
| 5645 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5646 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5647 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5648 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5649 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5650 | break; |
| 5651 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5652 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5653 | break; |
| 5654 | case ELS_CMD_RSCN: |
| 5655 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5656 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5657 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5658 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5659 | break; |
| 5660 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5661 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5662 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5663 | did, vport->port_state, ndlp->nlp_flag); |
| 5664 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5665 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5666 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5667 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5668 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5669 | break; |
| 5670 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5671 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5672 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5673 | break; |
| 5674 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5675 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5676 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5677 | did, vport->port_state, ndlp->nlp_flag); |
| 5678 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5679 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5680 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5681 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5682 | break; |
| 5683 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5684 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5685 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5686 | break; |
| 5687 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5688 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5689 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 5690 | did, vport->port_state, ndlp->nlp_flag); |
| 5691 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5692 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5693 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5694 | break; |
| 5695 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5696 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5697 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 5698 | did, vport->port_state, ndlp->nlp_flag); |
| 5699 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5700 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5701 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5702 | break; |
| 5703 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5704 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5705 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 5706 | did, vport->port_state, ndlp->nlp_flag); |
| 5707 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5708 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5709 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5710 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5711 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5712 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5713 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5714 | did, vport->port_state, ndlp->nlp_flag); |
| 5715 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5716 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5717 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5718 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5719 | break; |
| 5720 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5721 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5722 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5723 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5724 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5725 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 5726 | did, vport->port_state, ndlp->nlp_flag); |
| 5727 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5728 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5729 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5730 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5731 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5732 | break; |
| 5733 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5734 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5735 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 5736 | did, vport->port_state, ndlp->nlp_flag); |
| 5737 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5738 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5739 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5740 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5741 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5742 | break; |
| 5743 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5744 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5745 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5746 | did, vport->port_state, ndlp->nlp_flag); |
| 5747 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5748 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5749 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5750 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5751 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5752 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5753 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5754 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5755 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 5756 | did, vport->port_state, ndlp->nlp_flag); |
| 5757 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5758 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5759 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5760 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5761 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5762 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5763 | case ELS_CMD_RRQ: |
| 5764 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5765 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 5766 | did, vport->port_state, ndlp->nlp_flag); |
| 5767 | |
| 5768 | phba->fc_stat.elsRcvRRQ++; |
| 5769 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 5770 | if (newnode) |
| 5771 | lpfc_nlp_put(ndlp); |
| 5772 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5773 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5774 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5775 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5776 | cmd, did, vport->port_state); |
| 5777 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5778 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5779 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5780 | |
| 5781 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5782 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5783 | "0115 Unknown ELS command x%x " |
| 5784 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5785 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5786 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5787 | break; |
| 5788 | } |
| 5789 | |
| 5790 | /* check if need to LS_RJT received ELS cmd */ |
| 5791 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5792 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5793 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5794 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5795 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5796 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5797 | } |
| 5798 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5799 | lpfc_nlp_put(elsiocb->context1); |
| 5800 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5801 | return; |
| 5802 | |
| 5803 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5804 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5805 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5806 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5807 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5808 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5809 | phba->fc_stat.elsRcvDrop++; |
| 5810 | } |
| 5811 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5812 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5813 | * 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] | 5814 | * @phba: pointer to lpfc hba data structure. |
| 5815 | * @vpi: host virtual N_Port identifier. |
| 5816 | * |
| 5817 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5818 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5819 | * of the vport with the matching @vpi. |
| 5820 | * |
| 5821 | * Return code |
| 5822 | * NULL - No vport with the matching @vpi found |
| 5823 | * Otherwise - Address to the vport with the matching @vpi. |
| 5824 | **/ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5825 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5826 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5827 | { |
| 5828 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5829 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5830 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5831 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5832 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5833 | if (vport->vpi == vpi) { |
| 5834 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5835 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5836 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5837 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5838 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5839 | return NULL; |
| 5840 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5841 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5842 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5843 | * 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] | 5844 | * @phba: pointer to lpfc hba data structure. |
| 5845 | * @pring: pointer to a SLI ring. |
| 5846 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5847 | * |
| 5848 | * This routine is used to process an unsolicited event received from a SLI |
| 5849 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5850 | * associated with the unsolicited event is done by invoking the routine |
| 5851 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5852 | * SLI ring on which the unsolicited event was received. |
| 5853 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5854 | void |
| 5855 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5856 | struct lpfc_iocbq *elsiocb) |
| 5857 | { |
| 5858 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5859 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5860 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5861 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5862 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5863 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5864 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5865 | elsiocb->context2 = NULL; |
| 5866 | elsiocb->context3 = NULL; |
| 5867 | |
| 5868 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5869 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5870 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5871 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5872 | phba->fc_stat.NoRcvBuf++; |
| 5873 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5874 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5875 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5876 | return; |
| 5877 | } |
| 5878 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5879 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5880 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5881 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5882 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5883 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5884 | else |
| 5885 | vport = lpfc_find_vport_by_vpid(phba, |
| 5886 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5887 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5888 | /* If there are no BDEs associated |
| 5889 | * with this IOCB, there is nothing to do. |
| 5890 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5891 | if (icmd->ulpBdeCount == 0) |
| 5892 | return; |
| 5893 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5894 | /* type of ELS cmd is first 32bit word |
| 5895 | * in packet |
| 5896 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5897 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5898 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5899 | } else { |
| 5900 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5901 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5902 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5903 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5904 | } |
| 5905 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5906 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5907 | /* |
| 5908 | * The different unsolicited event handlers would tell us |
| 5909 | * if they are done with "mp" by setting context2 to NULL. |
| 5910 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5911 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5912 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5913 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5914 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5915 | |
| 5916 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5917 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5918 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5919 | elsiocb->context2 = bdeBuf2; |
| 5920 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5921 | /* free mp if we are done with it */ |
| 5922 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5923 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5924 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5925 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5926 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5927 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5928 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5929 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5930 | * 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] | 5931 | * @phba: pointer to lpfc hba data structure. |
| 5932 | * @vport: pointer to a virtual N_Port data structure. |
| 5933 | * |
| 5934 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5935 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5936 | * ndlp for the Name Server associated to the @vport if such node does |
| 5937 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5938 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5939 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5940 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5941 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5942 | void |
| 5943 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5944 | { |
| 5945 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5946 | |
| 5947 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 5948 | if (!ndlp) { |
| 5949 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5950 | if (!ndlp) { |
| 5951 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5952 | lpfc_disc_start(vport); |
| 5953 | return; |
| 5954 | } |
| 5955 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5956 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5957 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5958 | return; |
| 5959 | } |
| 5960 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5961 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5962 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5963 | if (!ndlp) { |
| 5964 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5965 | lpfc_disc_start(vport); |
| 5966 | return; |
| 5967 | } |
| 5968 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5969 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5970 | "0348 NameServer login: node freed\n"); |
| 5971 | return; |
| 5972 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5973 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5974 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5975 | |
| 5976 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5977 | |
| 5978 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 5979 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5980 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5981 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5982 | return; |
| 5983 | } |
| 5984 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5985 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5986 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 5987 | GFP_KERNEL); |
| 5988 | if (ndlp_fdmi) { |
| 5989 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 5990 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5991 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 5992 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5993 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 5994 | 0); |
| 5995 | } |
| 5996 | } |
| 5997 | return; |
| 5998 | } |
| 5999 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6000 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6001 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6002 | * @phba: pointer to lpfc hba data structure. |
| 6003 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6004 | * |
| 6005 | * This routine is the completion callback function to register new vport |
| 6006 | * mailbox command. If the new vport mailbox command completes successfully, |
| 6007 | * the fabric registration login shall be performed on physical port (the |
| 6008 | * new vport created is actually a physical port, with VPI 0) or the port |
| 6009 | * login to Name Server for State Change Request (SCR) will be performed |
| 6010 | * on virtual port (real virtual port, with VPI greater than 0). |
| 6011 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6012 | static void |
| 6013 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6014 | { |
| 6015 | struct lpfc_vport *vport = pmb->vport; |
| 6016 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6017 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6018 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6019 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6020 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6021 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6022 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6023 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6024 | |
| 6025 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6026 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6027 | "0915 Register VPI failed: 0x%x\n", |
| 6028 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6029 | |
| 6030 | switch (mb->mbxStatus) { |
| 6031 | case 0x11: /* unsupported feature */ |
| 6032 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6033 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6034 | /* giving up on vport registration */ |
| 6035 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6036 | spin_lock_irq(shost->host_lock); |
| 6037 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6038 | spin_unlock_irq(shost->host_lock); |
| 6039 | lpfc_can_disctmo(vport); |
| 6040 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6041 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 6042 | case 0x20: |
| 6043 | spin_lock_irq(shost->host_lock); |
| 6044 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6045 | spin_unlock_irq(shost->host_lock); |
| 6046 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 6047 | pmb->vport = vport; |
| 6048 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 6049 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 6050 | MBX_NOWAIT); |
| 6051 | if (rc == MBX_NOT_FINISHED) { |
| 6052 | lpfc_printf_vlog(vport, |
| 6053 | KERN_ERR, LOG_MBOX, |
| 6054 | "2732 Failed to issue INIT_VPI" |
| 6055 | " mailbox command\n"); |
| 6056 | } else { |
| 6057 | lpfc_nlp_put(ndlp); |
| 6058 | return; |
| 6059 | } |
| 6060 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6061 | default: |
| 6062 | /* Try to recover from this error */ |
| 6063 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6064 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6065 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6066 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6067 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 6068 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6069 | lpfc_initial_flogi(vport); |
| 6070 | else |
| 6071 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6072 | break; |
| 6073 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6074 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6075 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 6076 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6077 | spin_unlock_irq(shost->host_lock); |
| 6078 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6079 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6080 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6081 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6082 | /* |
| 6083 | * If the physical port is instantiated using |
| 6084 | * FDISC, do not start vport discovery. |
| 6085 | */ |
| 6086 | if (vport->port_state != LPFC_FDISC) |
| 6087 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6088 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6089 | } |
| 6090 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6091 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6092 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6093 | |
| 6094 | /* Now, we decrement the ndlp reference count held for this |
| 6095 | * callback function |
| 6096 | */ |
| 6097 | lpfc_nlp_put(ndlp); |
| 6098 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6099 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6100 | return; |
| 6101 | } |
| 6102 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6103 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6104 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6105 | * @phba: pointer to lpfc hba data structure. |
| 6106 | * @vport: pointer to a host virtual N_Port data structure. |
| 6107 | * @ndlp: pointer to a node-list data structure. |
| 6108 | * |
| 6109 | * This routine registers the @vport as a new virtual port with a HBA. |
| 6110 | * It is done through a registering vpi mailbox command. |
| 6111 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6112 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6113 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 6114 | struct lpfc_nodelist *ndlp) |
| 6115 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6116 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6117 | LPFC_MBOXQ_t *mbox; |
| 6118 | |
| 6119 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6120 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6121 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6122 | mbox->vport = vport; |
| 6123 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6124 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6125 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6126 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6127 | /* mailbox command not success, decrement ndlp |
| 6128 | * reference count for this command |
| 6129 | */ |
| 6130 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6131 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6132 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6133 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6134 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6135 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6136 | } |
| 6137 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6138 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6139 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6140 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6141 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6142 | return; |
| 6143 | |
| 6144 | mbox_err_exit: |
| 6145 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6146 | spin_lock_irq(shost->host_lock); |
| 6147 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 6148 | spin_unlock_irq(shost->host_lock); |
| 6149 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6150 | } |
| 6151 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6152 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6153 | * 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] | 6154 | * @phba: pointer to lpfc hba data structure. |
| 6155 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6156 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6157 | **/ |
| 6158 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6159 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6160 | { |
| 6161 | struct lpfc_vport **vports; |
| 6162 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6163 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6164 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6165 | |
| 6166 | /* Treat this failure as linkdown for all vports */ |
| 6167 | link_state = phba->link_state; |
| 6168 | lpfc_linkdown(phba); |
| 6169 | phba->link_state = link_state; |
| 6170 | |
| 6171 | vports = lpfc_create_vport_work_array(phba); |
| 6172 | |
| 6173 | if (vports) { |
| 6174 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6175 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6176 | if (ndlp) |
| 6177 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 6178 | lpfc_els_flush_cmd(vports[i]); |
| 6179 | } |
| 6180 | lpfc_destroy_vport_work_array(phba, vports); |
| 6181 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6182 | } |
| 6183 | |
| 6184 | /** |
| 6185 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 6186 | * @phba: pointer to lpfc hba data structure. |
| 6187 | * |
| 6188 | * This routine abort all pending discovery commands and |
| 6189 | * start a timer to retry FLOGI for the physical port |
| 6190 | * discovery. |
| 6191 | **/ |
| 6192 | void |
| 6193 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 6194 | { |
| 6195 | struct lpfc_nodelist *ndlp; |
| 6196 | struct Scsi_Host *shost; |
| 6197 | |
| 6198 | /* Cancel the all vports retry delay retry timers */ |
| 6199 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6200 | |
| 6201 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 6202 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6203 | if (!ndlp) |
| 6204 | return; |
| 6205 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6206 | shost = lpfc_shost_from_vport(phba->pport); |
| 6207 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 6208 | spin_lock_irq(shost->host_lock); |
| 6209 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 6210 | spin_unlock_irq(shost->host_lock); |
| 6211 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 6212 | phba->pport->port_state = LPFC_FLOGI; |
| 6213 | return; |
| 6214 | } |
| 6215 | |
| 6216 | /** |
| 6217 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 6218 | * @phba: pointer to lpfc hba data structure. |
| 6219 | * @cmdiocb: pointer to FDISC command iocb. |
| 6220 | * @rspiocb: pointer to FDISC response iocb. |
| 6221 | * |
| 6222 | * This routine checks if a FLOGI is reguired for FDISC |
| 6223 | * to succeed. |
| 6224 | **/ |
| 6225 | static int |
| 6226 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 6227 | struct lpfc_iocbq *cmdiocb, |
| 6228 | struct lpfc_iocbq *rspiocb) |
| 6229 | { |
| 6230 | |
| 6231 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 6232 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 6233 | return 0; |
| 6234 | else |
| 6235 | return 1; |
| 6236 | } |
| 6237 | |
| 6238 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6239 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6240 | * @phba: pointer to lpfc hba data structure. |
| 6241 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6242 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6243 | * |
| 6244 | * This routine is the completion callback function to a Fabric Discover |
| 6245 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 6246 | * single threaded, each FDISC completion callback function will reset |
| 6247 | * the discovery timer for all vports such that the timers will not get |
| 6248 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 6249 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 6250 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 6251 | * assigned to the vport has been changed with the completion of the FDISC |
| 6252 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 6253 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 6254 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 6255 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 6256 | * Server for State Change Request (SCR). |
| 6257 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6258 | static void |
| 6259 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6260 | struct lpfc_iocbq *rspiocb) |
| 6261 | { |
| 6262 | struct lpfc_vport *vport = cmdiocb->vport; |
| 6263 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6264 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 6265 | struct lpfc_nodelist *np; |
| 6266 | struct lpfc_nodelist *next_np; |
| 6267 | IOCB_t *irsp = &rspiocb->iocb; |
| 6268 | struct lpfc_iocbq *piocb; |
| 6269 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6270 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6271 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 6272 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 6273 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6274 | /* Since all FDISCs are being single threaded, we |
| 6275 | * must reset the discovery timer for ALL vports |
| 6276 | * waiting to send FDISC when one completes. |
| 6277 | */ |
| 6278 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 6279 | lpfc_set_disctmo(piocb->vport); |
| 6280 | } |
| 6281 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6282 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6283 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6284 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6285 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6286 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6287 | |
| 6288 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 6289 | lpfc_retry_pport_discovery(phba); |
| 6290 | goto out; |
| 6291 | } |
| 6292 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6293 | /* Check for retry */ |
| 6294 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6295 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6296 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6297 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6298 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6299 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6300 | goto fdisc_failed; |
| 6301 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6302 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6303 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6304 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6305 | vport->fc_flag |= FC_FABRIC; |
| 6306 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 6307 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6308 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6309 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6310 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6311 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6312 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6313 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6314 | /* If our NportID changed, we need to ensure all |
| 6315 | * remaining NPORTs get unreg_login'ed so we can |
| 6316 | * issue unreg_vpi. |
| 6317 | */ |
| 6318 | list_for_each_entry_safe(np, next_np, |
| 6319 | &vport->fc_nodes, nlp_listp) { |
| 6320 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6321 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6322 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6323 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6324 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6325 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6326 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6327 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6328 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6329 | lpfc_cleanup_pending_mbox(vport); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6330 | lpfc_mbx_unreg_vpi(vport); |
| 6331 | spin_lock_irq(shost->host_lock); |
| 6332 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6333 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6334 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6335 | else |
| 6336 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6337 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6338 | } |
| 6339 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6340 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 6341 | lpfc_issue_init_vpi(vport); |
| 6342 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6343 | lpfc_register_new_vport(phba, vport, ndlp); |
| 6344 | else |
| 6345 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6346 | goto out; |
| 6347 | fdisc_failed: |
| 6348 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6349 | /* Cancel discovery timer */ |
| 6350 | lpfc_can_disctmo(vport); |
| 6351 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6352 | out: |
| 6353 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6354 | } |
| 6355 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6356 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6357 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6358 | * @vport: pointer to a virtual N_Port data structure. |
| 6359 | * @ndlp: pointer to a node-list data structure. |
| 6360 | * @retry: number of retries to the command IOCB. |
| 6361 | * |
| 6362 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6363 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6364 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6365 | * IOCB will be sent off HBA at any given time. |
| 6366 | * |
| 6367 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6368 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6369 | * will be stored into the context1 field of the IOCB for the completion |
| 6370 | * callback function to the FDISC ELS command. |
| 6371 | * |
| 6372 | * Return code |
| 6373 | * 0 - Successfully issued fdisc iocb command |
| 6374 | * 1 - Failed to issue fdisc iocb command |
| 6375 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6376 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6377 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6378 | uint8_t retry) |
| 6379 | { |
| 6380 | struct lpfc_hba *phba = vport->phba; |
| 6381 | IOCB_t *icmd; |
| 6382 | struct lpfc_iocbq *elsiocb; |
| 6383 | struct serv_parm *sp; |
| 6384 | uint8_t *pcmd; |
| 6385 | uint16_t cmdsize; |
| 6386 | int did = ndlp->nlp_DID; |
| 6387 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6388 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6389 | vport->port_state = LPFC_FDISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6390 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6391 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6392 | ELS_CMD_FDISC); |
| 6393 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6394 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6395 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6396 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6397 | return 1; |
| 6398 | } |
| 6399 | |
| 6400 | icmd = &elsiocb->iocb; |
| 6401 | icmd->un.elsreq64.myID = 0; |
| 6402 | icmd->un.elsreq64.fl = 1; |
| 6403 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6404 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 6405 | /* FDISC needs to be 1 for WQE VPI */ |
| 6406 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 6407 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 6408 | /* Set the ulpContext to the vpi */ |
| 6409 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 6410 | } else { |
| 6411 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6412 | icmd->ulpCt_h = 1; |
| 6413 | icmd->ulpCt_l = 0; |
| 6414 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6415 | |
| 6416 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6417 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6418 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6419 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6420 | sp = (struct serv_parm *) pcmd; |
| 6421 | /* Setup CSPs accordingly for Fabric */ |
| 6422 | sp->cmn.e_d_tov = 0; |
| 6423 | sp->cmn.w2.r_a_tov = 0; |
| 6424 | sp->cls1.classValid = 0; |
| 6425 | sp->cls2.seqDelivery = 1; |
| 6426 | sp->cls3.seqDelivery = 1; |
| 6427 | |
| 6428 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6429 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6430 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6431 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6432 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6433 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6434 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6435 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6436 | |
| 6437 | lpfc_set_disctmo(vport); |
| 6438 | |
| 6439 | phba->fc_stat.elsXmitFDISC++; |
| 6440 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6441 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6442 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6443 | "Issue FDISC: did:x%x", |
| 6444 | did, 0, 0); |
| 6445 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6446 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6447 | if (rc == IOCB_ERROR) { |
| 6448 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6449 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6450 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6451 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6452 | return 1; |
| 6453 | } |
| 6454 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6455 | return 0; |
| 6456 | } |
| 6457 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6458 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6459 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6460 | * @phba: pointer to lpfc hba data structure. |
| 6461 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6462 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6463 | * |
| 6464 | * This routine is the completion callback function to the issuing of a LOGO |
| 6465 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6466 | * reference count held on ndlp for this completion function, indicating that |
| 6467 | * the reference to the ndlp is no long needed. Note that the |
| 6468 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6469 | * callback function and an additional explicit ndlp reference decrementation |
| 6470 | * will trigger the actual release of the ndlp. |
| 6471 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6472 | static void |
| 6473 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6474 | struct lpfc_iocbq *rspiocb) |
| 6475 | { |
| 6476 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6477 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6478 | struct lpfc_nodelist *ndlp; |
| 6479 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6480 | |
| 6481 | irsp = &rspiocb->iocb; |
| 6482 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6483 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6484 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6485 | |
| 6486 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6487 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6488 | |
| 6489 | /* Trigger the release of the ndlp after logo */ |
| 6490 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6491 | } |
| 6492 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6493 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6494 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6495 | * @vport: pointer to a virtual N_Port data structure. |
| 6496 | * @ndlp: pointer to a node-list data structure. |
| 6497 | * |
| 6498 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6499 | * |
| 6500 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6501 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6502 | * will be stored into the context1 field of the IOCB for the completion |
| 6503 | * callback function to the LOGO ELS command. |
| 6504 | * |
| 6505 | * Return codes |
| 6506 | * 0 - Successfully issued logo off the @vport |
| 6507 | * 1 - Failed to issue logo off the @vport |
| 6508 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6509 | int |
| 6510 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6511 | { |
| 6512 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6513 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6514 | IOCB_t *icmd; |
| 6515 | struct lpfc_iocbq *elsiocb; |
| 6516 | uint8_t *pcmd; |
| 6517 | uint16_t cmdsize; |
| 6518 | |
| 6519 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6520 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6521 | ELS_CMD_LOGO); |
| 6522 | if (!elsiocb) |
| 6523 | return 1; |
| 6524 | |
| 6525 | icmd = &elsiocb->iocb; |
| 6526 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6527 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6528 | pcmd += sizeof(uint32_t); |
| 6529 | |
| 6530 | /* Fill in LOGO payload */ |
| 6531 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6532 | pcmd += sizeof(uint32_t); |
| 6533 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6534 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6535 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6536 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6537 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6538 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6539 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6540 | spin_lock_irq(shost->host_lock); |
| 6541 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6542 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6543 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6544 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6545 | spin_lock_irq(shost->host_lock); |
| 6546 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6547 | spin_unlock_irq(shost->host_lock); |
| 6548 | lpfc_els_free_iocb(phba, elsiocb); |
| 6549 | return 1; |
| 6550 | } |
| 6551 | return 0; |
| 6552 | } |
| 6553 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6554 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6555 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6556 | * @ptr: holder for the timer function associated data. |
| 6557 | * |
| 6558 | * This routine is invoked by the fabric iocb block timer after |
| 6559 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6560 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6561 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6562 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6563 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6564 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6565 | void |
| 6566 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6567 | { |
| 6568 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6569 | unsigned long iflags; |
| 6570 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6571 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6572 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6573 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6574 | if (!tmo_posted) |
| 6575 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6576 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6577 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6578 | if (!tmo_posted) |
| 6579 | lpfc_worker_wake_up(phba); |
| 6580 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6581 | } |
| 6582 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6583 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6584 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6585 | * @phba: pointer to lpfc hba data structure. |
| 6586 | * |
| 6587 | * This routine issues one fabric iocb from the driver internal list to |
| 6588 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6589 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6590 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6591 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6592 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6593 | static void |
| 6594 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6595 | { |
| 6596 | struct lpfc_iocbq *iocb; |
| 6597 | unsigned long iflags; |
| 6598 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6599 | IOCB_t *cmd; |
| 6600 | |
| 6601 | repeat: |
| 6602 | iocb = NULL; |
| 6603 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6604 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6605 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6606 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6607 | list); |
| 6608 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6609 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6610 | atomic_inc(&phba->fabric_iocb_count); |
| 6611 | } |
| 6612 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6613 | if (iocb) { |
| 6614 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6615 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6616 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6617 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6618 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6619 | "Fabric sched1: ste:x%x", |
| 6620 | iocb->vport->port_state, 0, 0); |
| 6621 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6622 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6623 | |
| 6624 | if (ret == IOCB_ERROR) { |
| 6625 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6626 | iocb->fabric_iocb_cmpl = NULL; |
| 6627 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6628 | cmd = &iocb->iocb; |
| 6629 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6630 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6631 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6632 | |
| 6633 | atomic_dec(&phba->fabric_iocb_count); |
| 6634 | goto repeat; |
| 6635 | } |
| 6636 | } |
| 6637 | |
| 6638 | return; |
| 6639 | } |
| 6640 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6641 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6642 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6643 | * @phba: pointer to lpfc hba data structure. |
| 6644 | * |
| 6645 | * This routine unblocks the issuing fabric iocb command. The function |
| 6646 | * will clear the fabric iocb block bit and then invoke the routine |
| 6647 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6648 | * from the driver internal fabric iocb list. |
| 6649 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6650 | void |
| 6651 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6652 | { |
| 6653 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6654 | |
| 6655 | lpfc_resume_fabric_iocbs(phba); |
| 6656 | return; |
| 6657 | } |
| 6658 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6659 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6660 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6661 | * @phba: pointer to lpfc hba data structure. |
| 6662 | * |
| 6663 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6664 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6665 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6666 | * fabric iocb will be issued out of the HBA. |
| 6667 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6668 | static void |
| 6669 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6670 | { |
| 6671 | int blocked; |
| 6672 | |
| 6673 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6674 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6675 | if (!blocked) |
| 6676 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6677 | |
| 6678 | return; |
| 6679 | } |
| 6680 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6681 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6682 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6683 | * @phba: pointer to lpfc hba data structure. |
| 6684 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6685 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6686 | * |
| 6687 | * This routine is the callback function that is put to the fabric iocb's |
| 6688 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6689 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6690 | * function first restores and invokes the original iocb's callback function |
| 6691 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6692 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6693 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6694 | static void |
| 6695 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6696 | struct lpfc_iocbq *rspiocb) |
| 6697 | { |
| 6698 | struct ls_rjt stat; |
| 6699 | |
| 6700 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6701 | BUG(); |
| 6702 | |
| 6703 | switch (rspiocb->iocb.ulpStatus) { |
| 6704 | case IOSTAT_NPORT_RJT: |
| 6705 | case IOSTAT_FABRIC_RJT: |
| 6706 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6707 | lpfc_block_fabric_iocbs(phba); |
| 6708 | } |
| 6709 | break; |
| 6710 | |
| 6711 | case IOSTAT_NPORT_BSY: |
| 6712 | case IOSTAT_FABRIC_BSY: |
| 6713 | lpfc_block_fabric_iocbs(phba); |
| 6714 | break; |
| 6715 | |
| 6716 | case IOSTAT_LS_RJT: |
| 6717 | stat.un.lsRjtError = |
| 6718 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6719 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6720 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6721 | lpfc_block_fabric_iocbs(phba); |
| 6722 | break; |
| 6723 | } |
| 6724 | |
| 6725 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6726 | BUG(); |
| 6727 | |
| 6728 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6729 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6730 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6731 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6732 | |
| 6733 | atomic_dec(&phba->fabric_iocb_count); |
| 6734 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6735 | /* Post any pending iocbs to HBA */ |
| 6736 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6737 | } |
| 6738 | } |
| 6739 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6740 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6741 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6742 | * @phba: pointer to lpfc hba data structure. |
| 6743 | * @iocb: pointer to lpfc command iocb data structure. |
| 6744 | * |
| 6745 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6746 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6747 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6748 | * any given time. As such, this function will first check to see whether there |
| 6749 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6750 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6751 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6752 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6753 | * |
| 6754 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6755 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6756 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6757 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6758 | * ahead of the fabric IOCBs in the internal list. |
| 6759 | * |
| 6760 | * Return code |
| 6761 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6762 | * IOCB_ERROR - failed to issue fabric iocb |
| 6763 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6764 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6765 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6766 | { |
| 6767 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6768 | int ready; |
| 6769 | int ret; |
| 6770 | |
| 6771 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6772 | BUG(); |
| 6773 | |
| 6774 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6775 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6776 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6777 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6778 | if (ready) |
| 6779 | /* Increment fabric iocb count to hold the position */ |
| 6780 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6781 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6782 | if (ready) { |
| 6783 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6784 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6785 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6786 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6787 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6788 | "Fabric sched2: ste:x%x", |
| 6789 | iocb->vport->port_state, 0, 0); |
| 6790 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6791 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6792 | |
| 6793 | if (ret == IOCB_ERROR) { |
| 6794 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6795 | iocb->fabric_iocb_cmpl = NULL; |
| 6796 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6797 | atomic_dec(&phba->fabric_iocb_count); |
| 6798 | } |
| 6799 | } else { |
| 6800 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6801 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6802 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6803 | ret = IOCB_SUCCESS; |
| 6804 | } |
| 6805 | return ret; |
| 6806 | } |
| 6807 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6808 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6809 | * 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] | 6810 | * @vport: pointer to a virtual N_Port data structure. |
| 6811 | * |
| 6812 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6813 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6814 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6815 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6816 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6817 | * associated with the IOCB. |
| 6818 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6819 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6820 | { |
| 6821 | LIST_HEAD(completions); |
| 6822 | struct lpfc_hba *phba = vport->phba; |
| 6823 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6824 | |
| 6825 | spin_lock_irq(&phba->hbalock); |
| 6826 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6827 | list) { |
| 6828 | |
| 6829 | if (piocb->vport != vport) |
| 6830 | continue; |
| 6831 | |
| 6832 | list_move_tail(&piocb->list, &completions); |
| 6833 | } |
| 6834 | spin_unlock_irq(&phba->hbalock); |
| 6835 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6836 | /* Cancel all the IOCBs from the completions list */ |
| 6837 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6838 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6839 | } |
| 6840 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6841 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6842 | * 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] | 6843 | * @ndlp: pointer to a node-list data structure. |
| 6844 | * |
| 6845 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6846 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6847 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6848 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6849 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6850 | * associated with the IOCB. |
| 6851 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6852 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6853 | { |
| 6854 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6855 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6856 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6857 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6858 | |
| 6859 | spin_lock_irq(&phba->hbalock); |
| 6860 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6861 | list) { |
| 6862 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6863 | |
| 6864 | list_move_tail(&piocb->list, &completions); |
| 6865 | } |
| 6866 | } |
| 6867 | spin_unlock_irq(&phba->hbalock); |
| 6868 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6869 | /* Cancel all the IOCBs from the completions list */ |
| 6870 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6871 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6872 | } |
| 6873 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6874 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6875 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6876 | * @phba: pointer to lpfc hba data structure. |
| 6877 | * |
| 6878 | * This routine aborts all the IOCBs currently on the driver internal |
| 6879 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6880 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6881 | * list, removes IOCBs off the list, set the status feild to |
| 6882 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6883 | * the IOCB. |
| 6884 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6885 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6886 | { |
| 6887 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6888 | |
| 6889 | spin_lock_irq(&phba->hbalock); |
| 6890 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6891 | spin_unlock_irq(&phba->hbalock); |
| 6892 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6893 | /* Cancel all the IOCBs from the completions list */ |
| 6894 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6895 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6896 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6897 | |
| 6898 | /** |
| 6899 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 6900 | * @phba: pointer to lpfc hba data structure. |
| 6901 | * @axri: pointer to the els xri abort wcqe structure. |
| 6902 | * |
| 6903 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 6904 | * ELS aborted xri. |
| 6905 | **/ |
| 6906 | void |
| 6907 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 6908 | struct sli4_wcqe_xri_aborted *axri) |
| 6909 | { |
| 6910 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 6911 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 6912 | unsigned long iflag = 0; |
| 6913 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6914 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 6915 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6916 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 6917 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 6918 | if (sglq_entry->sli4_xritag == xri) { |
| 6919 | list_del(&sglq_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6920 | list_add_tail(&sglq_entry->list, |
| 6921 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6922 | sglq_entry->state = SGL_FREED; |
| 6923 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6924 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6925 | return; |
| 6926 | } |
| 6927 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6928 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 6929 | sglq_entry = __lpfc_get_active_sglq(phba, xri); |
| 6930 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
| 6931 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6932 | return; |
| 6933 | } |
| 6934 | sglq_entry->state = SGL_XRI_ABORTED; |
| 6935 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6936 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6937 | } |